1use std::assert_matches;
2
3use hir::Node;
4use rustc_attr_ir::find_attr;
5use rustc_data_structures::fx::FxIndexSet;
6use rustc_hir as hir;
7use rustc_hir::def::DefKind;
8use rustc_hir::def_id::{DefId, LocalDefId};
9use rustc_middle::ty::{
10 self, GenericClauses, ImplTraitInTraitData, IncludeSizedImplicitBounds, Ty, TyCtxt,
11 TypeVisitable, TypeVisitor, Upcast,
12};
13use rustc_span::{DUMMY_SP, Ident, Span, bug, span_bug};
14use tracing::{debug, instrument, trace};
15
16use super::item_bounds::explicit_item_bounds_with_filter;
17use crate::collect::ItemCtxt;
18use crate::constrained_generic_params as cgp;
19use crate::delegation::inherit_clauses_for_delegation_item;
20use crate::hir_ty_lowering::{
21 HirTyLowerer, ImpliedBoundsContext, OverlappingAsssocItemConstraints, PredicateFilter,
22 RegionInferReason,
23};
24
25{}
#[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("clauses_of",
"rustc_hir_analysis::collect::clauses_of",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/collect/clauses_of.rs"),
::tracing_core::__macro_support::Option::Some(28u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::clauses_of"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("def_id")
}> =
::tracing::__macro_support::FieldName::new("def_id");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&def_id)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: ty::GenericClauses<'_> = loop {};
return __tracing_attr_fake_return;
}
{
let mut result = tcx.explicit_clauses_of(def_id);
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/collect/clauses_of.rs:31",
"rustc_hir_analysis::collect::clauses_of",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/collect/clauses_of.rs"),
::tracing_core::__macro_support::Option::Some(31u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::clauses_of"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("clauses_of: explicit_clauses_of({0:?}) = {1:?}",
def_id, result) as &dyn ::tracing::field::Value))])
});
} else { ; }
};
let inferred_outlives = tcx.inferred_outlives_of(def_id);
if !inferred_outlives.is_empty() {
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/collect/clauses_of.rs:35",
"rustc_hir_analysis::collect::clauses_of",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/collect/clauses_of.rs"),
::tracing_core::__macro_support::Option::Some(35u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::clauses_of"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("clauses_of: inferred_outlives_of({0:?}) = {1:?}",
def_id, inferred_outlives) as
&dyn ::tracing::field::Value))])
});
} else { ; }
};
let inferred_outlives_iter =
inferred_outlives.iter().map(|(clause, span)|
((*clause).upcast(tcx), *span));
if result.clauses.is_empty() {
result.clauses =
tcx.arena.alloc_from_iter(inferred_outlives_iter);
} else {
result.clauses =
tcx.arena.alloc_from_iter(result.clauses.into_iter().copied().chain(inferred_outlives_iter));
}
}
if tcx.is_trait(def_id) {
let span = DUMMY_SP;
result.clauses =
tcx.arena.alloc_from_iter(result.clauses.iter().copied().chain(std::iter::once((ty::TraitRef::identity(tcx,
def_id).upcast(tcx), span))));
}
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/collect/clauses_of.rs:76",
"rustc_hir_analysis::collect::clauses_of",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/collect/clauses_of.rs"),
::tracing_core::__macro_support::Option::Some(76u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::clauses_of"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("clauses_of({0:?}) = {1:?}",
def_id, result) as &dyn ::tracing::field::Value))])
});
} else { ; }
};
result
}
}
}#[instrument(level = "debug", skip(tcx))]
29pub(super) fn clauses_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericClauses<'_> {
30 let mut result = tcx.explicit_clauses_of(def_id);
31 debug!("clauses_of: explicit_clauses_of({:?}) = {:?}", def_id, result);
32
33 let inferred_outlives = tcx.inferred_outlives_of(def_id);
34 if !inferred_outlives.is_empty() {
35 debug!("clauses_of: inferred_outlives_of({:?}) = {:?}", def_id, inferred_outlives,);
36 let inferred_outlives_iter =
37 inferred_outlives.iter().map(|(clause, span)| ((*clause).upcast(tcx), *span));
38 if result.clauses.is_empty() {
39 result.clauses = tcx.arena.alloc_from_iter(inferred_outlives_iter);
40 } else {
41 result.clauses = tcx
42 .arena
43 .alloc_from_iter(result.clauses.into_iter().copied().chain(inferred_outlives_iter));
44 }
45 }
46
47 if tcx.is_trait(def_id) {
48 let span = DUMMY_SP;
66
67 result.clauses = tcx.arena.alloc_from_iter(
68 result
69 .clauses
70 .iter()
71 .copied()
72 .chain(std::iter::once((ty::TraitRef::identity(tcx, def_id).upcast(tcx), span))),
73 );
74 }
75
76 debug!("clauses_of({:?}) = {:?}", def_id, result);
77 result
78}
79
80{}
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() || { false }
{
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("gather_explicit_clauses_of",
"rustc_hir_analysis::collect::clauses_of",
::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/collect/clauses_of.rs"),
::tracing_core::__macro_support::Option::Some(82u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::clauses_of"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("def_id")
}> =
::tracing::__macro_support::FieldName::new("def_id");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::TRACE <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&def_id)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[allow(clippy :: redundant_closure_call)]
let x =
(move ||
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy
:: needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: ty::GenericClauses<'_> =
loop {};
return __tracing_attr_fake_return;
}
{
use rustc_hir::*;
match tcx.opt_rpitit_info(def_id.to_def_id()) {
Some(ImplTraitInTraitData::Trait { fn_def_id, .. }) => {
let mut clauses = Vec::new();
let identity_args =
ty::GenericArgs::identity_for_item(tcx, def_id);
clauses.extend(tcx.explicit_clauses_of(fn_def_id).instantiate_own(tcx,
identity_args).map(|(c, s)| (c.skip_norm_wip(), s)));
compute_bidirectional_outlives_clauses(tcx,
&tcx.generics_of(def_id.to_def_id()).own_params[tcx.generics_of(fn_def_id).own_params.len()..],
&mut clauses);
return ty::GenericClauses {
parent: Some(tcx.local_parent(def_id).to_def_id()),
clauses: tcx.arena.alloc_from_iter(clauses),
};
}
Some(ImplTraitInTraitData::Impl { fn_def_id }) => {
let trait_item_def_id = tcx.trait_item_of(def_id).unwrap();
let trait_assoc_clauses =
tcx.explicit_clauses_of(trait_item_def_id);
let impl_assoc_identity_args =
ty::GenericArgs::identity_for_item(tcx, def_id);
let impl_def_id = tcx.parent(fn_def_id);
let impl_trait_ref_args =
tcx.impl_trait_ref(impl_def_id).instantiate_identity().skip_norm_wip().args;
let impl_assoc_args =
impl_assoc_identity_args.rebase_onto(tcx, impl_def_id,
impl_trait_ref_args);
let impl_clauses =
trait_assoc_clauses.instantiate_own(tcx,
impl_assoc_args).map(|(c, s)| (c.skip_norm_wip(), s));
return ty::GenericClauses {
parent: Some(impl_def_id),
clauses: tcx.arena.alloc_from_iter(impl_clauses),
};
}
None => {}
}
let hir_id = tcx.local_def_id_to_hir_id(def_id);
let node = tcx.hir_node(hir_id);
if let Some(sig) = node.fn_sig() &&
let Some(sig_id) = sig.decl.opt_delegation_sig_id() {
return inherit_clauses_for_delegation_item(tcx, def_id,
sig_id);
}
let mut is_trait = None;
let mut is_default_impl_trait = None;
let icx = ItemCtxt::new(tcx, def_id);
const NO_GENERICS: &hir::Generics<'_> =
hir::Generics::empty();
let mut clauses: FxIndexSet<(ty::Clause<'_>, Span)> =
FxIndexSet::default();
let hir_generics = node.generics().unwrap_or(NO_GENERICS);
if let Node::Item(item) = node {
match item.kind {
ItemKind::Impl(impl_) => {
if let Some(of_trait) = impl_.of_trait &&
of_trait.defaultness.is_default() {
is_default_impl_trait =
Some(ty::Binder::dummy(tcx.impl_trait_ref(def_id).instantiate_identity().skip_norm_wip()));
}
}
ItemKind::Trait { bounds: self_bounds, .. } |
ItemKind::TraitAlias(_, _, _, self_bounds) => {
is_trait = Some((self_bounds, item.span));
}
_ => {}
}
};
let generics = tcx.generics_of(def_id);
if let Some((self_bounds, span)) = is_trait {
let mut bounds = Vec::new();
icx.lowerer().lower_bounds(tcx.types.self_param,
self_bounds, &mut bounds, ty::List::empty(),
PredicateFilter::All,
OverlappingAsssocItemConstraints::Allowed);
icx.lowerer().add_implicit_bounds(&mut bounds,
tcx.types.self_param, self_bounds,
ImpliedBoundsContext::TraitDef(def_id), span,
IncludeSizedImplicitBounds::Yes);
clauses.extend(bounds);
}
if let Some(trait_ref) = is_default_impl_trait {
clauses.insert((trait_ref.upcast(tcx),
tcx.def_span(def_id)));
}
for param in hir_generics.params {
match param.kind {
GenericParamKind::Lifetime { .. } => (),
GenericParamKind::Type { .. } => {
let param_ty = icx.lowerer().lower_ty_param(param.hir_id);
let mut bounds = Vec::new();
icx.lowerer().add_implicit_bounds(&mut bounds, param_ty,
&[],
ImpliedBoundsContext::TyParam(param.def_id,
hir_generics.predicates), param.span,
IncludeSizedImplicitBounds::Yes);
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/collect/clauses_of.rs:240",
"rustc_hir_analysis::collect::clauses_of",
::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/collect/clauses_of.rs"),
::tracing_core::__macro_support::Option::Some(240u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::clauses_of"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("bounds")
}> =
::tracing::__macro_support::FieldName::new("bounds");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::TRACE <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&bounds)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
clauses.extend(bounds);
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/collect/clauses_of.rs:242",
"rustc_hir_analysis::collect::clauses_of",
::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/collect/clauses_of.rs"),
::tracing_core::__macro_support::Option::Some(242u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::clauses_of"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("clauses")
}> =
::tracing::__macro_support::FieldName::new("clauses");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::TRACE <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&clauses)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
}
hir::GenericParamKind::Const { .. } => {
let param_def_id = param.def_id.to_def_id();
let ct_ty =
tcx.type_of(param_def_id).instantiate_identity().skip_norm_wip();
let ct =
icx.lowerer().lower_const_param(param_def_id, param.hir_id);
clauses.insert((ty::ClauseKind::ConstArgHasType(ct,
ct_ty).upcast(tcx), param.span));
}
}
}
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/collect/clauses_of.rs:254",
"rustc_hir_analysis::collect::clauses_of",
::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/collect/clauses_of.rs"),
::tracing_core::__macro_support::Option::Some(254u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::clauses_of"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("clauses")
}> =
::tracing::__macro_support::FieldName::new("clauses");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::TRACE <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&clauses)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
for predicate in hir_generics.predicates {
where_predicate_clauses(&icx, predicate, &mut clauses);
}
if tcx.features().generic_const_exprs() {
clauses.extend(const_evaluatable_clauses_of(tcx, def_id,
&clauses));
}
let attrs =
tcx.hir_attrs(tcx.local_def_id_to_hir_id(def_id));
let allow_unstable_feature_attr =
{
'done:
{
for i in attrs {
#[allow(unused_imports)]
use ::rustc_attr_ir::AttributeKind::*;
let i: &::rustc_attr_ir::Attribute = i;
match i {
::rustc_attr_ir::Attribute::Parsed(UnstableFeatureBound(i))
=> {
break 'done Some(i);
}
::rustc_attr_ir::Attribute::Tool(..) |
::rustc_attr_ir::Attribute::DeriveHelper(..) =>
{}
#[deny(unreachable_patterns)]
_ => {}
}
}
None
}
}.map(|i| i.as_slice()).unwrap_or_default();
for (feat_name, span) in allow_unstable_feature_attr {
clauses.insert((ty::ClauseKind::UnstableFeature(*feat_name).upcast(tcx),
*span));
}
let mut clauses: Vec<_> = clauses.into_iter().collect();
if let Node::Item(&Item { kind: ItemKind::Impl(impl_), .. })
= node {
let self_ty =
tcx.type_of(def_id).instantiate_identity().skip_norm_wip();
let trait_ref =
impl_.of_trait.is_some().then(||
tcx.impl_trait_ref(def_id).instantiate_identity().skip_norm_wip());
cgp::setup_constraining_clauses(tcx, &mut clauses,
trait_ref,
&mut cgp::parameters_for_impl(tcx, self_ty, trait_ref));
}
if let Node::OpaqueTy(..) = node {
compute_bidirectional_outlives_clauses(tcx,
&generics.own_params, &mut clauses);
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/collect/clauses_of.rs:301",
"rustc_hir_analysis::collect::clauses_of",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/collect/clauses_of.rs"),
::tracing_core::__macro_support::Option::Some(301u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::clauses_of"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("clauses")
}> =
::tracing::__macro_support::FieldName::new("clauses");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&clauses)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
}
ty::GenericClauses {
parent: generics.parent,
clauses: tcx.arena.alloc_from_iter(clauses),
}
}
})();
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/collect/clauses_of.rs:82",
"rustc_hir_analysis::collect::clauses_of",
::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/collect/clauses_of.rs"),
::tracing_core::__macro_support::Option::Some(82u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::clauses_of"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("return")
}> =
::tracing::__macro_support::FieldName::new("return");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&x)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
x;#[instrument(level = "trace", skip(tcx), ret)]
83fn gather_explicit_clauses_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::GenericClauses<'_> {
84 use rustc_hir::*;
85
86 match tcx.opt_rpitit_info(def_id.to_def_id()) {
87 Some(ImplTraitInTraitData::Trait { fn_def_id, .. }) => {
88 let mut clauses = Vec::new();
89
90 let identity_args = ty::GenericArgs::identity_for_item(tcx, def_id);
95 clauses.extend(
96 tcx.explicit_clauses_of(fn_def_id)
97 .instantiate_own(tcx, identity_args)
98 .map(|(c, s)| (c.skip_norm_wip(), s)),
99 );
100
101 compute_bidirectional_outlives_clauses(
106 tcx,
107 &tcx.generics_of(def_id.to_def_id()).own_params
108 [tcx.generics_of(fn_def_id).own_params.len()..],
109 &mut clauses,
110 );
111
112 return ty::GenericClauses {
113 parent: Some(tcx.local_parent(def_id).to_def_id()),
114 clauses: tcx.arena.alloc_from_iter(clauses),
115 };
116 }
117
118 Some(ImplTraitInTraitData::Impl { fn_def_id }) => {
119 let trait_item_def_id = tcx.trait_item_of(def_id).unwrap();
120 let trait_assoc_clauses = tcx.explicit_clauses_of(trait_item_def_id);
121
122 let impl_assoc_identity_args = ty::GenericArgs::identity_for_item(tcx, def_id);
123 let impl_def_id = tcx.parent(fn_def_id);
124 let impl_trait_ref_args =
125 tcx.impl_trait_ref(impl_def_id).instantiate_identity().skip_norm_wip().args;
126
127 let impl_assoc_args =
128 impl_assoc_identity_args.rebase_onto(tcx, impl_def_id, impl_trait_ref_args);
129
130 let impl_clauses = trait_assoc_clauses
131 .instantiate_own(tcx, impl_assoc_args)
132 .map(|(c, s)| (c.skip_norm_wip(), s));
133
134 return ty::GenericClauses {
135 parent: Some(impl_def_id),
136 clauses: tcx.arena.alloc_from_iter(impl_clauses),
137 };
138 }
139
140 None => {}
141 }
142
143 let hir_id = tcx.local_def_id_to_hir_id(def_id);
144 let node = tcx.hir_node(hir_id);
145
146 if let Some(sig) = node.fn_sig()
147 && let Some(sig_id) = sig.decl.opt_delegation_sig_id()
148 {
149 return inherit_clauses_for_delegation_item(tcx, def_id, sig_id);
150 }
151
152 let mut is_trait = None;
153 let mut is_default_impl_trait = None;
154
155 let icx = ItemCtxt::new(tcx, def_id);
156
157 const NO_GENERICS: &hir::Generics<'_> = hir::Generics::empty();
158
159 let mut clauses: FxIndexSet<(ty::Clause<'_>, Span)> = FxIndexSet::default();
162
163 let hir_generics = node.generics().unwrap_or(NO_GENERICS);
164 if let Node::Item(item) = node {
165 match item.kind {
166 ItemKind::Impl(impl_) => {
167 if let Some(of_trait) = impl_.of_trait
168 && of_trait.defaultness.is_default()
169 {
170 is_default_impl_trait = Some(ty::Binder::dummy(
171 tcx.impl_trait_ref(def_id).instantiate_identity().skip_norm_wip(),
172 ));
173 }
174 }
175 ItemKind::Trait { bounds: self_bounds, .. }
176 | ItemKind::TraitAlias(_, _, _, self_bounds) => {
177 is_trait = Some((self_bounds, item.span));
178 }
179 _ => {}
180 }
181 };
182
183 let generics = tcx.generics_of(def_id);
184
185 if let Some((self_bounds, span)) = is_trait {
190 let mut bounds = Vec::new();
191 icx.lowerer().lower_bounds(
192 tcx.types.self_param,
193 self_bounds,
194 &mut bounds,
195 ty::List::empty(),
196 PredicateFilter::All,
197 OverlappingAsssocItemConstraints::Allowed,
198 );
199 icx.lowerer().add_implicit_bounds(
200 &mut bounds,
201 tcx.types.self_param,
202 self_bounds,
203 ImpliedBoundsContext::TraitDef(def_id),
204 span,
205 IncludeSizedImplicitBounds::Yes,
206 );
207 clauses.extend(bounds);
208 }
209
210 if let Some(trait_ref) = is_default_impl_trait {
219 clauses.insert((trait_ref.upcast(tcx), tcx.def_span(def_id)));
220 }
221
222 for param in hir_generics.params {
226 match param.kind {
227 GenericParamKind::Lifetime { .. } => (),
228 GenericParamKind::Type { .. } => {
229 let param_ty = icx.lowerer().lower_ty_param(param.hir_id);
230 let mut bounds = Vec::new();
231 icx.lowerer().add_implicit_bounds(
233 &mut bounds,
234 param_ty,
235 &[],
236 ImpliedBoundsContext::TyParam(param.def_id, hir_generics.predicates),
237 param.span,
238 IncludeSizedImplicitBounds::Yes,
239 );
240 trace!(?bounds);
241 clauses.extend(bounds);
242 trace!(?clauses);
243 }
244 hir::GenericParamKind::Const { .. } => {
245 let param_def_id = param.def_id.to_def_id();
246 let ct_ty = tcx.type_of(param_def_id).instantiate_identity().skip_norm_wip();
247 let ct = icx.lowerer().lower_const_param(param_def_id, param.hir_id);
248 clauses
249 .insert((ty::ClauseKind::ConstArgHasType(ct, ct_ty).upcast(tcx), param.span));
250 }
251 }
252 }
253
254 trace!(?clauses);
255 for predicate in hir_generics.predicates {
257 where_predicate_clauses(&icx, predicate, &mut clauses);
258 }
259
260 if tcx.features().generic_const_exprs() {
261 clauses.extend(const_evaluatable_clauses_of(tcx, def_id, &clauses));
262 }
263
264 let attrs = tcx.hir_attrs(tcx.local_def_id_to_hir_id(def_id));
265 let allow_unstable_feature_attr =
269 find_attr!(attrs, UnstableFeatureBound(i) => i).map(|i| i.as_slice()).unwrap_or_default();
270
271 for (feat_name, span) in allow_unstable_feature_attr {
272 clauses.insert((ty::ClauseKind::UnstableFeature(*feat_name).upcast(tcx), *span));
273 }
274
275 let mut clauses: Vec<_> = clauses.into_iter().collect();
276
277 if let Node::Item(&Item { kind: ItemKind::Impl(impl_), .. }) = node {
283 let self_ty = tcx.type_of(def_id).instantiate_identity().skip_norm_wip();
284 let trait_ref = impl_
285 .of_trait
286 .is_some()
287 .then(|| tcx.impl_trait_ref(def_id).instantiate_identity().skip_norm_wip());
288 cgp::setup_constraining_clauses(
289 tcx,
290 &mut clauses,
291 trait_ref,
292 &mut cgp::parameters_for_impl(tcx, self_ty, trait_ref),
293 );
294 }
295
296 if let Node::OpaqueTy(..) = node {
300 compute_bidirectional_outlives_clauses(tcx, &generics.own_params, &mut clauses);
301 debug!(?clauses);
302 }
303
304 ty::GenericClauses { parent: generics.parent, clauses: tcx.arena.alloc_from_iter(clauses) }
305}
306
307pub(super) fn where_predicate_clauses<'tcx>(
308 icx: &ItemCtxt<'tcx>,
309 predicate: &hir::WherePredicate<'_>,
310 clauses: &mut FxIndexSet<(ty::Clause<'tcx>, Span)>,
311) {
312 let tcx = icx.tcx;
313 match predicate.kind {
314 hir::WherePredicateKind::BoundPredicate(bound_pred) => {
315 let ty = icx.lowerer().lower_ty_maybe_return_type_notation(bound_pred.bounded_ty);
316 let bound_vars = tcx.late_bound_vars(predicate.hir_id);
317
318 if bound_pred.bounds.is_empty() {
320 if let ty::Param(_) = ty.kind() {
321 } else {
323 let span = bound_pred.bounded_ty.span;
327 let clause = ty::Binder::bind_with_vars(
328 ty::ClauseKind::WellFormed(ty.into()),
329 bound_vars,
330 );
331 clauses.insert((clause.upcast(tcx), span));
332 }
333 }
334
335 let mut bounds = Vec::new();
336 icx.lowerer().lower_bounds(
337 ty,
338 bound_pred.bounds,
339 &mut bounds,
340 bound_vars,
341 PredicateFilter::All,
342 OverlappingAsssocItemConstraints::Allowed,
343 );
344 clauses.extend(bounds);
345 }
346
347 hir::WherePredicateKind::RegionPredicate(region_pred) => {
348 let r1 = icx
349 .lowerer()
350 .lower_lifetime(region_pred.lifetime, RegionInferReason::RegionPredicate);
351 clauses.extend(region_pred.bounds.iter().map(|bound| {
352 let (r2, span) = match bound {
353 hir::GenericBound::Outlives(lt) => (
354 icx.lowerer().lower_lifetime(lt, RegionInferReason::RegionPredicate),
355 lt.ident.span,
356 ),
357 bound => {
358 ::rustc_span::macros::bug_impl(Some(bound.span()),
format_args!("lifetime param bounds must be outlives, but found {0:?}",
bound), Location::caller())span_bug!(
359 bound.span(),
360 "lifetime param bounds must be outlives, but found {bound:?}"
361 )
362 }
363 };
364 let clause = ty::ClauseKind::RegionOutlives(ty::OutlivesClause(r1, r2)).upcast(tcx);
365 (clause, span)
366 }))
367 }
368 }
369}
370
371fn compute_bidirectional_outlives_clauses<'tcx>(
374 tcx: TyCtxt<'tcx>,
375 opaque_own_params: &[ty::GenericParamDef],
376 clauses: &mut Vec<(ty::Clause<'tcx>, Span)>,
377) {
378 for param in opaque_own_params {
379 let orig_lifetime = tcx.map_opaque_lifetime_to_parent_lifetime(param.def_id.expect_local());
380 if let ty::ReEarlyParam(..) = orig_lifetime.kind() {
381 let dup_lifetime = ty::Region::new_early_param(
382 tcx,
383 ty::EarlyParamRegion { index: param.index, name: param.name },
384 );
385 let span = tcx.def_span(param.def_id);
386 clauses.push((
387 ty::ClauseKind::RegionOutlives(ty::OutlivesClause(orig_lifetime, dup_lifetime))
388 .upcast(tcx),
389 span,
390 ));
391 clauses.push((
392 ty::ClauseKind::RegionOutlives(ty::OutlivesClause(dup_lifetime, orig_lifetime))
393 .upcast(tcx),
394 span,
395 ));
396 }
397 }
398}
399
400{}
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() || { false }
{
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("const_evaluatable_clauses_of",
"rustc_hir_analysis::collect::clauses_of",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/collect/clauses_of.rs"),
::tracing_core::__macro_support::Option::Some(400u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::clauses_of"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("def_id")
}> =
::tracing::__macro_support::FieldName::new("def_id");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&def_id)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[allow(clippy :: redundant_closure_call)]
let x =
(move ||
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy
:: needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return:
FxIndexSet<(ty::Clause<'tcx>, Span)> = loop {};
return __tracing_attr_fake_return;
}
{
struct ConstCollector<'tcx> {
tcx: TyCtxt<'tcx>,
clauses: FxIndexSet<(ty::Clause<'tcx>, Span)>,
}
fn is_const_param_default(tcx: TyCtxt<'_>,
kind: ty::AliasConstKind<'_>) -> bool {
let ty::AliasConstKind::Anon { def_id } =
kind else { return false };
let Some(local) = def_id.as_local() else { return false };
let hir_id = tcx.local_def_id_to_hir_id(local);
let (_, parent_node) =
tcx.hir_parent_iter(hir_id).skip_while(|(_, n)|
#[allow(non_exhaustive_omitted_patterns)] match n {
Node::ConstArg(..) => true,
_ => false,
}).next().unwrap();
#[allow(non_exhaustive_omitted_patterns)]
match parent_node {
Node::GenericParam(hir::GenericParam {
kind: hir::GenericParamKind::Const { .. }, .. }) => true,
_ => false,
}
}
impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for
ConstCollector<'tcx> {
fn visit_const(&mut self, c: ty::Const<'tcx>) {
if let ty::ConstKind::Alias(_, alias_const) = c.kind() {
if is_const_param_default(self.tcx, alias_const.kind) {
return;
}
if alias_const.kind.is_direct_const(self.tcx) { return; }
let span = alias_const.kind.def_span(self.tcx);
self.clauses.insert((ty::ClauseKind::ConstEvaluatable(c).upcast(self.tcx),
span));
}
}
}
let hir_id = tcx.local_def_id_to_hir_id(def_id);
let node = tcx.hir_node(hir_id);
let mut collector =
ConstCollector { tcx, clauses: FxIndexSet::default() };
for (clause, _sp) in clauses {
clause.visit_with(&mut collector);
}
if let hir::Node::Item(item) = node &&
let hir::ItemKind::Impl(impl_) = item.kind {
if impl_.of_trait.is_some() {
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/collect/clauses_of.rs:465",
"rustc_hir_analysis::collect::clauses_of",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/collect/clauses_of.rs"),
::tracing_core::__macro_support::Option::Some(465u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::clauses_of"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("visit impl trait_ref")
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
let trait_ref = tcx.impl_trait_ref(def_id);
trait_ref.instantiate_identity().skip_norm_wip().visit_with(&mut collector);
}
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/collect/clauses_of.rs:470",
"rustc_hir_analysis::collect::clauses_of",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/collect/clauses_of.rs"),
::tracing_core::__macro_support::Option::Some(470u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::clauses_of"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("visit self_ty")
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
let self_ty = tcx.type_of(def_id);
self_ty.instantiate_identity().skip_norm_wip().visit_with(&mut collector);
}
if let Some(_) = tcx.hir_fn_sig_by_hir_id(hir_id) {
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/collect/clauses_of.rs:476",
"rustc_hir_analysis::collect::clauses_of",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/collect/clauses_of.rs"),
::tracing_core::__macro_support::Option::Some(476u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::clauses_of"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("visit fn sig")
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
let fn_sig = tcx.fn_sig(def_id);
let fn_sig = fn_sig.instantiate_identity().skip_norm_wip();
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/collect/clauses_of.rs:479",
"rustc_hir_analysis::collect::clauses_of",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/collect/clauses_of.rs"),
::tracing_core::__macro_support::Option::Some(479u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::clauses_of"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("fn_sig")
}> =
::tracing::__macro_support::FieldName::new("fn_sig");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&fn_sig)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
fn_sig.visit_with(&mut collector);
}
collector.clauses
}
})();
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/collect/clauses_of.rs:400",
"rustc_hir_analysis::collect::clauses_of",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/collect/clauses_of.rs"),
::tracing_core::__macro_support::Option::Some(400u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::clauses_of"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("return")
}> =
::tracing::__macro_support::FieldName::new("return");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&x)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
x;#[instrument(level = "debug", skip(tcx, clauses), ret)]
401fn const_evaluatable_clauses_of<'tcx>(
402 tcx: TyCtxt<'tcx>,
403 def_id: LocalDefId,
404 clauses: &FxIndexSet<(ty::Clause<'tcx>, Span)>,
405) -> FxIndexSet<(ty::Clause<'tcx>, Span)> {
406 struct ConstCollector<'tcx> {
407 tcx: TyCtxt<'tcx>,
408 clauses: FxIndexSet<(ty::Clause<'tcx>, Span)>,
409 }
410
411 fn is_const_param_default(tcx: TyCtxt<'_>, kind: ty::AliasConstKind<'_>) -> bool {
412 let ty::AliasConstKind::Anon { def_id } = kind else { return false };
413 let Some(local) = def_id.as_local() else { return false };
414
415 let hir_id = tcx.local_def_id_to_hir_id(local);
416 let (_, parent_node) = tcx
417 .hir_parent_iter(hir_id)
418 .skip_while(|(_, n)| matches!(n, Node::ConstArg(..)))
419 .next()
420 .unwrap();
421 matches!(
422 parent_node,
423 Node::GenericParam(hir::GenericParam { kind: hir::GenericParamKind::Const { .. }, .. })
424 )
425 }
426
427 impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for ConstCollector<'tcx> {
428 fn visit_const(&mut self, c: ty::Const<'tcx>) {
429 if let ty::ConstKind::Alias(_, alias_const) = c.kind() {
430 if is_const_param_default(self.tcx, alias_const.kind) {
431 return;
439 }
440
441 if alias_const.kind.is_direct_const(self.tcx) {
443 return;
444 }
445
446 let span = alias_const.kind.def_span(self.tcx);
447 self.clauses.insert((ty::ClauseKind::ConstEvaluatable(c).upcast(self.tcx), span));
448 }
449 }
450 }
451
452 let hir_id = tcx.local_def_id_to_hir_id(def_id);
453 let node = tcx.hir_node(hir_id);
454
455 let mut collector = ConstCollector { tcx, clauses: FxIndexSet::default() };
456
457 for (clause, _sp) in clauses {
458 clause.visit_with(&mut collector);
459 }
460
461 if let hir::Node::Item(item) = node
462 && let hir::ItemKind::Impl(impl_) = item.kind
463 {
464 if impl_.of_trait.is_some() {
465 debug!("visit impl trait_ref");
466 let trait_ref = tcx.impl_trait_ref(def_id);
467 trait_ref.instantiate_identity().skip_norm_wip().visit_with(&mut collector);
468 }
469
470 debug!("visit self_ty");
471 let self_ty = tcx.type_of(def_id);
472 self_ty.instantiate_identity().skip_norm_wip().visit_with(&mut collector);
473 }
474
475 if let Some(_) = tcx.hir_fn_sig_by_hir_id(hir_id) {
476 debug!("visit fn sig");
477 let fn_sig = tcx.fn_sig(def_id);
478 let fn_sig = fn_sig.instantiate_identity().skip_norm_wip();
479 debug!(?fn_sig);
480 fn_sig.visit_with(&mut collector);
481 }
482
483 collector.clauses
484}
485
486pub(super) fn trait_explicit_clauses_and_bounds(
487 tcx: TyCtxt<'_>,
488 def_id: LocalDefId,
489) -> ty::GenericClauses<'_> {
490 {
match (&tcx.def_kind(def_id), &DefKind::Trait) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val, ::core::option::Option::None);
}
}
}
};assert_eq!(tcx.def_kind(def_id), DefKind::Trait);
491 gather_explicit_clauses_of(tcx, def_id)
492}
493
494pub(super) fn explicit_clauses_of<'tcx>(
495 tcx: TyCtxt<'tcx>,
496 def_id: LocalDefId,
497) -> ty::GenericClauses<'tcx> {
498 let def_kind = tcx.def_kind(def_id);
499 if let DefKind::Trait = def_kind {
500 let clauses_and_bounds = tcx.trait_explicit_clauses_and_bounds(def_id);
503 let trait_identity_args = ty::GenericArgs::identity_for_item(tcx, def_id);
504
505 let is_assoc_item_ty = |ty: Ty<'tcx>| {
506 if let &ty::Alias(
516 _,
517 ty::AliasTy { kind: ty::Projection { def_id: projection_def_id }, args, .. },
518 ) = ty.kind()
519 {
520 args == trait_identity_args
521 && !tcx.is_impl_trait_in_trait(projection_def_id)
523 && tcx.parent(projection_def_id) == def_id.to_def_id()
524 } else {
525 false
526 }
527 };
528
529 let clauses: Vec<_> = clauses_and_bounds
530 .clauses
531 .iter()
532 .copied()
533 .filter(|(clause, _)| match clause.kind().skip_binder() {
534 ty::ClauseKind::Trait(tr) => !is_assoc_item_ty(tr.self_ty()),
535 ty::ClauseKind::Projection(proj) => {
536 !is_assoc_item_ty(proj.projection_term.self_ty())
537 }
538 ty::ClauseKind::TypeOutlives(outlives) => !is_assoc_item_ty(outlives.0),
539 _ => true,
540 })
541 .collect();
542 if clauses.len() == clauses_and_bounds.clauses.len() {
543 clauses_and_bounds
544 } else {
545 ty::GenericClauses {
546 parent: clauses_and_bounds.parent,
547 clauses: tcx.arena.alloc_slice(&clauses),
548 }
549 }
550 } else {
551 if def_kind == DefKind::AnonConst
552 && tcx.features().generic_const_exprs()
553 && let Some(defaulted_param_def_id) =
554 tcx.hir_opt_const_param_default_param_def_id(tcx.local_def_id_to_hir_id(def_id))
555 {
556 let parent_def_id = tcx.local_parent(def_id);
569 let parent_clauses = tcx.explicit_clauses_of(parent_def_id);
570
571 let filtered_clauses = parent_clauses
575 .clauses
576 .into_iter()
577 .filter(|(clause, _)| {
578 if let ty::ClauseKind::ConstArgHasType(ct, _) = clause.kind().skip_binder() {
579 match ct.kind() {
580 ty::ConstKind::Param(param_const) => {
581 let defaulted_param_idx = tcx
582 .generics_of(parent_def_id)
583 .param_def_id_to_index[&defaulted_param_def_id.to_def_id()];
584 param_const.index < defaulted_param_idx
585 }
586 _ => {
587 ::rustc_span::macros::bug_impl(None,
format_args!("`ConstArgHasType` in `clauses_of` that isn\'t a `Param` const"),
Location::caller())bug!("`ConstArgHasType` in `clauses_of` that isn't a `Param` const")
588 }
589 }
590 } else {
591 true
592 }
593 })
594 .cloned();
595 return GenericClauses {
596 parent: parent_clauses.parent,
597 clauses: { tcx.arena.alloc_from_iter(filtered_clauses) },
598 };
599 }
600 gather_explicit_clauses_of(tcx, def_id)
601 }
602}
603
604pub(super) fn explicit_super_clauses_of<'tcx>(
608 tcx: TyCtxt<'tcx>,
609 trait_def_id: LocalDefId,
610) -> ty::EarlyBinder<'tcx, &'tcx [(ty::Clause<'tcx>, Span)]> {
611 implied_clauses_with_filter(tcx, trait_def_id.to_def_id(), PredicateFilter::SelfOnly)
612}
613
614pub(super) fn explicit_supertraits_containing_assoc_item<'tcx>(
615 tcx: TyCtxt<'tcx>,
616 (trait_def_id, assoc_ident): (DefId, Ident),
617) -> ty::EarlyBinder<'tcx, &'tcx [(ty::Clause<'tcx>, Span)]> {
618 implied_clauses_with_filter(
619 tcx,
620 trait_def_id,
621 PredicateFilter::SelfTraitThatDefines(assoc_ident),
622 )
623}
624
625pub(super) fn explicit_implied_clauses_of<'tcx>(
626 tcx: TyCtxt<'tcx>,
627 trait_def_id: LocalDefId,
628) -> ty::EarlyBinder<'tcx, &'tcx [(ty::Clause<'tcx>, Span)]> {
629 implied_clauses_with_filter(
630 tcx,
631 trait_def_id.to_def_id(),
632 if tcx.is_trait_alias(trait_def_id.to_def_id()) {
633 PredicateFilter::All
634 } else {
635 PredicateFilter::SelfAndAssociatedTypeBounds
636 },
637 )
638}
639
640pub(super) fn implied_clauses_with_filter<'tcx>(
644 tcx: TyCtxt<'tcx>,
645 trait_def_id: DefId,
646 filter: PredicateFilter,
647) -> ty::EarlyBinder<'tcx, &'tcx [(ty::Clause<'tcx>, Span)]> {
648 let Some(trait_def_id) = trait_def_id.as_local() else {
649 {
match filter {
PredicateFilter::SelfTraitThatDefines(_) => {}
ref left_val => {
::core::panicking::assert_matches_failed(left_val,
"PredicateFilter::SelfTraitThatDefines(_)",
::core::option::Option::None);
}
}
};assert_matches!(filter, PredicateFilter::SelfTraitThatDefines(_));
652 return tcx.explicit_super_clauses_of(trait_def_id);
653 };
654
655 let Node::Item(item) = tcx.hir_node_by_def_id(trait_def_id) else {
656 ::rustc_span::macros::bug_impl(None,
format_args!("trait_def_id {0:?} is not an item", trait_def_id),
Location::caller());bug!("trait_def_id {trait_def_id:?} is not an item");
657 };
658
659 let (generics, superbounds) = match item.kind {
660 hir::ItemKind::Trait { generics, bounds: supertraits, .. } => (generics, supertraits),
661 hir::ItemKind::TraitAlias(_, _, generics, supertraits) => (generics, supertraits),
662 _ => ::rustc_span::macros::bug_impl(Some(item.span),
format_args!("super_clauses invoked on non-trait"), Location::caller())span_bug!(item.span, "super_clauses invoked on non-trait"),
663 };
664
665 let icx = ItemCtxt::new(tcx, trait_def_id);
666
667 let self_param_ty = tcx.types.self_param;
668 let mut bounds = Vec::new();
669 icx.lowerer().lower_bounds(
670 self_param_ty,
671 superbounds,
672 &mut bounds,
673 ty::List::empty(),
674 filter,
675 OverlappingAsssocItemConstraints::Allowed,
676 );
677 match filter {
678 PredicateFilter::All
679 | PredicateFilter::SelfOnly
680 | PredicateFilter::SelfTraitThatDefines(_)
681 | PredicateFilter::SelfAndAssociatedTypeBounds => {
682 icx.lowerer().add_implicit_bounds(
683 &mut bounds,
684 self_param_ty,
685 superbounds,
686 ImpliedBoundsContext::TraitDef(trait_def_id),
687 item.span,
688 IncludeSizedImplicitBounds::Yes,
689 );
690 }
691 PredicateFilter::ConstIfConst | PredicateFilter::SelfConstIfConst => {}
693 }
694
695 let where_bounds_that_match =
696 icx.probe_ty_param_bounds_in_generics(generics, item.owner_id.def_id, filter);
697
698 let implied_bounds =
700 &*tcx.arena.alloc_from_iter(bounds.into_iter().chain(where_bounds_that_match));
701 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/collect/clauses_of.rs:701",
"rustc_hir_analysis::collect::clauses_of",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/collect/clauses_of.rs"),
::tracing_core::__macro_support::Option::Some(701u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::clauses_of"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("implied_bounds")
}> =
::tracing::__macro_support::FieldName::new("implied_bounds");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&implied_bounds)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(?implied_bounds);
702
703 match filter {
708 PredicateFilter::SelfOnly => {
709 for &(clause, span) in implied_bounds {
710 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/collect/clauses_of.rs:710",
"rustc_hir_analysis::collect::clauses_of",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/collect/clauses_of.rs"),
::tracing_core::__macro_support::Option::Some(710u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::clauses_of"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("superbound: {0:?}",
clause) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("superbound: {:?}", clause);
711 if let ty::ClauseKind::Trait(bound) = clause.kind().skip_binder()
712 && bound.polarity == ty::ClausePolarity::Positive
713 {
714 tcx.at(span).explicit_super_clauses_of(bound.def_id());
715 }
716 }
717 }
718 PredicateFilter::All | PredicateFilter::SelfAndAssociatedTypeBounds => {
719 for &(clause, span) in implied_bounds {
720 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/collect/clauses_of.rs:720",
"rustc_hir_analysis::collect::clauses_of",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/collect/clauses_of.rs"),
::tracing_core::__macro_support::Option::Some(720u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::clauses_of"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("superbound: {0:?}",
clause) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("superbound: {:?}", clause);
721 if let ty::ClauseKind::Trait(bound) = clause.kind().skip_binder()
722 && bound.polarity == ty::ClausePolarity::Positive
723 {
724 tcx.at(span).explicit_implied_clauses_of(bound.def_id());
725 }
726 }
727 }
728 _ => {}
729 }
730
731 assert_only_contains_clauses_from(filter, implied_bounds, tcx.types.self_param);
732
733 ty::EarlyBinder::bind_iter(implied_bounds)
734}
735
736pub(super) fn assert_only_contains_clauses_from<'tcx>(
740 filter: PredicateFilter,
741 bounds: &'tcx [(ty::Clause<'tcx>, Span)],
742 ty: Ty<'tcx>,
743) {
744 if !truecfg!(debug_assertions) {
745 return;
746 }
747
748 match filter {
749 PredicateFilter::SelfOnly => {
750 for (clause, _) in bounds {
751 match clause.kind().skip_binder() {
752 ty::ClauseKind::Trait(trait_predicate) => {
753 {
match (&trait_predicate.self_ty(), &ty) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val,
::core::option::Option::Some(format_args!("expected `Self` predicate when computing `{0:?}` implied bounds: {1:?}",
filter, clause)));
}
}
}
};assert_eq!(
754 trait_predicate.self_ty(),
755 ty,
756 "expected `Self` predicate when computing \
757 `{filter:?}` implied bounds: {clause:?}"
758 );
759 }
760 ty::ClauseKind::Projection(projection_predicate) => {
761 {
match (&projection_predicate.self_ty(), &ty) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val,
::core::option::Option::Some(format_args!("expected `Self` predicate when computing `{0:?}` implied bounds: {1:?}",
filter, clause)));
}
}
}
};assert_eq!(
762 projection_predicate.self_ty(),
763 ty,
764 "expected `Self` predicate when computing \
765 `{filter:?}` implied bounds: {clause:?}"
766 );
767 }
768 ty::ClauseKind::TypeOutlives(outlives_clause) => {
769 {
match (&outlives_clause.0, &ty) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val,
::core::option::Option::Some(format_args!("expected `Self` clause when computing `{0:?}` implied bounds: {1:?}",
filter, clause)));
}
}
}
};assert_eq!(
770 outlives_clause.0, ty,
771 "expected `Self` clause when computing \
772 `{filter:?}` implied bounds: {clause:?}"
773 );
774 }
775 ty::ClauseKind::HostEffect(host_effect_clause) => {
776 {
match (&host_effect_clause.self_ty(), &ty) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val,
::core::option::Option::Some(format_args!("expected `Self` clause when computing `{0:?}` implied bounds: {1:?}",
filter, clause)));
}
}
}
};assert_eq!(
777 host_effect_clause.self_ty(),
778 ty,
779 "expected `Self` clause when computing \
780 `{filter:?}` implied bounds: {clause:?}"
781 );
782 }
783
784 ty::ClauseKind::RegionOutlives(_)
785 | ty::ClauseKind::ConstArgHasType(_, _)
786 | ty::ClauseKind::WellFormed(_)
787 | ty::ClauseKind::UnstableFeature(_)
788 | ty::ClauseKind::ConstEvaluatable(_) => {
789 ::rustc_span::macros::bug_impl(None,
format_args!("unexpected non-`Self` predicate when computing `{0:?}` implied bounds: {1:?}",
filter, clause), Location::caller());bug!(
790 "unexpected non-`Self` predicate when computing \
791 `{filter:?}` implied bounds: {clause:?}"
792 );
793 }
794 }
795 }
796 }
797 PredicateFilter::SelfTraitThatDefines(_) => {
798 for (clause, _) in bounds {
799 match clause.kind().skip_binder() {
800 ty::ClauseKind::Trait(trait_predicate) => {
801 {
match (&trait_predicate.self_ty(), &ty) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val,
::core::option::Option::Some(format_args!("expected `Self` predicate when computing `{0:?}` implied bounds: {1:?}",
filter, clause)));
}
}
}
};assert_eq!(
802 trait_predicate.self_ty(),
803 ty,
804 "expected `Self` predicate when computing \
805 `{filter:?}` implied bounds: {clause:?}"
806 );
807 }
808
809 ty::ClauseKind::Projection(_)
810 | ty::ClauseKind::TypeOutlives(_)
811 | ty::ClauseKind::RegionOutlives(_)
812 | ty::ClauseKind::ConstArgHasType(_, _)
813 | ty::ClauseKind::WellFormed(_)
814 | ty::ClauseKind::ConstEvaluatable(_)
815 | ty::ClauseKind::UnstableFeature(_)
816 | ty::ClauseKind::HostEffect(..) => {
817 ::rustc_span::macros::bug_impl(None,
format_args!("unexpected non-`Self` predicate when computing `{0:?}` implied bounds: {1:?}",
filter, clause), Location::caller());bug!(
818 "unexpected non-`Self` predicate when computing \
819 `{filter:?}` implied bounds: {clause:?}"
820 );
821 }
822 }
823 }
824 }
825 PredicateFilter::ConstIfConst => {
826 for (clause, _) in bounds {
827 match clause.kind().skip_binder() {
828 ty::ClauseKind::HostEffect(ty::HostEffectClause {
829 trait_ref: _,
830 constness: ty::BoundConstness::Maybe,
831 }) => {}
832 _ => {
833 ::rustc_span::macros::bug_impl(None,
format_args!("unexpected non-`HostEffect` clause when computing `{0:?}` implied bounds: {1:?}",
filter, clause), Location::caller());bug!(
834 "unexpected non-`HostEffect` clause when computing \
835 `{filter:?}` implied bounds: {clause:?}"
836 );
837 }
838 }
839 }
840 }
841 PredicateFilter::SelfConstIfConst => {
842 for (clause, _) in bounds {
843 match clause.kind().skip_binder() {
844 ty::ClauseKind::HostEffect(host_clause) => {
845 {
match (&host_clause.constness, &ty::BoundConstness::Maybe) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val,
::core::option::Option::Some(format_args!("expected `[const]` clause when computing `{0:?}` implied bounds: {1:?}",
filter, clause)));
}
}
}
};assert_eq!(
846 host_clause.constness,
847 ty::BoundConstness::Maybe,
848 "expected `[const]` clause when computing `{filter:?}` \
849 implied bounds: {clause:?}",
850 );
851 {
match (&host_clause.trait_ref.self_ty(), &ty) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val,
::core::option::Option::Some(format_args!("expected `Self` clause when computing `{0:?}` implied bounds: {1:?}",
filter, clause)));
}
}
}
};assert_eq!(
852 host_clause.trait_ref.self_ty(),
853 ty,
854 "expected `Self` clause when computing `{filter:?}` \
855 implied bounds: {clause:?}"
856 );
857 }
858 _ => {
859 ::rustc_span::macros::bug_impl(None,
format_args!("unexpected non-`HostEffect` clause when computing `{0:?}` implied bounds: {1:?}",
filter, clause), Location::caller());bug!(
860 "unexpected non-`HostEffect` clause when computing \
861 `{filter:?}` implied bounds: {clause:?}"
862 );
863 }
864 }
865 }
866 }
867 PredicateFilter::All | PredicateFilter::SelfAndAssociatedTypeBounds => {}
868 }
869}
870
871{}
#[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("type_param_clauses",
"rustc_hir_analysis::collect::clauses_of",
::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/collect/clauses_of.rs"),
::tracing_core::__macro_support::Option::Some(873u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::clauses_of"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("item_def_id")
}> =
::tracing::__macro_support::FieldName::new("item_def_id");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("def_id")
}> =
::tracing::__macro_support::FieldName::new("def_id");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("assoc_ident")
}> =
::tracing::__macro_support::FieldName::new("assoc_ident");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::TRACE <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&item_def_id)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&def_id)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&assoc_ident)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return:
ty::EarlyBinder<'tcx, &'tcx [(ty::Clause<'tcx>, Span)]> =
loop {};
return __tracing_attr_fake_return;
}
{
match tcx.opt_rpitit_info(item_def_id.to_def_id()) {
Some(ty::ImplTraitInTraitData::Trait { opaque_def_id, .. }) =>
{
return tcx.type_param_clauses((opaque_def_id.expect_local(),
def_id, assoc_ident));
}
Some(ty::ImplTraitInTraitData::Impl { .. }) => {
{
::core::panicking::panic_fmt(format_args!("internal error: entered unreachable code: {0}",
format_args!("should not be lowering bounds on RPITIT in impl")));
}
}
None => {}
}
let param_id = tcx.local_def_id_to_hir_id(def_id);
let param_owner = tcx.hir_ty_param_owner(def_id);
let parent =
if item_def_id == param_owner {
None
} else {
tcx.generics_of(item_def_id).parent.map(|def_id|
def_id.expect_local())
};
let result =
if let Some(parent) = parent {
let icx = ItemCtxt::new(tcx, parent);
icx.probe_ty_param_bounds(DUMMY_SP, def_id, assoc_ident)
} else { ty::EarlyBinder::bind_iter(&[] as &[_]) };
let mut extend = None;
let item_hir_id = tcx.local_def_id_to_hir_id(item_def_id);
let hir_node = tcx.hir_node(item_hir_id);
let Some(hir_generics) =
hir_node.generics() else { return result; };
if let Node::Item(item) = hir_node &&
let hir::ItemKind::Trait { .. } = item.kind &&
param_id == item_hir_id {
let identity_trait_ref =
ty::TraitRef::identity(tcx, item_def_id.to_def_id());
extend = Some((identity_trait_ref.upcast(tcx), item.span));
}
let icx = ItemCtxt::new(tcx, item_def_id);
let extra_clauses =
extend.into_iter().chain(icx.probe_ty_param_bounds_in_generics(hir_generics,
def_id,
PredicateFilter::SelfTraitThatDefines(assoc_ident)));
let bounds =
&*tcx.arena.alloc_from_iter(result.skip_binder().iter().copied().chain(extra_clauses));
let self_ty =
match tcx.def_kind(def_id) {
DefKind::TyParam =>
Ty::new_param(tcx,
tcx.generics_of(item_def_id).param_def_id_to_index(tcx,
def_id.to_def_id()).expect("expected generic param to be owned by item"),
tcx.item_name(def_id.to_def_id())),
DefKind::Trait | DefKind::TraitAlias =>
tcx.types.self_param,
_ => ::core::panicking::unreachable_default_msg(),
};
assert_only_contains_clauses_from(PredicateFilter::SelfTraitThatDefines(assoc_ident),
bounds, self_ty);
ty::EarlyBinder::bind_iter(bounds)
}
}
}#[instrument(level = "trace", skip(tcx))]
874pub(super) fn type_param_clauses<'tcx>(
875 tcx: TyCtxt<'tcx>,
876 (item_def_id, def_id, assoc_ident): (LocalDefId, LocalDefId, Ident),
877) -> ty::EarlyBinder<'tcx, &'tcx [(ty::Clause<'tcx>, Span)]> {
878 match tcx.opt_rpitit_info(item_def_id.to_def_id()) {
879 Some(ty::ImplTraitInTraitData::Trait { opaque_def_id, .. }) => {
880 return tcx.type_param_clauses((opaque_def_id.expect_local(), def_id, assoc_ident));
881 }
882 Some(ty::ImplTraitInTraitData::Impl { .. }) => {
883 unreachable!("should not be lowering bounds on RPITIT in impl")
884 }
885 None => {}
886 }
887
888 let param_id = tcx.local_def_id_to_hir_id(def_id);
893 let param_owner = tcx.hir_ty_param_owner(def_id);
894
895 let parent = if item_def_id == param_owner {
897 None
899 } else {
900 tcx.generics_of(item_def_id).parent.map(|def_id| def_id.expect_local())
901 };
902
903 let result = if let Some(parent) = parent {
904 let icx = ItemCtxt::new(tcx, parent);
905 icx.probe_ty_param_bounds(DUMMY_SP, def_id, assoc_ident)
906 } else {
907 ty::EarlyBinder::bind_iter(&[] as &[_])
908 };
909 let mut extend = None;
910
911 let item_hir_id = tcx.local_def_id_to_hir_id(item_def_id);
912
913 let hir_node = tcx.hir_node(item_hir_id);
914 let Some(hir_generics) = hir_node.generics() else {
915 return result;
916 };
917
918 if let Node::Item(item) = hir_node
919 && let hir::ItemKind::Trait { .. } = item.kind
920 && param_id == item_hir_id
922 {
923 let identity_trait_ref = ty::TraitRef::identity(tcx, item_def_id.to_def_id());
924 extend = Some((identity_trait_ref.upcast(tcx), item.span));
925 }
926
927 let icx = ItemCtxt::new(tcx, item_def_id);
928 let extra_clauses = extend.into_iter().chain(icx.probe_ty_param_bounds_in_generics(
929 hir_generics,
930 def_id,
931 PredicateFilter::SelfTraitThatDefines(assoc_ident),
932 ));
933
934 let bounds =
935 &*tcx.arena.alloc_from_iter(result.skip_binder().iter().copied().chain(extra_clauses));
936
937 let self_ty = match tcx.def_kind(def_id) {
939 DefKind::TyParam => Ty::new_param(
940 tcx,
941 tcx.generics_of(item_def_id)
942 .param_def_id_to_index(tcx, def_id.to_def_id())
943 .expect("expected generic param to be owned by item"),
944 tcx.item_name(def_id.to_def_id()),
945 ),
946 DefKind::Trait | DefKind::TraitAlias => tcx.types.self_param,
947 _ => unreachable!(),
948 };
949 assert_only_contains_clauses_from(
950 PredicateFilter::SelfTraitThatDefines(assoc_ident),
951 bounds,
952 self_ty,
953 );
954
955 ty::EarlyBinder::bind_iter(bounds)
956}
957
958impl<'tcx> ItemCtxt<'tcx> {
959 {}
#[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("probe_ty_param_bounds_in_generics",
"rustc_hir_analysis::collect::clauses_of",
::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/collect/clauses_of.rs"),
::tracing_core::__macro_support::Option::Some(964u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::collect::clauses_of"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("param_def_id")
}> =
::tracing::__macro_support::FieldName::new("param_def_id");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("filter")
}> =
::tracing::__macro_support::FieldName::new("filter");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::TRACE <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(¶m_def_id)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&filter)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: Vec<(ty::Clause<'tcx>, Span)> =
loop {};
return __tracing_attr_fake_return;
}
{
let mut bounds = Vec::new();
if let PredicateFilter::All = filter {
for param in hir_generics.params {
match param.kind {
hir::GenericParamKind::Type { .. } => {
let param_ty = self.lowerer().lower_ty_param(param.hir_id);
self.lowerer().add_implicit_bounds(&mut bounds, param_ty,
&[],
ImpliedBoundsContext::TyParam(param.def_id,
hir_generics.predicates), param.span,
IncludeSizedImplicitBounds::Yes);
}
hir::GenericParamKind::Lifetime { .. } |
hir::GenericParamKind::Const { .. } => {}
}
}
}
for predicate in hir_generics.predicates {
let hir_id = predicate.hir_id;
let hir::WherePredicateKind::BoundPredicate(predicate) =
predicate.kind else { continue; };
match filter {
_ if predicate.is_param_bound(param_def_id.to_def_id()) =>
{}
PredicateFilter::All => {}
PredicateFilter::SelfOnly |
PredicateFilter::SelfTraitThatDefines(_) |
PredicateFilter::SelfConstIfConst |
PredicateFilter::SelfAndAssociatedTypeBounds => continue,
PredicateFilter::ConstIfConst =>
::core::panicking::unreachable_default_msg(),
}
let bound_ty =
self.lowerer().lower_ty_maybe_return_type_notation(predicate.bounded_ty);
let bound_vars = self.tcx.late_bound_vars(hir_id);
self.lowerer().lower_bounds(bound_ty, predicate.bounds,
&mut bounds, bound_vars, filter,
OverlappingAsssocItemConstraints::Allowed);
}
bounds
}
}
}#[instrument(level = "trace", skip(self, hir_generics))]
965 fn probe_ty_param_bounds_in_generics(
966 &self,
967 hir_generics: &'tcx hir::Generics<'tcx>,
968 param_def_id: LocalDefId,
969 filter: PredicateFilter,
970 ) -> Vec<(ty::Clause<'tcx>, Span)> {
971 let mut bounds = Vec::new();
972
973 if let PredicateFilter::All = filter {
974 for param in hir_generics.params {
975 match param.kind {
976 hir::GenericParamKind::Type { .. } => {
977 let param_ty = self.lowerer().lower_ty_param(param.hir_id);
978 self.lowerer().add_implicit_bounds(
979 &mut bounds,
980 param_ty,
981 &[],
982 ImpliedBoundsContext::TyParam(param.def_id, hir_generics.predicates),
983 param.span,
984 IncludeSizedImplicitBounds::Yes,
985 );
986 }
987 hir::GenericParamKind::Lifetime { .. }
988 | hir::GenericParamKind::Const { .. } => {}
989 }
990 }
991 }
992
993 for predicate in hir_generics.predicates {
994 let hir_id = predicate.hir_id;
995 let hir::WherePredicateKind::BoundPredicate(predicate) = predicate.kind else {
996 continue;
997 };
998
999 match filter {
1000 _ if predicate.is_param_bound(param_def_id.to_def_id()) => {
1001 }
1003 PredicateFilter::All => {
1004 }
1006 PredicateFilter::SelfOnly
1007 | PredicateFilter::SelfTraitThatDefines(_)
1008 | PredicateFilter::SelfConstIfConst
1009 | PredicateFilter::SelfAndAssociatedTypeBounds => continue,
1010 PredicateFilter::ConstIfConst => unreachable!(),
1011 }
1012
1013 let bound_ty = self.lowerer().lower_ty_maybe_return_type_notation(predicate.bounded_ty);
1014
1015 let bound_vars = self.tcx.late_bound_vars(hir_id);
1016 self.lowerer().lower_bounds(
1017 bound_ty,
1018 predicate.bounds,
1019 &mut bounds,
1020 bound_vars,
1021 filter,
1022 OverlappingAsssocItemConstraints::Allowed,
1023 );
1024 }
1025
1026 bounds
1027 }
1028}
1029
1030pub(super) fn const_conditions<'tcx>(
1031 tcx: TyCtxt<'tcx>,
1032 def_id: LocalDefId,
1033) -> ty::ConstConditions<'tcx> {
1034 if !tcx.is_conditionally_const(def_id) {
1035 ::rustc_span::macros::bug_impl(None,
format_args!("const_conditions invoked for item that is not conditionally const: {0:?}",
def_id), Location::caller());bug!("const_conditions invoked for item that is not conditionally const: {def_id:?}");
1036 }
1037
1038 match tcx.opt_rpitit_info(def_id.to_def_id()) {
1039 Some(
1041 ty::ImplTraitInTraitData::Impl { fn_def_id }
1042 | ty::ImplTraitInTraitData::Trait { fn_def_id, .. },
1043 ) => return tcx.const_conditions(fn_def_id),
1044 None => {}
1045 }
1046
1047 let (generics, trait_def_id_and_supertraits, has_parent) = match tcx.hir_node_by_def_id(def_id)
1048 {
1049 Node::Item(item) => match item.kind {
1050 hir::ItemKind::Impl(impl_) => (impl_.generics, None, false),
1051 hir::ItemKind::Fn { generics, .. } => (generics, None, false),
1052 hir::ItemKind::Trait { generics, bounds: supertraits, .. } => {
1053 (generics, Some((Some(item.owner_id.def_id), supertraits)), false)
1054 }
1055 hir::ItemKind::TraitAlias(_, _, generics, supertraits) => {
1056 (generics, Some((None, supertraits)), false)
1057 }
1058 _ => ::rustc_span::macros::bug_impl(None,
format_args!("const_conditions called on wrong item: {0:?}", def_id),
Location::caller())bug!("const_conditions called on wrong item: {def_id:?}"),
1059 },
1060 Node::TraitItem(item) => match item.kind {
1065 hir::TraitItemKind::Fn(_, _) | hir::TraitItemKind::Type(_, _) => {
1066 (item.generics, None, true)
1067 }
1068 _ => ::rustc_span::macros::bug_impl(None,
format_args!("const_conditions called on wrong item: {0:?}", def_id),
Location::caller())bug!("const_conditions called on wrong item: {def_id:?}"),
1069 },
1070 Node::ImplItem(item) => match item.kind {
1071 hir::ImplItemKind::Fn(_, _) | hir::ImplItemKind::Type(_) => {
1072 (item.generics, None, tcx.is_conditionally_const(tcx.local_parent(def_id)))
1073 }
1074 _ => ::rustc_span::macros::bug_impl(None,
format_args!("const_conditions called on wrong item: {0:?}", def_id),
Location::caller())bug!("const_conditions called on wrong item: {def_id:?}"),
1075 },
1076 Node::ForeignItem(item) => match item.kind {
1077 hir::ForeignItemKind::Fn(_, _, generics) => (generics, None, false),
1078 _ => ::rustc_span::macros::bug_impl(None,
format_args!("const_conditions called on wrong item: {0:?}", def_id),
Location::caller())bug!("const_conditions called on wrong item: {def_id:?}"),
1079 },
1080 Node::OpaqueTy(opaque) => match opaque.origin {
1081 hir::OpaqueTyOrigin::FnReturn { parent, .. } => return tcx.const_conditions(parent),
1082 hir::OpaqueTyOrigin::AsyncFn { .. } | hir::OpaqueTyOrigin::TyAlias { .. } => {
1083 ::core::panicking::unreachable_default_msg()unreachable!()
1084 }
1085 },
1086 Node::Ctor(hir::VariantData::Tuple { .. }) => return Default::default(),
1088 Node::Expr(hir::Expr { kind: hir::ExprKind::Closure(_), .. }) => {
1089 (hir::Generics::empty(), None, tcx.is_conditionally_const(tcx.local_parent(def_id)))
1090 }
1091 _ => ::rustc_span::macros::bug_impl(None,
format_args!("const_conditions called on wrong item: {0:?}", def_id),
Location::caller())bug!("const_conditions called on wrong item: {def_id:?}"),
1092 };
1093
1094 let icx = ItemCtxt::new(tcx, def_id);
1095 let mut bounds = Vec::new();
1096
1097 for pred in generics.predicates {
1098 match pred.kind {
1099 hir::WherePredicateKind::BoundPredicate(bound_pred) => {
1100 let ty = icx.lowerer().lower_ty_maybe_return_type_notation(bound_pred.bounded_ty);
1101 let bound_vars = tcx.late_bound_vars(pred.hir_id);
1102 icx.lowerer().lower_bounds(
1103 ty,
1104 bound_pred.bounds.iter(),
1105 &mut bounds,
1106 bound_vars,
1107 PredicateFilter::ConstIfConst,
1108 OverlappingAsssocItemConstraints::Allowed,
1109 );
1110 }
1111 _ => {}
1112 }
1113 }
1114
1115 if let Some((def_id, supertraits)) = trait_def_id_and_supertraits {
1116 if let Some(def_id) = def_id {
1117 bounds.push((
1119 ty::Binder::dummy(ty::TraitRef::identity(tcx, def_id.to_def_id()))
1120 .to_host_effect_clause(tcx, ty::BoundConstness::Maybe),
1121 DUMMY_SP,
1122 ));
1123 }
1124
1125 icx.lowerer().lower_bounds(
1126 tcx.types.self_param,
1127 supertraits,
1128 &mut bounds,
1129 ty::List::empty(),
1130 PredicateFilter::ConstIfConst,
1131 OverlappingAsssocItemConstraints::Allowed,
1132 );
1133 }
1134
1135 ty::ConstConditions {
1136 parent: has_parent.then(|| tcx.local_parent(def_id).to_def_id()),
1137 clauses: tcx.arena.alloc_from_iter(bounds.into_iter().map(|(clause, span)| {
1138 (
1139 clause.kind().map_bound(|clause| match clause {
1140 ty::ClauseKind::HostEffect(ty::HostEffectClause {
1141 trait_ref,
1142 constness: ty::BoundConstness::Maybe,
1143 }) => trait_ref,
1144 _ => ::rustc_span::macros::bug_impl(None, format_args!("converted {0:?}", clause),
Location::caller())bug!("converted {clause:?}"),
1145 }),
1146 span,
1147 )
1148 })),
1149 }
1150}
1151
1152pub(super) fn explicit_implied_const_bounds<'tcx>(
1153 tcx: TyCtxt<'tcx>,
1154 def_id: LocalDefId,
1155) -> ty::EarlyBinder<'tcx, &'tcx [(ty::PolyTraitRef<'tcx>, Span)]> {
1156 if !tcx.is_conditionally_const(def_id) {
1157 ::rustc_span::macros::bug_impl(None,
format_args!("explicit_implied_const_bounds invoked for item that is not conditionally const: {0:?}",
def_id), Location::caller());bug!(
1158 "explicit_implied_const_bounds invoked for item that is not conditionally const: {def_id:?}"
1159 );
1160 }
1161
1162 let bounds = match tcx.opt_rpitit_info(def_id.to_def_id()) {
1163 Some(ty::ImplTraitInTraitData::Trait { .. }) => {
1166 explicit_item_bounds_with_filter(tcx, def_id, PredicateFilter::ConstIfConst)
1167 }
1168 Some(ty::ImplTraitInTraitData::Impl { .. }) => {
1169 ::rustc_span::macros::bug_impl(Some(tcx.def_span(def_id)),
format_args!("RPITIT in impl should not have item bounds"),
Location::caller())span_bug!(tcx.def_span(def_id), "RPITIT in impl should not have item bounds")
1170 }
1171 None => match tcx.hir_node_by_def_id(def_id) {
1172 Node::Item(hir::Item {
1173 kind: hir::ItemKind::Trait { .. } | hir::ItemKind::TraitAlias(..),
1174 ..
1175 }) => implied_clauses_with_filter(
1176 tcx,
1177 def_id.to_def_id(),
1178 PredicateFilter::SelfConstIfConst,
1179 ),
1180 Node::TraitItem(hir::TraitItem { kind: hir::TraitItemKind::Type(..), .. })
1181 | Node::OpaqueTy(_) => {
1182 explicit_item_bounds_with_filter(tcx, def_id, PredicateFilter::ConstIfConst)
1183 }
1184 _ => ::rustc_span::macros::bug_impl(None,
format_args!("explicit_implied_const_bounds called on wrong item: {0:?}",
def_id), Location::caller())bug!("explicit_implied_const_bounds called on wrong item: {def_id:?}"),
1185 },
1186 };
1187
1188 bounds.map_bound(|bounds| {
1189 &*tcx.arena.alloc_from_iter(bounds.iter().copied().map(|(clause, span)| {
1190 (
1191 clause.kind().map_bound(|clause| match clause {
1192 ty::ClauseKind::HostEffect(ty::HostEffectClause {
1193 trait_ref,
1194 constness: ty::BoundConstness::Maybe,
1195 }) => trait_ref,
1196 _ => ::rustc_span::macros::bug_impl(None, format_args!("converted {0:?}", clause),
Location::caller())bug!("converted {clause:?}"),
1197 }),
1198 span,
1199 )
1200 }))
1201 })
1202}