diff options
Diffstat (limited to 'src')
11 files changed, 407 insertions, 1 deletions
diff --git a/src/librustdoc/html/highlight.rs b/src/librustdoc/html/highlight.rs index 51392ca1191..33b1d98313c 100644 --- a/src/librustdoc/html/highlight.rs +++ b/src/librustdoc/html/highlight.rs @@ -413,7 +413,7 @@ impl<'a> Classifier<'a> { }, c => c, }, - TokenKind::RawIdent => Class::Ident, + TokenKind::RawIdent | TokenKind::UnknownPrefix => Class::Ident, TokenKind::Lifetime { .. } => Class::Lifetime, }; // Anything that didn't return above is the simple case where we the diff --git a/src/test/ui/rust-2021/auxiliary/reserved-prefixes-macro-2018.rs b/src/test/ui/rust-2021/auxiliary/reserved-prefixes-macro-2018.rs new file mode 100644 index 00000000000..eb301e5e1be --- /dev/null +++ b/src/test/ui/rust-2021/auxiliary/reserved-prefixes-macro-2018.rs @@ -0,0 +1,25 @@ +// 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_in_a_prefixed_integer_literal(_: TokenStream) -> TokenStream { + TokenStream::from_str("hey#123").unwrap().into_iter().count().to_string().parse().unwrap() +} + +#[proc_macro] +pub fn number_of_tokens_in_a_prefixed_char_literal(_: TokenStream) -> TokenStream { + TokenStream::from_str("hey#'a'").unwrap().into_iter().count().to_string().parse().unwrap() +} + +#[proc_macro] +pub fn number_of_tokens_in_a_prefixed_string_literal(_: TokenStream) -> TokenStream { + TokenStream::from_str("hey#\"abc\"").unwrap().into_iter().count().to_string().parse().unwrap() +} diff --git a/src/test/ui/rust-2021/auxiliary/reserved-prefixes-macro-2021.rs b/src/test/ui/rust-2021/auxiliary/reserved-prefixes-macro-2021.rs new file mode 100644 index 00000000000..691bfdc15c3 --- /dev/null +++ b/src/test/ui/rust-2021/auxiliary/reserved-prefixes-macro-2021.rs @@ -0,0 +1,25 @@ +// force-host +// edition:2021 +// 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_in_a_prefixed_integer_literal(_: TokenStream) -> TokenStream { + TokenStream::from_str("hey#123").unwrap().into_iter().count().to_string().parse().unwrap() +} + +#[proc_macro] +pub fn number_of_tokens_in_a_prefixed_char_literal(_: TokenStream) -> TokenStream { + TokenStream::from_str("hey#'a'").unwrap().into_iter().count().to_string().parse().unwrap() +} + +#[proc_macro] +pub fn number_of_tokens_in_a_prefixed_string_literal(_: TokenStream) -> TokenStream { + TokenStream::from_str("hey#\"abc\"").unwrap().into_iter().count().to_string().parse().unwrap() +} diff --git a/src/test/ui/rust-2021/reserved-prefixes-migration.fixed b/src/test/ui/rust-2021/reserved-prefixes-migration.fixed new file mode 100644 index 00000000000..dbc2ec6d42e --- /dev/null +++ b/src/test/ui/rust-2021/reserved-prefixes-migration.fixed @@ -0,0 +1,38 @@ +// check-pass +// run-rustfix +// compile-flags: -Z unstable-options --edition 2018 + +#![warn(reserved_prefix)] + +macro_rules! m2 { + ($a:tt $b:tt) => {}; +} + +macro_rules! m3 { + ($a:tt $b:tt $c:tt) => {}; +} + +fn main() { + m2!(z "hey"); + //~^ WARNING prefix `z` is unknown [reserved_prefix] + //~| WARNING hard error in Rust 2021 + m2!(prefix "hey"); + //~^ WARNING prefix `prefix` is unknown [reserved_prefix] + //~| WARNING hard error in Rust 2021 + m3!(hey #123); + //~^ WARNING prefix `hey` is unknown [reserved_prefix] + //~| WARNING hard error in Rust 2021 + m3!(hey #hey); + //~^ WARNING prefix `hey` is unknown [reserved_prefix] + //~| WARNING hard error in Rust 2021 +} + +macro_rules! quote { + (# name = # kind # value) => {}; +} + +quote! { + #name = #kind #value + //~^ WARNING prefix `kind` is unknown [reserved_prefix] + //~| WARNING hard error in Rust 2021 +} diff --git a/src/test/ui/rust-2021/reserved-prefixes-migration.rs b/src/test/ui/rust-2021/reserved-prefixes-migration.rs new file mode 100644 index 00000000000..6f7e3eb7a43 --- /dev/null +++ b/src/test/ui/rust-2021/reserved-prefixes-migration.rs @@ -0,0 +1,38 @@ +// check-pass +// run-rustfix +// compile-flags: -Z unstable-options --edition 2018 + +#![warn(reserved_prefix)] + +macro_rules! m2 { + ($a:tt $b:tt) => {}; +} + +macro_rules! m3 { + ($a:tt $b:tt $c:tt) => {}; +} + +fn main() { + m2!(z"hey"); + //~^ WARNING prefix `z` is unknown [reserved_prefix] + //~| WARNING hard error in Rust 2021 + m2!(prefix"hey"); + //~^ WARNING prefix `prefix` is unknown [reserved_prefix] + //~| WARNING hard error in Rust 2021 + m3!(hey#123); + //~^ WARNING prefix `hey` is unknown [reserved_prefix] + //~| WARNING hard error in Rust 2021 + m3!(hey#hey); + //~^ WARNING prefix `hey` is unknown [reserved_prefix] + //~| WARNING hard error in Rust 2021 +} + +macro_rules! quote { + (# name = # kind # value) => {}; +} + +quote! { + #name = #kind#value + //~^ WARNING prefix `kind` is unknown [reserved_prefix] + //~| WARNING hard error in Rust 2021 +} diff --git a/src/test/ui/rust-2021/reserved-prefixes-migration.stderr b/src/test/ui/rust-2021/reserved-prefixes-migration.stderr new file mode 100644 index 00000000000..28ac1966a1b --- /dev/null +++ b/src/test/ui/rust-2021/reserved-prefixes-migration.stderr @@ -0,0 +1,72 @@ +warning: prefix `z` is unknown + --> $DIR/reserved-prefixes-migration.rs:16:9 + | +LL | m2!(z"hey"); + | ^ unknown prefix + | +note: the lint level is defined here + --> $DIR/reserved-prefixes-migration.rs:5:9 + | +LL | #![warn(reserved_prefix)] + | ^^^^^^^^^^^^^^^ + = warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021! + = note: for more information, see issue #84978 <https://github.com/rust-lang/rust/issues/84978> +help: insert whitespace here to avoid this being parsed as a prefix in Rust 2021 + | +LL | m2!(z "hey"); + | -- + +warning: prefix `prefix` is unknown + --> $DIR/reserved-prefixes-migration.rs:19:9 + | +LL | m2!(prefix"hey"); + | ^^^^^^ unknown prefix + | + = warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021! + = note: for more information, see issue #84978 <https://github.com/rust-lang/rust/issues/84978> +help: insert whitespace here to avoid this being parsed as a prefix in Rust 2021 + | +LL | m2!(prefix "hey"); + | -- + +warning: prefix `hey` is unknown + --> $DIR/reserved-prefixes-migration.rs:22:9 + | +LL | m3!(hey#123); + | ^^^ unknown prefix + | + = warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021! + = note: for more information, see issue #84978 <https://github.com/rust-lang/rust/issues/84978> +help: insert whitespace here to avoid this being parsed as a prefix in Rust 2021 + | +LL | m3!(hey #123); + | -- + +warning: prefix `hey` is unknown + --> $DIR/reserved-prefixes-migration.rs:25:9 + | +LL | m3!(hey#hey); + | ^^^ unknown prefix + | + = warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021! + = note: for more information, see issue #84978 <https://github.com/rust-lang/rust/issues/84978> +help: insert whitespace here to avoid this being parsed as a prefix in Rust 2021 + | +LL | m3!(hey #hey); + | -- + +warning: prefix `kind` is unknown + --> $DIR/reserved-prefixes-migration.rs:35:14 + | +LL | #name = #kind#value + | ^^^^ unknown prefix + | + = warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021! + = note: for more information, see issue #84978 <https://github.com/rust-lang/rust/issues/84978> +help: insert whitespace here to avoid this being parsed as a prefix in Rust 2021 + | +LL | #name = #kind #value + | -- + +warning: 5 warnings emitted + diff --git a/src/test/ui/rust-2021/reserved-prefixes-via-macro-2.rs b/src/test/ui/rust-2021/reserved-prefixes-via-macro-2.rs new file mode 100644 index 00000000000..74f20660613 --- /dev/null +++ b/src/test/ui/rust-2021/reserved-prefixes-via-macro-2.rs @@ -0,0 +1,21 @@ +// edition:2018 +// aux-build:reserved-prefixes-macro-2018.rs +// aux-build:reserved-prefixes-macro-2021.rs + +extern crate reserved_prefixes_macro_2018 as m2018; +extern crate reserved_prefixes_macro_2021 as m2021; + +fn main() { + // Ok: + m2018::number_of_tokens_in_a_prefixed_integer_literal!(); + m2018::number_of_tokens_in_a_prefixed_char_literal!(); + m2018::number_of_tokens_in_a_prefixed_string_literal!(); + + // Error, even though *this* crate is 2018: + m2021::number_of_tokens_in_a_prefixed_integer_literal!(); + //~^ ERROR prefix `hey` is unknown + m2021::number_of_tokens_in_a_prefixed_char_literal!(); + //~^ ERROR prefix `hey` is unknown + m2021::number_of_tokens_in_a_prefixed_string_literal!(); + //~^ ERROR prefix `hey` is unknown +} diff --git a/src/test/ui/rust-2021/reserved-prefixes-via-macro-2.stderr b/src/test/ui/rust-2021/reserved-prefixes-via-macro-2.stderr new file mode 100644 index 00000000000..9d7ca570c4c --- /dev/null +++ b/src/test/ui/rust-2021/reserved-prefixes-via-macro-2.stderr @@ -0,0 +1,29 @@ +error: prefix `hey` is unknown + --> $DIR/reserved-prefixes-via-macro-2.rs:15:5 + | +LL | m2021::number_of_tokens_in_a_prefixed_integer_literal!(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unknown prefix + | + = note: prefixed identifiers and literals are reserved since Rust 2021 + = note: this error originates in the macro `m2021::number_of_tokens_in_a_prefixed_integer_literal` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: prefix `hey` is unknown + --> $DIR/reserved-prefixes-via-macro-2.rs:17:5 + | +LL | m2021::number_of_tokens_in_a_prefixed_char_literal!(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unknown prefix + | + = note: prefixed identifiers and literals are reserved since Rust 2021 + = note: this error originates in the macro `m2021::number_of_tokens_in_a_prefixed_char_literal` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: prefix `hey` is unknown + --> $DIR/reserved-prefixes-via-macro-2.rs:19:5 + | +LL | m2021::number_of_tokens_in_a_prefixed_string_literal!(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unknown prefix + | + = note: prefixed identifiers and literals are reserved since Rust 2021 + = note: this error originates in the macro `m2021::number_of_tokens_in_a_prefixed_string_literal` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: aborting due to 3 previous errors + diff --git a/src/test/ui/rust-2021/reserved-prefixes-via-macro.rs b/src/test/ui/rust-2021/reserved-prefixes-via-macro.rs new file mode 100644 index 00000000000..110b6d64ccc --- /dev/null +++ b/src/test/ui/rust-2021/reserved-prefixes-via-macro.rs @@ -0,0 +1,12 @@ +// run-pass +// edition:2021 +// aux-build:reserved-prefixes-macro-2018.rs + +extern crate reserved_prefixes_macro_2018 as m2018; + +fn main() { + // Ok, even though *this* crate is 2021: + assert_eq!(m2018::number_of_tokens_in_a_prefixed_integer_literal!(), 3); + assert_eq!(m2018::number_of_tokens_in_a_prefixed_char_literal!(), 3); + assert_eq!(m2018::number_of_tokens_in_a_prefixed_string_literal!(), 3); +} diff --git a/src/test/ui/rust-2021/reserved-prefixes.rs b/src/test/ui/rust-2021/reserved-prefixes.rs new file mode 100644 index 00000000000..5882c7d83d8 --- /dev/null +++ b/src/test/ui/rust-2021/reserved-prefixes.rs @@ -0,0 +1,36 @@ +// compile-flags: -Z unstable-options --edition 2021 + +macro_rules! demo2 { + ( $a:tt $b:tt ) => { println!("two tokens") }; +} + +macro_rules! demo3 { + ( $a:tt $b:tt $c:tt ) => { println!("three tokens") }; +} + +macro_rules! demo4 { + ( $a:tt $b:tt $c:tt $d:tt ) => { println!("four tokens") }; +} + +fn main() { + demo3!(foo#bar); //~ ERROR prefix `foo` is unknown + demo2!(foo"bar"); //~ ERROR prefix `foo` is unknown + demo2!(foo'b'); //~ ERROR prefix `foo` is unknown + + demo2!(foo'b); //~ ERROR prefix `foo` is unknown + demo3!(foo# bar); //~ ERROR prefix `foo` is unknown + demo4!(foo#! bar); //~ ERROR prefix `foo` is unknown + demo4!(foo## bar); //~ ERROR prefix `foo` is unknown + + demo4!(foo#bar#); + //~^ ERROR prefix `foo` is unknown + //~| ERROR prefix `bar` is unknown + + demo3!(foo # bar); + demo3!(foo #bar); + demo4!(foo!#bar); + demo4!(foo ##bar); + + demo3!(r"foo"#bar); + demo3!(r#foo#bar); +} diff --git a/src/test/ui/rust-2021/reserved-prefixes.stderr b/src/test/ui/rust-2021/reserved-prefixes.stderr new file mode 100644 index 00000000000..32e18563329 --- /dev/null +++ b/src/test/ui/rust-2021/reserved-prefixes.stderr @@ -0,0 +1,110 @@ +error: prefix `foo` is unknown + --> $DIR/reserved-prefixes.rs:16:12 + | +LL | demo3!(foo#bar); + | ^^^ unknown prefix + | + = note: prefixed identifiers and literals are reserved since Rust 2021 +help: consider inserting whitespace here + | +LL | demo3!(foo #bar); + | -- + +error: prefix `foo` is unknown + --> $DIR/reserved-prefixes.rs:17:12 + | +LL | demo2!(foo"bar"); + | ^^^ unknown prefix + | + = note: prefixed identifiers and literals are reserved since Rust 2021 +help: consider inserting whitespace here + | +LL | demo2!(foo "bar"); + | -- + +error: prefix `foo` is unknown + --> $DIR/reserved-prefixes.rs:18:12 + | +LL | demo2!(foo'b'); + | ^^^ unknown prefix + | + = note: prefixed identifiers and literals are reserved since Rust 2021 +help: consider inserting whitespace here + | +LL | demo2!(foo 'b'); + | -- + +error: prefix `foo` is unknown + --> $DIR/reserved-prefixes.rs:20:12 + | +LL | demo2!(foo'b); + | ^^^ unknown prefix + | + = note: prefixed identifiers and literals are reserved since Rust 2021 +help: consider inserting whitespace here + | +LL | demo2!(foo 'b); + | -- + +error: prefix `foo` is unknown + --> $DIR/reserved-prefixes.rs:21:12 + | +LL | demo3!(foo# bar); + | ^^^ unknown prefix + | + = note: prefixed identifiers and literals are reserved since Rust 2021 +help: consider inserting whitespace here + | +LL | demo3!(foo # bar); + | -- + +error: prefix `foo` is unknown + --> $DIR/reserved-prefixes.rs:22:12 + | +LL | demo4!(foo#! bar); + | ^^^ unknown prefix + | + = note: prefixed identifiers and literals are reserved since Rust 2021 +help: consider inserting whitespace here + | +LL | demo4!(foo #! bar); + | -- + +error: prefix `foo` is unknown + --> $DIR/reserved-prefixes.rs:23:12 + | +LL | demo4!(foo## bar); + | ^^^ unknown prefix + | + = note: prefixed identifiers and literals are reserved since Rust 2021 +help: consider inserting whitespace here + | +LL | demo4!(foo ## bar); + | -- + +error: prefix `foo` is unknown + --> $DIR/reserved-prefixes.rs:25:12 + | +LL | demo4!(foo#bar#); + | ^^^ unknown prefix + | + = note: prefixed identifiers and literals are reserved since Rust 2021 +help: consider inserting whitespace here + | +LL | demo4!(foo #bar#); + | -- + +error: prefix `bar` is unknown + --> $DIR/reserved-prefixes.rs:25:16 + | +LL | demo4!(foo#bar#); + | ^^^ unknown prefix + | + = note: prefixed identifiers and literals are reserved since Rust 2021 +help: consider inserting whitespace here + | +LL | demo4!(foo#bar #); + | -- + +error: aborting due to 9 previous errors + |
