From 81abfe3913fa3aac1d052b93d26f6a8f642d0ac0 Mon Sep 17 00:00:00 2001 From: Vincenzo Palazzo Date: Sun, 15 May 2022 01:28:10 +0200 Subject: add blanket impl suggestion to the local traits Signed-off-by: Vincenzo Palazzo --- compiler/rustc_typeck/src/astconv/mod.rs | 68 +++++++++++++++++++++++++++----- 1 file changed, 58 insertions(+), 10 deletions(-) diff --git a/compiler/rustc_typeck/src/astconv/mod.rs b/compiler/rustc_typeck/src/astconv/mod.rs index eec3b24aec2..6ef4122a644 100644 --- a/compiler/rustc_typeck/src/astconv/mod.rs +++ b/compiler/rustc_typeck/src/astconv/mod.rs @@ -2986,6 +2986,51 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { Some(r) } + /// make sure that we are in the condition to suggest the blanket implementation, if we are in the + /// case of suggest it, use the function `err_reporter` to report the error or suggestion. + fn maybe_lint_blanket_trait_impl( + &self, + self_ty: &hir::Ty<'_>, + diagnostic: &mut DiagnosticBuilder<'_, T>, + ) { + let tcx = self.tcx(); + let parent_id = tcx.hir().get_parent_item(self_ty.hir_id); + if let hir::Node::Item(hir::Item { + kind: + hir::ItemKind::Impl(hir::Impl { + self_ty: impl_self_typ, of_trait: Some(trait_ref), generics, .. + }), + .. + }) = tcx.hir().get_by_def_id(parent_id) && self_ty.hir_id == impl_self_typ.hir_id + { + let trait_span = trait_ref.path.span; + let target_span = if let Some(span) = generics.span_for_param_suggestion() { + span + } else { + trait_span + }; + let is_local = trait_ref.trait_def_id().map_or(false, |def_id| def_id.is_local()); + if is_local { + let trait_name = tcx.sess.source_map().span_to_snippet(trait_span).unwrap(); + let self_name = tcx.sess.source_map().span_to_snippet(self_ty.span).unwrap(); + let blanket_msg = format!( + "use a blanket implementation to implement {} for all types that also implement {}", + trait_name, self_name + ); + let blanket_sugg = vec![ + (target_span, "", self_name)), + (self_ty.span, "T".to_owned()), + ]; + diagnostic.multipart_suggestion( + blanket_msg, + blanket_sugg, + Applicability::Unspecified, + ); + } + } + } + fn maybe_lint_bare_trait(&self, self_ty: &hir::Ty<'_>, in_path: bool) { let tcx = self.tcx(); if let hir::TyKind::TraitObject([poly_trait_ref, ..], _, TraitObjectSyntax::None) = @@ -3021,9 +3066,11 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { if self_ty.span.edition() >= Edition::Edition2021 { let msg = "trait objects must include the `dyn` keyword"; let label = "add `dyn` keyword before this trait"; - rustc_errors::struct_span_err!(tcx.sess, self_ty.span, E0782, "{}", msg) - .multipart_suggestion_verbose(label, sugg, Applicability::MachineApplicable) - .emit(); + let mut diag = + rustc_errors::struct_span_err!(tcx.sess, self_ty.span, E0782, "{}", msg); + diag.multipart_suggestion_verbose(label, sugg, Applicability::MachineApplicable); + self.maybe_lint_blanket_trait_impl(&self_ty, &mut diag); + diag.emit(); } else { let msg = "trait objects without an explicit `dyn` are deprecated"; tcx.struct_span_lint_hir( @@ -3031,13 +3078,14 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { self_ty.hir_id, self_ty.span, |lint| { - lint.build(msg) - .multipart_suggestion_verbose( - "use `dyn`", - sugg, - Applicability::MachineApplicable, - ) - .emit(); + let mut diag = lint.build(msg); + diag.multipart_suggestion_verbose( + "use `dyn`", + sugg, + Applicability::MachineApplicable, + ); + self.maybe_lint_blanket_trait_impl::<()>(&self_ty, &mut diag); + diag.emit(); }, ); } -- cgit 1.4.1-3-g733a5 From 86c1a734f5b915685560baeebac9b773d7108ccf Mon Sep 17 00:00:00 2001 From: Vincenzo Palazzo Date: Wed, 22 Jun 2022 23:06:34 +0100 Subject: ui test: add test of blanklet implementation Signed-off-by: Vincenzo Palazzo --- compiler/rustc_typeck/src/astconv/mod.rs | 75 +++++++++------- .../suggest-blanket-impl-local-trait.rs | 44 ++++++++++ .../suggest-blanket-impl-local-trait.stderr | 99 ++++++++++++++++++++++ 3 files changed, 187 insertions(+), 31 deletions(-) create mode 100644 src/test/ui/suggestions/suggest-blanket-impl-local-trait.rs create mode 100644 src/test/ui/suggestions/suggest-blanket-impl-local-trait.stderr diff --git a/compiler/rustc_typeck/src/astconv/mod.rs b/compiler/rustc_typeck/src/astconv/mod.rs index 6ef4122a644..0347e7fc416 100644 --- a/compiler/rustc_typeck/src/astconv/mod.rs +++ b/compiler/rustc_typeck/src/astconv/mod.rs @@ -38,7 +38,9 @@ use rustc_span::{Span, DUMMY_SP}; use rustc_target::spec::abi; use rustc_trait_selection::traits; use rustc_trait_selection::traits::astconv_object_safety_violations; -use rustc_trait_selection::traits::error_reporting::report_object_safety_error; +use rustc_trait_selection::traits::error_reporting::{ + report_object_safety_error, suggestions::NextTypeParamName, +}; use rustc_trait_selection::traits::wf::object_region_bounds; use smallvec::SmallVec; @@ -2986,48 +2988,48 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { Some(r) } - /// make sure that we are in the condition to suggest the blanket implementation, if we are in the - /// case of suggest it, use the function `err_reporter` to report the error or suggestion. + /// Make sure that we are in the condition to suggest the blanket implementation. fn maybe_lint_blanket_trait_impl( &self, self_ty: &hir::Ty<'_>, - diagnostic: &mut DiagnosticBuilder<'_, T>, + diag: &mut DiagnosticBuilder<'_, T>, ) { let tcx = self.tcx(); let parent_id = tcx.hir().get_parent_item(self_ty.hir_id); if let hir::Node::Item(hir::Item { kind: hir::ItemKind::Impl(hir::Impl { - self_ty: impl_self_typ, of_trait: Some(trait_ref), generics, .. + self_ty: impl_self_ty, of_trait: Some(of_trait_ref), generics, .. }), .. - }) = tcx.hir().get_by_def_id(parent_id) && self_ty.hir_id == impl_self_typ.hir_id + }) = tcx.hir().get_by_def_id(parent_id) && self_ty.hir_id == impl_self_ty.hir_id { - let trait_span = trait_ref.path.span; - let target_span = if let Some(span) = generics.span_for_param_suggestion() { - span + if !of_trait_ref.trait_def_id().map_or(false, |def_id| def_id.is_local()) { + return; + } + let of_trait_span = of_trait_ref.path.span; + // make sure that we are not calling unwrap to abort during the compilation + let Ok(impl_trait_name) = tcx.sess.source_map().span_to_snippet(self_ty.span) else { return; }; + let Ok(of_trait_name) = tcx.sess.source_map().span_to_snippet(of_trait_span) else { return; }; + // check if the trait has generics, to make a correct suggestion + let param_name = generics.params.next_type_param_name(None); + + let add_generic_sugg = if let Some(span) = generics.span_for_param_suggestion() { + let param_name = generics.params.next_type_param_name(Some(&impl_trait_name)); + (span, format!(", {}: {}", param_name, impl_trait_name)) } else { - trait_span + (generics.span, format!("<{}: {}>", param_name, impl_trait_name)) }; - let is_local = trait_ref.trait_def_id().map_or(false, |def_id| def_id.is_local()); - if is_local { - let trait_name = tcx.sess.source_map().span_to_snippet(trait_span).unwrap(); - let self_name = tcx.sess.source_map().span_to_snippet(self_ty.span).unwrap(); - let blanket_msg = format!( - "use a blanket implementation to implement {} for all types that also implement {}", - trait_name, self_name - ); - let blanket_sugg = vec![ - (target_span, "", self_name)), - (self_ty.span, "T".to_owned()), - ]; - diagnostic.multipart_suggestion( - blanket_msg, - blanket_sugg, - Applicability::Unspecified, - ); - } + diag.multipart_suggestion( + format!("alternatively use a blanket \ + implementation to implement `{of_trait_name}` for \ + all types that also implement `{impl_trait_name}`"), + vec![ + (self_ty.span, param_name), + add_generic_sugg, + ], + Applicability::MaybeIncorrect, + ); } } @@ -3045,6 +3047,11 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { .map_or(false, |s| s.trim_end().ends_with('<')); let is_global = poly_trait_ref.trait_ref.path.is_global(); + let is_local = if let Some(def_id) = poly_trait_ref.trait_ref.trait_def_id() { + def_id.is_local() + } else { + false + }; let sugg = Vec::from_iter([ ( self_ty.span.shrink_to_lo(), @@ -3069,7 +3076,10 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { let mut diag = rustc_errors::struct_span_err!(tcx.sess, self_ty.span, E0782, "{}", msg); diag.multipart_suggestion_verbose(label, sugg, Applicability::MachineApplicable); - self.maybe_lint_blanket_trait_impl(&self_ty, &mut diag); + // check if the impl trait that we are considering is a impl of a local trait + if is_local { + self.maybe_lint_blanket_trait_impl(&self_ty, &mut diag); + } diag.emit(); } else { let msg = "trait objects without an explicit `dyn` are deprecated"; @@ -3084,7 +3094,10 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { sugg, Applicability::MachineApplicable, ); - self.maybe_lint_blanket_trait_impl::<()>(&self_ty, &mut diag); + // check if the impl trait that we are considering is a impl of a local trait + if is_local { + self.maybe_lint_blanket_trait_impl::<()>(&self_ty, &mut diag); + } diag.emit(); }, ); diff --git a/src/test/ui/suggestions/suggest-blanket-impl-local-trait.rs b/src/test/ui/suggestions/suggest-blanket-impl-local-trait.rs new file mode 100644 index 00000000000..61798c61cd0 --- /dev/null +++ b/src/test/ui/suggestions/suggest-blanket-impl-local-trait.rs @@ -0,0 +1,44 @@ +// Ensure that the compiler include the blanklet implementation suggestion +// when inside a `impl` statment are used two local traits. +// +// edition:2021 +use std::fmt; + +trait LocalTraitOne { } + +trait LocalTraitTwo { } + +trait GenericTrait {} + +impl LocalTraitTwo for LocalTraitOne {} +//~^ ERROR trait objects must include the `dyn` keyword + +impl fmt::Display for LocalTraitOne { +//~^ ERROR trait objects must include the `dyn` keyword + fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result { + todo!(); + } +} + +impl fmt::Display for LocalTraitTwo + Send { +//~^ ERROR trait objects must include the `dyn` keyword + fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result { + todo!(); + } +} + +impl LocalTraitOne for fmt::Display {} +//~^ ERROR trait objects must include the `dyn` keyword + +impl LocalTraitOne for fmt::Display + Send {} +//~^ ERROR trait objects must include the `dyn` keyword + +impl GenericTrait for LocalTraitOne {} +//~^ ERROR trait objects must include the `dyn` keyword + +trait GenericTraitTwo {} + +impl GenericTraitTwo for GenericTrait {} +//~^ ERROR trait objects must include the `dyn` keyword + +fn main() {} diff --git a/src/test/ui/suggestions/suggest-blanket-impl-local-trait.stderr b/src/test/ui/suggestions/suggest-blanket-impl-local-trait.stderr new file mode 100644 index 00000000000..014d9dd2232 --- /dev/null +++ b/src/test/ui/suggestions/suggest-blanket-impl-local-trait.stderr @@ -0,0 +1,99 @@ +error[E0782]: trait objects must include the `dyn` keyword + --> $DIR/suggest-blanket-impl-local-trait.rs:13:24 + | +LL | impl LocalTraitTwo for LocalTraitOne {} + | ^^^^^^^^^^^^^ + | +help: add `dyn` keyword before this trait + | +LL - impl LocalTraitTwo for LocalTraitOne {} +LL + impl LocalTraitTwo for dyn LocalTraitOne {} + | +help: alternatively use a blanket implementation to implement `LocalTraitTwo` for all types that also implement `LocalTraitOne` + | +LL | impl LocalTraitTwo for T {} + | ++++++++++++++++++ ~ + +error[E0782]: trait objects must include the `dyn` keyword + --> $DIR/suggest-blanket-impl-local-trait.rs:16:23 + | +LL | impl fmt::Display for LocalTraitOne { + | ^^^^^^^^^^^^^ + | +help: add `dyn` keyword before this trait + | +LL - impl fmt::Display for LocalTraitOne { +LL + impl fmt::Display for dyn LocalTraitOne { + | + +error[E0782]: trait objects must include the `dyn` keyword + --> $DIR/suggest-blanket-impl-local-trait.rs:23:23 + | +LL | impl fmt::Display for LocalTraitTwo + Send { + | ^^^^^^^^^^^^^^^^^^^^ + | +help: add `dyn` keyword before this trait + | +LL - impl fmt::Display for LocalTraitTwo + Send { +LL + impl fmt::Display for dyn LocalTraitTwo + Send { + | + +error[E0782]: trait objects must include the `dyn` keyword + --> $DIR/suggest-blanket-impl-local-trait.rs:30:24 + | +LL | impl LocalTraitOne for fmt::Display {} + | ^^^^^^^^^^^^ + | +help: add `dyn` keyword before this trait + | +LL - impl LocalTraitOne for fmt::Display {} +LL + impl LocalTraitOne for dyn fmt::Display {} + | + +error[E0782]: trait objects must include the `dyn` keyword + --> $DIR/suggest-blanket-impl-local-trait.rs:33:24 + | +LL | impl LocalTraitOne for fmt::Display + Send {} + | ^^^^^^^^^^^^^^^^^^^ + | +help: add `dyn` keyword before this trait + | +LL - impl LocalTraitOne for fmt::Display + Send {} +LL + impl LocalTraitOne for dyn fmt::Display + Send {} + | + +error[E0782]: trait objects must include the `dyn` keyword + --> $DIR/suggest-blanket-impl-local-trait.rs:36:29 + | +LL | impl GenericTrait for LocalTraitOne {} + | ^^^^^^^^^^^^^ + | +help: add `dyn` keyword before this trait + | +LL - impl GenericTrait for LocalTraitOne {} +LL + impl GenericTrait for dyn LocalTraitOne {} + | +help: alternatively use a blanket implementation to implement `GenericTrait` for all types that also implement `LocalTraitOne` + | +LL | impl GenericTrait for T {} + | ++++++++++++++++++ ~ + +error[E0782]: trait objects must include the `dyn` keyword + --> $DIR/suggest-blanket-impl-local-trait.rs:41:35 + | +LL | impl GenericTraitTwo for GenericTrait {} + | ^^^^^^^^^^^^^^^ + | +help: add `dyn` keyword before this trait + | +LL - impl GenericTraitTwo for GenericTrait {} +LL + impl GenericTraitTwo for dyn GenericTrait {} + | +help: alternatively use a blanket implementation to implement `GenericTraitTwo` for all types that also implement `GenericTrait` + | +LL | impl> GenericTraitTwo for U {} + | ++++++++++++++++++++ ~ + +error: aborting due to 7 previous errors + +For more information about this error, try `rustc --explain E0782`. -- cgit 1.4.1-3-g733a5 From 835b7a523a41cc89f0839f40652477af097db390 Mon Sep 17 00:00:00 2001 From: Vincenzo Palazzo Date: Wed, 29 Jun 2022 23:31:10 +0000 Subject: ui: improve suggestion test by addig the help message Signed-off-by: Vincenzo Palazzo --- compiler/rustc_typeck/src/astconv/mod.rs | 15 ++------ .../suggest-blanket-impl-local-trait.rs | 14 ++++++++ .../suggest-blanket-impl-local-trait.stderr | 38 +++++++++++++-------- suggest-blanket-impl-local-trait | Bin 0 -> 479160 bytes 4 files changed, 39 insertions(+), 28 deletions(-) create mode 100755 suggest-blanket-impl-local-trait diff --git a/compiler/rustc_typeck/src/astconv/mod.rs b/compiler/rustc_typeck/src/astconv/mod.rs index 0347e7fc416..37958cc0f40 100644 --- a/compiler/rustc_typeck/src/astconv/mod.rs +++ b/compiler/rustc_typeck/src/astconv/mod.rs @@ -3015,7 +3015,6 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { let param_name = generics.params.next_type_param_name(None); let add_generic_sugg = if let Some(span) = generics.span_for_param_suggestion() { - let param_name = generics.params.next_type_param_name(Some(&impl_trait_name)); (span, format!(", {}: {}", param_name, impl_trait_name)) } else { (generics.span, format!("<{}: {}>", param_name, impl_trait_name)) @@ -3047,11 +3046,6 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { .map_or(false, |s| s.trim_end().ends_with('<')); let is_global = poly_trait_ref.trait_ref.path.is_global(); - let is_local = if let Some(def_id) = poly_trait_ref.trait_ref.trait_def_id() { - def_id.is_local() - } else { - false - }; let sugg = Vec::from_iter([ ( self_ty.span.shrink_to_lo(), @@ -3077,9 +3071,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { rustc_errors::struct_span_err!(tcx.sess, self_ty.span, E0782, "{}", msg); diag.multipart_suggestion_verbose(label, sugg, Applicability::MachineApplicable); // check if the impl trait that we are considering is a impl of a local trait - if is_local { - self.maybe_lint_blanket_trait_impl(&self_ty, &mut diag); - } + self.maybe_lint_blanket_trait_impl(&self_ty, &mut diag); diag.emit(); } else { let msg = "trait objects without an explicit `dyn` are deprecated"; @@ -3094,10 +3086,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { sugg, Applicability::MachineApplicable, ); - // check if the impl trait that we are considering is a impl of a local trait - if is_local { - self.maybe_lint_blanket_trait_impl::<()>(&self_ty, &mut diag); - } + self.maybe_lint_blanket_trait_impl::<()>(&self_ty, &mut diag); diag.emit(); }, ); diff --git a/src/test/ui/suggestions/suggest-blanket-impl-local-trait.rs b/src/test/ui/suggestions/suggest-blanket-impl-local-trait.rs index 61798c61cd0..7cf536f7966 100644 --- a/src/test/ui/suggestions/suggest-blanket-impl-local-trait.rs +++ b/src/test/ui/suggestions/suggest-blanket-impl-local-trait.rs @@ -12,9 +12,12 @@ trait GenericTrait {} impl LocalTraitTwo for LocalTraitOne {} //~^ ERROR trait objects must include the `dyn` keyword +//~| HELP add `dyn` keyword before this trait +//~| HELP alternatively use a blanket implementation to implement `LocalTraitTwo` for all types that also implement `LocalTraitOne` impl fmt::Display for LocalTraitOne { //~^ ERROR trait objects must include the `dyn` keyword +//~| HELP add `dyn` keyword before this trait fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result { todo!(); } @@ -22,6 +25,7 @@ impl fmt::Display for LocalTraitOne { impl fmt::Display for LocalTraitTwo + Send { //~^ ERROR trait objects must include the `dyn` keyword +//~| HELP add `dyn` keyword before this trait fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result { todo!(); } @@ -29,16 +33,26 @@ impl fmt::Display for LocalTraitTwo + Send { impl LocalTraitOne for fmt::Display {} //~^ ERROR trait objects must include the `dyn` keyword +//~| HELP add `dyn` keyword before this trait +//~| HELP alternatively use a blanket implementation to implement `LocalTraitOne` for all types that also implement `fmt::Display` + impl LocalTraitOne for fmt::Display + Send {} //~^ ERROR trait objects must include the `dyn` keyword +//~| HELP add `dyn` keyword before this trait +//~| HELP alternatively use a blanket implementation to implement `LocalTraitOne` for all types that also implement `fmt::Display + Send` + impl GenericTrait for LocalTraitOne {} //~^ ERROR trait objects must include the `dyn` keyword +//~| HELP add `dyn` keyword before this trait +//~| HELP alternatively use a blanket implementation to implement `GenericTrait` for all types that also implement `LocalTraitOne` trait GenericTraitTwo {} impl GenericTraitTwo for GenericTrait {} //~^ ERROR trait objects must include the `dyn` keyword +//~| HELP add `dyn` keyword before this trait +//~| HELP alternatively use a blanket implementation to implement `GenericTraitTwo` for all types that also implement `GenericTrait` fn main() {} diff --git a/src/test/ui/suggestions/suggest-blanket-impl-local-trait.stderr b/src/test/ui/suggestions/suggest-blanket-impl-local-trait.stderr index 014d9dd2232..d739a8272f1 100644 --- a/src/test/ui/suggestions/suggest-blanket-impl-local-trait.stderr +++ b/src/test/ui/suggestions/suggest-blanket-impl-local-trait.stderr @@ -8,14 +8,14 @@ help: add `dyn` keyword before this trait | LL - impl LocalTraitTwo for LocalTraitOne {} LL + impl LocalTraitTwo for dyn LocalTraitOne {} - | + | help: alternatively use a blanket implementation to implement `LocalTraitTwo` for all types that also implement `LocalTraitOne` | LL | impl LocalTraitTwo for T {} | ++++++++++++++++++ ~ error[E0782]: trait objects must include the `dyn` keyword - --> $DIR/suggest-blanket-impl-local-trait.rs:16:23 + --> $DIR/suggest-blanket-impl-local-trait.rs:18:23 | LL | impl fmt::Display for LocalTraitOne { | ^^^^^^^^^^^^^ @@ -24,10 +24,10 @@ help: add `dyn` keyword before this trait | LL - impl fmt::Display for LocalTraitOne { LL + impl fmt::Display for dyn LocalTraitOne { - | + | error[E0782]: trait objects must include the `dyn` keyword - --> $DIR/suggest-blanket-impl-local-trait.rs:23:23 + --> $DIR/suggest-blanket-impl-local-trait.rs:26:23 | LL | impl fmt::Display for LocalTraitTwo + Send { | ^^^^^^^^^^^^^^^^^^^^ @@ -36,10 +36,10 @@ help: add `dyn` keyword before this trait | LL - impl fmt::Display for LocalTraitTwo + Send { LL + impl fmt::Display for dyn LocalTraitTwo + Send { - | + | error[E0782]: trait objects must include the `dyn` keyword - --> $DIR/suggest-blanket-impl-local-trait.rs:30:24 + --> $DIR/suggest-blanket-impl-local-trait.rs:34:24 | LL | impl LocalTraitOne for fmt::Display {} | ^^^^^^^^^^^^ @@ -48,10 +48,14 @@ help: add `dyn` keyword before this trait | LL - impl LocalTraitOne for fmt::Display {} LL + impl LocalTraitOne for dyn fmt::Display {} - | + | +help: alternatively use a blanket implementation to implement `LocalTraitOne` for all types that also implement `fmt::Display` + | +LL | impl LocalTraitOne for T {} + | +++++++++++++++++ ~ error[E0782]: trait objects must include the `dyn` keyword - --> $DIR/suggest-blanket-impl-local-trait.rs:33:24 + --> $DIR/suggest-blanket-impl-local-trait.rs:40:24 | LL | impl LocalTraitOne for fmt::Display + Send {} | ^^^^^^^^^^^^^^^^^^^ @@ -60,10 +64,14 @@ help: add `dyn` keyword before this trait | LL - impl LocalTraitOne for fmt::Display + Send {} LL + impl LocalTraitOne for dyn fmt::Display + Send {} - | + | +help: alternatively use a blanket implementation to implement `LocalTraitOne` for all types that also implement `fmt::Display + Send` + | +LL | impl LocalTraitOne for T {} + | ++++++++++++++++++++++++ ~ error[E0782]: trait objects must include the `dyn` keyword - --> $DIR/suggest-blanket-impl-local-trait.rs:36:29 + --> $DIR/suggest-blanket-impl-local-trait.rs:46:29 | LL | impl GenericTrait for LocalTraitOne {} | ^^^^^^^^^^^^^ @@ -72,14 +80,14 @@ help: add `dyn` keyword before this trait | LL - impl GenericTrait for LocalTraitOne {} LL + impl GenericTrait for dyn LocalTraitOne {} - | + | help: alternatively use a blanket implementation to implement `GenericTrait` for all types that also implement `LocalTraitOne` | -LL | impl GenericTrait for T {} +LL | impl GenericTrait for T {} | ++++++++++++++++++ ~ error[E0782]: trait objects must include the `dyn` keyword - --> $DIR/suggest-blanket-impl-local-trait.rs:41:35 + --> $DIR/suggest-blanket-impl-local-trait.rs:53:35 | LL | impl GenericTraitTwo for GenericTrait {} | ^^^^^^^^^^^^^^^ @@ -88,10 +96,10 @@ help: add `dyn` keyword before this trait | LL - impl GenericTraitTwo for GenericTrait {} LL + impl GenericTraitTwo for dyn GenericTrait {} - | + | help: alternatively use a blanket implementation to implement `GenericTraitTwo` for all types that also implement `GenericTrait` | -LL | impl> GenericTraitTwo for U {} +LL | impl> GenericTraitTwo for U {} | ++++++++++++++++++++ ~ error: aborting due to 7 previous errors diff --git a/suggest-blanket-impl-local-trait b/suggest-blanket-impl-local-trait new file mode 100755 index 00000000000..0a357e006c3 Binary files /dev/null and b/suggest-blanket-impl-local-trait differ -- cgit 1.4.1-3-g733a5