1use std::assert_matches;
2
3use hir::Node;
4use rustc_data_structures::fx::FxIndexSet;
5use rustc_hir as hir;
6use rustc_hir::def::DefKind;
7use rustc_hir::def_id::{DefId, LocalDefId};
8use rustc_hir::find_attr;
9use rustc_middle::ty::{
10 self, GenericClauses, ImplTraitInTraitData, Ty, TyCtxt, TypeVisitable, TypeVisitor, Upcast,
11};
12use rustc_middle::{bug, span_bug};
13use rustc_span::{DUMMY_SP, Ident, Span};
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/0fc141305da7a8a222f65aef1f1acc739c46282b/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/0fc141305da7a8a222f65aef1f1acc739c46282b/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/0fc141305da7a8a222f65aef1f1acc739c46282b/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/0fc141305da7a8a222f65aef1f1acc739c46282b/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/0fc141305da7a8a222f65aef1f1acc739c46282b/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/0fc141305da7a8a222f65aef1f1acc739c46282b/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/0fc141305da7a8a222f65aef1f1acc739c46282b/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/0fc141305da7a8a222f65aef1f1acc739c46282b/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_sizedness_bounds(&mut bounds,
tcx.types.self_param, self_bounds,
ImpliedBoundsContext::TraitDef(def_id), span);
icx.lowerer().add_default_traits(&mut bounds,
tcx.types.self_param, self_bounds,
ImpliedBoundsContext::TraitDef(def_id), span);
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_sizedness_bounds(&mut bounds,
param_ty, &[],
ImpliedBoundsContext::TyParam(param.def_id,
hir_generics.predicates), param.span);
icx.lowerer().add_default_traits(&mut bounds, param_ty, &[],
ImpliedBoundsContext::TyParam(param.def_id,
hir_generics.predicates), 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/0fc141305da7a8a222f65aef1f1acc739c46282b/compiler/rustc_hir_analysis/src/collect/clauses_of.rs:252",
"rustc_hir_analysis::collect::clauses_of",
::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("/rustc-dev/0fc141305da7a8a222f65aef1f1acc739c46282b/compiler/rustc_hir_analysis/src/collect/clauses_of.rs"),
::tracing_core::__macro_support::Option::Some(252u32),
::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/0fc141305da7a8a222f65aef1f1acc739c46282b/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/0fc141305da7a8a222f65aef1f1acc739c46282b/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 { ; }
};
}
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/0fc141305da7a8a222f65aef1f1acc739c46282b/compiler/rustc_hir_analysis/src/collect/clauses_of.rs:266",
"rustc_hir_analysis::collect::clauses_of",
::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("/rustc-dev/0fc141305da7a8a222f65aef1f1acc739c46282b/compiler/rustc_hir_analysis/src/collect/clauses_of.rs"),
::tracing_core::__macro_support::Option::Some(266u32),
::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::Unparsed(..) =>
{}
#[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/0fc141305da7a8a222f65aef1f1acc739c46282b/compiler/rustc_hir_analysis/src/collect/clauses_of.rs:313",
"rustc_hir_analysis::collect::clauses_of",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/0fc141305da7a8a222f65aef1f1acc739c46282b/compiler/rustc_hir_analysis/src/collect/clauses_of.rs"),
::tracing_core::__macro_support::Option::Some(313u32),
::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/0fc141305da7a8a222f65aef1f1acc739c46282b/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/0fc141305da7a8a222f65aef1f1acc739c46282b/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_sizedness_bounds(
200 &mut bounds,
201 tcx.types.self_param,
202 self_bounds,
203 ImpliedBoundsContext::TraitDef(def_id),
204 span,
205 );
206 icx.lowerer().add_default_traits(
207 &mut bounds,
208 tcx.types.self_param,
209 self_bounds,
210 ImpliedBoundsContext::TraitDef(def_id),
211 span,
212 );
213 clauses.extend(bounds);
214 }
215
216 if let Some(trait_ref) = is_default_impl_trait {
225 clauses.insert((trait_ref.upcast(tcx), tcx.def_span(def_id)));
226 }
227
228 for param in hir_generics.params {
232 match param.kind {
233 GenericParamKind::Lifetime { .. } => (),
234 GenericParamKind::Type { .. } => {
235 let param_ty = icx.lowerer().lower_ty_param(param.hir_id);
236 let mut bounds = Vec::new();
237 icx.lowerer().add_implicit_sizedness_bounds(
239 &mut bounds,
240 param_ty,
241 &[],
242 ImpliedBoundsContext::TyParam(param.def_id, hir_generics.predicates),
243 param.span,
244 );
245 icx.lowerer().add_default_traits(
246 &mut bounds,
247 param_ty,
248 &[],
249 ImpliedBoundsContext::TyParam(param.def_id, hir_generics.predicates),
250 param.span,
251 );
252 trace!(?bounds);
253 clauses.extend(bounds);
254 trace!(?clauses);
255 }
256 hir::GenericParamKind::Const { .. } => {
257 let param_def_id = param.def_id.to_def_id();
258 let ct_ty = tcx.type_of(param_def_id).instantiate_identity().skip_norm_wip();
259 let ct = icx.lowerer().lower_const_param(param_def_id, param.hir_id);
260 clauses
261 .insert((ty::ClauseKind::ConstArgHasType(ct, ct_ty).upcast(tcx), param.span));
262 }
263 }
264 }
265
266 trace!(?clauses);
267 for predicate in hir_generics.predicates {
269 where_predicate_clauses(&icx, predicate, &mut clauses);
270 }
271
272 if tcx.features().generic_const_exprs() {
273 clauses.extend(const_evaluatable_clauses_of(tcx, def_id, &clauses));
274 }
275
276 let attrs = tcx.hir_attrs(tcx.local_def_id_to_hir_id(def_id));
277 let allow_unstable_feature_attr =
281 find_attr!(attrs, UnstableFeatureBound(i) => i).map(|i| i.as_slice()).unwrap_or_default();
282
283 for (feat_name, span) in allow_unstable_feature_attr {
284 clauses.insert((ty::ClauseKind::UnstableFeature(*feat_name).upcast(tcx), *span));
285 }
286
287 let mut clauses: Vec<_> = clauses.into_iter().collect();
288
289 if let Node::Item(&Item { kind: ItemKind::Impl(impl_), .. }) = node {
295 let self_ty = tcx.type_of(def_id).instantiate_identity().skip_norm_wip();
296 let trait_ref = impl_
297 .of_trait
298 .is_some()
299 .then(|| tcx.impl_trait_ref(def_id).instantiate_identity().skip_norm_wip());
300 cgp::setup_constraining_clauses(
301 tcx,
302 &mut clauses,
303 trait_ref,
304 &mut cgp::parameters_for_impl(tcx, self_ty, trait_ref),
305 );
306 }
307
308 if let Node::OpaqueTy(..) = node {
312 compute_bidirectional_outlives_clauses(tcx, &generics.own_params, &mut clauses);
313 debug!(?clauses);
314 }
315
316 ty::GenericClauses { parent: generics.parent, clauses: tcx.arena.alloc_from_iter(clauses) }
317}
318
319pub(super) fn where_predicate_clauses<'tcx>(
320 icx: &ItemCtxt<'tcx>,
321 predicate: &hir::WherePredicate<'_>,
322 clauses: &mut FxIndexSet<(ty::Clause<'tcx>, Span)>,
323) {
324 let tcx = icx.tcx;
325 match predicate.kind {
326 hir::WherePredicateKind::BoundPredicate(bound_pred) => {
327 let ty = icx.lowerer().lower_ty_maybe_return_type_notation(bound_pred.bounded_ty);
328 let bound_vars = tcx.late_bound_vars(predicate.hir_id);
329
330 if bound_pred.bounds.is_empty() {
332 if let ty::Param(_) = ty.kind() {
333 } else {
335 let span = bound_pred.bounded_ty.span;
339 let clause = ty::Binder::bind_with_vars(
340 ty::ClauseKind::WellFormed(ty.into()),
341 bound_vars,
342 );
343 clauses.insert((clause.upcast(tcx), span));
344 }
345 }
346
347 let mut bounds = Vec::new();
348 icx.lowerer().lower_bounds(
349 ty,
350 bound_pred.bounds,
351 &mut bounds,
352 bound_vars,
353 PredicateFilter::All,
354 OverlappingAsssocItemConstraints::Allowed,
355 );
356 clauses.extend(bounds);
357 }
358
359 hir::WherePredicateKind::RegionPredicate(region_pred) => {
360 let r1 = icx
361 .lowerer()
362 .lower_lifetime(region_pred.lifetime, RegionInferReason::RegionPredicate);
363 clauses.extend(region_pred.bounds.iter().map(|bound| {
364 let (r2, span) = match bound {
365 hir::GenericBound::Outlives(lt) => (
366 icx.lowerer().lower_lifetime(lt, RegionInferReason::RegionPredicate),
367 lt.ident.span,
368 ),
369 bound => {
370 ::rustc_middle::util::bug::span_bug_fmt(bound.span(),
format_args!("lifetime param bounds must be outlives, but found {0:?}",
bound))span_bug!(
371 bound.span(),
372 "lifetime param bounds must be outlives, but found {bound:?}"
373 )
374 }
375 };
376 let clause = ty::ClauseKind::RegionOutlives(ty::OutlivesClause(r1, r2)).upcast(tcx);
377 (clause, span)
378 }))
379 }
380 }
381}
382
383fn compute_bidirectional_outlives_clauses<'tcx>(
386 tcx: TyCtxt<'tcx>,
387 opaque_own_params: &[ty::GenericParamDef],
388 clauses: &mut Vec<(ty::Clause<'tcx>, Span)>,
389) {
390 for param in opaque_own_params {
391 let orig_lifetime = tcx.map_opaque_lifetime_to_parent_lifetime(param.def_id.expect_local());
392 if let ty::ReEarlyParam(..) = orig_lifetime.kind() {
393 let dup_lifetime = ty::Region::new_early_param(
394 tcx,
395 ty::EarlyParamRegion { index: param.index, name: param.name },
396 );
397 let span = tcx.def_span(param.def_id);
398 clauses.push((
399 ty::ClauseKind::RegionOutlives(ty::OutlivesClause(orig_lifetime, dup_lifetime))
400 .upcast(tcx),
401 span,
402 ));
403 clauses.push((
404 ty::ClauseKind::RegionOutlives(ty::OutlivesClause(dup_lifetime, orig_lifetime))
405 .upcast(tcx),
406 span,
407 ));
408 }
409 }
410}
411
412{}
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/0fc141305da7a8a222f65aef1f1acc739c46282b/compiler/rustc_hir_analysis/src/collect/clauses_of.rs"),
::tracing_core::__macro_support::Option::Some(412u32),
::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/0fc141305da7a8a222f65aef1f1acc739c46282b/compiler/rustc_hir_analysis/src/collect/clauses_of.rs:477",
"rustc_hir_analysis::collect::clauses_of",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/0fc141305da7a8a222f65aef1f1acc739c46282b/compiler/rustc_hir_analysis/src/collect/clauses_of.rs"),
::tracing_core::__macro_support::Option::Some(477u32),
::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/0fc141305da7a8a222f65aef1f1acc739c46282b/compiler/rustc_hir_analysis/src/collect/clauses_of.rs:482",
"rustc_hir_analysis::collect::clauses_of",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/0fc141305da7a8a222f65aef1f1acc739c46282b/compiler/rustc_hir_analysis/src/collect/clauses_of.rs"),
::tracing_core::__macro_support::Option::Some(482u32),
::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/0fc141305da7a8a222f65aef1f1acc739c46282b/compiler/rustc_hir_analysis/src/collect/clauses_of.rs:488",
"rustc_hir_analysis::collect::clauses_of",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/0fc141305da7a8a222f65aef1f1acc739c46282b/compiler/rustc_hir_analysis/src/collect/clauses_of.rs"),
::tracing_core::__macro_support::Option::Some(488u32),
::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/0fc141305da7a8a222f65aef1f1acc739c46282b/compiler/rustc_hir_analysis/src/collect/clauses_of.rs:491",
"rustc_hir_analysis::collect::clauses_of",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/0fc141305da7a8a222f65aef1f1acc739c46282b/compiler/rustc_hir_analysis/src/collect/clauses_of.rs"),
::tracing_core::__macro_support::Option::Some(491u32),
::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/0fc141305da7a8a222f65aef1f1acc739c46282b/compiler/rustc_hir_analysis/src/collect/clauses_of.rs:412",
"rustc_hir_analysis::collect::clauses_of",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/0fc141305da7a8a222f65aef1f1acc739c46282b/compiler/rustc_hir_analysis/src/collect/clauses_of.rs"),
::tracing_core::__macro_support::Option::Some(412u32),
::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)]
413fn const_evaluatable_clauses_of<'tcx>(
414 tcx: TyCtxt<'tcx>,
415 def_id: LocalDefId,
416 clauses: &FxIndexSet<(ty::Clause<'tcx>, Span)>,
417) -> FxIndexSet<(ty::Clause<'tcx>, Span)> {
418 struct ConstCollector<'tcx> {
419 tcx: TyCtxt<'tcx>,
420 clauses: FxIndexSet<(ty::Clause<'tcx>, Span)>,
421 }
422
423 fn is_const_param_default(tcx: TyCtxt<'_>, kind: ty::AliasConstKind<'_>) -> bool {
424 let ty::AliasConstKind::Anon { def_id } = kind else { return false };
425 let Some(local) = def_id.as_local() else { return false };
426
427 let hir_id = tcx.local_def_id_to_hir_id(local);
428 let (_, parent_node) = tcx
429 .hir_parent_iter(hir_id)
430 .skip_while(|(_, n)| matches!(n, Node::ConstArg(..)))
431 .next()
432 .unwrap();
433 matches!(
434 parent_node,
435 Node::GenericParam(hir::GenericParam { kind: hir::GenericParamKind::Const { .. }, .. })
436 )
437 }
438
439 impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for ConstCollector<'tcx> {
440 fn visit_const(&mut self, c: ty::Const<'tcx>) {
441 if let ty::ConstKind::Alias(_, alias_const) = c.kind() {
442 if is_const_param_default(self.tcx, alias_const.kind) {
443 return;
451 }
452
453 if alias_const.kind.is_direct_const(self.tcx) {
455 return;
456 }
457
458 let span = alias_const.kind.def_span(self.tcx);
459 self.clauses.insert((ty::ClauseKind::ConstEvaluatable(c).upcast(self.tcx), span));
460 }
461 }
462 }
463
464 let hir_id = tcx.local_def_id_to_hir_id(def_id);
465 let node = tcx.hir_node(hir_id);
466
467 let mut collector = ConstCollector { tcx, clauses: FxIndexSet::default() };
468
469 for (clause, _sp) in clauses {
470 clause.visit_with(&mut collector);
471 }
472
473 if let hir::Node::Item(item) = node
474 && let hir::ItemKind::Impl(impl_) = item.kind
475 {
476 if impl_.of_trait.is_some() {
477 debug!("visit impl trait_ref");
478 let trait_ref = tcx.impl_trait_ref(def_id);
479 trait_ref.instantiate_identity().skip_norm_wip().visit_with(&mut collector);
480 }
481
482 debug!("visit self_ty");
483 let self_ty = tcx.type_of(def_id);
484 self_ty.instantiate_identity().skip_norm_wip().visit_with(&mut collector);
485 }
486
487 if let Some(_) = tcx.hir_fn_sig_by_hir_id(hir_id) {
488 debug!("visit fn sig");
489 let fn_sig = tcx.fn_sig(def_id);
490 let fn_sig = fn_sig.instantiate_identity().skip_norm_wip();
491 debug!(?fn_sig);
492 fn_sig.visit_with(&mut collector);
493 }
494
495 collector.clauses
496}
497
498pub(super) fn trait_explicit_clauses_and_bounds(
499 tcx: TyCtxt<'_>,
500 def_id: LocalDefId,
501) -> ty::GenericClauses<'_> {
502 {
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);
503 gather_explicit_clauses_of(tcx, def_id)
504}
505
506pub(super) fn explicit_clauses_of<'tcx>(
507 tcx: TyCtxt<'tcx>,
508 def_id: LocalDefId,
509) -> ty::GenericClauses<'tcx> {
510 let def_kind = tcx.def_kind(def_id);
511 if let DefKind::Trait = def_kind {
512 let clauses_and_bounds = tcx.trait_explicit_clauses_and_bounds(def_id);
515 let trait_identity_args = ty::GenericArgs::identity_for_item(tcx, def_id);
516
517 let is_assoc_item_ty = |ty: Ty<'tcx>| {
518 if let &ty::Alias(
528 _,
529 ty::AliasTy { kind: ty::Projection { def_id: projection_def_id }, args, .. },
530 ) = ty.kind()
531 {
532 args == trait_identity_args
533 && !tcx.is_impl_trait_in_trait(projection_def_id)
535 && tcx.parent(projection_def_id) == def_id.to_def_id()
536 } else {
537 false
538 }
539 };
540
541 let clauses: Vec<_> = clauses_and_bounds
542 .clauses
543 .iter()
544 .copied()
545 .filter(|(clause, _)| match clause.kind().skip_binder() {
546 ty::ClauseKind::Trait(tr) => !is_assoc_item_ty(tr.self_ty()),
547 ty::ClauseKind::Projection(proj) => {
548 !is_assoc_item_ty(proj.projection_term.self_ty())
549 }
550 ty::ClauseKind::TypeOutlives(outlives) => !is_assoc_item_ty(outlives.0),
551 _ => true,
552 })
553 .collect();
554 if clauses.len() == clauses_and_bounds.clauses.len() {
555 clauses_and_bounds
556 } else {
557 ty::GenericClauses {
558 parent: clauses_and_bounds.parent,
559 clauses: tcx.arena.alloc_slice(&clauses),
560 }
561 }
562 } else {
563 if def_kind == DefKind::AnonConst
564 && tcx.features().generic_const_exprs()
565 && let Some(defaulted_param_def_id) =
566 tcx.hir_opt_const_param_default_param_def_id(tcx.local_def_id_to_hir_id(def_id))
567 {
568 let parent_def_id = tcx.local_parent(def_id);
581 let parent_clauses = tcx.explicit_clauses_of(parent_def_id);
582
583 let filtered_clauses = parent_clauses
587 .clauses
588 .into_iter()
589 .filter(|(clause, _)| {
590 if let ty::ClauseKind::ConstArgHasType(ct, _) = clause.kind().skip_binder() {
591 match ct.kind() {
592 ty::ConstKind::Param(param_const) => {
593 let defaulted_param_idx = tcx
594 .generics_of(parent_def_id)
595 .param_def_id_to_index[&defaulted_param_def_id.to_def_id()];
596 param_const.index < defaulted_param_idx
597 }
598 _ => {
599 ::rustc_middle::util::bug::bug_fmt(format_args!("`ConstArgHasType` in `clauses_of` that isn\'t a `Param` const"))bug!("`ConstArgHasType` in `clauses_of` that isn't a `Param` const")
600 }
601 }
602 } else {
603 true
604 }
605 })
606 .cloned();
607 return GenericClauses {
608 parent: parent_clauses.parent,
609 clauses: { tcx.arena.alloc_from_iter(filtered_clauses) },
610 };
611 }
612 gather_explicit_clauses_of(tcx, def_id)
613 }
614}
615
616pub(super) fn explicit_super_clauses_of<'tcx>(
620 tcx: TyCtxt<'tcx>,
621 trait_def_id: LocalDefId,
622) -> ty::EarlyBinder<'tcx, &'tcx [(ty::Clause<'tcx>, Span)]> {
623 implied_clauses_with_filter(tcx, trait_def_id.to_def_id(), PredicateFilter::SelfOnly)
624}
625
626pub(super) fn explicit_supertraits_containing_assoc_item<'tcx>(
627 tcx: TyCtxt<'tcx>,
628 (trait_def_id, assoc_ident): (DefId, Ident),
629) -> ty::EarlyBinder<'tcx, &'tcx [(ty::Clause<'tcx>, Span)]> {
630 implied_clauses_with_filter(
631 tcx,
632 trait_def_id,
633 PredicateFilter::SelfTraitThatDefines(assoc_ident),
634 )
635}
636
637pub(super) fn explicit_implied_clauses_of<'tcx>(
638 tcx: TyCtxt<'tcx>,
639 trait_def_id: LocalDefId,
640) -> ty::EarlyBinder<'tcx, &'tcx [(ty::Clause<'tcx>, Span)]> {
641 implied_clauses_with_filter(
642 tcx,
643 trait_def_id.to_def_id(),
644 if tcx.is_trait_alias(trait_def_id.to_def_id()) {
645 PredicateFilter::All
646 } else {
647 PredicateFilter::SelfAndAssociatedTypeBounds
648 },
649 )
650}
651
652pub(super) fn implied_clauses_with_filter<'tcx>(
656 tcx: TyCtxt<'tcx>,
657 trait_def_id: DefId,
658 filter: PredicateFilter,
659) -> ty::EarlyBinder<'tcx, &'tcx [(ty::Clause<'tcx>, Span)]> {
660 let Some(trait_def_id) = trait_def_id.as_local() else {
661 {
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(_));
664 return tcx.explicit_super_clauses_of(trait_def_id);
665 };
666
667 let Node::Item(item) = tcx.hir_node_by_def_id(trait_def_id) else {
668 ::rustc_middle::util::bug::bug_fmt(format_args!("trait_def_id {0:?} is not an item",
trait_def_id));bug!("trait_def_id {trait_def_id:?} is not an item");
669 };
670
671 let (generics, superbounds) = match item.kind {
672 hir::ItemKind::Trait { generics, bounds: supertraits, .. } => (generics, supertraits),
673 hir::ItemKind::TraitAlias(_, _, generics, supertraits) => (generics, supertraits),
674 _ => ::rustc_middle::util::bug::span_bug_fmt(item.span,
format_args!("super_clauses invoked on non-trait"))span_bug!(item.span, "super_clauses invoked on non-trait"),
675 };
676
677 let icx = ItemCtxt::new(tcx, trait_def_id);
678
679 let self_param_ty = tcx.types.self_param;
680 let mut bounds = Vec::new();
681 icx.lowerer().lower_bounds(
682 self_param_ty,
683 superbounds,
684 &mut bounds,
685 ty::List::empty(),
686 filter,
687 OverlappingAsssocItemConstraints::Allowed,
688 );
689 match filter {
690 PredicateFilter::All
691 | PredicateFilter::SelfOnly
692 | PredicateFilter::SelfTraitThatDefines(_)
693 | PredicateFilter::SelfAndAssociatedTypeBounds => {
694 icx.lowerer().add_implicit_sizedness_bounds(
695 &mut bounds,
696 self_param_ty,
697 superbounds,
698 ImpliedBoundsContext::TraitDef(trait_def_id),
699 item.span,
700 );
701 icx.lowerer().add_default_traits(
702 &mut bounds,
703 self_param_ty,
704 superbounds,
705 ImpliedBoundsContext::TraitDef(trait_def_id),
706 item.span,
707 );
708 }
709 PredicateFilter::ConstIfConst | PredicateFilter::SelfConstIfConst => {}
711 }
712
713 let where_bounds_that_match =
714 icx.probe_ty_param_bounds_in_generics(generics, item.owner_id.def_id, filter);
715
716 let implied_bounds =
718 &*tcx.arena.alloc_from_iter(bounds.into_iter().chain(where_bounds_that_match));
719 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/0fc141305da7a8a222f65aef1f1acc739c46282b/compiler/rustc_hir_analysis/src/collect/clauses_of.rs:719",
"rustc_hir_analysis::collect::clauses_of",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/0fc141305da7a8a222f65aef1f1acc739c46282b/compiler/rustc_hir_analysis/src/collect/clauses_of.rs"),
::tracing_core::__macro_support::Option::Some(719u32),
::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);
720
721 match filter {
726 PredicateFilter::SelfOnly => {
727 for &(clause, span) in implied_bounds {
728 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/0fc141305da7a8a222f65aef1f1acc739c46282b/compiler/rustc_hir_analysis/src/collect/clauses_of.rs:728",
"rustc_hir_analysis::collect::clauses_of",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/0fc141305da7a8a222f65aef1f1acc739c46282b/compiler/rustc_hir_analysis/src/collect/clauses_of.rs"),
::tracing_core::__macro_support::Option::Some(728u32),
::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);
729 if let ty::ClauseKind::Trait(bound) = clause.kind().skip_binder()
730 && bound.polarity == ty::ClausePolarity::Positive
731 {
732 tcx.at(span).explicit_super_clauses_of(bound.def_id());
733 }
734 }
735 }
736 PredicateFilter::All | PredicateFilter::SelfAndAssociatedTypeBounds => {
737 for &(clause, span) in implied_bounds {
738 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/0fc141305da7a8a222f65aef1f1acc739c46282b/compiler/rustc_hir_analysis/src/collect/clauses_of.rs:738",
"rustc_hir_analysis::collect::clauses_of",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/0fc141305da7a8a222f65aef1f1acc739c46282b/compiler/rustc_hir_analysis/src/collect/clauses_of.rs"),
::tracing_core::__macro_support::Option::Some(738u32),
::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);
739 if let ty::ClauseKind::Trait(bound) = clause.kind().skip_binder()
740 && bound.polarity == ty::ClausePolarity::Positive
741 {
742 tcx.at(span).explicit_implied_clauses_of(bound.def_id());
743 }
744 }
745 }
746 _ => {}
747 }
748
749 assert_only_contains_clauses_from(filter, implied_bounds, tcx.types.self_param);
750
751 ty::EarlyBinder::bind_iter(implied_bounds)
752}
753
754pub(super) fn assert_only_contains_clauses_from<'tcx>(
758 filter: PredicateFilter,
759 bounds: &'tcx [(ty::Clause<'tcx>, Span)],
760 ty: Ty<'tcx>,
761) {
762 if !truecfg!(debug_assertions) {
763 return;
764 }
765
766 match filter {
767 PredicateFilter::SelfOnly => {
768 for (clause, _) in bounds {
769 match clause.kind().skip_binder() {
770 ty::ClauseKind::Trait(trait_predicate) => {
771 {
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!(
772 trait_predicate.self_ty(),
773 ty,
774 "expected `Self` predicate when computing \
775 `{filter:?}` implied bounds: {clause:?}"
776 );
777 }
778 ty::ClauseKind::Projection(projection_predicate) => {
779 {
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!(
780 projection_predicate.self_ty(),
781 ty,
782 "expected `Self` predicate when computing \
783 `{filter:?}` implied bounds: {clause:?}"
784 );
785 }
786 ty::ClauseKind::TypeOutlives(outlives_clause) => {
787 {
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!(
788 outlives_clause.0, ty,
789 "expected `Self` clause when computing \
790 `{filter:?}` implied bounds: {clause:?}"
791 );
792 }
793 ty::ClauseKind::HostEffect(host_effect_clause) => {
794 {
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!(
795 host_effect_clause.self_ty(),
796 ty,
797 "expected `Self` clause when computing \
798 `{filter:?}` implied bounds: {clause:?}"
799 );
800 }
801
802 ty::ClauseKind::RegionOutlives(_)
803 | ty::ClauseKind::ConstArgHasType(_, _)
804 | ty::ClauseKind::WellFormed(_)
805 | ty::ClauseKind::UnstableFeature(_)
806 | ty::ClauseKind::ConstEvaluatable(_) => {
807 ::rustc_middle::util::bug::bug_fmt(format_args!("unexpected non-`Self` predicate when computing `{0:?}` implied bounds: {1:?}",
filter, clause));bug!(
808 "unexpected non-`Self` predicate when computing \
809 `{filter:?}` implied bounds: {clause:?}"
810 );
811 }
812 }
813 }
814 }
815 PredicateFilter::SelfTraitThatDefines(_) => {
816 for (clause, _) in bounds {
817 match clause.kind().skip_binder() {
818 ty::ClauseKind::Trait(trait_predicate) => {
819 {
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!(
820 trait_predicate.self_ty(),
821 ty,
822 "expected `Self` predicate when computing \
823 `{filter:?}` implied bounds: {clause:?}"
824 );
825 }
826
827 ty::ClauseKind::Projection(_)
828 | ty::ClauseKind::TypeOutlives(_)
829 | ty::ClauseKind::RegionOutlives(_)
830 | ty::ClauseKind::ConstArgHasType(_, _)
831 | ty::ClauseKind::WellFormed(_)
832 | ty::ClauseKind::ConstEvaluatable(_)
833 | ty::ClauseKind::UnstableFeature(_)
834 | ty::ClauseKind::HostEffect(..) => {
835 ::rustc_middle::util::bug::bug_fmt(format_args!("unexpected non-`Self` predicate when computing `{0:?}` implied bounds: {1:?}",
filter, clause));bug!(
836 "unexpected non-`Self` predicate when computing \
837 `{filter:?}` implied bounds: {clause:?}"
838 );
839 }
840 }
841 }
842 }
843 PredicateFilter::ConstIfConst => {
844 for (clause, _) in bounds {
845 match clause.kind().skip_binder() {
846 ty::ClauseKind::HostEffect(ty::HostEffectClause {
847 trait_ref: _,
848 constness: ty::BoundConstness::Maybe,
849 }) => {}
850 _ => {
851 ::rustc_middle::util::bug::bug_fmt(format_args!("unexpected non-`HostEffect` clause when computing `{0:?}` implied bounds: {1:?}",
filter, clause));bug!(
852 "unexpected non-`HostEffect` clause when computing \
853 `{filter:?}` implied bounds: {clause:?}"
854 );
855 }
856 }
857 }
858 }
859 PredicateFilter::SelfConstIfConst => {
860 for (clause, _) in bounds {
861 match clause.kind().skip_binder() {
862 ty::ClauseKind::HostEffect(host_clause) => {
863 {
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!(
864 host_clause.constness,
865 ty::BoundConstness::Maybe,
866 "expected `[const]` clause when computing `{filter:?}` \
867 implied bounds: {clause:?}",
868 );
869 {
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!(
870 host_clause.trait_ref.self_ty(),
871 ty,
872 "expected `Self` clause when computing `{filter:?}` \
873 implied bounds: {clause:?}"
874 );
875 }
876 _ => {
877 ::rustc_middle::util::bug::bug_fmt(format_args!("unexpected non-`HostEffect` clause when computing `{0:?}` implied bounds: {1:?}",
filter, clause));bug!(
878 "unexpected non-`HostEffect` clause when computing \
879 `{filter:?}` implied bounds: {clause:?}"
880 );
881 }
882 }
883 }
884 }
885 PredicateFilter::All | PredicateFilter::SelfAndAssociatedTypeBounds => {}
886 }
887}
888
889{}
#[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/0fc141305da7a8a222f65aef1f1acc739c46282b/compiler/rustc_hir_analysis/src/collect/clauses_of.rs"),
::tracing_core::__macro_support::Option::Some(891u32),
::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::panic("internal error: entered unreachable code"),
};
assert_only_contains_clauses_from(PredicateFilter::SelfTraitThatDefines(assoc_ident),
bounds, self_ty);
ty::EarlyBinder::bind_iter(bounds)
}
}
}#[instrument(level = "trace", skip(tcx))]
892pub(super) fn type_param_clauses<'tcx>(
893 tcx: TyCtxt<'tcx>,
894 (item_def_id, def_id, assoc_ident): (LocalDefId, LocalDefId, Ident),
895) -> ty::EarlyBinder<'tcx, &'tcx [(ty::Clause<'tcx>, Span)]> {
896 match tcx.opt_rpitit_info(item_def_id.to_def_id()) {
897 Some(ty::ImplTraitInTraitData::Trait { opaque_def_id, .. }) => {
898 return tcx.type_param_clauses((opaque_def_id.expect_local(), def_id, assoc_ident));
899 }
900 Some(ty::ImplTraitInTraitData::Impl { .. }) => {
901 unreachable!("should not be lowering bounds on RPITIT in impl")
902 }
903 None => {}
904 }
905
906 let param_id = tcx.local_def_id_to_hir_id(def_id);
911 let param_owner = tcx.hir_ty_param_owner(def_id);
912
913 let parent = if item_def_id == param_owner {
915 None
917 } else {
918 tcx.generics_of(item_def_id).parent.map(|def_id| def_id.expect_local())
919 };
920
921 let result = if let Some(parent) = parent {
922 let icx = ItemCtxt::new(tcx, parent);
923 icx.probe_ty_param_bounds(DUMMY_SP, def_id, assoc_ident)
924 } else {
925 ty::EarlyBinder::bind_iter(&[] as &[_])
926 };
927 let mut extend = None;
928
929 let item_hir_id = tcx.local_def_id_to_hir_id(item_def_id);
930
931 let hir_node = tcx.hir_node(item_hir_id);
932 let Some(hir_generics) = hir_node.generics() else {
933 return result;
934 };
935
936 if let Node::Item(item) = hir_node
937 && let hir::ItemKind::Trait { .. } = item.kind
938 && param_id == item_hir_id
940 {
941 let identity_trait_ref = ty::TraitRef::identity(tcx, item_def_id.to_def_id());
942 extend = Some((identity_trait_ref.upcast(tcx), item.span));
943 }
944
945 let icx = ItemCtxt::new(tcx, item_def_id);
946 let extra_clauses = extend.into_iter().chain(icx.probe_ty_param_bounds_in_generics(
947 hir_generics,
948 def_id,
949 PredicateFilter::SelfTraitThatDefines(assoc_ident),
950 ));
951
952 let bounds =
953 &*tcx.arena.alloc_from_iter(result.skip_binder().iter().copied().chain(extra_clauses));
954
955 let self_ty = match tcx.def_kind(def_id) {
957 DefKind::TyParam => Ty::new_param(
958 tcx,
959 tcx.generics_of(item_def_id)
960 .param_def_id_to_index(tcx, def_id.to_def_id())
961 .expect("expected generic param to be owned by item"),
962 tcx.item_name(def_id.to_def_id()),
963 ),
964 DefKind::Trait | DefKind::TraitAlias => tcx.types.self_param,
965 _ => unreachable!(),
966 };
967 assert_only_contains_clauses_from(
968 PredicateFilter::SelfTraitThatDefines(assoc_ident),
969 bounds,
970 self_ty,
971 );
972
973 ty::EarlyBinder::bind_iter(bounds)
974}
975
976impl<'tcx> ItemCtxt<'tcx> {
977 {}
#[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/0fc141305da7a8a222f65aef1f1acc739c46282b/compiler/rustc_hir_analysis/src/collect/clauses_of.rs"),
::tracing_core::__macro_support::Option::Some(982u32),
::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_sizedness_bounds(&mut bounds,
param_ty, &[],
ImpliedBoundsContext::TyParam(param.def_id,
hir_generics.predicates), param.span);
self.lowerer().add_default_traits(&mut bounds, param_ty,
&[],
ImpliedBoundsContext::TyParam(param.def_id,
hir_generics.predicates), param.span);
}
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::panic("internal error: entered unreachable code"),
}
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))]
983 fn probe_ty_param_bounds_in_generics(
984 &self,
985 hir_generics: &'tcx hir::Generics<'tcx>,
986 param_def_id: LocalDefId,
987 filter: PredicateFilter,
988 ) -> Vec<(ty::Clause<'tcx>, Span)> {
989 let mut bounds = Vec::new();
990
991 if let PredicateFilter::All = filter {
992 for param in hir_generics.params {
993 match param.kind {
994 hir::GenericParamKind::Type { .. } => {
995 let param_ty = self.lowerer().lower_ty_param(param.hir_id);
996 self.lowerer().add_implicit_sizedness_bounds(
997 &mut bounds,
998 param_ty,
999 &[],
1000 ImpliedBoundsContext::TyParam(param.def_id, hir_generics.predicates),
1001 param.span,
1002 );
1003 self.lowerer().add_default_traits(
1004 &mut bounds,
1005 param_ty,
1006 &[],
1007 ImpliedBoundsContext::TyParam(param.def_id, hir_generics.predicates),
1008 param.span,
1009 );
1010 }
1011 hir::GenericParamKind::Lifetime { .. }
1012 | hir::GenericParamKind::Const { .. } => {}
1013 }
1014 }
1015 }
1016
1017 for predicate in hir_generics.predicates {
1018 let hir_id = predicate.hir_id;
1019 let hir::WherePredicateKind::BoundPredicate(predicate) = predicate.kind else {
1020 continue;
1021 };
1022
1023 match filter {
1024 _ if predicate.is_param_bound(param_def_id.to_def_id()) => {
1025 }
1027 PredicateFilter::All => {
1028 }
1030 PredicateFilter::SelfOnly
1031 | PredicateFilter::SelfTraitThatDefines(_)
1032 | PredicateFilter::SelfConstIfConst
1033 | PredicateFilter::SelfAndAssociatedTypeBounds => continue,
1034 PredicateFilter::ConstIfConst => unreachable!(),
1035 }
1036
1037 let bound_ty = self.lowerer().lower_ty_maybe_return_type_notation(predicate.bounded_ty);
1038
1039 let bound_vars = self.tcx.late_bound_vars(hir_id);
1040 self.lowerer().lower_bounds(
1041 bound_ty,
1042 predicate.bounds,
1043 &mut bounds,
1044 bound_vars,
1045 filter,
1046 OverlappingAsssocItemConstraints::Allowed,
1047 );
1048 }
1049
1050 bounds
1051 }
1052}
1053
1054pub(super) fn const_conditions<'tcx>(
1055 tcx: TyCtxt<'tcx>,
1056 def_id: LocalDefId,
1057) -> ty::ConstConditions<'tcx> {
1058 if !tcx.is_conditionally_const(def_id) {
1059 ::rustc_middle::util::bug::bug_fmt(format_args!("const_conditions invoked for item that is not conditionally const: {0:?}",
def_id));bug!("const_conditions invoked for item that is not conditionally const: {def_id:?}");
1060 }
1061
1062 match tcx.opt_rpitit_info(def_id.to_def_id()) {
1063 Some(
1065 ty::ImplTraitInTraitData::Impl { fn_def_id }
1066 | ty::ImplTraitInTraitData::Trait { fn_def_id, .. },
1067 ) => return tcx.const_conditions(fn_def_id),
1068 None => {}
1069 }
1070
1071 let (generics, trait_def_id_and_supertraits, has_parent) = match tcx.hir_node_by_def_id(def_id)
1072 {
1073 Node::Item(item) => match item.kind {
1074 hir::ItemKind::Impl(impl_) => (impl_.generics, None, false),
1075 hir::ItemKind::Fn { generics, .. } => (generics, None, false),
1076 hir::ItemKind::Trait { generics, bounds: supertraits, .. } => {
1077 (generics, Some((Some(item.owner_id.def_id), supertraits)), false)
1078 }
1079 hir::ItemKind::TraitAlias(_, _, generics, supertraits) => {
1080 (generics, Some((None, supertraits)), false)
1081 }
1082 _ => ::rustc_middle::util::bug::bug_fmt(format_args!("const_conditions called on wrong item: {0:?}",
def_id))bug!("const_conditions called on wrong item: {def_id:?}"),
1083 },
1084 Node::TraitItem(item) => match item.kind {
1089 hir::TraitItemKind::Fn(_, _) | hir::TraitItemKind::Type(_, _) => {
1090 (item.generics, None, true)
1091 }
1092 _ => ::rustc_middle::util::bug::bug_fmt(format_args!("const_conditions called on wrong item: {0:?}",
def_id))bug!("const_conditions called on wrong item: {def_id:?}"),
1093 },
1094 Node::ImplItem(item) => match item.kind {
1095 hir::ImplItemKind::Fn(_, _) | hir::ImplItemKind::Type(_) => {
1096 (item.generics, None, tcx.is_conditionally_const(tcx.local_parent(def_id)))
1097 }
1098 _ => ::rustc_middle::util::bug::bug_fmt(format_args!("const_conditions called on wrong item: {0:?}",
def_id))bug!("const_conditions called on wrong item: {def_id:?}"),
1099 },
1100 Node::ForeignItem(item) => match item.kind {
1101 hir::ForeignItemKind::Fn(_, _, generics) => (generics, None, false),
1102 _ => ::rustc_middle::util::bug::bug_fmt(format_args!("const_conditions called on wrong item: {0:?}",
def_id))bug!("const_conditions called on wrong item: {def_id:?}"),
1103 },
1104 Node::OpaqueTy(opaque) => match opaque.origin {
1105 hir::OpaqueTyOrigin::FnReturn { parent, .. } => return tcx.const_conditions(parent),
1106 hir::OpaqueTyOrigin::AsyncFn { .. } | hir::OpaqueTyOrigin::TyAlias { .. } => {
1107 ::core::panicking::panic("internal error: entered unreachable code")unreachable!()
1108 }
1109 },
1110 Node::Ctor(hir::VariantData::Tuple { .. }) => return Default::default(),
1112 Node::Expr(hir::Expr { kind: hir::ExprKind::Closure(_), .. }) => {
1113 (hir::Generics::empty(), None, tcx.is_conditionally_const(tcx.local_parent(def_id)))
1114 }
1115 _ => ::rustc_middle::util::bug::bug_fmt(format_args!("const_conditions called on wrong item: {0:?}",
def_id))bug!("const_conditions called on wrong item: {def_id:?}"),
1116 };
1117
1118 let icx = ItemCtxt::new(tcx, def_id);
1119 let mut bounds = Vec::new();
1120
1121 for pred in generics.predicates {
1122 match pred.kind {
1123 hir::WherePredicateKind::BoundPredicate(bound_pred) => {
1124 let ty = icx.lowerer().lower_ty_maybe_return_type_notation(bound_pred.bounded_ty);
1125 let bound_vars = tcx.late_bound_vars(pred.hir_id);
1126 icx.lowerer().lower_bounds(
1127 ty,
1128 bound_pred.bounds.iter(),
1129 &mut bounds,
1130 bound_vars,
1131 PredicateFilter::ConstIfConst,
1132 OverlappingAsssocItemConstraints::Allowed,
1133 );
1134 }
1135 _ => {}
1136 }
1137 }
1138
1139 if let Some((def_id, supertraits)) = trait_def_id_and_supertraits {
1140 if let Some(def_id) = def_id {
1141 bounds.push((
1143 ty::Binder::dummy(ty::TraitRef::identity(tcx, def_id.to_def_id()))
1144 .to_host_effect_clause(tcx, ty::BoundConstness::Maybe),
1145 DUMMY_SP,
1146 ));
1147 }
1148
1149 icx.lowerer().lower_bounds(
1150 tcx.types.self_param,
1151 supertraits,
1152 &mut bounds,
1153 ty::List::empty(),
1154 PredicateFilter::ConstIfConst,
1155 OverlappingAsssocItemConstraints::Allowed,
1156 );
1157 }
1158
1159 ty::ConstConditions {
1160 parent: has_parent.then(|| tcx.local_parent(def_id).to_def_id()),
1161 clauses: tcx.arena.alloc_from_iter(bounds.into_iter().map(|(clause, span)| {
1162 (
1163 clause.kind().map_bound(|clause| match clause {
1164 ty::ClauseKind::HostEffect(ty::HostEffectClause {
1165 trait_ref,
1166 constness: ty::BoundConstness::Maybe,
1167 }) => trait_ref,
1168 _ => ::rustc_middle::util::bug::bug_fmt(format_args!("converted {0:?}", clause))bug!("converted {clause:?}"),
1169 }),
1170 span,
1171 )
1172 })),
1173 }
1174}
1175
1176pub(super) fn explicit_implied_const_bounds<'tcx>(
1177 tcx: TyCtxt<'tcx>,
1178 def_id: LocalDefId,
1179) -> ty::EarlyBinder<'tcx, &'tcx [(ty::PolyTraitRef<'tcx>, Span)]> {
1180 if !tcx.is_conditionally_const(def_id) {
1181 ::rustc_middle::util::bug::bug_fmt(format_args!("explicit_implied_const_bounds invoked for item that is not conditionally const: {0:?}",
def_id));bug!(
1182 "explicit_implied_const_bounds invoked for item that is not conditionally const: {def_id:?}"
1183 );
1184 }
1185
1186 let bounds = match tcx.opt_rpitit_info(def_id.to_def_id()) {
1187 Some(ty::ImplTraitInTraitData::Trait { .. }) => {
1190 explicit_item_bounds_with_filter(tcx, def_id, PredicateFilter::ConstIfConst)
1191 }
1192 Some(ty::ImplTraitInTraitData::Impl { .. }) => {
1193 ::rustc_middle::util::bug::span_bug_fmt(tcx.def_span(def_id),
format_args!("RPITIT in impl should not have item bounds"))span_bug!(tcx.def_span(def_id), "RPITIT in impl should not have item bounds")
1194 }
1195 None => match tcx.hir_node_by_def_id(def_id) {
1196 Node::Item(hir::Item {
1197 kind: hir::ItemKind::Trait { .. } | hir::ItemKind::TraitAlias(..),
1198 ..
1199 }) => implied_clauses_with_filter(
1200 tcx,
1201 def_id.to_def_id(),
1202 PredicateFilter::SelfConstIfConst,
1203 ),
1204 Node::TraitItem(hir::TraitItem { kind: hir::TraitItemKind::Type(..), .. })
1205 | Node::OpaqueTy(_) => {
1206 explicit_item_bounds_with_filter(tcx, def_id, PredicateFilter::ConstIfConst)
1207 }
1208 _ => ::rustc_middle::util::bug::bug_fmt(format_args!("explicit_implied_const_bounds called on wrong item: {0:?}",
def_id))bug!("explicit_implied_const_bounds called on wrong item: {def_id:?}"),
1209 },
1210 };
1211
1212 bounds.map_bound(|bounds| {
1213 &*tcx.arena.alloc_from_iter(bounds.iter().copied().map(|(clause, span)| {
1214 (
1215 clause.kind().map_bound(|clause| match clause {
1216 ty::ClauseKind::HostEffect(ty::HostEffectClause {
1217 trait_ref,
1218 constness: ty::BoundConstness::Maybe,
1219 }) => trait_ref,
1220 _ => ::rustc_middle::util::bug::bug_fmt(format_args!("converted {0:?}", clause))bug!("converted {clause:?}"),
1221 }),
1222 span,
1223 )
1224 }))
1225 })
1226}