diff options
Diffstat (limited to 'src/test/ui/dyn-keyword')
14 files changed, 691 insertions, 0 deletions
diff --git a/src/test/ui/dyn-keyword/dyn-2015-edition-keyword-ident-lint.fixed b/src/test/ui/dyn-keyword/dyn-2015-edition-keyword-ident-lint.fixed new file mode 100644 index 000000000..c815080fc --- /dev/null +++ b/src/test/ui/dyn-keyword/dyn-2015-edition-keyword-ident-lint.fixed @@ -0,0 +1,82 @@ +// Under the 2015 edition with the keyword_idents lint, `dyn` is not +// entirely acceptable as an identifier. We currently do not attempt +// to detect or fix uses of `dyn` under a macro. Since we are testing +// this file via `rustfix`, we want the rustfix output to be +// compilable; so the macros here carefully use `dyn` "correctly." +// +// edition:2015 +// run-rustfix + +#![allow(non_camel_case_types)] +#![deny(keyword_idents)] + +mod outer_mod { + pub mod r#dyn { +//~^ ERROR `dyn` is a keyword +//~| WARN this is accepted in the current edition + pub struct r#dyn; +//~^ ERROR `dyn` is a keyword +//~| WARN this is accepted in the current edition + } +} +use outer_mod::r#dyn::r#dyn; +//~^ ERROR `dyn` is a keyword +//~| WARN this is accepted in the current edition +//~| ERROR `dyn` is a keyword +//~| WARN this is accepted in the current edition + +fn main() { + match r#dyn { r#dyn => {} } +//~^ ERROR `dyn` is a keyword +//~| WARN this is accepted in the current edition +//~| ERROR `dyn` is a keyword +//~| WARN this is accepted in the current edition + macro_defn::r#dyn(); +//~^ ERROR `dyn` is a keyword +//~| WARN this is accepted in the current edition + + macro_defn::boxed(); +} + +mod macro_defn { + use super::Trait; + + macro_rules! r#dyn { +//~^ ERROR `dyn` is a keyword +//~| WARN this is accepted in the current edition + + // Note that we do not lint nor fix occurrences under macros + ($dyn:tt) => { (Box<dyn Trait>, Box<$dyn Trait>) } + } + + pub fn r#dyn() -> ::outer_mod::r#dyn::r#dyn { +//~^ ERROR `dyn` is a keyword +//~| WARN this is accepted in the current edition +//~| ERROR `dyn` is a keyword +//~| WARN this is accepted in the current edition +//~| ERROR `dyn` is a keyword +//~| WARN this is accepted in the current edition + ::outer_mod::r#dyn::r#dyn +//~^ ERROR `dyn` is a keyword +//~| WARN this is accepted in the current edition +//~| ERROR `dyn` is a keyword +//~| WARN this is accepted in the current edition + } + + + + pub fn boxed() -> r#dyn!( + //~^ ERROR `dyn` is a keyword + //~| WARN this is accepted in the current edition + + // Note that we do not lint nor fix occurrences under macros + dyn + ) + { + (Box::new(1), Box::new(2)) + } +} + +pub trait Trait { } + +impl Trait for u32 { } diff --git a/src/test/ui/dyn-keyword/dyn-2015-edition-keyword-ident-lint.rs b/src/test/ui/dyn-keyword/dyn-2015-edition-keyword-ident-lint.rs new file mode 100644 index 000000000..6cdc70714 --- /dev/null +++ b/src/test/ui/dyn-keyword/dyn-2015-edition-keyword-ident-lint.rs @@ -0,0 +1,82 @@ +// Under the 2015 edition with the keyword_idents lint, `dyn` is not +// entirely acceptable as an identifier. We currently do not attempt +// to detect or fix uses of `dyn` under a macro. Since we are testing +// this file via `rustfix`, we want the rustfix output to be +// compilable; so the macros here carefully use `dyn` "correctly." +// +// edition:2015 +// run-rustfix + +#![allow(non_camel_case_types)] +#![deny(keyword_idents)] + +mod outer_mod { + pub mod dyn { +//~^ ERROR `dyn` is a keyword +//~| WARN this is accepted in the current edition + pub struct dyn; +//~^ ERROR `dyn` is a keyword +//~| WARN this is accepted in the current edition + } +} +use outer_mod::dyn::dyn; +//~^ ERROR `dyn` is a keyword +//~| WARN this is accepted in the current edition +//~| ERROR `dyn` is a keyword +//~| WARN this is accepted in the current edition + +fn main() { + match dyn { dyn => {} } +//~^ ERROR `dyn` is a keyword +//~| WARN this is accepted in the current edition +//~| ERROR `dyn` is a keyword +//~| WARN this is accepted in the current edition + macro_defn::dyn(); +//~^ ERROR `dyn` is a keyword +//~| WARN this is accepted in the current edition + + macro_defn::boxed(); +} + +mod macro_defn { + use super::Trait; + + macro_rules! dyn { +//~^ ERROR `dyn` is a keyword +//~| WARN this is accepted in the current edition + + // Note that we do not lint nor fix occurrences under macros + ($dyn:tt) => { (Box<dyn Trait>, Box<$dyn Trait>) } + } + + pub fn dyn() -> ::outer_mod::dyn::dyn { +//~^ ERROR `dyn` is a keyword +//~| WARN this is accepted in the current edition +//~| ERROR `dyn` is a keyword +//~| WARN this is accepted in the current edition +//~| ERROR `dyn` is a keyword +//~| WARN this is accepted in the current edition + ::outer_mod::dyn::dyn +//~^ ERROR `dyn` is a keyword +//~| WARN this is accepted in the current edition +//~| ERROR `dyn` is a keyword +//~| WARN this is accepted in the current edition + } + + + + pub fn boxed() -> dyn!( + //~^ ERROR `dyn` is a keyword + //~| WARN this is accepted in the current edition + + // Note that we do not lint nor fix occurrences under macros + dyn + ) + { + (Box::new(1), Box::new(2)) + } +} + +pub trait Trait { } + +impl Trait for u32 { } diff --git a/src/test/ui/dyn-keyword/dyn-2015-edition-keyword-ident-lint.stderr b/src/test/ui/dyn-keyword/dyn-2015-edition-keyword-ident-lint.stderr new file mode 100644 index 000000000..3eb5bb7b2 --- /dev/null +++ b/src/test/ui/dyn-keyword/dyn-2015-edition-keyword-ident-lint.stderr @@ -0,0 +1,133 @@ +error: `dyn` is a keyword in the 2018 edition + --> $DIR/dyn-2015-edition-keyword-ident-lint.rs:14:13 + | +LL | pub mod dyn { + | ^^^ help: you can use a raw identifier to stay compatible: `r#dyn` + | +note: the lint level is defined here + --> $DIR/dyn-2015-edition-keyword-ident-lint.rs:11:9 + | +LL | #![deny(keyword_idents)] + | ^^^^^^^^^^^^^^ + = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018! + = note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716> + +error: `dyn` is a keyword in the 2018 edition + --> $DIR/dyn-2015-edition-keyword-ident-lint.rs:17:20 + | +LL | pub struct dyn; + | ^^^ help: you can use a raw identifier to stay compatible: `r#dyn` + | + = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018! + = note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716> + +error: `dyn` is a keyword in the 2018 edition + --> $DIR/dyn-2015-edition-keyword-ident-lint.rs:22:16 + | +LL | use outer_mod::dyn::dyn; + | ^^^ help: you can use a raw identifier to stay compatible: `r#dyn` + | + = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018! + = note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716> + +error: `dyn` is a keyword in the 2018 edition + --> $DIR/dyn-2015-edition-keyword-ident-lint.rs:22:21 + | +LL | use outer_mod::dyn::dyn; + | ^^^ help: you can use a raw identifier to stay compatible: `r#dyn` + | + = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018! + = note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716> + +error: `dyn` is a keyword in the 2018 edition + --> $DIR/dyn-2015-edition-keyword-ident-lint.rs:29:11 + | +LL | match dyn { dyn => {} } + | ^^^ help: you can use a raw identifier to stay compatible: `r#dyn` + | + = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018! + = note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716> + +error: `dyn` is a keyword in the 2018 edition + --> $DIR/dyn-2015-edition-keyword-ident-lint.rs:29:17 + | +LL | match dyn { dyn => {} } + | ^^^ help: you can use a raw identifier to stay compatible: `r#dyn` + | + = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018! + = note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716> + +error: `dyn` is a keyword in the 2018 edition + --> $DIR/dyn-2015-edition-keyword-ident-lint.rs:34:17 + | +LL | macro_defn::dyn(); + | ^^^ help: you can use a raw identifier to stay compatible: `r#dyn` + | + = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018! + = note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716> + +error: `dyn` is a keyword in the 2018 edition + --> $DIR/dyn-2015-edition-keyword-ident-lint.rs:44:18 + | +LL | macro_rules! dyn { + | ^^^ help: you can use a raw identifier to stay compatible: `r#dyn` + | + = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018! + = note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716> + +error: `dyn` is a keyword in the 2018 edition + --> $DIR/dyn-2015-edition-keyword-ident-lint.rs:52:12 + | +LL | pub fn dyn() -> ::outer_mod::dyn::dyn { + | ^^^ help: you can use a raw identifier to stay compatible: `r#dyn` + | + = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018! + = note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716> + +error: `dyn` is a keyword in the 2018 edition + --> $DIR/dyn-2015-edition-keyword-ident-lint.rs:52:34 + | +LL | pub fn dyn() -> ::outer_mod::dyn::dyn { + | ^^^ help: you can use a raw identifier to stay compatible: `r#dyn` + | + = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018! + = note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716> + +error: `dyn` is a keyword in the 2018 edition + --> $DIR/dyn-2015-edition-keyword-ident-lint.rs:52:39 + | +LL | pub fn dyn() -> ::outer_mod::dyn::dyn { + | ^^^ help: you can use a raw identifier to stay compatible: `r#dyn` + | + = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018! + = note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716> + +error: `dyn` is a keyword in the 2018 edition + --> $DIR/dyn-2015-edition-keyword-ident-lint.rs:59:22 + | +LL | ::outer_mod::dyn::dyn + | ^^^ help: you can use a raw identifier to stay compatible: `r#dyn` + | + = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018! + = note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716> + +error: `dyn` is a keyword in the 2018 edition + --> $DIR/dyn-2015-edition-keyword-ident-lint.rs:59:27 + | +LL | ::outer_mod::dyn::dyn + | ^^^ help: you can use a raw identifier to stay compatible: `r#dyn` + | + = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018! + = note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716> + +error: `dyn` is a keyword in the 2018 edition + --> $DIR/dyn-2015-edition-keyword-ident-lint.rs:68:23 + | +LL | pub fn boxed() -> dyn!( + | ^^^ help: you can use a raw identifier to stay compatible: `r#dyn` + | + = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018! + = note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716> + +error: aborting due to 14 previous errors + diff --git a/src/test/ui/dyn-keyword/dyn-2015-idents-in-decl-macros-unlinted.rs b/src/test/ui/dyn-keyword/dyn-2015-idents-in-decl-macros-unlinted.rs new file mode 100644 index 000000000..bda2ed17e --- /dev/null +++ b/src/test/ui/dyn-keyword/dyn-2015-idents-in-decl-macros-unlinted.rs @@ -0,0 +1,52 @@ +// Under the 2015 edition with the keyword_idents lint, `dyn` is +// not entirely acceptable as an identifier. +// +// We currently do not attempt to detect or fix uses of `dyn` as an +// identifier under a macro, including under the declarative `macro` +// forms from macros 1.2 and macros 2.0. +// +// check-pass +// edition:2015 + +#![feature(decl_macro)] +#![allow(non_camel_case_types)] +#![deny(keyword_idents)] + +mod outer_mod { + pub mod r#dyn { + pub struct r#dyn; + } +} + +// Here we are illustrating that the current lint does not flag the +// occurrences of `dyn` in this macro definition; however, it +// certainly *could* (and it would be nice if it did), since these +// occurrences are not compatible with the 2018 edition's +// interpretation of `dyn` as a keyword. +macro defn_has_dyn_idents() { ::outer_mod::dyn::dyn } + +struct X; +trait Trait { fn hello(&self) { }} +impl Trait for X { } + +macro tt_trait($arg:tt) { & $arg Trait } +macro id_trait($id:ident) { & $id Trait } + +fn main() { + defn_has_dyn_idents!(); + + // Here we are illustrating that the current lint does not flag + // the occurrences of `dyn` in these macro invocations. It + // definitely should *not* flag the one in `tt_trait`, since that + // is expanding in a valid fashion to `&dyn Trait`. + // + // It is arguable whether it would be valid to flag the occurrence + // in `id_trait`, since that macro specifies that it takes an + // `ident` as its input. + fn f_tt(x: &X) -> tt_trait!(dyn) { x } + fn f_id(x: &X) -> id_trait!(dyn) { x } + + let x = X; + f_tt(&x).hello(); + f_id(&x).hello(); +} diff --git a/src/test/ui/dyn-keyword/dyn-2015-idents-in-macros-unlinted.rs b/src/test/ui/dyn-keyword/dyn-2015-idents-in-macros-unlinted.rs new file mode 100644 index 000000000..472f6b5c8 --- /dev/null +++ b/src/test/ui/dyn-keyword/dyn-2015-idents-in-macros-unlinted.rs @@ -0,0 +1,57 @@ +// Under the 2015 edition with the keyword_idents lint, `dyn` is +// not entirely acceptable as an identifier. +// +// We currently do not attempt to detect or fix uses of `dyn` as an +// identifier under a macro. +// +// check-pass +// edition:2015 + +#![allow(non_camel_case_types)] +#![deny(keyword_idents)] + +mod outer_mod { + pub mod r#dyn { + pub struct r#dyn; + } +} + +// Here we are illustrating that the current lint does not flag the +// occurrences of `dyn` in this macro definition; however, it +// certainly *could* (and it would be nice if it did), since these +// occurrences are not compatible with the 2018 edition's +// interpretation of `dyn` as a keyword. +macro_rules! defn_has_dyn_idents { + () => { ::outer_mod::dyn::dyn } +} + +struct X; +trait Trait { fn hello(&self) { }} +impl Trait for X { } + +macro_rules! tt_trait { + ($arg:tt) => { & $arg Trait } +} + +macro_rules! id_trait { + ($id:ident) => { & $id Trait } +} + +fn main() { + defn_has_dyn_idents!(); + + // Here we are illustrating that the current lint does not flag + // the occurrences of `dyn` in these macro invocations. It + // definitely should *not* flag the one in `tt_trait`, since that + // is expanding in a valid fashion to `&dyn Trait`. + // + // It is arguable whether it would be valid to flag the occurrence + // in `id_trait`, since that macro specifies that it takes an + // `ident` as its input. + fn f_tt(x: &X) -> tt_trait!(dyn) { x } + fn f_id(x: &X) -> id_trait!(dyn) { x } + + let x = X; + f_tt(&x).hello(); + f_id(&x).hello(); +} diff --git a/src/test/ui/dyn-keyword/dyn-2015-no-warnings-without-lints.rs b/src/test/ui/dyn-keyword/dyn-2015-no-warnings-without-lints.rs new file mode 100644 index 000000000..d6a33c08d --- /dev/null +++ b/src/test/ui/dyn-keyword/dyn-2015-no-warnings-without-lints.rs @@ -0,0 +1,28 @@ +// Under the 2015 edition without the keyword_idents lint, `dyn` is +// entirely acceptable as an identifier. +// +// check-pass +// edition:2015 + +#![allow(non_camel_case_types)] + +mod outer_mod { + pub mod dyn { + pub struct dyn; + } +} +use outer_mod::dyn::dyn; + +fn main() { + match dyn { dyn => {} } + macro_defn::dyn(); +} +mod macro_defn { + macro_rules! dyn { + () => { ::outer_mod::dyn::dyn } + } + + pub fn dyn() -> ::outer_mod::dyn::dyn { + dyn!() + } +} diff --git a/src/test/ui/dyn-keyword/dyn-2018-edition-lint.rs b/src/test/ui/dyn-keyword/dyn-2018-edition-lint.rs new file mode 100644 index 000000000..a074b5fa5 --- /dev/null +++ b/src/test/ui/dyn-keyword/dyn-2018-edition-lint.rs @@ -0,0 +1,24 @@ +// edition:2018 +#[deny(bare_trait_objects)] + +fn function(x: &SomeTrait, y: Box<SomeTrait>) { + //~^ ERROR trait objects without an explicit `dyn` are deprecated + //~| WARN this is accepted in the current edition + //~| ERROR trait objects without an explicit `dyn` are deprecated + //~| WARN this is accepted in the current edition + //~| ERROR trait objects without an explicit `dyn` are deprecated + //~| WARN this is accepted in the current edition + //~| ERROR trait objects without an explicit `dyn` are deprecated + //~| WARN this is accepted in the current edition + //~| ERROR trait objects without an explicit `dyn` are deprecated + //~| WARN this is accepted in the current edition + //~| ERROR trait objects without an explicit `dyn` are deprecated + //~| WARN this is accepted in the current edition + let _x: &SomeTrait = todo!(); + //~^ ERROR trait objects without an explicit `dyn` are deprecated + //~| WARN this is accepted in the current edition +} + +trait SomeTrait {} + +fn main() {} diff --git a/src/test/ui/dyn-keyword/dyn-2018-edition-lint.stderr b/src/test/ui/dyn-keyword/dyn-2018-edition-lint.stderr new file mode 100644 index 000000000..34699bb26 --- /dev/null +++ b/src/test/ui/dyn-keyword/dyn-2018-edition-lint.stderr @@ -0,0 +1,105 @@ +error: trait objects without an explicit `dyn` are deprecated + --> $DIR/dyn-2018-edition-lint.rs:4:17 + | +LL | fn function(x: &SomeTrait, y: Box<SomeTrait>) { + | ^^^^^^^^^ + | +note: the lint level is defined here + --> $DIR/dyn-2018-edition-lint.rs:2:8 + | +LL | #[deny(bare_trait_objects)] + | ^^^^^^^^^^^^^^^^^^ + = warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021! + = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html> +help: use `dyn` + | +LL - fn function(x: &SomeTrait, y: Box<SomeTrait>) { +LL + fn function(x: &dyn SomeTrait, y: Box<SomeTrait>) { + | + +error: trait objects without an explicit `dyn` are deprecated + --> $DIR/dyn-2018-edition-lint.rs:4:35 + | +LL | fn function(x: &SomeTrait, y: Box<SomeTrait>) { + | ^^^^^^^^^ + | + = warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021! + = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html> +help: use `dyn` + | +LL - fn function(x: &SomeTrait, y: Box<SomeTrait>) { +LL + fn function(x: &SomeTrait, y: Box<dyn SomeTrait>) { + | + +error: trait objects without an explicit `dyn` are deprecated + --> $DIR/dyn-2018-edition-lint.rs:17:14 + | +LL | let _x: &SomeTrait = todo!(); + | ^^^^^^^^^ + | + = warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021! + = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html> +help: use `dyn` + | +LL - let _x: &SomeTrait = todo!(); +LL + let _x: &dyn SomeTrait = todo!(); + | + +error: trait objects without an explicit `dyn` are deprecated + --> $DIR/dyn-2018-edition-lint.rs:4:17 + | +LL | fn function(x: &SomeTrait, y: Box<SomeTrait>) { + | ^^^^^^^^^ + | + = warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021! + = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html> +help: use `dyn` + | +LL - fn function(x: &SomeTrait, y: Box<SomeTrait>) { +LL + fn function(x: &dyn SomeTrait, y: Box<SomeTrait>) { + | + +error: trait objects without an explicit `dyn` are deprecated + --> $DIR/dyn-2018-edition-lint.rs:4:17 + | +LL | fn function(x: &SomeTrait, y: Box<SomeTrait>) { + | ^^^^^^^^^ + | + = warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021! + = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html> +help: use `dyn` + | +LL - fn function(x: &SomeTrait, y: Box<SomeTrait>) { +LL + fn function(x: &dyn SomeTrait, y: Box<SomeTrait>) { + | + +error: trait objects without an explicit `dyn` are deprecated + --> $DIR/dyn-2018-edition-lint.rs:4:35 + | +LL | fn function(x: &SomeTrait, y: Box<SomeTrait>) { + | ^^^^^^^^^ + | + = warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021! + = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html> +help: use `dyn` + | +LL - fn function(x: &SomeTrait, y: Box<SomeTrait>) { +LL + fn function(x: &SomeTrait, y: Box<dyn SomeTrait>) { + | + +error: trait objects without an explicit `dyn` are deprecated + --> $DIR/dyn-2018-edition-lint.rs:4:35 + | +LL | fn function(x: &SomeTrait, y: Box<SomeTrait>) { + | ^^^^^^^^^ + | + = warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021! + = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html> +help: use `dyn` + | +LL - fn function(x: &SomeTrait, y: Box<SomeTrait>) { +LL + fn function(x: &SomeTrait, y: Box<dyn SomeTrait>) { + | + +error: aborting due to 7 previous errors + diff --git a/src/test/ui/dyn-keyword/dyn-2021-edition-error.rs b/src/test/ui/dyn-keyword/dyn-2021-edition-error.rs new file mode 100644 index 000000000..0f05d8753 --- /dev/null +++ b/src/test/ui/dyn-keyword/dyn-2021-edition-error.rs @@ -0,0 +1,11 @@ +// edition:2021 + +fn function(x: &SomeTrait, y: Box<SomeTrait>) { + //~^ ERROR trait objects must include the `dyn` keyword + //~| ERROR trait objects must include the `dyn` keyword + let _x: &SomeTrait = todo!(); +} + +trait SomeTrait {} + +fn main() {} diff --git a/src/test/ui/dyn-keyword/dyn-2021-edition-error.stderr b/src/test/ui/dyn-keyword/dyn-2021-edition-error.stderr new file mode 100644 index 000000000..9e212c77d --- /dev/null +++ b/src/test/ui/dyn-keyword/dyn-2021-edition-error.stderr @@ -0,0 +1,27 @@ +error[E0782]: trait objects must include the `dyn` keyword + --> $DIR/dyn-2021-edition-error.rs:3:17 + | +LL | fn function(x: &SomeTrait, y: Box<SomeTrait>) { + | ^^^^^^^^^ + | +help: add `dyn` keyword before this trait + | +LL - fn function(x: &SomeTrait, y: Box<SomeTrait>) { +LL + fn function(x: &dyn SomeTrait, y: Box<SomeTrait>) { + | + +error[E0782]: trait objects must include the `dyn` keyword + --> $DIR/dyn-2021-edition-error.rs:3:35 + | +LL | fn function(x: &SomeTrait, y: Box<SomeTrait>) { + | ^^^^^^^^^ + | +help: add `dyn` keyword before this trait + | +LL - fn function(x: &SomeTrait, y: Box<SomeTrait>) { +LL + fn function(x: &SomeTrait, y: Box<dyn SomeTrait>) { + | + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0782`. diff --git a/src/test/ui/dyn-keyword/dyn-angle-brackets.fixed b/src/test/ui/dyn-keyword/dyn-angle-brackets.fixed new file mode 100644 index 000000000..00069a3e7 --- /dev/null +++ b/src/test/ui/dyn-keyword/dyn-angle-brackets.fixed @@ -0,0 +1,21 @@ +// See https://github.com/rust-lang/rust/issues/88508 +// run-rustfix +// edition:2018 +#![deny(bare_trait_objects)] +#![allow(dead_code)] +#![allow(unused_imports)] + +use std::fmt; + +#[derive(Debug)] +pub struct Foo; + +impl fmt::Display for Foo { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + <dyn fmt::Debug>::fmt(self, f) + //~^ ERROR trait objects without an explicit `dyn` are deprecated + //~| WARNING this is accepted in the current edition + } +} + +fn main() {} diff --git a/src/test/ui/dyn-keyword/dyn-angle-brackets.rs b/src/test/ui/dyn-keyword/dyn-angle-brackets.rs new file mode 100644 index 000000000..ee5fee4cf --- /dev/null +++ b/src/test/ui/dyn-keyword/dyn-angle-brackets.rs @@ -0,0 +1,21 @@ +// See https://github.com/rust-lang/rust/issues/88508 +// run-rustfix +// edition:2018 +#![deny(bare_trait_objects)] +#![allow(dead_code)] +#![allow(unused_imports)] + +use std::fmt; + +#[derive(Debug)] +pub struct Foo; + +impl fmt::Display for Foo { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + <fmt::Debug>::fmt(self, f) + //~^ ERROR trait objects without an explicit `dyn` are deprecated + //~| WARNING this is accepted in the current edition + } +} + +fn main() {} diff --git a/src/test/ui/dyn-keyword/dyn-angle-brackets.stderr b/src/test/ui/dyn-keyword/dyn-angle-brackets.stderr new file mode 100644 index 000000000..9bc603fba --- /dev/null +++ b/src/test/ui/dyn-keyword/dyn-angle-brackets.stderr @@ -0,0 +1,21 @@ +error: trait objects without an explicit `dyn` are deprecated + --> $DIR/dyn-angle-brackets.rs:15:10 + | +LL | <fmt::Debug>::fmt(self, f) + | ^^^^^^^^^^ + | +note: the lint level is defined here + --> $DIR/dyn-angle-brackets.rs:4:9 + | +LL | #![deny(bare_trait_objects)] + | ^^^^^^^^^^^^^^^^^^ + = warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021! + = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html> +help: use `dyn` + | +LL - <fmt::Debug>::fmt(self, f) +LL + <dyn fmt::Debug>::fmt(self, f) + | + +error: aborting due to previous error + diff --git a/src/test/ui/dyn-keyword/issue-56327-dyn-trait-in-macro-is-okay.rs b/src/test/ui/dyn-keyword/issue-56327-dyn-trait-in-macro-is-okay.rs new file mode 100644 index 000000000..59e7f9a60 --- /dev/null +++ b/src/test/ui/dyn-keyword/issue-56327-dyn-trait-in-macro-is-okay.rs @@ -0,0 +1,27 @@ +// check-pass +// edition:2015 +// +// rust-lang/rust#56327: Some occurrences of `dyn` within a macro are +// not instances of identifiers, and thus should *not* be caught by the +// keyword_ident lint. +// +// Otherwise, rustfix replaces the type `Box<dyn Drop>` with +// `Box<r#dyn Drop>`, which is injecting a bug rather than fixing +// anything. + +#![deny(rust_2018_compatibility)] +#![allow(dyn_drop)] + +macro_rules! foo { + () => { + fn generated_foo() { + let _x: Box<dyn Drop>; + } + } +} + +foo!(); + +fn main() { + generated_foo(); +} |