From 64d98f8ee037282c35007b64c2649055c56af1db Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:19:03 +0200 Subject: Merging upstream version 1.68.2+dfsg1. Signed-off-by: Daniel Baumann --- .../dyn-2015-edition-keyword-ident-lint.fixed | 82 +++++++++++++ .../dyn-2015-edition-keyword-ident-lint.rs | 82 +++++++++++++ .../dyn-2015-edition-keyword-ident-lint.stderr | 133 +++++++++++++++++++++ .../dyn-2015-idents-in-decl-macros-unlinted.rs | 52 ++++++++ .../dyn-2015-idents-in-macros-unlinted.rs | 57 +++++++++ .../dyn-2015-no-warnings-without-lints.rs | 28 +++++ tests/ui/dyn-keyword/dyn-2018-edition-lint.rs | 24 ++++ tests/ui/dyn-keyword/dyn-2018-edition-lint.stderr | 98 +++++++++++++++ tests/ui/dyn-keyword/dyn-2021-edition-error.rs | 11 ++ tests/ui/dyn-keyword/dyn-2021-edition-error.stderr | 25 ++++ tests/ui/dyn-keyword/dyn-angle-brackets.fixed | 21 ++++ tests/ui/dyn-keyword/dyn-angle-brackets.rs | 21 ++++ tests/ui/dyn-keyword/dyn-angle-brackets.stderr | 20 ++++ .../issue-56327-dyn-trait-in-macro-is-okay.rs | 27 +++++ 14 files changed, 681 insertions(+) create mode 100644 tests/ui/dyn-keyword/dyn-2015-edition-keyword-ident-lint.fixed create mode 100644 tests/ui/dyn-keyword/dyn-2015-edition-keyword-ident-lint.rs create mode 100644 tests/ui/dyn-keyword/dyn-2015-edition-keyword-ident-lint.stderr create mode 100644 tests/ui/dyn-keyword/dyn-2015-idents-in-decl-macros-unlinted.rs create mode 100644 tests/ui/dyn-keyword/dyn-2015-idents-in-macros-unlinted.rs create mode 100644 tests/ui/dyn-keyword/dyn-2015-no-warnings-without-lints.rs create mode 100644 tests/ui/dyn-keyword/dyn-2018-edition-lint.rs create mode 100644 tests/ui/dyn-keyword/dyn-2018-edition-lint.stderr create mode 100644 tests/ui/dyn-keyword/dyn-2021-edition-error.rs create mode 100644 tests/ui/dyn-keyword/dyn-2021-edition-error.stderr create mode 100644 tests/ui/dyn-keyword/dyn-angle-brackets.fixed create mode 100644 tests/ui/dyn-keyword/dyn-angle-brackets.rs create mode 100644 tests/ui/dyn-keyword/dyn-angle-brackets.stderr create mode 100644 tests/ui/dyn-keyword/issue-56327-dyn-trait-in-macro-is-okay.rs (limited to 'tests/ui/dyn-keyword') diff --git a/tests/ui/dyn-keyword/dyn-2015-edition-keyword-ident-lint.fixed b/tests/ui/dyn-keyword/dyn-2015-edition-keyword-ident-lint.fixed new file mode 100644 index 000000000..c815080fc --- /dev/null +++ b/tests/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, 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/tests/ui/dyn-keyword/dyn-2015-edition-keyword-ident-lint.rs b/tests/ui/dyn-keyword/dyn-2015-edition-keyword-ident-lint.rs new file mode 100644 index 000000000..6cdc70714 --- /dev/null +++ b/tests/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, 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/tests/ui/dyn-keyword/dyn-2015-edition-keyword-ident-lint.stderr b/tests/ui/dyn-keyword/dyn-2015-edition-keyword-ident-lint.stderr new file mode 100644 index 000000000..89aded913 --- /dev/null +++ b/tests/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` + | + = 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 +note: the lint level is defined here + --> $DIR/dyn-2015-edition-keyword-ident-lint.rs:11:9 + | +LL | #![deny(keyword_idents)] + | ^^^^^^^^^^^^^^ + +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 + +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 + +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 + +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 + +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 + +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 + +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 + +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 + +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 + +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 + +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 + +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 + +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 + +error: aborting due to 14 previous errors + diff --git a/tests/ui/dyn-keyword/dyn-2015-idents-in-decl-macros-unlinted.rs b/tests/ui/dyn-keyword/dyn-2015-idents-in-decl-macros-unlinted.rs new file mode 100644 index 000000000..bda2ed17e --- /dev/null +++ b/tests/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/tests/ui/dyn-keyword/dyn-2015-idents-in-macros-unlinted.rs b/tests/ui/dyn-keyword/dyn-2015-idents-in-macros-unlinted.rs new file mode 100644 index 000000000..472f6b5c8 --- /dev/null +++ b/tests/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/tests/ui/dyn-keyword/dyn-2015-no-warnings-without-lints.rs b/tests/ui/dyn-keyword/dyn-2015-no-warnings-without-lints.rs new file mode 100644 index 000000000..d6a33c08d --- /dev/null +++ b/tests/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/tests/ui/dyn-keyword/dyn-2018-edition-lint.rs b/tests/ui/dyn-keyword/dyn-2018-edition-lint.rs new file mode 100644 index 000000000..a074b5fa5 --- /dev/null +++ b/tests/ui/dyn-keyword/dyn-2018-edition-lint.rs @@ -0,0 +1,24 @@ +// edition:2018 +#[deny(bare_trait_objects)] + +fn function(x: &SomeTrait, y: Box) { + //~^ 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/tests/ui/dyn-keyword/dyn-2018-edition-lint.stderr b/tests/ui/dyn-keyword/dyn-2018-edition-lint.stderr new file mode 100644 index 000000000..6bafff919 --- /dev/null +++ b/tests/ui/dyn-keyword/dyn-2018-edition-lint.stderr @@ -0,0 +1,98 @@ +error: trait objects without an explicit `dyn` are deprecated + --> $DIR/dyn-2018-edition-lint.rs:4:17 + | +LL | fn function(x: &SomeTrait, y: Box) { + | ^^^^^^^^^ + | + = warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021! + = note: for more information, see +note: the lint level is defined here + --> $DIR/dyn-2018-edition-lint.rs:2:8 + | +LL | #[deny(bare_trait_objects)] + | ^^^^^^^^^^^^^^^^^^ +help: use `dyn` + | +LL | fn function(x: &dyn SomeTrait, y: Box) { + | +++ + +error: trait objects without an explicit `dyn` are deprecated + --> $DIR/dyn-2018-edition-lint.rs:4:35 + | +LL | fn function(x: &SomeTrait, y: Box) { + | ^^^^^^^^^ + | + = warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021! + = note: for more information, see +help: use `dyn` + | +LL | fn function(x: &SomeTrait, y: Box) { + | +++ + +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 +help: use `dyn` + | +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) { + | ^^^^^^^^^ + | + = warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021! + = note: for more information, see +help: use `dyn` + | +LL | fn function(x: &dyn SomeTrait, y: Box) { + | +++ + +error: trait objects without an explicit `dyn` are deprecated + --> $DIR/dyn-2018-edition-lint.rs:4:17 + | +LL | fn function(x: &SomeTrait, y: Box) { + | ^^^^^^^^^ + | + = warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021! + = note: for more information, see +help: use `dyn` + | +LL | fn function(x: &dyn SomeTrait, y: Box) { + | +++ + +error: trait objects without an explicit `dyn` are deprecated + --> $DIR/dyn-2018-edition-lint.rs:4:35 + | +LL | fn function(x: &SomeTrait, y: Box) { + | ^^^^^^^^^ + | + = warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021! + = note: for more information, see +help: use `dyn` + | +LL | fn function(x: &SomeTrait, y: Box) { + | +++ + +error: trait objects without an explicit `dyn` are deprecated + --> $DIR/dyn-2018-edition-lint.rs:4:35 + | +LL | fn function(x: &SomeTrait, y: Box) { + | ^^^^^^^^^ + | + = warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021! + = note: for more information, see +help: use `dyn` + | +LL | fn function(x: &SomeTrait, y: Box) { + | +++ + +error: aborting due to 7 previous errors + diff --git a/tests/ui/dyn-keyword/dyn-2021-edition-error.rs b/tests/ui/dyn-keyword/dyn-2021-edition-error.rs new file mode 100644 index 000000000..0f05d8753 --- /dev/null +++ b/tests/ui/dyn-keyword/dyn-2021-edition-error.rs @@ -0,0 +1,11 @@ +// edition:2021 + +fn function(x: &SomeTrait, y: Box) { + //~^ 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/tests/ui/dyn-keyword/dyn-2021-edition-error.stderr b/tests/ui/dyn-keyword/dyn-2021-edition-error.stderr new file mode 100644 index 000000000..08ee77116 --- /dev/null +++ b/tests/ui/dyn-keyword/dyn-2021-edition-error.stderr @@ -0,0 +1,25 @@ +error[E0782]: trait objects must include the `dyn` keyword + --> $DIR/dyn-2021-edition-error.rs:3:17 + | +LL | fn function(x: &SomeTrait, y: Box) { + | ^^^^^^^^^ + | +help: add `dyn` keyword before this trait + | +LL | fn function(x: &dyn SomeTrait, y: Box) { + | +++ + +error[E0782]: trait objects must include the `dyn` keyword + --> $DIR/dyn-2021-edition-error.rs:3:35 + | +LL | fn function(x: &SomeTrait, y: Box) { + | ^^^^^^^^^ + | +help: add `dyn` keyword before this trait + | +LL | fn function(x: &SomeTrait, y: Box) { + | +++ + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0782`. diff --git a/tests/ui/dyn-keyword/dyn-angle-brackets.fixed b/tests/ui/dyn-keyword/dyn-angle-brackets.fixed new file mode 100644 index 000000000..00069a3e7 --- /dev/null +++ b/tests/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 { + ::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/tests/ui/dyn-keyword/dyn-angle-brackets.rs b/tests/ui/dyn-keyword/dyn-angle-brackets.rs new file mode 100644 index 000000000..ee5fee4cf --- /dev/null +++ b/tests/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(self, f) + //~^ ERROR trait objects without an explicit `dyn` are deprecated + //~| WARNING this is accepted in the current edition + } +} + +fn main() {} diff --git a/tests/ui/dyn-keyword/dyn-angle-brackets.stderr b/tests/ui/dyn-keyword/dyn-angle-brackets.stderr new file mode 100644 index 000000000..0bb764d71 --- /dev/null +++ b/tests/ui/dyn-keyword/dyn-angle-brackets.stderr @@ -0,0 +1,20 @@ +error: trait objects without an explicit `dyn` are deprecated + --> $DIR/dyn-angle-brackets.rs:15:10 + | +LL | ::fmt(self, f) + | ^^^^^^^^^^ + | + = warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021! + = note: for more information, see +note: the lint level is defined here + --> $DIR/dyn-angle-brackets.rs:4:9 + | +LL | #![deny(bare_trait_objects)] + | ^^^^^^^^^^^^^^^^^^ +help: use `dyn` + | +LL | ::fmt(self, f) + | +++ + +error: aborting due to previous error + diff --git a/tests/ui/dyn-keyword/issue-56327-dyn-trait-in-macro-is-okay.rs b/tests/ui/dyn-keyword/issue-56327-dyn-trait-in-macro-is-okay.rs new file mode 100644 index 000000000..59e7f9a60 --- /dev/null +++ b/tests/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` with +// `Box`, 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; + } + } +} + +foo!(); + +fn main() { + generated_foo(); +} -- cgit v1.2.3