Skip to content

Commit

Permalink
Be less confident when dyn suggestion is not checked for object safety
Browse files Browse the repository at this point in the history
  • Loading branch information
trevyn committed Jan 31, 2024
1 parent 5ad7454 commit 8d31a53
Show file tree
Hide file tree
Showing 27 changed files with 211 additions and 64 deletions.
4 changes: 2 additions & 2 deletions compiler/rustc_hir_analysis/src/astconv/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,9 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
tcx.node_span_lint(BARE_TRAIT_OBJECTS, self_ty.hir_id, self_ty.span, msg, |lint| {
if self_ty.span.can_be_used_for_suggestions() {
lint.multipart_suggestion_verbose(
"use `dyn`",
"if this is an object-safe trait, use `dyn`",
sugg,
Applicability::MachineApplicable,
Applicability::MaybeIncorrect,
);
}
self.maybe_lint_blanket_trait_impl(self_ty, lint);
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/did_you_mean/bad-assoc-ty.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ LL | type H = Fn(u8) -> (u8)::Output;
= warning: this is accepted in the current edition (Rust 2015) 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>
= note: `#[warn(bare_trait_objects)]` on by default
help: use `dyn`
help: if this is an object-safe trait, use `dyn`
|
LL | type H = <dyn Fn(u8) -> (u8)>::Output;
| ++++ +
Expand Down
14 changes: 7 additions & 7 deletions tests/ui/dyn-keyword/dyn-2018-edition-lint.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ note: the lint level is defined here
|
LL | #[deny(bare_trait_objects)]
| ^^^^^^^^^^^^^^^^^^
help: use `dyn`
help: if this is an object-safe trait, use `dyn`
|
LL | fn function(x: &dyn SomeTrait, y: Box<SomeTrait>) {
| +++
Expand All @@ -24,7 +24,7 @@ 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`
help: if this is an object-safe trait, use `dyn`
|
LL | fn function(x: &SomeTrait, y: Box<dyn SomeTrait>) {
| +++
Expand All @@ -37,7 +37,7 @@ 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`
help: if this is an object-safe trait, use `dyn`
|
LL | let _x: &dyn SomeTrait = todo!();
| +++
Expand All @@ -51,7 +51,7 @@ 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>
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
help: use `dyn`
help: if this is an object-safe trait, use `dyn`
|
LL | fn function(x: &dyn SomeTrait, y: Box<SomeTrait>) {
| +++
Expand All @@ -65,7 +65,7 @@ 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>
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
help: use `dyn`
help: if this is an object-safe trait, use `dyn`
|
LL | fn function(x: &dyn SomeTrait, y: Box<SomeTrait>) {
| +++
Expand All @@ -79,7 +79,7 @@ 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>
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
help: use `dyn`
help: if this is an object-safe trait, use `dyn`
|
LL | fn function(x: &SomeTrait, y: Box<dyn SomeTrait>) {
| +++
Expand All @@ -93,7 +93,7 @@ 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>
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
help: use `dyn`
help: if this is an object-safe trait, use `dyn`
|
LL | fn function(x: &SomeTrait, y: Box<dyn SomeTrait>) {
| +++
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/dyn-keyword/dyn-angle-brackets.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ note: the lint level is defined here
|
LL | #![deny(bare_trait_objects)]
| ^^^^^^^^^^^^^^^^^^
help: use `dyn`
help: if this is an object-safe trait, use `dyn`
|
LL | <dyn fmt::Debug>::fmt(self, f)
| +++
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ LL | fn ice() -> impl AsRef<Fn(&())> {
= warning: this is accepted in the current edition (Rust 2015) 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>
= note: `#[warn(bare_trait_objects)]` on by default
help: use `dyn`
help: if this is an object-safe trait, use `dyn`
|
LL | fn ice() -> impl AsRef<dyn Fn(&())> {
| +++
Expand All @@ -21,7 +21,7 @@ LL | fn ice() -> impl AsRef<Fn(&())> {
= warning: this is accepted in the current edition (Rust 2015) 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>
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
help: use `dyn`
help: if this is an object-safe trait, use `dyn`
|
LL | fn ice() -> impl AsRef<dyn Fn(&())> {
| +++
Expand All @@ -35,7 +35,7 @@ LL | fn ice() -> impl AsRef<Fn(&())> {
= warning: this is accepted in the current edition (Rust 2015) 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>
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
help: use `dyn`
help: if this is an object-safe trait, use `dyn`
|
LL | fn ice() -> impl AsRef<dyn Fn(&())> {
| +++
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/issues/issue-28344.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ LL | let x: u8 = BitXor::bitor(0 as u8, 0 as u8);
= warning: this is accepted in the current edition (Rust 2015) 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>
= note: `#[warn(bare_trait_objects)]` on by default
help: use `dyn`
help: if this is an object-safe trait, use `dyn`
|
LL | let x: u8 = <dyn BitXor>::bitor(0 as u8, 0 as u8);
| ++++ +
Expand Down Expand Up @@ -35,7 +35,7 @@ LL | let g = BitXor::bitor;
|
= warning: this is accepted in the current edition (Rust 2015) 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`
help: if this is an object-safe trait, use `dyn`
|
LL | let g = <dyn BitXor>::bitor;
| ++++ +
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/issues/issue-58734.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ LL | Trait::nonexistent(());
= warning: this is accepted in the current edition (Rust 2015) 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>
= note: `#[warn(bare_trait_objects)]` on by default
help: use `dyn`
help: if this is an object-safe trait, use `dyn`
|
LL | <dyn Trait>::nonexistent(());
| ++++ +
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/issues/issue-86756.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ LL | eq::<dyn, Foo>
= warning: this is accepted in the current edition (Rust 2015) 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>
= note: `#[warn(bare_trait_objects)]` on by default
help: use `dyn`
help: if this is an object-safe trait, use `dyn`
|
LL | eq::<dyn, dyn Foo>
| +++
Expand Down
8 changes: 4 additions & 4 deletions tests/ui/lint/bare-trait-objects-path.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ LL | let _: Dyn::Ty;
= warning: this is accepted in the current edition (Rust 2015) 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>
= note: `#[warn(bare_trait_objects)]` on by default
help: use `dyn`
help: if this is an object-safe trait, use `dyn`
|
LL | let _: <dyn Dyn>::Ty;
| ++++ +
Expand All @@ -26,7 +26,7 @@ LL | Dyn::func();
|
= warning: this is accepted in the current edition (Rust 2015) 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`
help: if this is an object-safe trait, use `dyn`
|
LL | <dyn Dyn>::func();
| ++++ +
Expand All @@ -39,7 +39,7 @@ LL | ::Dyn::func();
|
= warning: this is accepted in the current edition (Rust 2015) 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`
help: if this is an object-safe trait, use `dyn`
|
LL | <dyn (::Dyn)>::func();
| ++++++ ++
Expand All @@ -52,7 +52,7 @@ LL | Dyn::CONST;
|
= warning: this is accepted in the current edition (Rust 2015) 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`
help: if this is an object-safe trait, use `dyn`
|
LL | <dyn Dyn>::CONST;
| ++++ +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ LL | pub fn function(_x: Box<SomeTrait>) {}
= warning: this is accepted in the current edition (Rust 2015) 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>
= note: requested on the command line with `--force-warn bare-trait-objects`
help: use `dyn`
help: if this is an object-safe trait, use `dyn`
|
LL | pub fn function(_x: Box<dyn SomeTrait>) {}
| +++
Expand All @@ -21,7 +21,7 @@ LL | pub fn function(_x: Box<SomeTrait>) {}
= warning: this is accepted in the current edition (Rust 2015) 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>
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
help: use `dyn`
help: if this is an object-safe trait, use `dyn`
|
LL | pub fn function(_x: Box<dyn SomeTrait>) {}
| +++
Expand All @@ -35,7 +35,7 @@ LL | pub fn function(_x: Box<SomeTrait>) {}
= warning: this is accepted in the current edition (Rust 2015) 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>
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
help: use `dyn`
help: if this is an object-safe trait, use `dyn`
|
LL | pub fn function(_x: Box<dyn SomeTrait>) {}
| +++
Expand Down
6 changes: 3 additions & 3 deletions tests/ui/lint/force-warn/cap-lints-allow.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ LL | pub fn function(_x: Box<SomeTrait>) {}
= warning: this is accepted in the current edition (Rust 2015) 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>
= note: requested on the command line with `--force-warn bare-trait-objects`
help: use `dyn`
help: if this is an object-safe trait, use `dyn`
|
LL | pub fn function(_x: Box<dyn SomeTrait>) {}
| +++
Expand All @@ -21,7 +21,7 @@ LL | pub fn function(_x: Box<SomeTrait>) {}
= warning: this is accepted in the current edition (Rust 2015) 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>
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
help: use `dyn`
help: if this is an object-safe trait, use `dyn`
|
LL | pub fn function(_x: Box<dyn SomeTrait>) {}
| +++
Expand All @@ -35,7 +35,7 @@ LL | pub fn function(_x: Box<SomeTrait>) {}
= warning: this is accepted in the current edition (Rust 2015) 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>
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
help: use `dyn`
help: if this is an object-safe trait, use `dyn`
|
LL | pub fn function(_x: Box<dyn SomeTrait>) {}
| +++
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ LL | pub fn function(_x: Box<SomeTrait>) {}
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
= note: `--force-warn bare-trait-objects` implied by `--force-warn rust-2018-idioms`
= help: to override `--force-warn rust-2018-idioms` add `#[allow(bare_trait_objects)]`
help: use `dyn`
help: if this is an object-safe trait, use `dyn`
|
LL | pub fn function(_x: Box<dyn SomeTrait>) {}
| +++
Expand All @@ -22,7 +22,7 @@ LL | pub fn function(_x: Box<SomeTrait>) {}
= warning: this is accepted in the current edition (Rust 2015) 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>
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
help: use `dyn`
help: if this is an object-safe trait, use `dyn`
|
LL | pub fn function(_x: Box<dyn SomeTrait>) {}
| +++
Expand All @@ -36,7 +36,7 @@ LL | pub fn function(_x: Box<SomeTrait>) {}
= warning: this is accepted in the current edition (Rust 2015) 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>
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
help: use `dyn`
help: if this is an object-safe trait, use `dyn`
|
LL | pub fn function(_x: Box<dyn SomeTrait>) {}
| +++
Expand Down
6 changes: 3 additions & 3 deletions tests/ui/lint/force-warn/lint-group-allowed-lint-group.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ LL | pub fn function(_x: Box<SomeTrait>) {}
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
= note: `--force-warn bare-trait-objects` implied by `--force-warn rust-2018-idioms`
= help: to override `--force-warn rust-2018-idioms` add `#[allow(bare_trait_objects)]`
help: use `dyn`
help: if this is an object-safe trait, use `dyn`
|
LL | pub fn function(_x: Box<dyn SomeTrait>) {}
| +++
Expand All @@ -22,7 +22,7 @@ LL | pub fn function(_x: Box<SomeTrait>) {}
= warning: this is accepted in the current edition (Rust 2015) 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>
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
help: use `dyn`
help: if this is an object-safe trait, use `dyn`
|
LL | pub fn function(_x: Box<dyn SomeTrait>) {}
| +++
Expand All @@ -36,7 +36,7 @@ LL | pub fn function(_x: Box<SomeTrait>) {}
= warning: this is accepted in the current edition (Rust 2015) 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>
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
help: use `dyn`
help: if this is an object-safe trait, use `dyn`
|
LL | pub fn function(_x: Box<dyn SomeTrait>) {}
| +++
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ LL | pub fn function(_x: Box<SomeTrait>) {}
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
= note: `--force-warn bare-trait-objects` implied by `--force-warn rust-2018-idioms`
= help: to override `--force-warn rust-2018-idioms` add `#[allow(bare_trait_objects)]`
help: use `dyn`
help: if this is an object-safe trait, use `dyn`
|
LL | pub fn function(_x: Box<dyn SomeTrait>) {}
| +++
Expand All @@ -22,7 +22,7 @@ LL | pub fn function(_x: Box<SomeTrait>) {}
= warning: this is accepted in the current edition (Rust 2015) 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>
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
help: use `dyn`
help: if this is an object-safe trait, use `dyn`
|
LL | pub fn function(_x: Box<dyn SomeTrait>) {}
| +++
Expand All @@ -36,7 +36,7 @@ LL | pub fn function(_x: Box<SomeTrait>) {}
= warning: this is accepted in the current edition (Rust 2015) 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>
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
help: use `dyn`
help: if this is an object-safe trait, use `dyn`
|
LL | pub fn function(_x: Box<dyn SomeTrait>) {}
| +++
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/object-safety/avoid-ice-on-warning-2.old.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ LL | fn id<F>(f: Copy) -> usize {
= warning: this is accepted in the current edition (Rust 2015) 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>
= note: `#[warn(bare_trait_objects)]` on by default
help: use `dyn`
help: if this is an object-safe trait, use `dyn`
|
LL | fn id<F>(f: dyn Copy) -> usize {
| +++
Expand All @@ -21,7 +21,7 @@ LL | fn id<F>(f: Copy) -> usize {
= warning: this is accepted in the current edition (Rust 2015) 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>
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
help: use `dyn`
help: if this is an object-safe trait, use `dyn`
|
LL | fn id<F>(f: dyn Copy) -> usize {
| +++
Expand Down
Loading

0 comments on commit 8d31a53

Please sign in to comment.