Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit e004adb

Browse files
committed
Auto merge of rust-lang#119069 - matthiaskrgr:rollup-xxk4m30, r=matthiaskrgr
Rollup of 5 pull requests Successful merges: - rust-lang#118852 (coverage: Skip instrumenting a function if no spans were extracted from MIR) - rust-lang#118905 ([AIX] Fix XCOFF metadata) - rust-lang#118967 (Add better ICE messages for some undescriptive panics) - rust-lang#119051 (Replace `FileAllocationInfo` with `FileEndOfFileInfo`) - rust-lang#119059 (Deny `~const` trait bounds in inherent impl headers) r? `@ghost` `@rustbot` modify labels: rollup
2 parents cda4736 + c088f6a commit e004adb

File tree

18 files changed

+162
-47
lines changed

18 files changed

+162
-47
lines changed

compiler/rustc_ast_lowering/src/path.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use rustc_ast::{self as ast, *};
99
use rustc_hir as hir;
1010
use rustc_hir::def::{DefKind, PartialRes, Res};
1111
use rustc_hir::GenericArg;
12+
use rustc_middle::span_bug;
1213
use rustc_span::symbol::{kw, sym, Ident};
1314
use rustc_span::{BytePos, Span, DUMMY_SP};
1415

@@ -285,7 +286,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
285286
let (start, end) = match self.resolver.get_lifetime_res(segment_id) {
286287
Some(LifetimeRes::ElidedAnchor { start, end }) => (start, end),
287288
None => return,
288-
Some(_) => panic!(),
289+
Some(res) => {
290+
span_bug!(path_span, "expected an elided lifetime to insert. found {res:?}")
291+
}
289292
};
290293
let expected_lifetimes = end.as_usize() - start.as_usize();
291294
debug!(expected_lifetimes);

compiler/rustc_ast_passes/messages.ftl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,8 @@ ast_passes_tilde_const_disallowed = `~const` is not allowed here
225225
.closure = closures cannot have `~const` trait bounds
226226
.function = this function is not `const`, so it cannot have `~const` trait bounds
227227
.trait = this trait is not a `#[const_trait]`, so it cannot have `~const` trait bounds
228-
.impl = this impl is not `const`, so it cannot have `~const` trait bounds
228+
.trait_impl = this impl is not `const`, so it cannot have `~const` trait bounds
229+
.impl = inherent impls cannot have `~const` trait bounds
229230
.object = trait objects cannot have `~const` trait bounds
230231
.item = this item cannot have `~const` trait bounds
231232

compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ enum DisallowTildeConstContext<'a> {
4141
TraitObject,
4242
Fn(FnKind<'a>),
4343
Trait(Span),
44+
TraitImpl(Span),
4445
Impl(Span),
4546
Item,
4647
}
@@ -836,7 +837,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
836837
this.visit_vis(&item.vis);
837838
this.visit_ident(item.ident);
838839
let disallowed = matches!(constness, Const::No)
839-
.then(|| DisallowTildeConstContext::Impl(item.span));
840+
.then(|| DisallowTildeConstContext::TraitImpl(item.span));
840841
this.with_tilde_const(disallowed, |this| this.visit_generics(generics));
841842
this.visit_trait_ref(t);
842843
this.visit_ty(self_ty);
@@ -889,7 +890,9 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
889890

890891
self.visit_vis(&item.vis);
891892
self.visit_ident(item.ident);
892-
self.with_tilde_const(None, |this| this.visit_generics(generics));
893+
self.with_tilde_const(Some(DisallowTildeConstContext::Impl(item.span)), |this| {
894+
this.visit_generics(generics)
895+
});
893896
self.visit_ty(self_ty);
894897
walk_list!(self, visit_assoc_item, items, AssocCtxt::Impl);
895898
walk_list!(self, visit_attribute, &item.attrs);
@@ -1215,7 +1218,12 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
12151218
&DisallowTildeConstContext::Trait(span) => {
12161219
errors::TildeConstReason::Trait { span }
12171220
}
1221+
&DisallowTildeConstContext::TraitImpl(span) => {
1222+
errors::TildeConstReason::TraitImpl { span }
1223+
}
12181224
&DisallowTildeConstContext::Impl(span) => {
1225+
// FIXME(effects): Consider providing a help message or even a structured
1226+
// suggestion for moving such bounds to the assoc const fns if available.
12191227
errors::TildeConstReason::Impl { span }
12201228
}
12211229
DisallowTildeConstContext::TraitObject => {

compiler/rustc_ast_passes/src/errors.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,11 @@ pub enum TildeConstReason {
563563
#[primary_span]
564564
span: Span,
565565
},
566+
#[note(ast_passes_trait_impl)]
567+
TraitImpl {
568+
#[primary_span]
569+
span: Span,
570+
},
566571
#[note(ast_passes_impl)]
567572
Impl {
568573
#[primary_span]

compiler/rustc_ast_pretty/src/pprust/state.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1597,7 +1597,9 @@ impl<'a> State<'a> {
15971597
}
15981598
match bound {
15991599
ast::GenericBound::Outlives(lt) => self.print_lifetime(*lt),
1600-
_ => panic!(),
1600+
_ => {
1601+
panic!("expected a lifetime bound, found a trait bound")
1602+
}
16011603
}
16021604
}
16031605
}

compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,14 @@ impl<'tcx> CoverageInfoBuilderMethods<'tcx> for Builder<'_, '_, 'tcx> {
8585

8686
let bx = self;
8787

88+
match coverage.kind {
89+
// Marker statements have no effect during codegen,
90+
// so return early and don't create `func_coverage`.
91+
CoverageKind::SpanMarker => return,
92+
// Match exhaustively to ensure that newly-added kinds are classified correctly.
93+
CoverageKind::CounterIncrement { .. } | CoverageKind::ExpressionUsed { .. } => {}
94+
}
95+
8896
let Some(function_coverage_info) =
8997
bx.tcx.instance_mir(instance.def).function_coverage_info.as_deref()
9098
else {
@@ -100,9 +108,9 @@ impl<'tcx> CoverageInfoBuilderMethods<'tcx> for Builder<'_, '_, 'tcx> {
100108

101109
let Coverage { kind } = coverage;
102110
match *kind {
103-
// Span markers are only meaningful during MIR instrumentation,
104-
// and have no effect during codegen.
105-
CoverageKind::SpanMarker => {}
111+
CoverageKind::SpanMarker => unreachable!(
112+
"unexpected marker statement {kind:?} should have caused an early return"
113+
),
106114
CoverageKind::CounterIncrement { id } => {
107115
func_coverage.mark_counter_id_seen(id);
108116
// We need to explicitly drop the `RefMut` before calling into `instrprof_increment`,

compiler/rustc_codegen_ssa/src/back/metadata.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,13 @@ pub(super) fn get_metadata_xcoff<'a>(path: &Path, data: &'a [u8]) -> Result<&'a
158158
file.symbols().find(|sym| sym.name() == Ok(AIX_METADATA_SYMBOL_NAME))
159159
{
160160
let offset = metadata_symbol.address() as usize;
161-
if offset < 8 {
161+
// The offset specifies the location of rustc metadata in the .info section of XCOFF.
162+
// Each string stored in .info section of XCOFF is preceded by a 4-byte length field.
163+
if offset < 4 {
162164
return Err(format!("Invalid metadata symbol offset: {offset}"));
163165
}
164-
// The offset specifies the location of rustc metadata in the comment section.
165-
// The metadata is preceded by a 8-byte length field.
166-
let len = u64::from_le_bytes(info_data[(offset - 8)..offset].try_into().unwrap()) as usize;
166+
// XCOFF format uses big-endian byte order.
167+
let len = u32::from_be_bytes(info_data[(offset - 4)..offset].try_into().unwrap()) as usize;
167168
if offset + len > (info_data.len() as usize) {
168169
return Err(format!(
169170
"Metadata at offset {offset} with size {len} is beyond .info section"
@@ -478,9 +479,12 @@ pub fn create_wrapper_file(
478479
file.add_section(Vec::new(), b".text".to_vec(), SectionKind::Text);
479480
file.section_mut(section).flags =
480481
SectionFlags::Xcoff { s_flags: xcoff::STYP_INFO as u32 };
481-
482-
let len = data.len() as u64;
483-
let offset = file.append_section_data(section, &len.to_le_bytes(), 1);
482+
// Encode string stored in .info section of XCOFF.
483+
// FIXME: The length of data here is not guaranteed to fit in a u32.
484+
// We may have to split the data into multiple pieces in order to
485+
// store in .info section.
486+
let len: u32 = data.len().try_into().unwrap();
487+
let offset = file.append_section_data(section, &len.to_be_bytes(), 1);
484488
// Add a symbol referring to the data in .info section.
485489
file.add_symbol(Symbol {
486490
name: AIX_METADATA_SYMBOL_NAME.into(),
@@ -599,12 +603,12 @@ pub fn create_compressed_metadata_file_for_xcoff(
599603
section: SymbolSection::Section(data_section),
600604
flags: SymbolFlags::None,
601605
});
602-
let len = data.len() as u64;
603-
let offset = file.append_section_data(section, &len.to_le_bytes(), 1);
606+
let len: u32 = data.len().try_into().unwrap();
607+
let offset = file.append_section_data(section, &len.to_be_bytes(), 1);
604608
// Add a symbol referring to the rustc metadata.
605609
file.add_symbol(Symbol {
606610
name: AIX_METADATA_SYMBOL_NAME.into(),
607-
value: offset + 8, // The metadata is preceded by a 8-byte length field.
611+
value: offset + 4, // The metadata is preceded by a 4-byte length field.
608612
size: 0,
609613
kind: SymbolKind::Unknown,
610614
scope: SymbolScope::Dynamic,

compiler/rustc_mir_transform/src/coverage/mod.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,15 @@ impl<'a, 'tcx> Instrumentor<'a, 'tcx> {
9999
fn inject_counters(&'a mut self) {
100100
////////////////////////////////////////////////////
101101
// Compute coverage spans from the `CoverageGraph`.
102-
let coverage_spans = CoverageSpans::generate_coverage_spans(
102+
let Some(coverage_spans) = CoverageSpans::generate_coverage_spans(
103103
self.mir_body,
104104
self.fn_sig_span,
105105
self.body_span,
106106
&self.basic_coverage_blocks,
107-
);
107+
) else {
108+
// No relevant spans were found in MIR, so skip instrumenting this function.
109+
return;
110+
};
108111

109112
////////////////////////////////////////////////////
110113
// Create an optimized mix of `Counter`s and `Expression`s for the `CoverageGraph`. Ensure

compiler/rustc_mir_transform/src/coverage/spans.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,34 @@ pub(super) struct CoverageSpans {
1515
}
1616

1717
impl CoverageSpans {
18+
/// Extracts coverage-relevant spans from MIR, and associates them with
19+
/// their corresponding BCBs.
20+
///
21+
/// Returns `None` if no coverage-relevant spans could be extracted.
1822
pub(super) fn generate_coverage_spans(
1923
mir_body: &mir::Body<'_>,
2024
fn_sig_span: Span,
2125
body_span: Span,
2226
basic_coverage_blocks: &CoverageGraph,
23-
) -> Self {
27+
) -> Option<Self> {
2428
let coverage_spans = CoverageSpansGenerator::generate_coverage_spans(
2529
mir_body,
2630
fn_sig_span,
2731
body_span,
2832
basic_coverage_blocks,
2933
);
3034

35+
if coverage_spans.is_empty() {
36+
return None;
37+
}
38+
3139
// Group the coverage spans by BCB, with the BCBs in sorted order.
3240
let mut bcb_to_spans = IndexVec::from_elem_n(Vec::new(), basic_coverage_blocks.num_nodes());
3341
for CoverageSpan { bcb, span, .. } in coverage_spans {
3442
bcb_to_spans[bcb].push(span);
3543
}
3644

37-
Self { bcb_to_spans }
45+
Some(Self { bcb_to_spans })
3846
}
3947

4048
pub(super) fn bcb_has_coverage_spans(&self, bcb: BasicCoverageBlock) -> bool {

compiler/rustc_span/src/caching_source_map_view.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ impl<'sm> CachingSourceMapView<'sm> {
117117
self.time_stamp += 1;
118118

119119
// Check if lo and hi are in the cached lines.
120-
let lo_cache_idx = self.cache_entry_index(span_data.lo);
120+
let lo_cache_idx: isize = self.cache_entry_index(span_data.lo);
121121
let hi_cache_idx = self.cache_entry_index(span_data.hi);
122122

123123
if lo_cache_idx != -1 && hi_cache_idx != -1 {
@@ -205,7 +205,9 @@ impl<'sm> CachingSourceMapView<'sm> {
205205
(lo_cache_idx as usize, oldest)
206206
}
207207
_ => {
208-
panic!();
208+
panic!(
209+
"the case of neither value being equal to -1 was handled above and the function returns."
210+
);
209211
}
210212
};
211213

0 commit comments

Comments
 (0)