Avoid ICEing when associated type bound trait is missing
This commit is contained in:
parent
5b6f206d23
commit
3c8cf6d802
@ -652,13 +652,21 @@ fn bound_defines_assoc_item(&self, b: &hir::GenericBound<'_>, assoc_name: Ident)
|
||||
match b {
|
||||
hir::GenericBound::Trait(poly_trait_ref, _) => {
|
||||
let trait_ref = &poly_trait_ref.trait_ref;
|
||||
let trait_did = trait_ref.trait_def_id().unwrap();
|
||||
super_traits_of(self.tcx, trait_did).any(|trait_did| {
|
||||
self.tcx
|
||||
.associated_items(trait_did)
|
||||
.find_by_name_and_kind(self.tcx, assoc_name, ty::AssocKind::Type, trait_did)
|
||||
.is_some()
|
||||
})
|
||||
if let Some(trait_did) = trait_ref.trait_def_id() {
|
||||
super_traits_of(self.tcx, trait_did).any(|trait_did| {
|
||||
self.tcx
|
||||
.associated_items(trait_did)
|
||||
.find_by_name_and_kind(
|
||||
self.tcx,
|
||||
assoc_name,
|
||||
ty::AssocKind::Type,
|
||||
trait_did,
|
||||
)
|
||||
.is_some()
|
||||
})
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
_ => false,
|
||||
}
|
||||
|
@ -0,0 +1,10 @@
|
||||
#[allow(dead_code)]
|
||||
fn foo<M>(_m: M)
|
||||
where
|
||||
M::Item: Temp,
|
||||
//~^ ERROR cannot find trait `Temp` in this scope [E0405]
|
||||
//~| ERROR associated type `Item` not found for `M` [E0220]
|
||||
{
|
||||
}
|
||||
|
||||
fn main() {}
|
@ -0,0 +1,16 @@
|
||||
error[E0405]: cannot find trait `Temp` in this scope
|
||||
--> $DIR/missing-trait-bound-for-assoc-fails.rs:4:14
|
||||
|
|
||||
LL | M::Item: Temp,
|
||||
| ^^^^ not found in this scope
|
||||
|
||||
error[E0220]: associated type `Item` not found for `M`
|
||||
--> $DIR/missing-trait-bound-for-assoc-fails.rs:4:8
|
||||
|
|
||||
LL | M::Item: Temp,
|
||||
| ^^^^ associated type `Item` not found
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0220, E0405.
|
||||
For more information about an error, try `rustc --explain E0220`.
|
Loading…
Reference in New Issue
Block a user