Skip to content

Commit 5bd6cac

Browse files
committed
Auto merge of #144929 - samueltardieu:rollup-n2c14p7, r=samueltardieu
Rollup of 18 pull requests Successful merges: - #144467 (rustdoc template font links only emit `crossorigin` when needed) - #144548 (Rehome 21 `tests/ui/issues/` tests to other subdirectories under `tests/ui/`) - #144596 (libtest: print the type of test being run) - #144741 (fix: Error on illegal `[const]`s inside blocks within legal positions) - #144776 (`Printer` cleanups) - #144779 (Implement debugging output of the bootstrap Step graph into a DOT file) - #144813 (Add a tidy check to prevent adding UI tests directly under `tests/ui/`) - #144817 (Properly reject tail calls to `&FnPtr` or `&FnDef`) - #144852 (Rename `rust_panic_without_hook` to `resume_unwind` ) - #144866 (Remove `SHOULD_EMIT_LINTS` in favor of `should_emit`) - #144867 (Use `as_array` in PartialEq for arrays) - #144872 (Document Poisoning in `LazyCell` and `LazyLock`) - #144877 (coverage: Various small cleanups) - #144887 (`rust-analyzer` subtree update) - #144890 (Add `InterpCx::project_fields`) - #144894 (Delete `tests/ui/threads-sendsync/tcp-stress.rs`) - #144905 (rustc-dev-guide subtree update) - #144920 (Dont print arg span in MIR dump for tail call) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 0060d5a + fb1198d commit 5bd6cac

File tree

481 files changed

+7714
-6384
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

481 files changed

+7714
-6384
lines changed

compiler/rustc_ast_passes/messages.ftl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,10 @@ ast_passes_tilde_const_disallowed = `[const]` is not allowed here
241241
.trait_assoc_ty = associated types in non-`const` traits cannot have `[const]` trait bounds
242242
.trait_impl_assoc_ty = associated types in non-const impls cannot have `[const]` trait bounds
243243
.inherent_assoc_ty = inherent associated types cannot have `[const]` trait bounds
244+
.struct = structs cannot have `[const]` trait bounds
245+
.enum = enums cannot have `[const]` trait bounds
246+
.union = unions cannot have `[const]` trait bounds
247+
.anon_const = anonymous constants cannot have `[const]` trait bounds
244248
.object = trait objects cannot have `[const]` trait bounds
245249
.item = this item cannot have `[const]` trait bounds
246250

compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,7 +1124,9 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
11241124
);
11251125
}
11261126
}
1127-
visit::walk_item(self, item)
1127+
self.with_tilde_const(Some(TildeConstReason::Enum { span: item.span }), |this| {
1128+
visit::walk_item(this, item)
1129+
});
11281130
}
11291131
ItemKind::Trait(box Trait {
11301132
constness,
@@ -1175,26 +1177,32 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
11751177
}
11761178
visit::walk_item(self, item)
11771179
}
1178-
ItemKind::Struct(ident, generics, vdata) => match vdata {
1179-
VariantData::Struct { fields, .. } => {
1180-
self.visit_attrs_vis_ident(&item.attrs, &item.vis, ident);
1181-
self.visit_generics(generics);
1182-
walk_list!(self, visit_field_def, fields);
1183-
}
1184-
_ => visit::walk_item(self, item),
1185-
},
1180+
ItemKind::Struct(ident, generics, vdata) => {
1181+
self.with_tilde_const(Some(TildeConstReason::Struct { span: item.span }), |this| {
1182+
match vdata {
1183+
VariantData::Struct { fields, .. } => {
1184+
this.visit_attrs_vis_ident(&item.attrs, &item.vis, ident);
1185+
this.visit_generics(generics);
1186+
walk_list!(this, visit_field_def, fields);
1187+
}
1188+
_ => visit::walk_item(this, item),
1189+
}
1190+
})
1191+
}
11861192
ItemKind::Union(ident, generics, vdata) => {
11871193
if vdata.fields().is_empty() {
11881194
self.dcx().emit_err(errors::FieldlessUnion { span: item.span });
11891195
}
1190-
match vdata {
1191-
VariantData::Struct { fields, .. } => {
1192-
self.visit_attrs_vis_ident(&item.attrs, &item.vis, ident);
1193-
self.visit_generics(generics);
1194-
walk_list!(self, visit_field_def, fields);
1196+
self.with_tilde_const(Some(TildeConstReason::Union { span: item.span }), |this| {
1197+
match vdata {
1198+
VariantData::Struct { fields, .. } => {
1199+
this.visit_attrs_vis_ident(&item.attrs, &item.vis, ident);
1200+
this.visit_generics(generics);
1201+
walk_list!(this, visit_field_def, fields);
1202+
}
1203+
_ => visit::walk_item(this, item),
11951204
}
1196-
_ => visit::walk_item(self, item),
1197-
}
1205+
});
11981206
}
11991207
ItemKind::Const(box ConstItem { defaultness, expr, .. }) => {
12001208
self.check_defaultness(item.span, *defaultness);
@@ -1623,6 +1631,13 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
16231631
_ => self.with_in_trait_impl(None, |this| visit::walk_assoc_item(this, item, ctxt)),
16241632
}
16251633
}
1634+
1635+
fn visit_anon_const(&mut self, anon_const: &'a AnonConst) {
1636+
self.with_tilde_const(
1637+
Some(TildeConstReason::AnonConst { span: anon_const.value.span }),
1638+
|this| visit::walk_anon_const(this, anon_const),
1639+
)
1640+
}
16261641
}
16271642

16281643
/// When encountering an equality constraint in a `where` clause, emit an error. If the code seems

compiler/rustc_ast_passes/src/errors.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,26 @@ pub(crate) enum TildeConstReason {
623623
#[primary_span]
624624
span: Span,
625625
},
626+
#[note(ast_passes_struct)]
627+
Struct {
628+
#[primary_span]
629+
span: Span,
630+
},
631+
#[note(ast_passes_enum)]
632+
Enum {
633+
#[primary_span]
634+
span: Span,
635+
},
636+
#[note(ast_passes_union)]
637+
Union {
638+
#[primary_span]
639+
span: Span,
640+
},
641+
#[note(ast_passes_anon_const)]
642+
AnonConst {
643+
#[primary_span]
644+
span: Span,
645+
},
626646
#[note(ast_passes_object)]
627647
TraitObject,
628648
#[note(ast_passes_item)]

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,6 @@ mod private {
222222
#[allow(private_interfaces)]
223223
pub trait Stage: Sized + 'static + Sealed {
224224
type Id: Copy;
225-
const SHOULD_EMIT_LINTS: bool;
226225

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

@@ -231,13 +230,14 @@ pub trait Stage: Sized + 'static + Sealed {
231230
sess: &'sess Session,
232231
diag: impl for<'x> Diagnostic<'x>,
233232
) -> ErrorGuaranteed;
233+
234+
fn should_emit(&self) -> ShouldEmit;
234235
}
235236

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

242242
fn parsers() -> &'static GroupType<Self> {
243243
&early::ATTRIBUTE_PARSERS
@@ -253,13 +253,16 @@ impl Stage for Early {
253253
sess.dcx().create_err(diag).delay_as_bug()
254254
}
255255
}
256+
257+
fn should_emit(&self) -> ShouldEmit {
258+
self.emit_errors
259+
}
256260
}
257261

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

264267
fn parsers() -> &'static GroupType<Self> {
265268
&late::ATTRIBUTE_PARSERS
@@ -271,6 +274,10 @@ impl Stage for Late {
271274
) -> ErrorGuaranteed {
272275
tcx.dcx().emit_err(diag)
273276
}
277+
278+
fn should_emit(&self) -> ShouldEmit {
279+
ShouldEmit::ErrorsAndLints
280+
}
274281
}
275282

276283
/// used when parsing attributes for miscellaneous things *before* ast lowering
@@ -309,7 +316,7 @@ impl<'f, 'sess: 'f, S: Stage> SharedContext<'f, 'sess, S> {
309316
/// must be delayed until after HIR is built. This method will take care of the details of
310317
/// that.
311318
pub(crate) fn emit_lint(&mut self, lint: AttributeLintKind, span: Span) {
312-
if !S::SHOULD_EMIT_LINTS {
319+
if !self.stage.should_emit().should_emit() {
313320
return;
314321
}
315322
let id = self.target_id;

compiler/rustc_borrowck/src/diagnostics/mod.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
613613
/// Return the name of the provided `Ty` (that must be a reference) with a synthesized lifetime
614614
/// name where required.
615615
pub(super) fn get_name_for_ty(&self, ty: Ty<'tcx>, counter: usize) -> String {
616-
let mut printer = ty::print::FmtPrinter::new(self.infcx.tcx, Namespace::TypeNS);
616+
let mut p = ty::print::FmtPrinter::new(self.infcx.tcx, Namespace::TypeNS);
617617

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

632-
ty.print(&mut printer).unwrap();
633-
printer.into_buffer()
632+
ty.print(&mut p).unwrap();
633+
p.into_buffer()
634634
}
635635

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

641641
let region = if let ty::Ref(region, ..) = ty.kind() {
642642
match region.kind() {
643643
ty::ReBound(_, ty::BoundRegion { kind: br, .. })
644644
| ty::RePlaceholder(ty::PlaceholderRegion {
645645
bound: ty::BoundRegion { kind: br, .. },
646646
..
647-
}) => printer.region_highlight_mode.highlighting_bound_region(br, counter),
647+
}) => p.region_highlight_mode.highlighting_bound_region(br, counter),
648648
_ => {}
649649
}
650650
region
651651
} else {
652652
bug!("ty for annotation of borrow region is not a reference");
653653
};
654654

655-
region.print(&mut printer).unwrap();
656-
printer.into_buffer()
655+
region.print(&mut p).unwrap();
656+
p.into_buffer()
657657
}
658658

659659
/// Add a note to region errors and borrow explanations when higher-ranked regions in predicates

compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
use std::assert_matches::assert_matches;
12
use std::sync::Arc;
23

34
use itertools::Itertools;
45
use rustc_abi::Align;
56
use rustc_codegen_ssa::traits::{BaseTypeCodegenMethods, ConstCodegenMethods};
67
use rustc_data_structures::fx::FxIndexMap;
78
use rustc_index::IndexVec;
9+
use rustc_macros::TryFromU32;
810
use rustc_middle::ty::TyCtxt;
911
use rustc_session::RemapFileNameExt;
1012
use rustc_session::config::RemapPathScopeComponents;
@@ -20,6 +22,23 @@ mod covfun;
2022
mod spans;
2123
mod unused;
2224

25+
/// Version number that will be included the `__llvm_covmap` section header.
26+
/// Corresponds to LLVM's `llvm::coverage::CovMapVersion` (in `CoverageMapping.h`),
27+
/// or at least the subset that we know and care about.
28+
///
29+
/// Note that version `n` is encoded as `(n-1)`.
30+
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, TryFromU32)]
31+
enum CovmapVersion {
32+
/// Used by LLVM 18 onwards.
33+
Version7 = 6,
34+
}
35+
36+
impl CovmapVersion {
37+
fn to_u32(self) -> u32 {
38+
self as u32
39+
}
40+
}
41+
2342
/// Generates and exports the coverage map, which is embedded in special
2443
/// linker sections in the final binary.
2544
///
@@ -29,19 +48,13 @@ pub(crate) fn finalize(cx: &mut CodegenCx<'_, '_>) {
2948
let tcx = cx.tcx;
3049

3150
// Ensure that LLVM is using a version of the coverage mapping format that
32-
// agrees with our Rust-side code. Expected versions (encoded as n-1) are:
33-
// - `CovMapVersion::Version7` (6) used by LLVM 18-19
34-
let covmap_version = {
35-
let llvm_covmap_version = llvm_cov::mapping_version();
36-
let expected_versions = 6..=6;
37-
assert!(
38-
expected_versions.contains(&llvm_covmap_version),
39-
"Coverage mapping version exposed by `llvm-wrapper` is out of sync; \
40-
expected {expected_versions:?} but was {llvm_covmap_version}"
41-
);
42-
// This is the version number that we will embed in the covmap section:
43-
llvm_covmap_version
44-
};
51+
// agrees with our Rust-side code. Expected versions are:
52+
// - `Version7` (6) used by LLVM 18 onwards.
53+
let covmap_version =
54+
CovmapVersion::try_from(llvm_cov::mapping_version()).unwrap_or_else(|raw_version: u32| {
55+
panic!("unknown coverage mapping version reported by `llvm-wrapper`: {raw_version}")
56+
});
57+
assert_matches!(covmap_version, CovmapVersion::Version7);
4558

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

@@ -201,7 +214,11 @@ impl VirtualFileMapping {
201214
/// Generates the contents of the covmap record for this CGU, which mostly
202215
/// consists of a header and a list of filenames. The record is then stored
203216
/// as a global variable in the `__llvm_covmap` section.
204-
fn generate_covmap_record<'ll>(cx: &mut CodegenCx<'ll, '_>, version: u32, filenames_buffer: &[u8]) {
217+
fn generate_covmap_record<'ll>(
218+
cx: &mut CodegenCx<'ll, '_>,
219+
version: CovmapVersion,
220+
filenames_buffer: &[u8],
221+
) {
205222
// A covmap record consists of four target-endian u32 values, followed by
206223
// the encoded filenames table. Two of the header fields are unused in
207224
// modern versions of the LLVM coverage mapping format, and are always 0.
@@ -212,7 +229,7 @@ fn generate_covmap_record<'ll>(cx: &mut CodegenCx<'ll, '_>, version: u32, filena
212229
cx.const_u32(0), // (unused)
213230
cx.const_u32(filenames_buffer.len() as u32),
214231
cx.const_u32(0), // (unused)
215-
cx.const_u32(version),
232+
cx.const_u32(version.to_u32()),
216233
],
217234
/* packed */ false,
218235
);

compiler/rustc_codegen_llvm/src/coverageinfo/mapgen/covfun.rs

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ use crate::llvm;
2727
/// the final record that will be embedded in the `__llvm_covfun` section.
2828
#[derive(Debug)]
2929
pub(crate) struct CovfunRecord<'tcx> {
30+
/// Not used directly, but helpful in debug messages.
31+
_instance: Instance<'tcx>,
32+
3033
mangled_function_name: &'tcx str,
3134
source_hash: u64,
3235
is_used: bool,
@@ -55,6 +58,7 @@ pub(crate) fn prepare_covfun_record<'tcx>(
5558
let expressions = prepare_expressions(ids_info);
5659

5760
let mut covfun = CovfunRecord {
61+
_instance: instance,
5862
mangled_function_name: tcx.symbol_name(instance).name,
5963
source_hash: if is_used { fn_cov_info.function_source_hash } else { 0 },
6064
is_used,
@@ -102,11 +106,21 @@ fn fill_region_tables<'tcx>(
102106
ids_info: &'tcx CoverageIdsInfo,
103107
covfun: &mut CovfunRecord<'tcx>,
104108
) {
109+
// If this function is unused, replace all counters with zero.
110+
let counter_for_bcb = |bcb: BasicCoverageBlock| -> ffi::Counter {
111+
let term = if covfun.is_used {
112+
ids_info.term_for_bcb[bcb].expect("every BCB in a mapping was given a term")
113+
} else {
114+
CovTerm::Zero
115+
};
116+
ffi::Counter::from_term(term)
117+
};
118+
105119
// Currently a function's mappings must all be in the same file, so use the
106120
// first mapping's span to determine the file.
107121
let source_map = tcx.sess.source_map();
108122
let Some(first_span) = (try { fn_cov_info.mappings.first()?.span }) else {
109-
debug_assert!(false, "function has no mappings: {:?}", covfun.mangled_function_name);
123+
debug_assert!(false, "function has no mappings: {covfun:?}");
110124
return;
111125
};
112126
let source_file = source_map.lookup_source_file(first_span.lo());
@@ -117,7 +131,7 @@ fn fill_region_tables<'tcx>(
117131
// codegen needs to handle that gracefully to avoid #133606.
118132
// It's hard for tests to trigger this organically, so instead we set
119133
// `-Zcoverage-options=discard-all-spans-in-codegen` to force it to occur.
120-
let discard_all = tcx.sess.coverage_discard_all_spans_in_codegen();
134+
let discard_all = tcx.sess.coverage_options().discard_all_spans_in_codegen;
121135
let make_coords = |span: Span| {
122136
if discard_all { None } else { spans::make_coords(source_map, &source_file, span) }
123137
};
@@ -133,16 +147,6 @@ fn fill_region_tables<'tcx>(
133147
// For each counter/region pair in this function+file, convert it to a
134148
// form suitable for FFI.
135149
for &Mapping { ref kind, span } in &fn_cov_info.mappings {
136-
// If this function is unused, replace all counters with zero.
137-
let counter_for_bcb = |bcb: BasicCoverageBlock| -> ffi::Counter {
138-
let term = if covfun.is_used {
139-
ids_info.term_for_bcb[bcb].expect("every BCB in a mapping was given a term")
140-
} else {
141-
CovTerm::Zero
142-
};
143-
ffi::Counter::from_term(term)
144-
};
145-
146150
let Some(coords) = make_coords(span) else { continue };
147151
let cov_span = coords.make_coverage_span(local_file_id);
148152

@@ -184,6 +188,7 @@ pub(crate) fn generate_covfun_record<'tcx>(
184188
covfun: &CovfunRecord<'tcx>,
185189
) {
186190
let &CovfunRecord {
191+
_instance,
187192
mangled_function_name,
188193
source_hash,
189194
is_used,

0 commit comments

Comments
 (0)