fix: Do not delay E0107 when there exists an assoc ty with the same name
This commit is contained in:
parent
a6acf0f07f
commit
08362d3e51
3 changed files with 72 additions and 2 deletions
|
|
@ -9,6 +9,7 @@ use rustc_middle::ty::{
|
|||
};
|
||||
use rustc_session::lint::builtin::LATE_BOUND_LIFETIME_ARGUMENTS;
|
||||
use rustc_span::kw;
|
||||
use rustc_trait_selection::traits;
|
||||
use smallvec::SmallVec;
|
||||
use tracing::{debug, instrument};
|
||||
|
||||
|
|
@ -535,9 +536,26 @@ pub(crate) fn check_generic_arg_count(
|
|||
.map(|param| param.name)
|
||||
.collect();
|
||||
if constraint_names == param_names {
|
||||
let has_assoc_ty_with_same_name =
|
||||
if let DefKind::Trait = cx.tcx().def_kind(def_id) {
|
||||
gen_args.constraints.iter().any(|constraint| {
|
||||
traits::supertrait_def_ids(cx.tcx(), def_id).any(|trait_did| {
|
||||
cx.probe_trait_that_defines_assoc_item(
|
||||
trait_did,
|
||||
ty::AssocTag::Type,
|
||||
constraint.ident,
|
||||
)
|
||||
})
|
||||
})
|
||||
} else {
|
||||
false
|
||||
};
|
||||
// We set this to true and delay emitting `WrongNumberOfGenericArgs`
|
||||
// to provide a succinct error for cases like issue #113073
|
||||
all_params_are_binded = true;
|
||||
// to provide a succinct error for cases like issue #113073,
|
||||
// but only if when we don't have any assoc type with the same name with a
|
||||
// generic arg. Otherwise it will cause an ICE due to a delayed error because we
|
||||
// don't have any error other than `WrongNumberOfGenericArgs`.
|
||||
all_params_are_binded = !has_assoc_ty_with_same_name;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,17 @@
|
|||
// A regression test for https://github.com/rust-lang/rust/issues/148121
|
||||
|
||||
pub trait Super<X> {
|
||||
type X;
|
||||
}
|
||||
|
||||
pub trait Zelf<X>: Super<X> {}
|
||||
|
||||
pub trait A {}
|
||||
|
||||
impl A for dyn Super<X = ()> {}
|
||||
//~^ ERROR: trait takes 1 generic argument but 0 generic arguments were supplied
|
||||
|
||||
impl A for dyn Zelf<X = ()> {}
|
||||
//~^ ERROR: trait takes 1 generic argument but 0 generic arguments were supplied
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
error[E0107]: trait takes 1 generic argument but 0 generic arguments were supplied
|
||||
--> $DIR/assoc-type-bounds-with-the-same-name-with-lacking-generic-arg-148121.rs:11:16
|
||||
|
|
||||
LL | impl A for dyn Super<X = ()> {}
|
||||
| ^^^^^ expected 1 generic argument
|
||||
|
|
||||
note: trait defined here, with 1 generic parameter: `X`
|
||||
--> $DIR/assoc-type-bounds-with-the-same-name-with-lacking-generic-arg-148121.rs:3:11
|
||||
|
|
||||
LL | pub trait Super<X> {
|
||||
| ^^^^^ -
|
||||
help: add missing generic argument
|
||||
|
|
||||
LL | impl A for dyn Super<X, X = ()> {}
|
||||
| ++
|
||||
|
||||
error[E0107]: trait takes 1 generic argument but 0 generic arguments were supplied
|
||||
--> $DIR/assoc-type-bounds-with-the-same-name-with-lacking-generic-arg-148121.rs:14:16
|
||||
|
|
||||
LL | impl A for dyn Zelf<X = ()> {}
|
||||
| ^^^^ expected 1 generic argument
|
||||
|
|
||||
note: trait defined here, with 1 generic parameter: `X`
|
||||
--> $DIR/assoc-type-bounds-with-the-same-name-with-lacking-generic-arg-148121.rs:7:11
|
||||
|
|
||||
LL | pub trait Zelf<X>: Super<X> {}
|
||||
| ^^^^ -
|
||||
help: add missing generic argument
|
||||
|
|
||||
LL | impl A for dyn Zelf<X, X = ()> {}
|
||||
| ++
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0107`.
|
||||
Loading…
Add table
Add a link
Reference in a new issue