Skip to content

Commit 8708f3c

Browse files
committed
Auto merge of #144490 - tgross35:rollup-ps0utme, r=tgross35
Rollup of 9 pull requests Successful merges: - #140871 (Don't lint against named labels in `naked_asm!`) - #141663 (rustdoc: add ways of collapsing all impl blocks) - #143272 (Upgrade the `fortanix-sgx-abi` dependency) - #143585 (`loop_match`: suggest extracting to a `const` item) - #143698 (Fix unused_parens false positive) - #143859 (Guarantee 8 bytes of alignment in Thread::into_raw) - #144160 (tests: debuginfo: Work around or disable broken tests on powerpc) - #144412 (Small cleanup: Use LocalKey<Cell> methods more) - #144431 (Disable has_reliable_f128_math on musl targets) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 051d0e8 + 39141d0 commit 8708f3c

File tree

28 files changed

+459
-61
lines changed

28 files changed

+459
-61
lines changed

compiler/rustc_ast/src/ast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2849,7 +2849,7 @@ impl InlineAsmOperand {
28492849
}
28502850
}
28512851

2852-
#[derive(Clone, Copy, Encodable, Decodable, Debug, HashStable_Generic, Walkable)]
2852+
#[derive(Clone, Copy, Encodable, Decodable, Debug, HashStable_Generic, Walkable, PartialEq, Eq)]
28532853
pub enum AsmMacro {
28542854
/// The `asm!` macro
28552855
Asm,

compiler/rustc_codegen_llvm/src/llvm_util.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,9 @@ fn update_target_reliable_float_cfg(sess: &Session, cfg: &mut TargetConfig) {
433433
// This rules out anything that doesn't have `long double` = `binary128`; <= 32 bits
434434
// (ld is `f64`), anything other than Linux (Windows and MacOS use `f64`), and `x86`
435435
// (ld is 80-bit extended precision).
436+
//
437+
// musl does not implement the symbols required for f128 math at all.
438+
_ if target_env == "musl" => false,
436439
("x86_64", _) => false,
437440
(_, "linux") if target_pointer_width == 64 => true,
438441
_ => false,

compiler/rustc_errors/src/markdown/term.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ thread_local! {
1818
pub(crate) fn entrypoint(stream: &MdStream<'_>, buf: &mut Buffer) -> io::Result<()> {
1919
#[cfg(not(test))]
2020
if let Some((w, _)) = termize::dimensions() {
21-
WIDTH.with(|c| c.set(std::cmp::min(w, DEFAULT_COLUMN_WIDTH)));
21+
WIDTH.set(std::cmp::min(w, DEFAULT_COLUMN_WIDTH));
2222
}
2323
write_stream(stream, buf, None, 0)?;
2424
buf.write_all(b"\n")
@@ -84,7 +84,7 @@ fn write_tt(tt: &MdTree<'_>, buf: &mut Buffer, indent: usize) -> io::Result<()>
8484
reset_cursor();
8585
}
8686
MdTree::HorizontalRule => {
87-
(0..WIDTH.with(Cell::get)).for_each(|_| buf.write_all(b"-").unwrap());
87+
(0..WIDTH.get()).for_each(|_| buf.write_all(b"-").unwrap());
8888
reset_cursor();
8989
}
9090
MdTree::Heading(n, stream) => {
@@ -121,7 +121,7 @@ fn write_tt(tt: &MdTree<'_>, buf: &mut Buffer, indent: usize) -> io::Result<()>
121121

122122
/// End of that block, just wrap the line
123123
fn reset_cursor() {
124-
CURSOR.with(|cur| cur.set(0));
124+
CURSOR.set(0);
125125
}
126126

127127
/// Change to be generic on Write for testing. If we have a link URL, we don't
@@ -144,7 +144,7 @@ fn write_wrapping<B: io::Write>(
144144
buf.write_all(ind_ws)?;
145145
cur.set(indent);
146146
}
147-
let ch_count = WIDTH.with(Cell::get) - cur.get();
147+
let ch_count = WIDTH.get() - cur.get();
148148
let mut iter = to_write.char_indices();
149149
let Some((end_idx, _ch)) = iter.nth(ch_count) else {
150150
// Write entire line

compiler/rustc_lint/src/builtin.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2870,14 +2870,23 @@ impl<'tcx> LateLintPass<'tcx> for AsmLabels {
28702870
if let hir::Expr {
28712871
kind:
28722872
hir::ExprKind::InlineAsm(hir::InlineAsm {
2873-
asm_macro: AsmMacro::Asm | AsmMacro::NakedAsm,
2873+
asm_macro: asm_macro @ (AsmMacro::Asm | AsmMacro::NakedAsm),
28742874
template_strs,
28752875
options,
28762876
..
28772877
}),
28782878
..
28792879
} = expr
28802880
{
2881+
// Non-generic naked functions are allowed to define arbitrary
2882+
// labels.
2883+
if *asm_macro == AsmMacro::NakedAsm {
2884+
let def_id = expr.hir_id.owner.def_id;
2885+
if !cx.tcx.generics_of(def_id).requires_monomorphization(cx.tcx) {
2886+
return;
2887+
}
2888+
}
2889+
28812890
// asm with `options(raw)` does not do replacement with `{` and `}`.
28822891
let raw = options.contains(InlineAsmOptions::RAW);
28832892

compiler/rustc_lint/src/unused.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1340,7 +1340,15 @@ impl EarlyLintPass for UnusedParens {
13401340
self.with_self_ty_parens = false;
13411341
}
13421342
ast::TyKind::Ref(_, mut_ty) | ast::TyKind::Ptr(mut_ty) => {
1343-
self.in_no_bounds_pos.insert(mut_ty.ty.id, NoBoundsException::OneBound);
1343+
// If this type itself appears in no-bounds position, we propagate its
1344+
// potentially tighter constraint or risk a false posive (issue 143653).
1345+
let own_constraint = self.in_no_bounds_pos.get(&ty.id);
1346+
let constraint = match own_constraint {
1347+
Some(NoBoundsException::None) => NoBoundsException::None,
1348+
Some(NoBoundsException::OneBound) => NoBoundsException::OneBound,
1349+
None => NoBoundsException::OneBound,
1350+
};
1351+
self.in_no_bounds_pos.insert(mut_ty.ty.id, constraint);
13441352
}
13451353
ast::TyKind::TraitObject(bounds, _) | ast::TyKind::ImplTrait(_, bounds) => {
13461354
for i in 0..bounds.len() {

compiler/rustc_middle/src/ty/print/pretty.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ macro_rules! define_helper {
8686

8787
impl $helper {
8888
pub fn new() -> $helper {
89-
$helper($tl.with(|c| c.replace(true)))
89+
$helper($tl.replace(true))
9090
}
9191
}
9292

@@ -100,12 +100,12 @@ macro_rules! define_helper {
100100

101101
impl Drop for $helper {
102102
fn drop(&mut self) {
103-
$tl.with(|c| c.set(self.0))
103+
$tl.set(self.0)
104104
}
105105
}
106106

107107
pub fn $name() -> bool {
108-
$tl.with(|c| c.get())
108+
$tl.get()
109109
}
110110
)+
111111
}

compiler/rustc_mir_build/messages.ftl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,16 @@ mir_build_confused = missing patterns are not covered because `{$variable}` is i
8686
8787
mir_build_const_continue_bad_const = could not determine the target branch for this `#[const_continue]`
8888
.label = this value is too generic
89-
.note = the value must be a literal or a monomorphic const
9089
9190
mir_build_const_continue_missing_value = a `#[const_continue]` must break to a label with a value
9291
92+
mir_build_const_continue_not_const = could not determine the target branch for this `#[const_continue]`
93+
.help = try extracting the expression into a `const` item
94+
95+
mir_build_const_continue_not_const_const_block = `const` blocks may use generics, and are not evaluated early enough
96+
mir_build_const_continue_not_const_const_other = this value must be a literal or a monomorphic const
97+
mir_build_const_continue_not_const_constant_parameter = constant parameters may use generics, and are not evaluated early enough
98+
9399
mir_build_const_continue_unknown_jump_target = the target of this `#[const_continue]` is not statically known
94100
.label = this value must be a literal or a monomorphic const
95101

compiler/rustc_mir_build/src/builder/scope.rs

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,9 @@ use tracing::{debug, instrument};
100100

101101
use super::matches::BuiltMatchTree;
102102
use crate::builder::{BlockAnd, BlockAndExtension, BlockFrame, Builder, CFG};
103-
use crate::errors::{ConstContinueBadConst, ConstContinueUnknownJumpTarget};
103+
use crate::errors::{
104+
ConstContinueBadConst, ConstContinueNotMonomorphicConst, ConstContinueUnknownJumpTarget,
105+
};
104106

105107
#[derive(Debug)]
106108
pub(crate) struct Scopes<'tcx> {
@@ -867,7 +869,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
867869
span_bug!(span, "break value must be a scope")
868870
};
869871

870-
let constant = match &self.thir[value].kind {
872+
let expr = &self.thir[value];
873+
let constant = match &expr.kind {
871874
ExprKind::Adt(box AdtExpr { variant_index, fields, base, .. }) => {
872875
assert!(matches!(base, AdtExprBase::None));
873876
assert!(fields.is_empty());
@@ -887,7 +890,27 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
887890
),
888891
}
889892
}
890-
_ => self.as_constant(&self.thir[value]),
893+
894+
ExprKind::Literal { .. }
895+
| ExprKind::NonHirLiteral { .. }
896+
| ExprKind::ZstLiteral { .. }
897+
| ExprKind::NamedConst { .. } => self.as_constant(&self.thir[value]),
898+
899+
other => {
900+
use crate::errors::ConstContinueNotMonomorphicConstReason as Reason;
901+
902+
let span = expr.span;
903+
let reason = match other {
904+
ExprKind::ConstParam { .. } => Reason::ConstantParameter { span },
905+
ExprKind::ConstBlock { .. } => Reason::ConstBlock { span },
906+
_ => Reason::Other { span },
907+
};
908+
909+
self.tcx
910+
.dcx()
911+
.emit_err(ConstContinueNotMonomorphicConst { span: expr.span, reason });
912+
return block.unit();
913+
}
891914
};
892915

893916
let break_index = self

compiler/rustc_mir_build/src/errors.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,6 +1213,38 @@ pub(crate) struct LoopMatchArmWithGuard {
12131213
pub span: Span,
12141214
}
12151215

1216+
#[derive(Diagnostic)]
1217+
#[diag(mir_build_const_continue_not_const)]
1218+
#[help]
1219+
pub(crate) struct ConstContinueNotMonomorphicConst {
1220+
#[primary_span]
1221+
pub span: Span,
1222+
1223+
#[subdiagnostic]
1224+
pub reason: ConstContinueNotMonomorphicConstReason,
1225+
}
1226+
1227+
#[derive(Subdiagnostic)]
1228+
pub(crate) enum ConstContinueNotMonomorphicConstReason {
1229+
#[label(mir_build_const_continue_not_const_constant_parameter)]
1230+
ConstantParameter {
1231+
#[primary_span]
1232+
span: Span,
1233+
},
1234+
1235+
#[label(mir_build_const_continue_not_const_const_block)]
1236+
ConstBlock {
1237+
#[primary_span]
1238+
span: Span,
1239+
},
1240+
1241+
#[label(mir_build_const_continue_not_const_const_other)]
1242+
Other {
1243+
#[primary_span]
1244+
span: Span,
1245+
},
1246+
}
1247+
12161248
#[derive(Diagnostic)]
12171249
#[diag(mir_build_const_continue_bad_const)]
12181250
pub(crate) struct ConstContinueBadConst {

compiler/rustc_query_system/src/query/plumbing.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,7 @@ fn incremental_verify_ich_failed<Tcx>(
720720
static INSIDE_VERIFY_PANIC: Cell<bool> = const { Cell::new(false) };
721721
};
722722

723-
let old_in_panic = INSIDE_VERIFY_PANIC.with(|in_panic| in_panic.replace(true));
723+
let old_in_panic = INSIDE_VERIFY_PANIC.replace(true);
724724

725725
if old_in_panic {
726726
tcx.sess().dcx().emit_err(crate::error::Reentrant);
@@ -739,7 +739,7 @@ fn incremental_verify_ich_failed<Tcx>(
739739
panic!("Found unstable fingerprints for {dep_node:?}: {}", result());
740740
}
741741

742-
INSIDE_VERIFY_PANIC.with(|in_panic| in_panic.set(old_in_panic));
742+
INSIDE_VERIFY_PANIC.set(old_in_panic);
743743
}
744744

745745
/// Ensure that either this query has all green inputs or been executed.

0 commit comments

Comments
 (0)