Skip to content

Commit f794a08

Browse files
committed
Auto merge of #150106 - matthiaskrgr:rollup-98nwcjp, r=matthiaskrgr
Rollup of 4 pull requests Successful merges: - #149919 (Correctly encode doc attribute metadata) - #150051 (mir_build: Rename `TestCase` to `TestableCase`) - #150088 (miri: add `miri_spin_loop` to make `hint::spin_loop` work consistently) - #150096 (Revert #148937) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 68f11a1 + 92bd07b commit f794a08

File tree

34 files changed

+509
-125
lines changed

34 files changed

+509
-125
lines changed

compiler/rustc_hir/src/attrs/data_structures.rs

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ pub struct CfgHideShow {
530530
pub values: ThinVec<CfgInfo>,
531531
}
532532

533-
#[derive(Clone, Debug, Default, HashStable_Generic, Encodable, Decodable, PrintAttribute)]
533+
#[derive(Clone, Debug, Default, HashStable_Generic, Decodable, PrintAttribute)]
534534
pub struct DocAttribute {
535535
pub aliases: FxIndexMap<Symbol, Span>,
536536
pub hidden: Option<Span>,
@@ -566,6 +566,62 @@ pub struct DocAttribute {
566566
pub no_crate_inject: Option<Span>,
567567
}
568568

569+
impl<E: rustc_span::SpanEncoder> rustc_serialize::Encodable<E> for DocAttribute {
570+
fn encode(&self, encoder: &mut E) {
571+
let DocAttribute {
572+
aliases,
573+
hidden,
574+
inline,
575+
cfg,
576+
auto_cfg,
577+
auto_cfg_change,
578+
fake_variadic,
579+
keyword,
580+
attribute,
581+
masked,
582+
notable_trait,
583+
search_unbox,
584+
html_favicon_url,
585+
html_logo_url,
586+
html_playground_url,
587+
html_root_url,
588+
html_no_source,
589+
issue_tracker_base_url,
590+
rust_logo,
591+
test_attrs,
592+
no_crate_inject,
593+
} = self;
594+
rustc_serialize::Encodable::<E>::encode(aliases, encoder);
595+
rustc_serialize::Encodable::<E>::encode(hidden, encoder);
596+
597+
// FIXME: The `doc(inline)` attribute is never encoded, but is it actually the right thing
598+
// to do? I suspect the condition was broken, should maybe instead not encode anything if we
599+
// have `doc(no_inline)`.
600+
let inline: ThinVec<_> =
601+
inline.iter().filter(|(i, _)| *i != DocInline::Inline).cloned().collect();
602+
rustc_serialize::Encodable::<E>::encode(&inline, encoder);
603+
604+
rustc_serialize::Encodable::<E>::encode(cfg, encoder);
605+
rustc_serialize::Encodable::<E>::encode(auto_cfg, encoder);
606+
rustc_serialize::Encodable::<E>::encode(auto_cfg_change, encoder);
607+
rustc_serialize::Encodable::<E>::encode(fake_variadic, encoder);
608+
rustc_serialize::Encodable::<E>::encode(keyword, encoder);
609+
rustc_serialize::Encodable::<E>::encode(attribute, encoder);
610+
rustc_serialize::Encodable::<E>::encode(masked, encoder);
611+
rustc_serialize::Encodable::<E>::encode(notable_trait, encoder);
612+
rustc_serialize::Encodable::<E>::encode(search_unbox, encoder);
613+
rustc_serialize::Encodable::<E>::encode(html_favicon_url, encoder);
614+
rustc_serialize::Encodable::<E>::encode(html_logo_url, encoder);
615+
rustc_serialize::Encodable::<E>::encode(html_playground_url, encoder);
616+
rustc_serialize::Encodable::<E>::encode(html_root_url, encoder);
617+
rustc_serialize::Encodable::<E>::encode(html_no_source, encoder);
618+
rustc_serialize::Encodable::<E>::encode(issue_tracker_base_url, encoder);
619+
rustc_serialize::Encodable::<E>::encode(rust_logo, encoder);
620+
rustc_serialize::Encodable::<E>::encode(test_attrs, encoder);
621+
rustc_serialize::Encodable::<E>::encode(no_crate_inject, encoder);
622+
}
623+
}
624+
569625
/// Represents parsed *built-in* inert attributes.
570626
///
571627
/// ## Overview

compiler/rustc_metadata/src/rmeta/encoder.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -879,13 +879,9 @@ fn analyze_attr(attr: &hir::Attribute, state: &mut AnalyzeAttrState<'_>) -> bool
879879
should_encode = true;
880880
}
881881
} else if let hir::Attribute::Parsed(AttributeKind::Doc(d)) = attr {
882-
// If this is a `doc` attribute that doesn't have anything except maybe `inline` (as in
883-
// `#[doc(inline)]`), then we can remove it. It won't be inlinable in downstream crates.
884-
if d.inline.is_empty() {
885-
should_encode = true;
886-
if d.hidden.is_some() {
887-
state.is_doc_hidden = true;
888-
}
882+
should_encode = true;
883+
if d.hidden.is_some() {
884+
state.is_doc_hidden = true;
889885
}
890886
} else if let &[sym::diagnostic, seg] = &*attr.path() {
891887
should_encode = rustc_feature::is_stable_diagnostic_attribute(seg, state.features);

compiler/rustc_mir_build/src/builder/matches/buckets.rs

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use tracing::debug;
77

88
use crate::builder::Builder;
99
use crate::builder::matches::test::is_switch_ty;
10-
use crate::builder::matches::{Candidate, Test, TestBranch, TestCase, TestKind};
10+
use crate::builder::matches::{Candidate, Test, TestBranch, TestKind, TestableCase};
1111

1212
/// Output of [`Builder::partition_candidates_into_buckets`].
1313
pub(crate) struct PartitionedCandidates<'tcx, 'b, 'c> {
@@ -140,12 +140,12 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
140140
// branch, so it can be removed. If false, the match pair is _compatible_
141141
// with its test branch, but still needs a more specific test.
142142
let fully_matched;
143-
let ret = match (&test.kind, &match_pair.test_case) {
143+
let ret = match (&test.kind, &match_pair.testable_case) {
144144
// If we are performing a variant switch, then this
145145
// informs variant patterns, but nothing else.
146146
(
147147
&TestKind::Switch { adt_def: tested_adt_def },
148-
&TestCase::Variant { adt_def, variant_index },
148+
&TestableCase::Variant { adt_def, variant_index },
149149
) => {
150150
assert_eq!(adt_def, tested_adt_def);
151151
fully_matched = true;
@@ -159,24 +159,23 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
159159
// things out here, in some cases.
160160
//
161161
// FIXME(Zalathar): Is the `is_switch_ty` test unnecessary?
162-
(TestKind::SwitchInt, &TestCase::Constant { value })
162+
(TestKind::SwitchInt, &TestableCase::Constant { value })
163163
if is_switch_ty(match_pair.pattern_ty) =>
164164
{
165165
// An important invariant of candidate bucketing is that a candidate
166166
// must not match in multiple branches. For `SwitchInt` tests, adding
167167
// a new value might invalidate that property for range patterns that
168168
// have already been partitioned into the failure arm, so we must take care
169169
// not to add such values here.
170-
let is_covering_range = |test_case: &TestCase<'tcx>| {
171-
test_case.as_range().is_some_and(|range| {
170+
let is_covering_range = |testable_case: &TestableCase<'tcx>| {
171+
testable_case.as_range().is_some_and(|range| {
172172
matches!(range.contains(value, self.tcx), None | Some(true))
173173
})
174174
};
175175
let is_conflicting_candidate = |candidate: &&mut Candidate<'tcx>| {
176-
candidate
177-
.match_pairs
178-
.iter()
179-
.any(|mp| mp.place == Some(test_place) && is_covering_range(&mp.test_case))
176+
candidate.match_pairs.iter().any(|mp| {
177+
mp.place == Some(test_place) && is_covering_range(&mp.testable_case)
178+
})
180179
};
181180
if prior_candidates
182181
.get(&TestBranch::Failure)
@@ -189,7 +188,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
189188
Some(TestBranch::Constant(value))
190189
}
191190
}
192-
(TestKind::SwitchInt, TestCase::Range(range)) => {
191+
(TestKind::SwitchInt, TestableCase::Range(range)) => {
193192
// When performing a `SwitchInt` test, a range pattern can be
194193
// sorted into the failure arm if it doesn't contain _any_ of
195194
// the values being tested. (This restricts what values can be
@@ -207,7 +206,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
207206
})
208207
}
209208

210-
(TestKind::If, TestCase::Constant { value }) => {
209+
(TestKind::If, TestableCase::Constant { value }) => {
211210
fully_matched = true;
212211
let value = value.try_to_bool().unwrap_or_else(|| {
213212
span_bug!(test.span, "expected boolean value but got {value:?}")
@@ -217,7 +216,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
217216

218217
(
219218
&TestKind::Len { len: test_len, op: BinOp::Eq },
220-
&TestCase::Slice { len, variable_length },
219+
&TestableCase::Slice { len, variable_length },
221220
) => {
222221
match (test_len.cmp(&(len as u64)), variable_length) {
223222
(Ordering::Equal, false) => {
@@ -249,7 +248,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
249248
}
250249
(
251250
&TestKind::Len { len: test_len, op: BinOp::Ge },
252-
&TestCase::Slice { len, variable_length },
251+
&TestableCase::Slice { len, variable_length },
253252
) => {
254253
// the test is `$actual_len >= test_len`
255254
match (test_len.cmp(&(len as u64)), variable_length) {
@@ -281,7 +280,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
281280
}
282281
}
283282

284-
(TestKind::Range(test), TestCase::Range(pat)) => {
283+
(TestKind::Range(test), TestableCase::Range(pat)) => {
285284
if test == pat {
286285
fully_matched = true;
287286
Some(TestBranch::Success)
@@ -292,7 +291,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
292291
if !test.overlaps(pat, self.tcx)? { Some(TestBranch::Failure) } else { None }
293292
}
294293
}
295-
(TestKind::Range(range), &TestCase::Constant { value }) => {
294+
(TestKind::Range(range), &TestableCase::Constant { value }) => {
296295
fully_matched = false;
297296
if !range.contains(value, self.tcx)? {
298297
// `value` is not contained in the testing range,
@@ -303,7 +302,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
303302
}
304303
}
305304

306-
(TestKind::Eq { value: test_val, .. }, TestCase::Constant { value: case_val }) => {
305+
(TestKind::Eq { value: test_val, .. }, TestableCase::Constant { value: case_val }) => {
307306
if test_val == case_val {
308307
fully_matched = true;
309308
Some(TestBranch::Success)
@@ -313,7 +312,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
313312
}
314313
}
315314

316-
(TestKind::Deref { temp: test_temp, .. }, TestCase::Deref { temp, .. })
315+
(TestKind::Deref { temp: test_temp, .. }, TestableCase::Deref { temp, .. })
317316
if test_temp == temp =>
318317
{
319318
fully_matched = true;

compiler/rustc_mir_build/src/builder/matches/match_pair.rs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_middle::ty::{self, Pinnedness, Ty, TypeVisitableExt};
88

99
use crate::builder::Builder;
1010
use crate::builder::expr::as_place::{PlaceBase, PlaceBuilder};
11-
use crate::builder::matches::{FlatPat, MatchPairTree, PatternExtraData, TestCase};
11+
use crate::builder::matches::{FlatPat, MatchPairTree, PatternExtraData, TestableCase};
1212

1313
impl<'a, 'tcx> Builder<'a, 'tcx> {
1414
/// Builds and pushes [`MatchPairTree`] subtrees, one for each pattern in
@@ -132,7 +132,7 @@ impl<'tcx> MatchPairTree<'tcx> {
132132

133133
let place = place_builder.try_to_place(cx);
134134
let mut subpairs = Vec::new();
135-
let test_case = match pattern.kind {
135+
let testable_case = match pattern.kind {
136136
PatKind::Missing | PatKind::Wild | PatKind::Error(_) => None,
137137

138138
PatKind::Or { ref pats } => {
@@ -146,18 +146,18 @@ impl<'tcx> MatchPairTree<'tcx> {
146146
// FIXME(@dianne): this needs updating/removing if we always merge or-patterns
147147
extra_data.bindings.push(super::SubpatternBindings::FromOrPattern);
148148
}
149-
Some(TestCase::Or { pats })
149+
Some(TestableCase::Or { pats })
150150
}
151151

152152
PatKind::Range(ref range) => {
153153
if range.is_full_range(cx.tcx) == Some(true) {
154154
None
155155
} else {
156-
Some(TestCase::Range(Arc::clone(range)))
156+
Some(TestableCase::Range(Arc::clone(range)))
157157
}
158158
}
159159

160-
PatKind::Constant { value } => Some(TestCase::Constant { value }),
160+
PatKind::Constant { value } => Some(TestableCase::Constant { value }),
161161

162162
PatKind::AscribeUserType {
163163
ascription: Ascription { ref annotation, variance },
@@ -256,7 +256,7 @@ impl<'tcx> MatchPairTree<'tcx> {
256256
if prefix.is_empty() && slice.is_some() && suffix.is_empty() {
257257
None
258258
} else {
259-
Some(TestCase::Slice {
259+
Some(TestableCase::Slice {
260260
len: prefix.len() + suffix.len(),
261261
variable_length: slice.is_some(),
262262
})
@@ -275,7 +275,11 @@ impl<'tcx> MatchPairTree<'tcx> {
275275
cx.def_id.into(),
276276
)
277277
}) && !adt_def.variant_list_has_applicable_non_exhaustive();
278-
if irrefutable { None } else { Some(TestCase::Variant { adt_def, variant_index }) }
278+
if irrefutable {
279+
None
280+
} else {
281+
Some(TestableCase::Variant { adt_def, variant_index })
282+
}
279283
}
280284

281285
PatKind::Leaf { ref subpatterns } => {
@@ -331,17 +335,17 @@ impl<'tcx> MatchPairTree<'tcx> {
331335
&mut subpairs,
332336
extra_data,
333337
);
334-
Some(TestCase::Deref { temp, mutability })
338+
Some(TestableCase::Deref { temp, mutability })
335339
}
336340

337-
PatKind::Never => Some(TestCase::Never),
341+
PatKind::Never => Some(TestableCase::Never),
338342
};
339343

340-
if let Some(test_case) = test_case {
344+
if let Some(testable_case) = testable_case {
341345
// This pattern is refutable, so push a new match-pair node.
342346
match_pairs.push(MatchPairTree {
343347
place,
344-
test_case,
348+
testable_case,
345349
subpairs,
346350
pattern_ty: pattern.ty,
347351
pattern_span: pattern.span,

compiler/rustc_mir_build/src/builder/matches/mod.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,7 +1078,7 @@ struct Candidate<'tcx> {
10781078
/// (see [`Builder::test_remaining_match_pairs_after_or`]).
10791079
///
10801080
/// Invariants:
1081-
/// - All or-patterns ([`TestCase::Or`]) have been sorted to the end.
1081+
/// - All or-patterns ([`TestableCase::Or`]) have been sorted to the end.
10821082
match_pairs: Vec<MatchPairTree<'tcx>>,
10831083

10841084
/// ...and if this is non-empty, one of these subcandidates also has to match...
@@ -1164,12 +1164,15 @@ impl<'tcx> Candidate<'tcx> {
11641164

11651165
/// Restores the invariant that or-patterns must be sorted to the end.
11661166
fn sort_match_pairs(&mut self) {
1167-
self.match_pairs.sort_by_key(|pair| matches!(pair.test_case, TestCase::Or { .. }));
1167+
self.match_pairs.sort_by_key(|pair| matches!(pair.testable_case, TestableCase::Or { .. }));
11681168
}
11691169

11701170
/// Returns whether the first match pair of this candidate is an or-pattern.
11711171
fn starts_with_or_pattern(&self) -> bool {
1172-
matches!(&*self.match_pairs, [MatchPairTree { test_case: TestCase::Or { .. }, .. }, ..])
1172+
matches!(
1173+
&*self.match_pairs,
1174+
[MatchPairTree { testable_case: TestableCase::Or { .. }, .. }, ..]
1175+
)
11731176
}
11741177

11751178
/// Visit the leaf candidates (those with no subcandidates) contained in
@@ -1261,7 +1264,7 @@ struct Ascription<'tcx> {
12611264
/// Instead they participate in or-pattern expansion, where they are transformed into
12621265
/// subcandidates. See [`Builder::expand_and_match_or_candidates`].
12631266
#[derive(Debug, Clone)]
1264-
enum TestCase<'tcx> {
1267+
enum TestableCase<'tcx> {
12651268
Variant { adt_def: ty::AdtDef<'tcx>, variant_index: VariantIdx },
12661269
Constant { value: ty::Value<'tcx> },
12671270
Range(Arc<PatRange<'tcx>>),
@@ -1271,7 +1274,7 @@ enum TestCase<'tcx> {
12711274
Or { pats: Box<[FlatPat<'tcx>]> },
12721275
}
12731276

1274-
impl<'tcx> TestCase<'tcx> {
1277+
impl<'tcx> TestableCase<'tcx> {
12751278
fn as_range(&self) -> Option<&PatRange<'tcx>> {
12761279
if let Self::Range(v) = self { Some(v.as_ref()) } else { None }
12771280
}
@@ -1289,12 +1292,12 @@ pub(crate) struct MatchPairTree<'tcx> {
12891292
/// ---
12901293
/// This can be `None` if it referred to a non-captured place in a closure.
12911294
///
1292-
/// Invariant: Can only be `None` when `test_case` is `Or`.
1295+
/// Invariant: Can only be `None` when `testable_case` is `Or`.
12931296
/// Therefore this must be `Some(_)` after or-pattern expansion.
12941297
place: Option<Place<'tcx>>,
12951298

12961299
/// ... must pass this test...
1297-
test_case: TestCase<'tcx>,
1300+
testable_case: TestableCase<'tcx>,
12981301

12991302
/// ... and these subpairs must match.
13001303
///
@@ -1317,7 +1320,7 @@ enum TestKind<'tcx> {
13171320
/// Test what enum variant a value is.
13181321
///
13191322
/// The subset of expected variants is not stored here; instead they are
1320-
/// extracted from the [`TestCase`]s of the candidates participating in the
1323+
/// extracted from the [`TestableCase`]s of the candidates participating in the
13211324
/// test.
13221325
Switch {
13231326
/// The enum type being tested.
@@ -1327,7 +1330,7 @@ enum TestKind<'tcx> {
13271330
/// Test what value an integer or `char` has.
13281331
///
13291332
/// The test's target values are not stored here; instead they are extracted
1330-
/// from the [`TestCase`]s of the candidates participating in the test.
1333+
/// from the [`TestableCase`]s of the candidates participating in the test.
13311334
SwitchInt,
13321335

13331336
/// Test whether a `bool` is `true` or `false`.
@@ -1948,7 +1951,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
19481951
candidate: &mut Candidate<'tcx>,
19491952
match_pair: MatchPairTree<'tcx>,
19501953
) {
1951-
let TestCase::Or { pats } = match_pair.test_case else { bug!() };
1954+
let TestableCase::Or { pats } = match_pair.testable_case else { bug!() };
19521955
debug!("expanding or-pattern: candidate={:#?}\npats={:#?}", candidate, pats);
19531956
candidate.or_span = Some(match_pair.pattern_span);
19541957
candidate.subcandidates = pats
@@ -2116,7 +2119,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
21162119
debug_assert!(
21172120
remaining_match_pairs
21182121
.iter()
2119-
.all(|match_pair| matches!(match_pair.test_case, TestCase::Or { .. }))
2122+
.all(|match_pair| matches!(match_pair.testable_case, TestableCase::Or { .. }))
21202123
);
21212124

21222125
// Visit each leaf candidate within this subtree, add a copy of the remaining

0 commit comments

Comments
 (0)