From a62287ea50ff28a076288248f581a77a29eb4c8e Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Wed, 5 Nov 2025 11:36:16 +0100 Subject: [PATCH 01/13] Don't produce empty literal pieces in inline_literals. --- compiler/rustc_ast_lowering/src/format.rs | 24 +++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/compiler/rustc_ast_lowering/src/format.rs b/compiler/rustc_ast_lowering/src/format.rs index c5bbc2b811887..f141802fad5a6 100644 --- a/compiler/rustc_ast_lowering/src/format.rs +++ b/compiler/rustc_ast_lowering/src/format.rs @@ -89,28 +89,32 @@ impl<'hir> LoweringContext<'_, 'hir> { let mut was_inlined = vec![false; fmt.arguments.all_args().len()]; let mut inlined_anything = false; - for i in 0..fmt.template.len() { - let FormatArgsPiece::Placeholder(placeholder) = &fmt.template[i] else { continue }; - let Ok(arg_index) = placeholder.argument.index else { continue }; + let mut i = 0; - let mut literal = None; - - if let FormatTrait::Display = placeholder.format_trait + while i < fmt.template.len() { + if let FormatArgsPiece::Placeholder(placeholder) = &fmt.template[i] + && let Ok(arg_index) = placeholder.argument.index + && let FormatTrait::Display = placeholder.format_trait && placeholder.format_options == Default::default() && let arg = fmt.arguments.all_args()[arg_index].expr.peel_parens_and_refs() && let ExprKind::Lit(lit) = arg.kind + && let Some(literal) = self.try_inline_lit(lit) { - literal = self.try_inline_lit(lit); - } - if let Some(literal) = literal { // Now we need to mutate the outer FormatArgs. // If this is the first time, this clones the outer FormatArgs. let fmt = fmt.to_mut(); // Replace the placeholder with the literal. - fmt.template[i] = FormatArgsPiece::Literal(literal); + if literal.is_empty() { + fmt.template.remove(i); + } else { + fmt.template[i] = FormatArgsPiece::Literal(literal); + i += 1; + } was_inlined[arg_index] = true; inlined_anything = true; + } else { + i += 1; } } From bde1eaaf8c17b8d84641716a72303d3bb3866caf Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Wed, 5 Nov 2025 11:37:23 +0100 Subject: [PATCH 02/13] Expose expr_unsafe in LoweringContext. --- compiler/rustc_ast_lowering/src/expr.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_ast_lowering/src/expr.rs b/compiler/rustc_ast_lowering/src/expr.rs index 2be2fca87c3c5..b085c08e6d49c 100644 --- a/compiler/rustc_ast_lowering/src/expr.rs +++ b/compiler/rustc_ast_lowering/src/expr.rs @@ -924,7 +924,7 @@ impl<'hir> LoweringContext<'_, 'hir> { arena_vec![self; new_unchecked, get_context], ), }; - self.arena.alloc(self.expr_unsafe(call)) + self.arena.alloc(self.expr_unsafe(span, call)) }; // `::std::task::Poll::Ready(result) => break result` @@ -1826,7 +1826,7 @@ impl<'hir> LoweringContext<'_, 'hir> { arena_vec![self; iter], )); // `unsafe { ... }` - let iter = self.arena.alloc(self.expr_unsafe(iter)); + let iter = self.arena.alloc(self.expr_unsafe(head_span, iter)); let kind = self.make_lowered_await(head_span, iter, FutureKind::AsyncIterator); self.arena.alloc(hir::Expr { hir_id: self.next_id(), kind, span: head_span }) } @@ -1881,7 +1881,7 @@ impl<'hir> LoweringContext<'_, 'hir> { arena_vec![self; iter], )); // `unsafe { ... }` - let iter = self.arena.alloc(self.expr_unsafe(iter)); + let iter = self.arena.alloc(self.expr_unsafe(head_span, iter)); let inner_match_expr = self.arena.alloc(self.expr_match( for_span, iter, @@ -2256,9 +2256,12 @@ impl<'hir> LoweringContext<'_, 'hir> { self.expr(span, expr_path) } - fn expr_unsafe(&mut self, expr: &'hir hir::Expr<'hir>) -> hir::Expr<'hir> { + pub(super) fn expr_unsafe( + &mut self, + span: Span, + expr: &'hir hir::Expr<'hir>, + ) -> hir::Expr<'hir> { let hir_id = self.next_id(); - let span = expr.span; self.expr( span, hir::ExprKind::Block( From 98678ec8e5a9dbb2d2a210cfb3d9fcf179246060 Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Wed, 5 Nov 2025 11:50:43 +0100 Subject: [PATCH 03/13] Don't use fmt::Arguments implementation details in assert_unsafe_precondition. --- library/core/src/ub_checks.rs | 2 +- tests/ui/consts/const-eval/ub-slice-get-unchecked.stderr | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/library/core/src/ub_checks.rs b/library/core/src/ub_checks.rs index 514ff93c9820e..f96bcd92085e8 100644 --- a/library/core/src/ub_checks.rs +++ b/library/core/src/ub_checks.rs @@ -70,7 +70,7 @@ macro_rules! assert_unsafe_precondition { let msg = concat!("unsafe precondition(s) violated: ", $message, "\n\nThis indicates a bug in the program. \ This Undefined Behavior check is optional, and cannot be relied on for safety."); - ::core::panicking::panic_nounwind_fmt(::core::fmt::Arguments::new_const(&[msg]), false); + ::core::panicking::panic_nounwind(msg); } } diff --git a/tests/ui/consts/const-eval/ub-slice-get-unchecked.stderr b/tests/ui/consts/const-eval/ub-slice-get-unchecked.stderr index 88ea310f19c68..5cd3c0d8b539e 100644 --- a/tests/ui/consts/const-eval/ub-slice-get-unchecked.stderr +++ b/tests/ui/consts/const-eval/ub-slice-get-unchecked.stderr @@ -4,7 +4,10 @@ error[E0080]: evaluation panicked: unsafe precondition(s) violated: slice::get_u --> $DIR/ub-slice-get-unchecked.rs:7:27 | LL | const B: &[()] = unsafe { A.get_unchecked(3..1) }; - | ^^^^^^^^^^^^^^^^^^^^^ evaluation of `B` failed here + | ^^^^^^^^^^^^^^^^^^^^^ evaluation of `B` failed inside this call + | +note: inside `core::panicking::panic_nounwind` + --> $SRC_DIR/core/src/panicking.rs:LL:COL error: aborting due to 1 previous error From 6a68f1f68e802c38cfa12494a4690e4d417e9b13 Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Wed, 5 Nov 2025 11:54:30 +0100 Subject: [PATCH 04/13] New fmt::Arguments implementation. --- compiler/rustc_ast_lowering/messages.ftl | 3 + compiler/rustc_ast_lowering/src/errors.rs | 7 + compiler/rustc_ast_lowering/src/expr.rs | 10 +- compiler/rustc_ast_lowering/src/format.rs | 433 +++++++++--------- compiler/rustc_hir/src/lang_items.rs | 5 +- compiler/rustc_span/src/symbol.rs | 6 +- library/core/src/fmt/mod.rs | 224 +++++---- library/core/src/fmt/rt.rs | 124 ++--- library/core/src/panicking.rs | 33 +- tests/ui/unpretty/exhaustive.hir.stdout | 9 +- .../ui/unpretty/flattened-format-args.stdout | 6 +- 11 files changed, 478 insertions(+), 382 deletions(-) diff --git a/compiler/rustc_ast_lowering/messages.ftl b/compiler/rustc_ast_lowering/messages.ftl index 370b15d2871a9..d386c17484788 100644 --- a/compiler/rustc_ast_lowering/messages.ftl +++ b/compiler/rustc_ast_lowering/messages.ftl @@ -169,6 +169,9 @@ ast_lowering_template_modifier = template modifier ast_lowering_this_not_async = this is not `async` +ast_lowering_too_many_format_arguments = + too many arguments used in format string + ast_lowering_underscore_expr_lhs_assign = in expressions, `_` can only be used on the left-hand side of an assignment .label = `_` not allowed here diff --git a/compiler/rustc_ast_lowering/src/errors.rs b/compiler/rustc_ast_lowering/src/errors.rs index 83f3a976e83f7..4b727d850ebf4 100644 --- a/compiler/rustc_ast_lowering/src/errors.rs +++ b/compiler/rustc_ast_lowering/src/errors.rs @@ -475,3 +475,10 @@ pub(crate) struct UnionWithDefault { #[primary_span] pub span: Span, } + +#[derive(Diagnostic)] +#[diag(ast_lowering_too_many_format_arguments)] +pub(crate) struct TooManyFormatArguments { + #[primary_span] + pub span: Span, +} diff --git a/compiler/rustc_ast_lowering/src/expr.rs b/compiler/rustc_ast_lowering/src/expr.rs index b085c08e6d49c..00115a314ce20 100644 --- a/compiler/rustc_ast_lowering/src/expr.rs +++ b/compiler/rustc_ast_lowering/src/expr.rs @@ -2105,18 +2105,10 @@ impl<'hir> LoweringContext<'_, 'hir> { self.expr(sp, hir::ExprKind::Lit(lit)) } - pub(super) fn expr_usize(&mut self, sp: Span, value: usize) -> hir::Expr<'hir> { + pub(super) fn expr_usize(&mut self, sp: Span, value: u64) -> hir::Expr<'hir> { self.expr_uint(sp, ast::UintTy::Usize, value as u128) } - pub(super) fn expr_u32(&mut self, sp: Span, value: u32) -> hir::Expr<'hir> { - self.expr_uint(sp, ast::UintTy::U32, value as u128) - } - - pub(super) fn expr_u16(&mut self, sp: Span, value: u16) -> hir::Expr<'hir> { - self.expr_uint(sp, ast::UintTy::U16, value as u128) - } - pub(super) fn expr_str(&mut self, sp: Span, value: Symbol) -> hir::Expr<'hir> { let lit = hir::Lit { span: self.lower_span(sp), diff --git a/compiler/rustc_ast_lowering/src/format.rs b/compiler/rustc_ast_lowering/src/format.rs index f141802fad5a6..5a63b84c81855 100644 --- a/compiler/rustc_ast_lowering/src/format.rs +++ b/compiler/rustc_ast_lowering/src/format.rs @@ -7,6 +7,7 @@ use rustc_session::config::FmtDebug; use rustc_span::{DesugaringKind, Ident, Span, Symbol, sym}; use super::LoweringContext; +use super::errors::TooManyFormatArguments; impl<'hir> LoweringContext<'_, 'hir> { pub(crate) fn lower_format_args(&mut self, sp: Span, fmt: &FormatArgs) -> hir::ExprKind<'hir> { @@ -230,6 +231,7 @@ fn flatten_format_args(mut fmt: Cow<'_, FormatArgs>) -> Cow<'_, FormatArgs> { enum ArgumentType { Format(FormatTrait), Usize, + Constant(u16), } /// Generate a hir expression representing an argument to a format_args invocation. @@ -263,101 +265,48 @@ fn make_argument<'hir>( Format(Binary) => sym::new_binary, Format(LowerHex) => sym::new_lower_hex, Format(UpperHex) => sym::new_upper_hex, - Usize => sym::from_usize, + Usize | Constant(_) => sym::from_usize, }, )); ctx.expr_call_mut(sp, new_fn, std::slice::from_ref(arg)) } -/// Generate a hir expression for a format_args Count. +/// Generate a hir expression for a format_piece. /// /// Generates: /// /// ```text -/// ::Is(…) +/// ::…(…) /// ``` -/// -/// or -/// -/// ```text -/// ::Param(…) -/// ``` -/// -/// or -/// -/// ```text -/// ::Implied -/// ``` -fn make_count<'hir>( +fn make_piece<'hir>( ctx: &mut LoweringContext<'_, 'hir>, + constructor: Symbol, + expr: hir::Expr<'hir>, sp: Span, - count: &Option, - argmap: &mut FxIndexMap<(usize, ArgumentType), Option>, ) -> hir::Expr<'hir> { - match count { - Some(FormatCount::Literal(n)) => { - let count_is = ctx.arena.alloc(ctx.expr_lang_item_type_relative( - sp, - hir::LangItem::FormatCount, - sym::Is, - )); - let value = ctx.arena.alloc_from_iter([ctx.expr_u16(sp, *n)]); - ctx.expr_call_mut(sp, count_is, value) - } - Some(FormatCount::Argument(arg)) => { - if let Ok(arg_index) = arg.index { - let (i, _) = argmap.insert_full((arg_index, ArgumentType::Usize), arg.span); - let count_param = ctx.arena.alloc(ctx.expr_lang_item_type_relative( - sp, - hir::LangItem::FormatCount, - sym::Param, - )); - let value = ctx.arena.alloc_from_iter([ctx.expr_usize(sp, i)]); - ctx.expr_call_mut(sp, count_param, value) - } else { - ctx.expr( - sp, - hir::ExprKind::Err( - ctx.dcx().span_delayed_bug(sp, "lowered bad format_args count"), - ), - ) - } - } - None => ctx.expr_lang_item_type_relative(sp, hir::LangItem::FormatCount, sym::Implied), - } + let new_fn = ctx.arena.alloc(ctx.expr_lang_item_type_relative( + sp, + hir::LangItem::FormatPiece, + constructor, + )); + let new_args = ctx.arena.alloc_from_iter([expr]); + ctx.expr(sp, hir::ExprKind::Call(new_fn, new_args)) } -/// Generate a hir expression for a format_args placeholder specification. -/// -/// Generates -/// -/// ```text -/// , -/// width: , -/// } -/// ``` -fn make_format_spec<'hir>( - ctx: &mut LoweringContext<'_, 'hir>, - sp: Span, +/// Generate the 64 bit descriptor for a format_args placeholder specification. +fn make_format_spec( placeholder: &FormatPlaceholder, argmap: &mut FxIndexMap<(usize, ArgumentType), Option>, -) -> hir::Expr<'hir> { - let position = match placeholder.argument.index { - Ok(arg_index) => { - let (i, _) = argmap.insert_full( - (arg_index, ArgumentType::Format(placeholder.format_trait)), - placeholder.span, - ); - ctx.expr_usize(sp, i) - } - Err(_) => ctx.expr( - sp, - hir::ExprKind::Err(ctx.dcx().span_delayed_bug(sp, "lowered bad format_args count")), - ), - }; +) -> u64 { + let position = argmap + .insert_full( + ( + placeholder.argument.index.unwrap_or(usize::MAX), + ArgumentType::Format(placeholder.format_trait), + ), + placeholder.span, + ) + .0 as u64; let &FormatOptions { ref width, ref precision, @@ -388,17 +337,38 @@ fn make_format_spec<'hir>( | (precision.is_some() as u32) << 28 | align << 29 | 1 << 31; // Highest bit always set. - let flags = ctx.expr_u32(sp, flags); - let precision = make_count(ctx, sp, precision, argmap); - let width = make_count(ctx, sp, width, argmap); - let position = ctx.expr_field(Ident::new(sym::position, sp), ctx.arena.alloc(position), sp); - let flags = ctx.expr_field(Ident::new(sym::flags, sp), ctx.arena.alloc(flags), sp); - let precision = ctx.expr_field(Ident::new(sym::precision, sp), ctx.arena.alloc(precision), sp); - let width = ctx.expr_field(Ident::new(sym::width, sp), ctx.arena.alloc(width), sp); - let placeholder = - ctx.arena.alloc(ctx.make_lang_item_qpath(hir::LangItem::FormatPlaceholder, sp, None)); - let fields = ctx.arena.alloc_from_iter([position, flags, precision, width]); - ctx.expr(sp, hir::ExprKind::Struct(placeholder, fields, hir::StructTailExpr::None)) + let (width_indirect, width) = make_count(width, argmap); + let (precision_indirect, precision) = make_count(precision, argmap); + (flags as u64) << 32 + | (precision_indirect as u64) << 31 + | (width_indirect as u64) << 30 + | precision << 20 + | width << 10 + | position +} + +fn make_count( + count: &Option, + argmap: &mut FxIndexMap<(usize, ArgumentType), Option>, +) -> (bool, u64) { + match count { + None => (false, 0), + &Some(FormatCount::Literal(n)) => { + if n < 1 << 10 { + (false, n as u64) + } else { + // Too big. Upgrade to an argument. + let index = + argmap.insert_full((usize::MAX, ArgumentType::Constant(n)), None).0 as u64; + (true, index) + } + } + Some(FormatCount::Argument(arg)) => ( + true, + argmap.insert_full((arg.index.unwrap_or(usize::MAX), ArgumentType::Usize), arg.span).0 + as u64, + ), + } } fn expand_format_args<'hir>( @@ -407,84 +377,155 @@ fn expand_format_args<'hir>( fmt: &FormatArgs, allow_const: bool, ) -> hir::ExprKind<'hir> { - let macsp = ctx.lower_span(macsp); + // Create a list of all _unique_ (argument, format trait) combinations. + // E.g. "{0} {0:x} {0} {1}" -> [(0, Display), (0, LowerHex), (1, Display)] + // + // We use usize::MAX for arguments that don't exist, because that can never be a valid index + // into the arguments array. + let mut argmap = FxIndexMap::default(); + + // Generate: + // + // ``` + // &[ + // Piece::num(4), + // Piece::str("meow"), + // Piece::num(0xE000_0020_0000_0002), + // …, + // Piece::num(0), + // ] + // ``` + let mut pieces = Vec::new(); let mut incomplete_lit = String::new(); - let lit_pieces = - ctx.arena.alloc_from_iter(fmt.template.iter().enumerate().filter_map(|(i, piece)| { - match piece { - &FormatArgsPiece::Literal(s) => { - // Coalesce adjacent literal pieces. - if let Some(FormatArgsPiece::Literal(_)) = fmt.template.get(i + 1) { - incomplete_lit.push_str(s.as_str()); - None - } else if !incomplete_lit.is_empty() { - incomplete_lit.push_str(s.as_str()); - let s = Symbol::intern(&incomplete_lit); - incomplete_lit.clear(); - Some(ctx.expr_str(fmt.span, s)) - } else { - Some(ctx.expr_str(fmt.span, s)) - } + + let default_options = 0xE000_0020_0000_0000; + let mut implicit_arg_index = 0; + + for (i, piece) in fmt.template.iter().enumerate() { + match piece { + &FormatArgsPiece::Literal(sym) => { + assert!(!sym.is_empty()); + // Coalesce adjacent literal pieces. + if let Some(FormatArgsPiece::Literal(_)) = fmt.template.get(i + 1) { + incomplete_lit.push_str(sym.as_str()); + continue; } - &FormatArgsPiece::Placeholder(_) => { - // Inject empty string before placeholders when not already preceded by a literal piece. - if i == 0 || matches!(fmt.template[i - 1], FormatArgsPiece::Placeholder(_)) { - Some(ctx.expr_str(fmt.span, sym::empty)) - } else { - None + let (sym, len) = if incomplete_lit.is_empty() { + (sym, sym.as_str().len()) + } else { + incomplete_lit.push_str(sym.as_str()); + let sym = Symbol::intern(&incomplete_lit); + let len = incomplete_lit.len(); + incomplete_lit.clear(); + (sym, len) + }; + + // ``` + // Piece::num(4), + // ``` + let i = ctx.expr_usize(macsp, len as u64); + pieces.push(make_piece(ctx, sym::num, i, macsp)); + + // ``` + // Piece::str("meow"), + // ``` + let s = ctx.expr_str(fmt.span, sym); + pieces.push(make_piece(ctx, sym::str, s, macsp)); + } + FormatArgsPiece::Placeholder(p) => { + // ``` + // Piece::num(0xE000_0020_0000_0000), + // ``` + // Or, on 32 bit platforms: + // ``` + // Piece::num(0xE000_0020), + // Piece::num(0x0000_0000), + // ``` + // Or, on 16 bit platforms: + // ``` + // Piece::num(0xE000), + // Piece::num(0x0020), + // Piece::num(0x0000), + // Piece::num(0x0000), + // ``` + + let bits = make_format_spec(p, &mut argmap); + + // If this placeholder uses the next argument index, is surrounded by literal string + // pieces, and uses default formatting options, then we can skip it, as this kind of + // placeholder is implied by two consequtive string pieces. + if bits == default_options + implicit_arg_index { + if let (Some(FormatArgsPiece::Literal(_)), Some(FormatArgsPiece::Literal(_))) = + (fmt.template.get(i.wrapping_sub(1)), fmt.template.get(i + 1)) + { + implicit_arg_index += 1; + continue; } } - } - })); - let lit_pieces = ctx.expr_array_ref(fmt.span, lit_pieces); - // Whether we'll use the `Arguments::new_v1_formatted` form (true), - // or the `Arguments::new_v1` form (false). - let mut use_format_options = false; + if ctx.tcx.sess.target.pointer_width >= 64 { + let bits = ctx.expr_usize(macsp, bits); + pieces.push(make_piece(ctx, sym::num, bits, macsp)); + } else if ctx.tcx.sess.target.pointer_width >= 32 { + let high = ctx.expr_usize(macsp, bits >> 32); + let low = ctx.expr_usize(macsp, bits & 0xFFFF_FFFF); + pieces.push(make_piece(ctx, sym::num, high, macsp)); + pieces.push(make_piece(ctx, sym::num, low, macsp)); + } else { + let w1 = ctx.expr_usize(macsp, bits >> 48); + let w2 = ctx.expr_usize(macsp, bits >> 32 & 0xFFFF); + let w3 = ctx.expr_usize(macsp, bits >> 16 & 0xFFFF); + let w4 = ctx.expr_usize(macsp, bits & 0xFFFF); + pieces.push(make_piece(ctx, sym::num, w1, macsp)); + pieces.push(make_piece(ctx, sym::num, w2, macsp)); + pieces.push(make_piece(ctx, sym::num, w3, macsp)); + pieces.push(make_piece(ctx, sym::num, w4, macsp)); + } - // Create a list of all _unique_ (argument, format trait) combinations. - // E.g. "{0} {0:x} {0} {1}" -> [(0, Display), (0, LowerHex), (1, Display)] - let mut argmap = FxIndexMap::default(); - for piece in &fmt.template { - let FormatArgsPiece::Placeholder(placeholder) = piece else { continue }; - if placeholder.format_options != Default::default() { - // Can't use basic form if there's any formatting options. - use_format_options = true; - } - if let Ok(index) = placeholder.argument.index { - if argmap - .insert((index, ArgumentType::Format(placeholder.format_trait)), placeholder.span) - .is_some() - { - // Duplicate (argument, format trait) combination, - // which we'll only put once in the args array. - use_format_options = true; + implicit_arg_index = (bits & 0x3FF) + 1; } } } - let format_options = use_format_options.then(|| { - // Generate: - // &[format_spec_0, format_spec_1, format_spec_2] - let elements = ctx.arena.alloc_from_iter(fmt.template.iter().filter_map(|piece| { - let FormatArgsPiece::Placeholder(placeholder) = piece else { return None }; - Some(make_format_spec(ctx, macsp, placeholder, &mut argmap)) - })); - ctx.expr_array_ref(macsp, elements) - }); + assert!(incomplete_lit.is_empty()); + + // Zero terminator. + // + // ``` + // Piece::num(0), + // ``` + let zero = ctx.expr_usize(macsp, 0); + pieces.push(make_piece(ctx, sym::num, zero, macsp)); + + // ``` + // unsafe { ::new(&[pieces…]) } + // ``` + let template_new = + ctx.expr_lang_item_type_relative(macsp, hir::LangItem::FormatTemplate, sym::new); + let pieces = ctx.expr_array_ref(macsp, ctx.arena.alloc_from_iter(pieces)); + let template = ctx.expr( + macsp, + hir::ExprKind::Call(ctx.arena.alloc(template_new), ctx.arena.alloc_from_iter([pieces])), + ); + let template = ctx.expr_unsafe(macsp, ctx.arena.alloc(template)); + + // Ensure all argument indexes actually fit in 10 bits, as we truncated them to 10 bits before. + if argmap.len() >= 1 << 10 { + ctx.dcx().emit_err(TooManyFormatArguments { span: fmt.span }); + } let arguments = fmt.arguments.all_args(); if allow_const && arguments.is_empty() && argmap.is_empty() { // Generate: - // ::new_const(lit_pieces) + // ::new_const(template) let new = ctx.arena.alloc(ctx.expr_lang_item_type_relative( macsp, hir::LangItem::FormatArguments, sym::new_const, )); - let new_args = ctx.arena.alloc_from_iter([lit_pieces]); + let new_args = ctx.arena.alloc_from_iter([template]); return hir::ExprKind::Call(new, new_args); } @@ -516,22 +557,37 @@ fn expand_format_args<'hir>( // ]; let args = ctx.arena.alloc_from_iter(argmap.iter().map( |(&(arg_index, ty), &placeholder_span)| { - let arg = &arguments[arg_index]; - let placeholder_span = - placeholder_span.unwrap_or(arg.expr.span).with_ctxt(macsp.ctxt()); - let arg_span = match arg.kind { - FormatArgumentKind::Captured(_) => placeholder_span, - _ => arg.expr.span.with_ctxt(macsp.ctxt()), - }; - let args_ident_expr = ctx.expr_ident(macsp, args_ident, args_hir_id); - let arg = ctx.arena.alloc(ctx.expr( - arg_span, - hir::ExprKind::Field( - args_ident_expr, - Ident::new(sym::integer(arg_index), macsp), - ), - )); - make_argument(ctx, placeholder_span, arg, ty) + if let ArgumentType::Constant(c) = ty { + let arg = ctx.arena.alloc(ctx.expr_usize(macsp, c.into())); + let arg = ctx.arena.alloc(ctx.expr( + macsp, + hir::ExprKind::AddrOf(hir::BorrowKind::Ref, hir::Mutability::Not, arg), + )); + make_argument(ctx, macsp, arg, ty) + } else if let Some(arg) = arguments.get(arg_index) { + let placeholder_span = + placeholder_span.unwrap_or(arg.expr.span).with_ctxt(macsp.ctxt()); + let arg_span = match arg.kind { + FormatArgumentKind::Captured(_) => placeholder_span, + _ => arg.expr.span.with_ctxt(macsp.ctxt()), + }; + let args_ident_expr = ctx.expr_ident(macsp, args_ident, args_hir_id); + let arg = ctx.arena.alloc(ctx.expr( + arg_span, + hir::ExprKind::Field( + args_ident_expr, + Ident::new(sym::integer(arg_index), macsp), + ), + )); + make_argument(ctx, placeholder_span, arg, ty) + } else { + ctx.expr( + macsp, + hir::ExprKind::Err( + ctx.dcx().span_delayed_bug(macsp, "missing format_args argument"), + ), + ) + } }, )); let args = ctx.arena.alloc(ctx.expr(macsp, hir::ExprKind::Array(args))); @@ -544,50 +600,19 @@ fn expand_format_args<'hir>( }; // Generate: - // &args - let args = ctx.expr_ref(macsp, args); - - let call = if let Some(format_options) = format_options { - // Generate: - // unsafe { - // ::new_v1_formatted( - // lit_pieces, - // args, - // format_options, - // ) - // } - let new_v1_formatted = ctx.arena.alloc(ctx.expr_lang_item_type_relative( - macsp, - hir::LangItem::FormatArguments, - sym::new_v1_formatted, - )); - let args = ctx.arena.alloc_from_iter([lit_pieces, args, format_options]); - let call = ctx.expr_call(macsp, new_v1_formatted, args); - let hir_id = ctx.next_id(); - hir::ExprKind::Block( - ctx.arena.alloc(hir::Block { - stmts: &[], - expr: Some(call), - hir_id, - rules: hir::BlockCheckMode::UnsafeBlock(hir::UnsafeSource::CompilerGenerated), - span: macsp, - targeted_by_break: false, - }), - None, - ) - } else { - // Generate: - // ::new_v1( - // lit_pieces, - // args, - // ) - let new_v1 = ctx.arena.alloc(ctx.expr_lang_item_type_relative( + // ::new( + // template, + // &args, + // ) + let call = { + let new = ctx.arena.alloc(ctx.expr_lang_item_type_relative( macsp, hir::LangItem::FormatArguments, - sym::new_v1, + sym::new, )); - let new_args = ctx.arena.alloc_from_iter([lit_pieces, args]); - hir::ExprKind::Call(new_v1, new_args) + let args = ctx.expr_ref(macsp, args); + let new_args = ctx.arena.alloc_from_iter([template, args]); + hir::ExprKind::Call(new, new_args) }; if !let_statements.is_empty() { @@ -595,7 +620,7 @@ fn expand_format_args<'hir>( // { // super let … // super let … - // ::new_…(…) + // ::new(…) // } let call = ctx.arena.alloc(ctx.expr(macsp, call)); let block = ctx.block_all(macsp, ctx.arena.alloc_from_iter(let_statements), Some(call)); diff --git a/compiler/rustc_hir/src/lang_items.rs b/compiler/rustc_hir/src/lang_items.rs index 9f7f4c7583412..81fdd64d34a0f 100644 --- a/compiler/rustc_hir/src/lang_items.rs +++ b/compiler/rustc_hir/src/lang_items.rs @@ -328,9 +328,8 @@ language_item_table! { // Lang items needed for `format_args!()`. FormatArgument, sym::format_argument, format_argument, Target::Struct, GenericRequirement::None; FormatArguments, sym::format_arguments, format_arguments, Target::Struct, GenericRequirement::None; - FormatCount, sym::format_count, format_count, Target::Enum, GenericRequirement::None; - FormatPlaceholder, sym::format_placeholder, format_placeholder, Target::Struct, GenericRequirement::None; - FormatUnsafeArg, sym::format_unsafe_arg, format_unsafe_arg, Target::Struct, GenericRequirement::None; + FormatPiece, sym::format_piece, format_piece, Target::Union, GenericRequirement::None; + FormatTemplate, sym::format_template, format_template, Target::Struct, GenericRequirement::None; ExchangeMalloc, sym::exchange_malloc, exchange_malloc_fn, Target::Fn, GenericRequirement::None; DropInPlace, sym::drop_in_place, drop_in_place_fn, Target::Fn, GenericRequirement::Minimum(1); diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 38718bad9e57e..f275491f9ac37 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -1092,10 +1092,9 @@ symbols! { format_args_nl, format_argument, format_arguments, - format_count, format_macro, - format_placeholder, - format_unsafe_arg, + format_piece, + format_template, framework, freeze, freeze_impls, @@ -1573,6 +1572,7 @@ symbols! { notable_trait, note, null, + num, nvptx64, nvptx_target_feature, object_safe_for_dispatch, diff --git a/library/core/src/fmt/mod.rs b/library/core/src/fmt/mod.rs index 502ca4aefe10d..c82a3554db3e7 100644 --- a/library/core/src/fmt/mod.rs +++ b/library/core/src/fmt/mod.rs @@ -7,6 +7,7 @@ use crate::char::{EscapeDebugExtArgs, MAX_LEN_UTF8}; use crate::marker::{PhantomData, PointeeSized}; use crate::num::fmt as numfmt; use crate::ops::Deref; +use crate::ptr::NonNull; use crate::{iter, result, str}; mod builders; @@ -616,15 +617,8 @@ impl<'a> Formatter<'a> { #[stable(feature = "rust1", since = "1.0.0")] #[derive(Copy, Clone)] pub struct Arguments<'a> { - // Format string pieces to print. - pieces: &'a [&'static str], - - // Placeholder specs, or `None` if all specs are default (as in "{}{}"). - fmt: Option<&'a [rt::Placeholder]>, - - // Dynamic arguments for interpolation, to be interleaved with string - // pieces. (Every argument is preceded by a string piece.) - args: &'a [rt::Argument<'a>], + template: rt::Template<'a>, + args: NonNull>, } #[doc(hidden)] @@ -636,20 +630,54 @@ impl<'a> Arguments<'a> { /// when using `format!`. Note: this is neither the lower nor upper bound. #[inline] pub fn estimated_capacity(&self) -> usize { - let pieces_length: usize = self.pieces.iter().map(|x| x.len()).sum(); + // Iterate over the template, counting the length of literal pieces. + let mut length = 0usize; + let mut starts_with_placeholder = false; + let mut template = self.template; + let mut has_placeholders = false; + loop { + // SAFETY: We can assume the template is valid. + unsafe { + let n = template.next().i; + if n == 0 { + // End of template. + break; + } else if n <= isize::MAX as _ { + // Literal string piece. + if length != 0 { + // More than one literal string piece means we have placeholders. + has_placeholders = true; + } + length += n as usize; + let _ptr = template.next(); // Skip the string pointer. + } else { + // Placeholder piece. + if length == 0 { + starts_with_placeholder = true; + } + has_placeholders = true; + // Skip remainder of placeholder: + #[cfg(target_pointer_width = "32")] + let _ = template.next(); + #[cfg(target_pointer_width = "16")] + let _ = (template.next(), template.next(), template.next()); + } + } + } - if self.args.is_empty() { - pieces_length - } else if !self.pieces.is_empty() && self.pieces[0].is_empty() && pieces_length < 16 { - // If the format string starts with an argument, + if !has_placeholders { + // If the template has no placeholders, we know the length exactly. + length + } else if starts_with_placeholder && length < 16 { + // If the format string starts with a placeholder, // don't preallocate anything, unless length - // of pieces is significant. + // of literal pieces is significant. 0 } else { - // There are some arguments, so any additional push + // There are some placeholders, so any additional push // will reallocate the string. To avoid that, // we're "pre-doubling" the capacity here. - pieces_length.checked_mul(2).unwrap_or(0) + length.wrapping_mul(2) } } } @@ -702,11 +730,27 @@ impl<'a> Arguments<'a> { #[must_use] #[inline] pub const fn as_str(&self) -> Option<&'static str> { - match (self.pieces, self.args) { - ([], []) => Some(""), - ([s], []) => Some(s), - _ => None, + let mut template = self.template; + // SAFETY: We can assume the template is valid. + let n = unsafe { template.next().i }; + if n == 0 { + // The template is empty. + return Some(""); + } + if n <= isize::MAX as _ { + // Template starts with a string piece. + // SAFETY: We can assume the template is valid. + unsafe { + let ptr = template.next().p; + if template.next().i == 0 { + // The template has only one piece. + return Some(str::from_utf8_unchecked(crate::slice::from_raw_parts( + ptr, n as usize, + ))); + } + } } + None } /// Same as [`Arguments::as_str`], but will only return `Some(s)` if it can be determined at compile time. @@ -1448,86 +1492,74 @@ pub trait UpperExp: PointeeSized { /// /// [`write!`]: crate::write! #[stable(feature = "rust1", since = "1.0.0")] -pub fn write(output: &mut dyn Write, args: Arguments<'_>) -> Result { - let mut formatter = Formatter::new(output, FormattingOptions::new()); - let mut idx = 0; - - match args.fmt { - None => { - // We can use default formatting parameters for all arguments. - for (i, arg) in args.args.iter().enumerate() { - // SAFETY: args.args and args.pieces come from the same Arguments, - // which guarantees the indexes are always within bounds. - let piece = unsafe { args.pieces.get_unchecked(i) }; - if !piece.is_empty() { - formatter.buf.write_str(*piece)?; - } - - // SAFETY: There are no formatting parameters and hence no - // count arguments. +pub fn write(output: &mut dyn Write, fmt: Arguments<'_>) -> Result { + let mut template = fmt.template; + let args = fmt.args; + + let mut last_piece_was_str = false; + let mut implicit_arg_index = 0; + + loop { + // SAFETY: We can assume the template is valid. + let n = unsafe { template.next().i }; + if n == 0 { + // End of template. + return Ok(()); + } else if n <= isize::MAX as _ { + // Literal string piece. + if last_piece_was_str { + // Two consecutive string pieces means we need to insert + // an implicit argument with default options. + let options = FormattingOptions::new(); + // SAFETY: We can assume the template only refers to arguments that exist. + let arg = unsafe { *args.add(implicit_arg_index).as_ref() }; + implicit_arg_index += 1; + // SAFETY: We can assume the placeholders match the arguments. + unsafe { arg.fmt(&mut Formatter::new(output, options)) }?; + } + // SAFETY: We can assume the strings in the template are valid. + let s = unsafe { crate::str::from_raw_parts(template.next().p, n as usize) }; + output.write_str(s)?; + last_piece_was_str = true; + } else { + // Placeholder piece. + #[cfg(target_pointer_width = "64")] + let (high, low) = ((n >> 32) as u32, n as u32); + #[cfg(target_pointer_width = "32")] + // SAFETY: We can assume the template is valid. + let (high, low) = (n as u32, unsafe { template.next().i } as u32); + #[cfg(target_pointer_width = "16")] + // SAFETY: We can assume the template is valid. + let (high, low) = unsafe { + ( + (n as u32) << 16 | template.next().i as u32, + (template.next().i as u32) << 16 | template.next().i as u32, + ) + }; + let arg_index = (low & 0x3FF) as usize; + let mut width = (low >> 10 & 0x3FF) as u16; + let mut precision = (low >> 20 & 0x3FF) as u16; + if low & 1 << 30 != 0 { + // Dynamic width from a usize argument. + // SAFETY: We can assume the template only refers to arguments that exist. unsafe { - arg.fmt(&mut formatter)?; + width = args.add(width as usize).as_ref().as_u16().unwrap_unchecked(); } - idx += 1; } - } - Some(fmt) => { - // Every spec has a corresponding argument that is preceded by - // a string piece. - for (i, arg) in fmt.iter().enumerate() { - // SAFETY: fmt and args.pieces come from the same Arguments, - // which guarantees the indexes are always within bounds. - let piece = unsafe { args.pieces.get_unchecked(i) }; - if !piece.is_empty() { - formatter.buf.write_str(*piece)?; + if low & 1 << 31 != 0 { + // Dynamic precision from a usize argument. + // SAFETY: We can assume the template only refers to arguments that exist. + unsafe { + precision = args.add(precision as usize).as_ref().as_u16().unwrap_unchecked(); } - // SAFETY: arg and args.args come from the same Arguments, - // which guarantees the indexes are always within bounds. - unsafe { run(&mut formatter, arg, args.args) }?; - idx += 1; } - } - } - - // There can be only one trailing string piece left. - if let Some(piece) = args.pieces.get(idx) { - formatter.buf.write_str(*piece)?; - } - - Ok(()) -} - -unsafe fn run(fmt: &mut Formatter<'_>, arg: &rt::Placeholder, args: &[rt::Argument<'_>]) -> Result { - let (width, precision) = - // SAFETY: arg and args come from the same Arguments, - // which guarantees the indexes are always within bounds. - unsafe { (getcount(args, &arg.width), getcount(args, &arg.precision)) }; - - let options = FormattingOptions { flags: arg.flags, width, precision }; - - // Extract the correct argument - debug_assert!(arg.position < args.len()); - // SAFETY: arg and args come from the same Arguments, - // which guarantees its index is always within bounds. - let value = unsafe { args.get_unchecked(arg.position) }; - - // Set all the formatting options. - fmt.options = options; - - // Then actually do some printing - // SAFETY: this is a placeholder argument. - unsafe { value.fmt(fmt) } -} - -unsafe fn getcount(args: &[rt::Argument<'_>], cnt: &rt::Count) -> u16 { - match *cnt { - rt::Count::Is(n) => n, - rt::Count::Implied => 0, - rt::Count::Param(i) => { - debug_assert!(i < args.len()); - // SAFETY: cnt and args come from the same Arguments, - // which guarantees this index is always within bounds. - unsafe { args.get_unchecked(i).as_u16().unwrap_unchecked() } + let options = FormattingOptions { flags: high, width, precision }; + // SAFETY: We can assume the template only refers to arguments that exist. + let arg = unsafe { *args.add(arg_index).as_ref() }; + // SAFETY: We can assume the placeholders match the arguments. + unsafe { arg.fmt(&mut Formatter::new(output, options)) }?; + last_piece_was_str = false; + implicit_arg_index = arg_index + 1; } } } diff --git a/library/core/src/fmt/rt.rs b/library/core/src/fmt/rt.rs index fb858a0572612..add92150eb6a2 100644 --- a/library/core/src/fmt/rt.rs +++ b/library/core/src/fmt/rt.rs @@ -8,28 +8,65 @@ use super::*; use crate::hint::unreachable_unchecked; +use crate::marker::PhantomData; use crate::ptr::NonNull; -#[lang = "format_placeholder"] +#[lang = "format_template"] #[derive(Copy, Clone)] -pub struct Placeholder { - pub position: usize, - pub flags: u32, - pub precision: Count, - pub width: Count, +pub struct Template<'a> { + pub(super) pieces: NonNull, + lifetime: PhantomData<&'a rt::Piece>, } -/// Used by [width](https://doc.rust-lang.org/std/fmt/#width) -/// and [precision](https://doc.rust-lang.org/std/fmt/#precision) specifiers. -#[lang = "format_count"] +unsafe impl Send for Template<'_> {} +unsafe impl Sync for Template<'_> {} + +impl<'a> Template<'a> { + #[inline] + pub const unsafe fn new(pieces: &'a [rt::Piece; N]) -> Self { + Self { pieces: NonNull::from_ref(pieces).cast(), lifetime: PhantomData } + } + + #[inline] + pub const unsafe fn next(&mut self) -> Piece { + // SAFETY: Guaranteed by caller. + unsafe { + let piece = *self.pieces.as_ref(); + self.pieces = self.pieces.add(1); + piece + } + } +} + +#[lang = "format_piece"] #[derive(Copy, Clone)] -pub enum Count { - /// Specified with a literal number, stores the value - Is(u16), - /// Specified using `$` and `*` syntaxes, stores the index into `args` - Param(usize), - /// Not specified - Implied, +pub union Piece { + pub i: usize, + pub p: *const u8, +} + +unsafe impl Send for Piece {} +unsafe impl Sync for Piece {} + +// These are marked as #[stable] because of #[rustc_promotable] and #[rustc_const_stable]. +// With #[rustc_const_unstable], many format_args!() invocations would result in errors. +// +// There is still no way to use these on stable, because Piece itself is #[unstable] and not +// reachable through any public path. (format_args!()'s expansion uses it as a lang item.) +impl Piece { + #[rustc_promotable] + #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_stable(feature = "rust1", since = "1.0.0")] + pub const fn str(s: &'static str) -> Self { + Self { p: s as *const str as *const u8 } + } + + #[rustc_promotable] + #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_stable(feature = "rust1", since = "1.0.0")] + pub const fn num(i: usize) -> Self { + Self { i } + } } #[derive(Copy, Clone)] @@ -187,52 +224,31 @@ impl Argument<'_> { /// Used by the format_args!() macro to create a fmt::Arguments object. #[doc(hidden)] -#[unstable(feature = "fmt_internals", issue = "none")] #[rustc_diagnostic_item = "FmtArgumentsNew"] impl<'a> Arguments<'a> { #[inline] - pub const fn new_const(pieces: &'a [&'static str; N]) -> Self { - const { assert!(N <= 1) }; - Arguments { pieces, fmt: None, args: &[] } + pub const fn new_const(template: rt::Template<'a>) -> Arguments<'a> { + Arguments { template, args: NonNull::dangling() } } - /// When using the format_args!() macro, this function is used to generate the - /// Arguments structure. - /// - /// This function should _not_ be const, to make sure we don't accept - /// format_args!() and panic!() with arguments in const, even when not evaluated: - /// - /// ```compile_fail,E0015 - /// const _: () = if false { panic!("a {}", "a") }; - /// ``` #[inline] - pub fn new_v1( - pieces: &'a [&'static str; P], - args: &'a [rt::Argument<'a>; A], + pub fn new( + template: rt::Template<'a>, + args: &'a [rt::Argument<'a>; N], ) -> Arguments<'a> { - const { assert!(P >= A && P <= A + 1, "invalid args") } - Arguments { pieces, fmt: None, args } + Arguments { template, args: NonNull::from_ref(args).cast() } } - /// Specifies nonstandard formatting parameters. - /// - /// SAFETY: the following invariants must be held: - /// 1. The `pieces` slice must be at least as long as `fmt`. - /// 2. Every `rt::Placeholder::position` value within `fmt` must be a valid index of `args`. - /// 3. Every `rt::Count::Param` within `fmt` must contain a valid index of `args`. - /// - /// This function should _not_ be const, to make sure we don't accept - /// format_args!() and panic!() with arguments in const, even when not evaluated: - /// - /// ```compile_fail,E0015 - /// const _: () = if false { panic!("a {:1}", "a") }; - /// ``` - #[inline] - pub unsafe fn new_v1_formatted( - pieces: &'a [&'static str], - args: &'a [rt::Argument<'a>], - fmt: &'a [rt::Placeholder], - ) -> Arguments<'a> { - Arguments { pieces, fmt: Some(fmt), args } + // These two methods are used in library/core/src/panicking.rs to create a + // `fmt::Arguments` for a `&'static str`. + #[inline] + pub(crate) const fn pieces_for_str(s: &'static str) -> [rt::Piece; 3] { + [rt::Piece { i: s.len() as _ }, rt::Piece::str(s), rt::Piece { i: 0 }] + } + /// Safety: Only call this with the result of `pieces_for_str`. + #[inline] + pub(crate) const unsafe fn from_pieces(p: &'a [rt::Piece; 3]) -> Self { + // SAFETY: Guaranteed by caller. + Self::new_const(unsafe { rt::Template::new(p) }) } } diff --git a/library/core/src/panicking.rs b/library/core/src/panicking.rs index 448f4ffc3dae0..6d5f47f188e71 100644 --- a/library/core/src/panicking.rs +++ b/library/core/src/panicking.rs @@ -147,7 +147,10 @@ pub const fn panic(expr: &'static str) -> ! { // payload without any allocation or copying. Shorter-lived strings would become invalid as // stack frames get popped during unwinding, and couldn't be directly referenced from the // payload. - panic_fmt(fmt::Arguments::new_const(&[expr])); + // SAFETY: This is the correct way to make a `fmt::Arguments` from a string literal. + unsafe { + panic_fmt(fmt::Arguments::from_pieces(&fmt::Arguments::pieces_for_str(expr))); + } } // We generate functions for usage by compiler-generated assertions. @@ -171,13 +174,10 @@ macro_rules! panic_const { #[rustc_const_stable_indirect] // must follow stable const rules since it is exposed to stable #[lang = stringify!($lang)] pub const fn $lang() -> ! { - // Use Arguments::new_const instead of format_args!("{expr}") to potentially - // reduce size overhead. The format_args! macro uses str's Display trait to - // write expr, which calls Formatter::pad, which must accommodate string - // truncation and padding (even though none is used here). Using - // Arguments::new_const may allow the compiler to omit Formatter::pad from the - // output binary, saving up to a few kilobytes. - panic_fmt(fmt::Arguments::new_const(&[$message])); + // SAFETY: This is the correct way to make a `fmt::Arguments` from a string literal. + unsafe { + panic_fmt(fmt::Arguments::from_pieces(&fmt::Arguments::pieces_for_str($message))); + } } )+ } @@ -227,7 +227,14 @@ pub mod panic_const { #[rustc_nounwind] #[rustc_const_stable_indirect] // must follow stable const rules since it is exposed to stable pub const fn panic_nounwind(expr: &'static str) -> ! { - panic_nounwind_fmt(fmt::Arguments::new_const(&[expr]), /* force_no_backtrace */ false); + // SAFETY: This is the correct way to make a `fmt::Arguments` from a string literal. + unsafe { + panic_nounwind_fmt( + // SAFETY: This is the correct way to make a `fmt::Arguments` from a string literal. + fmt::Arguments::from_pieces(&fmt::Arguments::pieces_for_str(expr)), + /* force_no_backtrace */ false, + ); + } } /// Like `panic_nounwind`, but also inhibits showing a backtrace. @@ -235,7 +242,13 @@ pub const fn panic_nounwind(expr: &'static str) -> ! { #[cfg_attr(panic = "immediate-abort", inline)] #[rustc_nounwind] pub fn panic_nounwind_nobacktrace(expr: &'static str) -> ! { - panic_nounwind_fmt(fmt::Arguments::new_const(&[expr]), /* force_no_backtrace */ true); + // SAFETY: This is the correct way to make a `fmt::Arguments` from a string literal. + unsafe { + panic_nounwind_fmt( + fmt::Arguments::from_pieces(&fmt::Arguments::pieces_for_str(expr)), + /* force_no_backtrace */ true, + ); + } } #[inline] diff --git a/tests/ui/unpretty/exhaustive.hir.stdout b/tests/ui/unpretty/exhaustive.hir.stdout index ee22c3aeba9df..5a13a71d94202 100644 --- a/tests/ui/unpretty/exhaustive.hir.stdout +++ b/tests/ui/unpretty/exhaustive.hir.stdout @@ -390,11 +390,16 @@ mod expressions { /// ExprKind::FormatArgs fn expr_format_args() { let expr; - format_arguments::new_const(&[]); + format_arguments::new_const(unsafe { + format_template::new(&[format_piece::num(0usize)]) + }); { super let args = (&expr,); super let args = [format_argument::new_display(args.0)]; - format_arguments::new_v1(&[""], &args) + format_arguments::new(unsafe { + format_template::new(&[format_piece::num(16140901201934811136usize), + format_piece::num(0usize)]) + }, &args) }; } } diff --git a/tests/ui/unpretty/flattened-format-args.stdout b/tests/ui/unpretty/flattened-format-args.stdout index 233c9f1c91bd7..e50086d464832 100644 --- a/tests/ui/unpretty/flattened-format-args.stdout +++ b/tests/ui/unpretty/flattened-format-args.stdout @@ -13,7 +13,11 @@ fn main() { ::std::io::_print({ super let args = (&x,); super let args = [format_argument::new_display(args.0)]; - format_arguments::new_v1(&["a 123 b ", " xyz\n"], &args) + format_arguments::new(unsafe { + format_template::new(&[format_piece::num(8usize), + format_piece::str("a 123 b "), format_piece::num(5usize), + format_piece::str(" xyz\n"), format_piece::num(0usize)]) + }, &args) }); }; } From c9a4bc6302cc6d4e882e83c8daab4cc6c97adf63 Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Wed, 5 Nov 2025 15:29:53 +0100 Subject: [PATCH 05/13] Formatting. --- compiler/rustc_ast_lowering/src/format.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/compiler/rustc_ast_lowering/src/format.rs b/compiler/rustc_ast_lowering/src/format.rs index 5a63b84c81855..09890f8bb48cf 100644 --- a/compiler/rustc_ast_lowering/src/format.rs +++ b/compiler/rustc_ast_lowering/src/format.rs @@ -101,7 +101,6 @@ impl<'hir> LoweringContext<'_, 'hir> { && let ExprKind::Lit(lit) = arg.kind && let Some(literal) = self.try_inline_lit(lit) { - // Now we need to mutate the outer FormatArgs. // If this is the first time, this clones the outer FormatArgs. let fmt = fmt.to_mut(); From 2205bcd281d238621d2ab9221a03897475e2fd17 Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Wed, 5 Nov 2025 15:31:03 +0100 Subject: [PATCH 06/13] Optimize fmt::Arguments for the static string case. fmt::Arguments can now store a &str without any indirection and additional storage: There is now a fmt::Arguments::from_str() function. --- compiler/rustc_ast_lowering/src/format.rs | 47 ++++++++----- .../rustc_const_eval/src/check_consts/ops.rs | 4 +- compiler/rustc_span/src/symbol.rs | 5 +- library/core/src/fmt/mod.rs | 66 ++++++++----------- library/core/src/fmt/rt.rs | 52 ++++++++++----- library/core/src/panicking.rs | 33 ++-------- 6 files changed, 107 insertions(+), 100 deletions(-) diff --git a/compiler/rustc_ast_lowering/src/format.rs b/compiler/rustc_ast_lowering/src/format.rs index 09890f8bb48cf..4131a832b85a8 100644 --- a/compiler/rustc_ast_lowering/src/format.rs +++ b/compiler/rustc_ast_lowering/src/format.rs @@ -401,12 +401,19 @@ fn expand_format_args<'hir>( let default_options = 0xE000_0020_0000_0000; let mut implicit_arg_index = 0; - for (i, piece) in fmt.template.iter().enumerate() { + let template = if fmt.template.is_empty() { + // Treat empty templates as a single literal piece (with an empty string), + // so we produce `from_str("")` for those. + &[FormatArgsPiece::Literal(sym::empty)][..] + } else { + &fmt.template[..] + }; + + for (i, piece) in template.iter().enumerate() { match piece { &FormatArgsPiece::Literal(sym) => { - assert!(!sym.is_empty()); // Coalesce adjacent literal pieces. - if let Some(FormatArgsPiece::Literal(_)) = fmt.template.get(i + 1) { + if let Some(FormatArgsPiece::Literal(_)) = template.get(i + 1) { incomplete_lit.push_str(sym.as_str()); continue; } @@ -420,6 +427,26 @@ fn expand_format_args<'hir>( (sym, len) }; + // If this is the last piece and was the only piece, that means + // there are no placeholders and the entire format string is just a literal. + // + // In that case, we don't need an array of `Piece`s: we can just use `from_str`. + if i + 1 == template.len() && pieces.is_empty() { + // Generate: + // ::from_str("meow") + let from_str = ctx.arena.alloc(ctx.expr_lang_item_type_relative( + macsp, + hir::LangItem::FormatArguments, + if allow_const { sym::from_str } else { sym::from_str_nonconst }, + )); + let s = ctx.expr_str(fmt.span, sym); + let args = ctx.arena.alloc_from_iter([s]); + return hir::ExprKind::Call(from_str, args); + } + + // Producing a `Piece::num(0)` would be problematic, as that is the terminator. + assert!(len > 0); + // ``` // Piece::num(4), // ``` @@ -456,7 +483,7 @@ fn expand_format_args<'hir>( // placeholder is implied by two consequtive string pieces. if bits == default_options + implicit_arg_index { if let (Some(FormatArgsPiece::Literal(_)), Some(FormatArgsPiece::Literal(_))) = - (fmt.template.get(i.wrapping_sub(1)), fmt.template.get(i + 1)) + (template.get(i.wrapping_sub(1)), template.get(i + 1)) { implicit_arg_index += 1; continue; @@ -516,18 +543,6 @@ fn expand_format_args<'hir>( let arguments = fmt.arguments.all_args(); - if allow_const && arguments.is_empty() && argmap.is_empty() { - // Generate: - // ::new_const(template) - let new = ctx.arena.alloc(ctx.expr_lang_item_type_relative( - macsp, - hir::LangItem::FormatArguments, - sym::new_const, - )); - let new_args = ctx.arena.alloc_from_iter([template]); - return hir::ExprKind::Call(new, new_args); - } - let (let_statements, args) = if arguments.is_empty() { // Generate: // [] diff --git a/compiler/rustc_const_eval/src/check_consts/ops.rs b/compiler/rustc_const_eval/src/check_consts/ops.rs index d81b31b704b3d..cddf0bf80c4de 100644 --- a/compiler/rustc_const_eval/src/check_consts/ops.rs +++ b/compiler/rustc_const_eval/src/check_consts/ops.rs @@ -345,7 +345,9 @@ fn build_error_for_const_call<'tcx>( note_trait_if_possible(&mut err, self_ty, tcx.require_lang_item(LangItem::Deref, span)); err } - _ if tcx.opt_parent(callee) == tcx.get_diagnostic_item(sym::FmtArgumentsNew) => { + _ if tcx.is_diagnostic_item(sym::FmtTemplateNew, callee) + || tcx.is_diagnostic_item(sym::FmtArgumentsFromStrNonconst, callee) => + { ccx.dcx().create_err(errors::NonConstFmtMacroCall { span, kind: ccx.const_kind(), diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index f275491f9ac37..e2ae2eb3ba06a 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -235,7 +235,8 @@ symbols! { Error, File, FileType, - FmtArgumentsNew, + FmtArgumentsFromStrNonconst, + FmtTemplateNew, FmtWrite, Fn, FnMut, @@ -1109,7 +1110,9 @@ symbols! { from_output, from_residual, from_size_align_unchecked, + from_str, from_str_method, + from_str_nonconst, from_u16, from_usize, from_yeet, diff --git a/library/core/src/fmt/mod.rs b/library/core/src/fmt/mod.rs index c82a3554db3e7..4c5e1da2a1106 100644 --- a/library/core/src/fmt/mod.rs +++ b/library/core/src/fmt/mod.rs @@ -630,45 +630,39 @@ impl<'a> Arguments<'a> { /// when using `format!`. Note: this is neither the lower nor upper bound. #[inline] pub fn estimated_capacity(&self) -> usize { + if let Some(s) = self.as_str() { + return s.len(); + } // Iterate over the template, counting the length of literal pieces. let mut length = 0usize; let mut starts_with_placeholder = false; let mut template = self.template; - let mut has_placeholders = false; loop { // SAFETY: We can assume the template is valid. unsafe { - let n = template.next().i; + let n = template.next_piece().i; if n == 0 { // End of template. break; } else if n <= isize::MAX as _ { // Literal string piece. - if length != 0 { - // More than one literal string piece means we have placeholders. - has_placeholders = true; - } length += n as usize; - let _ptr = template.next(); // Skip the string pointer. + let _ptr = template.next_piece(); // Skip the string pointer. } else { // Placeholder piece. if length == 0 { starts_with_placeholder = true; } - has_placeholders = true; // Skip remainder of placeholder: #[cfg(target_pointer_width = "32")] - let _ = template.next(); + let _ = template.next_piece(); #[cfg(target_pointer_width = "16")] - let _ = (template.next(), template.next(), template.next()); + let _ = (template.next_piece(), template.next_piece(), template.next_piece()); } } } - if !has_placeholders { - // If the template has no placeholders, we know the length exactly. - length - } else if starts_with_placeholder && length < 16 { + if starts_with_placeholder && length < 16 { // If the format string starts with a placeholder, // don't preallocate anything, unless length // of literal pieces is significant. @@ -730,27 +724,17 @@ impl<'a> Arguments<'a> { #[must_use] #[inline] pub const fn as_str(&self) -> Option<&'static str> { - let mut template = self.template; - // SAFETY: We can assume the template is valid. - let n = unsafe { template.next().i }; - if n == 0 { - // The template is empty. - return Some(""); - } - if n <= isize::MAX as _ { - // Template starts with a string piece. - // SAFETY: We can assume the template is valid. - unsafe { - let ptr = template.next().p; - if template.next().i == 0 { - // The template has only one piece. - return Some(str::from_utf8_unchecked(crate::slice::from_raw_parts( - ptr, n as usize, - ))); - } - } + if let Some(len) = self.template.as_str_len() { + // SAFETY: This fmt::Arguments stores a &'static str. + Some(unsafe { + str::from_utf8_unchecked(crate::slice::from_raw_parts( + self.args.cast().as_ptr(), + len, + )) + }) + } else { + None } - None } /// Same as [`Arguments::as_str`], but will only return `Some(s)` if it can be determined at compile time. @@ -1493,6 +1477,10 @@ pub trait UpperExp: PointeeSized { /// [`write!`]: crate::write! #[stable(feature = "rust1", since = "1.0.0")] pub fn write(output: &mut dyn Write, fmt: Arguments<'_>) -> Result { + if let Some(s) = fmt.as_str() { + return output.write_str(s); + } + let mut template = fmt.template; let args = fmt.args; @@ -1501,7 +1489,7 @@ pub fn write(output: &mut dyn Write, fmt: Arguments<'_>) -> Result { loop { // SAFETY: We can assume the template is valid. - let n = unsafe { template.next().i }; + let n = unsafe { template.next_piece().i }; if n == 0 { // End of template. return Ok(()); @@ -1518,7 +1506,7 @@ pub fn write(output: &mut dyn Write, fmt: Arguments<'_>) -> Result { unsafe { arg.fmt(&mut Formatter::new(output, options)) }?; } // SAFETY: We can assume the strings in the template are valid. - let s = unsafe { crate::str::from_raw_parts(template.next().p, n as usize) }; + let s = unsafe { crate::str::from_raw_parts(template.next_piece().p, n as usize) }; output.write_str(s)?; last_piece_was_str = true; } else { @@ -1527,13 +1515,13 @@ pub fn write(output: &mut dyn Write, fmt: Arguments<'_>) -> Result { let (high, low) = ((n >> 32) as u32, n as u32); #[cfg(target_pointer_width = "32")] // SAFETY: We can assume the template is valid. - let (high, low) = (n as u32, unsafe { template.next().i } as u32); + let (high, low) = (n as u32, unsafe { template.next_piece().i } as u32); #[cfg(target_pointer_width = "16")] // SAFETY: We can assume the template is valid. let (high, low) = unsafe { ( - (n as u32) << 16 | template.next().i as u32, - (template.next().i as u32) << 16 | template.next().i as u32, + (n as u32) << 16 | template.next_piece().i as u32, + (template.next_piece().i as u32) << 16 | template.next_piece().i as u32, ) }; let arg_index = (low & 0x3FF) as usize; diff --git a/library/core/src/fmt/rt.rs b/library/core/src/fmt/rt.rs index add92150eb6a2..b428de6e72b1f 100644 --- a/library/core/src/fmt/rt.rs +++ b/library/core/src/fmt/rt.rs @@ -9,6 +9,7 @@ use super::*; use crate::hint::unreachable_unchecked; use crate::marker::PhantomData; +use crate::num::NonZeroUsize; use crate::ptr::NonNull; #[lang = "format_template"] @@ -23,12 +24,29 @@ unsafe impl Sync for Template<'_> {} impl<'a> Template<'a> { #[inline] - pub const unsafe fn new(pieces: &'a [rt::Piece; N]) -> Self { + #[rustc_diagnostic_item = "FmtTemplateNew"] + pub unsafe fn new(pieces: &'a [rt::Piece; N]) -> Self { Self { pieces: NonNull::from_ref(pieces).cast(), lifetime: PhantomData } } #[inline] - pub const unsafe fn next(&mut self) -> Piece { + pub const unsafe fn new_str_len(len: usize) -> Self { + // SAFETY: We set the lowest bit, so it's nonzero. + let bits = unsafe { NonZeroUsize::new_unchecked(len << 1 | 1) }; + Self { pieces: NonNull::without_provenance(bits), lifetime: PhantomData } + } + + #[inline] + pub const fn as_str_len(self) -> Option { + // SAFETY: During const eval, `self.pieces` must have come from a usize, not a pointer, + // because `new()` above is not const. + // Outside const eval, transmuting a pointer to a usize is fine. + let bits = unsafe { crate::mem::transmute::<_, usize>(self.pieces) }; + if bits & 1 == 1 { Some(bits >> 1) } else { None } + } + + #[inline] + pub const unsafe fn next_piece(&mut self) -> Piece { // SAFETY: Guaranteed by caller. unsafe { let piece = *self.pieces.as_ref(); @@ -40,6 +58,7 @@ impl<'a> Template<'a> { #[lang = "format_piece"] #[derive(Copy, Clone)] +#[repr(align(2))] pub union Piece { pub i: usize, pub p: *const u8, @@ -224,31 +243,30 @@ impl Argument<'_> { /// Used by the format_args!() macro to create a fmt::Arguments object. #[doc(hidden)] -#[rustc_diagnostic_item = "FmtArgumentsNew"] impl<'a> Arguments<'a> { #[inline] - pub const fn new_const(template: rt::Template<'a>) -> Arguments<'a> { - Arguments { template, args: NonNull::dangling() } - } - - #[inline] - pub fn new( + pub const fn new( template: rt::Template<'a>, args: &'a [rt::Argument<'a>; N], ) -> Arguments<'a> { Arguments { template, args: NonNull::from_ref(args).cast() } } - // These two methods are used in library/core/src/panicking.rs to create a - // `fmt::Arguments` for a `&'static str`. #[inline] - pub(crate) const fn pieces_for_str(s: &'static str) -> [rt::Piece; 3] { - [rt::Piece { i: s.len() as _ }, rt::Piece::str(s), rt::Piece { i: 0 }] + pub const fn from_str(s: &'static str) -> Arguments<'a> { + Arguments { + // SAFETY: This is the "static str" representation of fmt::Arguments. + template: unsafe { rt::Template::new_str_len(s.len()) }, + args: NonNull::from_ref(s).cast(), + } } - /// Safety: Only call this with the result of `pieces_for_str`. + + // Same as `from_str`, but not const. + // Used by format_args!() expansion when arguments are inlined, + // e.g. format_args!("{}", 123), which is not allowed in const. #[inline] - pub(crate) const unsafe fn from_pieces(p: &'a [rt::Piece; 3]) -> Self { - // SAFETY: Guaranteed by caller. - Self::new_const(unsafe { rt::Template::new(p) }) + #[rustc_diagnostic_item = "FmtArgumentsFromStrNonconst"] + pub fn from_str_nonconst(s: &'static str) -> Arguments<'a> { + Arguments::from_str(s) } } diff --git a/library/core/src/panicking.rs b/library/core/src/panicking.rs index 6d5f47f188e71..fa758ebf46678 100644 --- a/library/core/src/panicking.rs +++ b/library/core/src/panicking.rs @@ -136,21 +136,18 @@ pub const fn panic_nounwind_fmt(fmt: fmt::Arguments<'_>, force_no_backtrace: boo #[rustc_const_stable_indirect] // must follow stable const rules since it is exposed to stable #[lang = "panic"] // used by lints and miri for panics pub const fn panic(expr: &'static str) -> ! { - // Use Arguments::new_const instead of format_args!("{expr}") to potentially + // Use Arguments::from_str instead of format_args!("{expr}") to potentially // reduce size overhead. The format_args! macro uses str's Display trait to // write expr, which calls Formatter::pad, which must accommodate string // truncation and padding (even though none is used here). Using - // Arguments::new_const may allow the compiler to omit Formatter::pad from the + // Arguments::from_str may allow the compiler to omit Formatter::pad from the // output binary, saving up to a few kilobytes. - // However, this optimization only works for `'static` strings: `new_const` also makes this + // However, this optimization only works for `'static` strings: `from_str` also makes this // message return `Some` from `Arguments::as_str`, which means it can become part of the panic // payload without any allocation or copying. Shorter-lived strings would become invalid as // stack frames get popped during unwinding, and couldn't be directly referenced from the // payload. - // SAFETY: This is the correct way to make a `fmt::Arguments` from a string literal. - unsafe { - panic_fmt(fmt::Arguments::from_pieces(&fmt::Arguments::pieces_for_str(expr))); - } + panic_fmt(fmt::Arguments::from_str(expr)); } // We generate functions for usage by compiler-generated assertions. @@ -174,10 +171,7 @@ macro_rules! panic_const { #[rustc_const_stable_indirect] // must follow stable const rules since it is exposed to stable #[lang = stringify!($lang)] pub const fn $lang() -> ! { - // SAFETY: This is the correct way to make a `fmt::Arguments` from a string literal. - unsafe { - panic_fmt(fmt::Arguments::from_pieces(&fmt::Arguments::pieces_for_str($message))); - } + panic_fmt(fmt::Arguments::from_str($message)); } )+ } @@ -227,14 +221,7 @@ pub mod panic_const { #[rustc_nounwind] #[rustc_const_stable_indirect] // must follow stable const rules since it is exposed to stable pub const fn panic_nounwind(expr: &'static str) -> ! { - // SAFETY: This is the correct way to make a `fmt::Arguments` from a string literal. - unsafe { - panic_nounwind_fmt( - // SAFETY: This is the correct way to make a `fmt::Arguments` from a string literal. - fmt::Arguments::from_pieces(&fmt::Arguments::pieces_for_str(expr)), - /* force_no_backtrace */ false, - ); - } + panic_nounwind_fmt(fmt::Arguments::from_str(expr), /* force_no_backtrace */ false); } /// Like `panic_nounwind`, but also inhibits showing a backtrace. @@ -242,13 +229,7 @@ pub const fn panic_nounwind(expr: &'static str) -> ! { #[cfg_attr(panic = "immediate-abort", inline)] #[rustc_nounwind] pub fn panic_nounwind_nobacktrace(expr: &'static str) -> ! { - // SAFETY: This is the correct way to make a `fmt::Arguments` from a string literal. - unsafe { - panic_nounwind_fmt( - fmt::Arguments::from_pieces(&fmt::Arguments::pieces_for_str(expr)), - /* force_no_backtrace */ true, - ); - } + panic_nounwind_fmt(fmt::Arguments::from_str(expr), /* force_no_backtrace */ true); } #[inline] From 4136c71d7561f01be0c54529c871c2c5c7807076 Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Wed, 5 Nov 2025 15:35:49 +0100 Subject: [PATCH 07/13] Bless tests. --- tests/coverage/abort.cov-map | 5 +- tests/coverage/assert.cov-map | 10 +- tests/coverage/async2.cov-map | 20 +-- .../coverage/attr/trait-impl-inherit.cov-map | 5 +- tests/coverage/bad_counter_ids.cov-map | 44 ++---- tests/coverage/closure.cov-map | 97 +++++------- tests/coverage/closure_macro.cov-map | 18 +-- tests/coverage/closure_macro_async.cov-map | 18 +-- tests/coverage/conditions.cov-map | 87 +++++----- tests/coverage/coverage_attr_closure.cov-map | 15 +- tests/coverage/drop_trait.cov-map | 10 +- tests/coverage/generics.cov-map | 15 +- tests/coverage/inline-dead.cov-map | 5 +- tests/coverage/inner_items.cov-map | 5 +- tests/coverage/issue-83601.cov-map | 7 +- tests/coverage/issue-84561.cov-map | 63 +++----- tests/coverage/loops_branches.cov-map | 18 +-- tests/coverage/macro_in_closure.cov-map | 10 +- tests/coverage/no_cov_crate.cov-map | 25 ++- tests/coverage/overflow.cov-map | 12 +- tests/coverage/panic_unwind.cov-map | 5 +- tests/coverage/partial_eq.cov-map | 7 +- tests/coverage/rustfmt-skip.cov-map | 7 +- tests/coverage/sort_groups.cov-map | 28 ++-- tests/coverage/unused_mod.cov-map | 10 +- tests/coverage/uses_crate.cov-map | 20 +-- tests/coverage/uses_inline_crate.cov-map | 20 +-- tests/mir-opt/gvn.slices.GVN.panic-abort.diff | 15 +- .../mir-opt/gvn.slices.GVN.panic-unwind.diff | 15 +- ...mes.foo.ScalarReplacementOfAggregates.diff | 148 ++++++++++-------- tests/ui/unpretty/exhaustive.hir.stdout | 4 +- 31 files changed, 333 insertions(+), 435 deletions(-) diff --git a/tests/coverage/abort.cov-map b/tests/coverage/abort.cov-map index 4d8ea874bd79f..b6bd0edebaaef 100644 --- a/tests/coverage/abort.cov-map +++ b/tests/coverage/abort.cov-map @@ -37,16 +37,15 @@ Number of file 0 mappings: 16 Highest counter ID seen: c4 Function name: abort::might_abort -Raw bytes (41): 0x[01, 01, 01, 01, 05, 07, 01, 03, 01, 00, 2e, 01, 01, 08, 00, 14, 05, 01, 09, 00, 11, 05, 00, 12, 00, 1f, 05, 01, 09, 00, 0f, 02, 01, 0c, 02, 06, 02, 03, 01, 00, 02] +Raw bytes (36): 0x[01, 01, 01, 01, 05, 06, 01, 03, 01, 00, 2e, 01, 01, 08, 00, 14, 05, 01, 09, 00, 11, 05, 01, 09, 00, 0f, 02, 01, 0c, 02, 06, 02, 03, 01, 00, 02] Number of files: 1 - file 0 => $DIR/abort.rs Number of expressions: 1 - expression 0 operands: lhs = Counter(0), rhs = Counter(1) -Number of file 0 mappings: 7 +Number of file 0 mappings: 6 - Code(Counter(0)) at (prev + 3, 1) to (start + 0, 46) - Code(Counter(0)) at (prev + 1, 8) to (start + 0, 20) - Code(Counter(1)) at (prev + 1, 9) to (start + 0, 17) -- Code(Counter(1)) at (prev + 0, 18) to (start + 0, 31) - Code(Counter(1)) at (prev + 1, 9) to (start + 0, 15) - Code(Expression(0, Sub)) at (prev + 1, 12) to (start + 2, 6) = (c0 - c1) diff --git a/tests/coverage/assert.cov-map b/tests/coverage/assert.cov-map index 07a0d4c8c27eb..543ab89628281 100644 --- a/tests/coverage/assert.cov-map +++ b/tests/coverage/assert.cov-map @@ -29,18 +29,14 @@ Number of file 0 mappings: 12 Highest counter ID seen: c3 Function name: assert::might_fail_assert -Raw bytes (36): 0x[01, 01, 01, 01, 05, 06, 01, 04, 01, 00, 28, 01, 01, 05, 00, 0d, 01, 00, 0e, 00, 20, 01, 01, 05, 00, 0f, 02, 00, 25, 00, 3d, 05, 01, 01, 00, 02] +Raw bytes (24): 0x[01, 01, 00, 04, 01, 04, 01, 00, 28, 01, 01, 05, 00, 0d, 01, 01, 05, 00, 0f, 05, 01, 01, 00, 02] Number of files: 1 - file 0 => $DIR/assert.rs -Number of expressions: 1 -- expression 0 operands: lhs = Counter(0), rhs = Counter(1) -Number of file 0 mappings: 6 +Number of expressions: 0 +Number of file 0 mappings: 4 - Code(Counter(0)) at (prev + 4, 1) to (start + 0, 40) - Code(Counter(0)) at (prev + 1, 5) to (start + 0, 13) -- Code(Counter(0)) at (prev + 0, 14) to (start + 0, 32) - Code(Counter(0)) at (prev + 1, 5) to (start + 0, 15) -- Code(Expression(0, Sub)) at (prev + 0, 37) to (start + 0, 61) - = (c0 - c1) - Code(Counter(1)) at (prev + 1, 1) to (start + 0, 2) Highest counter ID seen: c1 diff --git a/tests/coverage/async2.cov-map b/tests/coverage/async2.cov-map index cc62951709802..9fb5e8e4ef37e 100644 --- a/tests/coverage/async2.cov-map +++ b/tests/coverage/async2.cov-map @@ -8,14 +8,13 @@ Number of file 0 mappings: 1 Highest counter ID seen: c0 Function name: async2::async_func::{closure#0} -Raw bytes (49): 0x[01, 01, 00, 09, 01, 0f, 17, 00, 18, 01, 01, 05, 00, 0d, 01, 00, 0e, 00, 26, 01, 01, 09, 00, 0a, 01, 00, 0d, 00, 11, 01, 01, 08, 00, 09, 01, 00, 0a, 02, 06, 00, 02, 05, 00, 06, 01, 01, 01, 00, 02] +Raw bytes (44): 0x[01, 01, 00, 08, 01, 0f, 17, 00, 18, 01, 01, 05, 00, 0d, 01, 01, 09, 00, 0a, 01, 00, 0d, 00, 11, 01, 01, 08, 00, 09, 01, 00, 0a, 02, 06, 00, 02, 05, 00, 06, 01, 01, 01, 00, 02] Number of files: 1 - file 0 => $DIR/async2.rs Number of expressions: 0 -Number of file 0 mappings: 9 +Number of file 0 mappings: 8 - Code(Counter(0)) at (prev + 15, 23) to (start + 0, 24) - Code(Counter(0)) at (prev + 1, 5) to (start + 0, 13) -- Code(Counter(0)) at (prev + 0, 14) to (start + 0, 38) - Code(Counter(0)) at (prev + 1, 9) to (start + 0, 10) - Code(Counter(0)) at (prev + 0, 13) to (start + 0, 17) - Code(Counter(0)) at (prev + 1, 8) to (start + 0, 9) @@ -34,26 +33,24 @@ Number of file 0 mappings: 1 Highest counter ID seen: c0 Function name: async2::async_func_just_println::{closure#0} -Raw bytes (24): 0x[01, 01, 00, 04, 01, 17, 24, 00, 25, 01, 01, 05, 00, 0d, 01, 00, 0e, 00, 33, 01, 01, 01, 00, 02] +Raw bytes (19): 0x[01, 01, 00, 03, 01, 17, 24, 00, 25, 01, 01, 05, 00, 0d, 01, 01, 01, 00, 02] Number of files: 1 - file 0 => $DIR/async2.rs Number of expressions: 0 -Number of file 0 mappings: 4 +Number of file 0 mappings: 3 - Code(Counter(0)) at (prev + 23, 36) to (start + 0, 37) - Code(Counter(0)) at (prev + 1, 5) to (start + 0, 13) -- Code(Counter(0)) at (prev + 0, 14) to (start + 0, 51) - Code(Counter(0)) at (prev + 1, 1) to (start + 0, 2) Highest counter ID seen: c0 Function name: async2::main -Raw bytes (49): 0x[01, 01, 00, 09, 01, 1b, 01, 00, 0a, 01, 01, 05, 00, 0d, 01, 00, 0e, 00, 23, 01, 02, 05, 00, 13, 01, 02, 05, 00, 17, 01, 00, 18, 00, 22, 01, 01, 05, 00, 17, 01, 00, 18, 00, 2f, 01, 01, 01, 00, 02] +Raw bytes (44): 0x[01, 01, 00, 08, 01, 1b, 01, 00, 0a, 01, 01, 05, 00, 0d, 01, 02, 05, 00, 13, 01, 02, 05, 00, 17, 01, 00, 18, 00, 22, 01, 01, 05, 00, 17, 01, 00, 18, 00, 2f, 01, 01, 01, 00, 02] Number of files: 1 - file 0 => $DIR/async2.rs Number of expressions: 0 -Number of file 0 mappings: 9 +Number of file 0 mappings: 8 - Code(Counter(0)) at (prev + 27, 1) to (start + 0, 10) - Code(Counter(0)) at (prev + 1, 5) to (start + 0, 13) -- Code(Counter(0)) at (prev + 0, 14) to (start + 0, 35) - Code(Counter(0)) at (prev + 2, 5) to (start + 0, 19) - Code(Counter(0)) at (prev + 2, 5) to (start + 0, 23) - Code(Counter(0)) at (prev + 0, 24) to (start + 0, 34) @@ -63,14 +60,13 @@ Number of file 0 mappings: 9 Highest counter ID seen: c0 Function name: async2::non_async_func -Raw bytes (49): 0x[01, 01, 00, 09, 01, 07, 01, 00, 14, 01, 01, 05, 00, 0d, 01, 00, 0e, 00, 2a, 01, 01, 09, 00, 0a, 01, 00, 0d, 00, 11, 01, 01, 08, 00, 09, 01, 00, 0a, 02, 06, 00, 02, 05, 00, 06, 01, 01, 01, 00, 02] +Raw bytes (44): 0x[01, 01, 00, 08, 01, 07, 01, 00, 14, 01, 01, 05, 00, 0d, 01, 01, 09, 00, 0a, 01, 00, 0d, 00, 11, 01, 01, 08, 00, 09, 01, 00, 0a, 02, 06, 00, 02, 05, 00, 06, 01, 01, 01, 00, 02] Number of files: 1 - file 0 => $DIR/async2.rs Number of expressions: 0 -Number of file 0 mappings: 9 +Number of file 0 mappings: 8 - Code(Counter(0)) at (prev + 7, 1) to (start + 0, 20) - Code(Counter(0)) at (prev + 1, 5) to (start + 0, 13) -- Code(Counter(0)) at (prev + 0, 14) to (start + 0, 42) - Code(Counter(0)) at (prev + 1, 9) to (start + 0, 10) - Code(Counter(0)) at (prev + 0, 13) to (start + 0, 17) - Code(Counter(0)) at (prev + 1, 8) to (start + 0, 9) diff --git a/tests/coverage/attr/trait-impl-inherit.cov-map b/tests/coverage/attr/trait-impl-inherit.cov-map index bf10083dd2909..6aedd1043f97d 100644 --- a/tests/coverage/attr/trait-impl-inherit.cov-map +++ b/tests/coverage/attr/trait-impl-inherit.cov-map @@ -1,12 +1,11 @@ Function name: ::f -Raw bytes (24): 0x[01, 01, 00, 04, 01, 11, 05, 00, 10, 01, 01, 09, 00, 11, 01, 00, 12, 00, 1a, 01, 01, 05, 00, 06] +Raw bytes (19): 0x[01, 01, 00, 03, 01, 11, 05, 00, 10, 01, 01, 09, 00, 11, 01, 01, 05, 00, 06] Number of files: 1 - file 0 => $DIR/trait-impl-inherit.rs Number of expressions: 0 -Number of file 0 mappings: 4 +Number of file 0 mappings: 3 - Code(Counter(0)) at (prev + 17, 5) to (start + 0, 16) - Code(Counter(0)) at (prev + 1, 9) to (start + 0, 17) -- Code(Counter(0)) at (prev + 0, 18) to (start + 0, 26) - Code(Counter(0)) at (prev + 1, 5) to (start + 0, 6) Highest counter ID seen: c0 diff --git a/tests/coverage/bad_counter_ids.cov-map b/tests/coverage/bad_counter_ids.cov-map index 8b1b177f906ed..309b29220144e 100644 --- a/tests/coverage/bad_counter_ids.cov-map +++ b/tests/coverage/bad_counter_ids.cov-map @@ -1,108 +1,96 @@ Function name: bad_counter_ids::eq_bad -Raw bytes (29): 0x[01, 01, 00, 05, 01, 24, 01, 00, 0c, 01, 01, 05, 00, 0d, 01, 00, 0e, 00, 11, 01, 01, 05, 00, 0f, 00, 01, 01, 00, 02] +Raw bytes (24): 0x[01, 01, 00, 04, 01, 24, 01, 00, 0c, 01, 01, 05, 00, 0d, 01, 01, 05, 00, 0f, 00, 01, 01, 00, 02] Number of files: 1 - file 0 => $DIR/bad_counter_ids.rs Number of expressions: 0 -Number of file 0 mappings: 5 +Number of file 0 mappings: 4 - Code(Counter(0)) at (prev + 36, 1) to (start + 0, 12) - Code(Counter(0)) at (prev + 1, 5) to (start + 0, 13) -- Code(Counter(0)) at (prev + 0, 14) to (start + 0, 17) - Code(Counter(0)) at (prev + 1, 5) to (start + 0, 15) - Code(Zero) at (prev + 1, 1) to (start + 0, 2) Highest counter ID seen: c0 Function name: bad_counter_ids::eq_bad_message -Raw bytes (34): 0x[01, 01, 00, 06, 01, 29, 01, 00, 14, 01, 01, 05, 00, 0d, 01, 00, 0e, 00, 11, 01, 01, 05, 00, 0f, 01, 00, 20, 00, 2b, 00, 01, 01, 00, 02] +Raw bytes (24): 0x[01, 01, 00, 04, 01, 29, 01, 00, 14, 01, 01, 05, 00, 0d, 01, 01, 05, 00, 0f, 00, 01, 01, 00, 02] Number of files: 1 - file 0 => $DIR/bad_counter_ids.rs Number of expressions: 0 -Number of file 0 mappings: 6 +Number of file 0 mappings: 4 - Code(Counter(0)) at (prev + 41, 1) to (start + 0, 20) - Code(Counter(0)) at (prev + 1, 5) to (start + 0, 13) -- Code(Counter(0)) at (prev + 0, 14) to (start + 0, 17) - Code(Counter(0)) at (prev + 1, 5) to (start + 0, 15) -- Code(Counter(0)) at (prev + 0, 32) to (start + 0, 43) - Code(Zero) at (prev + 1, 1) to (start + 0, 2) Highest counter ID seen: c0 Function name: bad_counter_ids::eq_good -Raw bytes (29): 0x[01, 01, 00, 05, 01, 10, 01, 00, 0d, 01, 01, 05, 00, 0d, 01, 00, 0e, 00, 11, 01, 01, 05, 00, 0f, 01, 01, 01, 00, 02] +Raw bytes (24): 0x[01, 01, 00, 04, 01, 10, 01, 00, 0d, 01, 01, 05, 00, 0d, 01, 01, 05, 00, 0f, 01, 01, 01, 00, 02] Number of files: 1 - file 0 => $DIR/bad_counter_ids.rs Number of expressions: 0 -Number of file 0 mappings: 5 +Number of file 0 mappings: 4 - Code(Counter(0)) at (prev + 16, 1) to (start + 0, 13) - Code(Counter(0)) at (prev + 1, 5) to (start + 0, 13) -- Code(Counter(0)) at (prev + 0, 14) to (start + 0, 17) - Code(Counter(0)) at (prev + 1, 5) to (start + 0, 15) - Code(Counter(0)) at (prev + 1, 1) to (start + 0, 2) Highest counter ID seen: c0 Function name: bad_counter_ids::eq_good_message -Raw bytes (34): 0x[01, 01, 00, 06, 01, 15, 01, 00, 15, 01, 01, 05, 00, 0d, 01, 00, 0e, 00, 11, 01, 01, 05, 00, 0f, 00, 00, 20, 00, 2b, 01, 01, 01, 00, 02] +Raw bytes (24): 0x[01, 01, 00, 04, 01, 15, 01, 00, 15, 01, 01, 05, 00, 0d, 01, 01, 05, 00, 0f, 01, 01, 01, 00, 02] Number of files: 1 - file 0 => $DIR/bad_counter_ids.rs Number of expressions: 0 -Number of file 0 mappings: 6 +Number of file 0 mappings: 4 - Code(Counter(0)) at (prev + 21, 1) to (start + 0, 21) - Code(Counter(0)) at (prev + 1, 5) to (start + 0, 13) -- Code(Counter(0)) at (prev + 0, 14) to (start + 0, 17) - Code(Counter(0)) at (prev + 1, 5) to (start + 0, 15) -- Code(Zero) at (prev + 0, 32) to (start + 0, 43) - Code(Counter(0)) at (prev + 1, 1) to (start + 0, 2) Highest counter ID seen: c0 Function name: bad_counter_ids::ne_bad -Raw bytes (29): 0x[01, 01, 00, 05, 01, 2e, 01, 00, 0c, 01, 01, 05, 00, 0d, 01, 00, 0e, 00, 11, 01, 01, 05, 00, 0f, 00, 01, 01, 00, 02] +Raw bytes (24): 0x[01, 01, 00, 04, 01, 2e, 01, 00, 0c, 01, 01, 05, 00, 0d, 01, 01, 05, 00, 0f, 00, 01, 01, 00, 02] Number of files: 1 - file 0 => $DIR/bad_counter_ids.rs Number of expressions: 0 -Number of file 0 mappings: 5 +Number of file 0 mappings: 4 - Code(Counter(0)) at (prev + 46, 1) to (start + 0, 12) - Code(Counter(0)) at (prev + 1, 5) to (start + 0, 13) -- Code(Counter(0)) at (prev + 0, 14) to (start + 0, 17) - Code(Counter(0)) at (prev + 1, 5) to (start + 0, 15) - Code(Zero) at (prev + 1, 1) to (start + 0, 2) Highest counter ID seen: c0 Function name: bad_counter_ids::ne_bad_message -Raw bytes (34): 0x[01, 01, 00, 06, 01, 33, 01, 00, 14, 01, 01, 05, 00, 0d, 01, 00, 0e, 00, 11, 01, 01, 05, 00, 0f, 01, 00, 20, 00, 2b, 00, 01, 01, 00, 02] +Raw bytes (24): 0x[01, 01, 00, 04, 01, 33, 01, 00, 14, 01, 01, 05, 00, 0d, 01, 01, 05, 00, 0f, 00, 01, 01, 00, 02] Number of files: 1 - file 0 => $DIR/bad_counter_ids.rs Number of expressions: 0 -Number of file 0 mappings: 6 +Number of file 0 mappings: 4 - Code(Counter(0)) at (prev + 51, 1) to (start + 0, 20) - Code(Counter(0)) at (prev + 1, 5) to (start + 0, 13) -- Code(Counter(0)) at (prev + 0, 14) to (start + 0, 17) - Code(Counter(0)) at (prev + 1, 5) to (start + 0, 15) -- Code(Counter(0)) at (prev + 0, 32) to (start + 0, 43) - Code(Zero) at (prev + 1, 1) to (start + 0, 2) Highest counter ID seen: c0 Function name: bad_counter_ids::ne_good -Raw bytes (29): 0x[01, 01, 00, 05, 01, 1a, 01, 00, 0d, 01, 01, 05, 00, 0d, 01, 00, 0e, 00, 11, 01, 01, 05, 00, 0f, 01, 01, 01, 00, 02] +Raw bytes (24): 0x[01, 01, 00, 04, 01, 1a, 01, 00, 0d, 01, 01, 05, 00, 0d, 01, 01, 05, 00, 0f, 01, 01, 01, 00, 02] Number of files: 1 - file 0 => $DIR/bad_counter_ids.rs Number of expressions: 0 -Number of file 0 mappings: 5 +Number of file 0 mappings: 4 - Code(Counter(0)) at (prev + 26, 1) to (start + 0, 13) - Code(Counter(0)) at (prev + 1, 5) to (start + 0, 13) -- Code(Counter(0)) at (prev + 0, 14) to (start + 0, 17) - Code(Counter(0)) at (prev + 1, 5) to (start + 0, 15) - Code(Counter(0)) at (prev + 1, 1) to (start + 0, 2) Highest counter ID seen: c0 Function name: bad_counter_ids::ne_good_message -Raw bytes (34): 0x[01, 01, 00, 06, 01, 1f, 01, 00, 15, 01, 01, 05, 00, 0d, 01, 00, 0e, 00, 11, 01, 01, 05, 00, 0f, 00, 00, 20, 00, 2b, 01, 01, 01, 00, 02] +Raw bytes (24): 0x[01, 01, 00, 04, 01, 1f, 01, 00, 15, 01, 01, 05, 00, 0d, 01, 01, 05, 00, 0f, 01, 01, 01, 00, 02] Number of files: 1 - file 0 => $DIR/bad_counter_ids.rs Number of expressions: 0 -Number of file 0 mappings: 6 +Number of file 0 mappings: 4 - Code(Counter(0)) at (prev + 31, 1) to (start + 0, 21) - Code(Counter(0)) at (prev + 1, 5) to (start + 0, 13) -- Code(Counter(0)) at (prev + 0, 14) to (start + 0, 17) - Code(Counter(0)) at (prev + 1, 5) to (start + 0, 15) -- Code(Zero) at (prev + 0, 32) to (start + 0, 43) - Code(Counter(0)) at (prev + 1, 1) to (start + 0, 2) Highest counter ID seen: c0 diff --git a/tests/coverage/closure.cov-map b/tests/coverage/closure.cov-map index ee8934f0a846f..d713145d86129 100644 --- a/tests/coverage/closure.cov-map +++ b/tests/coverage/closure.cov-map @@ -1,10 +1,10 @@ Function name: closure::main -Raw bytes (336): 0x[01, 01, 01, 01, 05, 42, 01, 09, 01, 00, 0a, 01, 04, 09, 00, 10, 01, 00, 13, 00, 2e, 01, 01, 09, 00, 11, 01, 00, 14, 00, 1c, 01, 02, 09, 00, 18, 01, 00, 1b, 00, 43, 01, 01, 05, 00, 0d, 01, 01, 09, 00, 20, 01, 02, 09, 00, 14, 01, 02, 0d, 00, 1b, 01, 0d, 05, 00, 10, 01, 00, 13, 00, 3b, 01, 02, 09, 00, 0a, 01, 0a, 05, 00, 0d, 01, 01, 09, 00, 20, 01, 02, 09, 00, 14, 01, 02, 0d, 00, 1b, 01, 02, 0d, 00, 0e, 01, 04, 05, 00, 10, 01, 00, 13, 00, 17, 01, 01, 05, 00, 0d, 01, 01, 09, 00, 20, 01, 02, 09, 00, 14, 01, 02, 0d, 00, 1b, 01, 0d, 05, 00, 10, 01, 00, 13, 00, 17, 01, 02, 09, 00, 0a, 01, 0a, 05, 00, 0d, 01, 01, 09, 00, 20, 01, 02, 09, 00, 14, 01, 02, 0d, 00, 1b, 01, 02, 0d, 00, 0e, 01, 05, 09, 00, 16, 01, 0a, 05, 00, 0d, 01, 01, 09, 00, 28, 01, 02, 09, 00, 1a, 01, 01, 0e, 00, 12, 01, 01, 0e, 00, 11, 01, 02, 0d, 00, 1a, 01, 02, 0e, 00, 15, 01, 04, 09, 00, 18, 01, 0c, 09, 00, 16, 01, 00, 19, 00, 1b, 01, 01, 09, 00, 1e, 01, 03, 09, 00, 29, 01, 01, 09, 00, 2d, 01, 01, 09, 00, 24, 01, 05, 09, 00, 24, 01, 02, 09, 00, 21, 01, 04, 09, 00, 21, 01, 04, 09, 00, 28, 01, 09, 09, 00, 32, 01, 04, 09, 00, 33, 01, 07, 09, 00, 4b, 01, 08, 09, 00, 48, 01, 0a, 09, 00, 47, 01, 08, 09, 00, 44, 01, 0a, 08, 00, 10, 05, 00, 11, 04, 06, 05, 01, 09, 00, 30, 02, 03, 05, 00, 06, 01, 01, 05, 00, 28, 01, 01, 05, 00, 46, 01, 01, 05, 00, 43, 01, 01, 01, 00, 02] +Raw bytes (311): 0x[01, 01, 01, 01, 05, 3d, 01, 09, 01, 00, 0a, 01, 04, 09, 00, 10, 01, 00, 13, 00, 2e, 01, 01, 09, 00, 11, 01, 00, 14, 00, 1c, 01, 02, 09, 00, 18, 01, 00, 1b, 00, 43, 01, 01, 05, 00, 0d, 01, 03, 09, 00, 14, 01, 02, 0d, 00, 1b, 01, 0d, 05, 00, 10, 01, 00, 13, 00, 3b, 01, 02, 09, 00, 0a, 01, 0a, 05, 00, 0d, 01, 03, 09, 00, 14, 01, 02, 0d, 00, 1b, 01, 02, 0d, 00, 0e, 01, 04, 05, 00, 10, 01, 00, 13, 00, 17, 01, 01, 05, 00, 0d, 01, 03, 09, 00, 14, 01, 02, 0d, 00, 1b, 01, 0d, 05, 00, 10, 01, 00, 13, 00, 17, 01, 02, 09, 00, 0a, 01, 0a, 05, 00, 0d, 01, 03, 09, 00, 14, 01, 02, 0d, 00, 1b, 01, 02, 0d, 00, 0e, 01, 05, 09, 00, 16, 01, 0a, 05, 00, 0d, 01, 03, 09, 00, 1a, 01, 01, 0e, 00, 12, 01, 01, 0e, 00, 11, 01, 02, 0d, 00, 1a, 01, 02, 0e, 00, 15, 01, 04, 09, 00, 18, 01, 0c, 09, 00, 16, 01, 00, 19, 00, 1b, 01, 01, 09, 00, 1e, 01, 03, 09, 00, 29, 01, 01, 09, 00, 2d, 01, 01, 09, 00, 24, 01, 05, 09, 00, 24, 01, 02, 09, 00, 21, 01, 04, 09, 00, 21, 01, 04, 09, 00, 28, 01, 09, 09, 00, 32, 01, 04, 09, 00, 33, 01, 07, 09, 00, 4b, 01, 08, 09, 00, 48, 01, 0a, 09, 00, 47, 01, 08, 09, 00, 44, 01, 0a, 08, 00, 10, 05, 00, 11, 04, 06, 05, 01, 09, 00, 30, 02, 03, 05, 00, 06, 01, 01, 05, 00, 28, 01, 01, 05, 00, 46, 01, 01, 05, 00, 43, 01, 01, 01, 00, 02] Number of files: 1 - file 0 => $DIR/closure.rs Number of expressions: 1 - expression 0 operands: lhs = Counter(0), rhs = Counter(1) -Number of file 0 mappings: 66 +Number of file 0 mappings: 61 - Code(Counter(0)) at (prev + 9, 1) to (start + 0, 10) - Code(Counter(0)) at (prev + 4, 9) to (start + 0, 16) - Code(Counter(0)) at (prev + 0, 19) to (start + 0, 46) @@ -13,35 +13,30 @@ Number of file 0 mappings: 66 - Code(Counter(0)) at (prev + 2, 9) to (start + 0, 24) - Code(Counter(0)) at (prev + 0, 27) to (start + 0, 67) - Code(Counter(0)) at (prev + 1, 5) to (start + 0, 13) -- Code(Counter(0)) at (prev + 1, 9) to (start + 0, 32) -- Code(Counter(0)) at (prev + 2, 9) to (start + 0, 20) +- Code(Counter(0)) at (prev + 3, 9) to (start + 0, 20) - Code(Counter(0)) at (prev + 2, 13) to (start + 0, 27) - Code(Counter(0)) at (prev + 13, 5) to (start + 0, 16) - Code(Counter(0)) at (prev + 0, 19) to (start + 0, 59) - Code(Counter(0)) at (prev + 2, 9) to (start + 0, 10) - Code(Counter(0)) at (prev + 10, 5) to (start + 0, 13) -- Code(Counter(0)) at (prev + 1, 9) to (start + 0, 32) -- Code(Counter(0)) at (prev + 2, 9) to (start + 0, 20) +- Code(Counter(0)) at (prev + 3, 9) to (start + 0, 20) - Code(Counter(0)) at (prev + 2, 13) to (start + 0, 27) - Code(Counter(0)) at (prev + 2, 13) to (start + 0, 14) - Code(Counter(0)) at (prev + 4, 5) to (start + 0, 16) - Code(Counter(0)) at (prev + 0, 19) to (start + 0, 23) - Code(Counter(0)) at (prev + 1, 5) to (start + 0, 13) -- Code(Counter(0)) at (prev + 1, 9) to (start + 0, 32) -- Code(Counter(0)) at (prev + 2, 9) to (start + 0, 20) +- Code(Counter(0)) at (prev + 3, 9) to (start + 0, 20) - Code(Counter(0)) at (prev + 2, 13) to (start + 0, 27) - Code(Counter(0)) at (prev + 13, 5) to (start + 0, 16) - Code(Counter(0)) at (prev + 0, 19) to (start + 0, 23) - Code(Counter(0)) at (prev + 2, 9) to (start + 0, 10) - Code(Counter(0)) at (prev + 10, 5) to (start + 0, 13) -- Code(Counter(0)) at (prev + 1, 9) to (start + 0, 32) -- Code(Counter(0)) at (prev + 2, 9) to (start + 0, 20) +- Code(Counter(0)) at (prev + 3, 9) to (start + 0, 20) - Code(Counter(0)) at (prev + 2, 13) to (start + 0, 27) - Code(Counter(0)) at (prev + 2, 13) to (start + 0, 14) - Code(Counter(0)) at (prev + 5, 9) to (start + 0, 22) - Code(Counter(0)) at (prev + 10, 5) to (start + 0, 13) -- Code(Counter(0)) at (prev + 1, 9) to (start + 0, 40) -- Code(Counter(0)) at (prev + 2, 9) to (start + 0, 26) +- Code(Counter(0)) at (prev + 3, 9) to (start + 0, 26) - Code(Counter(0)) at (prev + 1, 14) to (start + 0, 18) - Code(Counter(0)) at (prev + 1, 14) to (start + 0, 17) - Code(Counter(0)) at (prev + 2, 13) to (start + 0, 26) @@ -94,74 +89,68 @@ Number of file 0 mappings: 9 Highest counter ID seen: c1 Function name: closure::main::{closure#10} (unused) -Raw bytes (25): 0x[01, 01, 00, 04, 00, 9b, 01, 07, 00, 08, 00, 00, 09, 00, 11, 00, 00, 12, 00, 1e, 00, 00, 20, 00, 21] +Raw bytes (20): 0x[01, 01, 00, 03, 00, 9b, 01, 07, 00, 08, 00, 00, 09, 00, 11, 00, 00, 20, 00, 21] Number of files: 1 - file 0 => $DIR/closure.rs Number of expressions: 0 -Number of file 0 mappings: 4 +Number of file 0 mappings: 3 - Code(Zero) at (prev + 155, 7) to (start + 0, 8) - Code(Zero) at (prev + 0, 9) to (start + 0, 17) -- Code(Zero) at (prev + 0, 18) to (start + 0, 30) - Code(Zero) at (prev + 0, 32) to (start + 0, 33) Highest counter ID seen: (none) Function name: closure::main::{closure#11} (unused) -Raw bytes (25): 0x[01, 01, 00, 04, 00, 9f, 01, 07, 00, 08, 00, 00, 09, 00, 11, 00, 00, 12, 00, 1e, 00, 00, 20, 00, 21] +Raw bytes (20): 0x[01, 01, 00, 03, 00, 9f, 01, 07, 00, 08, 00, 00, 09, 00, 11, 00, 00, 20, 00, 21] Number of files: 1 - file 0 => $DIR/closure.rs Number of expressions: 0 -Number of file 0 mappings: 4 +Number of file 0 mappings: 3 - Code(Zero) at (prev + 159, 7) to (start + 0, 8) - Code(Zero) at (prev + 0, 9) to (start + 0, 17) -- Code(Zero) at (prev + 0, 18) to (start + 0, 30) - Code(Zero) at (prev + 0, 32) to (start + 0, 33) Highest counter ID seen: (none) Function name: closure::main::{closure#12} (unused) -Raw bytes (15): 0x[01, 01, 00, 02, 00, a7, 01, 01, 00, 09, 00, 00, 0a, 00, 16] +Raw bytes (10): 0x[01, 01, 00, 01, 00, a7, 01, 01, 00, 09] Number of files: 1 - file 0 => $DIR/closure.rs Number of expressions: 0 -Number of file 0 mappings: 2 +Number of file 0 mappings: 1 - Code(Zero) at (prev + 167, 1) to (start + 0, 9) -- Code(Zero) at (prev + 0, 10) to (start + 0, 22) Highest counter ID seen: (none) Function name: closure::main::{closure#13} (unused) -Raw bytes (15): 0x[01, 01, 00, 02, 00, ac, 01, 0d, 00, 15, 00, 01, 11, 00, 1d] +Raw bytes (10): 0x[01, 01, 00, 01, 00, ac, 01, 0d, 00, 15] Number of files: 1 - file 0 => $DIR/closure.rs Number of expressions: 0 -Number of file 0 mappings: 2 +Number of file 0 mappings: 1 - Code(Zero) at (prev + 172, 13) to (start + 0, 21) -- Code(Zero) at (prev + 1, 17) to (start + 0, 29) Highest counter ID seen: (none) Function name: closure::main::{closure#14} -Raw bytes (27): 0x[01, 01, 01, 01, 05, 04, 01, b4, 01, 11, 00, 21, 01, 01, 14, 00, 1b, 05, 00, 1e, 00, 25, 02, 00, 2f, 00, 33] +Raw bytes (22): 0x[01, 01, 01, 01, 05, 03, 01, b5, 01, 14, 00, 1b, 05, 00, 1e, 00, 25, 02, 00, 2f, 00, 33] Number of files: 1 - file 0 => $DIR/closure.rs Number of expressions: 1 - expression 0 operands: lhs = Counter(0), rhs = Counter(1) -Number of file 0 mappings: 4 -- Code(Counter(0)) at (prev + 180, 17) to (start + 0, 33) -- Code(Counter(0)) at (prev + 1, 20) to (start + 0, 27) +Number of file 0 mappings: 3 +- Code(Counter(0)) at (prev + 181, 20) to (start + 0, 27) - Code(Counter(1)) at (prev + 0, 30) to (start + 0, 37) - Code(Expression(0, Sub)) at (prev + 0, 47) to (start + 0, 51) = (c0 - c1) Highest counter ID seen: c1 Function name: closure::main::{closure#15} -Raw bytes (42): 0x[01, 01, 01, 01, 05, 07, 01, bb, 01, 09, 00, 0a, 01, 01, 0d, 00, 15, 01, 01, 11, 00, 21, 01, 01, 14, 00, 1b, 05, 00, 1e, 00, 25, 02, 00, 2f, 00, 33, 01, 02, 09, 00, 0a] +Raw bytes (37): 0x[01, 01, 01, 01, 05, 06, 01, bb, 01, 09, 00, 0a, 01, 01, 0d, 00, 15, 01, 02, 14, 00, 1b, 05, 00, 1e, 00, 25, 02, 00, 2f, 00, 33, 01, 02, 09, 00, 0a] Number of files: 1 - file 0 => $DIR/closure.rs Number of expressions: 1 - expression 0 operands: lhs = Counter(0), rhs = Counter(1) -Number of file 0 mappings: 7 +Number of file 0 mappings: 6 - Code(Counter(0)) at (prev + 187, 9) to (start + 0, 10) - Code(Counter(0)) at (prev + 1, 13) to (start + 0, 21) -- Code(Counter(0)) at (prev + 1, 17) to (start + 0, 33) -- Code(Counter(0)) at (prev + 1, 20) to (start + 0, 27) +- Code(Counter(0)) at (prev + 2, 20) to (start + 0, 27) - Code(Counter(1)) at (prev + 0, 30) to (start + 0, 37) - Code(Expression(0, Sub)) at (prev + 0, 47) to (start + 0, 51) = (c0 - c1) @@ -169,30 +158,28 @@ Number of file 0 mappings: 7 Highest counter ID seen: c1 Function name: closure::main::{closure#16} -Raw bytes (27): 0x[01, 01, 01, 01, 05, 04, 01, c6, 01, 11, 00, 21, 01, 01, 14, 00, 1b, 05, 00, 1e, 00, 25, 02, 00, 2f, 00, 33] +Raw bytes (22): 0x[01, 01, 01, 01, 05, 03, 01, c7, 01, 14, 00, 1b, 05, 00, 1e, 00, 25, 02, 00, 2f, 00, 33] Number of files: 1 - file 0 => $DIR/closure.rs Number of expressions: 1 - expression 0 operands: lhs = Counter(0), rhs = Counter(1) -Number of file 0 mappings: 4 -- Code(Counter(0)) at (prev + 198, 17) to (start + 0, 33) -- Code(Counter(0)) at (prev + 1, 20) to (start + 0, 27) +Number of file 0 mappings: 3 +- Code(Counter(0)) at (prev + 199, 20) to (start + 0, 27) - Code(Counter(1)) at (prev + 0, 30) to (start + 0, 37) - Code(Expression(0, Sub)) at (prev + 0, 47) to (start + 0, 51) = (c0 - c1) Highest counter ID seen: c1 Function name: closure::main::{closure#17} -Raw bytes (42): 0x[01, 01, 01, 01, 05, 07, 01, cd, 01, 09, 00, 0a, 01, 01, 0d, 00, 15, 01, 01, 11, 00, 21, 01, 01, 14, 00, 1b, 05, 00, 1e, 00, 25, 02, 00, 2f, 00, 33, 01, 02, 09, 00, 0a] +Raw bytes (37): 0x[01, 01, 01, 01, 05, 06, 01, cd, 01, 09, 00, 0a, 01, 01, 0d, 00, 15, 01, 02, 14, 00, 1b, 05, 00, 1e, 00, 25, 02, 00, 2f, 00, 33, 01, 02, 09, 00, 0a] Number of files: 1 - file 0 => $DIR/closure.rs Number of expressions: 1 - expression 0 operands: lhs = Counter(0), rhs = Counter(1) -Number of file 0 mappings: 7 +Number of file 0 mappings: 6 - Code(Counter(0)) at (prev + 205, 9) to (start + 0, 10) - Code(Counter(0)) at (prev + 1, 13) to (start + 0, 21) -- Code(Counter(0)) at (prev + 1, 17) to (start + 0, 33) -- Code(Counter(0)) at (prev + 1, 20) to (start + 0, 27) +- Code(Counter(0)) at (prev + 2, 20) to (start + 0, 27) - Code(Counter(1)) at (prev + 0, 30) to (start + 0, 37) - Code(Expression(0, Sub)) at (prev + 0, 47) to (start + 0, 51) = (c0 - c1) @@ -257,12 +244,12 @@ Number of file 0 mappings: 9 Highest counter ID seen: c1 Function name: closure::main::{closure#2} -Raw bytes (51): 0x[01, 01, 01, 01, 05, 09, 01, 68, 05, 00, 06, 01, 01, 0d, 00, 1a, 01, 00, 1d, 00, 1e, 01, 01, 0c, 00, 14, 05, 00, 15, 02, 0a, 02, 02, 09, 00, 0a, 01, 01, 09, 00, 10, 01, 00, 11, 00, 17, 01, 01, 05, 00, 06] +Raw bytes (46): 0x[01, 01, 01, 01, 05, 08, 01, 68, 05, 00, 06, 01, 01, 0d, 00, 1a, 01, 00, 1d, 00, 1e, 01, 01, 0c, 00, 14, 05, 00, 15, 02, 0a, 02, 02, 09, 00, 0a, 01, 01, 09, 00, 10, 01, 01, 05, 00, 06] Number of files: 1 - file 0 => $DIR/closure.rs Number of expressions: 1 - expression 0 operands: lhs = Counter(0), rhs = Counter(1) -Number of file 0 mappings: 9 +Number of file 0 mappings: 8 - Code(Counter(0)) at (prev + 104, 5) to (start + 0, 6) - Code(Counter(0)) at (prev + 1, 13) to (start + 0, 26) - Code(Counter(0)) at (prev + 0, 29) to (start + 0, 30) @@ -271,7 +258,6 @@ Number of file 0 mappings: 9 - Code(Expression(0, Sub)) at (prev + 2, 9) to (start + 0, 10) = (c0 - c1) - Code(Counter(0)) at (prev + 1, 9) to (start + 0, 16) -- Code(Counter(0)) at (prev + 0, 17) to (start + 0, 23) - Code(Counter(0)) at (prev + 1, 5) to (start + 0, 6) Highest counter ID seen: c1 @@ -291,56 +277,51 @@ Number of file 0 mappings: 7 Highest counter ID seen: (none) Function name: closure::main::{closure#5} -Raw bytes (15): 0x[01, 01, 00, 02, 01, 8c, 01, 3d, 00, 45, 01, 00, 46, 00, 4e] +Raw bytes (10): 0x[01, 01, 00, 01, 01, 8c, 01, 3d, 00, 45] Number of files: 1 - file 0 => $DIR/closure.rs Number of expressions: 0 -Number of file 0 mappings: 2 +Number of file 0 mappings: 1 - Code(Counter(0)) at (prev + 140, 61) to (start + 0, 69) -- Code(Counter(0)) at (prev + 0, 70) to (start + 0, 78) Highest counter ID seen: c0 Function name: closure::main::{closure#6} -Raw bytes (15): 0x[01, 01, 00, 02, 01, 8d, 01, 41, 00, 49, 01, 00, 4a, 00, 56] +Raw bytes (10): 0x[01, 01, 00, 01, 01, 8d, 01, 41, 00, 49] Number of files: 1 - file 0 => $DIR/closure.rs Number of expressions: 0 -Number of file 0 mappings: 2 +Number of file 0 mappings: 1 - Code(Counter(0)) at (prev + 141, 65) to (start + 0, 73) -- Code(Counter(0)) at (prev + 0, 74) to (start + 0, 86) Highest counter ID seen: c0 Function name: closure::main::{closure#7} (unused) -Raw bytes (15): 0x[01, 01, 00, 02, 00, 8e, 01, 3b, 00, 43, 00, 00, 44, 00, 50] +Raw bytes (10): 0x[01, 01, 00, 01, 00, 8e, 01, 3b, 00, 43] Number of files: 1 - file 0 => $DIR/closure.rs Number of expressions: 0 -Number of file 0 mappings: 2 +Number of file 0 mappings: 1 - Code(Zero) at (prev + 142, 59) to (start + 0, 67) -- Code(Zero) at (prev + 0, 68) to (start + 0, 80) Highest counter ID seen: (none) Function name: closure::main::{closure#8} (unused) -Raw bytes (25): 0x[01, 01, 00, 04, 00, 93, 01, 3b, 00, 3c, 00, 00, 3d, 00, 45, 00, 00, 46, 00, 52, 00, 00, 54, 00, 55] +Raw bytes (20): 0x[01, 01, 00, 03, 00, 93, 01, 3b, 00, 3c, 00, 00, 3d, 00, 45, 00, 00, 54, 00, 55] Number of files: 1 - file 0 => $DIR/closure.rs Number of expressions: 0 -Number of file 0 mappings: 4 +Number of file 0 mappings: 3 - Code(Zero) at (prev + 147, 59) to (start + 0, 60) - Code(Zero) at (prev + 0, 61) to (start + 0, 69) -- Code(Zero) at (prev + 0, 70) to (start + 0, 82) - Code(Zero) at (prev + 0, 84) to (start + 0, 85) Highest counter ID seen: (none) Function name: closure::main::{closure#9} (unused) -Raw bytes (25): 0x[01, 01, 00, 04, 00, 95, 01, 38, 00, 39, 00, 01, 09, 00, 11, 00, 00, 12, 00, 1e, 00, 01, 05, 00, 06] +Raw bytes (20): 0x[01, 01, 00, 03, 00, 95, 01, 38, 00, 39, 00, 01, 09, 00, 11, 00, 01, 05, 00, 06] Number of files: 1 - file 0 => $DIR/closure.rs Number of expressions: 0 -Number of file 0 mappings: 4 +Number of file 0 mappings: 3 - Code(Zero) at (prev + 149, 56) to (start + 0, 57) - Code(Zero) at (prev + 1, 9) to (start + 0, 17) -- Code(Zero) at (prev + 0, 18) to (start + 0, 30) - Code(Zero) at (prev + 1, 5) to (start + 0, 6) Highest counter ID seen: (none) diff --git a/tests/coverage/closure_macro.cov-map b/tests/coverage/closure_macro.cov-map index 3ab1d7f5fba80..dd3629771085f 100644 --- a/tests/coverage/closure_macro.cov-map +++ b/tests/coverage/closure_macro.cov-map @@ -10,15 +10,14 @@ Number of file 0 mappings: 3 Highest counter ID seen: c0 Function name: closure_macro::main -Raw bytes (66): 0x[01, 01, 01, 01, 05, 0c, 01, 21, 01, 00, 24, 01, 01, 05, 00, 0d, 01, 00, 0e, 00, 20, 02, 01, 09, 00, 0f, 01, 00, 12, 00, 1b, 01, 00, 1c, 00, 34, 05, 00, 54, 00, 55, 02, 02, 09, 00, 1f, 02, 00, 22, 00, 2e, 02, 01, 0d, 00, 2d, 02, 01, 05, 00, 0b, 01, 01, 01, 00, 02] +Raw bytes (61): 0x[01, 01, 01, 01, 05, 0b, 01, 21, 01, 00, 24, 01, 01, 05, 00, 0d, 02, 01, 09, 00, 0f, 01, 00, 12, 00, 1b, 01, 00, 1c, 00, 34, 05, 00, 54, 00, 55, 02, 02, 09, 00, 1f, 02, 00, 22, 00, 2e, 02, 01, 0d, 00, 2d, 02, 01, 05, 00, 0b, 01, 01, 01, 00, 02] Number of files: 1 - file 0 => $DIR/closure_macro.rs Number of expressions: 1 - expression 0 operands: lhs = Counter(0), rhs = Counter(1) -Number of file 0 mappings: 12 +Number of file 0 mappings: 11 - Code(Counter(0)) at (prev + 33, 1) to (start + 0, 36) - Code(Counter(0)) at (prev + 1, 5) to (start + 0, 13) -- Code(Counter(0)) at (prev + 0, 14) to (start + 0, 32) - Code(Expression(0, Sub)) at (prev + 1, 9) to (start + 0, 15) = (c0 - c1) - Code(Counter(0)) at (prev + 0, 18) to (start + 0, 27) @@ -36,25 +35,22 @@ Number of file 0 mappings: 12 Highest counter ID seen: c1 Function name: closure_macro::main::{closure#0} -Raw bytes (60): 0x[01, 01, 03, 01, 05, 01, 0b, 05, 09, 0a, 01, 10, 1c, 00, 1d, 01, 02, 11, 00, 18, 01, 00, 1b, 00, 22, 01, 01, 10, 00, 21, 05, 01, 11, 00, 19, 05, 00, 1a, 00, 1e, 05, 01, 11, 00, 27, 02, 02, 11, 00, 16, 06, 00, 17, 00, 1e, 01, 02, 09, 00, 0a] +Raw bytes (51): 0x[01, 01, 01, 01, 05, 09, 01, 10, 1c, 00, 1d, 01, 02, 11, 00, 18, 01, 00, 1b, 00, 22, 01, 01, 10, 00, 21, 05, 01, 11, 00, 19, 05, 01, 11, 00, 27, 02, 02, 11, 00, 16, 02, 00, 17, 00, 1e, 01, 02, 09, 00, 0a] Number of files: 1 - file 0 => $DIR/closure_macro.rs -Number of expressions: 3 +Number of expressions: 1 - expression 0 operands: lhs = Counter(0), rhs = Counter(1) -- expression 1 operands: lhs = Counter(0), rhs = Expression(2, Add) -- expression 2 operands: lhs = Counter(1), rhs = Counter(2) -Number of file 0 mappings: 10 +Number of file 0 mappings: 9 - Code(Counter(0)) at (prev + 16, 28) to (start + 0, 29) - Code(Counter(0)) at (prev + 2, 17) to (start + 0, 24) - Code(Counter(0)) at (prev + 0, 27) to (start + 0, 34) - Code(Counter(0)) at (prev + 1, 16) to (start + 0, 33) - Code(Counter(1)) at (prev + 1, 17) to (start + 0, 25) -- Code(Counter(1)) at (prev + 0, 26) to (start + 0, 30) - Code(Counter(1)) at (prev + 1, 17) to (start + 0, 39) - Code(Expression(0, Sub)) at (prev + 2, 17) to (start + 0, 22) = (c0 - c1) -- Code(Expression(1, Sub)) at (prev + 0, 23) to (start + 0, 30) - = (c0 - (c1 + c2)) +- Code(Expression(0, Sub)) at (prev + 0, 23) to (start + 0, 30) + = (c0 - c1) - Code(Counter(0)) at (prev + 2, 9) to (start + 0, 10) Highest counter ID seen: c1 diff --git a/tests/coverage/closure_macro_async.cov-map b/tests/coverage/closure_macro_async.cov-map index b5f4cee0ec445..b6dd4a930c78e 100644 --- a/tests/coverage/closure_macro_async.cov-map +++ b/tests/coverage/closure_macro_async.cov-map @@ -19,15 +19,14 @@ Number of file 0 mappings: 1 Highest counter ID seen: c0 Function name: closure_macro_async::test::{closure#0} -Raw bytes (66): 0x[01, 01, 01, 01, 05, 0c, 01, 25, 2b, 00, 2c, 01, 01, 05, 00, 0d, 01, 00, 0e, 00, 20, 02, 01, 09, 00, 0f, 01, 00, 12, 00, 1b, 01, 00, 1c, 00, 34, 05, 00, 54, 00, 55, 02, 02, 09, 00, 1f, 02, 00, 22, 00, 2e, 02, 01, 0d, 00, 2d, 02, 01, 05, 00, 0b, 01, 01, 01, 00, 02] +Raw bytes (61): 0x[01, 01, 01, 01, 05, 0b, 01, 25, 2b, 00, 2c, 01, 01, 05, 00, 0d, 02, 01, 09, 00, 0f, 01, 00, 12, 00, 1b, 01, 00, 1c, 00, 34, 05, 00, 54, 00, 55, 02, 02, 09, 00, 1f, 02, 00, 22, 00, 2e, 02, 01, 0d, 00, 2d, 02, 01, 05, 00, 0b, 01, 01, 01, 00, 02] Number of files: 1 - file 0 => $DIR/closure_macro_async.rs Number of expressions: 1 - expression 0 operands: lhs = Counter(0), rhs = Counter(1) -Number of file 0 mappings: 12 +Number of file 0 mappings: 11 - Code(Counter(0)) at (prev + 37, 43) to (start + 0, 44) - Code(Counter(0)) at (prev + 1, 5) to (start + 0, 13) -- Code(Counter(0)) at (prev + 0, 14) to (start + 0, 32) - Code(Expression(0, Sub)) at (prev + 1, 9) to (start + 0, 15) = (c0 - c1) - Code(Counter(0)) at (prev + 0, 18) to (start + 0, 27) @@ -45,25 +44,22 @@ Number of file 0 mappings: 12 Highest counter ID seen: c1 Function name: closure_macro_async::test::{closure#0}::{closure#0} -Raw bytes (60): 0x[01, 01, 03, 01, 05, 01, 0b, 05, 09, 0a, 01, 14, 1c, 00, 1d, 01, 02, 11, 00, 18, 01, 00, 1b, 00, 22, 01, 01, 10, 00, 21, 05, 01, 11, 00, 19, 05, 00, 1a, 00, 1e, 05, 01, 11, 00, 27, 02, 02, 11, 00, 16, 06, 00, 17, 00, 1e, 01, 02, 09, 00, 0a] +Raw bytes (51): 0x[01, 01, 01, 01, 05, 09, 01, 14, 1c, 00, 1d, 01, 02, 11, 00, 18, 01, 00, 1b, 00, 22, 01, 01, 10, 00, 21, 05, 01, 11, 00, 19, 05, 01, 11, 00, 27, 02, 02, 11, 00, 16, 02, 00, 17, 00, 1e, 01, 02, 09, 00, 0a] Number of files: 1 - file 0 => $DIR/closure_macro_async.rs -Number of expressions: 3 +Number of expressions: 1 - expression 0 operands: lhs = Counter(0), rhs = Counter(1) -- expression 1 operands: lhs = Counter(0), rhs = Expression(2, Add) -- expression 2 operands: lhs = Counter(1), rhs = Counter(2) -Number of file 0 mappings: 10 +Number of file 0 mappings: 9 - Code(Counter(0)) at (prev + 20, 28) to (start + 0, 29) - Code(Counter(0)) at (prev + 2, 17) to (start + 0, 24) - Code(Counter(0)) at (prev + 0, 27) to (start + 0, 34) - Code(Counter(0)) at (prev + 1, 16) to (start + 0, 33) - Code(Counter(1)) at (prev + 1, 17) to (start + 0, 25) -- Code(Counter(1)) at (prev + 0, 26) to (start + 0, 30) - Code(Counter(1)) at (prev + 1, 17) to (start + 0, 39) - Code(Expression(0, Sub)) at (prev + 2, 17) to (start + 0, 22) = (c0 - c1) -- Code(Expression(1, Sub)) at (prev + 0, 23) to (start + 0, 30) - = (c0 - (c1 + c2)) +- Code(Expression(0, Sub)) at (prev + 0, 23) to (start + 0, 30) + = (c0 - c1) - Code(Counter(0)) at (prev + 2, 9) to (start + 0, 10) Highest counter ID seen: c1 diff --git a/tests/coverage/conditions.cov-map b/tests/coverage/conditions.cov-map index 29d9604085ede..c6eba8c8b3ab7 100644 --- a/tests/coverage/conditions.cov-map +++ b/tests/coverage/conditions.cov-map @@ -1,8 +1,8 @@ Function name: conditions::main -Raw bytes (656): 0x[01, 01, 57, 05, 09, 01, 05, 09, 5d, 09, 27, 5d, 61, 27, 65, 5d, 61, 09, 23, 27, 65, 5d, 61, 01, 03, 03, 0d, 11, 51, 11, 4f, 51, 55, 4f, 59, 51, 55, 11, 4b, 4f, 59, 51, 55, 03, 9f, 01, 0d, 11, 0d, 11, 0d, 11, 0d, 11, 0d, 11, 0d, 11, 0d, 11, 9f, 01, 15, 0d, 11, 19, 45, 19, 97, 01, 45, 49, 97, 01, 4d, 45, 49, 19, 93, 01, 97, 01, 4d, 45, 49, 9f, 01, 9b, 02, 0d, 11, 15, 19, 15, 19, 15, 19, 15, 19, 15, 19, 1d, 21, 15, 19, 9b, 02, 1d, 15, 19, 21, 39, 21, e3, 01, 39, 3d, e3, 01, 41, 39, 3d, 21, df, 01, e3, 01, 41, 39, 3d, 9b, 02, d7, 02, 15, 19, 1d, 21, 9b, 02, d7, 02, 15, 19, 1d, 21, 9b, 02, d7, 02, 15, 19, 1d, 21, 9b, 02, d7, 02, 15, 19, 1d, 21, 9b, 02, d7, 02, 15, 19, 1d, 21, 25, 29, 1d, 21, d7, 02, 25, 1d, 21, 29, 2d, 29, cf, 02, 2d, 31, cf, 02, 35, 2d, 31, 29, cb, 02, cf, 02, 35, 2d, 31, d7, 02, db, 02, 1d, 21, 25, 29, 53, 01, 03, 01, 00, 0a, 01, 01, 09, 00, 16, 01, 00, 19, 00, 1a, 01, 01, 08, 00, 0c, 01, 00, 0d, 02, 06, 00, 02, 05, 00, 06, 03, 03, 09, 00, 0a, 01, 00, 10, 00, 1d, 05, 01, 09, 00, 17, 05, 01, 09, 00, 0a, 06, 01, 0f, 00, 1c, 09, 01, 0c, 00, 19, 0a, 00, 1d, 00, 2a, 0e, 00, 2e, 00, 3c, 23, 00, 3d, 02, 0a, 1e, 02, 09, 00, 0a, 09, 01, 09, 00, 17, 09, 01, 09, 00, 12, 2a, 02, 09, 00, 0f, 03, 03, 09, 00, 16, 03, 00, 19, 00, 1a, 03, 01, 08, 00, 0c, 03, 00, 0d, 02, 06, 00, 02, 05, 00, 06, 03, 02, 08, 00, 15, 0d, 00, 16, 02, 06, 2e, 02, 0f, 00, 1c, 11, 01, 0c, 00, 19, 32, 00, 1d, 00, 2a, 36, 00, 2e, 00, 3c, 4b, 00, 3d, 02, 0a, 46, 02, 09, 00, 0a, 11, 01, 09, 00, 17, 52, 02, 09, 00, 0f, 9f, 01, 03, 08, 00, 0c, 9f, 01, 01, 0d, 00, 1a, 9f, 01, 00, 1d, 00, 1e, 9f, 01, 01, 0c, 00, 10, 9f, 01, 00, 11, 02, 0a, 00, 02, 09, 00, 0a, 9f, 01, 02, 0c, 00, 19, 15, 00, 1a, 02, 0a, 72, 04, 11, 00, 1e, 19, 01, 10, 00, 1d, 7a, 00, 21, 00, 2e, 7e, 00, 32, 00, 40, 93, 01, 00, 41, 02, 0e, 8e, 01, 02, 0d, 00, 0e, 19, 01, 0d, 00, 1b, 9a, 01, 02, 0d, 00, 13, 00, 02, 05, 00, 06, 9b, 02, 02, 09, 00, 16, 9b, 02, 00, 19, 00, 1a, 9b, 02, 01, 08, 00, 0c, 9b, 02, 00, 0d, 02, 06, 00, 02, 05, 00, 06, d7, 02, 02, 09, 00, 0a, 9b, 02, 00, 10, 00, 1d, 1d, 00, 1e, 02, 06, be, 01, 02, 0f, 00, 1c, 21, 01, 0c, 00, 19, c6, 01, 00, 1d, 00, 2a, ca, 01, 00, 2e, 00, 3c, df, 01, 00, 3d, 02, 0a, da, 01, 02, 09, 00, 0a, 21, 01, 09, 00, 17, 96, 02, 02, 0d, 00, 20, 96, 02, 00, 23, 00, 2c, 96, 02, 01, 09, 00, 11, 96, 02, 00, 12, 00, 1b, 96, 02, 01, 09, 00, 0f, db, 02, 03, 09, 00, 0a, d7, 02, 00, 10, 00, 1d, 25, 00, 1e, 02, 06, aa, 02, 02, 0f, 00, 1c, 29, 01, 0c, 00, 19, b2, 02, 00, 1d, 00, 2a, b6, 02, 00, 2e, 00, 3c, cb, 02, 00, 3d, 02, 0a, c6, 02, 02, 09, 00, 0a, 29, 01, 09, 00, 17, d2, 02, 02, 09, 00, 0f, 01, 02, 01, 00, 02] +Raw bytes (642): 0x[01, 01, 54, 05, 09, 01, 05, 09, 5d, 09, 27, 5d, 61, 27, 65, 5d, 61, 09, 23, 27, 65, 5d, 61, 01, 03, 03, 0d, 11, 51, 11, 4f, 51, 55, 4f, 59, 51, 55, 11, 4b, 4f, 59, 51, 55, 03, 9f, 01, 0d, 11, 0d, 11, 0d, 11, 0d, 11, 0d, 11, 0d, 11, 0d, 11, 9f, 01, 15, 0d, 11, 19, 45, 19, 97, 01, 45, 49, 97, 01, 4d, 45, 49, 19, 93, 01, 97, 01, 4d, 45, 49, 9f, 01, 8f, 02, 0d, 11, 15, 19, 15, 19, 15, 19, 15, 19, 15, 19, 1d, 21, 15, 19, 8f, 02, 1d, 15, 19, 21, 39, 21, e3, 01, 39, 3d, e3, 01, 41, 39, 3d, 21, df, 01, e3, 01, 41, 39, 3d, 8f, 02, cb, 02, 15, 19, 1d, 21, 8f, 02, cb, 02, 15, 19, 1d, 21, 8f, 02, cb, 02, 15, 19, 1d, 21, 8f, 02, cb, 02, 15, 19, 1d, 21, 25, 29, 1d, 21, cb, 02, 25, 1d, 21, 29, 2d, 29, c3, 02, 2d, 31, c3, 02, 35, 2d, 31, 29, bf, 02, c3, 02, 35, 2d, 31, cb, 02, cf, 02, 1d, 21, 25, 29, 52, 01, 03, 01, 00, 0a, 01, 01, 09, 00, 16, 01, 00, 19, 00, 1a, 01, 01, 08, 00, 0c, 01, 00, 0d, 02, 06, 00, 02, 05, 00, 06, 03, 03, 09, 00, 0a, 01, 00, 10, 00, 1d, 05, 01, 09, 00, 17, 05, 01, 09, 00, 0a, 06, 01, 0f, 00, 1c, 09, 01, 0c, 00, 19, 0a, 00, 1d, 00, 2a, 0e, 00, 2e, 00, 3c, 23, 00, 3d, 02, 0a, 1e, 02, 09, 00, 0a, 09, 01, 09, 00, 17, 09, 01, 09, 00, 12, 2a, 02, 09, 00, 0f, 03, 03, 09, 00, 16, 03, 00, 19, 00, 1a, 03, 01, 08, 00, 0c, 03, 00, 0d, 02, 06, 00, 02, 05, 00, 06, 03, 02, 08, 00, 15, 0d, 00, 16, 02, 06, 2e, 02, 0f, 00, 1c, 11, 01, 0c, 00, 19, 32, 00, 1d, 00, 2a, 36, 00, 2e, 00, 3c, 4b, 00, 3d, 02, 0a, 46, 02, 09, 00, 0a, 11, 01, 09, 00, 17, 52, 02, 09, 00, 0f, 9f, 01, 03, 08, 00, 0c, 9f, 01, 01, 0d, 00, 1a, 9f, 01, 00, 1d, 00, 1e, 9f, 01, 01, 0c, 00, 10, 9f, 01, 00, 11, 02, 0a, 00, 02, 09, 00, 0a, 9f, 01, 02, 0c, 00, 19, 15, 00, 1a, 02, 0a, 72, 04, 11, 00, 1e, 19, 01, 10, 00, 1d, 7a, 00, 21, 00, 2e, 7e, 00, 32, 00, 40, 93, 01, 00, 41, 02, 0e, 8e, 01, 02, 0d, 00, 0e, 19, 01, 0d, 00, 1b, 9a, 01, 02, 0d, 00, 13, 00, 02, 05, 00, 06, 8f, 02, 02, 09, 00, 16, 8f, 02, 00, 19, 00, 1a, 8f, 02, 01, 08, 00, 0c, 8f, 02, 00, 0d, 02, 06, 00, 02, 05, 00, 06, cb, 02, 02, 09, 00, 0a, 8f, 02, 00, 10, 00, 1d, 1d, 00, 1e, 02, 06, be, 01, 02, 0f, 00, 1c, 21, 01, 0c, 00, 19, c6, 01, 00, 1d, 00, 2a, ca, 01, 00, 2e, 00, 3c, df, 01, 00, 3d, 02, 0a, da, 01, 02, 09, 00, 0a, 21, 01, 09, 00, 17, 8a, 02, 02, 0d, 00, 20, 8a, 02, 00, 23, 00, 2c, 8a, 02, 01, 09, 00, 11, 8a, 02, 01, 09, 00, 0f, cf, 02, 03, 09, 00, 0a, cb, 02, 00, 10, 00, 1d, 25, 00, 1e, 02, 06, 9e, 02, 02, 0f, 00, 1c, 29, 01, 0c, 00, 19, a6, 02, 00, 1d, 00, 2a, aa, 02, 00, 2e, 00, 3c, bf, 02, 00, 3d, 02, 0a, ba, 02, 02, 09, 00, 0a, 29, 01, 09, 00, 17, c6, 02, 02, 09, 00, 0f, 01, 02, 01, 00, 02] Number of files: 1 - file 0 => $DIR/conditions.rs -Number of expressions: 87 +Number of expressions: 84 - expression 0 operands: lhs = Counter(1), rhs = Counter(2) - expression 1 operands: lhs = Counter(0), rhs = Counter(1) - expression 2 operands: lhs = Counter(2), rhs = Counter(23) @@ -41,7 +41,7 @@ Number of expressions: 87 - expression 35 operands: lhs = Counter(6), rhs = Expression(36, Add) - expression 36 operands: lhs = Expression(37, Add), rhs = Counter(19) - expression 37 operands: lhs = Counter(17), rhs = Counter(18) -- expression 38 operands: lhs = Expression(39, Add), rhs = Expression(70, Add) +- expression 38 operands: lhs = Expression(39, Add), rhs = Expression(67, Add) - expression 39 operands: lhs = Counter(3), rhs = Counter(4) - expression 40 operands: lhs = Counter(5), rhs = Counter(6) - expression 41 operands: lhs = Counter(5), rhs = Counter(6) @@ -50,7 +50,7 @@ Number of expressions: 87 - expression 44 operands: lhs = Counter(5), rhs = Counter(6) - expression 45 operands: lhs = Counter(7), rhs = Counter(8) - expression 46 operands: lhs = Counter(5), rhs = Counter(6) -- expression 47 operands: lhs = Expression(70, Add), rhs = Counter(7) +- expression 47 operands: lhs = Expression(67, Add), rhs = Counter(7) - expression 48 operands: lhs = Counter(5), rhs = Counter(6) - expression 49 operands: lhs = Counter(8), rhs = Counter(14) - expression 50 operands: lhs = Counter(8), rhs = Expression(56, Add) @@ -60,37 +60,34 @@ Number of expressions: 87 - expression 54 operands: lhs = Counter(8), rhs = Expression(55, Add) - expression 55 operands: lhs = Expression(56, Add), rhs = Counter(16) - expression 56 operands: lhs = Counter(14), rhs = Counter(15) -- expression 57 operands: lhs = Expression(70, Add), rhs = Expression(85, Add) +- expression 57 operands: lhs = Expression(67, Add), rhs = Expression(82, Add) - expression 58 operands: lhs = Counter(5), rhs = Counter(6) - expression 59 operands: lhs = Counter(7), rhs = Counter(8) -- expression 60 operands: lhs = Expression(70, Add), rhs = Expression(85, Add) +- expression 60 operands: lhs = Expression(67, Add), rhs = Expression(82, Add) - expression 61 operands: lhs = Counter(5), rhs = Counter(6) - expression 62 operands: lhs = Counter(7), rhs = Counter(8) -- expression 63 operands: lhs = Expression(70, Add), rhs = Expression(85, Add) +- expression 63 operands: lhs = Expression(67, Add), rhs = Expression(82, Add) - expression 64 operands: lhs = Counter(5), rhs = Counter(6) - expression 65 operands: lhs = Counter(7), rhs = Counter(8) -- expression 66 operands: lhs = Expression(70, Add), rhs = Expression(85, Add) +- expression 66 operands: lhs = Expression(67, Add), rhs = Expression(82, Add) - expression 67 operands: lhs = Counter(5), rhs = Counter(6) - expression 68 operands: lhs = Counter(7), rhs = Counter(8) -- expression 69 operands: lhs = Expression(70, Add), rhs = Expression(85, Add) -- expression 70 operands: lhs = Counter(5), rhs = Counter(6) -- expression 71 operands: lhs = Counter(7), rhs = Counter(8) -- expression 72 operands: lhs = Counter(9), rhs = Counter(10) -- expression 73 operands: lhs = Counter(7), rhs = Counter(8) -- expression 74 operands: lhs = Expression(85, Add), rhs = Counter(9) -- expression 75 operands: lhs = Counter(7), rhs = Counter(8) -- expression 76 operands: lhs = Counter(10), rhs = Counter(11) -- expression 77 operands: lhs = Counter(10), rhs = Expression(83, Add) -- expression 78 operands: lhs = Counter(11), rhs = Counter(12) -- expression 79 operands: lhs = Expression(83, Add), rhs = Counter(13) +- expression 69 operands: lhs = Counter(9), rhs = Counter(10) +- expression 70 operands: lhs = Counter(7), rhs = Counter(8) +- expression 71 operands: lhs = Expression(82, Add), rhs = Counter(9) +- expression 72 operands: lhs = Counter(7), rhs = Counter(8) +- expression 73 operands: lhs = Counter(10), rhs = Counter(11) +- expression 74 operands: lhs = Counter(10), rhs = Expression(80, Add) +- expression 75 operands: lhs = Counter(11), rhs = Counter(12) +- expression 76 operands: lhs = Expression(80, Add), rhs = Counter(13) +- expression 77 operands: lhs = Counter(11), rhs = Counter(12) +- expression 78 operands: lhs = Counter(10), rhs = Expression(79, Add) +- expression 79 operands: lhs = Expression(80, Add), rhs = Counter(13) - expression 80 operands: lhs = Counter(11), rhs = Counter(12) -- expression 81 operands: lhs = Counter(10), rhs = Expression(82, Add) -- expression 82 operands: lhs = Expression(83, Add), rhs = Counter(13) -- expression 83 operands: lhs = Counter(11), rhs = Counter(12) -- expression 84 operands: lhs = Expression(85, Add), rhs = Expression(86, Add) -- expression 85 operands: lhs = Counter(7), rhs = Counter(8) -- expression 86 operands: lhs = Counter(9), rhs = Counter(10) -Number of file 0 mappings: 83 +- expression 81 operands: lhs = Expression(82, Add), rhs = Expression(83, Add) +- expression 82 operands: lhs = Counter(7), rhs = Counter(8) +- expression 83 operands: lhs = Counter(9), rhs = Counter(10) +Number of file 0 mappings: 82 - Code(Counter(0)) at (prev + 3, 1) to (start + 0, 10) - Code(Counter(0)) at (prev + 1, 9) to (start + 0, 22) - Code(Counter(0)) at (prev + 0, 25) to (start + 0, 26) @@ -172,18 +169,18 @@ Number of file 0 mappings: 83 - Code(Expression(38, Sub)) at (prev + 2, 13) to (start + 0, 19) = ((c3 + c4) - (c5 + c6)) - Code(Zero) at (prev + 2, 5) to (start + 0, 6) -- Code(Expression(70, Add)) at (prev + 2, 9) to (start + 0, 22) +- Code(Expression(67, Add)) at (prev + 2, 9) to (start + 0, 22) = (c5 + c6) -- Code(Expression(70, Add)) at (prev + 0, 25) to (start + 0, 26) +- Code(Expression(67, Add)) at (prev + 0, 25) to (start + 0, 26) = (c5 + c6) -- Code(Expression(70, Add)) at (prev + 1, 8) to (start + 0, 12) +- Code(Expression(67, Add)) at (prev + 1, 8) to (start + 0, 12) = (c5 + c6) -- Code(Expression(70, Add)) at (prev + 0, 13) to (start + 2, 6) +- Code(Expression(67, Add)) at (prev + 0, 13) to (start + 2, 6) = (c5 + c6) - Code(Zero) at (prev + 2, 5) to (start + 0, 6) -- Code(Expression(85, Add)) at (prev + 2, 9) to (start + 0, 10) +- Code(Expression(82, Add)) at (prev + 2, 9) to (start + 0, 10) = (c7 + c8) -- Code(Expression(70, Add)) at (prev + 0, 16) to (start + 0, 29) +- Code(Expression(67, Add)) at (prev + 0, 16) to (start + 0, 29) = (c5 + c6) - Code(Counter(7)) at (prev + 0, 30) to (start + 2, 6) - Code(Expression(47, Sub)) at (prev + 2, 15) to (start + 0, 28) @@ -198,34 +195,32 @@ Number of file 0 mappings: 83 - Code(Expression(54, Sub)) at (prev + 2, 9) to (start + 0, 10) = (c8 - ((c14 + c15) + c16)) - Code(Counter(8)) at (prev + 1, 9) to (start + 0, 23) -- Code(Expression(69, Sub)) at (prev + 2, 13) to (start + 0, 32) +- Code(Expression(66, Sub)) at (prev + 2, 13) to (start + 0, 32) = ((c5 + c6) - (c7 + c8)) -- Code(Expression(69, Sub)) at (prev + 0, 35) to (start + 0, 44) +- Code(Expression(66, Sub)) at (prev + 0, 35) to (start + 0, 44) = ((c5 + c6) - (c7 + c8)) -- Code(Expression(69, Sub)) at (prev + 1, 9) to (start + 0, 17) +- Code(Expression(66, Sub)) at (prev + 1, 9) to (start + 0, 17) = ((c5 + c6) - (c7 + c8)) -- Code(Expression(69, Sub)) at (prev + 0, 18) to (start + 0, 27) +- Code(Expression(66, Sub)) at (prev + 1, 9) to (start + 0, 15) = ((c5 + c6) - (c7 + c8)) -- Code(Expression(69, Sub)) at (prev + 1, 9) to (start + 0, 15) - = ((c5 + c6) - (c7 + c8)) -- Code(Expression(86, Add)) at (prev + 3, 9) to (start + 0, 10) +- Code(Expression(83, Add)) at (prev + 3, 9) to (start + 0, 10) = (c9 + c10) -- Code(Expression(85, Add)) at (prev + 0, 16) to (start + 0, 29) +- Code(Expression(82, Add)) at (prev + 0, 16) to (start + 0, 29) = (c7 + c8) - Code(Counter(9)) at (prev + 0, 30) to (start + 2, 6) -- Code(Expression(74, Sub)) at (prev + 2, 15) to (start + 0, 28) +- Code(Expression(71, Sub)) at (prev + 2, 15) to (start + 0, 28) = ((c7 + c8) - c9) - Code(Counter(10)) at (prev + 1, 12) to (start + 0, 25) -- Code(Expression(76, Sub)) at (prev + 0, 29) to (start + 0, 42) +- Code(Expression(73, Sub)) at (prev + 0, 29) to (start + 0, 42) = (c10 - c11) -- Code(Expression(77, Sub)) at (prev + 0, 46) to (start + 0, 60) +- Code(Expression(74, Sub)) at (prev + 0, 46) to (start + 0, 60) = (c10 - (c11 + c12)) -- Code(Expression(82, Add)) at (prev + 0, 61) to (start + 2, 10) +- Code(Expression(79, Add)) at (prev + 0, 61) to (start + 2, 10) = ((c11 + c12) + c13) -- Code(Expression(81, Sub)) at (prev + 2, 9) to (start + 0, 10) +- Code(Expression(78, Sub)) at (prev + 2, 9) to (start + 0, 10) = (c10 - ((c11 + c12) + c13)) - Code(Counter(10)) at (prev + 1, 9) to (start + 0, 23) -- Code(Expression(84, Sub)) at (prev + 2, 9) to (start + 0, 15) +- Code(Expression(81, Sub)) at (prev + 2, 9) to (start + 0, 15) = ((c7 + c8) - (c9 + c10)) - Code(Counter(0)) at (prev + 2, 1) to (start + 0, 2) Highest counter ID seen: c10 diff --git a/tests/coverage/coverage_attr_closure.cov-map b/tests/coverage/coverage_attr_closure.cov-map index deba65f22cca2..aea805df303ea 100644 --- a/tests/coverage/coverage_attr_closure.cov-map +++ b/tests/coverage/coverage_attr_closure.cov-map @@ -1,24 +1,22 @@ Function name: coverage_attr_closure::GLOBAL_CLOSURE_ON::{closure#0} -Raw bytes (24): 0x[01, 01, 00, 04, 01, 06, 0f, 00, 10, 01, 01, 05, 00, 0d, 01, 00, 0e, 00, 17, 01, 01, 01, 00, 02] +Raw bytes (19): 0x[01, 01, 00, 03, 01, 06, 0f, 00, 10, 01, 01, 05, 00, 0d, 01, 01, 01, 00, 02] Number of files: 1 - file 0 => $DIR/coverage_attr_closure.rs Number of expressions: 0 -Number of file 0 mappings: 4 +Number of file 0 mappings: 3 - Code(Counter(0)) at (prev + 6, 15) to (start + 0, 16) - Code(Counter(0)) at (prev + 1, 5) to (start + 0, 13) -- Code(Counter(0)) at (prev + 0, 14) to (start + 0, 23) - Code(Counter(0)) at (prev + 1, 1) to (start + 0, 2) Highest counter ID seen: c0 Function name: coverage_attr_closure::contains_closures_off::{closure#0} (unused) -Raw bytes (24): 0x[01, 01, 00, 04, 00, 1d, 13, 00, 14, 00, 01, 09, 00, 11, 00, 00, 12, 00, 1b, 00, 01, 05, 00, 06] +Raw bytes (19): 0x[01, 01, 00, 03, 00, 1d, 13, 00, 14, 00, 01, 09, 00, 11, 00, 01, 05, 00, 06] Number of files: 1 - file 0 => $DIR/coverage_attr_closure.rs Number of expressions: 0 -Number of file 0 mappings: 4 +Number of file 0 mappings: 3 - Code(Zero) at (prev + 29, 19) to (start + 0, 20) - Code(Zero) at (prev + 1, 9) to (start + 0, 17) -- Code(Zero) at (prev + 0, 18) to (start + 0, 27) - Code(Zero) at (prev + 1, 5) to (start + 0, 6) Highest counter ID seen: (none) @@ -35,14 +33,13 @@ Number of file 0 mappings: 4 Highest counter ID seen: c0 Function name: coverage_attr_closure::contains_closures_on::{closure#0} (unused) -Raw bytes (24): 0x[01, 01, 00, 04, 00, 11, 13, 00, 14, 00, 01, 09, 00, 11, 00, 00, 12, 00, 1b, 00, 01, 05, 00, 06] +Raw bytes (19): 0x[01, 01, 00, 03, 00, 11, 13, 00, 14, 00, 01, 09, 00, 11, 00, 01, 05, 00, 06] Number of files: 1 - file 0 => $DIR/coverage_attr_closure.rs Number of expressions: 0 -Number of file 0 mappings: 4 +Number of file 0 mappings: 3 - Code(Zero) at (prev + 17, 19) to (start + 0, 20) - Code(Zero) at (prev + 1, 9) to (start + 0, 17) -- Code(Zero) at (prev + 0, 18) to (start + 0, 27) - Code(Zero) at (prev + 1, 5) to (start + 0, 6) Highest counter ID seen: (none) diff --git a/tests/coverage/drop_trait.cov-map b/tests/coverage/drop_trait.cov-map index dcf9dbd8c6478..b4a1499d5f95f 100644 --- a/tests/coverage/drop_trait.cov-map +++ b/tests/coverage/drop_trait.cov-map @@ -1,21 +1,20 @@ Function name: ::drop -Raw bytes (24): 0x[01, 01, 00, 04, 01, 09, 05, 00, 17, 01, 01, 09, 00, 11, 01, 00, 12, 00, 24, 01, 01, 05, 00, 06] +Raw bytes (19): 0x[01, 01, 00, 03, 01, 09, 05, 00, 17, 01, 01, 09, 00, 11, 01, 01, 05, 00, 06] Number of files: 1 - file 0 => $DIR/drop_trait.rs Number of expressions: 0 -Number of file 0 mappings: 4 +Number of file 0 mappings: 3 - Code(Counter(0)) at (prev + 9, 5) to (start + 0, 23) - Code(Counter(0)) at (prev + 1, 9) to (start + 0, 17) -- Code(Counter(0)) at (prev + 0, 18) to (start + 0, 36) - Code(Counter(0)) at (prev + 1, 5) to (start + 0, 6) Highest counter ID seen: c0 Function name: drop_trait::main -Raw bytes (69): 0x[01, 01, 00, 0d, 01, 0e, 01, 00, 1c, 01, 01, 09, 00, 15, 01, 00, 18, 00, 30, 01, 02, 09, 00, 0d, 01, 00, 10, 00, 2a, 01, 02, 08, 00, 0c, 01, 01, 09, 00, 11, 01, 00, 12, 00, 29, 01, 01, 10, 00, 16, 00, 01, 05, 00, 06, 00, 02, 0d, 00, 28, 00, 02, 05, 00, 0b, 01, 01, 01, 00, 02] +Raw bytes (64): 0x[01, 01, 00, 0c, 01, 0e, 01, 00, 1c, 01, 01, 09, 00, 15, 01, 00, 18, 00, 30, 01, 02, 09, 00, 0d, 01, 00, 10, 00, 2a, 01, 02, 08, 00, 0c, 01, 01, 09, 00, 11, 01, 01, 10, 00, 16, 00, 01, 05, 00, 06, 00, 02, 0d, 00, 28, 00, 02, 05, 00, 0b, 01, 01, 01, 00, 02] Number of files: 1 - file 0 => $DIR/drop_trait.rs Number of expressions: 0 -Number of file 0 mappings: 13 +Number of file 0 mappings: 12 - Code(Counter(0)) at (prev + 14, 1) to (start + 0, 28) - Code(Counter(0)) at (prev + 1, 9) to (start + 0, 21) - Code(Counter(0)) at (prev + 0, 24) to (start + 0, 48) @@ -23,7 +22,6 @@ Number of file 0 mappings: 13 - Code(Counter(0)) at (prev + 0, 16) to (start + 0, 42) - Code(Counter(0)) at (prev + 2, 8) to (start + 0, 12) - Code(Counter(0)) at (prev + 1, 9) to (start + 0, 17) -- Code(Counter(0)) at (prev + 0, 18) to (start + 0, 41) - Code(Counter(0)) at (prev + 1, 16) to (start + 0, 22) - Code(Zero) at (prev + 1, 5) to (start + 0, 6) - Code(Zero) at (prev + 2, 13) to (start + 0, 40) diff --git a/tests/coverage/generics.cov-map b/tests/coverage/generics.cov-map index 7f9b7ee0f4718..0d9cf9a1449b3 100644 --- a/tests/coverage/generics.cov-map +++ b/tests/coverage/generics.cov-map @@ -1,12 +1,11 @@ Function name: as core::ops::drop::Drop>::drop -Raw bytes (24): 0x[01, 01, 00, 04, 01, 11, 05, 00, 17, 01, 01, 09, 00, 11, 01, 00, 12, 00, 24, 01, 01, 05, 00, 06] +Raw bytes (19): 0x[01, 01, 00, 03, 01, 11, 05, 00, 17, 01, 01, 09, 00, 11, 01, 01, 05, 00, 06] Number of files: 1 - file 0 => $DIR/generics.rs Number of expressions: 0 -Number of file 0 mappings: 4 +Number of file 0 mappings: 3 - Code(Counter(0)) at (prev + 17, 5) to (start + 0, 23) - Code(Counter(0)) at (prev + 1, 9) to (start + 0, 17) -- Code(Counter(0)) at (prev + 0, 18) to (start + 0, 36) - Code(Counter(0)) at (prev + 1, 5) to (start + 0, 6) Highest counter ID seen: c0 @@ -22,14 +21,13 @@ Number of file 0 mappings: 3 Highest counter ID seen: c0 Function name: as core::ops::drop::Drop>::drop -Raw bytes (24): 0x[01, 01, 00, 04, 01, 11, 05, 00, 17, 01, 01, 09, 00, 11, 01, 00, 12, 00, 24, 01, 01, 05, 00, 06] +Raw bytes (19): 0x[01, 01, 00, 03, 01, 11, 05, 00, 17, 01, 01, 09, 00, 11, 01, 01, 05, 00, 06] Number of files: 1 - file 0 => $DIR/generics.rs Number of expressions: 0 -Number of file 0 mappings: 4 +Number of file 0 mappings: 3 - Code(Counter(0)) at (prev + 17, 5) to (start + 0, 23) - Code(Counter(0)) at (prev + 1, 9) to (start + 0, 17) -- Code(Counter(0)) at (prev + 0, 18) to (start + 0, 36) - Code(Counter(0)) at (prev + 1, 5) to (start + 0, 6) Highest counter ID seen: c0 @@ -45,11 +43,11 @@ Number of file 0 mappings: 3 Highest counter ID seen: c0 Function name: generics::main -Raw bytes (99): 0x[01, 01, 00, 13, 01, 16, 01, 00, 1c, 01, 01, 09, 00, 18, 01, 00, 1b, 00, 33, 01, 01, 05, 00, 10, 01, 00, 11, 00, 1d, 01, 02, 09, 00, 10, 01, 00, 13, 00, 2f, 01, 01, 05, 00, 08, 01, 00, 09, 00, 15, 01, 01, 05, 00, 08, 01, 00, 09, 00, 15, 01, 02, 08, 00, 0c, 01, 01, 09, 00, 11, 01, 00, 12, 00, 29, 01, 01, 10, 00, 16, 00, 01, 05, 00, 06, 00, 02, 0d, 00, 28, 00, 02, 05, 00, 0b, 01, 01, 01, 00, 02] +Raw bytes (94): 0x[01, 01, 00, 12, 01, 16, 01, 00, 1c, 01, 01, 09, 00, 18, 01, 00, 1b, 00, 33, 01, 01, 05, 00, 10, 01, 00, 11, 00, 1d, 01, 02, 09, 00, 10, 01, 00, 13, 00, 2f, 01, 01, 05, 00, 08, 01, 00, 09, 00, 15, 01, 01, 05, 00, 08, 01, 00, 09, 00, 15, 01, 02, 08, 00, 0c, 01, 01, 09, 00, 11, 01, 01, 10, 00, 16, 00, 01, 05, 00, 06, 00, 02, 0d, 00, 28, 00, 02, 05, 00, 0b, 01, 01, 01, 00, 02] Number of files: 1 - file 0 => $DIR/generics.rs Number of expressions: 0 -Number of file 0 mappings: 19 +Number of file 0 mappings: 18 - Code(Counter(0)) at (prev + 22, 1) to (start + 0, 28) - Code(Counter(0)) at (prev + 1, 9) to (start + 0, 24) - Code(Counter(0)) at (prev + 0, 27) to (start + 0, 51) @@ -63,7 +61,6 @@ Number of file 0 mappings: 19 - Code(Counter(0)) at (prev + 0, 9) to (start + 0, 21) - Code(Counter(0)) at (prev + 2, 8) to (start + 0, 12) - Code(Counter(0)) at (prev + 1, 9) to (start + 0, 17) -- Code(Counter(0)) at (prev + 0, 18) to (start + 0, 41) - Code(Counter(0)) at (prev + 1, 16) to (start + 0, 22) - Code(Zero) at (prev + 1, 5) to (start + 0, 6) - Code(Zero) at (prev + 2, 13) to (start + 0, 40) diff --git a/tests/coverage/inline-dead.cov-map b/tests/coverage/inline-dead.cov-map index 95a5f6bf68b72..c461b3a6eedcc 100644 --- a/tests/coverage/inline-dead.cov-map +++ b/tests/coverage/inline-dead.cov-map @@ -25,14 +25,13 @@ Number of file 0 mappings: 5 Highest counter ID seen: c1 Function name: inline_dead::main -Raw bytes (39): 0x[01, 01, 00, 07, 01, 04, 01, 00, 0a, 01, 01, 05, 00, 0d, 01, 00, 0e, 00, 12, 01, 00, 14, 00, 21, 01, 02, 09, 00, 0a, 01, 03, 05, 00, 0d, 01, 01, 01, 00, 02] +Raw bytes (34): 0x[01, 01, 00, 06, 01, 04, 01, 00, 0a, 01, 01, 05, 00, 0d, 01, 00, 14, 00, 21, 01, 02, 09, 00, 0a, 01, 03, 05, 00, 0d, 01, 01, 01, 00, 02] Number of files: 1 - file 0 => $DIR/inline-dead.rs Number of expressions: 0 -Number of file 0 mappings: 7 +Number of file 0 mappings: 6 - Code(Counter(0)) at (prev + 4, 1) to (start + 0, 10) - Code(Counter(0)) at (prev + 1, 5) to (start + 0, 13) -- Code(Counter(0)) at (prev + 0, 14) to (start + 0, 18) - Code(Counter(0)) at (prev + 0, 20) to (start + 0, 33) - Code(Counter(0)) at (prev + 2, 9) to (start + 0, 10) - Code(Counter(0)) at (prev + 3, 5) to (start + 0, 13) diff --git a/tests/coverage/inner_items.cov-map b/tests/coverage/inner_items.cov-map index ca6ddfda2ddf9..0e3ed47bbc67c 100644 --- a/tests/coverage/inner_items.cov-map +++ b/tests/coverage/inner_items.cov-map @@ -53,18 +53,17 @@ Number of file 0 mappings: 16 Highest counter ID seen: c2 Function name: inner_items::main::in_func -Raw bytes (44): 0x[01, 01, 00, 08, 01, 12, 05, 00, 17, 01, 01, 0d, 00, 0e, 01, 00, 11, 00, 12, 01, 01, 0d, 00, 0e, 01, 00, 11, 00, 16, 01, 01, 09, 00, 11, 01, 00, 12, 00, 1a, 01, 01, 05, 00, 06] +Raw bytes (39): 0x[01, 01, 00, 07, 01, 12, 05, 00, 17, 01, 01, 0d, 00, 0e, 01, 00, 11, 00, 12, 01, 01, 0d, 00, 0e, 01, 00, 11, 00, 16, 01, 01, 09, 00, 11, 01, 01, 05, 00, 06] Number of files: 1 - file 0 => $DIR/inner_items.rs Number of expressions: 0 -Number of file 0 mappings: 8 +Number of file 0 mappings: 7 - Code(Counter(0)) at (prev + 18, 5) to (start + 0, 23) - Code(Counter(0)) at (prev + 1, 13) to (start + 0, 14) - Code(Counter(0)) at (prev + 0, 17) to (start + 0, 18) - Code(Counter(0)) at (prev + 1, 13) to (start + 0, 14) - Code(Counter(0)) at (prev + 0, 17) to (start + 0, 22) - Code(Counter(0)) at (prev + 1, 9) to (start + 0, 17) -- Code(Counter(0)) at (prev + 0, 18) to (start + 0, 26) - Code(Counter(0)) at (prev + 1, 5) to (start + 0, 6) Highest counter ID seen: c0 diff --git a/tests/coverage/issue-83601.cov-map b/tests/coverage/issue-83601.cov-map index e42b5591c0fb3..6d89397023c6f 100644 --- a/tests/coverage/issue-83601.cov-map +++ b/tests/coverage/issue-83601.cov-map @@ -1,9 +1,9 @@ Function name: issue_83601::main -Raw bytes (74): 0x[01, 01, 00, 0e, 01, 06, 01, 00, 0a, 01, 01, 09, 00, 0c, 01, 00, 0f, 00, 15, 01, 01, 05, 00, 0f, 01, 01, 09, 00, 0c, 01, 00, 0f, 00, 15, 01, 01, 05, 00, 0f, 01, 01, 05, 00, 0d, 01, 00, 0e, 00, 14, 01, 01, 05, 00, 0d, 01, 00, 0e, 00, 14, 01, 01, 05, 00, 0d, 01, 00, 0e, 00, 14, 01, 01, 01, 00, 02] +Raw bytes (59): 0x[01, 01, 00, 0b, 01, 06, 01, 00, 0a, 01, 01, 09, 00, 0c, 01, 00, 0f, 00, 15, 01, 01, 05, 00, 0f, 01, 01, 09, 00, 0c, 01, 00, 0f, 00, 15, 01, 01, 05, 00, 0f, 01, 01, 05, 00, 0d, 01, 01, 05, 00, 0d, 01, 01, 05, 00, 0d, 01, 01, 01, 00, 02] Number of files: 1 - file 0 => $DIR/issue-83601.rs Number of expressions: 0 -Number of file 0 mappings: 14 +Number of file 0 mappings: 11 - Code(Counter(0)) at (prev + 6, 1) to (start + 0, 10) - Code(Counter(0)) at (prev + 1, 9) to (start + 0, 12) - Code(Counter(0)) at (prev + 0, 15) to (start + 0, 21) @@ -12,11 +12,8 @@ Number of file 0 mappings: 14 - Code(Counter(0)) at (prev + 0, 15) to (start + 0, 21) - Code(Counter(0)) at (prev + 1, 5) to (start + 0, 15) - Code(Counter(0)) at (prev + 1, 5) to (start + 0, 13) -- Code(Counter(0)) at (prev + 0, 14) to (start + 0, 20) - Code(Counter(0)) at (prev + 1, 5) to (start + 0, 13) -- Code(Counter(0)) at (prev + 0, 14) to (start + 0, 20) - Code(Counter(0)) at (prev + 1, 5) to (start + 0, 13) -- Code(Counter(0)) at (prev + 0, 14) to (start + 0, 20) - Code(Counter(0)) at (prev + 1, 1) to (start + 0, 2) Highest counter ID seen: c0 diff --git a/tests/coverage/issue-84561.cov-map b/tests/coverage/issue-84561.cov-map index e5bb1afdcc263..ca009260cddc9 100644 --- a/tests/coverage/issue-84561.cov-map +++ b/tests/coverage/issue-84561.cov-map @@ -1,14 +1,13 @@ Function name: ::fmt -Raw bytes (42): 0x[01, 01, 01, 01, 05, 07, 01, 8a, 01, 05, 00, 43, 01, 01, 09, 00, 0f, 01, 00, 10, 00, 11, 01, 00, 13, 00, 24, 05, 00, 25, 00, 26, 02, 01, 09, 00, 0f, 01, 01, 05, 00, 06] +Raw bytes (37): 0x[01, 01, 01, 01, 05, 06, 01, 8a, 01, 05, 00, 43, 01, 01, 09, 00, 0f, 01, 00, 10, 00, 11, 05, 00, 25, 00, 26, 02, 01, 09, 00, 0f, 01, 01, 05, 00, 06] Number of files: 1 - file 0 => $DIR/issue-84561.rs Number of expressions: 1 - expression 0 operands: lhs = Counter(0), rhs = Counter(1) -Number of file 0 mappings: 7 +Number of file 0 mappings: 6 - Code(Counter(0)) at (prev + 138, 5) to (start + 0, 67) - Code(Counter(0)) at (prev + 1, 9) to (start + 0, 15) - Code(Counter(0)) at (prev + 0, 16) to (start + 0, 17) -- Code(Counter(0)) at (prev + 0, 19) to (start + 0, 36) - Code(Counter(1)) at (prev + 0, 37) to (start + 0, 38) - Code(Expression(0, Sub)) at (prev + 1, 9) to (start + 0, 15) = (c0 - c1) @@ -29,54 +28,48 @@ Number of file 0 mappings: 5 Highest counter ID seen: c0 Function name: issue_84561::test1 -Raw bytes (65): 0x[01, 01, 00, 0c, 01, 9a, 01, 01, 00, 0b, 01, 01, 05, 00, 0b, 05, 00, 0c, 00, 1e, 01, 01, 05, 00, 0b, 09, 00, 0c, 00, 1e, 01, 01, 0d, 00, 0e, 01, 01, 05, 00, 0b, 0d, 00, 0c, 00, 1e, 01, 01, 05, 02, 06, 01, 03, 05, 00, 0b, 11, 00, 0c, 00, 1e, 01, 01, 01, 00, 02] +Raw bytes (45): 0x[01, 01, 00, 08, 01, 9a, 01, 01, 00, 0b, 01, 01, 05, 00, 0b, 01, 01, 05, 00, 0b, 01, 01, 0d, 00, 0e, 01, 01, 05, 00, 0b, 01, 01, 05, 02, 06, 01, 03, 05, 00, 0b, 01, 01, 01, 00, 02] Number of files: 1 - file 0 => $DIR/issue-84561.rs Number of expressions: 0 -Number of file 0 mappings: 12 +Number of file 0 mappings: 8 - Code(Counter(0)) at (prev + 154, 1) to (start + 0, 11) - Code(Counter(0)) at (prev + 1, 5) to (start + 0, 11) -- Code(Counter(1)) at (prev + 0, 12) to (start + 0, 30) - Code(Counter(0)) at (prev + 1, 5) to (start + 0, 11) -- Code(Counter(2)) at (prev + 0, 12) to (start + 0, 30) - Code(Counter(0)) at (prev + 1, 13) to (start + 0, 14) - Code(Counter(0)) at (prev + 1, 5) to (start + 0, 11) -- Code(Counter(3)) at (prev + 0, 12) to (start + 0, 30) - Code(Counter(0)) at (prev + 1, 5) to (start + 2, 6) - Code(Counter(0)) at (prev + 3, 5) to (start + 0, 11) -- Code(Counter(4)) at (prev + 0, 12) to (start + 0, 30) - Code(Counter(0)) at (prev + 1, 1) to (start + 0, 2) -Highest counter ID seen: c4 +Highest counter ID seen: c0 Function name: issue_84561::test2 -Raw bytes (25): 0x[01, 01, 00, 04, 01, b0, 01, 01, 00, 0b, 01, 01, 05, 00, 10, 05, 00, 11, 00, 23, 01, 01, 01, 00, 02] +Raw bytes (20): 0x[01, 01, 00, 03, 01, b0, 01, 01, 00, 0b, 01, 01, 05, 00, 10, 01, 01, 01, 00, 02] Number of files: 1 - file 0 => $DIR/issue-84561.rs Number of expressions: 0 -Number of file 0 mappings: 4 +Number of file 0 mappings: 3 - Code(Counter(0)) at (prev + 176, 1) to (start + 0, 11) - Code(Counter(0)) at (prev + 1, 5) to (start + 0, 16) -- Code(Counter(1)) at (prev + 0, 17) to (start + 0, 35) - Code(Counter(0)) at (prev + 1, 1) to (start + 0, 2) -Highest counter ID seen: c1 +Highest counter ID seen: c0 Function name: issue_84561::test2::call_print -Raw bytes (25): 0x[01, 01, 00, 04, 01, a7, 01, 09, 00, 1f, 01, 01, 0d, 00, 13, 01, 00, 14, 00, 18, 01, 01, 09, 00, 0a] +Raw bytes (20): 0x[01, 01, 00, 03, 01, a7, 01, 09, 00, 1f, 01, 01, 0d, 00, 13, 01, 01, 09, 00, 0a] Number of files: 1 - file 0 => $DIR/issue-84561.rs Number of expressions: 0 -Number of file 0 mappings: 4 +Number of file 0 mappings: 3 - Code(Counter(0)) at (prev + 167, 9) to (start + 0, 31) - Code(Counter(0)) at (prev + 1, 13) to (start + 0, 19) -- Code(Counter(0)) at (prev + 0, 20) to (start + 0, 24) - Code(Counter(0)) at (prev + 1, 9) to (start + 0, 10) Highest counter ID seen: c0 Function name: issue_84561::test3 -Raw bytes (409): 0x[01, 01, 0a, 01, 05, 01, 09, 01, 0d, 11, 15, 1d, 21, 19, 1d, 19, 1d, 19, 1d, 27, 25, 1d, 21, 4d, 01, 08, 01, 00, 0b, 01, 01, 09, 00, 10, 01, 00, 13, 00, 2e, 01, 01, 09, 00, 0c, 01, 00, 0f, 00, 15, 01, 01, 05, 00, 0f, 01, 01, 09, 00, 0c, 01, 00, 0f, 00, 15, 01, 01, 05, 00, 0f, 01, 01, 05, 00, 0d, 01, 00, 0e, 00, 14, 01, 01, 05, 00, 0d, 01, 00, 0e, 00, 14, 01, 01, 05, 00, 0d, 01, 00, 0e, 00, 14, 01, 02, 05, 00, 0f, 01, 01, 05, 00, 0f, 01, 01, 05, 00, 0f, 01, 01, 09, 00, 0c, 01, 00, 0f, 00, 15, 01, 01, 05, 00, 0f, 01, 01, 05, 00, 0f, 01, 01, 05, 00, 0f, 00, 00, 20, 00, 30, 01, 01, 05, 00, 0d, 01, 00, 0e, 00, 14, 01, 01, 05, 00, 0d, 01, 00, 0e, 00, 14, 01, 02, 05, 00, 0f, 00, 00, 20, 00, 24, 00, 00, 29, 00, 30, 00, 00, 33, 00, 41, 00, 00, 4b, 00, 5a, 01, 01, 05, 00, 0f, 00, 05, 09, 00, 0d, 00, 03, 09, 00, 10, 00, 02, 0d, 00, 1b, 00, 02, 0d, 00, 1c, 01, 04, 09, 00, 10, 01, 00, 13, 00, 2e, 01, 02, 05, 00, 0f, 01, 04, 05, 00, 0f, 01, 04, 05, 00, 0f, 01, 04, 09, 00, 0c, 01, 00, 0f, 00, 15, 01, 01, 05, 00, 0f, 01, 04, 08, 00, 0f, 05, 01, 09, 00, 13, 02, 05, 09, 00, 13, 01, 05, 08, 00, 0f, 09, 01, 09, 00, 13, 00, 03, 0d, 00, 1d, 06, 03, 09, 00, 13, 00, 03, 0d, 00, 1d, 01, 03, 05, 00, 0f, 01, 01, 0c, 00, 13, 0d, 01, 0d, 00, 13, 0a, 02, 0d, 00, 13, 11, 04, 05, 00, 0f, 11, 02, 0c, 00, 13, 15, 01, 0d, 00, 13, 0e, 02, 0d, 00, 13, 27, 03, 05, 00, 0f, 19, 01, 0c, 00, 13, 1d, 01, 0d, 00, 17, 1d, 04, 0d, 00, 13, 1e, 02, 0d, 00, 17, 1e, 01, 14, 00, 1b, 00, 01, 15, 00, 1b, 1e, 02, 15, 00, 1b, 21, 04, 0d, 00, 13, 22, 03, 09, 00, 19, 25, 02, 05, 00, 0f, 25, 03, 09, 00, 22, 00, 02, 05, 00, 0f, 00, 03, 09, 00, 2c, 00, 02, 01, 00, 02] +Raw bytes (340): 0x[01, 01, 08, 01, 05, 01, 09, 01, 0d, 11, 15, 1d, 21, 19, 1d, 19, 1d, 19, 1d, 40, 01, 08, 01, 00, 0b, 01, 01, 09, 00, 10, 01, 00, 13, 00, 2e, 01, 01, 09, 00, 0c, 01, 00, 0f, 00, 15, 01, 01, 05, 00, 0f, 01, 01, 09, 00, 0c, 01, 00, 0f, 00, 15, 01, 01, 05, 00, 0f, 01, 01, 05, 00, 0d, 01, 01, 05, 00, 0d, 01, 01, 05, 00, 0d, 01, 02, 05, 00, 0f, 01, 01, 05, 00, 0f, 01, 01, 05, 00, 0f, 01, 01, 09, 00, 0c, 01, 00, 0f, 00, 15, 01, 01, 05, 00, 0f, 01, 01, 05, 00, 0f, 01, 01, 05, 00, 0f, 01, 01, 05, 00, 0d, 01, 01, 05, 00, 0d, 01, 02, 05, 00, 0f, 00, 00, 29, 00, 30, 00, 00, 33, 00, 41, 00, 00, 4b, 00, 5a, 01, 01, 05, 00, 0f, 00, 08, 09, 00, 10, 00, 02, 0d, 00, 1b, 00, 02, 0d, 00, 1c, 01, 04, 09, 00, 10, 01, 00, 13, 00, 2e, 01, 02, 05, 00, 0f, 01, 04, 05, 00, 0f, 01, 04, 05, 00, 0f, 01, 04, 09, 00, 0c, 01, 00, 0f, 00, 15, 01, 01, 05, 00, 0f, 01, 04, 08, 00, 0f, 05, 01, 09, 00, 13, 02, 05, 09, 00, 13, 01, 05, 08, 00, 0f, 09, 01, 09, 00, 13, 06, 06, 09, 00, 13, 01, 06, 05, 00, 0f, 01, 01, 0c, 00, 13, 0d, 01, 0d, 00, 13, 0a, 02, 0d, 00, 13, 11, 04, 05, 00, 0f, 11, 02, 0c, 00, 13, 15, 01, 0d, 00, 13, 0e, 02, 0d, 00, 13, 13, 03, 05, 00, 0f, 19, 01, 0c, 00, 13, 1d, 01, 0d, 00, 17, 1d, 04, 0d, 00, 13, 1e, 02, 0d, 00, 17, 1e, 01, 14, 00, 1b, 00, 01, 15, 00, 1b, 1e, 02, 15, 00, 1b, 21, 04, 0d, 00, 13, 25, 05, 05, 00, 0f, 00, 05, 05, 00, 0f, 00, 05, 01, 00, 02] Number of files: 1 - file 0 => $DIR/issue-84561.rs -Number of expressions: 10 +Number of expressions: 8 - expression 0 operands: lhs = Counter(0), rhs = Counter(1) - expression 1 operands: lhs = Counter(0), rhs = Counter(2) - expression 2 operands: lhs = Counter(0), rhs = Counter(3) @@ -85,9 +78,7 @@ Number of expressions: 10 - expression 5 operands: lhs = Counter(6), rhs = Counter(7) - expression 6 operands: lhs = Counter(6), rhs = Counter(7) - expression 7 operands: lhs = Counter(6), rhs = Counter(7) -- expression 8 operands: lhs = Expression(9, Add), rhs = Counter(9) -- expression 9 operands: lhs = Counter(7), rhs = Counter(8) -Number of file 0 mappings: 77 +Number of file 0 mappings: 64 - Code(Counter(0)) at (prev + 8, 1) to (start + 0, 11) - Code(Counter(0)) at (prev + 1, 9) to (start + 0, 16) - Code(Counter(0)) at (prev + 0, 19) to (start + 0, 46) @@ -98,11 +89,8 @@ Number of file 0 mappings: 77 - Code(Counter(0)) at (prev + 0, 15) to (start + 0, 21) - Code(Counter(0)) at (prev + 1, 5) to (start + 0, 15) - Code(Counter(0)) at (prev + 1, 5) to (start + 0, 13) -- Code(Counter(0)) at (prev + 0, 14) to (start + 0, 20) - Code(Counter(0)) at (prev + 1, 5) to (start + 0, 13) -- Code(Counter(0)) at (prev + 0, 14) to (start + 0, 20) - Code(Counter(0)) at (prev + 1, 5) to (start + 0, 13) -- Code(Counter(0)) at (prev + 0, 14) to (start + 0, 20) - Code(Counter(0)) at (prev + 2, 5) to (start + 0, 15) - Code(Counter(0)) at (prev + 1, 5) to (start + 0, 15) - Code(Counter(0)) at (prev + 1, 5) to (start + 0, 15) @@ -111,19 +99,14 @@ Number of file 0 mappings: 77 - Code(Counter(0)) at (prev + 1, 5) to (start + 0, 15) - Code(Counter(0)) at (prev + 1, 5) to (start + 0, 15) - Code(Counter(0)) at (prev + 1, 5) to (start + 0, 15) -- Code(Zero) at (prev + 0, 32) to (start + 0, 48) - Code(Counter(0)) at (prev + 1, 5) to (start + 0, 13) -- Code(Counter(0)) at (prev + 0, 14) to (start + 0, 20) - Code(Counter(0)) at (prev + 1, 5) to (start + 0, 13) -- Code(Counter(0)) at (prev + 0, 14) to (start + 0, 20) - Code(Counter(0)) at (prev + 2, 5) to (start + 0, 15) -- Code(Zero) at (prev + 0, 32) to (start + 0, 36) - Code(Zero) at (prev + 0, 41) to (start + 0, 48) - Code(Zero) at (prev + 0, 51) to (start + 0, 65) - Code(Zero) at (prev + 0, 75) to (start + 0, 90) - Code(Counter(0)) at (prev + 1, 5) to (start + 0, 15) -- Code(Zero) at (prev + 5, 9) to (start + 0, 13) -- Code(Zero) at (prev + 3, 9) to (start + 0, 16) +- Code(Zero) at (prev + 8, 9) to (start + 0, 16) - Code(Zero) at (prev + 2, 13) to (start + 0, 27) - Code(Zero) at (prev + 2, 13) to (start + 0, 28) - Code(Counter(0)) at (prev + 4, 9) to (start + 0, 16) @@ -140,11 +123,9 @@ Number of file 0 mappings: 77 = (c0 - c1) - Code(Counter(0)) at (prev + 5, 8) to (start + 0, 15) - Code(Counter(2)) at (prev + 1, 9) to (start + 0, 19) -- Code(Zero) at (prev + 3, 13) to (start + 0, 29) -- Code(Expression(1, Sub)) at (prev + 3, 9) to (start + 0, 19) +- Code(Expression(1, Sub)) at (prev + 6, 9) to (start + 0, 19) = (c0 - c2) -- Code(Zero) at (prev + 3, 13) to (start + 0, 29) -- Code(Counter(0)) at (prev + 3, 5) to (start + 0, 15) +- Code(Counter(0)) at (prev + 6, 5) to (start + 0, 15) - Code(Counter(0)) at (prev + 1, 12) to (start + 0, 19) - Code(Counter(3)) at (prev + 1, 13) to (start + 0, 19) - Code(Expression(2, Sub)) at (prev + 2, 13) to (start + 0, 19) @@ -154,7 +135,7 @@ Number of file 0 mappings: 77 - Code(Counter(5)) at (prev + 1, 13) to (start + 0, 19) - Code(Expression(3, Sub)) at (prev + 2, 13) to (start + 0, 19) = (c4 - c5) -- Code(Expression(9, Add)) at (prev + 3, 5) to (start + 0, 15) +- Code(Expression(4, Add)) at (prev + 3, 5) to (start + 0, 15) = (c7 + c8) - Code(Counter(6)) at (prev + 1, 12) to (start + 0, 19) - Code(Counter(7)) at (prev + 1, 13) to (start + 0, 23) @@ -167,12 +148,8 @@ Number of file 0 mappings: 77 - Code(Expression(7, Sub)) at (prev + 2, 21) to (start + 0, 27) = (c6 - c7) - Code(Counter(8)) at (prev + 4, 13) to (start + 0, 19) -- Code(Expression(8, Sub)) at (prev + 3, 9) to (start + 0, 25) - = ((c7 + c8) - c9) -- Code(Counter(9)) at (prev + 2, 5) to (start + 0, 15) -- Code(Counter(9)) at (prev + 3, 9) to (start + 0, 34) -- Code(Zero) at (prev + 2, 5) to (start + 0, 15) -- Code(Zero) at (prev + 3, 9) to (start + 0, 44) -- Code(Zero) at (prev + 2, 1) to (start + 0, 2) +- Code(Counter(9)) at (prev + 5, 5) to (start + 0, 15) +- Code(Zero) at (prev + 5, 5) to (start + 0, 15) +- Code(Zero) at (prev + 5, 1) to (start + 0, 2) Highest counter ID seen: c9 diff --git a/tests/coverage/loops_branches.cov-map b/tests/coverage/loops_branches.cov-map index 78fdaa53f46f1..35a5f2b916883 100644 --- a/tests/coverage/loops_branches.cov-map +++ b/tests/coverage/loops_branches.cov-map @@ -1,5 +1,5 @@ Function name: ::fmt -Raw bytes (137): 0x[01, 01, 04, 07, 0b, 01, 0d, 05, 09, 09, 0d, 19, 01, 09, 05, 00, 43, 01, 01, 0c, 00, 10, 01, 01, 10, 00, 15, 00, 01, 17, 00, 1b, 00, 00, 1c, 00, 1e, 01, 01, 0d, 00, 0e, 01, 01, 0d, 00, 13, 01, 00, 14, 00, 15, 01, 00, 17, 00, 1d, 05, 00, 1e, 00, 1f, 00, 01, 10, 01, 0a, 0d, 03, 0d, 00, 0e, 09, 00, 12, 00, 17, 0d, 01, 10, 00, 14, 0d, 01, 14, 00, 19, 00, 01, 1b, 00, 1f, 00, 00, 20, 00, 22, 0d, 01, 11, 00, 12, 0d, 01, 11, 00, 17, 0d, 00, 18, 00, 19, 0d, 00, 1b, 00, 21, 02, 00, 22, 00, 23, 00, 01, 14, 01, 0e, 0e, 03, 09, 00, 0f, 01, 01, 05, 00, 06] +Raw bytes (127): 0x[01, 01, 04, 07, 0b, 01, 0d, 05, 09, 09, 0d, 17, 01, 09, 05, 00, 43, 01, 01, 0c, 00, 10, 01, 01, 10, 00, 15, 00, 01, 17, 00, 1b, 00, 00, 1c, 00, 1e, 01, 01, 0d, 00, 0e, 01, 01, 0d, 00, 13, 01, 00, 14, 00, 15, 05, 00, 1e, 00, 1f, 00, 01, 10, 01, 0a, 0d, 03, 0d, 00, 0e, 09, 00, 12, 00, 17, 0d, 01, 10, 00, 14, 0d, 01, 14, 00, 19, 00, 01, 1b, 00, 1f, 00, 00, 20, 00, 22, 0d, 01, 11, 00, 12, 0d, 01, 11, 00, 17, 0d, 00, 18, 00, 19, 02, 00, 22, 00, 23, 00, 01, 14, 01, 0e, 0e, 03, 09, 00, 0f, 01, 01, 05, 00, 06] Number of files: 1 - file 0 => $DIR/loops_branches.rs Number of expressions: 4 @@ -7,7 +7,7 @@ Number of expressions: 4 - expression 1 operands: lhs = Counter(0), rhs = Counter(3) - expression 2 operands: lhs = Counter(1), rhs = Counter(2) - expression 3 operands: lhs = Counter(2), rhs = Counter(3) -Number of file 0 mappings: 25 +Number of file 0 mappings: 23 - Code(Counter(0)) at (prev + 9, 5) to (start + 0, 67) - Code(Counter(0)) at (prev + 1, 12) to (start + 0, 16) - Code(Counter(0)) at (prev + 1, 16) to (start + 0, 21) @@ -16,7 +16,6 @@ Number of file 0 mappings: 25 - Code(Counter(0)) at (prev + 1, 13) to (start + 0, 14) - Code(Counter(0)) at (prev + 1, 13) to (start + 0, 19) - Code(Counter(0)) at (prev + 0, 20) to (start + 0, 21) -- Code(Counter(0)) at (prev + 0, 23) to (start + 0, 29) - Code(Counter(1)) at (prev + 0, 30) to (start + 0, 31) - Code(Zero) at (prev + 1, 16) to (start + 1, 10) - Code(Counter(3)) at (prev + 3, 13) to (start + 0, 14) @@ -28,7 +27,6 @@ Number of file 0 mappings: 25 - Code(Counter(3)) at (prev + 1, 17) to (start + 0, 18) - Code(Counter(3)) at (prev + 1, 17) to (start + 0, 23) - Code(Counter(3)) at (prev + 0, 24) to (start + 0, 25) -- Code(Counter(3)) at (prev + 0, 27) to (start + 0, 33) - Code(Expression(0, Sub)) at (prev + 0, 34) to (start + 0, 35) = ((c0 + c3) - (c1 + c2)) - Code(Zero) at (prev + 1, 20) to (start + 1, 14) @@ -38,7 +36,7 @@ Number of file 0 mappings: 25 Highest counter ID seen: c3 Function name: ::fmt -Raw bytes (137): 0x[01, 01, 04, 07, 0b, 01, 09, 05, 0d, 05, 09, 19, 01, 22, 05, 00, 43, 01, 01, 0c, 00, 11, 00, 00, 12, 01, 0a, 01, 02, 10, 00, 15, 00, 01, 17, 00, 1b, 00, 00, 1c, 00, 1e, 01, 01, 0d, 00, 0e, 01, 01, 0d, 00, 13, 01, 00, 14, 00, 15, 01, 00, 17, 00, 1d, 0d, 00, 1e, 00, 1f, 09, 02, 0d, 00, 0e, 05, 00, 12, 00, 17, 09, 01, 10, 00, 15, 00, 00, 16, 01, 0e, 09, 02, 14, 00, 19, 00, 01, 1b, 00, 1f, 00, 00, 20, 00, 22, 09, 01, 11, 00, 12, 09, 01, 11, 00, 17, 09, 00, 18, 00, 19, 09, 00, 1b, 00, 21, 02, 00, 22, 00, 23, 0e, 03, 09, 00, 0f, 01, 01, 05, 00, 06] +Raw bytes (127): 0x[01, 01, 04, 07, 0b, 01, 09, 05, 0d, 05, 09, 17, 01, 22, 05, 00, 43, 01, 01, 0c, 00, 11, 00, 00, 12, 01, 0a, 01, 02, 10, 00, 15, 00, 01, 17, 00, 1b, 00, 00, 1c, 00, 1e, 01, 01, 0d, 00, 0e, 01, 01, 0d, 00, 13, 01, 00, 14, 00, 15, 0d, 00, 1e, 00, 1f, 09, 02, 0d, 00, 0e, 05, 00, 12, 00, 17, 09, 01, 10, 00, 15, 00, 00, 16, 01, 0e, 09, 02, 14, 00, 19, 00, 01, 1b, 00, 1f, 00, 00, 20, 00, 22, 09, 01, 11, 00, 12, 09, 01, 11, 00, 17, 09, 00, 18, 00, 19, 02, 00, 22, 00, 23, 0e, 03, 09, 00, 0f, 01, 01, 05, 00, 06] Number of files: 1 - file 0 => $DIR/loops_branches.rs Number of expressions: 4 @@ -46,7 +44,7 @@ Number of expressions: 4 - expression 1 operands: lhs = Counter(0), rhs = Counter(2) - expression 2 operands: lhs = Counter(1), rhs = Counter(3) - expression 3 operands: lhs = Counter(1), rhs = Counter(2) -Number of file 0 mappings: 25 +Number of file 0 mappings: 23 - Code(Counter(0)) at (prev + 34, 5) to (start + 0, 67) - Code(Counter(0)) at (prev + 1, 12) to (start + 0, 17) - Code(Zero) at (prev + 0, 18) to (start + 1, 10) @@ -56,7 +54,6 @@ Number of file 0 mappings: 25 - Code(Counter(0)) at (prev + 1, 13) to (start + 0, 14) - Code(Counter(0)) at (prev + 1, 13) to (start + 0, 19) - Code(Counter(0)) at (prev + 0, 20) to (start + 0, 21) -- Code(Counter(0)) at (prev + 0, 23) to (start + 0, 29) - Code(Counter(3)) at (prev + 0, 30) to (start + 0, 31) - Code(Counter(2)) at (prev + 2, 13) to (start + 0, 14) - Code(Counter(1)) at (prev + 0, 18) to (start + 0, 23) @@ -68,7 +65,6 @@ Number of file 0 mappings: 25 - Code(Counter(2)) at (prev + 1, 17) to (start + 0, 18) - Code(Counter(2)) at (prev + 1, 17) to (start + 0, 23) - Code(Counter(2)) at (prev + 0, 24) to (start + 0, 25) -- Code(Counter(2)) at (prev + 0, 27) to (start + 0, 33) - Code(Expression(0, Sub)) at (prev + 0, 34) to (start + 0, 35) = ((c0 + c2) - (c1 + c3)) - Code(Expression(3, Sub)) at (prev + 3, 9) to (start + 0, 15) @@ -77,20 +73,18 @@ Number of file 0 mappings: 25 Highest counter ID seen: c3 Function name: loops_branches::main -Raw bytes (54): 0x[01, 01, 00, 0a, 01, 37, 01, 00, 0a, 01, 01, 09, 00, 13, 01, 00, 16, 00, 1f, 01, 01, 05, 00, 0d, 01, 00, 0e, 00, 14, 01, 01, 09, 00, 15, 01, 00, 18, 00, 23, 01, 01, 05, 00, 0d, 01, 00, 0e, 00, 12, 01, 01, 01, 00, 02] +Raw bytes (44): 0x[01, 01, 00, 08, 01, 37, 01, 00, 0a, 01, 01, 09, 00, 13, 01, 00, 16, 00, 1f, 01, 01, 05, 00, 0d, 01, 01, 09, 00, 15, 01, 00, 18, 00, 23, 01, 01, 05, 00, 0d, 01, 01, 01, 00, 02] Number of files: 1 - file 0 => $DIR/loops_branches.rs Number of expressions: 0 -Number of file 0 mappings: 10 +Number of file 0 mappings: 8 - Code(Counter(0)) at (prev + 55, 1) to (start + 0, 10) - Code(Counter(0)) at (prev + 1, 9) to (start + 0, 19) - Code(Counter(0)) at (prev + 0, 22) to (start + 0, 31) - Code(Counter(0)) at (prev + 1, 5) to (start + 0, 13) -- Code(Counter(0)) at (prev + 0, 14) to (start + 0, 20) - Code(Counter(0)) at (prev + 1, 9) to (start + 0, 21) - Code(Counter(0)) at (prev + 0, 24) to (start + 0, 35) - Code(Counter(0)) at (prev + 1, 5) to (start + 0, 13) -- Code(Counter(0)) at (prev + 0, 14) to (start + 0, 18) - Code(Counter(0)) at (prev + 1, 1) to (start + 0, 2) Highest counter ID seen: c0 diff --git a/tests/coverage/macro_in_closure.cov-map b/tests/coverage/macro_in_closure.cov-map index 3529d0c4c321b..1a3960196acd6 100644 --- a/tests/coverage/macro_in_closure.cov-map +++ b/tests/coverage/macro_in_closure.cov-map @@ -1,22 +1,20 @@ Function name: macro_in_closure::NO_BLOCK::{closure#0} -Raw bytes (14): 0x[01, 01, 00, 02, 01, 07, 1c, 00, 24, 01, 00, 25, 00, 2c] +Raw bytes (9): 0x[01, 01, 00, 01, 01, 07, 1c, 00, 24] Number of files: 1 - file 0 => $DIR/macro_in_closure.rs Number of expressions: 0 -Number of file 0 mappings: 2 +Number of file 0 mappings: 1 - Code(Counter(0)) at (prev + 7, 28) to (start + 0, 36) -- Code(Counter(0)) at (prev + 0, 37) to (start + 0, 44) Highest counter ID seen: c0 Function name: macro_in_closure::WITH_BLOCK::{closure#0} -Raw bytes (24): 0x[01, 01, 00, 04, 01, 09, 1e, 00, 1f, 01, 01, 05, 00, 0d, 01, 00, 0e, 00, 15, 01, 01, 01, 00, 02] +Raw bytes (19): 0x[01, 01, 00, 03, 01, 09, 1e, 00, 1f, 01, 01, 05, 00, 0d, 01, 01, 01, 00, 02] Number of files: 1 - file 0 => $DIR/macro_in_closure.rs Number of expressions: 0 -Number of file 0 mappings: 4 +Number of file 0 mappings: 3 - Code(Counter(0)) at (prev + 9, 30) to (start + 0, 31) - Code(Counter(0)) at (prev + 1, 5) to (start + 0, 13) -- Code(Counter(0)) at (prev + 0, 14) to (start + 0, 21) - Code(Counter(0)) at (prev + 1, 1) to (start + 0, 2) Highest counter ID seen: c0 diff --git a/tests/coverage/no_cov_crate.cov-map b/tests/coverage/no_cov_crate.cov-map index ca3c95fe84c4b..bdbce570b1964 100644 --- a/tests/coverage/no_cov_crate.cov-map +++ b/tests/coverage/no_cov_crate.cov-map @@ -1,36 +1,33 @@ Function name: no_cov_crate::add_coverage_1 -Raw bytes (24): 0x[01, 01, 00, 04, 01, 16, 01, 00, 14, 01, 01, 05, 00, 0d, 01, 00, 0e, 00, 22, 01, 01, 01, 00, 02] +Raw bytes (19): 0x[01, 01, 00, 03, 01, 16, 01, 00, 14, 01, 01, 05, 00, 0d, 01, 01, 01, 00, 02] Number of files: 1 - file 0 => $DIR/no_cov_crate.rs Number of expressions: 0 -Number of file 0 mappings: 4 +Number of file 0 mappings: 3 - Code(Counter(0)) at (prev + 22, 1) to (start + 0, 20) - Code(Counter(0)) at (prev + 1, 5) to (start + 0, 13) -- Code(Counter(0)) at (prev + 0, 14) to (start + 0, 34) - Code(Counter(0)) at (prev + 1, 1) to (start + 0, 2) Highest counter ID seen: c0 Function name: no_cov_crate::add_coverage_2 -Raw bytes (24): 0x[01, 01, 00, 04, 01, 1a, 01, 00, 14, 01, 01, 05, 00, 0d, 01, 00, 0e, 00, 22, 01, 01, 01, 00, 02] +Raw bytes (19): 0x[01, 01, 00, 03, 01, 1a, 01, 00, 14, 01, 01, 05, 00, 0d, 01, 01, 01, 00, 02] Number of files: 1 - file 0 => $DIR/no_cov_crate.rs Number of expressions: 0 -Number of file 0 mappings: 4 +Number of file 0 mappings: 3 - Code(Counter(0)) at (prev + 26, 1) to (start + 0, 20) - Code(Counter(0)) at (prev + 1, 5) to (start + 0, 13) -- Code(Counter(0)) at (prev + 0, 14) to (start + 0, 34) - Code(Counter(0)) at (prev + 1, 1) to (start + 0, 2) Highest counter ID seen: c0 Function name: no_cov_crate::add_coverage_not_called (unused) -Raw bytes (24): 0x[01, 01, 00, 04, 00, 1f, 01, 00, 1d, 00, 01, 05, 00, 0d, 00, 00, 0e, 00, 26, 00, 01, 01, 00, 02] +Raw bytes (19): 0x[01, 01, 00, 03, 00, 1f, 01, 00, 1d, 00, 01, 05, 00, 0d, 00, 01, 01, 00, 02] Number of files: 1 - file 0 => $DIR/no_cov_crate.rs Number of expressions: 0 -Number of file 0 mappings: 4 +Number of file 0 mappings: 3 - Code(Zero) at (prev + 31, 1) to (start + 0, 29) - Code(Zero) at (prev + 1, 5) to (start + 0, 13) -- Code(Zero) at (prev + 0, 14) to (start + 0, 38) - Code(Zero) at (prev + 1, 1) to (start + 0, 2) Highest counter ID seen: (none) @@ -57,28 +54,26 @@ Number of file 0 mappings: 14 Highest counter ID seen: c0 Function name: no_cov_crate::nested_fns::outer -Raw bytes (34): 0x[01, 01, 00, 06, 01, 33, 05, 00, 20, 01, 01, 09, 00, 11, 01, 00, 12, 00, 26, 01, 01, 09, 00, 1a, 01, 00, 1b, 00, 22, 01, 0a, 05, 00, 06] +Raw bytes (29): 0x[01, 01, 00, 05, 01, 33, 05, 00, 20, 01, 01, 09, 00, 11, 01, 01, 09, 00, 1a, 01, 00, 1b, 00, 22, 01, 0a, 05, 00, 06] Number of files: 1 - file 0 => $DIR/no_cov_crate.rs Number of expressions: 0 -Number of file 0 mappings: 6 +Number of file 0 mappings: 5 - Code(Counter(0)) at (prev + 51, 5) to (start + 0, 32) - Code(Counter(0)) at (prev + 1, 9) to (start + 0, 17) -- Code(Counter(0)) at (prev + 0, 18) to (start + 0, 38) - Code(Counter(0)) at (prev + 1, 9) to (start + 0, 26) - Code(Counter(0)) at (prev + 0, 27) to (start + 0, 34) - Code(Counter(0)) at (prev + 10, 5) to (start + 0, 6) Highest counter ID seen: c0 Function name: no_cov_crate::nested_fns::outer_both_covered -Raw bytes (34): 0x[01, 01, 00, 06, 01, 41, 05, 00, 2d, 01, 01, 09, 00, 11, 01, 00, 12, 00, 26, 01, 01, 09, 00, 0e, 01, 00, 0f, 00, 16, 01, 09, 05, 00, 06] +Raw bytes (29): 0x[01, 01, 00, 05, 01, 41, 05, 00, 2d, 01, 01, 09, 00, 11, 01, 01, 09, 00, 0e, 01, 00, 0f, 00, 16, 01, 09, 05, 00, 06] Number of files: 1 - file 0 => $DIR/no_cov_crate.rs Number of expressions: 0 -Number of file 0 mappings: 6 +Number of file 0 mappings: 5 - Code(Counter(0)) at (prev + 65, 5) to (start + 0, 45) - Code(Counter(0)) at (prev + 1, 9) to (start + 0, 17) -- Code(Counter(0)) at (prev + 0, 18) to (start + 0, 38) - Code(Counter(0)) at (prev + 1, 9) to (start + 0, 14) - Code(Counter(0)) at (prev + 0, 15) to (start + 0, 22) - Code(Counter(0)) at (prev + 9, 5) to (start + 0, 6) diff --git a/tests/coverage/overflow.cov-map b/tests/coverage/overflow.cov-map index 18b0503b9e7c1..22a4ed0d49cd3 100644 --- a/tests/coverage/overflow.cov-map +++ b/tests/coverage/overflow.cov-map @@ -1,5 +1,5 @@ Function name: overflow::main -Raw bytes (96): 0x[01, 01, 06, 05, 01, 05, 17, 01, 09, 05, 13, 17, 0d, 01, 09, 10, 01, 10, 01, 00, 1c, 01, 01, 09, 00, 16, 01, 00, 19, 00, 1b, 05, 01, 0b, 00, 18, 02, 01, 0c, 00, 1a, 09, 00, 1b, 03, 0a, 09, 01, 11, 00, 17, 09, 00, 1a, 00, 28, 06, 02, 13, 00, 20, 0d, 00, 21, 03, 0a, 0d, 01, 11, 00, 17, 0d, 00, 1a, 00, 28, 0e, 02, 09, 00, 0a, 02, 01, 09, 00, 17, 01, 02, 05, 00, 0b, 01, 01, 01, 00, 02] +Raw bytes (86): 0x[01, 01, 06, 05, 01, 05, 17, 01, 09, 05, 13, 17, 0d, 01, 09, 0e, 01, 10, 01, 00, 1c, 01, 01, 09, 00, 16, 01, 00, 19, 00, 1b, 05, 01, 0b, 00, 18, 02, 01, 0c, 00, 1a, 09, 00, 1b, 03, 0a, 09, 01, 11, 00, 17, 06, 02, 13, 00, 20, 0d, 00, 21, 03, 0a, 0d, 01, 11, 00, 17, 0e, 02, 09, 00, 0a, 02, 01, 09, 00, 17, 01, 02, 05, 00, 0b, 01, 01, 01, 00, 02] Number of files: 1 - file 0 => $DIR/overflow.rs Number of expressions: 6 @@ -9,7 +9,7 @@ Number of expressions: 6 - expression 3 operands: lhs = Counter(1), rhs = Expression(4, Add) - expression 4 operands: lhs = Expression(5, Add), rhs = Counter(3) - expression 5 operands: lhs = Counter(0), rhs = Counter(2) -Number of file 0 mappings: 16 +Number of file 0 mappings: 14 - Code(Counter(0)) at (prev + 16, 1) to (start + 0, 28) - Code(Counter(0)) at (prev + 1, 9) to (start + 0, 22) - Code(Counter(0)) at (prev + 0, 25) to (start + 0, 27) @@ -18,12 +18,10 @@ Number of file 0 mappings: 16 = (c1 - c0) - Code(Counter(2)) at (prev + 0, 27) to (start + 3, 10) - Code(Counter(2)) at (prev + 1, 17) to (start + 0, 23) -- Code(Counter(2)) at (prev + 0, 26) to (start + 0, 40) - Code(Expression(1, Sub)) at (prev + 2, 19) to (start + 0, 32) = (c1 - (c0 + c2)) - Code(Counter(3)) at (prev + 0, 33) to (start + 3, 10) - Code(Counter(3)) at (prev + 1, 17) to (start + 0, 23) -- Code(Counter(3)) at (prev + 0, 26) to (start + 0, 40) - Code(Expression(3, Sub)) at (prev + 2, 9) to (start + 0, 10) = (c1 - ((c0 + c2) + c3)) - Code(Expression(0, Sub)) at (prev + 1, 9) to (start + 0, 23) @@ -33,12 +31,12 @@ Number of file 0 mappings: 16 Highest counter ID seen: c3 Function name: overflow::might_overflow -Raw bytes (76): 0x[01, 01, 01, 01, 05, 0e, 01, 05, 01, 00, 26, 01, 01, 08, 00, 12, 05, 00, 13, 02, 06, 02, 02, 05, 00, 06, 01, 01, 09, 00, 0f, 01, 00, 12, 00, 1e, 01, 01, 05, 00, 0d, 01, 00, 0e, 00, 26, 01, 01, 09, 00, 0f, 01, 00, 12, 00, 21, 01, 01, 05, 00, 0d, 01, 00, 0e, 00, 2f, 01, 01, 05, 00, 0b, 01, 01, 01, 00, 02] +Raw bytes (66): 0x[01, 01, 01, 01, 05, 0c, 01, 05, 01, 00, 26, 01, 01, 08, 00, 12, 05, 00, 13, 02, 06, 02, 02, 05, 00, 06, 01, 01, 09, 00, 0f, 01, 00, 12, 00, 1e, 01, 01, 05, 00, 0d, 01, 01, 09, 00, 0f, 01, 00, 12, 00, 21, 01, 01, 05, 00, 0d, 01, 01, 05, 00, 0b, 01, 01, 01, 00, 02] Number of files: 1 - file 0 => $DIR/overflow.rs Number of expressions: 1 - expression 0 operands: lhs = Counter(0), rhs = Counter(1) -Number of file 0 mappings: 14 +Number of file 0 mappings: 12 - Code(Counter(0)) at (prev + 5, 1) to (start + 0, 38) - Code(Counter(0)) at (prev + 1, 8) to (start + 0, 18) - Code(Counter(1)) at (prev + 0, 19) to (start + 2, 6) @@ -47,11 +45,9 @@ Number of file 0 mappings: 14 - Code(Counter(0)) at (prev + 1, 9) to (start + 0, 15) - Code(Counter(0)) at (prev + 0, 18) to (start + 0, 30) - Code(Counter(0)) at (prev + 1, 5) to (start + 0, 13) -- Code(Counter(0)) at (prev + 0, 14) to (start + 0, 38) - Code(Counter(0)) at (prev + 1, 9) to (start + 0, 15) - Code(Counter(0)) at (prev + 0, 18) to (start + 0, 33) - Code(Counter(0)) at (prev + 1, 5) to (start + 0, 13) -- Code(Counter(0)) at (prev + 0, 14) to (start + 0, 47) - Code(Counter(0)) at (prev + 1, 5) to (start + 0, 11) - Code(Counter(0)) at (prev + 1, 1) to (start + 0, 2) Highest counter ID seen: c1 diff --git a/tests/coverage/panic_unwind.cov-map b/tests/coverage/panic_unwind.cov-map index ff656d3d8d588..42a3587786194 100644 --- a/tests/coverage/panic_unwind.cov-map +++ b/tests/coverage/panic_unwind.cov-map @@ -29,16 +29,15 @@ Number of file 0 mappings: 12 Highest counter ID seen: c3 Function name: panic_unwind::might_panic -Raw bytes (41): 0x[01, 01, 01, 01, 05, 07, 01, 04, 01, 00, 23, 01, 01, 08, 00, 14, 05, 01, 09, 00, 11, 05, 00, 12, 00, 20, 05, 01, 09, 00, 0f, 02, 01, 0c, 02, 06, 02, 03, 01, 00, 02] +Raw bytes (36): 0x[01, 01, 01, 01, 05, 06, 01, 04, 01, 00, 23, 01, 01, 08, 00, 14, 05, 01, 09, 00, 11, 05, 01, 09, 00, 0f, 02, 01, 0c, 02, 06, 02, 03, 01, 00, 02] Number of files: 1 - file 0 => $DIR/panic_unwind.rs Number of expressions: 1 - expression 0 operands: lhs = Counter(0), rhs = Counter(1) -Number of file 0 mappings: 7 +Number of file 0 mappings: 6 - Code(Counter(0)) at (prev + 4, 1) to (start + 0, 35) - Code(Counter(0)) at (prev + 1, 8) to (start + 0, 20) - Code(Counter(1)) at (prev + 1, 9) to (start + 0, 17) -- Code(Counter(1)) at (prev + 0, 18) to (start + 0, 32) - Code(Counter(1)) at (prev + 1, 9) to (start + 0, 15) - Code(Expression(0, Sub)) at (prev + 1, 12) to (start + 2, 6) = (c0 - c1) diff --git a/tests/coverage/partial_eq.cov-map b/tests/coverage/partial_eq.cov-map index 0a81be7491289..8def64a3f546d 100644 --- a/tests/coverage/partial_eq.cov-map +++ b/tests/coverage/partial_eq.cov-map @@ -11,19 +11,18 @@ Number of file 0 mappings: 4 Highest counter ID seen: c0 Function name: partial_eq::main -Raw bytes (49): 0x[01, 01, 00, 09, 01, 11, 01, 00, 0a, 01, 01, 09, 00, 16, 01, 00, 19, 00, 25, 01, 01, 09, 00, 16, 01, 00, 19, 00, 25, 01, 02, 05, 00, 0d, 01, 01, 09, 00, 1b, 01, 03, 09, 00, 26, 01, 02, 01, 00, 02] +Raw bytes (44): 0x[01, 01, 00, 08, 01, 11, 01, 00, 0a, 01, 01, 09, 00, 16, 01, 00, 19, 00, 25, 01, 01, 09, 00, 16, 01, 00, 19, 00, 25, 01, 02, 05, 00, 0d, 01, 04, 09, 00, 26, 01, 02, 01, 00, 02] Number of files: 1 - file 0 => $DIR/partial_eq.rs Number of expressions: 0 -Number of file 0 mappings: 9 +Number of file 0 mappings: 8 - Code(Counter(0)) at (prev + 17, 1) to (start + 0, 10) - Code(Counter(0)) at (prev + 1, 9) to (start + 0, 22) - Code(Counter(0)) at (prev + 0, 25) to (start + 0, 37) - Code(Counter(0)) at (prev + 1, 9) to (start + 0, 22) - Code(Counter(0)) at (prev + 0, 25) to (start + 0, 37) - Code(Counter(0)) at (prev + 2, 5) to (start + 0, 13) -- Code(Counter(0)) at (prev + 1, 9) to (start + 0, 27) -- Code(Counter(0)) at (prev + 3, 9) to (start + 0, 38) +- Code(Counter(0)) at (prev + 4, 9) to (start + 0, 38) - Code(Counter(0)) at (prev + 2, 1) to (start + 0, 2) Highest counter ID seen: c0 diff --git a/tests/coverage/rustfmt-skip.cov-map b/tests/coverage/rustfmt-skip.cov-map index bb673a411bfdd..25e4995ea6da2 100644 --- a/tests/coverage/rustfmt-skip.cov-map +++ b/tests/coverage/rustfmt-skip.cov-map @@ -1,12 +1,11 @@ Function name: rustfmt_skip::main -Raw bytes (24): 0x[01, 01, 00, 04, 01, 0a, 01, 00, 0a, 01, 02, 05, 00, 0d, 01, 03, 09, 00, 10, 01, 02, 01, 00, 02] +Raw bytes (19): 0x[01, 01, 00, 03, 01, 0a, 01, 00, 0a, 01, 02, 05, 00, 0d, 01, 05, 01, 00, 02] Number of files: 1 - file 0 => $DIR/rustfmt-skip.rs Number of expressions: 0 -Number of file 0 mappings: 4 +Number of file 0 mappings: 3 - Code(Counter(0)) at (prev + 10, 1) to (start + 0, 10) - Code(Counter(0)) at (prev + 2, 5) to (start + 0, 13) -- Code(Counter(0)) at (prev + 3, 9) to (start + 0, 16) -- Code(Counter(0)) at (prev + 2, 1) to (start + 0, 2) +- Code(Counter(0)) at (prev + 5, 1) to (start + 0, 2) Highest counter ID seen: c0 diff --git a/tests/coverage/sort_groups.cov-map b/tests/coverage/sort_groups.cov-map index 70cf7cff4b675..29d54d88a87ee 100644 --- a/tests/coverage/sort_groups.cov-map +++ b/tests/coverage/sort_groups.cov-map @@ -1,63 +1,59 @@ Function name: sort_groups::generic_fn::<&str> -Raw bytes (36): 0x[01, 01, 01, 01, 05, 06, 01, 11, 01, 00, 1d, 01, 01, 08, 00, 0c, 05, 00, 0d, 02, 06, 05, 01, 09, 00, 11, 02, 01, 05, 00, 06, 01, 01, 01, 00, 02] +Raw bytes (31): 0x[01, 01, 01, 01, 05, 05, 01, 11, 01, 00, 1d, 01, 01, 08, 00, 0c, 05, 00, 0d, 02, 06, 02, 02, 05, 00, 06, 01, 01, 01, 00, 02] Number of files: 1 - file 0 => $DIR/sort_groups.rs Number of expressions: 1 - expression 0 operands: lhs = Counter(0), rhs = Counter(1) -Number of file 0 mappings: 6 +Number of file 0 mappings: 5 - Code(Counter(0)) at (prev + 17, 1) to (start + 0, 29) - Code(Counter(0)) at (prev + 1, 8) to (start + 0, 12) - Code(Counter(1)) at (prev + 0, 13) to (start + 2, 6) -- Code(Counter(1)) at (prev + 1, 9) to (start + 0, 17) -- Code(Expression(0, Sub)) at (prev + 1, 5) to (start + 0, 6) +- Code(Expression(0, Sub)) at (prev + 2, 5) to (start + 0, 6) = (c0 - c1) - Code(Counter(0)) at (prev + 1, 1) to (start + 0, 2) Highest counter ID seen: c1 Function name: sort_groups::generic_fn::<()> -Raw bytes (36): 0x[01, 01, 01, 01, 05, 06, 01, 11, 01, 00, 1d, 01, 01, 08, 00, 0c, 05, 00, 0d, 02, 06, 05, 01, 09, 00, 11, 02, 01, 05, 00, 06, 01, 01, 01, 00, 02] +Raw bytes (31): 0x[01, 01, 01, 01, 05, 05, 01, 11, 01, 00, 1d, 01, 01, 08, 00, 0c, 05, 00, 0d, 02, 06, 02, 02, 05, 00, 06, 01, 01, 01, 00, 02] Number of files: 1 - file 0 => $DIR/sort_groups.rs Number of expressions: 1 - expression 0 operands: lhs = Counter(0), rhs = Counter(1) -Number of file 0 mappings: 6 +Number of file 0 mappings: 5 - Code(Counter(0)) at (prev + 17, 1) to (start + 0, 29) - Code(Counter(0)) at (prev + 1, 8) to (start + 0, 12) - Code(Counter(1)) at (prev + 0, 13) to (start + 2, 6) -- Code(Counter(1)) at (prev + 1, 9) to (start + 0, 17) -- Code(Expression(0, Sub)) at (prev + 1, 5) to (start + 0, 6) +- Code(Expression(0, Sub)) at (prev + 2, 5) to (start + 0, 6) = (c0 - c1) - Code(Counter(0)) at (prev + 1, 1) to (start + 0, 2) Highest counter ID seen: c1 Function name: sort_groups::generic_fn:: -Raw bytes (36): 0x[01, 01, 01, 01, 05, 06, 01, 11, 01, 00, 1d, 01, 01, 08, 00, 0c, 05, 00, 0d, 02, 06, 05, 01, 09, 00, 11, 02, 01, 05, 00, 06, 01, 01, 01, 00, 02] +Raw bytes (31): 0x[01, 01, 01, 01, 05, 05, 01, 11, 01, 00, 1d, 01, 01, 08, 00, 0c, 05, 00, 0d, 02, 06, 02, 02, 05, 00, 06, 01, 01, 01, 00, 02] Number of files: 1 - file 0 => $DIR/sort_groups.rs Number of expressions: 1 - expression 0 operands: lhs = Counter(0), rhs = Counter(1) -Number of file 0 mappings: 6 +Number of file 0 mappings: 5 - Code(Counter(0)) at (prev + 17, 1) to (start + 0, 29) - Code(Counter(0)) at (prev + 1, 8) to (start + 0, 12) - Code(Counter(1)) at (prev + 0, 13) to (start + 2, 6) -- Code(Counter(1)) at (prev + 1, 9) to (start + 0, 17) -- Code(Expression(0, Sub)) at (prev + 1, 5) to (start + 0, 6) +- Code(Expression(0, Sub)) at (prev + 2, 5) to (start + 0, 6) = (c0 - c1) - Code(Counter(0)) at (prev + 1, 1) to (start + 0, 2) Highest counter ID seen: c1 Function name: sort_groups::generic_fn:: -Raw bytes (36): 0x[01, 01, 01, 01, 05, 06, 01, 11, 01, 00, 1d, 01, 01, 08, 00, 0c, 05, 00, 0d, 02, 06, 05, 01, 09, 00, 11, 02, 01, 05, 00, 06, 01, 01, 01, 00, 02] +Raw bytes (31): 0x[01, 01, 01, 01, 05, 05, 01, 11, 01, 00, 1d, 01, 01, 08, 00, 0c, 05, 00, 0d, 02, 06, 02, 02, 05, 00, 06, 01, 01, 01, 00, 02] Number of files: 1 - file 0 => $DIR/sort_groups.rs Number of expressions: 1 - expression 0 operands: lhs = Counter(0), rhs = Counter(1) -Number of file 0 mappings: 6 +Number of file 0 mappings: 5 - Code(Counter(0)) at (prev + 17, 1) to (start + 0, 29) - Code(Counter(0)) at (prev + 1, 8) to (start + 0, 12) - Code(Counter(1)) at (prev + 0, 13) to (start + 2, 6) -- Code(Counter(1)) at (prev + 1, 9) to (start + 0, 17) -- Code(Expression(0, Sub)) at (prev + 1, 5) to (start + 0, 6) +- Code(Expression(0, Sub)) at (prev + 2, 5) to (start + 0, 6) = (c0 - c1) - Code(Counter(0)) at (prev + 1, 1) to (start + 0, 2) Highest counter ID seen: c1 diff --git a/tests/coverage/unused_mod.cov-map b/tests/coverage/unused_mod.cov-map index ea419edbdafe6..ab8aad618e511 100644 --- a/tests/coverage/unused_mod.cov-map +++ b/tests/coverage/unused_mod.cov-map @@ -1,24 +1,22 @@ Function name: unused_mod::main -Raw bytes (24): 0x[01, 01, 00, 04, 01, 04, 01, 00, 0a, 01, 01, 05, 00, 0d, 01, 00, 0e, 00, 1c, 01, 01, 01, 00, 02] +Raw bytes (19): 0x[01, 01, 00, 03, 01, 04, 01, 00, 0a, 01, 01, 05, 00, 0d, 01, 01, 01, 00, 02] Number of files: 1 - file 0 => $DIR/unused_mod.rs Number of expressions: 0 -Number of file 0 mappings: 4 +Number of file 0 mappings: 3 - Code(Counter(0)) at (prev + 4, 1) to (start + 0, 10) - Code(Counter(0)) at (prev + 1, 5) to (start + 0, 13) -- Code(Counter(0)) at (prev + 0, 14) to (start + 0, 28) - Code(Counter(0)) at (prev + 1, 1) to (start + 0, 2) Highest counter ID seen: c0 Function name: unused_mod::unused_module::never_called_function (unused) -Raw bytes (24): 0x[01, 02, 00, 04, 00, 02, 01, 00, 1f, 00, 01, 05, 00, 0d, 00, 00, 0e, 00, 21, 00, 01, 01, 00, 02] +Raw bytes (19): 0x[01, 02, 00, 03, 00, 02, 01, 00, 1f, 00, 01, 05, 00, 0d, 00, 01, 01, 00, 02] Number of files: 1 - file 0 => $DIR/auxiliary/unused_mod_helper.rs Number of expressions: 0 -Number of file 0 mappings: 4 +Number of file 0 mappings: 3 - Code(Zero) at (prev + 2, 1) to (start + 0, 31) - Code(Zero) at (prev + 1, 5) to (start + 0, 13) -- Code(Zero) at (prev + 0, 14) to (start + 0, 33) - Code(Zero) at (prev + 1, 1) to (start + 0, 2) Highest counter ID seen: (none) diff --git a/tests/coverage/uses_crate.cov-map b/tests/coverage/uses_crate.cov-map index 8f3c63aba5ce3..fd65fa03dcdb6 100644 --- a/tests/coverage/uses_crate.cov-map +++ b/tests/coverage/uses_crate.cov-map @@ -1,48 +1,44 @@ Function name: used_crate::used_from_bin_crate_and_lib_crate_generic_function::> -Raw bytes (24): 0x[01, 01, 00, 04, 01, 1b, 01, 00, 4c, 01, 01, 05, 00, 0d, 01, 00, 0e, 00, 4f, 01, 01, 01, 00, 02] +Raw bytes (19): 0x[01, 01, 00, 03, 01, 1b, 01, 00, 4c, 01, 01, 05, 00, 0d, 01, 01, 01, 00, 02] Number of files: 1 - file 0 => $DIR/auxiliary/used_crate.rs Number of expressions: 0 -Number of file 0 mappings: 4 +Number of file 0 mappings: 3 - Code(Counter(0)) at (prev + 27, 1) to (start + 0, 76) - Code(Counter(0)) at (prev + 1, 5) to (start + 0, 13) -- Code(Counter(0)) at (prev + 0, 14) to (start + 0, 79) - Code(Counter(0)) at (prev + 1, 1) to (start + 0, 2) Highest counter ID seen: c0 Function name: used_crate::used_only_from_bin_crate_generic_function::<&alloc::vec::Vec> -Raw bytes (24): 0x[01, 01, 00, 04, 01, 13, 01, 00, 43, 01, 01, 05, 00, 0d, 01, 00, 0e, 00, 46, 01, 01, 01, 00, 02] +Raw bytes (19): 0x[01, 01, 00, 03, 01, 13, 01, 00, 43, 01, 01, 05, 00, 0d, 01, 01, 01, 00, 02] Number of files: 1 - file 0 => $DIR/auxiliary/used_crate.rs Number of expressions: 0 -Number of file 0 mappings: 4 +Number of file 0 mappings: 3 - Code(Counter(0)) at (prev + 19, 1) to (start + 0, 67) - Code(Counter(0)) at (prev + 1, 5) to (start + 0, 13) -- Code(Counter(0)) at (prev + 0, 14) to (start + 0, 70) - Code(Counter(0)) at (prev + 1, 1) to (start + 0, 2) Highest counter ID seen: c0 Function name: used_crate::used_only_from_bin_crate_generic_function::<&str> -Raw bytes (24): 0x[01, 01, 00, 04, 01, 13, 01, 00, 43, 01, 01, 05, 00, 0d, 01, 00, 0e, 00, 46, 01, 01, 01, 00, 02] +Raw bytes (19): 0x[01, 01, 00, 03, 01, 13, 01, 00, 43, 01, 01, 05, 00, 0d, 01, 01, 01, 00, 02] Number of files: 1 - file 0 => $DIR/auxiliary/used_crate.rs Number of expressions: 0 -Number of file 0 mappings: 4 +Number of file 0 mappings: 3 - Code(Counter(0)) at (prev + 19, 1) to (start + 0, 67) - Code(Counter(0)) at (prev + 1, 5) to (start + 0, 13) -- Code(Counter(0)) at (prev + 0, 14) to (start + 0, 70) - Code(Counter(0)) at (prev + 1, 1) to (start + 0, 2) Highest counter ID seen: c0 Function name: used_crate::used_with_same_type_from_bin_crate_and_lib_crate_generic_function::<&str> -Raw bytes (24): 0x[01, 01, 00, 04, 01, 1f, 01, 00, 5b, 01, 01, 05, 00, 0d, 01, 00, 0e, 00, 5e, 01, 01, 01, 00, 02] +Raw bytes (19): 0x[01, 01, 00, 03, 01, 1f, 01, 00, 5b, 01, 01, 05, 00, 0d, 01, 01, 01, 00, 02] Number of files: 1 - file 0 => $DIR/auxiliary/used_crate.rs Number of expressions: 0 -Number of file 0 mappings: 4 +Number of file 0 mappings: 3 - Code(Counter(0)) at (prev + 31, 1) to (start + 0, 91) - Code(Counter(0)) at (prev + 1, 5) to (start + 0, 13) -- Code(Counter(0)) at (prev + 0, 14) to (start + 0, 94) - Code(Counter(0)) at (prev + 1, 1) to (start + 0, 2) Highest counter ID seen: c0 diff --git a/tests/coverage/uses_inline_crate.cov-map b/tests/coverage/uses_inline_crate.cov-map index 52f3f94ce6424..863f6df7adb71 100644 --- a/tests/coverage/uses_inline_crate.cov-map +++ b/tests/coverage/uses_inline_crate.cov-map @@ -1,12 +1,11 @@ Function name: used_inline_crate::used_from_bin_crate_and_lib_crate_generic_function::> -Raw bytes (24): 0x[01, 01, 00, 04, 01, 2c, 01, 00, 4c, 01, 01, 05, 00, 0d, 01, 00, 0e, 00, 4f, 01, 01, 01, 00, 02] +Raw bytes (19): 0x[01, 01, 00, 03, 01, 2c, 01, 00, 4c, 01, 01, 05, 00, 0d, 01, 01, 01, 00, 02] Number of files: 1 - file 0 => $DIR/auxiliary/used_inline_crate.rs Number of expressions: 0 -Number of file 0 mappings: 4 +Number of file 0 mappings: 3 - Code(Counter(0)) at (prev + 44, 1) to (start + 0, 76) - Code(Counter(0)) at (prev + 1, 5) to (start + 0, 13) -- Code(Counter(0)) at (prev + 0, 14) to (start + 0, 79) - Code(Counter(0)) at (prev + 1, 1) to (start + 0, 2) Highest counter ID seen: c0 @@ -31,38 +30,35 @@ Number of file 0 mappings: 10 Highest counter ID seen: c1 Function name: used_inline_crate::used_only_from_bin_crate_generic_function::<&alloc::vec::Vec> -Raw bytes (24): 0x[01, 01, 00, 04, 01, 21, 01, 00, 43, 01, 01, 05, 00, 0d, 01, 00, 0e, 00, 46, 01, 01, 01, 00, 02] +Raw bytes (19): 0x[01, 01, 00, 03, 01, 21, 01, 00, 43, 01, 01, 05, 00, 0d, 01, 01, 01, 00, 02] Number of files: 1 - file 0 => $DIR/auxiliary/used_inline_crate.rs Number of expressions: 0 -Number of file 0 mappings: 4 +Number of file 0 mappings: 3 - Code(Counter(0)) at (prev + 33, 1) to (start + 0, 67) - Code(Counter(0)) at (prev + 1, 5) to (start + 0, 13) -- Code(Counter(0)) at (prev + 0, 14) to (start + 0, 70) - Code(Counter(0)) at (prev + 1, 1) to (start + 0, 2) Highest counter ID seen: c0 Function name: used_inline_crate::used_only_from_bin_crate_generic_function::<&str> -Raw bytes (24): 0x[01, 01, 00, 04, 01, 21, 01, 00, 43, 01, 01, 05, 00, 0d, 01, 00, 0e, 00, 46, 01, 01, 01, 00, 02] +Raw bytes (19): 0x[01, 01, 00, 03, 01, 21, 01, 00, 43, 01, 01, 05, 00, 0d, 01, 01, 01, 00, 02] Number of files: 1 - file 0 => $DIR/auxiliary/used_inline_crate.rs Number of expressions: 0 -Number of file 0 mappings: 4 +Number of file 0 mappings: 3 - Code(Counter(0)) at (prev + 33, 1) to (start + 0, 67) - Code(Counter(0)) at (prev + 1, 5) to (start + 0, 13) -- Code(Counter(0)) at (prev + 0, 14) to (start + 0, 70) - Code(Counter(0)) at (prev + 1, 1) to (start + 0, 2) Highest counter ID seen: c0 Function name: used_inline_crate::used_with_same_type_from_bin_crate_and_lib_crate_generic_function::<&str> -Raw bytes (24): 0x[01, 01, 00, 04, 01, 31, 01, 00, 5b, 01, 01, 05, 00, 0d, 01, 00, 0e, 00, 5e, 01, 01, 01, 00, 02] +Raw bytes (19): 0x[01, 01, 00, 03, 01, 31, 01, 00, 5b, 01, 01, 05, 00, 0d, 01, 01, 01, 00, 02] Number of files: 1 - file 0 => $DIR/auxiliary/used_inline_crate.rs Number of expressions: 0 -Number of file 0 mappings: 4 +Number of file 0 mappings: 3 - Code(Counter(0)) at (prev + 49, 1) to (start + 0, 91) - Code(Counter(0)) at (prev + 1, 5) to (start + 0, 13) -- Code(Counter(0)) at (prev + 0, 14) to (start + 0, 94) - Code(Counter(0)) at (prev + 1, 1) to (start + 0, 2) Highest counter ID seen: c0 diff --git a/tests/mir-opt/gvn.slices.GVN.panic-abort.diff b/tests/mir-opt/gvn.slices.GVN.panic-abort.diff index 091c3bd5c7b2a..b7872fc9952ba 100644 --- a/tests/mir-opt/gvn.slices.GVN.panic-abort.diff +++ b/tests/mir-opt/gvn.slices.GVN.panic-abort.diff @@ -209,9 +209,10 @@ + _27 = &(*_12); _26 = &(*_27); StorageLive(_28); - _28 = Option::>::None; +- _28 = Option::>::None; - _22 = assert_failed::<*const u8, *const u8>(move _23, move _24, move _26, move _28) -> unwind unreachable; -+ _22 = assert_failed::<*const u8, *const u8>(const core::panicking::AssertKind::Eq, move _24, move _26, move _28) -> unwind unreachable; ++ _28 = const Option::>::None; ++ _22 = assert_failed::<*const u8, *const u8>(const core::panicking::AssertKind::Eq, move _24, move _26, const Option::>::None) -> unwind unreachable; } bb7: { @@ -311,11 +312,15 @@ + _53 = &(*_38); _52 = &(*_53); StorageLive(_54); - _54 = Option::>::None; +- _54 = Option::>::None; - _48 = assert_failed::<*const u8, *const u8>(move _49, move _50, move _52, move _54) -> unwind unreachable; -+ _48 = assert_failed::<*const u8, *const u8>(const core::panicking::AssertKind::Eq, move _50, move _52, move _54) -> unwind unreachable; ++ _54 = const Option::>::None; ++ _48 = assert_failed::<*const u8, *const u8>(const core::panicking::AssertKind::Eq, move _50, move _52, const Option::>::None) -> unwind unreachable; } } - ALLOC0 (size: 18, align: 1) { .. } +- ALLOC0 (size: 18, align: 1) { .. } ++ ALLOC0 (size: 16, align: 8) { .. } ++ ++ ALLOC1 (size: 18, align: 1) { .. } diff --git a/tests/mir-opt/gvn.slices.GVN.panic-unwind.diff b/tests/mir-opt/gvn.slices.GVN.panic-unwind.diff index 9768956c9c870..37817b48c1992 100644 --- a/tests/mir-opt/gvn.slices.GVN.panic-unwind.diff +++ b/tests/mir-opt/gvn.slices.GVN.panic-unwind.diff @@ -209,9 +209,10 @@ + _27 = &(*_12); _26 = &(*_27); StorageLive(_28); - _28 = Option::>::None; +- _28 = Option::>::None; - _22 = assert_failed::<*const u8, *const u8>(move _23, move _24, move _26, move _28) -> unwind continue; -+ _22 = assert_failed::<*const u8, *const u8>(const core::panicking::AssertKind::Eq, move _24, move _26, move _28) -> unwind continue; ++ _28 = const Option::>::None; ++ _22 = assert_failed::<*const u8, *const u8>(const core::panicking::AssertKind::Eq, move _24, move _26, const Option::>::None) -> unwind continue; } bb7: { @@ -311,11 +312,15 @@ + _53 = &(*_38); _52 = &(*_53); StorageLive(_54); - _54 = Option::>::None; +- _54 = Option::>::None; - _48 = assert_failed::<*const u8, *const u8>(move _49, move _50, move _52, move _54) -> unwind continue; -+ _48 = assert_failed::<*const u8, *const u8>(const core::panicking::AssertKind::Eq, move _50, move _52, move _54) -> unwind continue; ++ _54 = const Option::>::None; ++ _48 = assert_failed::<*const u8, *const u8>(const core::panicking::AssertKind::Eq, move _50, move _52, const Option::>::None) -> unwind continue; } } - ALLOC0 (size: 18, align: 1) { .. } +- ALLOC0 (size: 18, align: 1) { .. } ++ ALLOC0 (size: 16, align: 8) { .. } ++ ++ ALLOC1 (size: 18, align: 1) { .. } diff --git a/tests/mir-opt/sroa/lifetimes.foo.ScalarReplacementOfAggregates.diff b/tests/mir-opt/sroa/lifetimes.foo.ScalarReplacementOfAggregates.diff index 056dc4c42c11f..3a0ddd135b6c2 100644 --- a/tests/mir-opt/sroa/lifetimes.foo.ScalarReplacementOfAggregates.diff +++ b/tests/mir-opt/sroa/lifetimes.foo.ScalarReplacementOfAggregates.diff @@ -17,23 +17,31 @@ let mut _17: &std::boxed::Box; let mut _18: core::fmt::rt::Argument<'_>; let mut _19: &u32; - let mut _20: &[&str; 3]; - let _21: &[&str; 3]; - let _22: [&str; 3]; - let mut _23: &[core::fmt::rt::Argument<'_>; 2]; - let _24: &[core::fmt::rt::Argument<'_>; 2]; - let mut _26: &std::boxed::Box; - let mut _27: &u32; - let mut _28: bool; - let mut _29: isize; - let mut _30: isize; - let mut _31: isize; -+ let _32: std::result::Result, ::Err>; -+ let _33: u32; + let mut _20: core::fmt::rt::Template<'_>; + let mut _21: &[core::fmt::rt::Piece; 7]; + let _22: &[core::fmt::rt::Piece; 7]; + let _23: [core::fmt::rt::Piece; 7]; + let mut _24: core::fmt::rt::Piece; + let mut _25: core::fmt::rt::Piece; + let mut _26: core::fmt::rt::Piece; + let mut _27: core::fmt::rt::Piece; + let mut _28: core::fmt::rt::Piece; + let mut _29: core::fmt::rt::Piece; + let mut _30: core::fmt::rt::Piece; + let mut _31: &[core::fmt::rt::Argument<'_>; 2]; + let _32: &[core::fmt::rt::Argument<'_>; 2]; + let mut _34: &std::boxed::Box; + let mut _35: &u32; + let mut _36: bool; + let mut _37: isize; + let mut _38: isize; + let mut _39: isize; ++ let _40: std::result::Result, ::Err>; ++ let _41: u32; scope 1 { - debug foo => _1; -+ debug ((foo: Foo).0: std::result::Result, ::Err>) => _32; -+ debug ((foo: Foo).1: u32) => _33; ++ debug ((foo: Foo).0: std::result::Result, ::Err>) => _40; ++ debug ((foo: Foo).1: u32) => _41; let _5: std::result::Result, ::Err>; scope 2 { debug x => _5; @@ -44,16 +52,16 @@ debug x => _8; let _8: std::boxed::Box; let _12: (&std::boxed::Box, &u32); -+ let _34: &std::boxed::Box; -+ let _35: &u32; ++ let _42: &std::boxed::Box; ++ let _43: &u32; scope 5 { - debug args => _12; -+ debug ((args: (&Box, &u32)).0: &std::boxed::Box) => _34; -+ debug ((args: (&Box, &u32)).1: &u32) => _35; ++ debug ((args: (&Box, &u32)).0: &std::boxed::Box) => _42; ++ debug ((args: (&Box, &u32)).1: &u32) => _43; let _15: [core::fmt::rt::Argument<'_>; 2]; scope 6 { debug args => _15; - let mut _25: &[&str; 3]; + let mut _33: &[core::fmt::rt::Piece; 7]; } } } @@ -62,10 +70,10 @@ } bb0: { - _28 = const false; + _36 = const false; - StorageLive(_1); -+ StorageLive(_32); -+ StorageLive(_33); ++ StorageLive(_40); ++ StorageLive(_41); + nop; StorageLive(_2); StorageLive(_3); @@ -79,19 +87,19 @@ _2 = Result::, ::Err>::Ok(move _3); StorageDead(_3); - _1 = Foo:: { x: move _2, y: const 7_u32 }; -+ _32 = move _2; -+ _33 = const 7_u32; ++ _40 = move _2; ++ _41 = const 7_u32; + nop; StorageDead(_2); StorageLive(_5); - _28 = const true; + _36 = const true; - _5 = move (_1.0: std::result::Result, ::Err>); -+ _5 = move _32; ++ _5 = move _40; StorageLive(_6); - _6 = copy (_1.1: u32); -+ _6 = copy _33; ++ _6 = copy _41; _7 = discriminant(_5); - switchInt(move _7) -> [0: bb2, otherwise: bb7]; + switchInt(move _7) -> [0: bb2, otherwise: bb8]; } bb2: { @@ -101,25 +109,25 @@ StorageLive(_10); StorageLive(_11); - StorageLive(_12); -+ StorageLive(_34); -+ StorageLive(_35); ++ StorageLive(_42); ++ StorageLive(_43); + nop; StorageLive(_13); _13 = &_8; StorageLive(_14); _14 = &_6; - _12 = (move _13, move _14); -+ _34 = move _13; -+ _35 = move _14; ++ _42 = move _13; ++ _43 = move _14; + nop; StorageDead(_14); StorageDead(_13); StorageLive(_15); StorageLive(_16); StorageLive(_17); -- _26 = copy (_12.0: &std::boxed::Box); -+ _26 = copy _34; - _17 = &(*_26); +- _34 = copy (_12.0: &std::boxed::Box); ++ _34 = copy _42; + _17 = &(*_34); _16 = core::fmt::rt::Argument::<'_>::new_display::>(move _17) -> [return: bb3, unwind unreachable]; } @@ -127,9 +135,9 @@ StorageDead(_17); StorageLive(_18); StorageLive(_19); -- _27 = copy (_12.1: &u32); -+ _27 = copy _35; - _19 = &(*_27); +- _35 = copy (_12.1: &u32); ++ _35 = copy _43; + _19 = &(*_35); _18 = core::fmt::rt::Argument::<'_>::new_display::(move _19) -> [return: bb4, unwind unreachable]; } @@ -140,66 +148,72 @@ StorageDead(_16); StorageLive(_20); StorageLive(_21); - _25 = const foo::::promoted[0]; - _21 = &(*_25); - _20 = &(*_21); - StorageLive(_23); - StorageLive(_24); - _24 = &_15; - _23 = &(*_24); - _11 = core::fmt::rt::>::new_v1::<3, 2>(move _20, move _23) -> [return: bb5, unwind unreachable]; + StorageLive(_22); + _33 = const foo::::promoted[0]; + _22 = &(*_33); + _21 = &(*_22); + _20 = core::fmt::rt::Template::<'_>::new::<7>(move _21) -> [return: bb5, unwind unreachable]; } bb5: { - StorageDead(_24); - StorageDead(_23); + StorageDead(_22); StorageDead(_21); - StorageDead(_20); - _10 = _eprint(move _11) -> [return: bb6, unwind unreachable]; + StorageLive(_31); + StorageLive(_32); + _32 = &_15; + _31 = &(*_32); + _11 = core::fmt::rt::>::new::<2>(move _20, move _31) -> [return: bb6, unwind unreachable]; } bb6: { + StorageDead(_32); + StorageDead(_31); + StorageDead(_20); + _10 = _eprint(move _11) -> [return: bb7, unwind unreachable]; + } + + bb7: { StorageDead(_11); StorageDead(_15); - StorageDead(_12); -+ StorageDead(_34); -+ StorageDead(_35); ++ StorageDead(_42); ++ StorageDead(_43); + nop; StorageDead(_10); _9 = const (); StorageDead(_9); _0 = const (); - drop(_8) -> [return: bb8, unwind unreachable]; + drop(_8) -> [return: bb9, unwind unreachable]; } - bb7: { + bb8: { _0 = const (); - goto -> bb9; + goto -> bb10; } - bb8: { + bb9: { StorageDead(_8); - goto -> bb9; + goto -> bb10; } - bb9: { + bb10: { StorageDead(_6); - _29 = discriminant(_5); - switchInt(move _29) -> [0: bb10, otherwise: bb11]; + _37 = discriminant(_5); + switchInt(move _37) -> [0: bb11, otherwise: bb12]; } - bb10: { - _28 = const false; + bb11: { + _36 = const false; StorageDead(_5); - StorageDead(_1); -+ StorageDead(_32); -+ StorageDead(_33); ++ StorageDead(_40); ++ StorageDead(_41); + nop; return; } - bb11: { - drop(_5) -> [return: bb10, unwind unreachable]; + bb12: { + drop(_5) -> [return: bb11, unwind unreachable]; } } diff --git a/tests/ui/unpretty/exhaustive.hir.stdout b/tests/ui/unpretty/exhaustive.hir.stdout index 5a13a71d94202..0b3256cdb1f14 100644 --- a/tests/ui/unpretty/exhaustive.hir.stdout +++ b/tests/ui/unpretty/exhaustive.hir.stdout @@ -390,9 +390,7 @@ mod expressions { /// ExprKind::FormatArgs fn expr_format_args() { let expr; - format_arguments::new_const(unsafe { - format_template::new(&[format_piece::num(0usize)]) - }); + format_arguments::from_str(""); { super let args = (&expr,); super let args = [format_argument::new_display(args.0)]; From 400931e86172e591b2440ce5537e78bbaf85dd04 Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Wed, 5 Nov 2025 15:58:21 +0100 Subject: [PATCH 08/13] Fix typo. --- compiler/rustc_ast_lowering/src/format.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_ast_lowering/src/format.rs b/compiler/rustc_ast_lowering/src/format.rs index 4131a832b85a8..23d808275ec82 100644 --- a/compiler/rustc_ast_lowering/src/format.rs +++ b/compiler/rustc_ast_lowering/src/format.rs @@ -480,7 +480,7 @@ fn expand_format_args<'hir>( // If this placeholder uses the next argument index, is surrounded by literal string // pieces, and uses default formatting options, then we can skip it, as this kind of - // placeholder is implied by two consequtive string pieces. + // placeholder is implied by two consecutive string pieces. if bits == default_options + implicit_arg_index { if let (Some(FormatArgsPiece::Literal(_)), Some(FormatArgsPiece::Literal(_))) = (template.get(i.wrapping_sub(1)), template.get(i + 1)) From 4f55e1137b5b94b5bf52920dc7cf2b470bd6da64 Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Wed, 5 Nov 2025 16:44:48 +0100 Subject: [PATCH 09/13] Make clippy happy. --- src/tools/clippy/clippy_utils/src/sym.rs | 1 - .../tests/ui/author/macro_in_closure.stdout | 39 ++++++++++++++----- .../tests/ui/author/macro_in_loop.stdout | 39 ++++++++++++++----- 3 files changed, 60 insertions(+), 19 deletions(-) diff --git a/src/tools/clippy/clippy_utils/src/sym.rs b/src/tools/clippy/clippy_utils/src/sym.rs index 8e8a80a6a9c95..c2523540f007d 100644 --- a/src/tools/clippy/clippy_utils/src/sym.rs +++ b/src/tools/clippy/clippy_utils/src/sym.rs @@ -166,7 +166,6 @@ generate! { from_ne_bytes, from_ptr, from_raw, - from_str, from_str_radix, fs, fuse, diff --git a/src/tools/clippy/tests/ui/author/macro_in_closure.stdout b/src/tools/clippy/tests/ui/author/macro_in_closure.stdout index 786c61e0c018e..35e8d5c18627d 100644 --- a/src/tools/clippy/tests/ui/author/macro_in_closure.stdout +++ b/src/tools/clippy/tests/ui/author/macro_in_closure.stdout @@ -31,17 +31,38 @@ if let StmtKind::Let(local) = stmt.kind && name1.as_str() == "args" && let Some(trailing_expr) = block1.expr && let ExprKind::Call(func2, args2) = trailing_expr.kind - && paths::CORE_FMT_RT_NEW_V1.matches_path(cx, func2) // Add the path to `clippy_utils::paths` if needed + && paths::CORE_FMT_RT_NEW.matches_path(cx, func2) // Add the path to `clippy_utils::paths` if needed && args2.len() == 2 - && let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Not, inner1) = args2[0].kind + && let ExprKind::Block(block2, None) = args2[0].kind + && block2.stmts.is_empty() + && let Some(trailing_expr1) = block2.expr + && let ExprKind::Call(func3, args3) = trailing_expr1.kind + && func3.res(cx).is_diag_item(cx, sym::FmtTemplateNew) + && args3.len() == 1 + && let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Not, inner1) = args3[0].kind && let ExprKind::Array(elements2) = inner1.kind - && elements2.len() == 2 - && let ExprKind::Lit(ref lit) = elements2[0].kind - && let LitKind::Str(s, _) = lit.node - && s.as_str() == "" - && let ExprKind::Lit(ref lit1) = elements2[1].kind - && let LitKind::Str(s1, _) = lit1.node - && s1.as_str() == "\n" + && elements2.len() == 4 + && let ExprKind::Call(func4, args4) = elements2[0].kind + && paths::CORE_FMT_RT_PIECE_NUM.matches_path(cx, func4) // Add the path to `clippy_utils::paths` if needed + && args4.len() == 1 + && let ExprKind::Lit(ref lit) = args4[0].kind + && let LitKind::Int(16140901201934811136, LitIntType::Unsigned(UintTy::Usize)) = lit.node + && let ExprKind::Call(func5, args5) = elements2[1].kind + && paths::CORE_FMT_RT_PIECE_NUM.matches_path(cx, func5) // Add the path to `clippy_utils::paths` if needed + && args5.len() == 1 + && let ExprKind::Lit(ref lit1) = args5[0].kind + && let LitKind::Int(1, LitIntType::Unsigned(UintTy::Usize)) = lit1.node + && let ExprKind::Call(func6, args6) = elements2[2].kind + && paths::CORE_FMT_RT_PIECE_STR.matches_path(cx, func6) // Add the path to `clippy_utils::paths` if needed + && args6.len() == 1 + && let ExprKind::Lit(ref lit2) = args6[0].kind + && let LitKind::Str(s, _) = lit2.node + && s.as_str() == "\n" + && let ExprKind::Call(func7, args7) = elements2[3].kind + && paths::CORE_FMT_RT_PIECE_NUM.matches_path(cx, func7) // Add the path to `clippy_utils::paths` if needed + && args7.len() == 1 + && let ExprKind::Lit(ref lit3) = args7[0].kind + && let LitKind::Int(0, LitIntType::Unsigned(UintTy::Usize)) = lit3.node && let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Not, inner2) = args2[1].kind && block.expr.is_none() && let PatKind::Binding(BindingMode::NONE, _, name2, None) = local.pat.kind diff --git a/src/tools/clippy/tests/ui/author/macro_in_loop.stdout b/src/tools/clippy/tests/ui/author/macro_in_loop.stdout index ba3b7e2442043..ba96f4713a234 100644 --- a/src/tools/clippy/tests/ui/author/macro_in_loop.stdout +++ b/src/tools/clippy/tests/ui/author/macro_in_loop.stdout @@ -42,17 +42,38 @@ if let Some(higher::ForLoop { pat: pat, arg: arg, body: body, .. }) = higher::Fo && name2.as_str() == "args" && let Some(trailing_expr) = block2.expr && let ExprKind::Call(func2, args2) = trailing_expr.kind - && paths::CORE_FMT_RT_NEW_V1.matches_path(cx, func2) // Add the path to `clippy_utils::paths` if needed + && paths::CORE_FMT_RT_NEW.matches_path(cx, func2) // Add the path to `clippy_utils::paths` if needed && args2.len() == 2 - && let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Not, inner1) = args2[0].kind + && let ExprKind::Block(block3, None) = args2[0].kind + && block3.stmts.is_empty() + && let Some(trailing_expr1) = block3.expr + && let ExprKind::Call(func3, args3) = trailing_expr1.kind + && func3.res(cx).is_diag_item(cx, sym::FmtTemplateNew) + && args3.len() == 1 + && let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Not, inner1) = args3[0].kind && let ExprKind::Array(elements2) = inner1.kind - && elements2.len() == 2 - && let ExprKind::Lit(ref lit2) = elements2[0].kind - && let LitKind::Str(s, _) = lit2.node - && s.as_str() == "" - && let ExprKind::Lit(ref lit3) = elements2[1].kind - && let LitKind::Str(s1, _) = lit3.node - && s1.as_str() == "\n" + && elements2.len() == 4 + && let ExprKind::Call(func4, args4) = elements2[0].kind + && paths::CORE_FMT_RT_PIECE_NUM.matches_path(cx, func4) // Add the path to `clippy_utils::paths` if needed + && args4.len() == 1 + && let ExprKind::Lit(ref lit2) = args4[0].kind + && let LitKind::Int(16140901201934811136, LitIntType::Unsigned(UintTy::Usize)) = lit2.node + && let ExprKind::Call(func5, args5) = elements2[1].kind + && paths::CORE_FMT_RT_PIECE_NUM.matches_path(cx, func5) // Add the path to `clippy_utils::paths` if needed + && args5.len() == 1 + && let ExprKind::Lit(ref lit3) = args5[0].kind + && let LitKind::Int(1, LitIntType::Unsigned(UintTy::Usize)) = lit3.node + && let ExprKind::Call(func6, args6) = elements2[2].kind + && paths::CORE_FMT_RT_PIECE_STR.matches_path(cx, func6) // Add the path to `clippy_utils::paths` if needed + && args6.len() == 1 + && let ExprKind::Lit(ref lit4) = args6[0].kind + && let LitKind::Str(s, _) = lit4.node + && s.as_str() == "\n" + && let ExprKind::Call(func7, args7) = elements2[3].kind + && paths::CORE_FMT_RT_PIECE_NUM.matches_path(cx, func7) // Add the path to `clippy_utils::paths` if needed + && args7.len() == 1 + && let ExprKind::Lit(ref lit5) = args7[0].kind + && let LitKind::Int(0, LitIntType::Unsigned(UintTy::Usize)) = lit5.node && let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Not, inner2) = args2[1].kind && block1.expr.is_none() && block.expr.is_none() From 44e7fa87096f86f03498baee7e9f260e3a30254f Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Thu, 6 Nov 2025 11:43:52 +0100 Subject: [PATCH 10/13] Put const data of format_args in const block. --- compiler/rustc_ast_lowering/src/expr.rs | 9 +++++++++ compiler/rustc_ast_lowering/src/format.rs | 3 ++- compiler/rustc_ast_lowering/src/item.rs | 2 +- library/core/src/fmt/rt.rs | 11 ----------- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/compiler/rustc_ast_lowering/src/expr.rs b/compiler/rustc_ast_lowering/src/expr.rs index 00115a314ce20..4778dc836bc2c 100644 --- a/compiler/rustc_ast_lowering/src/expr.rs +++ b/compiler/rustc_ast_lowering/src/expr.rs @@ -2270,6 +2270,15 @@ impl<'hir> LoweringContext<'_, 'hir> { ) } + pub(super) fn expr_const(&mut self, span: Span, expr: hir::Expr<'hir>) -> hir::Expr<'hir> { + let node_id = self.next_node_id(); + let def_id = + self.create_def(node_id, None, DefKind::InlineConst, DefPathData::LateAnonConst, span); + let hir_id = self.lower_node_id(node_id); + let body = self.record_body(&[], expr); + self.expr(span, hir::ExprKind::ConstBlock(hir::ConstBlock { hir_id, def_id, body })) + } + fn expr_block_empty(&mut self, span: Span) -> &'hir hir::Expr<'hir> { let blk = self.block_all(span, &[], None); let expr = self.expr_block(blk); diff --git a/compiler/rustc_ast_lowering/src/format.rs b/compiler/rustc_ast_lowering/src/format.rs index 23d808275ec82..7ef8774a72eed 100644 --- a/compiler/rustc_ast_lowering/src/format.rs +++ b/compiler/rustc_ast_lowering/src/format.rs @@ -525,11 +525,12 @@ fn expand_format_args<'hir>( pieces.push(make_piece(ctx, sym::num, zero, macsp)); // ``` - // unsafe { ::new(&[pieces…]) } + // unsafe { ::new(const { &[pieces…] }) } // ``` let template_new = ctx.expr_lang_item_type_relative(macsp, hir::LangItem::FormatTemplate, sym::new); let pieces = ctx.expr_array_ref(macsp, ctx.arena.alloc_from_iter(pieces)); + let pieces = ctx.expr_const(macsp, pieces); let template = ctx.expr( macsp, hir::ExprKind::Call(ctx.arena.alloc(template_new), ctx.arena.alloc_from_iter([pieces])), diff --git a/compiler/rustc_ast_lowering/src/item.rs b/compiler/rustc_ast_lowering/src/item.rs index 177f33c0d8f1c..f78bc53e4084b 100644 --- a/compiler/rustc_ast_lowering/src/item.rs +++ b/compiler/rustc_ast_lowering/src/item.rs @@ -1174,7 +1174,7 @@ impl<'hir> LoweringContext<'_, 'hir> { } } - fn record_body( + pub(super) fn record_body( &mut self, params: &'hir [hir::Param<'hir>], value: hir::Expr<'hir>, diff --git a/library/core/src/fmt/rt.rs b/library/core/src/fmt/rt.rs index b428de6e72b1f..8c9115b18b3ca 100644 --- a/library/core/src/fmt/rt.rs +++ b/library/core/src/fmt/rt.rs @@ -67,22 +67,11 @@ pub union Piece { unsafe impl Send for Piece {} unsafe impl Sync for Piece {} -// These are marked as #[stable] because of #[rustc_promotable] and #[rustc_const_stable]. -// With #[rustc_const_unstable], many format_args!() invocations would result in errors. -// -// There is still no way to use these on stable, because Piece itself is #[unstable] and not -// reachable through any public path. (format_args!()'s expansion uses it as a lang item.) impl Piece { - #[rustc_promotable] - #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_stable(feature = "rust1", since = "1.0.0")] pub const fn str(s: &'static str) -> Self { Self { p: s as *const str as *const u8 } } - #[rustc_promotable] - #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_stable(feature = "rust1", since = "1.0.0")] pub const fn num(i: usize) -> Self { Self { i } } From ed27e3543dc07e4d19b09ac123f4a7c7214f0429 Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Thu, 6 Nov 2025 11:46:03 +0100 Subject: [PATCH 11/13] Use transmute in core::fmt::rt to improve perf. This avoids creating NonZeros, saving a bunch of queries. --- library/core/src/fmt/rt.rs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/library/core/src/fmt/rt.rs b/library/core/src/fmt/rt.rs index 8c9115b18b3ca..5227a458f7751 100644 --- a/library/core/src/fmt/rt.rs +++ b/library/core/src/fmt/rt.rs @@ -9,7 +9,7 @@ use super::*; use crate::hint::unreachable_unchecked; use crate::marker::PhantomData; -use crate::num::NonZeroUsize; +use crate::mem; use crate::ptr::NonNull; #[lang = "format_template"] @@ -31,9 +31,9 @@ impl<'a> Template<'a> { #[inline] pub const unsafe fn new_str_len(len: usize) -> Self { + let bits = len << 1 | 1; // SAFETY: We set the lowest bit, so it's nonzero. - let bits = unsafe { NonZeroUsize::new_unchecked(len << 1 | 1) }; - Self { pieces: NonNull::without_provenance(bits), lifetime: PhantomData } + Self { pieces: unsafe { mem::transmute(bits) }, lifetime: PhantomData } } #[inline] @@ -41,7 +41,7 @@ impl<'a> Template<'a> { // SAFETY: During const eval, `self.pieces` must have come from a usize, not a pointer, // because `new()` above is not const. // Outside const eval, transmuting a pointer to a usize is fine. - let bits = unsafe { crate::mem::transmute::<_, usize>(self.pieces) }; + let bits: usize = unsafe { mem::transmute(self.pieces) }; if bits & 1 == 1 { Some(bits >> 1) } else { None } } @@ -243,10 +243,12 @@ impl<'a> Arguments<'a> { #[inline] pub const fn from_str(s: &'static str) -> Arguments<'a> { - Arguments { - // SAFETY: This is the "static str" representation of fmt::Arguments. - template: unsafe { rt::Template::new_str_len(s.len()) }, - args: NonNull::from_ref(s).cast(), + // SAFETY: This is the "static str" representation of fmt::Arguments. + unsafe { + Arguments { + template: rt::Template::new_str_len(s.len()), + args: mem::transmute(s.as_ptr()), + } } } From 61707d3b181f7886302ab84d5ab7bf21e929423e Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Thu, 6 Nov 2025 11:47:16 +0100 Subject: [PATCH 12/13] Bless tests. --- .../tests/ui/author/macro_in_closure.stdout | 27 +---- .../tests/ui/author/macro_in_loop.stdout | 27 +---- .../item-collection/opaque-return-impls.rs | 2 +- ...mes.foo.ScalarReplacementOfAggregates.diff | 108 ++++++++---------- .../ui/consts/recursive-const-in-impl.stderr | 2 +- tests/ui/unpretty/exhaustive.hir.stdout | 5 +- .../ui/unpretty/flattened-format-args.stdout | 7 +- 7 files changed, 62 insertions(+), 116 deletions(-) diff --git a/src/tools/clippy/tests/ui/author/macro_in_closure.stdout b/src/tools/clippy/tests/ui/author/macro_in_closure.stdout index 35e8d5c18627d..573cb6ed8d1ed 100644 --- a/src/tools/clippy/tests/ui/author/macro_in_closure.stdout +++ b/src/tools/clippy/tests/ui/author/macro_in_closure.stdout @@ -39,31 +39,8 @@ if let StmtKind::Let(local) = stmt.kind && let ExprKind::Call(func3, args3) = trailing_expr1.kind && func3.res(cx).is_diag_item(cx, sym::FmtTemplateNew) && args3.len() == 1 - && let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Not, inner1) = args3[0].kind - && let ExprKind::Array(elements2) = inner1.kind - && elements2.len() == 4 - && let ExprKind::Call(func4, args4) = elements2[0].kind - && paths::CORE_FMT_RT_PIECE_NUM.matches_path(cx, func4) // Add the path to `clippy_utils::paths` if needed - && args4.len() == 1 - && let ExprKind::Lit(ref lit) = args4[0].kind - && let LitKind::Int(16140901201934811136, LitIntType::Unsigned(UintTy::Usize)) = lit.node - && let ExprKind::Call(func5, args5) = elements2[1].kind - && paths::CORE_FMT_RT_PIECE_NUM.matches_path(cx, func5) // Add the path to `clippy_utils::paths` if needed - && args5.len() == 1 - && let ExprKind::Lit(ref lit1) = args5[0].kind - && let LitKind::Int(1, LitIntType::Unsigned(UintTy::Usize)) = lit1.node - && let ExprKind::Call(func6, args6) = elements2[2].kind - && paths::CORE_FMT_RT_PIECE_STR.matches_path(cx, func6) // Add the path to `clippy_utils::paths` if needed - && args6.len() == 1 - && let ExprKind::Lit(ref lit2) = args6[0].kind - && let LitKind::Str(s, _) = lit2.node - && s.as_str() == "\n" - && let ExprKind::Call(func7, args7) = elements2[3].kind - && paths::CORE_FMT_RT_PIECE_NUM.matches_path(cx, func7) // Add the path to `clippy_utils::paths` if needed - && args7.len() == 1 - && let ExprKind::Lit(ref lit3) = args7[0].kind - && let LitKind::Int(0, LitIntType::Unsigned(UintTy::Usize)) = lit3.node - && let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Not, inner2) = args2[1].kind + && let ExprKind::ConstBlock(_) = args3[0].kind + && let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Not, inner1) = args2[1].kind && block.expr.is_none() && let PatKind::Binding(BindingMode::NONE, _, name2, None) = local.pat.kind && name2.as_str() == "print_text" diff --git a/src/tools/clippy/tests/ui/author/macro_in_loop.stdout b/src/tools/clippy/tests/ui/author/macro_in_loop.stdout index ba96f4713a234..8ea9f786b4b41 100644 --- a/src/tools/clippy/tests/ui/author/macro_in_loop.stdout +++ b/src/tools/clippy/tests/ui/author/macro_in_loop.stdout @@ -50,31 +50,8 @@ if let Some(higher::ForLoop { pat: pat, arg: arg, body: body, .. }) = higher::Fo && let ExprKind::Call(func3, args3) = trailing_expr1.kind && func3.res(cx).is_diag_item(cx, sym::FmtTemplateNew) && args3.len() == 1 - && let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Not, inner1) = args3[0].kind - && let ExprKind::Array(elements2) = inner1.kind - && elements2.len() == 4 - && let ExprKind::Call(func4, args4) = elements2[0].kind - && paths::CORE_FMT_RT_PIECE_NUM.matches_path(cx, func4) // Add the path to `clippy_utils::paths` if needed - && args4.len() == 1 - && let ExprKind::Lit(ref lit2) = args4[0].kind - && let LitKind::Int(16140901201934811136, LitIntType::Unsigned(UintTy::Usize)) = lit2.node - && let ExprKind::Call(func5, args5) = elements2[1].kind - && paths::CORE_FMT_RT_PIECE_NUM.matches_path(cx, func5) // Add the path to `clippy_utils::paths` if needed - && args5.len() == 1 - && let ExprKind::Lit(ref lit3) = args5[0].kind - && let LitKind::Int(1, LitIntType::Unsigned(UintTy::Usize)) = lit3.node - && let ExprKind::Call(func6, args6) = elements2[2].kind - && paths::CORE_FMT_RT_PIECE_STR.matches_path(cx, func6) // Add the path to `clippy_utils::paths` if needed - && args6.len() == 1 - && let ExprKind::Lit(ref lit4) = args6[0].kind - && let LitKind::Str(s, _) = lit4.node - && s.as_str() == "\n" - && let ExprKind::Call(func7, args7) = elements2[3].kind - && paths::CORE_FMT_RT_PIECE_NUM.matches_path(cx, func7) // Add the path to `clippy_utils::paths` if needed - && args7.len() == 1 - && let ExprKind::Lit(ref lit5) = args7[0].kind - && let LitKind::Int(0, LitIntType::Unsigned(UintTy::Usize)) = lit5.node - && let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Not, inner2) = args2[1].kind + && let ExprKind::ConstBlock(_) = args3[0].kind + && let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Not, inner1) = args2[1].kind && block1.expr.is_none() && block.expr.is_none() { diff --git a/tests/codegen-units/item-collection/opaque-return-impls.rs b/tests/codegen-units/item-collection/opaque-return-impls.rs index 7d5f4f5b66982..2859e16799189 100644 --- a/tests/codegen-units/item-collection/opaque-return-impls.rs +++ b/tests/codegen-units/item-collection/opaque-return-impls.rs @@ -86,4 +86,4 @@ pub fn foo3() -> Box> { //~ MONO_ITEM fn foo3 //~ MONO_ITEM fn std::boxed::Box::::new //~ MONO_ITEM fn Counter::new -//~ MONO_ITEM fn core::fmt::rt::>::new_const::<1> +//~ MONO_ITEM fn core::fmt::rt::>::from_str diff --git a/tests/mir-opt/sroa/lifetimes.foo.ScalarReplacementOfAggregates.diff b/tests/mir-opt/sroa/lifetimes.foo.ScalarReplacementOfAggregates.diff index 3a0ddd135b6c2..171a984456481 100644 --- a/tests/mir-opt/sroa/lifetimes.foo.ScalarReplacementOfAggregates.diff +++ b/tests/mir-opt/sroa/lifetimes.foo.ScalarReplacementOfAggregates.diff @@ -20,28 +20,20 @@ let mut _20: core::fmt::rt::Template<'_>; let mut _21: &[core::fmt::rt::Piece; 7]; let _22: &[core::fmt::rt::Piece; 7]; - let _23: [core::fmt::rt::Piece; 7]; - let mut _24: core::fmt::rt::Piece; - let mut _25: core::fmt::rt::Piece; - let mut _26: core::fmt::rt::Piece; - let mut _27: core::fmt::rt::Piece; - let mut _28: core::fmt::rt::Piece; - let mut _29: core::fmt::rt::Piece; - let mut _30: core::fmt::rt::Piece; - let mut _31: &[core::fmt::rt::Argument<'_>; 2]; - let _32: &[core::fmt::rt::Argument<'_>; 2]; - let mut _34: &std::boxed::Box; - let mut _35: &u32; - let mut _36: bool; - let mut _37: isize; - let mut _38: isize; - let mut _39: isize; -+ let _40: std::result::Result, ::Err>; -+ let _41: u32; + let mut _23: &[core::fmt::rt::Argument<'_>; 2]; + let _24: &[core::fmt::rt::Argument<'_>; 2]; + let mut _25: &std::boxed::Box; + let mut _26: &u32; + let mut _27: bool; + let mut _28: isize; + let mut _29: isize; + let mut _30: isize; ++ let _31: std::result::Result, ::Err>; ++ let _32: u32; scope 1 { - debug foo => _1; -+ debug ((foo: Foo).0: std::result::Result, ::Err>) => _40; -+ debug ((foo: Foo).1: u32) => _41; ++ debug ((foo: Foo).0: std::result::Result, ::Err>) => _31; ++ debug ((foo: Foo).1: u32) => _32; let _5: std::result::Result, ::Err>; scope 2 { debug x => _5; @@ -52,16 +44,15 @@ debug x => _8; let _8: std::boxed::Box; let _12: (&std::boxed::Box, &u32); -+ let _42: &std::boxed::Box; -+ let _43: &u32; ++ let _33: &std::boxed::Box; ++ let _34: &u32; scope 5 { - debug args => _12; -+ debug ((args: (&Box, &u32)).0: &std::boxed::Box) => _42; -+ debug ((args: (&Box, &u32)).1: &u32) => _43; ++ debug ((args: (&Box, &u32)).0: &std::boxed::Box) => _33; ++ debug ((args: (&Box, &u32)).1: &u32) => _34; let _15: [core::fmt::rt::Argument<'_>; 2]; scope 6 { debug args => _15; - let mut _33: &[core::fmt::rt::Piece; 7]; } } } @@ -70,10 +61,10 @@ } bb0: { - _36 = const false; + _27 = const false; - StorageLive(_1); -+ StorageLive(_40); -+ StorageLive(_41); ++ StorageLive(_31); ++ StorageLive(_32); + nop; StorageLive(_2); StorageLive(_3); @@ -87,17 +78,17 @@ _2 = Result::, ::Err>::Ok(move _3); StorageDead(_3); - _1 = Foo:: { x: move _2, y: const 7_u32 }; -+ _40 = move _2; -+ _41 = const 7_u32; ++ _31 = move _2; ++ _32 = const 7_u32; + nop; StorageDead(_2); StorageLive(_5); - _36 = const true; + _27 = const true; - _5 = move (_1.0: std::result::Result, ::Err>); -+ _5 = move _40; ++ _5 = move _31; StorageLive(_6); - _6 = copy (_1.1: u32); -+ _6 = copy _41; ++ _6 = copy _32; _7 = discriminant(_5); switchInt(move _7) -> [0: bb2, otherwise: bb8]; } @@ -109,25 +100,25 @@ StorageLive(_10); StorageLive(_11); - StorageLive(_12); -+ StorageLive(_42); -+ StorageLive(_43); ++ StorageLive(_33); ++ StorageLive(_34); + nop; StorageLive(_13); _13 = &_8; StorageLive(_14); _14 = &_6; - _12 = (move _13, move _14); -+ _42 = move _13; -+ _43 = move _14; ++ _33 = move _13; ++ _34 = move _14; + nop; StorageDead(_14); StorageDead(_13); StorageLive(_15); StorageLive(_16); StorageLive(_17); -- _34 = copy (_12.0: &std::boxed::Box); -+ _34 = copy _42; - _17 = &(*_34); +- _25 = copy (_12.0: &std::boxed::Box); ++ _25 = copy _33; + _17 = &(*_25); _16 = core::fmt::rt::Argument::<'_>::new_display::>(move _17) -> [return: bb3, unwind unreachable]; } @@ -135,9 +126,9 @@ StorageDead(_17); StorageLive(_18); StorageLive(_19); -- _35 = copy (_12.1: &u32); -+ _35 = copy _43; - _19 = &(*_35); +- _26 = copy (_12.1: &u32); ++ _26 = copy _34; + _19 = &(*_26); _18 = core::fmt::rt::Argument::<'_>::new_display::(move _19) -> [return: bb4, unwind unreachable]; } @@ -149,8 +140,7 @@ StorageLive(_20); StorageLive(_21); StorageLive(_22); - _33 = const foo::::promoted[0]; - _22 = &(*_33); + _22 = const foo::::{constant#0}::<&[core::fmt::rt::Piece; 7]>; _21 = &(*_22); _20 = core::fmt::rt::Template::<'_>::new::<7>(move _21) -> [return: bb5, unwind unreachable]; } @@ -158,16 +148,16 @@ bb5: { StorageDead(_22); StorageDead(_21); - StorageLive(_31); - StorageLive(_32); - _32 = &_15; - _31 = &(*_32); - _11 = core::fmt::rt::>::new::<2>(move _20, move _31) -> [return: bb6, unwind unreachable]; + StorageLive(_23); + StorageLive(_24); + _24 = &_15; + _23 = &(*_24); + _11 = core::fmt::rt::>::new::<2>(move _20, move _23) -> [return: bb6, unwind unreachable]; } bb6: { - StorageDead(_32); - StorageDead(_31); + StorageDead(_24); + StorageDead(_23); StorageDead(_20); _10 = _eprint(move _11) -> [return: bb7, unwind unreachable]; } @@ -176,8 +166,8 @@ StorageDead(_11); StorageDead(_15); - StorageDead(_12); -+ StorageDead(_42); -+ StorageDead(_43); ++ StorageDead(_33); ++ StorageDead(_34); + nop; StorageDead(_10); _9 = const (); @@ -198,16 +188,16 @@ bb10: { StorageDead(_6); - _37 = discriminant(_5); - switchInt(move _37) -> [0: bb11, otherwise: bb12]; + _28 = discriminant(_5); + switchInt(move _28) -> [0: bb11, otherwise: bb12]; } bb11: { - _36 = const false; + _27 = const false; StorageDead(_5); - StorageDead(_1); -+ StorageDead(_40); -+ StorageDead(_41); ++ StorageDead(_31); ++ StorageDead(_32); + nop; return; } diff --git a/tests/ui/consts/recursive-const-in-impl.stderr b/tests/ui/consts/recursive-const-in-impl.stderr index 035d9c2f21c5a..ec5ad52fadd42 100644 --- a/tests/ui/consts/recursive-const-in-impl.stderr +++ b/tests/ui/consts/recursive-const-in-impl.stderr @@ -5,7 +5,7 @@ LL | println!("{}", Thing::::X); | ^^^^^^^^^^^^^^^ | = help: consider increasing the recursion limit by adding a `#![recursion_limit = "14"]` attribute to your crate (`recursive_const_in_impl`) - = note: query depth increased by 9 when simplifying constant for the type system `main::promoted[1]` + = note: query depth increased by 9 when simplifying constant for the type system `main::promoted[0]` = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to 1 previous error diff --git a/tests/ui/unpretty/exhaustive.hir.stdout b/tests/ui/unpretty/exhaustive.hir.stdout index 0b3256cdb1f14..3efc6c582a91a 100644 --- a/tests/ui/unpretty/exhaustive.hir.stdout +++ b/tests/ui/unpretty/exhaustive.hir.stdout @@ -395,8 +395,9 @@ mod expressions { super let args = (&expr,); super let args = [format_argument::new_display(args.0)]; format_arguments::new(unsafe { - format_template::new(&[format_piece::num(16140901201934811136usize), - format_piece::num(0usize)]) + format_template::new(const + &[format_piece::num(16140901201934811136usize), + format_piece::num(0usize)]) }, &args) }; } diff --git a/tests/ui/unpretty/flattened-format-args.stdout b/tests/ui/unpretty/flattened-format-args.stdout index e50086d464832..46890c30528c3 100644 --- a/tests/ui/unpretty/flattened-format-args.stdout +++ b/tests/ui/unpretty/flattened-format-args.stdout @@ -14,9 +14,10 @@ fn main() { super let args = (&x,); super let args = [format_argument::new_display(args.0)]; format_arguments::new(unsafe { - format_template::new(&[format_piece::num(8usize), - format_piece::str("a 123 b "), format_piece::num(5usize), - format_piece::str(" xyz\n"), format_piece::num(0usize)]) + format_template::new(const + &[format_piece::num(8usize), format_piece::str("a 123 b "), + format_piece::num(5usize), format_piece::str(" xyz\n"), + format_piece::num(0usize)]) }, &args) }); }; From efeeca49f083f12d925a3532bab98c1e3816e2aa Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Thu, 6 Nov 2025 18:00:44 +0100 Subject: [PATCH 13/13] Simplify format_args!() expansion. --- compiler/rustc_ast_lowering/src/format.rs | 40 +++--- .../rustc_const_eval/src/check_consts/ops.rs | 4 +- compiler/rustc_hir/src/lang_items.rs | 1 - compiler/rustc_span/src/symbol.rs | 4 +- library/core/src/fmt/rt.rs | 21 ++-- ...mes.foo.ScalarReplacementOfAggregates.diff | 119 +++++++++--------- tests/ui/unpretty/exhaustive.hir.stdout | 10 +- .../ui/unpretty/flattened-format-args.stdout | 12 +- 8 files changed, 100 insertions(+), 111 deletions(-) diff --git a/compiler/rustc_ast_lowering/src/format.rs b/compiler/rustc_ast_lowering/src/format.rs index 7ef8774a72eed..c7b0e852505ac 100644 --- a/compiler/rustc_ast_lowering/src/format.rs +++ b/compiler/rustc_ast_lowering/src/format.rs @@ -524,19 +524,6 @@ fn expand_format_args<'hir>( let zero = ctx.expr_usize(macsp, 0); pieces.push(make_piece(ctx, sym::num, zero, macsp)); - // ``` - // unsafe { ::new(const { &[pieces…] }) } - // ``` - let template_new = - ctx.expr_lang_item_type_relative(macsp, hir::LangItem::FormatTemplate, sym::new); - let pieces = ctx.expr_array_ref(macsp, ctx.arena.alloc_from_iter(pieces)); - let pieces = ctx.expr_const(macsp, pieces); - let template = ctx.expr( - macsp, - hir::ExprKind::Call(ctx.arena.alloc(template_new), ctx.arena.alloc_from_iter([pieces])), - ); - let template = ctx.expr_unsafe(macsp, ctx.arena.alloc(template)); - // Ensure all argument indexes actually fit in 10 bits, as we truncated them to 10 bits before. if argmap.len() >= 1 << 10 { ctx.dcx().emit_err(TooManyFormatArguments { span: fmt.span }); @@ -615,10 +602,14 @@ fn expand_format_args<'hir>( }; // Generate: - // ::new( - // template, - // &args, - // ) + // unsafe { + // ::new( + // const { &[pieces…] }, + // &args, + // ) + // } + let pieces = ctx.expr_array_ref(macsp, ctx.arena.alloc_from_iter(pieces)); + let pieces = ctx.expr_const(macsp, pieces); let call = { let new = ctx.arena.alloc(ctx.expr_lang_item_type_relative( macsp, @@ -626,9 +617,20 @@ fn expand_format_args<'hir>( sym::new, )); let args = ctx.expr_ref(macsp, args); - let new_args = ctx.arena.alloc_from_iter([template, args]); - hir::ExprKind::Call(new, new_args) + let new_args = ctx.arena.alloc_from_iter([pieces, args]); + ctx.expr_call(macsp, new, new_args) }; + let call = hir::ExprKind::Block( + ctx.arena.alloc(hir::Block { + stmts: &[], + expr: Some(call), + hir_id: ctx.next_id(), + rules: hir::BlockCheckMode::UnsafeBlock(hir::UnsafeSource::CompilerGenerated), + span: macsp, + targeted_by_break: false, + }), + None, + ); if !let_statements.is_empty() { // Generate: diff --git a/compiler/rustc_const_eval/src/check_consts/ops.rs b/compiler/rustc_const_eval/src/check_consts/ops.rs index cddf0bf80c4de..d81b31b704b3d 100644 --- a/compiler/rustc_const_eval/src/check_consts/ops.rs +++ b/compiler/rustc_const_eval/src/check_consts/ops.rs @@ -345,9 +345,7 @@ fn build_error_for_const_call<'tcx>( note_trait_if_possible(&mut err, self_ty, tcx.require_lang_item(LangItem::Deref, span)); err } - _ if tcx.is_diagnostic_item(sym::FmtTemplateNew, callee) - || tcx.is_diagnostic_item(sym::FmtArgumentsFromStrNonconst, callee) => - { + _ if tcx.opt_parent(callee) == tcx.get_diagnostic_item(sym::FmtArgumentsNew) => { ccx.dcx().create_err(errors::NonConstFmtMacroCall { span, kind: ccx.const_kind(), diff --git a/compiler/rustc_hir/src/lang_items.rs b/compiler/rustc_hir/src/lang_items.rs index 81fdd64d34a0f..b056a529226c1 100644 --- a/compiler/rustc_hir/src/lang_items.rs +++ b/compiler/rustc_hir/src/lang_items.rs @@ -329,7 +329,6 @@ language_item_table! { FormatArgument, sym::format_argument, format_argument, Target::Struct, GenericRequirement::None; FormatArguments, sym::format_arguments, format_arguments, Target::Struct, GenericRequirement::None; FormatPiece, sym::format_piece, format_piece, Target::Union, GenericRequirement::None; - FormatTemplate, sym::format_template, format_template, Target::Struct, GenericRequirement::None; ExchangeMalloc, sym::exchange_malloc, exchange_malloc_fn, Target::Fn, GenericRequirement::None; DropInPlace, sym::drop_in_place, drop_in_place_fn, Target::Fn, GenericRequirement::Minimum(1); diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index e2ae2eb3ba06a..c567fe44c6828 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -235,8 +235,7 @@ symbols! { Error, File, FileType, - FmtArgumentsFromStrNonconst, - FmtTemplateNew, + FmtArgumentsNew, FmtWrite, Fn, FnMut, @@ -1095,7 +1094,6 @@ symbols! { format_arguments, format_macro, format_piece, - format_template, framework, freeze, freeze_impls, diff --git a/library/core/src/fmt/rt.rs b/library/core/src/fmt/rt.rs index 5227a458f7751..d2ee01ede8afe 100644 --- a/library/core/src/fmt/rt.rs +++ b/library/core/src/fmt/rt.rs @@ -12,7 +12,6 @@ use crate::marker::PhantomData; use crate::mem; use crate::ptr::NonNull; -#[lang = "format_template"] #[derive(Copy, Clone)] pub struct Template<'a> { pub(super) pieces: NonNull, @@ -24,7 +23,6 @@ unsafe impl Sync for Template<'_> {} impl<'a> Template<'a> { #[inline] - #[rustc_diagnostic_item = "FmtTemplateNew"] pub unsafe fn new(pieces: &'a [rt::Piece; N]) -> Self { Self { pieces: NonNull::from_ref(pieces).cast(), lifetime: PhantomData } } @@ -232,23 +230,25 @@ impl Argument<'_> { /// Used by the format_args!() macro to create a fmt::Arguments object. #[doc(hidden)] +#[rustc_diagnostic_item = "FmtArgumentsNew"] impl<'a> Arguments<'a> { #[inline] - pub const fn new( - template: rt::Template<'a>, - args: &'a [rt::Argument<'a>; N], + pub unsafe fn new( + pieces: &'a [rt::Piece; N], + args: &'a [rt::Argument<'a>; M], ) -> Arguments<'a> { - Arguments { template, args: NonNull::from_ref(args).cast() } + Arguments { + // SAFETY: Responsibility of the caller. + template: unsafe { Template::new(pieces) }, + args: NonNull::from_ref(args).cast(), + } } #[inline] pub const fn from_str(s: &'static str) -> Arguments<'a> { // SAFETY: This is the "static str" representation of fmt::Arguments. unsafe { - Arguments { - template: rt::Template::new_str_len(s.len()), - args: mem::transmute(s.as_ptr()), - } + Arguments { template: Template::new_str_len(s.len()), args: mem::transmute(s.as_ptr()) } } } @@ -256,7 +256,6 @@ impl<'a> Arguments<'a> { // Used by format_args!() expansion when arguments are inlined, // e.g. format_args!("{}", 123), which is not allowed in const. #[inline] - #[rustc_diagnostic_item = "FmtArgumentsFromStrNonconst"] pub fn from_str_nonconst(s: &'static str) -> Arguments<'a> { Arguments::from_str(s) } diff --git a/tests/mir-opt/sroa/lifetimes.foo.ScalarReplacementOfAggregates.diff b/tests/mir-opt/sroa/lifetimes.foo.ScalarReplacementOfAggregates.diff index 171a984456481..a01ea1e6c9433 100644 --- a/tests/mir-opt/sroa/lifetimes.foo.ScalarReplacementOfAggregates.diff +++ b/tests/mir-opt/sroa/lifetimes.foo.ScalarReplacementOfAggregates.diff @@ -17,23 +17,22 @@ let mut _17: &std::boxed::Box; let mut _18: core::fmt::rt::Argument<'_>; let mut _19: &u32; - let mut _20: core::fmt::rt::Template<'_>; - let mut _21: &[core::fmt::rt::Piece; 7]; - let _22: &[core::fmt::rt::Piece; 7]; - let mut _23: &[core::fmt::rt::Argument<'_>; 2]; - let _24: &[core::fmt::rt::Argument<'_>; 2]; - let mut _25: &std::boxed::Box; - let mut _26: &u32; - let mut _27: bool; + let mut _20: &[core::fmt::rt::Piece; 7]; + let _21: &[core::fmt::rt::Piece; 7]; + let mut _22: &[core::fmt::rt::Argument<'_>; 2]; + let _23: &[core::fmt::rt::Argument<'_>; 2]; + let mut _24: &std::boxed::Box; + let mut _25: &u32; + let mut _26: bool; + let mut _27: isize; let mut _28: isize; let mut _29: isize; - let mut _30: isize; -+ let _31: std::result::Result, ::Err>; -+ let _32: u32; ++ let _30: std::result::Result, ::Err>; ++ let _31: u32; scope 1 { - debug foo => _1; -+ debug ((foo: Foo).0: std::result::Result, ::Err>) => _31; -+ debug ((foo: Foo).1: u32) => _32; ++ debug ((foo: Foo).0: std::result::Result, ::Err>) => _30; ++ debug ((foo: Foo).1: u32) => _31; let _5: std::result::Result, ::Err>; scope 2 { debug x => _5; @@ -44,12 +43,12 @@ debug x => _8; let _8: std::boxed::Box; let _12: (&std::boxed::Box, &u32); -+ let _33: &std::boxed::Box; -+ let _34: &u32; ++ let _32: &std::boxed::Box; ++ let _33: &u32; scope 5 { - debug args => _12; -+ debug ((args: (&Box, &u32)).0: &std::boxed::Box) => _33; -+ debug ((args: (&Box, &u32)).1: &u32) => _34; ++ debug ((args: (&Box, &u32)).0: &std::boxed::Box) => _32; ++ debug ((args: (&Box, &u32)).1: &u32) => _33; let _15: [core::fmt::rt::Argument<'_>; 2]; scope 6 { debug args => _15; @@ -61,10 +60,10 @@ } bb0: { - _27 = const false; + _26 = const false; - StorageLive(_1); ++ StorageLive(_30); + StorageLive(_31); -+ StorageLive(_32); + nop; StorageLive(_2); StorageLive(_3); @@ -78,19 +77,19 @@ _2 = Result::, ::Err>::Ok(move _3); StorageDead(_3); - _1 = Foo:: { x: move _2, y: const 7_u32 }; -+ _31 = move _2; -+ _32 = const 7_u32; ++ _30 = move _2; ++ _31 = const 7_u32; + nop; StorageDead(_2); StorageLive(_5); - _27 = const true; + _26 = const true; - _5 = move (_1.0: std::result::Result, ::Err>); -+ _5 = move _31; ++ _5 = move _30; StorageLive(_6); - _6 = copy (_1.1: u32); -+ _6 = copy _32; ++ _6 = copy _31; _7 = discriminant(_5); - switchInt(move _7) -> [0: bb2, otherwise: bb8]; + switchInt(move _7) -> [0: bb2, otherwise: bb7]; } bb2: { @@ -100,25 +99,25 @@ StorageLive(_10); StorageLive(_11); - StorageLive(_12); ++ StorageLive(_32); + StorageLive(_33); -+ StorageLive(_34); + nop; StorageLive(_13); _13 = &_8; StorageLive(_14); _14 = &_6; - _12 = (move _13, move _14); -+ _33 = move _13; -+ _34 = move _14; ++ _32 = move _13; ++ _33 = move _14; + nop; StorageDead(_14); StorageDead(_13); StorageLive(_15); StorageLive(_16); StorageLive(_17); -- _25 = copy (_12.0: &std::boxed::Box); -+ _25 = copy _33; - _17 = &(*_25); +- _24 = copy (_12.0: &std::boxed::Box); ++ _24 = copy _32; + _17 = &(*_24); _16 = core::fmt::rt::Argument::<'_>::new_display::>(move _17) -> [return: bb3, unwind unreachable]; } @@ -126,9 +125,9 @@ StorageDead(_17); StorageLive(_18); StorageLive(_19); -- _26 = copy (_12.1: &u32); -+ _26 = copy _34; - _19 = &(*_26); +- _25 = copy (_12.1: &u32); ++ _25 = copy _33; + _19 = &(*_25); _18 = core::fmt::rt::Argument::<'_>::new_display::(move _19) -> [return: bb4, unwind unreachable]; } @@ -139,71 +138,65 @@ StorageDead(_16); StorageLive(_20); StorageLive(_21); + _21 = const foo::::{constant#0}::<&[core::fmt::rt::Piece; 7]>; + _20 = &(*_21); StorageLive(_22); - _22 = const foo::::{constant#0}::<&[core::fmt::rt::Piece; 7]>; - _21 = &(*_22); - _20 = core::fmt::rt::Template::<'_>::new::<7>(move _21) -> [return: bb5, unwind unreachable]; + StorageLive(_23); + _23 = &_15; + _22 = &(*_23); + _11 = core::fmt::rt::>::new::<7, 2>(move _20, move _22) -> [return: bb5, unwind unreachable]; } bb5: { + StorageDead(_23); StorageDead(_22); StorageDead(_21); - StorageLive(_23); - StorageLive(_24); - _24 = &_15; - _23 = &(*_24); - _11 = core::fmt::rt::>::new::<2>(move _20, move _23) -> [return: bb6, unwind unreachable]; - } - - bb6: { - StorageDead(_24); - StorageDead(_23); StorageDead(_20); - _10 = _eprint(move _11) -> [return: bb7, unwind unreachable]; + _10 = _eprint(move _11) -> [return: bb6, unwind unreachable]; } - bb7: { + bb6: { StorageDead(_11); StorageDead(_15); - StorageDead(_12); ++ StorageDead(_32); + StorageDead(_33); -+ StorageDead(_34); + nop; StorageDead(_10); _9 = const (); StorageDead(_9); _0 = const (); - drop(_8) -> [return: bb9, unwind unreachable]; + drop(_8) -> [return: bb8, unwind unreachable]; } - bb8: { + bb7: { _0 = const (); - goto -> bb10; + goto -> bb9; } - bb9: { + bb8: { StorageDead(_8); - goto -> bb10; + goto -> bb9; } - bb10: { + bb9: { StorageDead(_6); - _28 = discriminant(_5); - switchInt(move _28) -> [0: bb11, otherwise: bb12]; + _27 = discriminant(_5); + switchInt(move _27) -> [0: bb10, otherwise: bb11]; } - bb11: { - _27 = const false; + bb10: { + _26 = const false; StorageDead(_5); - StorageDead(_1); ++ StorageDead(_30); + StorageDead(_31); -+ StorageDead(_32); + nop; return; } - bb12: { - drop(_5) -> [return: bb11, unwind unreachable]; + bb11: { + drop(_5) -> [return: bb10, unwind unreachable]; } } diff --git a/tests/ui/unpretty/exhaustive.hir.stdout b/tests/ui/unpretty/exhaustive.hir.stdout index 3efc6c582a91a..2dd595014046f 100644 --- a/tests/ui/unpretty/exhaustive.hir.stdout +++ b/tests/ui/unpretty/exhaustive.hir.stdout @@ -394,11 +394,11 @@ mod expressions { { super let args = (&expr,); super let args = [format_argument::new_display(args.0)]; - format_arguments::new(unsafe { - format_template::new(const - &[format_piece::num(16140901201934811136usize), - format_piece::num(0usize)]) - }, &args) + unsafe { + format_arguments::new(const + &[format_piece::num(16140901201934811136usize), + format_piece::num(0usize)], &args) + } }; } } diff --git a/tests/ui/unpretty/flattened-format-args.stdout b/tests/ui/unpretty/flattened-format-args.stdout index 46890c30528c3..049bb2897efdb 100644 --- a/tests/ui/unpretty/flattened-format-args.stdout +++ b/tests/ui/unpretty/flattened-format-args.stdout @@ -13,12 +13,12 @@ fn main() { ::std::io::_print({ super let args = (&x,); super let args = [format_argument::new_display(args.0)]; - format_arguments::new(unsafe { - format_template::new(const - &[format_piece::num(8usize), format_piece::str("a 123 b "), - format_piece::num(5usize), format_piece::str(" xyz\n"), - format_piece::num(0usize)]) - }, &args) + unsafe { + format_arguments::new(const + &[format_piece::num(8usize), format_piece::str("a 123 b "), + format_piece::num(5usize), format_piece::str(" xyz\n"), + format_piece::num(0usize)], &args) + } }); }; }