Rollup merge of #72556 - matthew-mcallister:trait-alias-inherent-impl, r=estebank

Fix trait alias inherent impl resolution

Fixes #60021 and fixes #72415.

Obviously, the fix was very easy, but getting started with the testing and debugging rust compiler was an interesting experience. Now I can cross it off my bucket list!
This commit is contained in:
Ralf Jung 2020-06-15 09:57:24 +02:00 committed by GitHub
commit 3d41252fcc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 1 deletions

View File

@ -795,6 +795,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
fn assemble_inherent_candidates_from_param(&mut self, param_ty: ty::ParamTy) {
// FIXME: do we want to commit to this behavior for param bounds?
debug!("assemble_inherent_candidates_from_param(param_ty={:?})", param_ty);
let bounds =
self.param_env.caller_bounds.iter().filter_map(|predicate| match predicate.kind() {
@ -952,7 +953,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
import_ids: import_ids.clone(),
kind: TraitCandidate(new_trait_ref),
},
true,
false,
);
});
} else {

View File

@ -0,0 +1,19 @@
// check-pass
#![feature(trait_alias)]
trait SomeTrait {
fn map(&self) {}
}
impl<T> SomeTrait for Option<T> {}
trait SomeAlias = SomeTrait;
fn main() {
let x = Some(123);
// This should resolve to the trait impl for Option
Option::map(x, |z| z);
// This should resolve to the trait impl for SomeTrait
SomeTrait::map(&x);
}

View File

@ -0,0 +1,14 @@
// check-pass
#![feature(trait_alias)]
trait Bounded { const MAX: Self; }
impl Bounded for u32 {
// This should correctly resolve to the associated const in the inherent impl of u32.
const MAX: Self = u32::MAX;
}
trait Num = Bounded + Copy;
fn main() {}