Skip to content

Commit b7a5f3a

Browse files
Instantiate instead of erasing binder when probing param methods
1 parent f63ccaf commit b7a5f3a

File tree

3 files changed

+45
-9
lines changed

3 files changed

+45
-9
lines changed

compiler/rustc_hir_typeck/src/method/probe.rs

+18-9
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,14 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
792792
// a `&self` method will wind up with an argument type like `&dyn Trait`.
793793
let trait_ref = principal.with_self_ty(self.tcx, self_ty);
794794
self.elaborate_bounds(iter::once(trait_ref), |this, new_trait_ref, item| {
795+
if new_trait_ref.has_non_region_late_bound() {
796+
this.tcx.sess.delay_span_bug(
797+
this.span,
798+
"tried to select method from HRTB with non-lifetime bound vars",
799+
);
800+
return;
801+
}
802+
795803
let new_trait_ref = this.erase_late_bound_regions(new_trait_ref);
796804

797805
let (xform_self_ty, xform_ret_ty) =
@@ -842,18 +850,15 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
842850
});
843851

844852
self.elaborate_bounds(bounds, |this, poly_trait_ref, item| {
845-
let trait_ref = this.erase_late_bound_regions(poly_trait_ref);
853+
let trait_ref = this.instantiate_binder_with_fresh_vars(
854+
this.span,
855+
infer::LateBoundRegionConversionTime::FnCall,
856+
poly_trait_ref,
857+
);
846858

847859
let (xform_self_ty, xform_ret_ty) =
848860
this.xform_self_ty(item, trait_ref.self_ty(), trait_ref.substs);
849861

850-
// Because this trait derives from a where-clause, it
851-
// should not contain any inference variables or other
852-
// artifacts. This means it is safe to put into the
853-
// `WhereClauseCandidate` and (eventually) into the
854-
// `WhereClausePick`.
855-
assert!(!trait_ref.substs.needs_infer());
856-
857862
this.push_candidate(
858863
Candidate {
859864
xform_self_ty,
@@ -963,7 +968,11 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
963968
bound_trait_ref.def_id(),
964969
));
965970
} else {
966-
let new_trait_ref = self.erase_late_bound_regions(bound_trait_ref);
971+
let new_trait_ref = self.instantiate_binder_with_fresh_vars(
972+
self.span,
973+
infer::LateBoundRegionConversionTime::FnCall,
974+
bound_trait_ref,
975+
);
967976

968977
let (xform_self_ty, xform_ret_ty) =
969978
self.xform_self_ty(item, new_trait_ref.self_ty(), new_trait_ref.substs);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// check-pass
2+
3+
#![feature(non_lifetime_binders)]
4+
//~^ WARN the feature `non_lifetime_binders` is incomplete
5+
6+
trait Foo: for<T> Bar<T> {}
7+
8+
trait Bar<T> {
9+
fn method() -> T;
10+
}
11+
12+
fn x<T: Foo>() {
13+
let _: i32 = T::method();
14+
}
15+
16+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
warning: the feature `non_lifetime_binders` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/method-probe.rs:3:12
3+
|
4+
LL | #![feature(non_lifetime_binders)]
5+
| ^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: see issue #108185 <https://github.com/rust-lang/rust/issues/108185> for more information
8+
= note: `#[warn(incomplete_features)]` on by default
9+
10+
warning: 1 warning emitted
11+

0 commit comments

Comments
 (0)