Rollup merge of #107803 - eggyal:do_not_bring_trait_alias_supertraits_into_scope, r=compiler-errors
Do not bring trait alias supertraits into scope Fixes #107747 cc #41517
This commit is contained in:
commit
16a4138387
@ -951,24 +951,38 @@ fn assemble_extension_candidates_for_trait(
|
|||||||
let trait_ref = self.tcx.mk_trait_ref(trait_def_id, trait_substs);
|
let trait_ref = self.tcx.mk_trait_ref(trait_def_id, trait_substs);
|
||||||
|
|
||||||
if self.tcx.is_trait_alias(trait_def_id) {
|
if self.tcx.is_trait_alias(trait_def_id) {
|
||||||
// For trait aliases, assume all supertraits are relevant.
|
// For trait aliases, recursively assume all explicitly named traits are relevant
|
||||||
let bounds = iter::once(ty::Binder::dummy(trait_ref));
|
for expansion in traits::expand_trait_aliases(
|
||||||
self.elaborate_bounds(bounds, |this, new_trait_ref, item| {
|
self.tcx,
|
||||||
let new_trait_ref = this.erase_late_bound_regions(new_trait_ref);
|
iter::once((ty::Binder::dummy(trait_ref), self.span)),
|
||||||
|
) {
|
||||||
|
let bound_trait_ref = expansion.trait_ref();
|
||||||
|
for item in self.impl_or_trait_item(bound_trait_ref.def_id()) {
|
||||||
|
if !self.has_applicable_self(&item) {
|
||||||
|
self.record_static_candidate(CandidateSource::Trait(
|
||||||
|
bound_trait_ref.def_id(),
|
||||||
|
));
|
||||||
|
} else {
|
||||||
|
let new_trait_ref = self.erase_late_bound_regions(bound_trait_ref);
|
||||||
|
|
||||||
let (xform_self_ty, xform_ret_ty) =
|
let (xform_self_ty, xform_ret_ty) = self.xform_self_ty(
|
||||||
this.xform_self_ty(&item, new_trait_ref.self_ty(), new_trait_ref.substs);
|
&item,
|
||||||
this.push_candidate(
|
new_trait_ref.self_ty(),
|
||||||
Candidate {
|
new_trait_ref.substs,
|
||||||
xform_self_ty,
|
);
|
||||||
xform_ret_ty,
|
self.push_candidate(
|
||||||
item,
|
Candidate {
|
||||||
import_ids: import_ids.clone(),
|
xform_self_ty,
|
||||||
kind: TraitCandidate(new_trait_ref),
|
xform_ret_ty,
|
||||||
},
|
item,
|
||||||
false,
|
import_ids: import_ids.clone(),
|
||||||
);
|
kind: TraitCandidate(new_trait_ref),
|
||||||
});
|
},
|
||||||
|
false,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
debug_assert!(self.tcx.is_trait(trait_def_id));
|
debug_assert!(self.tcx.is_trait(trait_def_id));
|
||||||
if self.tcx.trait_is_auto(trait_def_id) {
|
if self.tcx.trait_is_auto(trait_def_id) {
|
||||||
|
@ -0,0 +1,21 @@
|
|||||||
|
// Regression test for #107747: methods from trait alias supertraits were brought into scope
|
||||||
|
//
|
||||||
|
// check-pass
|
||||||
|
|
||||||
|
#![feature(trait_alias)]
|
||||||
|
|
||||||
|
use std::fmt;
|
||||||
|
|
||||||
|
trait Foo: fmt::Debug {}
|
||||||
|
trait Bar = Foo;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
struct Qux(bool);
|
||||||
|
|
||||||
|
impl fmt::Display for Qux {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
self.0.fmt(f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
Loading…
Reference in New Issue
Block a user