iat selection: normalize self ty & completely erase bound vars
This commit is contained in:
parent
397641f3bd
commit
a995255cf5
4 changed files with 92 additions and 19 deletions
|
@ -26,10 +26,9 @@ use rustc_hir::def::{CtorOf, DefKind, Namespace, Res};
|
||||||
use rustc_hir::def_id::{DefId, LocalDefId};
|
use rustc_hir::def_id::{DefId, LocalDefId};
|
||||||
use rustc_hir::intravisit::{walk_generics, Visitor as _};
|
use rustc_hir::intravisit::{walk_generics, Visitor as _};
|
||||||
use rustc_hir::{GenericArg, GenericArgs, OpaqueTyOrigin};
|
use rustc_hir::{GenericArg, GenericArgs, OpaqueTyOrigin};
|
||||||
use rustc_infer::infer::{InferCtxt, TyCtxtInferExt};
|
use rustc_infer::infer::{InferCtxt, InferOk, TyCtxtInferExt};
|
||||||
use rustc_infer::traits::ObligationCause;
|
use rustc_infer::traits::ObligationCause;
|
||||||
use rustc_middle::middle::stability::AllowUnstable;
|
use rustc_middle::middle::stability::AllowUnstable;
|
||||||
use rustc_middle::ty::fold::FnMutDelegate;
|
|
||||||
use rustc_middle::ty::subst::{self, GenericArgKind, InternalSubsts, SubstsRef};
|
use rustc_middle::ty::subst::{self, GenericArgKind, InternalSubsts, SubstsRef};
|
||||||
use rustc_middle::ty::GenericParamDefKind;
|
use rustc_middle::ty::GenericParamDefKind;
|
||||||
use rustc_middle::ty::{self, Const, IsSuggestable, Ty, TyCtxt, TypeVisitableExt};
|
use rustc_middle::ty::{self, Const, IsSuggestable, Ty, TyCtxt, TypeVisitableExt};
|
||||||
|
@ -43,7 +42,10 @@ use rustc_trait_selection::traits::error_reporting::{
|
||||||
report_object_safety_error, suggestions::NextTypeParamName,
|
report_object_safety_error, suggestions::NextTypeParamName,
|
||||||
};
|
};
|
||||||
use rustc_trait_selection::traits::wf::object_region_bounds;
|
use rustc_trait_selection::traits::wf::object_region_bounds;
|
||||||
use rustc_trait_selection::traits::{self, astconv_object_safety_violations, ObligationCtxt};
|
use rustc_trait_selection::traits::{
|
||||||
|
self, astconv_object_safety_violations, NormalizeExt, ObligationCtxt,
|
||||||
|
};
|
||||||
|
use rustc_type_ir::fold::{TypeFoldable, TypeFolder, TypeSuperFoldable};
|
||||||
|
|
||||||
use smallvec::{smallvec, SmallVec};
|
use smallvec::{smallvec, SmallVec};
|
||||||
use std::collections::BTreeSet;
|
use std::collections::BTreeSet;
|
||||||
|
@ -2442,6 +2444,11 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||||
return Ok(None);
|
return Ok(None);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !tcx.features().inherent_associated_types {
|
||||||
|
tcx.sess
|
||||||
|
.delay_span_bug(span, "found inherent assoc type without the feature being gated");
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Select applicable inherent associated type candidates modulo regions.
|
// Select applicable inherent associated type candidates modulo regions.
|
||||||
//
|
//
|
||||||
|
@ -2465,23 +2472,53 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||||
|
|
||||||
let mut fulfillment_errors = Vec::new();
|
let mut fulfillment_errors = Vec::new();
|
||||||
let mut applicable_candidates: Vec<_> = infcx.probe(|_| {
|
let mut applicable_candidates: Vec<_> = infcx.probe(|_| {
|
||||||
let universe = infcx.create_next_universe();
|
|
||||||
|
|
||||||
// Regions are not considered during selection.
|
// Regions are not considered during selection.
|
||||||
// FIXME(non_lifetime_binders): Here we are "truncating" or "flattening" the universes
|
let self_ty = self_ty
|
||||||
// of type and const binders. Is that correct in the selection phase? See also #109505.
|
.fold_with(&mut BoundVarEraser { tcx, universe: infcx.create_next_universe() });
|
||||||
let self_ty = tcx.replace_escaping_bound_vars_uncached(
|
|
||||||
self_ty,
|
struct BoundVarEraser<'tcx> {
|
||||||
FnMutDelegate {
|
tcx: TyCtxt<'tcx>,
|
||||||
regions: &mut |_| tcx.lifetimes.re_erased,
|
universe: ty::UniverseIndex,
|
||||||
types: &mut |bv| {
|
}
|
||||||
tcx.mk_placeholder(ty::PlaceholderType { universe, bound: bv })
|
|
||||||
},
|
// FIXME(non_lifetime_binders): Don't assign the same universe to each placeholder.
|
||||||
consts: &mut |bv, ty| {
|
impl<'tcx> TypeFolder<TyCtxt<'tcx>> for BoundVarEraser<'tcx> {
|
||||||
tcx.mk_const(ty::PlaceholderConst { universe, bound: bv }, ty)
|
fn interner(&self) -> TyCtxt<'tcx> {
|
||||||
},
|
self.tcx
|
||||||
},
|
}
|
||||||
);
|
|
||||||
|
fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
|
||||||
|
if r.is_late_bound() { self.tcx.lifetimes.re_erased } else { r }
|
||||||
|
}
|
||||||
|
|
||||||
|
fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
|
||||||
|
match *ty.kind() {
|
||||||
|
ty::Bound(_, bv) => self.tcx.mk_placeholder(ty::PlaceholderType {
|
||||||
|
universe: self.universe,
|
||||||
|
bound: bv,
|
||||||
|
}),
|
||||||
|
_ => ty.super_fold_with(self),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn fold_const(
|
||||||
|
&mut self,
|
||||||
|
ct: ty::Const<'tcx>,
|
||||||
|
) -> <TyCtxt<'tcx> as rustc_type_ir::Interner>::Const {
|
||||||
|
assert!(!ct.ty().has_escaping_bound_vars());
|
||||||
|
|
||||||
|
match ct.kind() {
|
||||||
|
ty::ConstKind::Bound(_, bv) => self.tcx.mk_const(
|
||||||
|
ty::PlaceholderConst { universe: self.universe, bound: bv },
|
||||||
|
ct.ty(),
|
||||||
|
),
|
||||||
|
_ => ct.super_fold_with(self),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let InferOk { value: self_ty, obligations } =
|
||||||
|
infcx.at(&cause, param_env).normalize(self_ty);
|
||||||
|
|
||||||
candidates
|
candidates
|
||||||
.iter()
|
.iter()
|
||||||
|
@ -2489,6 +2526,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||||
.filter(|&(impl_, _)| {
|
.filter(|&(impl_, _)| {
|
||||||
infcx.probe(|_| {
|
infcx.probe(|_| {
|
||||||
let ocx = ObligationCtxt::new_in_snapshot(&infcx);
|
let ocx = ObligationCtxt::new_in_snapshot(&infcx);
|
||||||
|
ocx.register_obligations(obligations.clone());
|
||||||
|
|
||||||
let impl_substs = infcx.fresh_substs_for_item(span, impl_);
|
let impl_substs = infcx.fresh_substs_for_item(span, impl_);
|
||||||
let impl_ty = tcx.type_of(impl_).subst(tcx, impl_substs);
|
let impl_ty = tcx.type_of(impl_).subst(tcx, impl_substs);
|
||||||
|
|
14
tests/ui/associated-inherent-types/issue-111404-0.rs
Normal file
14
tests/ui/associated-inherent-types/issue-111404-0.rs
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
// check-pass
|
||||||
|
|
||||||
|
#![feature(inherent_associated_types)]
|
||||||
|
#![allow(incomplete_features)]
|
||||||
|
|
||||||
|
struct Foo<T>(T);
|
||||||
|
|
||||||
|
impl<'a> Foo<fn(&'a ())> {
|
||||||
|
type Assoc = &'a ();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn bar(_: for<'a> fn(Foo<fn(Foo<fn(&'a ())>::Assoc)>::Assoc)) {}
|
||||||
|
|
||||||
|
fn main() {}
|
13
tests/ui/associated-inherent-types/issue-111404-1.rs
Normal file
13
tests/ui/associated-inherent-types/issue-111404-1.rs
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
#![feature(inherent_associated_types)]
|
||||||
|
#![allow(incomplete_features)]
|
||||||
|
|
||||||
|
struct Foo<T>(T);
|
||||||
|
|
||||||
|
impl<'a> Foo<fn(&'a ())> {
|
||||||
|
type Assoc = &'a ();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn bar(_: fn(Foo<for<'b> fn(Foo<fn(&'b ())>::Assoc)>::Assoc)) {}
|
||||||
|
//~^ ERROR higher-ranked subtype error
|
||||||
|
|
||||||
|
fn main() {}
|
8
tests/ui/associated-inherent-types/issue-111404-1.stderr
Normal file
8
tests/ui/associated-inherent-types/issue-111404-1.stderr
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
error: higher-ranked subtype error
|
||||||
|
--> $DIR/issue-111404-1.rs:10:1
|
||||||
|
|
|
||||||
|
LL | fn bar(_: fn(Foo<for<'b> fn(Foo<fn(&'b ())>::Assoc)>::Assoc)) {}
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
error: aborting due to previous error
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue