Rollup merge of #109423 - fmease:iat-selection-erase-regions-in-self-ty, r=compiler-errors
Use region-erased self type during IAT selection
Split off from #109410 as discussed.
Fixes #109299.
Re UI test: I use a reproducer of #109299 that contains a name resolution error instead of reproducer [`regionck-2.rs`](fc7ed4af16/tests/ui/associated-inherent-types/regionck-2.rs
) (as found in the `AliasKind::Inherent` PR) since it would (incorrectly) pass typeck in this PR due to the lack of regionck and I'd rather not make *that* a regression test (with or without `known-bug`).
``@rustbot`` label F-inherent_associated_types
r? ``@compiler-errors``
This commit is contained in:
commit
b22db3fca4
5 changed files with 101 additions and 31 deletions
|
@ -31,6 +31,7 @@ use rustc_infer::infer::{InferCtxt, TyCtxtInferExt};
|
||||||
use rustc_infer::traits::ObligationCause;
|
use rustc_infer::traits::ObligationCause;
|
||||||
use rustc_middle::infer::unify_key::{ConstVariableOrigin, ConstVariableOriginKind};
|
use rustc_middle::infer::unify_key::{ConstVariableOrigin, ConstVariableOriginKind};
|
||||||
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::DynKind;
|
use rustc_middle::ty::DynKind;
|
||||||
use rustc_middle::ty::GenericParamDefKind;
|
use rustc_middle::ty::GenericParamDefKind;
|
||||||
|
@ -2225,47 +2226,66 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||||
|
|
||||||
let param_env = tcx.param_env(block.owner.to_def_id());
|
let param_env = tcx.param_env(block.owner.to_def_id());
|
||||||
let cause = ObligationCause::misc(span, block.owner.def_id);
|
let cause = ObligationCause::misc(span, block.owner.def_id);
|
||||||
|
|
||||||
let mut fulfillment_errors = Vec::new();
|
let mut fulfillment_errors = Vec::new();
|
||||||
let mut applicable_candidates: Vec<_> = candidates
|
let mut applicable_candidates: Vec<_> = infcx.probe(|_| {
|
||||||
.iter()
|
let universe = infcx.create_next_universe();
|
||||||
.filter_map(|&(impl_, (assoc_item, def_scope))| {
|
|
||||||
infcx.probe(|_| {
|
|
||||||
let ocx = ObligationCtxt::new_in_snapshot(&infcx);
|
|
||||||
|
|
||||||
let impl_ty = tcx.type_of(impl_);
|
// Regions are not considered during selection.
|
||||||
let impl_substs = infcx.fresh_item_substs(impl_);
|
let self_ty = tcx.replace_escaping_bound_vars_uncached(
|
||||||
let impl_ty = impl_ty.subst(tcx, impl_substs);
|
self_ty,
|
||||||
let impl_ty = ocx.normalize(&cause, param_env, impl_ty);
|
FnMutDelegate {
|
||||||
|
regions: &mut |_| tcx.lifetimes.re_erased,
|
||||||
|
types: &mut |bv| {
|
||||||
|
tcx.mk_placeholder(ty::PlaceholderType { universe, name: bv.kind })
|
||||||
|
},
|
||||||
|
consts: &mut |bv, ty| {
|
||||||
|
tcx.mk_const(ty::PlaceholderConst { universe, name: bv }, ty)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
// Check that the Self-types can be related.
|
candidates
|
||||||
// FIXME(fmease): Should we use `eq` here?
|
.iter()
|
||||||
ocx.sup(&ObligationCause::dummy(), param_env, impl_ty, self_ty).ok()?;
|
.filter_map(|&(impl_, (assoc_item, def_scope))| {
|
||||||
|
infcx.probe(|_| {
|
||||||
|
let ocx = ObligationCtxt::new_in_snapshot(&infcx);
|
||||||
|
|
||||||
// Check whether the impl imposes obligations we have to worry about.
|
let impl_ty = tcx.type_of(impl_);
|
||||||
let impl_bounds = tcx.predicates_of(impl_);
|
let impl_substs = infcx.fresh_item_substs(impl_);
|
||||||
let impl_bounds = impl_bounds.instantiate(tcx, impl_substs);
|
let impl_ty = impl_ty.subst(tcx, impl_substs);
|
||||||
|
let impl_ty = ocx.normalize(&cause, param_env, impl_ty);
|
||||||
|
|
||||||
let impl_bounds = ocx.normalize(&cause, param_env, impl_bounds);
|
// Check that the Self-types can be related.
|
||||||
|
// FIXME(fmease): Should we use `eq` here?
|
||||||
|
ocx.sup(&ObligationCause::dummy(), param_env, impl_ty, self_ty).ok()?;
|
||||||
|
|
||||||
let impl_obligations = traits::predicates_for_generics(
|
// Check whether the impl imposes obligations we have to worry about.
|
||||||
|_, _| cause.clone(),
|
let impl_bounds = tcx.predicates_of(impl_);
|
||||||
param_env,
|
let impl_bounds = impl_bounds.instantiate(tcx, impl_substs);
|
||||||
impl_bounds,
|
|
||||||
);
|
|
||||||
|
|
||||||
ocx.register_obligations(impl_obligations);
|
let impl_bounds = ocx.normalize(&cause, param_env, impl_bounds);
|
||||||
|
|
||||||
let mut errors = ocx.select_where_possible();
|
let impl_obligations = traits::predicates_for_generics(
|
||||||
if !errors.is_empty() {
|
|_, _| cause.clone(),
|
||||||
fulfillment_errors.append(&mut errors);
|
param_env,
|
||||||
return None;
|
impl_bounds,
|
||||||
}
|
);
|
||||||
|
|
||||||
// FIXME(fmease): Unsolved vars can escape this InferCtxt snapshot.
|
ocx.register_obligations(impl_obligations);
|
||||||
Some((assoc_item, def_scope, infcx.resolve_vars_if_possible(impl_substs)))
|
|
||||||
|
let mut errors = ocx.select_where_possible();
|
||||||
|
if !errors.is_empty() {
|
||||||
|
fulfillment_errors.append(&mut errors);
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
|
// FIXME(fmease): Unsolved vars can escape this InferCtxt snapshot.
|
||||||
|
Some((assoc_item, def_scope, infcx.resolve_vars_if_possible(impl_substs)))
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
.collect()
|
||||||
.collect();
|
});
|
||||||
|
|
||||||
if applicable_candidates.len() > 1 {
|
if applicable_candidates.len() > 1 {
|
||||||
return Err(self.complain_about_ambiguous_inherent_assoc_type(
|
return Err(self.complain_about_ambiguous_inherent_assoc_type(
|
||||||
|
|
12
tests/ui/associated-inherent-types/issue-109299-1.rs
Normal file
12
tests/ui/associated-inherent-types/issue-109299-1.rs
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
#![feature(inherent_associated_types, non_lifetime_binders, type_alias_impl_trait)]
|
||||||
|
#![allow(incomplete_features)]
|
||||||
|
|
||||||
|
struct Lexer<T>(T);
|
||||||
|
|
||||||
|
impl Lexer<i32> {
|
||||||
|
type Cursor = ();
|
||||||
|
}
|
||||||
|
|
||||||
|
type X = impl for<T> Fn() -> Lexer<T>::Cursor; //~ ERROR associated type `Cursor` not found for `Lexer<T>` in the current scope
|
||||||
|
|
||||||
|
fn main() {}
|
15
tests/ui/associated-inherent-types/issue-109299-1.stderr
Normal file
15
tests/ui/associated-inherent-types/issue-109299-1.stderr
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
error[E0220]: associated type `Cursor` not found for `Lexer<T>` in the current scope
|
||||||
|
--> $DIR/issue-109299-1.rs:10:40
|
||||||
|
|
|
||||||
|
LL | struct Lexer<T>(T);
|
||||||
|
| --------------- associated item `Cursor` not found for this struct
|
||||||
|
...
|
||||||
|
LL | type X = impl for<T> Fn() -> Lexer<T>::Cursor;
|
||||||
|
| ^^^^^^ associated item not found in `Lexer<T>`
|
||||||
|
|
|
||||||
|
= note: the associated type was found for
|
||||||
|
- `Lexer<i32>`
|
||||||
|
|
||||||
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0220`.
|
12
tests/ui/associated-inherent-types/issue-109299.rs
Normal file
12
tests/ui/associated-inherent-types/issue-109299.rs
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
#![feature(inherent_associated_types)]
|
||||||
|
#![allow(incomplete_features)]
|
||||||
|
|
||||||
|
struct Lexer<'d>(&'d ());
|
||||||
|
|
||||||
|
impl Lexer<'d> { //~ ERROR use of undeclared lifetime name `'d`
|
||||||
|
type Cursor = ();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test(_: Lexer::Cursor) {}
|
||||||
|
|
||||||
|
fn main() {}
|
11
tests/ui/associated-inherent-types/issue-109299.stderr
Normal file
11
tests/ui/associated-inherent-types/issue-109299.stderr
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
error[E0261]: use of undeclared lifetime name `'d`
|
||||||
|
--> $DIR/issue-109299.rs:6:12
|
||||||
|
|
|
||||||
|
LL | impl Lexer<'d> {
|
||||||
|
| - ^^ undeclared lifetime
|
||||||
|
| |
|
||||||
|
| help: consider introducing lifetime `'d` here: `<'d>`
|
||||||
|
|
||||||
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0261`.
|
Loading…
Add table
Add a link
Reference in a new issue