Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix trait alias inherent impl resolution #72556

Merged
merged 1 commit into from
Jun 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/librustc_typeck/check/method/probe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, _) => {
Expand Down Expand Up @@ -949,7 +950,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
import_ids: import_ids.clone(),
kind: TraitCandidate(new_trait_ref),
},
true,
false,
);
});
} else {
Expand Down
19 changes: 19 additions & 0 deletions src/test/ui/traits/trait-alias/issue-60021-assoc-method-resolve.rs
Original file line number Diff line number Diff line change
@@ -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);
}
14 changes: 14 additions & 0 deletions src/test/ui/traits/trait-alias/issue-72415-assoc-const-resolve.rs
Original file line number Diff line number Diff line change
@@ -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() {}