1use itertools::Itertools;
24use rustc_abi::{ExternAbi, FieldIdx};
25use rustc_apfloat::Float;
26use rustc_apfloat::ieee::{Double, Half, Quad, Single};
27use rustc_attr_ir::find_attr;
28use rustc_data_structures::fx::FxHashMap;
29use rustc_data_structures::sorted_map::SortedIndexMultiMap;
30use rustc_errors::ErrorGuaranteed;
31use rustc_hir::def::DefKind;
32use rustc_hir::def_id::LocalDefId;
33use rustc_hir::{self as hir, BindingMode, ByRef, HirId, ItemLocalId, Node};
34use rustc_index::bit_set::GrowableBitSet;
35use rustc_index::{Idx, IndexSlice, IndexVec};
36use rustc_infer::infer::{InferCtxt, TyCtxtInferExt};
37use rustc_middle::hir::place::PlaceBase as HirPlaceBase;
38use rustc_middle::middle::region;
39use rustc_middle::mir::*;
40use rustc_middle::thir::{self, ExprId, LocalVarId, Param, ParamId, PatKind, Thir};
41use rustc_middle::ty::{self, ScalarInt, Ty, TyCtxt, TypeVisitableExt, TypingMode};
42use rustc_span::{Span, Symbol, bug, span_bug};
43
44use crate::builder::expr::as_place::PlaceBuilder;
45use crate::builder::scope::LintLevel;
46
47pub(crate) fn closure_saved_names_of_captured_variables<'tcx>(
48 tcx: TyCtxt<'tcx>,
49 def_id: LocalDefId,
50) -> IndexVec<FieldIdx, Symbol> {
51 tcx.closure_captures(def_id)
52 .iter()
53 .map(|captured_place| {
54 let name = captured_place.to_symbol();
55 match captured_place.info.capture_kind {
56 ty::UpvarCapture::ByValue | ty::UpvarCapture::ByUse => name,
57 ty::UpvarCapture::ByRef(..) => Symbol::intern(&::alloc::__export::must_use({
::alloc::fmt::format(format_args!("_ref__{0}", name))
})format!("_ref__{name}")),
58 }
59 })
60 .collect()
61}
62
63pub(crate) fn build_mir_inner_impl<'tcx>(tcx: TyCtxt<'tcx>, def: LocalDefId) -> Body<'tcx> {
68 tcx.ensure_done().thir_abstract_const(def);
69 if let Err(e) = tcx.ensure_result().check_match(def) {
70 return construct_error(tcx, def, e);
71 }
72
73 if let Err(err) = tcx.ensure_result().check_tail_calls(def) {
74 return construct_error(tcx, def, err);
75 }
76
77 let body = match tcx.thir_body(def) {
78 Err(error_reported) => construct_error(tcx, def, error_reported),
79 Ok((thir, expr)) => {
80 let build_mir = |thir: &Thir<'tcx>| match thir.body_type {
81 thir::BodyTy::Fn(fn_sig) => construct_fn(tcx, def, thir, expr, fn_sig),
82 thir::BodyTy::Const(ty) | thir::BodyTy::GlobalAsm(ty) => {
83 construct_const(tcx, def, thir, expr, ty)
84 }
85 };
86
87 build_mir(&thir.borrow())
91 }
92 };
93
94 if true {
if !!(body.local_decls.has_free_regions() ||
body.basic_blocks.has_free_regions() ||
body.var_debug_info.has_free_regions() ||
body.yield_ty().has_free_regions()) {
{
::core::panicking::panic_fmt(format_args!("Unexpected free regions in MIR: {0:?}",
body));
}
};
};debug_assert!(
99 !(body.local_decls.has_free_regions()
100 || body.basic_blocks.has_free_regions()
101 || body.var_debug_info.has_free_regions()
102 || body.yield_ty().has_free_regions()),
103 "Unexpected free regions in MIR: {body:?}",
104 );
105
106 body
107}
108
109#[derive(#[automatically_derived]impl ::core::fmt::Debug for BlockFrame {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
Self::Statement { ignores_expr_result: __self_0 } =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"Statement", "ignores_expr_result", &__self_0),
Self::TailExpr { info: __self_0 } =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"TailExpr", "info", &__self_0),
Self::SubExpr => ::core::fmt::Formatter::write_str(f, "SubExpr"),
}
}
}Debug, #[automatically_derived]impl ::core::marker::StructuralPartialEq for
BlockFrame {
}
#[automatically_derived]impl ::core::cmp::PartialEq for BlockFrame {
#[inline]
fn eq(&self, other: &Self) -> bool {
::core::intrinsics::discriminant_value(self) ==
::core::intrinsics::discriminant_value(other) &&
match (self, other) {
(Self::Statement { ignores_expr_result: __self_0 },
Self::Statement { ignores_expr_result: __arg1_0 }) =>
__self_0 == __arg1_0,
(Self::TailExpr { info: __self_0 }, Self::TailExpr {
info: __arg1_0 }) => __self_0 == __arg1_0,
_ => true,
}
}
}PartialEq, #[automatically_derived]impl ::core::cmp::Eq for BlockFrame {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<bool>;
let _: ::core::cmp::AssertParamIsEq<BlockTailInfo>;
}
}Eq)]
113enum BlockFrame {
114 Statement {
121 ignores_expr_result: bool,
124 },
125
126 TailExpr { info: BlockTailInfo },
130
131 SubExpr,
136}
137
138impl BlockFrame {
139 fn is_tail_expr(&self) -> bool {
140 match *self {
141 BlockFrame::TailExpr { .. } => true,
142
143 BlockFrame::Statement { .. } | BlockFrame::SubExpr => false,
144 }
145 }
146 fn is_statement(&self) -> bool {
147 match *self {
148 BlockFrame::Statement { .. } => true,
149
150 BlockFrame::TailExpr { .. } | BlockFrame::SubExpr => false,
151 }
152 }
153}
154
155#[derive(#[automatically_derived]impl ::core::fmt::Debug for BlockContext {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_tuple_field1_finish(f, "BlockContext",
&&self.0)
}
}Debug)]
156struct BlockContext(Vec<BlockFrame>);
157
158struct Builder<'a, 'tcx> {
159 tcx: TyCtxt<'tcx>,
160 infcx: InferCtxt<'tcx>,
165 region_scope_tree: &'tcx region::ScopeTree,
166 param_env: ty::ParamEnv<'tcx>,
167
168 thir: &'a Thir<'tcx>,
169 cfg: CFG<'tcx>,
170
171 def_id: LocalDefId,
172 hir_id: HirId,
173 check_overflow: bool,
174 fn_span: Span,
175 arg_count: usize,
176 coroutine: Option<Box<CoroutineInfo<'tcx>>>,
177
178 scopes: scope::Scopes<'tcx>,
181
182 block_context: BlockContext,
195
196 source_scopes: IndexVec<SourceScope, SourceScopeData<'tcx>>,
199 source_scope: SourceScope,
200
201 guard_context: Vec<GuardFrame>,
205
206 fixed_temps: FxHashMap<ExprId, Local>,
209 fixed_temps_scope: Option<region::Scope>,
211
212 var_indices: FxHashMap<LocalVarId, LocalsForNode>,
215 local_decls: IndexVec<Local, LocalDecl<'tcx>>,
216 canonical_user_type_annotations: ty::CanonicalUserTypeAnnotations<'tcx>,
217 upvars: CaptureMap<'tcx>,
218 unit_temp: Option<Place<'tcx>>,
219
220 var_debug_info: Vec<VarDebugInfo<'tcx>>,
221
222 lint_level_roots_cache: GrowableBitSet<hir::ItemLocalId>,
229
230 coverage_info: Option<coverageinfo::CoverageInfoBuilder>,
233}
234
235type CaptureMap<'tcx> = SortedIndexMultiMap<usize, ItemLocalId, Capture<'tcx>>;
236
237#[derive(#[automatically_derived]impl<'tcx> ::core::fmt::Debug for Capture<'tcx> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field3_finish(f, "Capture",
"captured_place", &self.captured_place, "use_place",
&self.use_place, "mutability", &&self.mutability)
}
}Debug)]
238struct Capture<'tcx> {
239 captured_place: &'tcx ty::CapturedPlace<'tcx>,
240 use_place: Place<'tcx>,
241 mutability: Mutability,
242}
243
244impl<'a, 'tcx> Builder<'a, 'tcx> {
245 fn typing_env(&self) -> ty::TypingEnv<'tcx> {
246 self.infcx.typing_env(self.param_env)
247 }
248
249 fn is_bound_var_in_guard(&self, id: LocalVarId) -> bool {
250 self.guard_context.iter().any(|frame| frame.locals.iter().any(|local| local.id == id))
251 }
252
253 fn var_local_id(&self, id: LocalVarId, for_guard: ForGuard) -> Local {
254 self.var_indices[&id].local_id(for_guard)
255 }
256}
257
258impl BlockContext {
259 fn new() -> Self {
260 BlockContext(::alloc::vec::Vec::new()vec![])
261 }
262 fn push(&mut self, bf: BlockFrame) {
263 self.0.push(bf);
264 }
265 fn pop(&mut self) -> Option<BlockFrame> {
266 self.0.pop()
267 }
268
269 fn currently_in_block_tail(&self) -> Option<BlockTailInfo> {
280 for bf in self.0.iter().rev() {
281 match bf {
282 BlockFrame::SubExpr => continue,
283 BlockFrame::Statement { .. } => break,
284 &BlockFrame::TailExpr { info } => return Some(info),
285 }
286 }
287
288 None
289 }
290
291 fn currently_ignores_tail_results(&self) -> bool {
298 match self.0.last() {
299 None => false,
301
302 Some(BlockFrame::SubExpr) => false,
304
305 Some(
307 BlockFrame::TailExpr { info: BlockTailInfo { tail_result_is_ignored: ign, .. } }
308 | BlockFrame::Statement { ignores_expr_result: ign },
309 ) => *ign,
310 }
311 }
312}
313
314#[derive(#[automatically_derived]impl ::core::fmt::Debug for LocalsForNode {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
Self::One(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f, "One",
&__self_0),
Self::ForGuard { ref_for_guard: __self_0, for_arm_body: __self_1 }
=>
::core::fmt::Formatter::debug_struct_field2_finish(f,
"ForGuard", "ref_for_guard", __self_0, "for_arm_body",
&__self_1),
}
}
}Debug)]
315enum LocalsForNode {
316 One(Local),
319
320 ForGuard { ref_for_guard: Local, for_arm_body: Local },
331}
332
333#[derive(#[automatically_derived]impl ::core::fmt::Debug for GuardFrameLocal {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field1_finish(f,
"GuardFrameLocal", "id", &&self.id)
}
}Debug)]
334struct GuardFrameLocal {
335 id: LocalVarId,
336}
337
338impl GuardFrameLocal {
339 fn new(id: LocalVarId) -> Self {
340 GuardFrameLocal { id }
341 }
342}
343
344#[derive(#[automatically_derived]impl ::core::fmt::Debug for GuardFrame {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field1_finish(f, "GuardFrame",
"locals", &&self.locals)
}
}Debug)]
345struct GuardFrame {
346 locals: Vec<GuardFrameLocal>,
358}
359
360#[derive(#[automatically_derived]impl ::core::marker::Copy for ForGuard { }Copy, #[automatically_derived]#[doc(hidden)]unsafe impl ::core::clone::TrivialClone
for ForGuard {
}
#[automatically_derived]impl ::core::clone::Clone for ForGuard {
#[inline]
fn clone(&self) -> Self { *self }
}Clone, #[automatically_derived]impl ::core::fmt::Debug for ForGuard {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f,
match self {
ForGuard::RefWithinGuard => "RefWithinGuard",
ForGuard::OutsideGuard => "OutsideGuard",
})
}
}Debug, #[automatically_derived]impl ::core::marker::StructuralPartialEq for ForGuard
{
}
#[automatically_derived]impl ::core::cmp::PartialEq for ForGuard {
#[inline]
fn eq(&self, other: &Self) -> bool {
::core::intrinsics::discriminant_value(self) ==
::core::intrinsics::discriminant_value(other)
}
}PartialEq, #[automatically_derived]impl ::core::cmp::Eq for ForGuard { }Eq)]
365enum ForGuard {
366 RefWithinGuard,
367 OutsideGuard,
368}
369
370impl LocalsForNode {
371 fn local_id(&self, for_guard: ForGuard) -> Local {
372 match (self, for_guard) {
373 (&LocalsForNode::One(local_id), ForGuard::OutsideGuard)
374 | (
375 &LocalsForNode::ForGuard { ref_for_guard: local_id, .. },
376 ForGuard::RefWithinGuard,
377 )
378 | (&LocalsForNode::ForGuard { for_arm_body: local_id, .. }, ForGuard::OutsideGuard) => {
379 local_id
380 }
381
382 (&LocalsForNode::One(_), ForGuard::RefWithinGuard) => {
383 ::rustc_span::macros::bug_impl(None,
format_args!("anything with one local should never be within a guard."),
Location::caller())bug!("anything with one local should never be within a guard.")
384 }
385 }
386 }
387}
388
389struct CFG<'tcx> {
390 basic_blocks: IndexVec<BasicBlock, BasicBlockData<'tcx>>,
391}
392
393#[automatically_derived]impl ::core::marker::Copy for ScopeId { }
impl ScopeId {
#[doc = r" Maximum value the index can take, as a `u32`."]
const MAX_AS_U32: u32 = 0xFFFF_FF00;
#[doc = r" Maximum value the index can take."]
const MAX: Self = Self::from_u32(0xFFFF_FF00);
#[doc = r" Zero value of the index."]
const ZERO: Self = Self::from_u32(0);
#[doc = r" Creates a new index from a given `usize`."]
#[doc = r""]
#[doc = r" # Panics"]
#[doc = r""]
#[doc = r" Will panic if `value` exceeds `MAX`."]
#[inline]
const fn from_usize(value: usize) -> Self {
if !(value <= (0xFFFF_FF00 as usize)) {
::core::panicking::panic("assertion failed: value <= (0xFFFF_FF00 as usize)")
};
unsafe { Self::from_u32_unchecked(value as u32) }
}
#[doc = r" Creates a new index from a given `u32`."]
#[doc = r""]
#[doc = r" # Panics"]
#[doc = r""]
#[doc = r" Will panic if `value` exceeds `MAX`."]
#[inline]
const fn from_u32(value: u32) -> Self {
if !(value <= 0xFFFF_FF00) {
::core::panicking::panic("assertion failed: value <= 0xFFFF_FF00")
};
unsafe { Self::from_u32_unchecked(value) }
}
#[doc = r" Creates a new index from a given `u16`."]
#[doc = r""]
#[doc = r" # Panics"]
#[doc = r""]
#[doc = r" Will panic if `value` exceeds `MAX`."]
#[inline]
const fn from_u16(value: u16) -> Self {
let value = value as u32;
if !(value <= 0xFFFF_FF00) {
::core::panicking::panic("assertion failed: value <= 0xFFFF_FF00")
};
unsafe { Self::from_u32_unchecked(value) }
}
#[doc = r" Creates a new index from a given `u32`."]
#[doc = r""]
#[doc = r" # Safety"]
#[doc = r""]
#[doc =
r" The provided value must be less than or equal to the maximum value for the newtype."]
#[doc =
r" Providing a value outside this range is undefined due to layout restrictions."]
#[doc = r""]
#[doc = r" Prefer using `from_u32`."]
#[inline]
const unsafe fn from_u32_unchecked(value: u32) -> Self {
Self {
private_use_as_methods_instead: unsafe {
std::mem::transmute(value)
},
}
}
#[doc = r" Extracts the value of this index as a `usize`."]
#[inline]
const fn index(self) -> usize { self.as_usize() }
#[doc = r" Extracts the value of this index as a `u32`."]
#[inline]
const fn as_u32(self) -> u32 {
unsafe { std::mem::transmute(self.private_use_as_methods_instead) }
}
#[doc = r" Extracts the value of this index as a `usize`."]
#[inline]
const fn as_usize(self) -> usize { self.as_u32() as usize }
}
impl std::ops::Add<usize> for ScopeId {
type Output = Self;
#[inline]
fn add(self, other: usize) -> Self {
Self::from_usize(self.index() + other)
}
}
impl std::ops::AddAssign<usize> for ScopeId {
#[inline]
fn add_assign(&mut self, other: usize) { *self = *self + other; }
}
impl rustc_index::Idx for ScopeId {
#[inline]
fn new(value: usize) -> Self { Self::from_usize(value) }
#[inline]
fn index(self) -> usize { self.as_usize() }
}
impl From<ScopeId> for u32 {
#[inline]
fn from(v: ScopeId) -> u32 { v.as_u32() }
}
impl From<ScopeId> for usize {
#[inline]
fn from(v: ScopeId) -> usize { v.as_usize() }
}
impl From<usize> for ScopeId {
#[inline]
fn from(value: usize) -> Self { Self::from_usize(value) }
}
impl From<u32> for ScopeId {
#[inline]
fn from(value: u32) -> Self { Self::from_u32(value) }
}
impl ::std::cmp::Eq for ScopeId {}
impl ::std::cmp::PartialEq for ScopeId {
fn eq(&self, other: &Self) -> bool { self.as_u32().eq(&other.as_u32()) }
}
impl ::std::marker::StructuralPartialEq for ScopeId {}
impl ::std::hash::Hash for ScopeId {
fn hash<H: ::std::hash::Hasher>(&self, state: &mut H) {
self.as_u32().hash(state)
}
}
impl ::std::fmt::Debug for ScopeId {
fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
fmt.write_fmt(format_args!("{0}", self.as_u32()))
}
}rustc_index::newtype_index! {
394 struct ScopeId {}
395}
396
397#[derive(#[automatically_derived]impl ::core::fmt::Debug for NeedsTemporary {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f,
match self {
NeedsTemporary::No => "No",
NeedsTemporary::Maybe => "Maybe",
})
}
}Debug)]
398enum NeedsTemporary {
399 No,
404 Maybe,
407}
408
409#[must_use = "if you don't use one of these results, you're leaving a dangling edge"]
414struct BlockAnd<T>(BasicBlock, T);
415
416impl BlockAnd<()> {
417 #[must_use]
419 fn into_block(self) -> BasicBlock {
420 let Self(block, ()) = self;
421 block
422 }
423}
424
425trait BlockAndExtension {
426 fn and<T>(self, v: T) -> BlockAnd<T>;
427 fn unit(self) -> BlockAnd<()>;
428}
429
430impl BlockAndExtension for BasicBlock {
431 fn and<T>(self, v: T) -> BlockAnd<T> {
432 BlockAnd(self, v)
433 }
434
435 fn unit(self) -> BlockAnd<()> {
436 BlockAnd(self, ())
437 }
438}
439
440macro_rules! unpack {
443 ($x:ident = $c:expr) => {{
444 let BlockAnd(b, v) = $c;
445 $x = b;
446 v
447 }};
448}
449
450fn construct_fn<'tcx>(
452 tcx: TyCtxt<'tcx>,
453 fn_def: LocalDefId,
454 thir: &Thir<'tcx>,
455 expr: ExprId,
456 fn_sig: ty::FnSig<'tcx>,
457) -> Body<'tcx> {
458 let span = tcx.def_span(fn_def);
459 let fn_id = tcx.local_def_id_to_hir_id(fn_def);
460
461 let body = tcx.hir_body_owned_by(fn_def);
463 let span_with_body = tcx.hir_span_with_body(fn_id);
464 let return_ty_span = tcx
465 .hir_fn_decl_by_hir_id(fn_id)
466 .unwrap_or_else(|| ::rustc_span::macros::bug_impl(Some(span),
format_args!("can\'t build MIR for {0:?}", fn_def), Location::caller())span_bug!(span, "can't build MIR for {:?}", fn_def))
467 .output
468 .span();
469
470 let mut abi = fn_sig.abi();
471 if let DefKind::Closure = tcx.def_kind(fn_def) {
472 abi = ExternAbi::Rust;
475 }
476
477 let arguments = &thir.params;
478
479 let return_ty = fn_sig.output();
480
481 if let Some((dialect, phase)) =
482 {
{
'done:
{
for i in ::rustc_attr_ir::HasAttrs::get_attrs(fn_id, &tcx) {
#[allow(unused_imports)]
use ::rustc_attr_ir::AttributeKind::*;
let i: &::rustc_attr_ir::Attribute = i;
match i {
::rustc_attr_ir::Attribute::Parsed(CustomMir(dialect,
phase)) => {
break 'done Some((dialect, phase));
}
::rustc_attr_ir::Attribute::Tool(..) |
::rustc_attr_ir::Attribute::DeriveHelper(..) =>
{}
#[deny(unreachable_patterns)]
_ => {}
}
}
None
}
}
}find_attr!(tcx, fn_id, CustomMir(dialect, phase) => (dialect, phase))
483 {
484 return custom::build_custom_mir(
485 tcx,
486 fn_def.to_def_id(),
487 fn_id,
488 thir,
489 expr,
490 arguments,
491 return_ty,
492 return_ty_span,
493 span_with_body,
494 dialect.as_ref().map(|(d, _)| *d),
495 phase.as_ref().map(|(p, _)| *p),
496 );
497 }
498
499 let typing_mode = if tcx.use_typing_mode_post_typeck_through_borrowck() {
500 TypingMode::borrowck(tcx, fn_def)
501 } else {
502 TypingMode::non_body_analysis()
505 };
506
507 let infcx = tcx.infer_ctxt().build(typing_mode);
508
509 let defining_ty = tcx.type_of(fn_def).instantiate_identity().skip_normalization();
510 let defining_ty = if infcx.next_trait_solver() {
511 ty::set_aliases_to_rigid(tcx, defining_ty)
516 } else {
517 defining_ty
518 };
519 let coroutine = match defining_ty.kind() {
520 ty::Coroutine(_, args) => Some(Box::new(CoroutineInfo::initial(
521 tcx.coroutine_kind(fn_def).unwrap(),
522 args.as_coroutine().yield_ty(),
523 args.as_coroutine().resume_ty(),
524 ))),
525 ty::Closure(..) | ty::CoroutineClosure(..) | ty::FnDef(..) => None,
526 ty => ::rustc_span::macros::bug_impl(Some(span_with_body),
format_args!("unexpected type of body: {0:?}", ty), Location::caller())span_bug!(span_with_body, "unexpected type of body: {ty:?}"),
527 };
528
529 let mut builder = Builder::new(
530 thir,
531 infcx,
532 fn_def,
533 fn_id,
534 span_with_body,
535 arguments.len(),
536 return_ty,
537 return_ty_span,
538 coroutine,
539 );
540
541 let call_site_scope =
542 region::Scope { local_id: body.id().hir_id.local_id, data: region::ScopeData::CallSite };
543 let arg_scope =
544 region::Scope { local_id: body.id().hir_id.local_id, data: region::ScopeData::Arguments };
545 let source_info = builder.source_info(span);
546 let call_site_s = (call_site_scope, source_info);
547 let _: BlockAnd<()> = builder.in_scope(call_site_s, LintLevel::Inherited, |builder| {
548 let arg_scope_s = (arg_scope, source_info);
549 let fn_end = span_with_body.shrink_to_hi();
551 let return_block = builder
552 .in_breakable_scope(None, Place::return_place(), fn_end, |builder| {
553 Some(builder.in_scope(arg_scope_s, LintLevel::Inherited, |builder| {
554 builder.args_and_body(START_BLOCK, arguments, arg_scope, expr)
555 }))
556 })
557 .into_block();
558 let source_info = builder.source_info(fn_end);
559 builder.push_coverage_point_for_fn_end(return_block, source_info, fn_id);
560 builder.cfg.terminate(return_block, source_info, TerminatorKind::Return);
561 builder.build_drop_trees();
562 return_block.unit()
563 });
564
565 let mut body = builder.finish();
566
567 body.spread_arg = if abi == ExternAbi::RustCall {
568 Some(Local::new(arguments.len()))
571 } else {
572 None
573 };
574
575 body
576}
577
578fn construct_const<'a, 'tcx>(
579 tcx: TyCtxt<'tcx>,
580 def: LocalDefId,
581 thir: &'a Thir<'tcx>,
582 expr: ExprId,
583 const_ty: Ty<'tcx>,
584) -> Body<'tcx> {
585 let hir_id = tcx.local_def_id_to_hir_id(def);
586
587 let (span, const_ty_span) = match tcx.hir_node(hir_id) {
589 Node::Item(hir::Item {
590 kind: hir::ItemKind::Static(_, _, ty, _) | hir::ItemKind::Const(_, _, ty, _),
591 span,
592 ..
593 })
594 | Node::ImplItem(hir::ImplItem { kind: hir::ImplItemKind::Const(ty, _), span, .. })
595 | Node::TraitItem(hir::TraitItem {
596 kind: hir::TraitItemKind::Const(ty, Some(_)),
597 span,
598 ..
599 }) => (*span, ty.span),
600 Node::AnonConst(ct) => (ct.span, ct.span),
601 Node::ConstBlock(_) => {
602 let span = tcx.def_span(def);
603 (span, span)
604 }
605 Node::Item(hir::Item { kind: hir::ItemKind::GlobalAsm { .. }, span, .. }) => (*span, *span),
606 _ => ::rustc_span::macros::bug_impl(Some(tcx.def_span(def)),
format_args!("can\'t build MIR for {0:?}", def), Location::caller())span_bug!(tcx.def_span(def), "can't build MIR for {:?}", def),
607 };
608
609 let typing_mode = if tcx.use_typing_mode_post_typeck_through_borrowck() {
610 TypingMode::borrowck(tcx, def)
611 } else {
612 TypingMode::non_body_analysis()
615 };
616
617 let infcx = tcx.infer_ctxt().build(typing_mode);
618 let mut builder =
619 Builder::new(thir, infcx, def, hir_id, span, 0, const_ty, const_ty_span, None);
620
621 let mut block = START_BLOCK;
622 block = builder.expr_into_dest(Place::return_place(), block, expr).into_block();
623
624 let source_info = builder.source_info(span);
625 builder.cfg.terminate(block, source_info, TerminatorKind::Return);
626
627 builder.build_drop_trees();
628 builder.finish()
629}
630
631fn construct_error(tcx: TyCtxt<'_>, def_id: LocalDefId, guar: ErrorGuaranteed) -> Body<'_> {
636 let span = tcx.def_span(def_id);
637 let hir_id = tcx.local_def_id_to_hir_id(def_id);
638
639 let (inputs, output, coroutine) = match tcx.def_kind(def_id) {
640 DefKind::Const
641 | DefKind::AssocConst
642 | DefKind::AnonConst
643 | DefKind::Static { .. }
644 | DefKind::GlobalAsm => {
645 (::alloc::vec::Vec::new()vec![], tcx.type_of(def_id).instantiate_identity().skip_norm_wip(), None)
646 }
647 DefKind::Ctor(..) | DefKind::Fn | DefKind::AssocFn => {
648 let sig = tcx.liberate_late_bound_regions(
649 def_id.to_def_id(),
650 tcx.fn_sig(def_id).instantiate_identity().skip_norm_wip(),
651 );
652 (sig.inputs().to_vec(), sig.output(), None)
653 }
654 DefKind::Closure => {
655 let closure_ty = tcx.type_of(def_id).instantiate_identity().skip_normalization();
656 let closure_ty = if tcx.next_trait_solver_globally() {
657 ty::set_aliases_to_rigid(tcx, closure_ty)
661 } else {
662 closure_ty
663 };
664 match closure_ty.kind() {
665 ty::Closure(_, args) => {
666 let args = args.as_closure();
667 let sig = tcx.liberate_late_bound_regions(def_id.to_def_id(), args.sig());
668 let self_ty = match args.kind() {
669 ty::ClosureKind::Fn => {
670 Ty::new_imm_ref(tcx, tcx.lifetimes.re_erased, closure_ty)
671 }
672 ty::ClosureKind::FnMut => {
673 Ty::new_mut_ref(tcx, tcx.lifetimes.re_erased, closure_ty)
674 }
675 ty::ClosureKind::FnOnce => closure_ty,
676 };
677 (
678 [self_ty].into_iter().chain(sig.inputs()[0].tuple_fields()).collect(),
679 sig.output(),
680 None,
681 )
682 }
683 ty::Coroutine(_, args) => {
684 let args = args.as_coroutine();
685 let resume_ty = args.resume_ty();
686 let yield_ty = args.yield_ty();
687 let return_ty = args.return_ty();
688 (
689 ::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
[closure_ty, resume_ty]))vec![closure_ty, resume_ty],
690 return_ty,
691 Some(Box::new(CoroutineInfo::initial(
692 tcx.coroutine_kind(def_id).unwrap(),
693 yield_ty,
694 resume_ty,
695 ))),
696 )
697 }
698 ty::CoroutineClosure(did, args) => {
699 let args = args.as_coroutine_closure();
700 let sig = tcx.liberate_late_bound_regions(
701 def_id.to_def_id(),
702 args.coroutine_closure_sig(),
703 );
704 let self_ty = match args.kind() {
705 ty::ClosureKind::Fn => {
706 Ty::new_imm_ref(tcx, tcx.lifetimes.re_erased, closure_ty)
707 }
708 ty::ClosureKind::FnMut => {
709 Ty::new_mut_ref(tcx, tcx.lifetimes.re_erased, closure_ty)
710 }
711 ty::ClosureKind::FnOnce => closure_ty,
712 };
713 (
714 [self_ty].into_iter().chain(sig.tupled_inputs_ty.tuple_fields()).collect(),
715 sig.to_coroutine(
716 tcx,
717 args.parent_args(),
718 args.kind_ty(),
719 tcx.coroutine_for_closure(*did),
720 Ty::new_error(tcx, guar),
721 ),
722 None,
723 )
724 }
725 ty::Error(_) => (::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
[closure_ty, closure_ty]))vec![closure_ty, closure_ty], closure_ty, None),
726 kind => {
727 ::rustc_span::macros::bug_impl(Some(span),
format_args!("expected type of closure body to be a closure or coroutine, got {0:?}",
kind), Location::caller());span_bug!(
728 span,
729 "expected type of closure body to be a closure or coroutine, got {kind:?}"
730 );
731 }
732 }
733 }
734 dk => ::rustc_span::macros::bug_impl(Some(span),
format_args!("{0:?} is not a body: {1:?}", def_id, dk),
Location::caller())span_bug!(span, "{:?} is not a body: {:?}", def_id, dk),
735 };
736
737 let source_info = SourceInfo { span, scope: OUTERMOST_SOURCE_SCOPE };
738 let local_decls = IndexVec::from_iter(
739 [output].iter().chain(&inputs).map(|ty| LocalDecl::with_source_info(*ty, source_info)),
740 );
741 let mut cfg = CFG { basic_blocks: IndexVec::new() };
742 let mut source_scopes = IndexVec::new();
743
744 cfg.start_new_block();
745 source_scopes.push(SourceScopeData {
746 span,
747 parent_scope: None,
748 inlined: None,
749 inlined_parent_scope: None,
750 local_data: ClearCrossCrate::Set(SourceScopeLocalData { lint_root: hir_id }),
751 });
752
753 cfg.terminate(START_BLOCK, source_info, TerminatorKind::Unreachable);
754
755 Body::new(
756 MirSource::item(def_id.to_def_id()),
757 cfg.basic_blocks,
758 source_scopes,
759 local_decls,
760 IndexVec::new(),
761 inputs.len(),
762 ::alloc::vec::Vec::new()vec![],
763 span,
764 coroutine,
765 Some(guar),
766 )
767}
768
769impl<'a, 'tcx> Builder<'a, 'tcx> {
770 fn new(
771 thir: &'a Thir<'tcx>,
772 infcx: InferCtxt<'tcx>,
773 def: LocalDefId,
774 hir_id: HirId,
775 span: Span,
776 arg_count: usize,
777 return_ty: Ty<'tcx>,
778 return_span: Span,
779 coroutine: Option<Box<CoroutineInfo<'tcx>>>,
780 ) -> Builder<'a, 'tcx> {
781 let tcx = infcx.tcx;
782 let mut check_overflow = {
{
'done:
{
for i in tcx.hir_attrs(hir_id) {
#[allow(unused_imports)]
use ::rustc_attr_ir::AttributeKind::*;
let i: &::rustc_attr_ir::Attribute = i;
match i {
::rustc_attr_ir::Attribute::Parsed(RustcInheritOverflowChecks)
=> {
break 'done Some(());
}
::rustc_attr_ir::Attribute::Tool(..) |
::rustc_attr_ir::Attribute::DeriveHelper(..) =>
{}
#[deny(unreachable_patterns)]
_ => {}
}
}
None
}
}.is_some()
}find_attr!(tcx.hir_attrs(hir_id), RustcInheritOverflowChecks);
786 check_overflow |= tcx.sess.overflow_checks();
788 check_overflow |= #[allow(non_exhaustive_omitted_patterns)] match tcx.hir_body_owner_kind(def) {
hir::BodyOwnerKind::Const { .. } | hir::BodyOwnerKind::Static(_) => true,
_ => false,
}matches!(
790 tcx.hir_body_owner_kind(def),
791 hir::BodyOwnerKind::Const { .. } | hir::BodyOwnerKind::Static(_)
792 );
793
794 let lint_level = LintLevel::Explicit(hir_id);
795 let param_env = tcx.param_env(def);
796 let mut builder = Builder {
797 thir,
798 tcx,
799 infcx,
800 region_scope_tree: tcx.region_scope_tree(def),
801 param_env,
802 def_id: def,
803 hir_id,
804 check_overflow,
805 cfg: CFG { basic_blocks: IndexVec::new() },
806 fn_span: span,
807 arg_count,
808 coroutine,
809 scopes: scope::Scopes::new(),
810 block_context: BlockContext::new(),
811 source_scopes: IndexVec::new(),
812 source_scope: OUTERMOST_SOURCE_SCOPE,
813 guard_context: ::alloc::vec::Vec::new()vec![],
814 fixed_temps: Default::default(),
815 fixed_temps_scope: None,
816 local_decls: IndexVec::from_elem_n(LocalDecl::new(return_ty, return_span), 1),
817 canonical_user_type_annotations: IndexVec::new(),
818 upvars: CaptureMap::new(),
819 var_indices: Default::default(),
820 unit_temp: None,
821 var_debug_info: ::alloc::vec::Vec::new()vec![],
822 lint_level_roots_cache: GrowableBitSet::new_empty(),
823 coverage_info: coverageinfo::CoverageInfoBuilder::new_if_enabled(tcx, def),
824 };
825
826 {
match (&builder.cfg.start_new_block(), &START_BLOCK) {
(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!(builder.cfg.start_new_block(), START_BLOCK);
827 {
match (&builder.new_source_scope(span, lint_level),
&OUTERMOST_SOURCE_SCOPE) {
(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!(builder.new_source_scope(span, lint_level), OUTERMOST_SOURCE_SCOPE);
828 builder.source_scopes[OUTERMOST_SOURCE_SCOPE].parent_scope = None;
829
830 builder
831 }
832
833 #[allow(dead_code)]
834 fn dump_for_debugging(&self) {
835 let mut body = Body::new(
836 MirSource::item(self.def_id.to_def_id()),
837 self.cfg.basic_blocks.clone(),
838 self.source_scopes.clone(),
839 self.local_decls.clone(),
840 self.canonical_user_type_annotations.clone(),
841 self.arg_count.clone(),
842 self.var_debug_info.clone(),
843 self.fn_span.clone(),
844 self.coroutine.clone(),
845 None,
846 );
847 body.coverage_early_info = self.coverage_info.as_ref().map(|b| b.as_done());
848
849 let writer = pretty::MirWriter::new(self.tcx);
850 writer.write_mir_fn(&body, &mut std::io::stdout()).unwrap();
851 }
852
853 fn finish(self) -> Body<'tcx> {
854 let mut body = Body::new(
855 MirSource::item(self.def_id.to_def_id()),
856 self.cfg.basic_blocks,
857 self.source_scopes,
858 self.local_decls,
859 self.canonical_user_type_annotations,
860 self.arg_count,
861 self.var_debug_info,
862 self.fn_span,
863 self.coroutine,
864 None,
865 );
866 body.coverage_early_info = self.coverage_info.map(|b| b.into_done());
867
868 let writer = pretty::MirWriter::new(self.tcx);
869 for (index, block) in body.basic_blocks.iter().enumerate() {
870 if block.terminator.is_none() {
871 writer.write_mir_fn(&body, &mut std::io::stdout()).unwrap();
872 ::rustc_span::macros::bug_impl(Some(self.fn_span),
format_args!("no terminator on block {0:?}", index), Location::caller());span_bug!(self.fn_span, "no terminator on block {:?}", index);
873 }
874 }
875
876 body
877 }
878
879 fn insert_upvar_arg(&mut self) {
880 let Some(closure_arg) = self.local_decls.get(ty::CAPTURE_STRUCT_LOCAL) else { return };
881
882 let mut closure_ty = closure_arg.ty;
883 let mut closure_env_projs = ::alloc::vec::Vec::new()vec![];
884 if let ty::Ref(_, ty, _) = closure_ty.kind() {
885 closure_env_projs.push(ProjectionElem::Deref);
886 closure_ty = *ty;
887 }
888
889 let upvar_args = match closure_ty.kind() {
890 ty::Closure(_, args) => ty::UpvarArgs::Closure(args),
891 ty::Coroutine(_, args) => ty::UpvarArgs::Coroutine(args),
892 ty::CoroutineClosure(_, args) => ty::UpvarArgs::CoroutineClosure(args),
893 _ => return,
894 };
895
896 let capture_tys = upvar_args.upvar_tys();
902
903 let tcx = self.tcx;
904 let mut upvar_owner = None;
905 self.upvars = tcx
906 .closure_captures(self.def_id)
907 .iter()
908 .zip_eq(capture_tys)
909 .enumerate()
910 .map(|(i, (captured_place, ty))| {
911 let name = captured_place.to_symbol();
912
913 let capture = captured_place.info.capture_kind;
914 let var_id = match captured_place.place.base {
915 HirPlaceBase::Upvar(upvar_id) => upvar_id.var_path.hir_id,
916 _ => ::rustc_span::macros::bug_impl(None, format_args!("Expected an upvar"),
Location::caller())bug!("Expected an upvar"),
917 };
918 let upvar_base = upvar_owner.get_or_insert(var_id.owner);
919 {
match (&*upvar_base, &var_id.owner) {
(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!(*upvar_base, var_id.owner);
920 let var_id = var_id.local_id;
921
922 let mutability = captured_place.mutability;
923
924 let mut projs = closure_env_projs.clone();
925 projs.push(ProjectionElem::Field(FieldIdx::new(i), ty));
926 match capture {
927 ty::UpvarCapture::ByValue | ty::UpvarCapture::ByUse => {}
928 ty::UpvarCapture::ByRef(..) => {
929 projs.push(ProjectionElem::Deref);
930 }
931 };
932
933 let use_place = Place {
934 local: ty::CAPTURE_STRUCT_LOCAL,
935 projection: tcx.mk_place_elems(&projs),
936 };
937 self.var_debug_info.push(VarDebugInfo {
938 name,
939 source_info: SourceInfo::outermost(captured_place.var_ident.span),
940 value: VarDebugInfoContents::Place(use_place),
941 composite: None,
942 argument_index: None,
943 });
944
945 let capture = Capture { captured_place, use_place, mutability };
946 (var_id, capture)
947 })
948 .collect();
949 }
950
951 fn args_and_body(
952 &mut self,
953 mut block: BasicBlock,
954 arguments: &IndexSlice<ParamId, Param<'tcx>>,
955 argument_scope: region::Scope,
956 expr_id: ExprId,
957 ) -> BlockAnd<()> {
958 let expr_span = self.thir[expr_id].span;
959 for (argument_index, param) in arguments.iter().enumerate() {
961 let source_info =
962 SourceInfo::outermost(param.pat.as_ref().map_or(self.fn_span, |pat| pat.span));
963 let arg_local =
964 self.local_decls.push(LocalDecl::with_source_info(param.ty, source_info));
965
966 if let Some(ref pat) = param.pat
968 && let Some(name) = pat.simple_ident()
969 {
970 self.var_debug_info.push(VarDebugInfo {
971 name,
972 source_info,
973 value: VarDebugInfoContents::Place(arg_local.into()),
974 composite: None,
975 argument_index: Some(argument_index as u16 + 1),
976 });
977 }
978 }
979
980 self.insert_upvar_arg();
981
982 let mut scope = None;
983 for (index, param) in arguments.iter().enumerate() {
985 let local = Local::arg(index);
987 let place = Place::from(local);
988
989 self.schedule_drop_value(
991 param.pat.as_ref().map_or(expr_span, |pat| pat.span),
992 argument_scope,
993 local,
994 );
995
996 let Some(ref pat) = param.pat else {
997 continue;
998 };
999 let original_source_scope = self.source_scope;
1000 let span = pat.span;
1001 if let Some(arg_hir_id) = param.hir_id {
1002 self.set_correct_source_scope_for_arg(arg_hir_id, original_source_scope, span);
1003 }
1004 match pat.kind {
1005 PatKind::Binding {
1007 var,
1008 mode: BindingMode(ByRef::No, mutability),
1009 subpattern: None,
1010 ..
1011 } => {
1012 self.local_decls[local].mutability = mutability;
1013 self.local_decls[local].source_info.scope = self.source_scope;
1014 **self.local_decls[local].local_info.as_mut().unwrap_crate_local() =
1015 if let Some(kind) = param.self_kind {
1016 LocalInfo::User(BindingForm::ImplicitSelf(kind))
1017 } else {
1018 let binding_mode = BindingMode(ByRef::No, mutability);
1019 LocalInfo::User(BindingForm::Var(VarBindingForm {
1020 binding_mode,
1021 opt_ty_info: param.ty_span,
1022 opt_match_place: Some((None, span)),
1023 pat_span: span,
1024 introductions: ::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
[VarBindingIntroduction { span, is_shorthand: false }]))vec![VarBindingIntroduction {
1025 span,
1026 is_shorthand: false,
1027 }],
1028 }))
1029 };
1030 self.var_indices.insert(var, LocalsForNode::One(local));
1031 }
1032 _ => {
1033 scope = self.declare_bindings(
1034 scope,
1035 expr_span,
1036 &pat,
1037 None,
1038 Some((Some(&place), span)),
1039 );
1040 let place_builder = PlaceBuilder::from(local);
1041 block = self.place_into_pattern(block, pat, place_builder, false).into_block();
1042 }
1043 }
1044 self.source_scope = original_source_scope;
1045 }
1046
1047 if let Some(source_scope) = scope {
1049 self.source_scope = source_scope;
1050 }
1051
1052 if self.tcx.intrinsic(self.def_id).is_some_and(|i| i.must_be_overridden)
1053 || self.tcx.is_sdylib_interface_build()
1054 {
1055 let source_info = self.source_info(rustc_span::DUMMY_SP);
1056 self.cfg.terminate(block, source_info, TerminatorKind::Unreachable);
1057 self.cfg.start_new_block().unit()
1058 } else {
1059 match self.tcx.hir_node(self.hir_id) {
1061 hir::Node::Item(hir::Item {
1062 kind: hir::ItemKind::Fn { has_body: false, .. },
1063 ..
1064 }) => {
1065 self.tcx.dcx().span_delayed_bug(
1066 expr_span,
1067 ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("fn item without body has reached MIR building: {0:?}",
self.def_id))
})format!("fn item without body has reached MIR building: {:?}", self.def_id),
1068 );
1069 }
1070 _ => {}
1071 }
1072 self.expr_into_dest(Place::return_place(), block, expr_id)
1073 }
1074 }
1075
1076 fn set_correct_source_scope_for_arg(
1077 &mut self,
1078 arg_hir_id: HirId,
1079 original_source_scope: SourceScope,
1080 pattern_span: Span,
1081 ) {
1082 let parent_id = self.source_scopes[original_source_scope]
1083 .local_data
1084 .as_ref()
1085 .unwrap_crate_local()
1086 .lint_root;
1087 self.maybe_new_source_scope(pattern_span, arg_hir_id, parent_id);
1088 }
1089
1090 fn get_unit_temp(&mut self) -> Place<'tcx> {
1091 match self.unit_temp {
1092 Some(tmp) => tmp,
1093 None => {
1094 let ty = self.tcx.types.unit;
1095 let fn_span = self.fn_span;
1096 let tmp = self.temp(ty, fn_span);
1097 self.unit_temp = Some(tmp);
1098 tmp
1099 }
1100 }
1101 }
1102}
1103
1104fn parse_float_into_constval(num: Symbol, float_ty: ty::FloatTy, neg: bool) -> Option<ConstValue> {
1105 parse_float_into_scalar(num, float_ty, neg).map(|s| ConstValue::Scalar(s.into()))
1106}
1107
1108pub(crate) fn parse_float_into_scalar(
1109 num: Symbol,
1110 float_ty: ty::FloatTy,
1111 neg: bool,
1112) -> Option<ScalarInt> {
1113 let num = num.as_str();
1114 match float_ty {
1115 ty::FloatTy::F16 => {
1117 let mut f = num.parse::<Half>().ok()?;
1118 if neg {
1119 f = -f;
1120 }
1121 Some(ScalarInt::from(f))
1122 }
1123 ty::FloatTy::F32 => {
1124 let Ok(rust_f) = num.parse::<f32>() else { return None };
1125 let mut f = num
1126 .parse::<Single>()
1127 .unwrap_or_else(|e| {
::core::panicking::panic_fmt(format_args!("apfloat::ieee::Single failed to parse `{0}`: {1:?}",
num, e));
}panic!("apfloat::ieee::Single failed to parse `{num}`: {e:?}"));
1128
1129 if !(u128::from(rust_f.to_bits()) == f.to_bits()) {
{
::core::panicking::panic_fmt(format_args!("apfloat::ieee::Single gave different result for `{0}`: {1}({2:#x}) vs Rust\'s {3}({4:#x})",
rust_f, f, f.to_bits(),
Single::from_bits(rust_f.to_bits().into()),
rust_f.to_bits()));
}
};assert!(
1130 u128::from(rust_f.to_bits()) == f.to_bits(),
1131 "apfloat::ieee::Single gave different result for `{}`: \
1132 {}({:#x}) vs Rust's {}({:#x})",
1133 rust_f,
1134 f,
1135 f.to_bits(),
1136 Single::from_bits(rust_f.to_bits().into()),
1137 rust_f.to_bits()
1138 );
1139
1140 if neg {
1141 f = -f;
1142 }
1143
1144 Some(ScalarInt::from(f))
1145 }
1146 ty::FloatTy::F64 => {
1147 let Ok(rust_f) = num.parse::<f64>() else { return None };
1148 let mut f = num
1149 .parse::<Double>()
1150 .unwrap_or_else(|e| {
::core::panicking::panic_fmt(format_args!("apfloat::ieee::Double failed to parse `{0}`: {1:?}",
num, e));
}panic!("apfloat::ieee::Double failed to parse `{num}`: {e:?}"));
1151
1152 if !(u128::from(rust_f.to_bits()) == f.to_bits()) {
{
::core::panicking::panic_fmt(format_args!("apfloat::ieee::Double gave different result for `{0}`: {1}({2:#x}) vs Rust\'s {3}({4:#x})",
rust_f, f, f.to_bits(),
Double::from_bits(rust_f.to_bits().into()),
rust_f.to_bits()));
}
};assert!(
1153 u128::from(rust_f.to_bits()) == f.to_bits(),
1154 "apfloat::ieee::Double gave different result for `{}`: \
1155 {}({:#x}) vs Rust's {}({:#x})",
1156 rust_f,
1157 f,
1158 f.to_bits(),
1159 Double::from_bits(rust_f.to_bits().into()),
1160 rust_f.to_bits()
1161 );
1162
1163 if neg {
1164 f = -f;
1165 }
1166
1167 Some(ScalarInt::from(f))
1168 }
1169 ty::FloatTy::F128 => {
1171 let mut f = num.parse::<Quad>().ok()?;
1172 if neg {
1173 f = -f;
1174 }
1175 Some(ScalarInt::from(f))
1176 }
1177 }
1178}
1179
1180mod block;
1186mod cfg;
1187mod coverageinfo;
1188mod custom;
1189mod expr;
1190mod matches;
1191mod misc;
1192mod scope;