Skip to content

Commit 1cc4107

Browse files
committed
Auto merge of #79867 - tmandry:rollup-7mubs3b, r=tmandry
Rollup of 12 pull requests Successful merges: - #79732 (minor stylistic clippy cleanups) - #79750 (Fix trimming of lint docs) - #79777 (Remove `first_merge` from liveness debug logs) - #79795 (Privatize some of libcore unicode_internals) - #79803 (Update xsv to prevent random CI failures) - #79810 (Account for gaps in def path table during decoding) - #79818 (Fixes to Rust coverage) - #79824 (Strip prefix instead of replacing it with empty string) - #79826 (Simplify visit_{foreign,trait}_item) - #79844 (Move RWUTable to a separate module) - #79861 (Update LLVM submodule) - #79862 (Remove tab-lock and replace it with ctrl+up/down arrows to switch between search result tabs) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents f0f6877 + f74f3b2 commit 1cc4107

File tree

26 files changed

+374
-288
lines changed

26 files changed

+374
-288
lines changed

compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ fn save_function_record(
241241
/// (functions referenced by other "used" or public items). Any other functions considered unused,
242242
/// or "Unreachable" were still parsed and processed through the MIR stage.
243243
///
244-
/// We can find the unreachable functions by the set different of all MIR `DefId`s (`tcx` query
244+
/// We can find the unreachable functions by the set difference of all MIR `DefId`s (`tcx` query
245245
/// `mir_keys`) minus the codegenned `DefId`s (`tcx` query `collect_and_partition_mono_items`).
246246
///
247247
/// *HOWEVER* the codegenned `DefId`s are partitioned across multiple `CodegenUnit`s (CGUs), and

compiler/rustc_infer/src/infer/error_reporting/nice_region_error/different_lifetimes.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
121121

122122
(Some(ret_span), _) => {
123123
let sup_future = self.future_return_type(scope_def_id_sup);
124-
let (return_type, action) = if let Some(_) = sup_future {
124+
let (return_type, action) = if sup_future.is_some() {
125125
("returned future", "held across an await point")
126126
} else {
127127
("return type", "returned")
@@ -140,7 +140,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
140140
}
141141
(_, Some(ret_span)) => {
142142
let sub_future = self.future_return_type(scope_def_id_sub);
143-
let (return_type, action) = if let Some(_) = sub_future {
143+
let (return_type, action) = if sub_future.is_some() {
144144
("returned future", "held across an await point")
145145
} else {
146146
("return type", "returned")

compiler/rustc_lint/src/nonstandard_style.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ impl NonCamelCaseTypes {
131131
let cc = to_camel_case(name);
132132
// We cannot provide meaningful suggestions
133133
// if the characters are in the category of "Lowercase Letter".
134-
if name.to_string() != cc {
134+
if *name != cc {
135135
err.span_suggestion(
136136
ident.span,
137137
"convert the identifier to upper camel case",
@@ -271,7 +271,7 @@ impl NonSnakeCase {
271271
let mut err = lint.build(&msg);
272272
// We cannot provide meaningful suggestions
273273
// if the characters are in the category of "Uppercase Letter".
274-
if name.to_string() != sc {
274+
if *name != sc {
275275
// We have a valid span in almost all cases, but we don't have one when linting a crate
276276
// name provided via the command line.
277277
if !ident.span.is_dummy() {
@@ -455,7 +455,7 @@ impl NonUpperCaseGlobals {
455455
lint.build(&format!("{} `{}` should have an upper case name", sort, name));
456456
// We cannot provide meaningful suggestions
457457
// if the characters are in the category of "Lowercase Letter".
458-
if name.to_string() != uc {
458+
if *name != uc {
459459
err.span_suggestion(
460460
ident.span,
461461
"convert the identifier to upper case",

compiler/rustc_metadata/src/rmeta/decoder.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -1553,6 +1553,8 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
15531553
return Some(DefId { krate, index: def_index_guess });
15541554
}
15551555

1556+
let is_proc_macro = self.is_proc_macro_crate();
1557+
15561558
// Slow path: We need to find out the new `DefIndex` of the provided
15571559
// `DefPathHash`, if its still exists. This requires decoding every `DefPathHash`
15581560
// stored in this crate.
@@ -1561,9 +1563,12 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
15611563
let mut map = FxHashMap::with_capacity_and_hasher(end_id as usize, Default::default());
15621564
for i in 0..end_id {
15631565
let def_index = DefIndex::from_u32(i);
1564-
let hash =
1565-
self.root.tables.def_path_hashes.get(self, def_index).unwrap().decode(self);
1566-
map.insert(hash, def_index);
1566+
// There may be gaps in the encoded table if we're decoding a proc-macro crate
1567+
if let Some(hash) = self.root.tables.def_path_hashes.get(self, def_index) {
1568+
map.insert(hash.decode(self), def_index);
1569+
} else if !is_proc_macro {
1570+
panic!("Missing def_path_hashes entry for {:?}", def_index);
1571+
}
15671572
}
15681573
map
15691574
});

compiler/rustc_mir/src/borrow_check/diagnostics/region_name.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
445445
"highlight_if_we_cannot_match_hir_ty: type_name={:?} needle_fr={:?}",
446446
type_name, needle_fr
447447
);
448-
if type_name.find(&format!("'{}", counter)).is_some() {
448+
if type_name.contains(&format!("'{}", counter)) {
449449
// Only add a label if we can confirm that a region was labelled.
450450
RegionNameHighlight::CannotMatchHirTy(span, type_name)
451451
} else {

compiler/rustc_mir/src/transform/coverage/graph.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ impl CoverageGraph {
3333
// Pre-transform MIR `BasicBlock` successors and predecessors into the BasicCoverageBlock
3434
// equivalents. Note that since the BasicCoverageBlock graph has been fully simplified, the
3535
// each predecessor of a BCB leader_bb should be in a unique BCB, and each successor of a
36-
// BCB last_bb should bin in its own unique BCB. Therefore, collecting the BCBs using
36+
// BCB last_bb should be in its own unique BCB. Therefore, collecting the BCBs using
3737
// `bb_to_bcb` should work without requiring a deduplication step.
3838

3939
let successors = IndexVec::from_fn_n(
@@ -283,7 +283,9 @@ rustc_index::newtype_index! {
283283
}
284284
}
285285

286-
/// A BasicCoverageBlockData (BCB) represents the maximal-length sequence of MIR BasicBlocks without
286+
/// `BasicCoverageBlockData` holds the data indexed by a `BasicCoverageBlock`.
287+
///
288+
/// A `BasicCoverageBlock` (BCB) represents the maximal-length sequence of MIR `BasicBlock`s without
287289
/// conditional branches, and form a new, simplified, coverage-specific Control Flow Graph, without
288290
/// altering the original MIR CFG.
289291
///

compiler/rustc_mir/src/transform/coverage/mod.rs

+18-4
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ struct Instrumentor<'a, 'tcx> {
8888
pass_name: &'a str,
8989
tcx: TyCtxt<'tcx>,
9090
mir_body: &'a mut mir::Body<'tcx>,
91+
source_file: Lrc<SourceFile>,
9192
fn_sig_span: Span,
9293
body_span: Span,
9394
basic_coverage_blocks: CoverageGraph,
@@ -96,9 +97,13 @@ struct Instrumentor<'a, 'tcx> {
9697

9798
impl<'a, 'tcx> Instrumentor<'a, 'tcx> {
9899
fn new(pass_name: &'a str, tcx: TyCtxt<'tcx>, mir_body: &'a mut mir::Body<'tcx>) -> Self {
100+
let source_map = tcx.sess.source_map();
99101
let (some_fn_sig, hir_body) = fn_sig_and_body(tcx, mir_body.source.def_id());
100102
let body_span = hir_body.value.span;
101-
let fn_sig_span = match some_fn_sig {
103+
let source_file = source_map.lookup_source_file(body_span.lo());
104+
let fn_sig_span = match some_fn_sig.filter(|fn_sig| {
105+
Lrc::ptr_eq(&source_file, &source_map.lookup_source_file(fn_sig.span.hi()))
106+
}) {
102107
Some(fn_sig) => fn_sig.span.with_hi(body_span.lo()),
103108
None => body_span.shrink_to_lo(),
104109
};
@@ -108,6 +113,7 @@ impl<'a, 'tcx> Instrumentor<'a, 'tcx> {
108113
pass_name,
109114
tcx,
110115
mir_body,
116+
source_file,
111117
fn_sig_span,
112118
body_span,
113119
basic_coverage_blocks,
@@ -268,8 +274,7 @@ impl<'a, 'tcx> Instrumentor<'a, 'tcx> {
268274
let tcx = self.tcx;
269275
let source_map = tcx.sess.source_map();
270276
let body_span = self.body_span;
271-
let source_file = source_map.lookup_source_file(body_span.lo());
272-
let file_name = Symbol::intern(&source_file.name.to_string());
277+
let file_name = Symbol::intern(&self.source_file.name.to_string());
273278

274279
let mut bcb_counters = IndexVec::from_elem_n(None, self.basic_coverage_blocks.num_nodes());
275280
for covspan in coverage_spans {
@@ -285,11 +290,20 @@ impl<'a, 'tcx> Instrumentor<'a, 'tcx> {
285290
bug!("Every BasicCoverageBlock should have a Counter or Expression");
286291
};
287292
graphviz_data.add_bcb_coverage_span_with_counter(bcb, &covspan, &counter_kind);
293+
294+
debug!(
295+
"Calling make_code_region(file_name={}, source_file={:?}, span={}, body_span={})",
296+
file_name,
297+
self.source_file,
298+
source_map.span_to_string(span),
299+
source_map.span_to_string(body_span)
300+
);
301+
288302
inject_statement(
289303
self.mir_body,
290304
counter_kind,
291305
self.bcb_last_bb(bcb),
292-
Some(make_code_region(file_name, &source_file, span, body_span)),
306+
Some(make_code_region(file_name, &self.source_file, span, body_span)),
293307
);
294308
}
295309
}

compiler/rustc_mir/src/transform/coverage/spans.rs

+21-21
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,27 @@ pub struct CoverageSpans<'a, 'tcx> {
217217
}
218218

219219
impl<'a, 'tcx> CoverageSpans<'a, 'tcx> {
220+
/// Generate a minimal set of `CoverageSpan`s, each representing a contiguous code region to be
221+
/// counted.
222+
///
223+
/// The basic steps are:
224+
///
225+
/// 1. Extract an initial set of spans from the `Statement`s and `Terminator`s of each
226+
/// `BasicCoverageBlockData`.
227+
/// 2. Sort the spans by span.lo() (starting position). Spans that start at the same position
228+
/// are sorted with longer spans before shorter spans; and equal spans are sorted
229+
/// (deterministically) based on "dominator" relationship (if any).
230+
/// 3. Traverse the spans in sorted order to identify spans that can be dropped (for instance,
231+
/// if another span or spans are already counting the same code region), or should be merged
232+
/// into a broader combined span (because it represents a contiguous, non-branching, and
233+
/// uninterrupted region of source code).
234+
///
235+
/// Closures are exposed in their enclosing functions as `Assign` `Rvalue`s, and since
236+
/// closures have their own MIR, their `Span` in their enclosing function should be left
237+
/// "uncovered".
238+
///
239+
/// Note the resulting vector of `CoverageSpan`s may not be fully sorted (and does not need
240+
/// to be).
220241
pub(super) fn generate_coverage_spans(
221242
mir_body: &'a mir::Body<'tcx>,
222243
fn_sig_span: Span,
@@ -247,27 +268,6 @@ impl<'a, 'tcx> CoverageSpans<'a, 'tcx> {
247268
coverage_spans.to_refined_spans()
248269
}
249270

250-
/// Generate a minimal set of `CoverageSpan`s, each representing a contiguous code region to be
251-
/// counted.
252-
///
253-
/// The basic steps are:
254-
///
255-
/// 1. Extract an initial set of spans from the `Statement`s and `Terminator`s of each
256-
/// `BasicCoverageBlockData`.
257-
/// 2. Sort the spans by span.lo() (starting position). Spans that start at the same position
258-
/// are sorted with longer spans before shorter spans; and equal spans are sorted
259-
/// (deterministically) based on "dominator" relationship (if any).
260-
/// 3. Traverse the spans in sorted order to identify spans that can be dropped (for instance,
261-
/// if another span or spans are already counting the same code region), or should be merged
262-
/// into a broader combined span (because it represents a contiguous, non-branching, and
263-
/// uninterrupted region of source code).
264-
///
265-
/// Closures are exposed in their enclosing functions as `Assign` `Rvalue`s, and since
266-
/// closures have their own MIR, their `Span` in their enclosing function should be left
267-
/// "uncovered".
268-
///
269-
/// Note the resulting vector of `CoverageSpan`s does may not be fully sorted (and does not need
270-
/// to be).
271271
fn mir_to_initial_sorted_coverage_spans(&self) -> Vec<CoverageSpan> {
272272
let mut initial_spans = Vec::<CoverageSpan>::with_capacity(self.mir_body.num_nodes() * 2);
273273
for (bcb, bcb_data) in self.basic_coverage_blocks.iter_enumerated() {

compiler/rustc_passes/src/dead.rs

+10-20
Original file line numberDiff line numberDiff line change
@@ -423,15 +423,11 @@ impl<'v, 'k, 'tcx> ItemLikeVisitor<'v> for LifeSeeder<'k, 'tcx> {
423423
}
424424

425425
fn visit_trait_item(&mut self, trait_item: &hir::TraitItem<'_>) {
426-
match trait_item.kind {
427-
hir::TraitItemKind::Const(_, Some(_))
428-
| hir::TraitItemKind::Fn(_, hir::TraitFn::Provided(_)) => {
429-
if has_allow_dead_code_or_lang_attr(self.tcx, trait_item.hir_id, &trait_item.attrs)
430-
{
431-
self.worklist.push(trait_item.hir_id);
432-
}
433-
}
434-
_ => {}
426+
use hir::TraitItemKind::{Const, Fn};
427+
if matches!(trait_item.kind, Const(_, Some(_)) | Fn(_, hir::TraitFn::Provided(_)))
428+
&& has_allow_dead_code_or_lang_attr(self.tcx, trait_item.hir_id, &trait_item.attrs)
429+
{
430+
self.worklist.push(trait_item.hir_id);
435431
}
436432
}
437433

@@ -440,17 +436,11 @@ impl<'v, 'k, 'tcx> ItemLikeVisitor<'v> for LifeSeeder<'k, 'tcx> {
440436
}
441437

442438
fn visit_foreign_item(&mut self, foreign_item: &hir::ForeignItem<'_>) {
443-
match foreign_item.kind {
444-
hir::ForeignItemKind::Static(..) | hir::ForeignItemKind::Fn(..) => {
445-
if has_allow_dead_code_or_lang_attr(
446-
self.tcx,
447-
foreign_item.hir_id,
448-
&foreign_item.attrs,
449-
) {
450-
self.worklist.push(foreign_item.hir_id);
451-
}
452-
}
453-
_ => {}
439+
use hir::ForeignItemKind::{Fn, Static};
440+
if matches!(foreign_item.kind, Static(..) | Fn(..))
441+
&& has_allow_dead_code_or_lang_attr(self.tcx, foreign_item.hir_id, &foreign_item.attrs)
442+
{
443+
self.worklist.push(foreign_item.hir_id);
454444
}
455445
}
456446
}

0 commit comments

Comments
 (0)