diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2023-04-09 23:40:03 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-04-09 23:40:03 +0200 |
| commit | 4e165c1c9923e19fa91ddcdb09fbc9d07f7c29da (patch) | |
| tree | 5d05d6b57e97f842e494f36c0e358ca677f7b45a /compiler | |
| parent | 39bf7777aab9ac1f6b0802cd52cd91d6e021aa91 (diff) | |
| parent | b7a5f3a41c6613033f0e6be9307c40e3174a9381 (diff) | |
| download | rust-4e165c1c9923e19fa91ddcdb09fbc9d07f7c29da.tar.gz rust-4e165c1c9923e19fa91ddcdb09fbc9d07f7c29da.zip | |
Rollup merge of #108843 - compiler-errors:non_lifetime_binders-method-probe, r=jackh726
Instantiate instead of erasing binder when probing param methods Fixes #108836 There is a really old comment saying that a `WhereClauseCandidate` probe candidate "should not contain any inference variables", but I'm not really confident that that comment applies anymore. In contrast, other candidates that we assemble during method probe contain inference variables in their substitutions (e.g. `InherentImplCandidate`)... Since this change is made only to support a nightly feature, I'm happy to gate the new behavior behind this feature flag or discuss it further. r? types
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_hir_typeck/src/method/probe.rs | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/compiler/rustc_hir_typeck/src/method/probe.rs b/compiler/rustc_hir_typeck/src/method/probe.rs index 0092bd2c6e6..4258a100d98 100644 --- a/compiler/rustc_hir_typeck/src/method/probe.rs +++ b/compiler/rustc_hir_typeck/src/method/probe.rs @@ -793,6 +793,14 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { // a `&self` method will wind up with an argument type like `&dyn Trait`. let trait_ref = principal.with_self_ty(self.tcx, self_ty); self.elaborate_bounds(iter::once(trait_ref), |this, new_trait_ref, item| { + if new_trait_ref.has_non_region_late_bound() { + this.tcx.sess.delay_span_bug( + this.span, + "tried to select method from HRTB with non-lifetime bound vars", + ); + return; + } + let new_trait_ref = this.erase_late_bound_regions(new_trait_ref); let (xform_self_ty, xform_ret_ty) = @@ -843,18 +851,15 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { }); self.elaborate_bounds(bounds, |this, poly_trait_ref, item| { - let trait_ref = this.erase_late_bound_regions(poly_trait_ref); + let trait_ref = this.instantiate_binder_with_fresh_vars( + this.span, + infer::LateBoundRegionConversionTime::FnCall, + poly_trait_ref, + ); let (xform_self_ty, xform_ret_ty) = this.xform_self_ty(item, trait_ref.self_ty(), trait_ref.substs); - // Because this trait derives from a where-clause, it - // should not contain any inference variables or other - // artifacts. This means it is safe to put into the - // `WhereClauseCandidate` and (eventually) into the - // `WhereClausePick`. - assert!(!trait_ref.substs.needs_infer()); - this.push_candidate( Candidate { xform_self_ty, @@ -964,7 +969,11 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { bound_trait_ref.def_id(), )); } else { - let new_trait_ref = self.erase_late_bound_regions(bound_trait_ref); + let new_trait_ref = self.instantiate_binder_with_fresh_vars( + self.span, + infer::LateBoundRegionConversionTime::FnCall, + bound_trait_ref, + ); let (xform_self_ty, xform_ret_ty) = self.xform_self_ty(item, new_trait_ref.self_ty(), new_trait_ref.substs); |
