Skip to content

Commit 9e0a42c

Browse files
committed
Auto merge of #154151 - JonathanBrouwer:rollup-qLQ5uET, r=JonathanBrouwer
Rollup of 5 pull requests Successful merges: - #153828 (Guard patterns: lowering to THIR) - #154015 (refactor - moving `check_stability` check to `parse_stability`) - #154119 (llvm: Update `reliable_f128` configuration for LLVM22 on Sparc) - #154138 (vec::Drain::fill: avoid reference to uninitialized memory) - #154143 (test copy_specializes_from_vecdeque: reduce iteration count for Miri)
2 parents ac7f9ec + 80faf6f commit 9e0a42c

21 files changed

Lines changed: 131 additions & 98 deletions

File tree

compiler/rustc_attr_parsing/src/attributes/stability.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::num::NonZero;
22

33
use rustc_errors::ErrorGuaranteed;
4+
use rustc_feature::ACCEPTED_LANG_FEATURES;
45
use rustc_hir::target::GenericParamKind;
56
use rustc_hir::{
67
DefaultBodyStability, MethodKind, PartialConstStability, Stability, StabilityLevel,
@@ -366,7 +367,7 @@ pub(crate) fn parse_stability<S: Stage>(
366367
}
367368
}
368369

369-
// Read the content of a `unstable`/`rustc_const_unstable`/`rustc_default_body_unstable`
370+
/// Read the content of a `unstable`/`rustc_const_unstable`/`rustc_default_body_unstable`
370371
/// attribute, and return the feature name and its stability information.
371372
pub(crate) fn parse_unstability<S: Stage>(
372373
cx: &AcceptContext<'_, '_, S>,
@@ -451,6 +452,16 @@ pub(crate) fn parse_unstability<S: Stage>(
451452

452453
match (feature, issue) {
453454
(Ok(feature), Ok(_)) => {
455+
// Stable *language* features shouldn't be used as unstable library features.
456+
// (Not doing this for stable library features is checked by tidy.)
457+
if ACCEPTED_LANG_FEATURES.iter().any(|f| f.name == feature) {
458+
cx.emit_err(session_diagnostics::UnstableAttrForAlreadyStableFeature {
459+
attr_span: cx.attr_span,
460+
item_span: cx.target_span,
461+
});
462+
return None;
463+
}
464+
454465
let level = StabilityLevel::Unstable {
455466
reason: UnstableReason::from_opt_reason(reason),
456467
issue: issue_num,

compiler/rustc_attr_parsing/src/session_diagnostics.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,3 +1046,14 @@ pub(crate) struct CustomMirIncompatibleDialectAndPhase {
10461046
#[label("... is not compatible with this phase")]
10471047
pub phase_span: Span,
10481048
}
1049+
1050+
#[derive(Diagnostic)]
1051+
#[diag("can't mark as unstable using an already stable feature")]
1052+
pub(crate) struct UnstableAttrForAlreadyStableFeature {
1053+
#[primary_span]
1054+
#[label("this feature is already stable")]
1055+
#[help("consider removing the attribute")]
1056+
pub attr_span: Span,
1057+
#[label("the stability attribute annotates this item")]
1058+
pub item_span: Span,
1059+
}

compiler/rustc_codegen_llvm/src/llvm_util.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,8 +394,8 @@ fn update_target_reliable_float_cfg(sess: &Session, cfg: &mut TargetConfig) {
394394
// ABI bugs <https://github.com/rust-lang/rust/issues/125109> et al. (full
395395
// list at <https://github.com/rust-lang/rust/issues/116909>)
396396
(Arch::PowerPC | Arch::PowerPC64, _) => false,
397-
// ABI unsupported <https://github.com/llvm/llvm-project/issues/41838>
398-
(Arch::Sparc, _) => false,
397+
// ABI unsupported <https://github.com/llvm/llvm-project/issues/41838> (fixed in llvm22)
398+
(Arch::Sparc, _) if major < 22 => false,
399399
// MinGW ABI bugs <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115054>
400400
(Arch::X86_64, Os::Windows) if *target_env == Env::Gnu && *target_abi != Abi::Llvm => false,
401401
// There are no known problems on other platforms, so the only requirement is that symbols

compiler/rustc_middle/src/thir.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -866,6 +866,13 @@ pub enum PatKind<'tcx> {
866866
pats: Box<[Pat<'tcx>]>,
867867
},
868868

869+
/// A guard pattern, e.g. `x if guard(x)`
870+
Guard {
871+
subpattern: Box<Pat<'tcx>>,
872+
#[type_visitable(ignore)]
873+
condition: ExprId,
874+
},
875+
869876
/// A never pattern `!`.
870877
Never,
871878

compiler/rustc_middle/src/thir/visit.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,12 @@ pub fn walk_pat<'thir, 'tcx: 'thir, V: Visitor<'thir, 'tcx>>(
247247
visitor: &mut V,
248248
pat: &'thir Pat<'tcx>,
249249
) {
250+
if let PatKind::Guard { subpattern, condition } = &pat.kind {
251+
visitor.visit_pat(subpattern);
252+
visitor.visit_expr(&visitor.thir()[*condition]);
253+
return;
254+
};
255+
250256
for_each_immediate_subpat(pat, |p| visitor.visit_pat(p));
251257
}
252258

@@ -287,5 +293,9 @@ pub(crate) fn for_each_immediate_subpat<'a, 'tcx>(
287293
callback(pat);
288294
}
289295
}
296+
297+
PatKind::Guard { subpattern, .. } => {
298+
callback(subpattern);
299+
}
290300
}
291301
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,11 @@ impl<'tcx> MatchPairTree<'tcx> {
360360
Some(TestableCase::Deref { temp, mutability })
361361
}
362362

363+
PatKind::Guard { .. } => {
364+
// FIXME(guard_patterns)
365+
None
366+
}
367+
363368
PatKind::Never => Some(TestableCase::Never),
364369
};
365370

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -944,6 +944,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
944944
visit_subpat(self, subpattern, user_tys, f);
945945
}
946946
}
947+
PatKind::Guard { ref subpattern, .. } => {
948+
visit_subpat(self, subpattern, user_tys, f);
949+
}
947950
}
948951
}
949952
}

compiler/rustc_mir_build/src/check_unsafety.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@ impl<'a, 'tcx> Visitor<'a, 'tcx> for UnsafetyVisitor<'a, 'tcx> {
315315
| PatKind::Range { .. }
316316
| PatKind::Slice { .. }
317317
| PatKind::Array { .. }
318+
| PatKind::Guard { .. }
318319
// Never constitutes a witness of uninhabitedness.
319320
| PatKind::Never => {
320321
self.requires_unsafe(pat.span, AccessToUnionField);

compiler/rustc_mir_build/src/thir/cx/block.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ impl<'tcx> ThirBuildCx<'tcx> {
8383
}
8484
Some(_) | None => local.span,
8585
};
86+
let initializer = local.init.map(|init| self.mirror_expr(init));
8687
let stmt = Stmt {
8788
kind: StmtKind::Let {
8889
remainder_scope,
@@ -91,7 +92,7 @@ impl<'tcx> ThirBuildCx<'tcx> {
9192
data: region::ScopeData::Node,
9293
},
9394
pattern,
94-
initializer: local.init.map(|init| self.mirror_expr(init)),
95+
initializer,
9596
else_block,
9697
hir_id: local.hir_id,
9798
span,

compiler/rustc_mir_build/src/thir/cx/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -876,7 +876,7 @@ impl<'tcx> ThirBuildCx<'tcx> {
876876
};
877877

878878
let indices = self.typeck_results.offset_of_data().get(expr.hir_id).unwrap();
879-
let mut expr = None::<ExprKind<'tcx>>;
879+
let mut expr = None::<ExprKind<'_>>;
880880

881881
for &(container, variant, field) in indices.iter() {
882882
let next = mk_call(&mut self.thir, container, variant, field);

0 commit comments

Comments
 (0)