Skip to content
/ rust Public
forked from rust-lang/rust

Commit 21033f6

Browse files
committed
Auto merge of rust-lang#121514 - matthiaskrgr:rollup-5f0vhv7, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - rust-lang#120742 (mark `min_exhaustive_patterns` as complete) - rust-lang#121470 (Don't ICE on anonymous struct in enum variant) - rust-lang#121492 (coverage: Rename `is_closure` to `is_hole`) - rust-lang#121495 (remove repetitive words) - rust-lang#121498 (Make QNX/NTO specific "timespec capping" public to crate::sys) - rust-lang#121510 (lint-overflowing-ops: unify cases and remove redundancy) r? `@ghost` `@rustbot` modify labels: rollup
2 parents b6a23b8 + 06e54f8 commit 21033f6

File tree

48 files changed

+1504
-1003
lines changed

Some content is hidden

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

48 files changed

+1504
-1003
lines changed

Diff for: compiler/rustc_codegen_ssa/src/back/metadata.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,7 @@ pub fn create_compressed_metadata_file_for_xcoff(
623623
/// that contains a custom section of the name `section_name` with contents
624624
/// `data`.
625625
///
626-
/// NB: the `object` crate does not yet have support for writing the the wasm
626+
/// NB: the `object` crate does not yet have support for writing the wasm
627627
/// object file format. The format is simple enough that for now an extra crate
628628
/// from crates.io (such as `wasm-encoder`). The file format is:
629629
///

Diff for: compiler/rustc_feature/src/unstable.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ declare_features! (
518518
(unstable, marker_trait_attr, "1.30.0", Some(29864)),
519519
/// Allows exhaustive pattern matching on types that contain uninhabited types in cases that are
520520
/// unambiguously sound.
521-
(incomplete, min_exhaustive_patterns, "1.77.0", Some(119612)),
521+
(unstable, min_exhaustive_patterns, "1.77.0", Some(119612)),
522522
/// A minimal, sound subset of specialization intended to be used by the
523523
/// standard library until the soundness issues with specialization
524524
/// are fixed.

Diff for: compiler/rustc_hir/src/hir.rs

+5
Original file line numberDiff line numberDiff line change
@@ -3004,6 +3004,11 @@ impl<'hir> Item<'hir> {
30043004
matches!(self.kind, ItemKind::Enum(..) | ItemKind::Struct(..) | ItemKind::Union(..))
30053005
}
30063006

3007+
/// Check if this is an [`ItemKind::Struct`] or [`ItemKind::Union`].
3008+
pub fn is_struct_or_union(&self) -> bool {
3009+
matches!(self.kind, ItemKind::Struct(..) | ItemKind::Union(..))
3010+
}
3011+
30073012
expect_methods_self_kind! {
30083013
expect_extern_crate, Option<Symbol>, ItemKind::ExternCrate(s), *s;
30093014

Diff for: compiler/rustc_hir_analysis/src/collect.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -1025,7 +1025,15 @@ fn adt_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::AdtDef<'_> {
10251025

10261026
let is_anonymous = item.ident.name == kw::Empty;
10271027
let repr = if is_anonymous {
1028-
tcx.adt_def(tcx.local_parent(def_id)).repr()
1028+
let parent = tcx.local_parent(def_id);
1029+
if let Node::Item(item) = tcx.hir_node_by_def_id(parent)
1030+
&& item.is_struct_or_union()
1031+
{
1032+
tcx.adt_def(parent).repr()
1033+
} else {
1034+
tcx.dcx().span_delayed_bug(item.span, "anonymous field inside non struct/union");
1035+
ty::ReprOptions::default()
1036+
}
10291037
} else {
10301038
tcx.repr_options_of_def(def_id)
10311039
};

Diff for: compiler/rustc_middle/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
2525
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
2626
#![doc(rust_logo)]
27+
#![cfg_attr(bootstrap, feature(exhaustive_patterns))]
28+
#![cfg_attr(not(bootstrap), feature(min_exhaustive_patterns))]
2729
#![feature(rustdoc_internals)]
2830
#![feature(allocator_api)]
2931
#![feature(array_windows)]
@@ -32,7 +34,6 @@
3234
#![feature(core_intrinsics)]
3335
#![feature(const_type_name)]
3436
#![feature(discriminant_kind)]
35-
#![feature(exhaustive_patterns)]
3637
#![feature(coroutines)]
3738
#![feature(generic_nonzero)]
3839
#![feature(if_let_guard)]

Diff for: compiler/rustc_middle/src/traits/select.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ pub enum SelectionCandidate<'tcx> {
139139
/// generated for an `async ||` expression.
140140
AsyncClosureCandidate,
141141

142-
/// Implementation of the the `AsyncFnKindHelper` helper trait, which
142+
/// Implementation of the `AsyncFnKindHelper` helper trait, which
143143
/// is used internally to delay computation for async closures until after
144144
/// upvar analysis is performed in HIR typeck.
145145
AsyncFnKindHelperCandidate,

Diff for: compiler/rustc_mir_transform/src/coverage/spans.rs

+46-54
Original file line numberDiff line numberDiff line change
@@ -90,23 +90,23 @@ pub(super) fn generate_coverage_spans(
9090
struct CurrCovspan {
9191
span: Span,
9292
bcb: BasicCoverageBlock,
93-
is_closure: bool,
93+
is_hole: bool,
9494
}
9595

9696
impl CurrCovspan {
97-
fn new(span: Span, bcb: BasicCoverageBlock, is_closure: bool) -> Self {
98-
Self { span, bcb, is_closure }
97+
fn new(span: Span, bcb: BasicCoverageBlock, is_hole: bool) -> Self {
98+
Self { span, bcb, is_hole }
9999
}
100100

101101
fn into_prev(self) -> PrevCovspan {
102-
let Self { span, bcb, is_closure } = self;
103-
PrevCovspan { span, bcb, merged_spans: vec![span], is_closure }
102+
let Self { span, bcb, is_hole } = self;
103+
PrevCovspan { span, bcb, merged_spans: vec![span], is_hole }
104104
}
105105

106106
fn into_refined(self) -> RefinedCovspan {
107-
// This is only called in cases where `curr` is a closure span that has
107+
// This is only called in cases where `curr` is a hole span that has
108108
// been carved out of `prev`.
109-
debug_assert!(self.is_closure);
109+
debug_assert!(self.is_hole);
110110
self.into_prev().into_refined()
111111
}
112112
}
@@ -118,12 +118,12 @@ struct PrevCovspan {
118118
/// List of all the original spans from MIR that have been merged into this
119119
/// span. Mainly used to precisely skip over gaps when truncating a span.
120120
merged_spans: Vec<Span>,
121-
is_closure: bool,
121+
is_hole: bool,
122122
}
123123

124124
impl PrevCovspan {
125125
fn is_mergeable(&self, other: &CurrCovspan) -> bool {
126-
self.bcb == other.bcb && !self.is_closure && !other.is_closure
126+
self.bcb == other.bcb && !self.is_hole && !other.is_hole
127127
}
128128

129129
fn merge_from(&mut self, other: &CurrCovspan) {
@@ -142,8 +142,8 @@ impl PrevCovspan {
142142
}
143143

144144
fn refined_copy(&self) -> RefinedCovspan {
145-
let &Self { span, bcb, merged_spans: _, is_closure } = self;
146-
RefinedCovspan { span, bcb, is_closure }
145+
let &Self { span, bcb, merged_spans: _, is_hole } = self;
146+
RefinedCovspan { span, bcb, is_hole }
147147
}
148148

149149
fn into_refined(self) -> RefinedCovspan {
@@ -156,12 +156,12 @@ impl PrevCovspan {
156156
struct RefinedCovspan {
157157
span: Span,
158158
bcb: BasicCoverageBlock,
159-
is_closure: bool,
159+
is_hole: bool,
160160
}
161161

162162
impl RefinedCovspan {
163163
fn is_mergeable(&self, other: &Self) -> bool {
164-
self.bcb == other.bcb && !self.is_closure && !other.is_closure
164+
self.bcb == other.bcb && !self.is_hole && !other.is_hole
165165
}
166166

167167
fn merge_from(&mut self, other: &Self) {
@@ -176,16 +176,16 @@ impl RefinedCovspan {
176176
/// * Remove duplicate source code coverage regions
177177
/// * Merge spans that represent continuous (both in source code and control flow), non-branching
178178
/// execution
179-
/// * Carve out (leave uncovered) any span that will be counted by another MIR (notably, closures)
179+
/// * Carve out (leave uncovered) any "hole" spans that need to be left blank
180+
/// (e.g. closures that will be counted by their own MIR body)
180181
struct SpansRefiner {
181182
/// The initial set of coverage spans, sorted by `Span` (`lo` and `hi`) and by relative
182183
/// dominance between the `BasicCoverageBlock`s of equal `Span`s.
183184
sorted_spans_iter: std::vec::IntoIter<SpanFromMir>,
184185

185-
/// The current coverage span to compare to its `prev`, to possibly merge, discard, force the
186-
/// discard of the `prev` (and or `pending_dups`), or keep both (with `prev` moved to
187-
/// `pending_dups`). If `curr` is not discarded or merged, it becomes `prev` for the next
188-
/// iteration.
186+
/// The current coverage span to compare to its `prev`, to possibly merge, discard,
187+
/// or cause `prev` to be modified or discarded.
188+
/// If `curr` is not discarded or merged, it becomes `prev` for the next iteration.
189189
some_curr: Option<CurrCovspan>,
190190

191191
/// The coverage span from a prior iteration; typically assigned from that iteration's `curr`.
@@ -229,7 +229,7 @@ impl SpansRefiner {
229229
let curr = self.curr();
230230

231231
if prev.is_mergeable(curr) {
232-
debug!(" same bcb (and neither is a closure), merge with prev={prev:?}");
232+
debug!(?prev, "curr will be merged into prev");
233233
let curr = self.take_curr();
234234
self.prev_mut().merge_from(&curr);
235235
} else if prev.span.hi() <= curr.span.lo() {
@@ -238,15 +238,13 @@ impl SpansRefiner {
238238
);
239239
let prev = self.take_prev().into_refined();
240240
self.refined_spans.push(prev);
241-
} else if prev.is_closure {
241+
} else if prev.is_hole {
242242
// drop any equal or overlapping span (`curr`) and keep `prev` to test again in the
243243
// next iter
244-
debug!(
245-
" curr overlaps a closure (prev). Drop curr and keep prev for next iter. prev={prev:?}",
246-
);
244+
debug!(?prev, "prev (a hole) overlaps curr, so discarding curr");
247245
self.take_curr(); // Discards curr.
248-
} else if curr.is_closure {
249-
self.carve_out_span_for_closure();
246+
} else if curr.is_hole {
247+
self.carve_out_span_for_hole();
250248
} else {
251249
self.cutoff_prev_at_overlapping_curr();
252250
}
@@ -270,10 +268,9 @@ impl SpansRefiner {
270268
}
271269
});
272270

273-
// Remove spans derived from closures, originally added to ensure the coverage
274-
// regions for the current function leave room for the closure's own coverage regions
275-
// (injected separately, from the closure's own MIR).
276-
self.refined_spans.retain(|covspan| !covspan.is_closure);
271+
// Discard hole spans, since their purpose was to carve out chunks from
272+
// other spans, but we don't want the holes themselves in the final mappings.
273+
self.refined_spans.retain(|covspan| !covspan.is_hole);
277274
self.refined_spans
278275
}
279276

@@ -316,48 +313,43 @@ impl SpansRefiner {
316313
{
317314
// Skip curr because prev has already advanced beyond the end of curr.
318315
// This can only happen if a prior iteration updated `prev` to skip past
319-
// a region of code, such as skipping past a closure.
320-
debug!(
321-
" prev.span starts after curr.span, so curr will be dropped (skipping past \
322-
closure?); prev={prev:?}",
323-
);
316+
// a region of code, such as skipping past a hole.
317+
debug!(?prev, "prev.span starts after curr.span, so curr will be dropped");
324318
} else {
325-
self.some_curr = Some(CurrCovspan::new(curr.span, curr.bcb, curr.is_closure));
319+
self.some_curr = Some(CurrCovspan::new(curr.span, curr.bcb, curr.is_hole));
326320
return true;
327321
}
328322
}
329323
false
330324
}
331325

332-
/// If `prev`s span extends left of the closure (`curr`), carve out the closure's span from
333-
/// `prev`'s span. (The closure's coverage counters will be injected when processing the
334-
/// closure's own MIR.) Add the portion of the span to the left of the closure; and if the span
335-
/// extends to the right of the closure, update `prev` to that portion of the span. For any
336-
/// `pending_dups`, repeat the same process.
337-
fn carve_out_span_for_closure(&mut self) {
326+
/// If `prev`s span extends left of the hole (`curr`), carve out the hole's span from
327+
/// `prev`'s span. Add the portion of the span to the left of the hole; and if the span
328+
/// extends to the right of the hole, update `prev` to that portion of the span.
329+
fn carve_out_span_for_hole(&mut self) {
338330
let prev = self.prev();
339331
let curr = self.curr();
340332

341333
let left_cutoff = curr.span.lo();
342334
let right_cutoff = curr.span.hi();
343-
let has_pre_closure_span = prev.span.lo() < right_cutoff;
344-
let has_post_closure_span = prev.span.hi() > right_cutoff;
345-
346-
if has_pre_closure_span {
347-
let mut pre_closure = self.prev().refined_copy();
348-
pre_closure.span = pre_closure.span.with_hi(left_cutoff);
349-
debug!(" prev overlaps a closure. Adding span for pre_closure={:?}", pre_closure);
350-
self.refined_spans.push(pre_closure);
335+
let has_pre_hole_span = prev.span.lo() < right_cutoff;
336+
let has_post_hole_span = prev.span.hi() > right_cutoff;
337+
338+
if has_pre_hole_span {
339+
let mut pre_hole = prev.refined_copy();
340+
pre_hole.span = pre_hole.span.with_hi(left_cutoff);
341+
debug!(?pre_hole, "prev overlaps a hole; adding pre-hole span");
342+
self.refined_spans.push(pre_hole);
351343
}
352344

353-
if has_post_closure_span {
354-
// Mutate `prev.span` to start after the closure (and discard curr).
345+
if has_post_hole_span {
346+
// Mutate `prev.span` to start after the hole (and discard curr).
355347
self.prev_mut().span = self.prev().span.with_lo(right_cutoff);
356-
debug!(" Mutated prev.span to start after the closure. prev={:?}", self.prev());
348+
debug!(prev=?self.prev(), "mutated prev to start after the hole");
357349

358350
// Prevent this curr from becoming prev.
359-
let closure_covspan = self.take_curr().into_refined();
360-
self.refined_spans.push(closure_covspan); // since self.prev() was already updated
351+
let hole_covspan = self.take_curr().into_refined();
352+
self.refined_spans.push(hole_covspan); // since self.prev() was already updated
361353
}
362354
}
363355

Diff for: compiler/rustc_mir_transform/src/coverage/spans/from_mir.rs

+16-11
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,14 @@ pub(super) fn mir_to_initial_sorted_coverage_spans(
5252
// - Span A extends further left, or
5353
// - Both have the same start and span A extends further right
5454
.then_with(|| Ord::cmp(&a.span.hi(), &b.span.hi()).reverse())
55-
// If two spans have the same lo & hi, put closure spans first,
56-
// as they take precedence over non-closure spans.
57-
.then_with(|| Ord::cmp(&a.is_closure, &b.is_closure).reverse())
55+
// If two spans have the same lo & hi, put hole spans first,
56+
// as they take precedence over non-hole spans.
57+
.then_with(|| Ord::cmp(&a.is_hole, &b.is_hole).reverse())
5858
// After deduplication, we want to keep only the most-dominated BCB.
5959
.then_with(|| basic_coverage_blocks.cmp_in_dominator_order(a.bcb, b.bcb).reverse())
6060
});
6161

62-
// Among covspans with the same span, keep only one. Closure spans take
62+
// Among covspans with the same span, keep only one. Hole spans take
6363
// precedence, otherwise keep the one with the most-dominated BCB.
6464
// (Ideally we should try to preserve _all_ non-dominating BCBs, but that
6565
// requires a lot more complexity in the span refiner, for little benefit.)
@@ -78,8 +78,8 @@ pub(super) fn mir_to_initial_sorted_coverage_spans(
7878
fn remove_unwanted_macro_spans(initial_spans: &mut Vec<SpanFromMir>) {
7979
let mut seen_macro_spans = FxHashSet::default();
8080
initial_spans.retain(|covspan| {
81-
// Ignore (retain) closure spans and non-macro-expansion spans.
82-
if covspan.is_closure || covspan.visible_macro.is_none() {
81+
// Ignore (retain) hole spans and non-macro-expansion spans.
82+
if covspan.is_hole || covspan.visible_macro.is_none() {
8383
return true;
8484
}
8585

@@ -96,7 +96,7 @@ fn split_visible_macro_spans(initial_spans: &mut Vec<SpanFromMir>) {
9696
let mut extra_spans = vec![];
9797

9898
initial_spans.retain(|covspan| {
99-
if covspan.is_closure {
99+
if covspan.is_hole {
100100
return true;
101101
}
102102

@@ -112,7 +112,7 @@ fn split_visible_macro_spans(initial_spans: &mut Vec<SpanFromMir>) {
112112
return true;
113113
}
114114

115-
assert!(!covspan.is_closure);
115+
assert!(!covspan.is_hole);
116116
extra_spans.push(SpanFromMir::new(before, covspan.visible_macro, covspan.bcb, false));
117117
extra_spans.push(SpanFromMir::new(after, covspan.visible_macro, covspan.bcb, false));
118118
false // Discard the original covspan that we just split.
@@ -148,6 +148,8 @@ fn bcb_to_initial_coverage_spans<'a, 'tcx>(
148148
let expn_span = filtered_statement_span(statement)?;
149149
let (span, visible_macro) = unexpand(expn_span)?;
150150

151+
// A statement that looks like the assignment of a closure expression
152+
// is treated as a "hole" span, to be carved out of other spans.
151153
Some(SpanFromMir::new(span, visible_macro, bcb, is_closure_like(statement)))
152154
});
153155

@@ -336,7 +338,10 @@ pub(super) struct SpanFromMir {
336338
pub(super) span: Span,
337339
visible_macro: Option<Symbol>,
338340
pub(super) bcb: BasicCoverageBlock,
339-
pub(super) is_closure: bool,
341+
/// If true, this covspan represents a "hole" that should be carved out
342+
/// from other spans, e.g. because it represents a closure expression that
343+
/// will be instrumented separately as its own function.
344+
pub(super) is_hole: bool,
340345
}
341346

342347
impl SpanFromMir {
@@ -348,8 +353,8 @@ impl SpanFromMir {
348353
span: Span,
349354
visible_macro: Option<Symbol>,
350355
bcb: BasicCoverageBlock,
351-
is_closure: bool,
356+
is_hole: bool,
352357
) -> Self {
353-
Self { span, visible_macro, bcb, is_closure }
358+
Self { span, visible_macro, bcb, is_hole }
354359
}
355360
}

Diff for: compiler/rustc_target/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99
1010
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
1111
#![doc(rust_logo)]
12+
#![cfg_attr(bootstrap, feature(exhaustive_patterns))]
13+
#![cfg_attr(not(bootstrap), feature(min_exhaustive_patterns))]
1214
#![feature(rustdoc_internals)]
1315
#![feature(assert_matches)]
14-
#![feature(exhaustive_patterns)]
1516
#![feature(iter_intersperse)]
1617
#![feature(let_chains)]
1718
#![cfg_attr(bootstrap, feature(min_specialization))]

0 commit comments

Comments
 (0)