-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #113476 - fee1-dead-contrib:c-str-lit, r=petrochenkov
Reimplement C-str literals This reverts #113334, cc `@fmease.` While converting lexer tokens to ast Tokens in `rustc_parse`, we check the edition of the span of the token. If the edition < 2021, we split the token into two, one being the identifier and other being the str literal.
- Loading branch information
Showing
12 changed files
with
85 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
tests/ui/rfcs/rfc-3348-c-string-literals/auxiliary/count.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// force-host | ||
// edition: 2018 | ||
// no-prefer-dynamic | ||
#![crate_type = "proc-macro"] | ||
|
||
extern crate proc_macro; | ||
|
||
use proc_macro::TokenStream; | ||
use std::str::FromStr; | ||
|
||
#[proc_macro] | ||
pub fn number_of_tokens(_: TokenStream) -> TokenStream { | ||
TokenStream::from_str("c\"\"").unwrap().into_iter().count().to_string().parse().unwrap() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// even if this crate is edition 2021, proc macros compiled using older | ||
// editions should still be able to observe the pre-2021 token behavior | ||
// | ||
// adapted from tests/ui/rust-2021/reserved-prefixes-via-macro.rs | ||
|
||
// edition: 2021 | ||
// check-pass | ||
|
||
// aux-build: count.rs | ||
extern crate count; | ||
|
||
const _: () = { | ||
assert!(count::number_of_tokens!() == 2); | ||
}; | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,21 @@ | ||
error: prefix `c` is unknown | ||
error[E0658]: `c".."` literals are experimental | ||
--> $DIR/gate.rs:10:5 | ||
| | ||
LL | c"foo"; | ||
| ^ unknown prefix | ||
| ^^^^^^ | ||
| | ||
= note: prefixed identifiers and literals are reserved since Rust 2021 | ||
help: consider inserting whitespace here | ||
| | ||
LL | c "foo"; | ||
| + | ||
= note: see issue #105723 <https://github.com/rust-lang/rust/issues/105723> for more information | ||
= help: add `#![feature(c_str_literals)]` to the crate attributes to enable | ||
|
||
error: prefix `c` is unknown | ||
error[E0658]: `c".."` literals are experimental | ||
--> $DIR/gate.rs:13:8 | ||
| | ||
LL | m!(c"test"); | ||
| ^ unknown prefix | ||
| | ||
= note: prefixed identifiers and literals are reserved since Rust 2021 | ||
help: consider inserting whitespace here | ||
| ^^^^^^^ | ||
| | ||
LL | m!(c "test"); | ||
| + | ||
|
||
error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found `"foo"` | ||
--> $DIR/gate.rs:10:6 | ||
| | ||
LL | c"foo"; | ||
| ^^^^^ expected one of 8 possible tokens | ||
= note: see issue #105723 <https://github.com/rust-lang/rust/issues/105723> for more information | ||
= help: add `#![feature(c_str_literals)]` to the crate attributes to enable | ||
|
||
error: aborting due to 3 previous errors | ||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0658`. |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.