File tree Expand file tree Collapse file tree 3 files changed +72
-2
lines changed
compiler/rustc_hir_analysis/src/hir_ty_lowering
tests/ui/traits/associated_type_bound Expand file tree Collapse file tree 3 files changed +72
-2
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ use rustc_middle::ty::{
99} ;
1010use rustc_session:: lint:: builtin:: LATE_BOUND_LIFETIME_ARGUMENTS ;
1111use rustc_span:: kw;
12+ use rustc_trait_selection:: traits;
1213use smallvec:: SmallVec ;
1314use tracing:: { debug, instrument} ;
1415
@@ -535,9 +536,26 @@ pub(crate) fn check_generic_arg_count(
535536 . map ( |param| param. name )
536537 . collect ( ) ;
537538 if constraint_names == param_names {
539+ let has_assoc_ty_with_same_name =
540+ if let DefKind :: Trait = cx. tcx ( ) . def_kind ( def_id) {
541+ gen_args. constraints . iter ( ) . any ( |constraint| {
542+ traits:: supertrait_def_ids ( cx. tcx ( ) , def_id) . any ( |trait_did| {
543+ cx. probe_trait_that_defines_assoc_item (
544+ trait_did,
545+ ty:: AssocTag :: Type ,
546+ constraint. ident ,
547+ )
548+ } )
549+ } )
550+ } else {
551+ false
552+ } ;
538553 // We set this to true and delay emitting `WrongNumberOfGenericArgs`
539- // to provide a succinct error for cases like issue #113073
540- all_params_are_binded = true ;
554+ // to provide a succinct error for cases like issue #113073,
555+ // but only if when we don't have any assoc type with the same name with a
556+ // generic arg. Otherwise it will cause an ICE due to a delayed error because we
557+ // don't have any error other than `WrongNumberOfGenericArgs`.
558+ all_params_are_binded = !has_assoc_ty_with_same_name;
541559 } ;
542560 }
543561
Original file line number Diff line number Diff line change 1+ // A regression test for https://github.com/rust-lang/rust/issues/148121
2+
3+ pub trait Super < X > {
4+ type X ;
5+ }
6+
7+ pub trait Zelf < X > : Super < X > { }
8+
9+ pub trait A { }
10+
11+ impl A for dyn Super < X = ( ) > { }
12+ //~^ ERROR: trait takes 1 generic argument but 0 generic arguments were supplied
13+
14+ impl A for dyn Zelf < X = ( ) > { }
15+ //~^ ERROR: trait takes 1 generic argument but 0 generic arguments were supplied
16+
17+ fn main ( ) { }
Original file line number Diff line number Diff line change 1+ error[E0107]: trait takes 1 generic argument but 0 generic arguments were supplied
2+ --> $DIR/assoc-type-bounds-with-the-same-name-with-lacking-generic-arg-148121.rs:11:16
3+ |
4+ LL | impl A for dyn Super<X = ()> {}
5+ | ^^^^^ expected 1 generic argument
6+ |
7+ note: trait defined here, with 1 generic parameter: `X`
8+ --> $DIR/assoc-type-bounds-with-the-same-name-with-lacking-generic-arg-148121.rs:3:11
9+ |
10+ LL | pub trait Super<X> {
11+ | ^^^^^ -
12+ help: add missing generic argument
13+ |
14+ LL | impl A for dyn Super<X, X = ()> {}
15+ | ++
16+
17+ error[E0107]: trait takes 1 generic argument but 0 generic arguments were supplied
18+ --> $DIR/assoc-type-bounds-with-the-same-name-with-lacking-generic-arg-148121.rs:14:16
19+ |
20+ LL | impl A for dyn Zelf<X = ()> {}
21+ | ^^^^ expected 1 generic argument
22+ |
23+ note: trait defined here, with 1 generic parameter: `X`
24+ --> $DIR/assoc-type-bounds-with-the-same-name-with-lacking-generic-arg-148121.rs:7:11
25+ |
26+ LL | pub trait Zelf<X>: Super<X> {}
27+ | ^^^^ -
28+ help: add missing generic argument
29+ |
30+ LL | impl A for dyn Zelf<X, X = ()> {}
31+ | ++
32+
33+ error: aborting due to 2 previous errors
34+
35+ For more information about this error, try `rustc --explain E0107`.
You can’t perform that action at this time.
0 commit comments