diff options
| author | Matthew McAllister <matthew.mcallister.0@gmail.com> | 2020-05-24 17:54:30 -0700 |
|---|---|---|
| committer | Matthew McAllister <matthew.mcallister.0@gmail.com> | 2020-05-24 17:54:30 -0700 |
| commit | 98eb29cbba66561cf184f2d7f4277b38bd6b2aad (patch) | |
| tree | 1f29fd547585a58a761bf763cb17ecddb3410c62 | |
| parent | 963bf528292d8f97104515e32908e30c2467b6a8 (diff) | |
| download | rust-98eb29cbba66561cf184f2d7f4277b38bd6b2aad.tar.gz rust-98eb29cbba66561cf184f2d7f4277b38bd6b2aad.zip | |
Fix trait alias inherent impl resolution
Fixes #60021 and #72415.
3 files changed, 35 insertions, 1 deletions
diff --git a/src/librustc_typeck/check/method/probe.rs b/src/librustc_typeck/check/method/probe.rs index e21db9035e2..33290b5ca82 100644 --- a/src/librustc_typeck/check/method/probe.rs +++ b/src/librustc_typeck/check/method/probe.rs @@ -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 { ty::Predicate::Trait(ref trait_predicate, _) => { @@ -949,7 +950,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { import_ids: import_ids.clone(), kind: TraitCandidate(new_trait_ref), }, - true, + false, ); }); } else { diff --git a/src/test/ui/traits/trait-alias/issue-60021-assoc-method-resolve.rs b/src/test/ui/traits/trait-alias/issue-60021-assoc-method-resolve.rs new file mode 100644 index 00000000000..5e27ed3c646 --- /dev/null +++ b/src/test/ui/traits/trait-alias/issue-60021-assoc-method-resolve.rs @@ -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); +} diff --git a/src/test/ui/traits/trait-alias/issue-72415-assoc-const-resolve.rs b/src/test/ui/traits/trait-alias/issue-72415-assoc-const-resolve.rs new file mode 100644 index 00000000000..e49125d1024 --- /dev/null +++ b/src/test/ui/traits/trait-alias/issue-72415-assoc-const-resolve.rs @@ -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() {} |
