Skip to content

Update BARE_TRAIT_OBJECTS lint to deny in 2021 edition #81244

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion compiler/rustc_lint_defs/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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! {
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_lint_defs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
};
);
}
Expand Down
11 changes: 11 additions & 0 deletions src/test/ui/dyn-keyword/dyn-2021-edition-error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// edition:2021
fn function(x: &SomeTrait, y: Box<SomeTrait>) {
//~^ 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() {}
22 changes: 22 additions & 0 deletions src/test/ui/dyn-keyword/dyn-2021-edition-error.stderr
Original file line number Diff line number Diff line change
@@ -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<SomeTrait>) {
| ^^^^^^^^^ 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<SomeTrait>) {
| ^^^^^^^^^ 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