1use rustc_hir::def::DefKind;
2use rustc_hir::def_id::DefId;
3use rustc_session::lint;
4use rustc_span::{DUMMY_SP, Span};
5use tracing::{debug, instrument};
6
7use super::{
8 ErrorHandled, EvalToAllocationRawResult, EvalToConstValueResult, GlobalId, ReportedErrorInfo,
9};
10use crate::mir::interpret::ValTreeCreationError;
11use crate::ty::{self, ConstToValTreeResult, GenericArgs, TyCtxt, TypeVisitableExt};
12use crate::{error, mir};
13
14impl<'tcx> TyCtxt<'tcx> {
15 #[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("const_eval_poly",
"rustc_middle::mir::interpret::queries",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_middle/src/mir/interpret/queries.rs"),
::tracing_core::__macro_support::Option::Some(18u32),
::tracing_core::__macro_support::Option::Some("rustc_middle::mir::interpret::queries"),
::tracing_core::field::FieldSet::new(&["def_id"],
::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};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&def_id)
as &dyn 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: EvalToConstValueResult<'tcx> =
loop {};
return __tracing_attr_fake_return;
}
{
let args = GenericArgs::identity_for_item(self, def_id);
let instance = ty::Instance::new_raw(def_id, args);
let cid = GlobalId { instance, promoted: None };
let typing_env = ty::TypingEnv::post_analysis(self, def_id);
self.const_eval_global_id(typing_env, cid, DUMMY_SP)
}
}
}#[instrument(skip(self), level = "debug")]
19 pub fn const_eval_poly(self, def_id: DefId) -> EvalToConstValueResult<'tcx> {
20 let args = GenericArgs::identity_for_item(self, def_id);
25 let instance = ty::Instance::new_raw(def_id, args);
26 let cid = GlobalId { instance, promoted: None };
27 let typing_env = ty::TypingEnv::post_analysis(self, def_id);
28 self.const_eval_global_id(typing_env, cid, DUMMY_SP)
29 }
30
31 #[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("const_eval_poly_to_alloc",
"rustc_middle::mir::interpret::queries",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_middle/src/mir/interpret/queries.rs"),
::tracing_core::__macro_support::Option::Some(34u32),
::tracing_core::__macro_support::Option::Some("rustc_middle::mir::interpret::queries"),
::tracing_core::field::FieldSet::new(&["def_id"],
::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};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&def_id)
as &dyn 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: EvalToAllocationRawResult<'tcx> =
loop {};
return __tracing_attr_fake_return;
}
{
let args = GenericArgs::identity_for_item(self, def_id);
let instance = ty::Instance::new_raw(def_id, args);
let cid = GlobalId { instance, promoted: None };
let typing_env = ty::TypingEnv::post_analysis(self, def_id);
let inputs =
self.erase_and_anonymize_regions(typing_env.as_query_input(cid));
self.eval_to_allocation_raw(inputs)
}
}
}#[instrument(skip(self), level = "debug")]
35 pub fn const_eval_poly_to_alloc(self, def_id: DefId) -> EvalToAllocationRawResult<'tcx> {
36 let args = GenericArgs::identity_for_item(self, def_id);
41 let instance = ty::Instance::new_raw(def_id, args);
42 let cid = GlobalId { instance, promoted: None };
43 let typing_env = ty::TypingEnv::post_analysis(self, def_id);
44 let inputs = self.erase_and_anonymize_regions(typing_env.as_query_input(cid));
45 self.eval_to_allocation_raw(inputs)
46 }
47
48 #[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("const_eval_resolve",
"rustc_middle::mir::interpret::queries",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_middle/src/mir/interpret/queries.rs"),
::tracing_core::__macro_support::Option::Some(57u32),
::tracing_core::__macro_support::Option::Some("rustc_middle::mir::interpret::queries"),
::tracing_core::field::FieldSet::new(&["typing_env", "ct",
"span"], ::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};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&typing_env)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&ct)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&span)
as &dyn 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: EvalToConstValueResult<'tcx> =
loop {};
return __tracing_attr_fake_return;
}
{
if ct.args.has_non_region_infer() {
crate::util::bug::bug_fmt(format_args!("did not expect inference variables here"));
}
match ty::Instance::try_resolve(self, typing_env, ct.def, ct.args)
{
Ok(Some(instance)) => {
let cid = GlobalId { instance, promoted: ct.promoted };
self.const_eval_global_id(typing_env, cid, span)
}
Ok(None) => Err(ErrorHandled::TooGeneric(DUMMY_SP)),
Err(err) => {
Err(ErrorHandled::Reported(ReportedErrorInfo::non_const_eval_error(err),
DUMMY_SP))
}
}
}
}
}#[instrument(level = "debug", skip(self))]
58 pub fn const_eval_resolve(
59 self,
60 typing_env: ty::TypingEnv<'tcx>,
61 ct: mir::UnevaluatedConst<'tcx>,
62 span: Span,
63 ) -> EvalToConstValueResult<'tcx> {
64 if ct.args.has_non_region_infer() {
71 bug!("did not expect inference variables here");
72 }
73
74 match ty::Instance::try_resolve(self, typing_env, ct.def, ct.args) {
76 Ok(Some(instance)) => {
77 let cid = GlobalId { instance, promoted: ct.promoted };
78 self.const_eval_global_id(typing_env, cid, span)
79 }
80 Ok(None) => Err(ErrorHandled::TooGeneric(DUMMY_SP)),
83 Err(err) => {
84 Err(ErrorHandled::Reported(ReportedErrorInfo::non_const_eval_error(err), DUMMY_SP))
85 }
86 }
87 }
88
89 #[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("const_eval_resolve_for_typeck",
"rustc_middle::mir::interpret::queries",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_middle/src/mir/interpret/queries.rs"),
::tracing_core::__macro_support::Option::Some(89u32),
::tracing_core::__macro_support::Option::Some("rustc_middle::mir::interpret::queries"),
::tracing_core::field::FieldSet::new(&["typing_env", "ct",
"span"], ::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};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&typing_env)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&ct)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&span)
as &dyn 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: ConstToValTreeResult<'tcx> =
loop {};
return __tracing_attr_fake_return;
}
{
if ct.args.has_non_region_infer() {
crate::util::bug::bug_fmt(format_args!("did not expect inference variables here"));
}
let cid =
match ty::Instance::try_resolve(self, typing_env,
ct.kind.def_id(), ct.args) {
Ok(Some(instance)) => GlobalId { instance, promoted: None },
Ok(None) => return Err(ErrorHandled::TooGeneric(DUMMY_SP)),
Err(err) => {
return Err(ErrorHandled::Reported(ReportedErrorInfo::non_const_eval_error(err),
DUMMY_SP));
}
};
self.const_eval_global_id_for_typeck(typing_env, cid,
span).inspect(|_|
{
if !self.features().generic_const_exprs() &&
ct.args.has_non_region_param() &&
self.def_kind(cid.instance.def_id()) == DefKind::AnonConst
&& !self.is_trivial_const(cid.instance.def_id()) {
let mir_body = self.mir_for_ctfe(cid.instance.def_id());
if mir_body.is_polymorphic {
let Some(local_def_id) =
ct.kind.def_id().as_local() else { return };
self.emit_node_span_lint(lint::builtin::CONST_EVALUATABLE_UNCHECKED,
self.local_def_id_to_hir_id(local_def_id),
self.def_span(ct.kind.def_id()),
rustc_errors::DiagDecorator(|lint|
{
lint.primary_message("cannot use constants which depend on generic parameters in types");
}))
}
}
})
}
}
}#[instrument(level = "debug", skip(self))]
90 pub fn const_eval_resolve_for_typeck(
91 self,
92 typing_env: ty::TypingEnv<'tcx>,
93 ct: ty::UnevaluatedConst<'tcx>,
94 span: Span,
95 ) -> ConstToValTreeResult<'tcx> {
96 if ct.args.has_non_region_infer() {
103 bug!("did not expect inference variables here");
104 }
105
106 let cid = match ty::Instance::try_resolve(self, typing_env, ct.kind.def_id(), ct.args) {
107 Ok(Some(instance)) => GlobalId { instance, promoted: None },
108 Ok(None) => return Err(ErrorHandled::TooGeneric(DUMMY_SP)),
111 Err(err) => {
112 return Err(ErrorHandled::Reported(
113 ReportedErrorInfo::non_const_eval_error(err),
114 DUMMY_SP,
115 ));
116 }
117 };
118
119 self.const_eval_global_id_for_typeck(typing_env, cid, span).inspect(|_| {
120 if !self.features().generic_const_exprs()
128 && ct.args.has_non_region_param()
129 && self.def_kind(cid.instance.def_id()) == DefKind::AnonConst
136 && !self.is_trivial_const(cid.instance.def_id())
137 {
138 let mir_body = self.mir_for_ctfe(cid.instance.def_id());
139 if mir_body.is_polymorphic {
140 let Some(local_def_id) = ct.kind.def_id().as_local() else { return };
141 self.emit_node_span_lint(
142 lint::builtin::CONST_EVALUATABLE_UNCHECKED,
143 self.local_def_id_to_hir_id(local_def_id),
144 self.def_span(ct.kind.def_id()),
145 rustc_errors::DiagDecorator(|lint| {
146 lint.primary_message(
147 "cannot use constants which depend on generic parameters in types",
148 );
149 }),
150 )
151 }
152 }
153 })
154 }
155
156 pub fn const_eval_instance(
157 self,
158 typing_env: ty::TypingEnv<'tcx>,
159 instance: ty::Instance<'tcx>,
160 span: Span,
161 ) -> EvalToConstValueResult<'tcx> {
162 self.const_eval_global_id(typing_env, GlobalId { instance, promoted: None }, span)
163 }
164
165 #[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("const_eval_global_id",
"rustc_middle::mir::interpret::queries",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_middle/src/mir/interpret/queries.rs"),
::tracing_core::__macro_support::Option::Some(166u32),
::tracing_core::__macro_support::Option::Some("rustc_middle::mir::interpret::queries"),
::tracing_core::field::FieldSet::new(&["typing_env", "cid",
"span"], ::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};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&typing_env)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&cid)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&span)
as &dyn 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: EvalToConstValueResult<'tcx> =
loop {};
return __tracing_attr_fake_return;
}
{
let inputs =
self.erase_and_anonymize_regions(typing_env.with_post_analysis_normalized(self).as_query_input(cid));
if !span.is_dummy() {
self.at(span).eval_to_const_value_raw(inputs).map_err(|e|
e.with_span(span))
} else { self.eval_to_const_value_raw(inputs) }
}
}
}#[instrument(skip(self), level = "debug")]
167 pub fn const_eval_global_id(
168 self,
169 typing_env: ty::TypingEnv<'tcx>,
170 cid: GlobalId<'tcx>,
171 span: Span,
172 ) -> EvalToConstValueResult<'tcx> {
173 let inputs = self.erase_and_anonymize_regions(
176 typing_env.with_post_analysis_normalized(self).as_query_input(cid),
177 );
178 if !span.is_dummy() {
179 self.at(span).eval_to_const_value_raw(inputs).map_err(|e| e.with_span(span))
181 } else {
182 self.eval_to_const_value_raw(inputs)
183 }
184 }
185
186 #[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("const_eval_global_id_for_typeck",
"rustc_middle::mir::interpret::queries",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_middle/src/mir/interpret/queries.rs"),
::tracing_core::__macro_support::Option::Some(187u32),
::tracing_core::__macro_support::Option::Some("rustc_middle::mir::interpret::queries"),
::tracing_core::field::FieldSet::new(&["typing_env", "cid",
"span"], ::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};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&typing_env)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&cid)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&span)
as &dyn 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: ConstToValTreeResult<'tcx> =
loop {};
return __tracing_attr_fake_return;
}
{
let inputs =
self.erase_and_anonymize_regions(typing_env.with_post_analysis_normalized(self).as_query_input(cid));
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_middle/src/mir/interpret/queries.rs:199",
"rustc_middle::mir::interpret::queries",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_middle/src/mir/interpret/queries.rs"),
::tracing_core::__macro_support::Option::Some(199u32),
::tracing_core::__macro_support::Option::Some("rustc_middle::mir::interpret::queries"),
::tracing_core::field::FieldSet::new(&["inputs"],
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&inputs) as
&dyn Value))])
});
} else { ; }
};
let res =
if !span.is_dummy() {
self.at(span).eval_to_valtree(inputs).map_err(|e|
e.with_span(span))
} else { self.eval_to_valtree(inputs) };
match res {
Ok(valtree) => Ok(Ok(valtree)),
Err(err) => {
match err {
ValTreeCreationError::NonSupportedType(ty) => Ok(Err(ty)),
ValTreeCreationError::NodesOverflow => {
let handled =
self.dcx().emit_err(error::MaxNumNodesInValtree {
span,
global_const_id: cid.display(self),
});
Err(ReportedErrorInfo::allowed_in_infallible(handled).into())
}
ValTreeCreationError::InvalidConst => {
let handled =
self.dcx().emit_err(error::InvalidConstInValtree {
span,
global_const_id: cid.display(self),
});
Err(ReportedErrorInfo::allowed_in_infallible(handled).into())
}
ValTreeCreationError::ErrorHandled(handled) => Err(handled),
}
}
}
}
}
}#[instrument(skip(self), level = "debug")]
188 pub fn const_eval_global_id_for_typeck(
189 self,
190 typing_env: ty::TypingEnv<'tcx>,
191 cid: GlobalId<'tcx>,
192 span: Span,
193 ) -> ConstToValTreeResult<'tcx> {
194 let inputs = self.erase_and_anonymize_regions(
197 typing_env.with_post_analysis_normalized(self).as_query_input(cid),
198 );
199 debug!(?inputs);
200 let res = if !span.is_dummy() {
201 self.at(span).eval_to_valtree(inputs).map_err(|e| e.with_span(span))
203 } else {
204 self.eval_to_valtree(inputs)
205 };
206 match res {
207 Ok(valtree) => Ok(Ok(valtree)),
208 Err(err) => {
209 match err {
210 ValTreeCreationError::NonSupportedType(ty) => Ok(Err(ty)),
212 ValTreeCreationError::NodesOverflow => {
214 let handled = self.dcx().emit_err(error::MaxNumNodesInValtree {
215 span,
216 global_const_id: cid.display(self),
217 });
218 Err(ReportedErrorInfo::allowed_in_infallible(handled).into())
219 }
220 ValTreeCreationError::InvalidConst => {
221 let handled = self.dcx().emit_err(error::InvalidConstInValtree {
222 span,
223 global_const_id: cid.display(self),
224 });
225 Err(ReportedErrorInfo::allowed_in_infallible(handled).into())
226 }
227 ValTreeCreationError::ErrorHandled(handled) => Err(handled),
228 }
229 }
230 }
231 }
232}