diff --git a/compiler/rustc_hir_analysis/src/impl_wf_check.rs b/compiler/rustc_hir_analysis/src/impl_wf_check.rs index 8ab9964d81000..9f98923275435 100644 --- a/compiler/rustc_hir_analysis/src/impl_wf_check.rs +++ b/compiler/rustc_hir_analysis/src/impl_wf_check.rs @@ -12,7 +12,7 @@ use crate::constrained_generic_params as cgp; use min_specialization::check_min_specialization; use rustc_data_structures::fx::FxHashSet; -use rustc_errors::struct_span_err; +use rustc_errors::{struct_span_err, Applicability}; use rustc_hir::def::DefKind; use rustc_hir::def_id::LocalDefId; use rustc_middle::ty::query::Providers; @@ -181,6 +181,15 @@ fn report_unused_parameter(tcx: TyCtxt<'_>, span: Span, kind: &str, name: Symbol name ); err.span_label(span, format!("unconstrained {} parameter", kind)); + err.span_suggestion( + span, + format!( + "Either remove the type parameter '{}' or make use of it, for example ` for S<{}>`.", + name, name + ), + "", + Applicability::MaybeIncorrect, + ); if kind == "const" { err.note( "expressions using a const parameter must map each value to a distinct output value", diff --git a/tests/ui/async-await/issues/issue-78654.full.stderr b/tests/ui/async-await/issues/issue-78654.full.stderr index 0d12a948c68bd..9291b8be7084e 100644 --- a/tests/ui/async-await/issues/issue-78654.full.stderr +++ b/tests/ui/async-await/issues/issue-78654.full.stderr @@ -12,6 +12,11 @@ LL | impl Foo { | = note: expressions using a const parameter must map each value to a distinct output value = note: proving the result of expressions other than the parameter are unique is not supported +help: Either remove the type parameter 'H' or make use of it, for example ` for S`. + | +LL - impl Foo { +LL + impl<> Foo { + | error: aborting due to 2 previous errors diff --git a/tests/ui/async-await/issues/issue-78654.min.stderr b/tests/ui/async-await/issues/issue-78654.min.stderr index 0d12a948c68bd..9291b8be7084e 100644 --- a/tests/ui/async-await/issues/issue-78654.min.stderr +++ b/tests/ui/async-await/issues/issue-78654.min.stderr @@ -12,6 +12,11 @@ LL | impl Foo { | = note: expressions using a const parameter must map each value to a distinct output value = note: proving the result of expressions other than the parameter are unique is not supported +help: Either remove the type parameter 'H' or make use of it, for example ` for S`. + | +LL - impl Foo { +LL + impl<> Foo { + | error: aborting due to 2 previous errors diff --git a/tests/ui/const-generics/issues/issue-68366.full.stderr b/tests/ui/const-generics/issues/issue-68366.full.stderr index ca9eb801dfce7..7019bac8d903a 100644 --- a/tests/ui/const-generics/issues/issue-68366.full.stderr +++ b/tests/ui/const-generics/issues/issue-68366.full.stderr @@ -6,6 +6,11 @@ LL | impl Collatz<{Some(N)}> {} | = note: expressions using a const parameter must map each value to a distinct output value = note: proving the result of expressions other than the parameter are unique is not supported +help: Either remove the type parameter 'N' or make use of it, for example ` for S`. + | +LL - impl Collatz<{Some(N)}> {} +LL + impl <> Collatz<{Some(N)}> {} + | error[E0207]: the const parameter `N` is not constrained by the impl trait, self type, or predicates --> $DIR/issue-68366.rs:17:6 @@ -15,6 +20,11 @@ LL | impl Foo {} | = note: expressions using a const parameter must map each value to a distinct output value = note: proving the result of expressions other than the parameter are unique is not supported +help: Either remove the type parameter 'N' or make use of it, for example ` for S`. + | +LL - impl Foo {} +LL + impl<> Foo {} + | error: aborting due to 2 previous errors diff --git a/tests/ui/const-generics/issues/issue-68366.min.stderr b/tests/ui/const-generics/issues/issue-68366.min.stderr index 3740ced90b1d7..e9d07a7d86673 100644 --- a/tests/ui/const-generics/issues/issue-68366.min.stderr +++ b/tests/ui/const-generics/issues/issue-68366.min.stderr @@ -15,6 +15,11 @@ LL | impl Collatz<{Some(N)}> {} | = note: expressions using a const parameter must map each value to a distinct output value = note: proving the result of expressions other than the parameter are unique is not supported +help: Either remove the type parameter 'N' or make use of it, for example ` for S`. + | +LL - impl Collatz<{Some(N)}> {} +LL + impl <> Collatz<{Some(N)}> {} + | error[E0207]: the const parameter `N` is not constrained by the impl trait, self type, or predicates --> $DIR/issue-68366.rs:17:6 @@ -24,6 +29,11 @@ LL | impl Foo {} | = note: expressions using a const parameter must map each value to a distinct output value = note: proving the result of expressions other than the parameter are unique is not supported +help: Either remove the type parameter 'N' or make use of it, for example ` for S`. + | +LL - impl Foo {} +LL + impl<> Foo {} + | error: aborting due to 3 previous errors diff --git a/tests/ui/duplicate/duplicate-type-parameter.stderr b/tests/ui/duplicate/duplicate-type-parameter.stderr index 628f898d5c879..a9554b7479e83 100644 --- a/tests/ui/duplicate/duplicate-type-parameter.stderr +++ b/tests/ui/duplicate/duplicate-type-parameter.stderr @@ -59,6 +59,12 @@ error[E0207]: the type parameter `T` is not constrained by the impl trait, self | LL | impl Qux for Option {} | ^ unconstrained type parameter + | +help: Either remove the type parameter 'T' or make use of it, for example ` for S`. + | +LL - impl Qux for Option {} +LL + impl Qux for Option {} + | error: aborting due to 8 previous errors diff --git a/tests/ui/error-codes/E0207.stderr b/tests/ui/error-codes/E0207.stderr index 5ef51ed86926a..a4a24ed2be64c 100644 --- a/tests/ui/error-codes/E0207.stderr +++ b/tests/ui/error-codes/E0207.stderr @@ -3,6 +3,12 @@ error[E0207]: the type parameter `T` is not constrained by the impl trait, self | LL | impl Foo { | ^ unconstrained type parameter + | +help: Either remove the type parameter 'T' or make use of it, for example ` for S`. + | +LL - impl Foo { +LL + impl<: Default> Foo { + | error: aborting due to previous error diff --git a/tests/ui/generic-associated-types/bugs/issue-87735.stderr b/tests/ui/generic-associated-types/bugs/issue-87735.stderr index ebe2054ce5efc..9f136b653c050 100644 --- a/tests/ui/generic-associated-types/bugs/issue-87735.stderr +++ b/tests/ui/generic-associated-types/bugs/issue-87735.stderr @@ -3,6 +3,12 @@ error[E0207]: the type parameter `U` is not constrained by the impl trait, self | LL | impl<'b, T, U> AsRef2 for Foo | ^ unconstrained type parameter + | +help: Either remove the type parameter 'U' or make use of it, for example ` for S`. + | +LL - impl<'b, T, U> AsRef2 for Foo +LL + impl<'b, T, > AsRef2 for Foo + | error: aborting due to previous error diff --git a/tests/ui/generic-associated-types/bugs/issue-88526.stderr b/tests/ui/generic-associated-types/bugs/issue-88526.stderr index 56857c6550bdc..07534fae48498 100644 --- a/tests/ui/generic-associated-types/bugs/issue-88526.stderr +++ b/tests/ui/generic-associated-types/bugs/issue-88526.stderr @@ -3,6 +3,12 @@ error[E0207]: the type parameter `I` is not constrained by the impl trait, self | LL | impl<'q, Q, I, F> A for TestB | ^ unconstrained type parameter + | +help: Either remove the type parameter 'I' or make use of it, for example ` for S`. + | +LL - impl<'q, Q, I, F> A for TestB +LL + impl<'q, Q, , F> A for TestB + | error: aborting due to previous error diff --git a/tests/ui/generic-associated-types/gat-trait-path-generic-type-arg.stderr b/tests/ui/generic-associated-types/gat-trait-path-generic-type-arg.stderr index cb2b9f32bfe72..103bce1ddf2a1 100644 --- a/tests/ui/generic-associated-types/gat-trait-path-generic-type-arg.stderr +++ b/tests/ui/generic-associated-types/gat-trait-path-generic-type-arg.stderr @@ -18,6 +18,12 @@ error[E0207]: the type parameter `T1` is not constrained by the impl trait, self | LL | impl Foo for T { | ^^ unconstrained type parameter + | +help: Either remove the type parameter 'T1' or make use of it, for example ` for S`. + | +LL - impl Foo for T { +LL + impl Foo for T { + | error: aborting due to 3 previous errors diff --git a/tests/ui/impl-trait/issues/issue-87340.stderr b/tests/ui/impl-trait/issues/issue-87340.stderr index 2ab1e6a031248..3c82e3894ba19 100644 --- a/tests/ui/impl-trait/issues/issue-87340.stderr +++ b/tests/ui/impl-trait/issues/issue-87340.stderr @@ -3,6 +3,12 @@ error[E0207]: the type parameter `T` is not constrained by the impl trait, self | LL | impl X for () { | ^ unconstrained type parameter + | +help: Either remove the type parameter 'T' or make use of it, for example ` for S`. + | +LL - impl X for () { +LL + impl<> X for () { + | error: aborting due to previous error diff --git a/tests/ui/impl-unused-rps-in-assoc-type.stderr b/tests/ui/impl-unused-rps-in-assoc-type.stderr index c7ad1b4e608fc..699658d76c4af 100644 --- a/tests/ui/impl-unused-rps-in-assoc-type.stderr +++ b/tests/ui/impl-unused-rps-in-assoc-type.stderr @@ -3,6 +3,12 @@ error[E0207]: the lifetime parameter `'a` is not constrained by the impl trait, | LL | impl<'a> Fun for Holder { | ^^ unconstrained lifetime parameter + | +help: Either remove the type parameter ''a' or make use of it, for example ` for S<'a>`. + | +LL - impl<'a> Fun for Holder { +LL + impl<> Fun for Holder { + | error: aborting due to previous error diff --git a/tests/ui/impl-unused-tps-inherent.stderr b/tests/ui/impl-unused-tps-inherent.stderr index 43f63cf968cf5..a1b67617fc1fe 100644 --- a/tests/ui/impl-unused-tps-inherent.stderr +++ b/tests/ui/impl-unused-tps-inherent.stderr @@ -3,12 +3,24 @@ error[E0207]: the type parameter `T` is not constrained by the impl trait, self | LL | impl MyType { | ^ unconstrained type parameter + | +help: Either remove the type parameter 'T' or make use of it, for example ` for S`. + | +LL - impl MyType { +LL + impl<> MyType { + | error[E0207]: the type parameter `U` is not constrained by the impl trait, self type, or predicates --> $DIR/impl-unused-tps-inherent.rs:17:8 | LL | impl MyType1 { | ^ unconstrained type parameter + | +help: Either remove the type parameter 'U' or make use of it, for example ` for S`. + | +LL - impl MyType1 { +LL + impl MyType1 { + | error: aborting due to 2 previous errors diff --git a/tests/ui/impl-unused-tps.stderr b/tests/ui/impl-unused-tps.stderr index 053ab91c89328..47b2c88c49308 100644 --- a/tests/ui/impl-unused-tps.stderr +++ b/tests/ui/impl-unused-tps.stderr @@ -3,30 +3,60 @@ error[E0207]: the type parameter `U` is not constrained by the impl trait, self | LL | impl Foo for [isize;1] { | ^ unconstrained type parameter + | +help: Either remove the type parameter 'U' or make use of it, for example ` for S`. + | +LL - impl Foo for [isize;1] { +LL + impl Foo for [isize;1] { + | error[E0207]: the type parameter `U` is not constrained by the impl trait, self type, or predicates --> $DIR/impl-unused-tps.rs:30:8 | LL | impl Bar for T { | ^ unconstrained type parameter + | +help: Either remove the type parameter 'U' or make use of it, for example ` for S`. + | +LL - impl Bar for T { +LL + impl Bar for T { + | error[E0207]: the type parameter `U` is not constrained by the impl trait, self type, or predicates --> $DIR/impl-unused-tps.rs:38:8 | LL | impl Bar for T | ^ unconstrained type parameter + | +help: Either remove the type parameter 'U' or make use of it, for example ` for S`. + | +LL - impl Bar for T +LL + impl Bar for T + | error[E0207]: the type parameter `U` is not constrained by the impl trait, self type, or predicates --> $DIR/impl-unused-tps.rs:46:8 | LL | impl Foo for T | ^ unconstrained type parameter + | +help: Either remove the type parameter 'U' or make use of it, for example ` for S`. + | +LL - impl Foo for T +LL + impl Foo for T + | error[E0207]: the type parameter `V` is not constrained by the impl trait, self type, or predicates --> $DIR/impl-unused-tps.rs:46:10 | LL | impl Foo for T | ^ unconstrained type parameter + | +help: Either remove the type parameter 'V' or make use of it, for example ` for S`. + | +LL - impl Foo for T +LL + impl Foo for T + | error: aborting due to 5 previous errors diff --git a/tests/ui/issues/issue-16562.stderr b/tests/ui/issues/issue-16562.stderr index 3fe7507e8a412..60385e06a52f2 100644 --- a/tests/ui/issues/issue-16562.stderr +++ b/tests/ui/issues/issue-16562.stderr @@ -3,6 +3,12 @@ error[E0207]: the type parameter `T` is not constrained by the impl trait, self | LL | impl Collection for Col { | ^ unconstrained type parameter + | +help: Either remove the type parameter 'T' or make use of it, for example ` for S`. + | +LL - impl Collection for Col { +LL + impl<, M: MatrixShape> Collection for Col { + | error: aborting due to previous error diff --git a/tests/ui/issues/issue-22886.stderr b/tests/ui/issues/issue-22886.stderr index c4b3965592411..b05a9ca34709f 100644 --- a/tests/ui/issues/issue-22886.stderr +++ b/tests/ui/issues/issue-22886.stderr @@ -3,6 +3,12 @@ error[E0207]: the lifetime parameter `'a` is not constrained by the impl trait, | LL | impl<'a> Iterator for Newtype { | ^^ unconstrained lifetime parameter + | +help: Either remove the type parameter ''a' or make use of it, for example ` for S<'a>`. + | +LL - impl<'a> Iterator for Newtype { +LL + impl<> Iterator for Newtype { + | error: aborting due to previous error diff --git a/tests/ui/issues/issue-26262.stderr b/tests/ui/issues/issue-26262.stderr index 90e2d0d930164..9b5f72a34f1f3 100644 --- a/tests/ui/issues/issue-26262.stderr +++ b/tests/ui/issues/issue-26262.stderr @@ -3,12 +3,24 @@ error[E0207]: the type parameter `T` is not constrained by the impl trait, self | LL | impl S { | ^ unconstrained type parameter + | +help: Either remove the type parameter 'T' or make use of it, for example ` for S`. + | +LL - impl S { +LL + impl<: Tr> S { + | error[E0207]: the lifetime parameter `'a` is not constrained by the impl trait, self type, or predicates --> $DIR/issue-26262.rs:17:6 | LL | impl<'a,T: Trait2<'a>> Trait1<>::Foo> for T { | ^^ unconstrained lifetime parameter + | +help: Either remove the type parameter ''a' or make use of it, for example ` for S<'a>`. + | +LL - impl<'a,T: Trait2<'a>> Trait1<>::Foo> for T { +LL + impl<,T: Trait2<'a>> Trait1<>::Foo> for T { + | error: aborting due to 2 previous errors diff --git a/tests/ui/issues/issue-29861.stderr b/tests/ui/issues/issue-29861.stderr index d9d3cf360df2d..aa659e704c298 100644 --- a/tests/ui/issues/issue-29861.stderr +++ b/tests/ui/issues/issue-29861.stderr @@ -3,6 +3,12 @@ error[E0207]: the lifetime parameter `'a` is not constrained by the impl trait, | LL | impl<'a, T: 'a> MakeRef2 for T { | ^^ unconstrained lifetime parameter + | +help: Either remove the type parameter ''a' or make use of it, for example ` for S<'a>`. + | +LL - impl<'a, T: 'a> MakeRef2 for T { +LL + impl<, T: 'a> MakeRef2 for T { + | error: aborting due to previous error diff --git a/tests/ui/issues/issue-35139.stderr b/tests/ui/issues/issue-35139.stderr index 79e889b7e599e..7de42fbd9a4c4 100644 --- a/tests/ui/issues/issue-35139.stderr +++ b/tests/ui/issues/issue-35139.stderr @@ -3,6 +3,12 @@ error[E0207]: the lifetime parameter `'a` is not constrained by the impl trait, | LL | impl<'a> MethodType for MTFn { | ^^ unconstrained lifetime parameter + | +help: Either remove the type parameter ''a' or make use of it, for example ` for S<'a>`. + | +LL - impl<'a> MethodType for MTFn { +LL + impl<> MethodType for MTFn { + | error: aborting due to previous error diff --git a/tests/ui/type-alias-impl-trait/assoc-type-lifetime-unconstrained.stderr b/tests/ui/type-alias-impl-trait/assoc-type-lifetime-unconstrained.stderr index e594dc577b1cd..464dc7062024e 100644 --- a/tests/ui/type-alias-impl-trait/assoc-type-lifetime-unconstrained.stderr +++ b/tests/ui/type-alias-impl-trait/assoc-type-lifetime-unconstrained.stderr @@ -3,6 +3,12 @@ error[E0207]: the lifetime parameter `'a` is not constrained by the impl trait, | LL | impl<'a, I> UnwrapItemsExt for I { | ^^ unconstrained lifetime parameter + | +help: Either remove the type parameter ''a' or make use of it, for example ` for S<'a>`. + | +LL - impl<'a, I> UnwrapItemsExt for I { +LL + impl<, I> UnwrapItemsExt for I { + | error: aborting due to previous error diff --git a/tests/ui/type-alias-impl-trait/impl-with-unconstrained-param.stderr b/tests/ui/type-alias-impl-trait/impl-with-unconstrained-param.stderr index 8cf8fb1d16c4d..980c440c6eabf 100644 --- a/tests/ui/type-alias-impl-trait/impl-with-unconstrained-param.stderr +++ b/tests/ui/type-alias-impl-trait/impl-with-unconstrained-param.stderr @@ -3,6 +3,12 @@ error[E0207]: the type parameter `T` is not constrained by the impl trait, self | LL | impl X for () { | ^ unconstrained type parameter + | +help: Either remove the type parameter 'T' or make use of it, for example ` for S`. + | +LL - impl X for () { +LL + impl<> X for () { + | error: aborting due to previous error diff --git a/tests/ui/type-alias-impl-trait/issue-74244.stderr b/tests/ui/type-alias-impl-trait/issue-74244.stderr index ff6bacd277e1e..bdd1657eb1d4c 100644 --- a/tests/ui/type-alias-impl-trait/issue-74244.stderr +++ b/tests/ui/type-alias-impl-trait/issue-74244.stderr @@ -3,6 +3,12 @@ error[E0207]: the type parameter `T` is not constrained by the impl trait, self | LL | impl Allocator for DefaultAllocator { | ^ unconstrained type parameter + | +help: Either remove the type parameter 'T' or make use of it, for example ` for S`. + | +LL - impl Allocator for DefaultAllocator { +LL + impl<> Allocator for DefaultAllocator { + | error: aborting due to previous error diff --git a/tests/ui/type-alias-impl-trait/issue-74761-2.stderr b/tests/ui/type-alias-impl-trait/issue-74761-2.stderr index f15d0a069ca8a..253256d64d607 100644 --- a/tests/ui/type-alias-impl-trait/issue-74761-2.stderr +++ b/tests/ui/type-alias-impl-trait/issue-74761-2.stderr @@ -3,12 +3,24 @@ error[E0207]: the lifetime parameter `'a` is not constrained by the impl trait, | LL | impl<'a, 'b> A for () { | ^^ unconstrained lifetime parameter + | +help: Either remove the type parameter ''a' or make use of it, for example ` for S<'a>`. + | +LL - impl<'a, 'b> A for () { +LL + impl<, 'b> A for () { + | error[E0207]: the lifetime parameter `'b` is not constrained by the impl trait, self type, or predicates --> $DIR/issue-74761-2.rs:7:10 | LL | impl<'a, 'b> A for () { | ^^ unconstrained lifetime parameter + | +help: Either remove the type parameter ''b' or make use of it, for example ` for S<'b>`. + | +LL - impl<'a, 'b> A for () { +LL + impl<'a, > A for () { + | error: aborting due to 2 previous errors diff --git a/tests/ui/type-alias-impl-trait/issue-74761.stderr b/tests/ui/type-alias-impl-trait/issue-74761.stderr index 1d016fe070f9c..e76aa8cfba362 100644 --- a/tests/ui/type-alias-impl-trait/issue-74761.stderr +++ b/tests/ui/type-alias-impl-trait/issue-74761.stderr @@ -3,12 +3,24 @@ error[E0207]: the lifetime parameter `'a` is not constrained by the impl trait, | LL | impl<'a, 'b> A for () { | ^^ unconstrained lifetime parameter + | +help: Either remove the type parameter ''a' or make use of it, for example ` for S<'a>`. + | +LL - impl<'a, 'b> A for () { +LL + impl<, 'b> A for () { + | error[E0207]: the lifetime parameter `'b` is not constrained by the impl trait, self type, or predicates --> $DIR/issue-74761.rs:7:10 | LL | impl<'a, 'b> A for () { | ^^ unconstrained lifetime parameter + | +help: Either remove the type parameter ''b' or make use of it, for example ` for S<'b>`. + | +LL - impl<'a, 'b> A for () { +LL + impl<'a, > A for () { + | error: aborting due to 2 previous errors diff --git a/tests/ui/type-alias-impl-trait/type-alias-impl-trait-unconstrained-lifetime.stderr b/tests/ui/type-alias-impl-trait/type-alias-impl-trait-unconstrained-lifetime.stderr index 8cdce2f8e81ca..9bac0f9a336d2 100644 --- a/tests/ui/type-alias-impl-trait/type-alias-impl-trait-unconstrained-lifetime.stderr +++ b/tests/ui/type-alias-impl-trait/type-alias-impl-trait-unconstrained-lifetime.stderr @@ -3,6 +3,12 @@ error[E0207]: the lifetime parameter `'a` is not constrained by the impl trait, | LL | impl<'a, I: Iterator> Trait for (i32, I) { | ^^ unconstrained lifetime parameter + | +help: Either remove the type parameter ''a' or make use of it, for example ` for S<'a>`. + | +LL - impl<'a, I: Iterator> Trait for (i32, I) { +LL + impl<, I: Iterator> Trait for (i32, I) { + | error: aborting due to previous error diff --git a/tests/ui/typeck/issue-13853-5.stderr b/tests/ui/typeck/issue-13853-5.stderr index 3d8f824ec94cb..ecfe102a630f2 100644 --- a/tests/ui/typeck/issue-13853-5.stderr +++ b/tests/ui/typeck/issue-13853-5.stderr @@ -3,6 +3,12 @@ error[E0207]: the type parameter `T` is not constrained by the impl trait, self | LL | impl<'a, T: Deserializable> Deserializable for &'a str { | ^ unconstrained type parameter + | +help: Either remove the type parameter 'T' or make use of it, for example ` for S`. + | +LL - impl<'a, T: Deserializable> Deserializable for &'a str { +LL + impl<'a, : Deserializable> Deserializable for &'a str { + | error: aborting due to previous error