Auto merge of #119261 - cjgillot:outlive-def-kind, r=compiler-errors
Do not fetch HIR in inferred_outlives_of. Small simplification allowed by https://github.com/rust-lang/rust/pull/119248
This commit is contained in:
commit
e4c626dd9a
1 changed files with 25 additions and 39 deletions
|
@ -1,5 +1,4 @@
|
||||||
use hir::Node;
|
use rustc_hir::def::DefKind;
|
||||||
use rustc_hir as hir;
|
|
||||||
use rustc_hir::def_id::LocalDefId;
|
use rustc_hir::def_id::LocalDefId;
|
||||||
use rustc_middle::query::Providers;
|
use rustc_middle::query::Providers;
|
||||||
use rustc_middle::ty::GenericArgKind;
|
use rustc_middle::ty::GenericArgKind;
|
||||||
|
@ -17,45 +16,32 @@ pub fn provide(providers: &mut Providers) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn inferred_outlives_of(tcx: TyCtxt<'_>, item_def_id: LocalDefId) -> &[(ty::Clause<'_>, Span)] {
|
fn inferred_outlives_of(tcx: TyCtxt<'_>, item_def_id: LocalDefId) -> &[(ty::Clause<'_>, Span)] {
|
||||||
let id = tcx.local_def_id_to_hir_id(item_def_id);
|
match tcx.def_kind(item_def_id) {
|
||||||
|
DefKind::Struct | DefKind::Enum | DefKind::Union => {
|
||||||
if matches!(tcx.def_kind(item_def_id), hir::def::DefKind::AnonConst)
|
let crate_map = tcx.inferred_outlives_crate(());
|
||||||
&& tcx.features().generic_const_exprs
|
crate_map.predicates.get(&item_def_id.to_def_id()).copied().unwrap_or(&[])
|
||||||
{
|
|
||||||
if tcx.hir().opt_const_param_default_param_def_id(id).is_some() {
|
|
||||||
// In `generics_of` we set the generics' parent to be our parent's parent which means that
|
|
||||||
// we lose out on the predicates of our actual parent if we dont return those predicates here.
|
|
||||||
// (See comment in `generics_of` for more information on why the parent shenanigans is necessary)
|
|
||||||
//
|
|
||||||
// struct Foo<'a, 'b, const N: usize = { ... }>(&'a &'b ());
|
|
||||||
// ^^^ ^^^^^^^ the def id we are calling
|
|
||||||
// ^^^ inferred_outlives_of on
|
|
||||||
// parent item we dont have set as the
|
|
||||||
// parent of generics returned by `generics_of`
|
|
||||||
//
|
|
||||||
// In the above code we want the anon const to have predicates in its param env for `'b: 'a`
|
|
||||||
let item_def_id = tcx.hir().get_parent_item(id);
|
|
||||||
// In the above code example we would be calling `inferred_outlives_of(Foo)` here
|
|
||||||
return tcx.inferred_outlives_of(item_def_id);
|
|
||||||
}
|
}
|
||||||
}
|
DefKind::AnonConst if tcx.features().generic_const_exprs => {
|
||||||
|
let id = tcx.local_def_id_to_hir_id(item_def_id);
|
||||||
match tcx.hir_node(id) {
|
if tcx.hir().opt_const_param_default_param_def_id(id).is_some() {
|
||||||
Node::Item(item) => match item.kind {
|
// In `generics_of` we set the generics' parent to be our parent's parent which means that
|
||||||
hir::ItemKind::Struct(..) | hir::ItemKind::Enum(..) | hir::ItemKind::Union(..) => {
|
// we lose out on the predicates of our actual parent if we dont return those predicates here.
|
||||||
let crate_map = tcx.inferred_outlives_crate(());
|
// (See comment in `generics_of` for more information on why the parent shenanigans is necessary)
|
||||||
|
//
|
||||||
let predicates =
|
// struct Foo<'a, 'b, const N: usize = { ... }>(&'a &'b ());
|
||||||
crate_map.predicates.get(&item_def_id.to_def_id()).copied().unwrap_or(&[]);
|
// ^^^ ^^^^^^^ the def id we are calling
|
||||||
|
// ^^^ inferred_outlives_of on
|
||||||
debug!("inferred_outlives_of({:?}) = {:?}", item_def_id, predicates);
|
// parent item we dont have set as the
|
||||||
|
// parent of generics returned by `generics_of`
|
||||||
predicates
|
//
|
||||||
|
// In the above code we want the anon const to have predicates in its param env for `'b: 'a`
|
||||||
|
let item_def_id = tcx.hir().get_parent_item(id);
|
||||||
|
// In the above code example we would be calling `inferred_outlives_of(Foo)` here
|
||||||
|
tcx.inferred_outlives_of(item_def_id)
|
||||||
|
} else {
|
||||||
|
&[]
|
||||||
}
|
}
|
||||||
|
}
|
||||||
_ => &[],
|
|
||||||
},
|
|
||||||
|
|
||||||
_ => &[],
|
_ => &[],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue