From f31eb725f43cc78548a97b63422c92905f4281c8 Mon Sep 17 00:00:00 2001 From: Gurinder Singh Date: Sat, 23 Mar 2024 14:00:47 +0530 Subject: [PATCH] Emit suggestions when equality constraints are wronlgy used --- .../src/hir_ty_lowering/errors.rs | 88 ++++++++- .../src/hir_ty_lowering/generics.rs | 2 +- .../src/hir_ty_lowering/mod.rs | 8 +- .../invalid_associated_const.stderr | 11 ++ tests/rustdoc-ui/issue-102467.stderr | 11 ++ .../issue-102335-const.stderr | 11 ++ .../associated-type-bounds/issue-102335-ty.rs | 8 +- .../issue-102335-ty.stderr | 42 ++++- .../associated-types/associated-types-eq-2.rs | 64 ++++++- .../associated-types-eq-2.stderr | 178 +++++++++++++++++- .../issue-89013-no-kw.stderr | 5 + .../parser-error-recovery/issue-89013.stderr | 5 + tests/ui/error-codes/E0229.stderr | 16 ++ .../issue-102335-gat.stderr | 11 ++ ...lid-associated-type-supertrait-hrtb.stderr | 6 + tests/ui/suggestions/issue-85347.rs | 6 +- tests/ui/suggestions/issue-85347.stderr | 11 ++ 17 files changed, 458 insertions(+), 25 deletions(-) diff --git a/compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs b/compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs index ca2e14ee3591e..f12937740fc87 100644 --- a/compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs +++ b/compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs @@ -15,11 +15,13 @@ use rustc_hir as hir; use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_infer::traits::FulfillmentError; use rustc_middle::query::Key; -use rustc_middle::ty::{self, suggest_constraining_type_param, Ty, TyCtxt, TypeVisitableExt}; +use rustc_middle::ty::{ + self, suggest_constraining_type_param, GenericParamCount, Ty, TyCtxt, TypeVisitableExt, +}; use rustc_session::parse::feature_err; use rustc_span::edit_distance::find_best_match_for_name; use rustc_span::symbol::{sym, Ident}; -use rustc_span::{Span, Symbol, DUMMY_SP}; +use rustc_span::{BytePos, Span, Symbol, DUMMY_SP}; use rustc_trait_selection::traits::object_safety_violations_for_assoc_item; impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { @@ -1029,12 +1031,12 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { /// Emits an error regarding forbidden type binding associations pub fn prohibit_assoc_item_binding( tcx: TyCtxt<'_>, - span: Span, - segment: Option<(&hir::PathSegment<'_>, Span)>, + binding: &hir::TypeBinding<'_>, + segment: Option<(DefId, &hir::PathSegment<'_>, Span)>, ) { - tcx.dcx().emit_err(AssocTypeBindingNotAllowed { - span, - fn_trait_expansion: if let Some((segment, span)) = segment + let mut err = tcx.dcx().create_err(AssocTypeBindingNotAllowed { + span: binding.span, + fn_trait_expansion: if let Some((_, segment, span)) = segment && segment.args().parenthesized == hir::GenericArgsParentheses::ParenSugar { Some(ParenthesizedFnTraitExpansion { @@ -1045,6 +1047,78 @@ pub fn prohibit_assoc_item_binding( None }, }); + + // Emit a suggestion if possible + if let Some((def_id, segment, _)) = segment + && segment.args().parenthesized == hir::GenericArgsParentheses::No + && let hir::TypeBindingKind::Equality { term: binding_arg_ty } = binding.kind + { + // Suggests removal of the offending equality constraint + let suggest_removal = |e: &mut Diag<'_>| { + let mut suggestion_span = binding.span.with_hi(binding.span.hi() + BytePos(1)); // Include the comma or the angle bracket at the end + if segment.args().bindings.len() == 1 { + // If it is the only binding specified + // include the starting angle bracket as well + suggestion_span = suggestion_span.with_lo(suggestion_span.lo() - BytePos(1)) + } + if let Ok(suggestion) = tcx.sess.source_map().span_to_snippet(suggestion_span) { + e.span_suggestion_verbose( + suggestion_span, + "try removing this type binding", + suggestion, + Applicability::MaybeIncorrect, + ); + } + }; + + // Suggests replacing the quality constraint with + // normal type argument + let suggest_direct_use = |e: &mut Diag<'_>, sp: Span, is_ty: bool| { + if let Ok(snippet) = tcx.sess.source_map().span_to_snippet(sp) { + let ty_or_const = if is_ty { "generic" } else { "const" }; + e.span_suggestion_verbose( + binding.span, + format!("to use `{snippet}` as a {ty_or_const} argument specify it directly"), + snippet, + Applicability::MaybeIncorrect, + ); + } + }; + + // Get a sense of what generic args the type expects + let generics = tcx.generics_of(def_id); + let GenericParamCount { mut types, consts, .. } = generics.own_counts(); + if generics.has_self && types > 0 { + types -= 1 // Ignore the `Self` type + } + + // Now emit suggestion + if types == 0 && consts == 0 { + err.note(format!("`{0}` is not a generic type", segment.ident)); + suggest_removal(&mut err); + } else { + match binding_arg_ty { + hir::Term::Ty(ty) => { + if types > 0 { + suggest_direct_use(&mut err, ty.span, true); + } else { + suggest_removal(&mut err); + } + } + hir::Term::Const(c) if consts > 0 => { + if consts > 0 { + let span = tcx.hir().span(c.hir_id); + suggest_direct_use(&mut err, span, false); + } else { + suggest_removal(&mut err); + } + } + _ => {} + } + } + } + + err.emit(); } pub(crate) fn fn_trait_to_string( diff --git a/compiler/rustc_hir_analysis/src/hir_ty_lowering/generics.rs b/compiler/rustc_hir_analysis/src/hir_ty_lowering/generics.rs index d340a08ee79b1..1957849c5aaad 100644 --- a/compiler/rustc_hir_analysis/src/hir_ty_lowering/generics.rs +++ b/compiler/rustc_hir_analysis/src/hir_ty_lowering/generics.rs @@ -454,7 +454,7 @@ pub(crate) fn check_generic_arg_count( if gen_pos != GenericArgPosition::Type && let Some(b) = gen_args.bindings.first() { - prohibit_assoc_item_binding(tcx, b.span, None); + prohibit_assoc_item_binding(tcx, b, None); } let explicit_late_bound = diff --git a/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs b/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs index 109e00d4f24e5..7100b30a393bd 100644 --- a/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs +++ b/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs @@ -322,7 +322,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { ty::BoundConstness::NotConst, ); if let Some(b) = item_segment.args().bindings.first() { - prohibit_assoc_item_binding(self.tcx(), b.span, Some((item_segment, span))); + prohibit_assoc_item_binding(self.tcx(), b, Some((def_id, item_segment, span))); } args } @@ -619,7 +619,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { ty::BoundConstness::NotConst, ); if let Some(b) = item_segment.args().bindings.first() { - prohibit_assoc_item_binding(self.tcx(), b.span, Some((item_segment, span))); + prohibit_assoc_item_binding(self.tcx(), b, Some((item_def_id, item_segment, span))); } args } @@ -758,7 +758,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { constness, ); if let Some(b) = trait_segment.args().bindings.first() { - prohibit_assoc_item_binding(self.tcx(), b.span, Some((trait_segment, span))); + prohibit_assoc_item_binding(self.tcx(), b, Some((trait_def_id, trait_segment, span))); } ty::TraitRef::new(self.tcx(), trait_def_id, generic_args) } @@ -1724,7 +1724,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { for segment in segments { // Only emit the first error to avoid overloading the user with error messages. if let Some(b) = segment.args().bindings.first() { - prohibit_assoc_item_binding(self.tcx(), b.span, None); + prohibit_assoc_item_binding(self.tcx(), b, None); return true; } } diff --git a/tests/rustdoc-ui/invalid_associated_const.stderr b/tests/rustdoc-ui/invalid_associated_const.stderr index 1eb6d2714e31b..b256316b317b4 100644 --- a/tests/rustdoc-ui/invalid_associated_const.stderr +++ b/tests/rustdoc-ui/invalid_associated_const.stderr @@ -3,6 +3,12 @@ error[E0229]: associated type bindings are not allowed here | LL | type A: S = 34>; | ^^^^^^^^ associated type not allowed here + | + = note: `C` is not a generic type +help: try removing this type binding + | +LL | type A: S = 34>; + | ~~~~~~~~~~ error[E0229]: associated type bindings are not allowed here --> $DIR/invalid_associated_const.rs:4:17 @@ -10,7 +16,12 @@ error[E0229]: associated type bindings are not allowed here LL | type A: S = 34>; | ^^^^^^^^ associated type not allowed here | + = note: `C` is not a generic type = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` +help: try removing this type binding + | +LL | type A: S = 34>; + | ~~~~~~~~~~ error: aborting due to 2 previous errors diff --git a/tests/rustdoc-ui/issue-102467.stderr b/tests/rustdoc-ui/issue-102467.stderr index f54a50a4e1952..87f82548e82c0 100644 --- a/tests/rustdoc-ui/issue-102467.stderr +++ b/tests/rustdoc-ui/issue-102467.stderr @@ -3,6 +3,12 @@ error[E0229]: associated type bindings are not allowed here | LL | type A: S = 34>; | ^^^^^^^^ associated type not allowed here + | + = note: `C` is not a generic type +help: try removing this type binding + | +LL | type A: S = 34>; + | ~~~~~~~~~~ error[E0229]: associated type bindings are not allowed here --> $DIR/issue-102467.rs:7:17 @@ -10,7 +16,12 @@ error[E0229]: associated type bindings are not allowed here LL | type A: S = 34>; | ^^^^^^^^ associated type not allowed here | + = note: `C` is not a generic type = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` +help: try removing this type binding + | +LL | type A: S = 34>; + | ~~~~~~~~~~ error: aborting due to 2 previous errors diff --git a/tests/ui/associated-consts/issue-102335-const.stderr b/tests/ui/associated-consts/issue-102335-const.stderr index 2a70425a3cc87..96a4ab35e9e2c 100644 --- a/tests/ui/associated-consts/issue-102335-const.stderr +++ b/tests/ui/associated-consts/issue-102335-const.stderr @@ -3,6 +3,12 @@ error[E0229]: associated type bindings are not allowed here | LL | type A: S = 34>; | ^^^^^^^^ associated type not allowed here + | + = note: `C` is not a generic type +help: try removing this type binding + | +LL | type A: S = 34>; + | ~~~~~~~~~~ error[E0229]: associated type bindings are not allowed here --> $DIR/issue-102335-const.rs:4:17 @@ -10,7 +16,12 @@ error[E0229]: associated type bindings are not allowed here LL | type A: S = 34>; | ^^^^^^^^ associated type not allowed here | + = note: `C` is not a generic type = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` +help: try removing this type binding + | +LL | type A: S = 34>; + | ~~~~~~~~~~ error: aborting due to 2 previous errors diff --git a/tests/ui/associated-type-bounds/issue-102335-ty.rs b/tests/ui/associated-type-bounds/issue-102335-ty.rs index 5fd8b71e679b2..b2df68b18ae4d 100644 --- a/tests/ui/associated-type-bounds/issue-102335-ty.rs +++ b/tests/ui/associated-type-bounds/issue-102335-ty.rs @@ -1,5 +1,11 @@ trait T { - type A: S = ()>; + type A: S = ()>; // Just one erroneous equality constraint + //~^ ERROR associated type bindings are not allowed here + //~| ERROR associated type bindings are not allowed here +} + +trait T2 { + type A: S = ()>; // More than one erroneous equality constraints //~^ ERROR associated type bindings are not allowed here //~| ERROR associated type bindings are not allowed here } diff --git a/tests/ui/associated-type-bounds/issue-102335-ty.stderr b/tests/ui/associated-type-bounds/issue-102335-ty.stderr index 3bd7566ad1e0a..4f772a10960b7 100644 --- a/tests/ui/associated-type-bounds/issue-102335-ty.stderr +++ b/tests/ui/associated-type-bounds/issue-102335-ty.stderr @@ -1,17 +1,53 @@ error[E0229]: associated type bindings are not allowed here --> $DIR/issue-102335-ty.rs:2:17 | -LL | type A: S = ()>; +LL | type A: S = ()>; // Just one erroneous equality constraint | ^^^^^^^^^ associated type not allowed here + | + = note: `C` is not a generic type +help: try removing this type binding + | +LL | type A: S = ()>; // Just one erroneous equality constraint + | ~~~~~~~~~~~ error[E0229]: associated type bindings are not allowed here --> $DIR/issue-102335-ty.rs:2:17 | -LL | type A: S = ()>; +LL | type A: S = ()>; // Just one erroneous equality constraint + | ^^^^^^^^^ associated type not allowed here + | + = note: `C` is not a generic type + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` +help: try removing this type binding + | +LL | type A: S = ()>; // Just one erroneous equality constraint + | ~~~~~~~~~~~ + +error[E0229]: associated type bindings are not allowed here + --> $DIR/issue-102335-ty.rs:8:17 + | +LL | type A: S = ()>; // More than one erroneous equality constraints + | ^^^^^^^^^ associated type not allowed here + | + = note: `C` is not a generic type +help: try removing this type binding + | +LL | type A: S = ()>; // More than one erroneous equality constraints + | ~~~~~~~~~~ + +error[E0229]: associated type bindings are not allowed here + --> $DIR/issue-102335-ty.rs:8:17 + | +LL | type A: S = ()>; // More than one erroneous equality constraints | ^^^^^^^^^ associated type not allowed here | + = note: `C` is not a generic type = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` +help: try removing this type binding + | +LL | type A: S = ()>; // More than one erroneous equality constraints + | ~~~~~~~~~~ -error: aborting due to 2 previous errors +error: aborting due to 4 previous errors For more information about this error, try `rustc --explain E0229`. diff --git a/tests/ui/associated-types/associated-types-eq-2.rs b/tests/ui/associated-types/associated-types-eq-2.rs index 18e38d4466702..e10d6cf46949d 100644 --- a/tests/ui/associated-types/associated-types-eq-2.rs +++ b/tests/ui/associated-types/associated-types-eq-2.rs @@ -1,5 +1,5 @@ // Test equality constraints on associated types. Check we get an error when an -// equality constraint is used in a qualified path. +// equality constraint is used outside of type parameter declarations pub trait Foo { type A; @@ -7,13 +7,73 @@ pub trait Foo { } struct Bar; +struct Qux; impl Foo for isize { type A = usize; fn boo(&self) -> usize { 42 } } -fn baz(x: &>::A) {} +fn baz(_x: &>::A) {} //~^ ERROR associated type bindings are not allowed here + +trait Tr1 { +} + +impl Tr1 for Bar { +//~^ ERROR associated type bindings are not allowed here +//~| ERROR trait takes 1 generic argument but 0 generic arguments were supplied +} + + +trait Tr2 { +} + +// E0229 is emitted only for the first erroneous equality +// constraint (T2) not for any subequent ones (e.g. T3) +impl Tr2 for Bar { +//~^ ERROR associated type bindings are not allowed here +//~| ERROR trait takes 3 generic arguments but 1 generic argument was supplied +} + +struct GenericStruct { _t: T } + +impl Tr2> for Bar { +//~^ ERROR associated type bindings are not allowed here +//~| ERROR trait takes 3 generic arguments but 2 generic arguments were supplied +} + + +// Covers the case when the type has a const param +trait Tr3 { +} + +impl Tr3 for Bar { +//~^ ERROR associated type bindings are not allowed here +//~| ERROR associated const equality is incomplete +//~| ERROR trait takes 3 generic arguments but 0 generic arguments were supplied +} + + +// Covers the case when lifetimes +// are present +struct St<'a, T> { v: &'a T } + +impl<'a, T> St<'a, T = Qux> { +//~^ ERROR associated type bindings are not allowed here +//~| ERROR struct takes 1 generic argument but 0 generic arguments were supplied +} + + +// Covers the case when the type +// in question has no generic params +trait Tr4 { +} + +impl Tr4 for Bar { +//~^ ERROR associated type bindings are not allowed here +} + + pub fn main() {} diff --git a/tests/ui/associated-types/associated-types-eq-2.stderr b/tests/ui/associated-types/associated-types-eq-2.stderr index 447b8413ee294..f27f2736aa89f 100644 --- a/tests/ui/associated-types/associated-types-eq-2.stderr +++ b/tests/ui/associated-types/associated-types-eq-2.stderr @@ -1,9 +1,177 @@ +error[E0658]: associated const equality is incomplete + --> $DIR/associated-types-eq-2.rs:52:10 + | +LL | impl Tr3 for Bar { + | ^^^^^^ + | + = note: see issue #92827 for more information + = help: add `#![feature(associated_const_equality)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error[E0229]: associated type bindings are not allowed here + --> $DIR/associated-types-eq-2.rs:17:31 + | +LL | fn baz(_x: &>::A) {} + | ^^^^^ associated type not allowed here + | + = note: `Foo` is not a generic type +help: try removing this type binding + | +LL | fn baz(_x: &>::A) {} + | ~~~~~~~ + +error[E0107]: trait takes 1 generic argument but 0 generic arguments were supplied + --> $DIR/associated-types-eq-2.rs:24:6 + | +LL | impl Tr1 for Bar { + | ^^^ expected 1 generic argument + | +note: trait defined here, with 1 generic parameter: `T1` + --> $DIR/associated-types-eq-2.rs:21:7 + | +LL | trait Tr1 { + | ^^^ -- +help: add missing generic argument + | +LL | impl Tr1 for Bar { + | +++ + +error[E0229]: associated type bindings are not allowed here + --> $DIR/associated-types-eq-2.rs:24:10 + | +LL | impl Tr1 for Bar { + | ^^^^^^^^^^^ associated type not allowed here + | +help: to use `String` as a generic argument specify it directly + | +LL | impl Tr1 for Bar { + | ~~~~~~ + +error[E0107]: trait takes 3 generic arguments but 1 generic argument was supplied + --> $DIR/associated-types-eq-2.rs:35:6 + | +LL | impl Tr2 for Bar { + | ^^^ --- supplied 1 generic argument + | | + | expected 3 generic arguments + | +note: trait defined here, with 3 generic parameters: `T1`, `T2`, `T3` + --> $DIR/associated-types-eq-2.rs:30:7 + | +LL | trait Tr2 { + | ^^^ -- -- -- +help: add missing generic arguments + | +LL | impl Tr2 for Bar { + | ++++++++ + +error[E0229]: associated type bindings are not allowed here + --> $DIR/associated-types-eq-2.rs:35:15 + | +LL | impl Tr2 for Bar { + | ^^^^^^^^ associated type not allowed here + | +help: to use `Qux` as a generic argument specify it directly + | +LL | impl Tr2 for Bar { + | ~~~ + +error[E0107]: trait takes 3 generic arguments but 2 generic arguments were supplied + --> $DIR/associated-types-eq-2.rs:42:6 + | +LL | impl Tr2> for Bar { + | ^^^ --- --- supplied 2 generic arguments + | | + | expected 3 generic arguments + | +note: trait defined here, with 3 generic parameters: `T1`, `T2`, `T3` + --> $DIR/associated-types-eq-2.rs:30:7 + | +LL | trait Tr2 { + | ^^^ -- -- -- +help: add missing generic argument + | +LL | impl Tr2> for Bar { + | ++++ + +error[E0229]: associated type bindings are not allowed here + --> $DIR/associated-types-eq-2.rs:42:20 + | +LL | impl Tr2> for Bar { + | ^^^^^^^^^^^^^^^^^^^^^^^ associated type not allowed here + | +help: to use `GenericStruct` as a generic argument specify it directly + | +LL | impl Tr2> for Bar { + | ~~~~~~~~~~~~~~~~~~ + +error[E0107]: trait takes 3 generic arguments but 0 generic arguments were supplied + --> $DIR/associated-types-eq-2.rs:52:6 + | +LL | impl Tr3 for Bar { + | ^^^ expected 3 generic arguments + | +note: trait defined here, with 3 generic parameters: `N`, `T2`, `T3` + --> $DIR/associated-types-eq-2.rs:49:7 + | +LL | trait Tr3 { + | ^^^ ------------ -- -- +help: add missing generic arguments + | +LL | impl Tr3 for Bar { + | ++++++++++ + +error[E0229]: associated type bindings are not allowed here + --> $DIR/associated-types-eq-2.rs:52:10 + | +LL | impl Tr3 for Bar { + | ^^^^^^ associated type not allowed here + | +help: to use `42` as a const argument specify it directly + | +LL | impl Tr3<42, T2 = Qux, T3 = usize> for Bar { + | ~~ + +error[E0107]: struct takes 1 generic argument but 0 generic arguments were supplied + --> $DIR/associated-types-eq-2.rs:63:13 + | +LL | impl<'a, T> St<'a, T = Qux> { + | ^^ expected 1 generic argument + | +note: struct defined here, with 1 generic parameter: `T` + --> $DIR/associated-types-eq-2.rs:61:8 + | +LL | struct St<'a, T> { v: &'a T } + | ^^ - +help: add missing generic argument + | +LL | impl<'a, T> St<'a, T, T = Qux> { + | +++ + error[E0229]: associated type bindings are not allowed here - --> $DIR/associated-types-eq-2.rs:16:30 + --> $DIR/associated-types-eq-2.rs:63:20 + | +LL | impl<'a, T> St<'a, T = Qux> { + | ^^^^^^^ associated type not allowed here + | +help: to use `Qux` as a generic argument specify it directly + | +LL | impl<'a, T> St<'a, Qux> { + | ~~~ + +error[E0229]: associated type bindings are not allowed here + --> $DIR/associated-types-eq-2.rs:74:10 + | +LL | impl Tr4 for Bar { + | ^^^^^^^ associated type not allowed here + | + = note: `Tr4` is not a generic type +help: try removing this type binding | -LL | fn baz(x: &>::A) {} - | ^^^^^ associated type not allowed here +LL | impl Tr4 for Bar { + | ~~~~~~~~ -error: aborting due to 1 previous error +error: aborting due to 13 previous errors -For more information about this error, try `rustc --explain E0229`. +Some errors have detailed explanations: E0107, E0229, E0658. +For more information about an error, try `rustc --explain E0107`. diff --git a/tests/ui/const-generics/parser-error-recovery/issue-89013-no-kw.stderr b/tests/ui/const-generics/parser-error-recovery/issue-89013-no-kw.stderr index 92dedd74feb50..c707d1dbccd8d 100644 --- a/tests/ui/const-generics/parser-error-recovery/issue-89013-no-kw.stderr +++ b/tests/ui/const-generics/parser-error-recovery/issue-89013-no-kw.stderr @@ -29,6 +29,11 @@ error[E0229]: associated type bindings are not allowed here | LL | impl Foo for Bar { | ^^^^^ associated type not allowed here + | +help: to use `3` as a const argument specify it directly + | +LL | impl Foo<3> for Bar { + | ~ error: aborting due to 3 previous errors diff --git a/tests/ui/const-generics/parser-error-recovery/issue-89013.stderr b/tests/ui/const-generics/parser-error-recovery/issue-89013.stderr index 801d14b395054..5ff0b712350d2 100644 --- a/tests/ui/const-generics/parser-error-recovery/issue-89013.stderr +++ b/tests/ui/const-generics/parser-error-recovery/issue-89013.stderr @@ -41,6 +41,11 @@ error[E0229]: associated type bindings are not allowed here | LL | impl Foo for Bar { | ^^^^^^^^^^^ associated type not allowed here + | +help: to use `3` as a const argument specify it directly + | +LL | impl Foo<3> for Bar { + | ~ error: aborting due to 4 previous errors diff --git a/tests/ui/error-codes/E0229.stderr b/tests/ui/error-codes/E0229.stderr index bd8e1955ac684..f0171ab82cffd 100644 --- a/tests/ui/error-codes/E0229.stderr +++ b/tests/ui/error-codes/E0229.stderr @@ -3,6 +3,12 @@ error[E0229]: associated type bindings are not allowed here | LL | fn baz(x: &>::A) {} | ^^^^^ associated type not allowed here + | + = note: `Foo` is not a generic type +help: try removing this type binding + | +LL | fn baz(x: &>::A) {} + | ~~~~~~~ error[E0229]: associated type bindings are not allowed here --> $DIR/E0229.rs:13:25 @@ -10,7 +16,12 @@ error[E0229]: associated type bindings are not allowed here LL | fn baz(x: &>::A) {} | ^^^^^ associated type not allowed here | + = note: `Foo` is not a generic type = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` +help: try removing this type binding + | +LL | fn baz(x: &>::A) {} + | ~~~~~~~ error[E0229]: associated type bindings are not allowed here --> $DIR/E0229.rs:13:25 @@ -18,7 +29,12 @@ error[E0229]: associated type bindings are not allowed here LL | fn baz(x: &>::A) {} | ^^^^^ associated type not allowed here | + = note: `Foo` is not a generic type = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` +help: try removing this type binding + | +LL | fn baz(x: &>::A) {} + | ~~~~~~~ error[E0277]: the trait bound `I: Foo` is not satisfied --> $DIR/E0229.rs:13:15 diff --git a/tests/ui/generic-associated-types/issue-102335-gat.stderr b/tests/ui/generic-associated-types/issue-102335-gat.stderr index f5e782e92fc6a..50ab5981f4926 100644 --- a/tests/ui/generic-associated-types/issue-102335-gat.stderr +++ b/tests/ui/generic-associated-types/issue-102335-gat.stderr @@ -3,6 +3,12 @@ error[E0229]: associated type bindings are not allowed here | LL | type A: S = ()>; | ^^^^^^^^ associated type not allowed here + | + = note: `C` is not a generic type +help: try removing this type binding + | +LL | type A: S = ()>; + | ~~~~~~~~~ error[E0229]: associated type bindings are not allowed here --> $DIR/issue-102335-gat.rs:2:21 @@ -10,7 +16,12 @@ error[E0229]: associated type bindings are not allowed here LL | type A: S = ()>; | ^^^^^^^^ associated type not allowed here | + = note: `C` is not a generic type = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` +help: try removing this type binding + | +LL | type A: S = ()>; + | ~~~~~~~~~ error: aborting due to 2 previous errors diff --git a/tests/ui/lifetimes/issue-83753-invalid-associated-type-supertrait-hrtb.stderr b/tests/ui/lifetimes/issue-83753-invalid-associated-type-supertrait-hrtb.stderr index d99ea6a0c309f..39cf6ad99a83c 100644 --- a/tests/ui/lifetimes/issue-83753-invalid-associated-type-supertrait-hrtb.stderr +++ b/tests/ui/lifetimes/issue-83753-invalid-associated-type-supertrait-hrtb.stderr @@ -3,6 +3,12 @@ error[E0229]: associated type bindings are not allowed here | LL | fn bar(foo: Foo) {} | ^^^^^^^^^^^^^^ associated type not allowed here + | + = note: `Foo` is not a generic type +help: try removing this type binding + | +LL | fn bar(foo: Foo) {} + | ~~~~~~~~~~~~~~~~ error: aborting due to 1 previous error diff --git a/tests/ui/suggestions/issue-85347.rs b/tests/ui/suggestions/issue-85347.rs index d14cf07d915ed..a528274247861 100644 --- a/tests/ui/suggestions/issue-85347.rs +++ b/tests/ui/suggestions/issue-85347.rs @@ -2,11 +2,13 @@ use std::ops::Deref; trait Foo { type Bar<'a>: Deref::Bar>; //~^ ERROR associated type takes 1 lifetime argument but 0 lifetime arguments were supplied - //~| ERROR associated type bindings are not allowed here //~| HELP add missing - //~| ERROR associated type takes 1 lifetime argument but 0 lifetime arguments were supplied //~| ERROR associated type bindings are not allowed here + //~| HELP try removing this type binding + //~| ERROR associated type takes 1 lifetime argument but 0 lifetime arguments were supplied //~| HELP add missing + //~| ERROR associated type bindings are not allowed here + //~| HELP try removing this type binding } fn main() {} diff --git a/tests/ui/suggestions/issue-85347.stderr b/tests/ui/suggestions/issue-85347.stderr index 45f87e539b4e6..6435c503189b4 100644 --- a/tests/ui/suggestions/issue-85347.stderr +++ b/tests/ui/suggestions/issue-85347.stderr @@ -19,6 +19,12 @@ error[E0229]: associated type bindings are not allowed here | LL | type Bar<'a>: Deref::Bar>; | ^^^^^^^^^^^^^ associated type not allowed here + | + = note: `Bar` is not a generic type +help: try removing this type binding + | +LL | type Bar<'a>: Deref::Bar>; + | ~~~~~~~~~~~~~~~ error[E0107]: associated type takes 1 lifetime argument but 0 lifetime arguments were supplied --> $DIR/issue-85347.rs:3:42 @@ -43,7 +49,12 @@ error[E0229]: associated type bindings are not allowed here LL | type Bar<'a>: Deref::Bar>; | ^^^^^^^^^^^^^ associated type not allowed here | + = note: `Bar` is not a generic type = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` +help: try removing this type binding + | +LL | type Bar<'a>: Deref::Bar>; + | ~~~~~~~~~~~~~~~ error: aborting due to 4 previous errors