Skip to content

Rollup of 18 pull requests #144929

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 109 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
109 commits
Select commit Hold shift + click to select a range
34ddd59
Improve settings tree title and descriptions
joshka Jul 3, 2025
3540446
Fix gen panics doc template for debug_assert
A4-Tacks Jul 25, 2025
1d5a582
refactor: conpare text of name_ref instead of syntax name_ref
Hmikihiro Jul 27, 2025
b3ea82f
Migrate `inline_type_alias` assist to use `SyntaxEditor`
Hmikihiro Jul 27, 2025
b1b7077
remove ted from convert_tuple_struct_to_named_struct
Hmikihiro Jul 26, 2025
85486a7
migrate `fn edit_struct_def` in `convert_tuple_struct_to_named_struct…
Hmikihiro Jul 26, 2025
8f89872
Migrate `convert_tuple_struct_to_named_struct' assist to use `SyntaxE…
Hmikihiro Jul 27, 2025
3e6f950
avoid the need to specify if toc should be generated
tshepang Jul 17, 2025
65589ad
remove the markers
tshepang Jul 28, 2025
b4b9f3e
Merge pull request #20300 from A4-Tacks/fix-debug_assert-doc-gen
ChayimFriedman2 Jul 29, 2025
8b214fb
fix: Do not require all rename definitions to be renameable
Veykril Jul 29, 2025
e45400a
Merge pull request #20333 from Veykril/push-xmulpqkxrytn
Veykril Jul 29, 2025
1532b37
Use GH app for authenticating sync PRs
Kobzol Jul 29, 2025
f7c3a89
Merge pull request #20335 from Kobzol/ci-gh-app
lnicola Jul 29, 2025
bad05ff
In generate_mut_trait_impl, don't add a tabstop if the client does no…
ChayimFriedman2 Jul 29, 2025
f5ecbb5
Merge pull request #20336 from ChayimFriedman2/mut-trait-impl-snippet
Veykril Jul 29, 2025
5043dc9
Merge pull request #20154 from joshka/jm/improve-setting-titles
Veykril Jul 29, 2025
ea1e24a
When displaying a projection into a type parameter that has bounds as…
ChayimFriedman2 Jul 29, 2025
b2d9f17
Merge pull request #20337 from ChayimFriedman2/double-inlay-hints
Veykril Jul 29, 2025
cca89bc
add `SyntaxFactory::record_expr` to hide clone_for_update
Hmikihiro Jul 29, 2025
08c6768
replace `make::` to `SyntaxFactory::` in `inline_type_alias`
Hmikihiro Jul 29, 2025
a9c4316
Merge pull request #20311 from Hmikihiro/migrate_convert_tuple_struct…
ShoyuVanilla Jul 30, 2025
cd0f643
Merge pull request #20314 from Hmikihiro/Migrate_inline_type_alias_to…
ShoyuVanilla Jul 30, 2025
2918a2b
Abtract away json protocol for proc-macro-srv
Veykril Jul 30, 2025
d71e972
add `SyntaxEditor::delete_all` to migrate utils.rs `add_trait_assoc_i…
Hmikihiro Jul 29, 2025
8971681
Properly clean proc-macro-srv proc-macro temp dir
Veykril Jul 31, 2025
1975c98
Reorganize proc-macro-srv
Veykril Jul 31, 2025
7543395
Add version command to proc-macro-srv
Veykril Jul 31, 2025
6bf9700
Merge pull request #20342 from Veykril/push-zysqtqskuxvr
Veykril Jul 31, 2025
a7b01aa
`cargo clippy --fix`
Veykril Jul 31, 2025
ddc1b9f
Merge pull request #20349 from Veykril/push-orvqsnqtttzv
Veykril Jul 31, 2025
7c60865
Merge pull request #20345 from Hmikihiro/Migrate_add_trait_assoc_item…
ShoyuVanilla Jul 31, 2025
a6d1842
libtest: print the type of test being run
lolbinarycat Jul 28, 2025
053f681
Update documentation for overrideCommand config options
iorizu Aug 1, 2025
7d16726
Fix more docs
iorizu Aug 1, 2025
f516d4c
rustdoc font links only emit `crossorigin` when needed
MingweiSamuel Jul 25, 2025
5b03d07
Pull out unexpected extension check into own function
jieyouxu Aug 2, 2025
c10dc99
Pull out stray/empty output snapshot checks into own functions
jieyouxu Aug 2, 2025
a714288
Pull out non-descriptive test name check to own function
jieyouxu Aug 2, 2025
a97d0aa
Make `issues_txt_header` a const
jieyouxu Aug 2, 2025
fa31c7d
Pull out recursive ui test check into its own function
jieyouxu Aug 2, 2025
0b1547e
Reject adding new UI tests directly under `tests/ui/`
jieyouxu Aug 2, 2025
81c4086
Migrate `convert_from_to_tryfrom` assist to use `SyntaxEditor`
Hmikihiro Aug 2, 2025
5ebb0dd
update doc
Kivooeo Aug 2, 2025
700e063
Merge pull request #2531 from Kivooeo/update-doc
BoxyUwU Aug 2, 2025
e314bfa
Migrate `generate_delegate_methods` assist to use `SyntaxEditor`
Hmikihiro Aug 2, 2025
4c6e804
Merge pull request #20358 from iorizu/issue-20346
ChayimFriedman2 Aug 2, 2025
ac34f3d
When renaming a parameter to `self`, change callers to use method cal…
ChayimFriedman2 Jul 31, 2025
f360d6c
Merge pull request #20351 from ChayimFriedman2/rename-self1
Veykril Aug 2, 2025
807d340
Rehome tests/ui/issues/ tests [2/?]
Oneirical Jul 13, 2025
3bba46b
Merge pull request #2509 from rust-lang/tshepang-auto-toc
tshepang Aug 3, 2025
f84c621
there is still no official policy
tshepang Aug 3, 2025
279b464
Merge pull request #20364 from Hmikihiro/migrate_convert_from_to_tryfrom
Veykril Aug 3, 2025
e47f791
Merge pull request #20368 from Hmikihiro/migrate_delegate_methods
Veykril Aug 3, 2025
b373cb1
Migrate `generate_trait_from_impl` assist to use `SyntaxEditor`
Hmikihiro Aug 3, 2025
0d2a7e6
Merge pull request #20371 from Hmikihiro/migrate_generate_trait_from_…
Veykril Aug 3, 2025
7888458
Merge pull request #2532 from rust-lang/tshepang/date-check
Noratrieb Aug 3, 2025
df52416
Mark `Printer` methods as unreachable where appropriate.
nnethercote Jul 31, 2025
bd0a308
Inline and remove two `FmtPrinter` methods.
nnethercote Jul 31, 2025
e7d6a07
Remove `type_name::AbsolutePathPrinter::comma_sep`.
nnethercote Jul 31, 2025
1698c8e
Rename `Printer` variables.
nnethercote Aug 1, 2025
03bc1be
Simplify `SymbolMangler::print_type`.
nnethercote Aug 1, 2025
03dab50
Remove `p!`.
nnethercote Aug 1, 2025
2434d8c
Remove unused arg from `path_append_impl`.
nnethercote Aug 1, 2025
277cf46
Remove unused functions from edit_in_place
Hmikihiro Aug 3, 2025
efbe625
Merge pull request #20372 from Hmikihiro/remove_unused_fn_from_edit_i…
Veykril Aug 3, 2025
754654d
rename rust_panic_without_hook
Kivooeo Aug 3, 2025
7d78968
fix: Error on illegal `[const]`s inside blocks within legal positions
ShoyuVanilla Jul 31, 2025
eee2813
Use `as_array` in PartialEq for arrays
scottmcm Aug 3, 2025
f92934f
Remove `SHOULD_EMIT_LINTS` in favor of `should_emit`
JonathanBrouwer Aug 3, 2025
cf3865f
fix broken doc section link in `poison.rs`
connortsui20 Aug 3, 2025
37922fc
add poisoning documentation to `LazyCell`
connortsui20 Aug 3, 2025
96adb7d
add poisoning documentation to `LazyLock`
connortsui20 Aug 3, 2025
cc62d55
Avoid some code duplication.
nnethercote Aug 3, 2025
33706fc
coverage: Include an `Instance` in `CovfunRecord` for debug messages
Zalathar Aug 2, 2025
16843ce
coverage: Hoist `counter_for_bcb` out of its loop
Zalathar May 9, 2025
51e62a0
coverage: Remove `-Zcoverage-options=no-mir-spans`
Zalathar Aug 2, 2025
fb39d3e
coverage: Push async special case down into `extract_refined_covspans`
Zalathar Aug 2, 2025
f496e83
coverage: Simplify access to debug/testing `-Zcoverage-options` flags
Zalathar Aug 2, 2025
b37c214
coverage: Represent `CovmapVersion` as an enum
Zalathar Aug 3, 2025
b8d1af5
Prepare for merging from rust-lang/rust
invalid-email-address Aug 4, 2025
682a6e1
Merge ref '383b9c447b61' from rust-lang/rust
invalid-email-address Aug 4, 2025
450040f
Implement debugging output of the bootstrap Step graph into a DOT file
Kobzol Aug 1, 2025
2f4b40f
Do not render both cached and uncached edge between two steps
Kobzol Aug 1, 2025
4f94bbf
drive-by cleanup: fix outdated documentation
WaffleLapkin Aug 2, 2025
8b65f3d
properly reject tail calls to `&FnPtr` or `&FnDef`
WaffleLapkin Aug 2, 2025
e3ed3e0
small refactor of `InterpResult`
WaffleLapkin Aug 4, 2025
cf7b674
add `project_fields` helper function
WaffleLapkin Aug 4, 2025
51f60d1
Remove `tcp-stress.rs` test
jieyouxu Aug 4, 2025
a13caaa
Merge pull request #2533 from rust-lang/rustc-pull
tshepang Aug 4, 2025
878acaa
Dont print arg span in MIR dump for tail call
compiler-errors Aug 4, 2025
4004dd4
Rollup merge of #144467 - hydro-project:users/mingwes/rustdoc-fix-cor…
samueltardieu Aug 4, 2025
fbe91ed
Rollup merge of #144548 - Oneirical:uncountable-integer-2, r=jieyouxu
samueltardieu Aug 4, 2025
9113f86
Rollup merge of #144596 - lolbinarycat:libtest-print-doctest-type, r=…
samueltardieu Aug 4, 2025
ac5d43b
Rollup merge of #144741 - ShoyuVanilla:tilde-const-in-block, r=fee1-dead
samueltardieu Aug 4, 2025
2aecc7c
Rollup merge of #144776 - nnethercote:Printer-cleanups, r=cjgillot
samueltardieu Aug 4, 2025
b485592
Rollup merge of #144779 - Kobzol:bootstrap-dot, r=jieyouxu
samueltardieu Aug 4, 2025
c671485
Rollup merge of #144813 - jieyouxu:no-top-level-tests, r=Kobzol
samueltardieu Aug 4, 2025
d630c82
Rollup merge of #144817 - WaffleLapkin:reject-referety, r=Urgau
samueltardieu Aug 4, 2025
2884d7d
Rollup merge of #144852 - Kivooeo:rename-panic, r=m-ou-se
samueltardieu Aug 4, 2025
ed8fbeb
Rollup merge of #144866 - JonathanBrouwer:should_emit_fix, r=jdonszel…
samueltardieu Aug 4, 2025
d3e2aed
Rollup merge of #144867 - scottmcm:more-as-array, r=chenyukang
samueltardieu Aug 4, 2025
d1c6a82
Rollup merge of #144872 - connortsui20:once-poison-docs, r=Amanieu
samueltardieu Aug 4, 2025
d6e8cc2
Rollup merge of #144877 - Zalathar:coverage-various, r=lcnr
samueltardieu Aug 4, 2025
0bc4ce8
Rollup merge of #144887 - lnicola:sync-from-ra, r=lnicola
samueltardieu Aug 4, 2025
d8750a2
Rollup merge of #144890 - WaffleLapkin:project_fields, r=lcnr
samueltardieu Aug 4, 2025
a0c10c8
Rollup merge of #144894 - jieyouxu:chop-thread-cnt, r=ChrisDenton
samueltardieu Aug 4, 2025
3cda94b
Rollup merge of #144905 - tshepang:rdg-sync, r=jieyouxu
samueltardieu Aug 4, 2025
fb1198d
Rollup merge of #144920 - compiler-errors:span-arg, r=lqd
samueltardieu Aug 4, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 4 additions & 0 deletions compiler/rustc_ast_passes/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,10 @@ ast_passes_tilde_const_disallowed = `[const]` is not allowed here
.trait_assoc_ty = associated types in non-`const` traits cannot have `[const]` trait bounds
.trait_impl_assoc_ty = associated types in non-const impls cannot have `[const]` trait bounds
.inherent_assoc_ty = inherent associated types cannot have `[const]` trait bounds
.struct = structs cannot have `[const]` trait bounds
.enum = enums cannot have `[const]` trait bounds
.union = unions cannot have `[const]` trait bounds
.anon_const = anonymous constants cannot have `[const]` trait bounds
.object = trait objects cannot have `[const]` trait bounds
.item = this item cannot have `[const]` trait bounds
Expand Down
47 changes: 31 additions & 16 deletions compiler/rustc_ast_passes/src/ast_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1124,7 +1124,9 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
);
}
}
visit::walk_item(self, item)
self.with_tilde_const(Some(TildeConstReason::Enum { span: item.span }), |this| {
visit::walk_item(this, item)
});
}
ItemKind::Trait(box Trait {
constness,
Expand Down Expand Up @@ -1175,26 +1177,32 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
}
visit::walk_item(self, item)
}
ItemKind::Struct(ident, generics, vdata) => match vdata {
VariantData::Struct { fields, .. } => {
self.visit_attrs_vis_ident(&item.attrs, &item.vis, ident);
self.visit_generics(generics);
walk_list!(self, visit_field_def, fields);
}
_ => visit::walk_item(self, item),
},
ItemKind::Struct(ident, generics, vdata) => {
self.with_tilde_const(Some(TildeConstReason::Struct { span: item.span }), |this| {
match vdata {
VariantData::Struct { fields, .. } => {
this.visit_attrs_vis_ident(&item.attrs, &item.vis, ident);
this.visit_generics(generics);
walk_list!(this, visit_field_def, fields);
}
_ => visit::walk_item(this, item),
}
})
}
ItemKind::Union(ident, generics, vdata) => {
if vdata.fields().is_empty() {
self.dcx().emit_err(errors::FieldlessUnion { span: item.span });
}
match vdata {
VariantData::Struct { fields, .. } => {
self.visit_attrs_vis_ident(&item.attrs, &item.vis, ident);
self.visit_generics(generics);
walk_list!(self, visit_field_def, fields);
self.with_tilde_const(Some(TildeConstReason::Union { span: item.span }), |this| {
match vdata {
VariantData::Struct { fields, .. } => {
this.visit_attrs_vis_ident(&item.attrs, &item.vis, ident);
this.visit_generics(generics);
walk_list!(this, visit_field_def, fields);
}
_ => visit::walk_item(this, item),
}
_ => visit::walk_item(self, item),
}
});
}
ItemKind::Const(box ConstItem { defaultness, expr, .. }) => {
self.check_defaultness(item.span, *defaultness);
Expand Down Expand Up @@ -1623,6 +1631,13 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
_ => self.with_in_trait_impl(None, |this| visit::walk_assoc_item(this, item, ctxt)),
}
}

fn visit_anon_const(&mut self, anon_const: &'a AnonConst) {
self.with_tilde_const(
Some(TildeConstReason::AnonConst { span: anon_const.value.span }),
|this| visit::walk_anon_const(this, anon_const),
)
}
}

/// When encountering an equality constraint in a `where` clause, emit an error. If the code seems
Expand Down
20 changes: 20 additions & 0 deletions compiler/rustc_ast_passes/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,26 @@ pub(crate) enum TildeConstReason {
#[primary_span]
span: Span,
},
#[note(ast_passes_struct)]
Struct {
#[primary_span]
span: Span,
},
#[note(ast_passes_enum)]
Enum {
#[primary_span]
span: Span,
},
#[note(ast_passes_union)]
Union {
#[primary_span]
span: Span,
},
#[note(ast_passes_anon_const)]
AnonConst {
#[primary_span]
span: Span,
},
#[note(ast_passes_object)]
TraitObject,
#[note(ast_passes_item)]
Expand Down
15 changes: 11 additions & 4 deletions compiler/rustc_attr_parsing/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,6 @@ mod private {
#[allow(private_interfaces)]
pub trait Stage: Sized + 'static + Sealed {
type Id: Copy;
const SHOULD_EMIT_LINTS: bool;

fn parsers() -> &'static GroupType<Self>;

Expand All @@ -231,13 +230,14 @@ pub trait Stage: Sized + 'static + Sealed {
sess: &'sess Session,
diag: impl for<'x> Diagnostic<'x>,
) -> ErrorGuaranteed;

fn should_emit(&self) -> ShouldEmit;
}

// allow because it's a sealed trait
#[allow(private_interfaces)]
impl Stage for Early {
type Id = NodeId;
const SHOULD_EMIT_LINTS: bool = false;

fn parsers() -> &'static GroupType<Self> {
&early::ATTRIBUTE_PARSERS
Expand All @@ -253,13 +253,16 @@ impl Stage for Early {
sess.dcx().create_err(diag).delay_as_bug()
}
}

fn should_emit(&self) -> ShouldEmit {
self.emit_errors
}
}

// allow because it's a sealed trait
#[allow(private_interfaces)]
impl Stage for Late {
type Id = HirId;
const SHOULD_EMIT_LINTS: bool = true;

fn parsers() -> &'static GroupType<Self> {
&late::ATTRIBUTE_PARSERS
Expand All @@ -271,6 +274,10 @@ impl Stage for Late {
) -> ErrorGuaranteed {
tcx.dcx().emit_err(diag)
}

fn should_emit(&self) -> ShouldEmit {
ShouldEmit::ErrorsAndLints
}
}

/// used when parsing attributes for miscellaneous things *before* ast lowering
Expand Down Expand Up @@ -309,7 +316,7 @@ impl<'f, 'sess: 'f, S: Stage> SharedContext<'f, 'sess, S> {
/// must be delayed until after HIR is built. This method will take care of the details of
/// that.
pub(crate) fn emit_lint(&mut self, lint: AttributeLintKind, span: Span) {
if !S::SHOULD_EMIT_LINTS {
if !self.stage.should_emit().should_emit() {
return;
}
let id = self.target_id;
Expand Down
16 changes: 8 additions & 8 deletions compiler/rustc_borrowck/src/diagnostics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
/// Return the name of the provided `Ty` (that must be a reference) with a synthesized lifetime
/// name where required.
pub(super) fn get_name_for_ty(&self, ty: Ty<'tcx>, counter: usize) -> String {
let mut printer = ty::print::FmtPrinter::new(self.infcx.tcx, Namespace::TypeNS);
let mut p = ty::print::FmtPrinter::new(self.infcx.tcx, Namespace::TypeNS);

// We need to add synthesized lifetimes where appropriate. We do
// this by hooking into the pretty printer and telling it to label the
Expand All @@ -624,36 +624,36 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
| ty::RePlaceholder(ty::PlaceholderRegion {
bound: ty::BoundRegion { kind: br, .. },
..
}) => printer.region_highlight_mode.highlighting_bound_region(br, counter),
}) => p.region_highlight_mode.highlighting_bound_region(br, counter),
_ => {}
}
}

ty.print(&mut printer).unwrap();
printer.into_buffer()
ty.print(&mut p).unwrap();
p.into_buffer()
}

/// Returns the name of the provided `Ty` (that must be a reference)'s region with a
/// synthesized lifetime name where required.
pub(super) fn get_region_name_for_ty(&self, ty: Ty<'tcx>, counter: usize) -> String {
let mut printer = ty::print::FmtPrinter::new(self.infcx.tcx, Namespace::TypeNS);
let mut p = ty::print::FmtPrinter::new(self.infcx.tcx, Namespace::TypeNS);

let region = if let ty::Ref(region, ..) = ty.kind() {
match region.kind() {
ty::ReBound(_, ty::BoundRegion { kind: br, .. })
| ty::RePlaceholder(ty::PlaceholderRegion {
bound: ty::BoundRegion { kind: br, .. },
..
}) => printer.region_highlight_mode.highlighting_bound_region(br, counter),
}) => p.region_highlight_mode.highlighting_bound_region(br, counter),
_ => {}
}
region
} else {
bug!("ty for annotation of borrow region is not a reference");
};

region.print(&mut printer).unwrap();
printer.into_buffer()
region.print(&mut p).unwrap();
p.into_buffer()
}

/// Add a note to region errors and borrow explanations when higher-ranked regions in predicates
Expand Down
47 changes: 32 additions & 15 deletions compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use std::assert_matches::assert_matches;
use std::sync::Arc;

use itertools::Itertools;
use rustc_abi::Align;
use rustc_codegen_ssa::traits::{BaseTypeCodegenMethods, ConstCodegenMethods};
use rustc_data_structures::fx::FxIndexMap;
use rustc_index::IndexVec;
use rustc_macros::TryFromU32;
use rustc_middle::ty::TyCtxt;
use rustc_session::RemapFileNameExt;
use rustc_session::config::RemapPathScopeComponents;
Expand All @@ -20,6 +22,23 @@ mod covfun;
mod spans;
mod unused;

/// Version number that will be included the `__llvm_covmap` section header.
/// Corresponds to LLVM's `llvm::coverage::CovMapVersion` (in `CoverageMapping.h`),
/// or at least the subset that we know and care about.
///
/// Note that version `n` is encoded as `(n-1)`.
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, TryFromU32)]
enum CovmapVersion {
/// Used by LLVM 18 onwards.
Version7 = 6,
}

impl CovmapVersion {
fn to_u32(self) -> u32 {
self as u32
}
}

/// Generates and exports the coverage map, which is embedded in special
/// linker sections in the final binary.
///
Expand All @@ -29,19 +48,13 @@ pub(crate) fn finalize(cx: &mut CodegenCx<'_, '_>) {
let tcx = cx.tcx;

// Ensure that LLVM is using a version of the coverage mapping format that
// agrees with our Rust-side code. Expected versions (encoded as n-1) are:
// - `CovMapVersion::Version7` (6) used by LLVM 18-19
let covmap_version = {
let llvm_covmap_version = llvm_cov::mapping_version();
let expected_versions = 6..=6;
assert!(
expected_versions.contains(&llvm_covmap_version),
"Coverage mapping version exposed by `llvm-wrapper` is out of sync; \
expected {expected_versions:?} but was {llvm_covmap_version}"
);
// This is the version number that we will embed in the covmap section:
llvm_covmap_version
};
// agrees with our Rust-side code. Expected versions are:
// - `Version7` (6) used by LLVM 18 onwards.
let covmap_version =
CovmapVersion::try_from(llvm_cov::mapping_version()).unwrap_or_else(|raw_version: u32| {
panic!("unknown coverage mapping version reported by `llvm-wrapper`: {raw_version}")
});
assert_matches!(covmap_version, CovmapVersion::Version7);

debug!("Generating coverage map for CodegenUnit: `{}`", cx.codegen_unit.name());

Expand Down Expand Up @@ -201,7 +214,11 @@ impl VirtualFileMapping {
/// Generates the contents of the covmap record for this CGU, which mostly
/// consists of a header and a list of filenames. The record is then stored
/// as a global variable in the `__llvm_covmap` section.
fn generate_covmap_record<'ll>(cx: &mut CodegenCx<'ll, '_>, version: u32, filenames_buffer: &[u8]) {
fn generate_covmap_record<'ll>(
cx: &mut CodegenCx<'ll, '_>,
version: CovmapVersion,
filenames_buffer: &[u8],
) {
// A covmap record consists of four target-endian u32 values, followed by
// the encoded filenames table. Two of the header fields are unused in
// modern versions of the LLVM coverage mapping format, and are always 0.
Expand All @@ -212,7 +229,7 @@ fn generate_covmap_record<'ll>(cx: &mut CodegenCx<'ll, '_>, version: u32, filena
cx.const_u32(0), // (unused)
cx.const_u32(filenames_buffer.len() as u32),
cx.const_u32(0), // (unused)
cx.const_u32(version),
cx.const_u32(version.to_u32()),
],
/* packed */ false,
);
Expand Down
29 changes: 17 additions & 12 deletions compiler/rustc_codegen_llvm/src/coverageinfo/mapgen/covfun.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ use crate::llvm;
/// the final record that will be embedded in the `__llvm_covfun` section.
#[derive(Debug)]
pub(crate) struct CovfunRecord<'tcx> {
/// Not used directly, but helpful in debug messages.
_instance: Instance<'tcx>,

mangled_function_name: &'tcx str,
source_hash: u64,
is_used: bool,
Expand Down Expand Up @@ -55,6 +58,7 @@ pub(crate) fn prepare_covfun_record<'tcx>(
let expressions = prepare_expressions(ids_info);

let mut covfun = CovfunRecord {
_instance: instance,
mangled_function_name: tcx.symbol_name(instance).name,
source_hash: if is_used { fn_cov_info.function_source_hash } else { 0 },
is_used,
Expand Down Expand Up @@ -102,11 +106,21 @@ fn fill_region_tables<'tcx>(
ids_info: &'tcx CoverageIdsInfo,
covfun: &mut CovfunRecord<'tcx>,
) {
// If this function is unused, replace all counters with zero.
let counter_for_bcb = |bcb: BasicCoverageBlock| -> ffi::Counter {
let term = if covfun.is_used {
ids_info.term_for_bcb[bcb].expect("every BCB in a mapping was given a term")
} else {
CovTerm::Zero
};
ffi::Counter::from_term(term)
};

// Currently a function's mappings must all be in the same file, so use the
// first mapping's span to determine the file.
let source_map = tcx.sess.source_map();
let Some(first_span) = (try { fn_cov_info.mappings.first()?.span }) else {
debug_assert!(false, "function has no mappings: {:?}", covfun.mangled_function_name);
debug_assert!(false, "function has no mappings: {covfun:?}");
return;
};
let source_file = source_map.lookup_source_file(first_span.lo());
Expand All @@ -117,7 +131,7 @@ fn fill_region_tables<'tcx>(
// codegen needs to handle that gracefully to avoid #133606.
// It's hard for tests to trigger this organically, so instead we set
// `-Zcoverage-options=discard-all-spans-in-codegen` to force it to occur.
let discard_all = tcx.sess.coverage_discard_all_spans_in_codegen();
let discard_all = tcx.sess.coverage_options().discard_all_spans_in_codegen;
let make_coords = |span: Span| {
if discard_all { None } else { spans::make_coords(source_map, &source_file, span) }
};
Expand All @@ -133,16 +147,6 @@ fn fill_region_tables<'tcx>(
// For each counter/region pair in this function+file, convert it to a
// form suitable for FFI.
for &Mapping { ref kind, span } in &fn_cov_info.mappings {
// If this function is unused, replace all counters with zero.
let counter_for_bcb = |bcb: BasicCoverageBlock| -> ffi::Counter {
let term = if covfun.is_used {
ids_info.term_for_bcb[bcb].expect("every BCB in a mapping was given a term")
} else {
CovTerm::Zero
};
ffi::Counter::from_term(term)
};

let Some(coords) = make_coords(span) else { continue };
let cov_span = coords.make_coverage_span(local_file_id);

Expand Down Expand Up @@ -184,6 +188,7 @@ pub(crate) fn generate_covfun_record<'tcx>(
covfun: &CovfunRecord<'tcx>,
) {
let &CovfunRecord {
_instance,
mangled_function_name,
source_hash,
is_used,
Expand Down
Loading
Loading