diff options
| author | Vincenzo Palazzo <vincenzopalazzodev@gmail.com> | 2022-06-29 23:31:10 +0000 |
|---|---|---|
| committer | Vincenzo Palazzo <vincenzopalazzodev@gmail.com> | 2022-06-30 18:59:36 +0000 |
| commit | 835b7a523a41cc89f0839f40652477af097db390 (patch) | |
| tree | 9b361a36248ceaffa2cd465d46f7b409419edaf9 | |
| parent | 86c1a734f5b915685560baeebac9b773d7108ccf (diff) | |
| download | rust-835b7a523a41cc89f0839f40652477af097db390.tar.gz rust-835b7a523a41cc89f0839f40652477af097db390.zip | |
ui: improve suggestion test by addig the help message
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
| -rw-r--r-- | compiler/rustc_typeck/src/astconv/mod.rs | 15 | ||||
| -rw-r--r-- | src/test/ui/suggestions/suggest-blanket-impl-local-trait.rs | 14 | ||||
| -rw-r--r-- | src/test/ui/suggestions/suggest-blanket-impl-local-trait.stderr | 38 | ||||
| -rwxr-xr-x | suggest-blanket-impl-local-trait | bin | 0 -> 479160 bytes |
4 files changed, 39 insertions, 28 deletions
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<T> {} 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<E> GenericTrait<E> 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<E>` for all types that also implement `LocalTraitOne` trait GenericTraitTwo<T> {} impl<T, E> GenericTraitTwo<E> for GenericTrait<T> {} //~^ ERROR trait objects must include the `dyn` keyword +//~| HELP add `dyn` keyword before this trait +//~| HELP alternatively use a blanket implementation to implement `GenericTraitTwo<E>` for all types that also implement `GenericTrait<T>` 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<T: LocalTraitOne> 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<T: fmt::Display> 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<T: fmt::Display + Send> 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<E> GenericTrait<E> for LocalTraitOne {} | ^^^^^^^^^^^^^ @@ -72,14 +80,14 @@ help: add `dyn` keyword before this trait | LL - impl<E> GenericTrait<E> for LocalTraitOne {} LL + impl<E> GenericTrait<E> for dyn LocalTraitOne {} - | + | help: alternatively use a blanket implementation to implement `GenericTrait<E>` for all types that also implement `LocalTraitOne` | -LL | impl<E, L: LocalTraitOne> GenericTrait<E> for T {} +LL | impl<E, T: LocalTraitOne> GenericTrait<E> 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<T, E> GenericTraitTwo<E> for GenericTrait<T> {} | ^^^^^^^^^^^^^^^ @@ -88,10 +96,10 @@ help: add `dyn` keyword before this trait | LL - impl<T, E> GenericTraitTwo<E> for GenericTrait<T> {} LL + impl<T, E> GenericTraitTwo<E> for dyn GenericTrait<T> {} - | + | help: alternatively use a blanket implementation to implement `GenericTraitTwo<E>` for all types that also implement `GenericTrait<T>` | -LL | impl<T, E, G: GenericTrait<T>> GenericTraitTwo<E> for U {} +LL | impl<T, E, U: GenericTrait<T>> GenericTraitTwo<E> 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 --- /dev/null +++ b/suggest-blanket-impl-local-trait Binary files differ |
