From 5d7eb5c34e4f91972801005be23b81b6dbf0b9c9 Mon Sep 17 00:00:00 2001 From: Ryan Levick Date: Thu, 21 Jan 2021 18:58:55 +0100 Subject: [PATCH] Update bare_trait_objects lint to error in 2021 edition --- compiler/rustc_lint_defs/src/builtin.rs | 3 ++- compiler/rustc_lint_defs/src/lib.rs | 1 + .../ui/dyn-keyword/dyn-2021-edition-error.rs | 11 ++++++++++ .../dyn-keyword/dyn-2021-edition-error.stderr | 22 +++++++++++++++++++ 4 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 src/test/ui/dyn-keyword/dyn-2021-edition-error.rs create mode 100644 src/test/ui/dyn-keyword/dyn-2021-edition-error.stderr diff --git a/compiler/rustc_lint_defs/src/builtin.rs b/compiler/rustc_lint_defs/src/builtin.rs index 20052ad9bfcbd..d1eb84cd0373f 100644 --- a/compiler/rustc_lint_defs/src/builtin.rs +++ b/compiler/rustc_lint_defs/src/builtin.rs @@ -1637,7 +1637,8 @@ declare_lint! { /// [`impl Trait`]: https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters pub BARE_TRAIT_OBJECTS, Warn, - "suggest using `dyn Trait` for trait objects" + "suggest using `dyn Trait` for trait objects", + Edition::Edition2021 => Deny } declare_lint! { diff --git a/compiler/rustc_lint_defs/src/lib.rs b/compiler/rustc_lint_defs/src/lib.rs index 9d60a51a0afb3..8f882097a48c0 100644 --- a/compiler/rustc_lint_defs/src/lib.rs +++ b/compiler/rustc_lint_defs/src/lib.rs @@ -426,6 +426,7 @@ macro_rules! declare_lint { edition_lint_opts: Some(($lint_edition, $crate::Level::$edition_level)), report_in_external_macro: false, is_plugin: false, + ..$crate::Lint::default_fields_for_macro() }; ); } 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 0000000000000..8ad9d40cade16 --- /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) { + //~^ ERROR trait objects without an explicit `dyn` are deprecated + //~| ERROR trait objects without an explicit `dyn` are deprecated + let _x: &SomeTrait = todo!(); + //~^ ERROR trait objects without an explicit `dyn` are deprecated +} + +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 0000000000000..448a906106192 --- /dev/null +++ b/src/test/ui/dyn-keyword/dyn-2021-edition-error.stderr @@ -0,0 +1,22 @@ +error: trait objects without an explicit `dyn` are deprecated + --> $DIR/dyn-2021-edition-error.rs:2:17 + | +LL | fn function(x: &SomeTrait, y: Box) { + | ^^^^^^^^^ help: use `dyn`: `dyn SomeTrait` + | + = note: `#[deny(bare_trait_objects)]` on by default + +error: trait objects without an explicit `dyn` are deprecated + --> $DIR/dyn-2021-edition-error.rs:2:35 + | +LL | fn function(x: &SomeTrait, y: Box) { + | ^^^^^^^^^ help: use `dyn`: `dyn SomeTrait` + +error: trait objects without an explicit `dyn` are deprecated + --> $DIR/dyn-2021-edition-error.rs:5:14 + | +LL | let _x: &SomeTrait = todo!(); + | ^^^^^^^^^ help: use `dyn`: `dyn SomeTrait` + +error: aborting due to 3 previous errors +