Skip to content

Commit 827a0d6

Browse files
committed
Auto merge of #137231 - Urgau:rollup-heiq934, r=Urgau
Rollup of 9 pull requests Successful merges: - #136750 (Make ub_check message clear that it's not an assert) - #137151 (Install more signal stack trace handlers) - #137167 (tests: Also gate `f16::erfc()` doctest with `reliable_f16_math` cfg) - #137195 (cg_clif: use exclusively ABI alignment) - #137202 (Enforce T: Hash for Interned<...>) - #137205 (Remove `std::os::wasi::fs::FileExt::tell`) - #137211 (don't ICE for alias-relate goals with error term) - #137214 (add last std diagnostic items for clippy) - #137221 (Remove scrutinee_hir_id from ExprKind::Match) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 3b022d8 + 3ebe11b commit 827a0d6

File tree

20 files changed

+134
-35
lines changed

20 files changed

+134
-35
lines changed

compiler/rustc_codegen_cranelift/src/abi/comments.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ pub(super) fn add_locals_header_comment(fx: &mut FunctionCx<'_, '_, '_>) {
6565
if fx.clif_comments.enabled() {
6666
fx.add_global_comment(String::new());
6767
fx.add_global_comment(
68-
"kind local ty size align (abi,pref)".to_string(),
68+
"kind local ty size align (abi)".to_string(),
6969
);
7070
}
7171
}
@@ -84,14 +84,13 @@ pub(super) fn add_local_place_comments<'tcx>(
8484
let (kind, extra) = place.debug_comment();
8585

8686
fx.add_global_comment(format!(
87-
"{:<5} {:5} {:30} {:4}b {}, {}{}{}",
87+
"{:<5} {:5} {:30} {:4}b {}{}{}",
8888
kind,
8989
format!("{:?}", local),
9090
format!("{:?}", ty),
9191
size.bytes(),
9292
align.abi.bytes(),
93-
align.pref.bytes(),
94-
if extra.is_empty() { "" } else { " " },
93+
if extra.is_empty() { "" } else { " " },
9594
extra,
9695
));
9796
}

compiler/rustc_codegen_cranelift/src/constant.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ fn data_id_for_static(
272272
.layout_of(ty::TypingEnv::fully_monomorphized().as_query_input(ty))
273273
.unwrap()
274274
.align
275-
.pref
275+
.abi
276276
.bytes();
277277

278278
let linkage = if import_linkage == rustc_middle::mir::mono::Linkage::ExternalWeak

compiler/rustc_data_structures/src/intern.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,10 @@ impl<'a, T: Ord> Ord for Interned<'a, T> {
9292
}
9393
}
9494

95-
impl<'a, T> Hash for Interned<'a, T> {
95+
impl<'a, T> Hash for Interned<'a, T>
96+
where
97+
T: Hash,
98+
{
9699
#[inline]
97100
fn hash<H: Hasher>(&self, s: &mut H) {
98101
// Pointer hashing is sufficient, due to the uniqueness constraint.

compiler/rustc_driver_impl/src/signal_handler.rs

+39-11
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@ use std::{fmt, mem, ptr, slice};
66

77
use rustc_interface::util::{DEFAULT_STACK_SIZE, STACK_SIZE};
88

9+
/// Signals that represent that we have a bug, and our prompt termination has
10+
/// been ordered.
11+
#[rustfmt::skip]
12+
const KILL_SIGNALS: [(libc::c_int, &str); 3] = [
13+
(libc::SIGILL, "SIGILL"),
14+
(libc::SIGBUS, "SIGBUS"),
15+
(libc::SIGSEGV, "SIGSEGV")
16+
];
17+
918
unsafe extern "C" {
1019
fn backtrace_symbols_fd(buffer: *const *mut libc::c_void, size: libc::c_int, fd: libc::c_int);
1120
}
@@ -39,8 +48,19 @@ macro raw_errln($tokens:tt) {
3948
/// # Safety
4049
///
4150
/// Caller must ensure that this function is not re-entered.
42-
unsafe extern "C" fn print_stack_trace(_: libc::c_int) {
51+
unsafe extern "C" fn print_stack_trace(signum: libc::c_int) {
4352
const MAX_FRAMES: usize = 256;
53+
54+
let signame = {
55+
let mut signame = "<unknown>";
56+
for sig in KILL_SIGNALS {
57+
if sig.0 == signum {
58+
signame = sig.1;
59+
}
60+
}
61+
signame
62+
};
63+
4464
let stack = unsafe {
4565
// Reserve data segment so we don't have to malloc in a signal handler, which might fail
4666
// in incredibly undesirable and unexpected ways due to e.g. the allocator deadlocking
@@ -54,7 +74,8 @@ unsafe extern "C" fn print_stack_trace(_: libc::c_int) {
5474
};
5575

5676
// Just a stack trace is cryptic. Explain what we're doing.
57-
raw_errln!("error: rustc interrupted by SIGSEGV, printing backtrace\n");
77+
raw_errln!("error: rustc interrupted by {signame}, printing backtrace\n");
78+
5879
let mut written = 1;
5980
let mut consumed = 0;
6081
// Begin elaborating return addrs into symbols and writing them directly to stderr
@@ -94,7 +115,7 @@ unsafe extern "C" fn print_stack_trace(_: libc::c_int) {
94115
written += rem.len() + 1;
95116

96117
let random_depth = || 8 * 16; // chosen by random diceroll (2d20)
97-
if cyclic || stack.len() > random_depth() {
118+
if (cyclic || stack.len() > random_depth()) && signum == libc::SIGSEGV {
98119
// technically speculation, but assert it with confidence anyway.
99120
// rustc only arrived in this signal handler because bad things happened
100121
// and this message is for explaining it's not the programmer's fault
@@ -106,17 +127,22 @@ unsafe extern "C" fn print_stack_trace(_: libc::c_int) {
106127
written += 1;
107128
}
108129
raw_errln!("note: we would appreciate a report at https://github.com/rust-lang/rust");
109-
// get the current stack size WITHOUT blocking and double it
110-
let new_size = STACK_SIZE.get().copied().unwrap_or(DEFAULT_STACK_SIZE) * 2;
111-
raw_errln!("help: you can increase rustc's stack size by setting RUST_MIN_STACK={new_size}");
112-
written += 2;
130+
written += 1;
131+
if signum == libc::SIGSEGV {
132+
// get the current stack size WITHOUT blocking and double it
133+
let new_size = STACK_SIZE.get().copied().unwrap_or(DEFAULT_STACK_SIZE) * 2;
134+
raw_errln!(
135+
"help: you can increase rustc's stack size by setting RUST_MIN_STACK={new_size}"
136+
);
137+
written += 1;
138+
}
113139
if written > 24 {
114-
// We probably just scrolled the earlier "we got SIGSEGV" message off the terminal
115-
raw_errln!("note: backtrace dumped due to SIGSEGV! resuming signal");
140+
// We probably just scrolled the earlier "interrupted by {signame}" message off the terminal
141+
raw_errln!("note: backtrace dumped due to {signame}! resuming signal");
116142
};
117143
}
118144

119-
/// When SIGSEGV is delivered to the process, print a stack trace and then exit.
145+
/// When one of the KILL signals is delivered to the process, print a stack trace and then exit.
120146
pub(super) fn install() {
121147
unsafe {
122148
let alt_stack_size: usize = min_sigstack_size() + 64 * 1024;
@@ -129,7 +155,9 @@ pub(super) fn install() {
129155
sa.sa_sigaction = print_stack_trace as libc::sighandler_t;
130156
sa.sa_flags = libc::SA_NODEFER | libc::SA_RESETHAND | libc::SA_ONSTACK;
131157
libc::sigemptyset(&mut sa.sa_mask);
132-
libc::sigaction(libc::SIGSEGV, &sa, ptr::null_mut());
158+
for (signum, _signame) in KILL_SIGNALS {
159+
libc::sigaction(signum, &sa, ptr::null_mut());
160+
}
133161
}
134162
}
135163

compiler/rustc_middle/src/thir.rs

-1
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,6 @@ pub enum ExprKind<'tcx> {
376376
/// A `match` expression.
377377
Match {
378378
scrutinee: ExprId,
379-
scrutinee_hir_id: HirId,
380379
arms: Box<[ArmId]>,
381380
match_source: MatchSource,
382381
},

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

-1
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,6 @@ impl<'tcx> ThirBuildCx<'tcx> {
828828
},
829829
hir::ExprKind::Match(discr, arms, match_source) => ExprKind::Match {
830830
scrutinee: self.mirror_expr(discr),
831-
scrutinee_hir_id: discr.hir_id,
832831
arms: arms.iter().map(|a| self.convert_arm(a)).collect(),
833832
match_source,
834833
},

compiler/rustc_mir_build/src/thir/pattern/check_match.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ impl<'p, 'tcx> Visitor<'p, 'tcx> for MatchVisitor<'p, 'tcx> {
151151
}
152152
return;
153153
}
154-
ExprKind::Match { scrutinee, scrutinee_hir_id: _, box ref arms, match_source } => {
154+
ExprKind::Match { scrutinee, box ref arms, match_source } => {
155155
self.check_match(scrutinee, arms, match_source, ex.span);
156156
}
157157
ExprKind::Let { box ref pat, expr } => {

compiler/rustc_next_trait_solver/src/solve/alias_relate.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,17 @@ where
3434
) -> QueryResult<I> {
3535
let cx = self.cx();
3636
let Goal { param_env, predicate: (lhs, rhs, direction) } = goal;
37-
debug_assert!(lhs.to_alias_term().is_some() || rhs.to_alias_term().is_some());
37+
38+
// Check that the alias-relate goal is reasonable. Writeback for
39+
// `coroutine_stalled_predicates` can replace alias terms with
40+
// `{type error}` if the alias still contains infer vars, so we also
41+
// accept alias-relate goals where one of the terms is an error.
42+
debug_assert!(
43+
lhs.to_alias_term().is_some()
44+
|| rhs.to_alias_term().is_some()
45+
|| lhs.is_error()
46+
|| rhs.is_error()
47+
);
3848

3949
// Structurally normalize the lhs.
4050
let lhs = if let Some(alias) = lhs.to_alias_term() {

compiler/rustc_resolve/src/imports.rs

+13
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,19 @@ pub(crate) struct ImportData<'ra> {
182182
/// so we can use referential equality to compare them.
183183
pub(crate) type Import<'ra> = Interned<'ra, ImportData<'ra>>;
184184

185+
// Allows us to use Interned without actually enforcing (via Hash/PartialEq/...) uniqueness of the
186+
// contained data.
187+
// FIXME: We may wish to actually have at least debug-level assertions that Interned's guarantees
188+
// are upheld.
189+
impl std::hash::Hash for ImportData<'_> {
190+
fn hash<H>(&self, _: &mut H)
191+
where
192+
H: std::hash::Hasher,
193+
{
194+
unreachable!()
195+
}
196+
}
197+
185198
impl<'ra> ImportData<'ra> {
186199
pub(crate) fn is_glob(&self) -> bool {
187200
matches!(self.kind, ImportKind::Glob { .. })

compiler/rustc_resolve/src/lib.rs

+26
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,19 @@ struct ModuleData<'ra> {
589589
#[rustc_pass_by_value]
590590
struct Module<'ra>(Interned<'ra, ModuleData<'ra>>);
591591

592+
// Allows us to use Interned without actually enforcing (via Hash/PartialEq/...) uniqueness of the
593+
// contained data.
594+
// FIXME: We may wish to actually have at least debug-level assertions that Interned's guarantees
595+
// are upheld.
596+
impl std::hash::Hash for ModuleData<'_> {
597+
fn hash<H>(&self, _: &mut H)
598+
where
599+
H: std::hash::Hasher,
600+
{
601+
unreachable!()
602+
}
603+
}
604+
592605
impl<'ra> ModuleData<'ra> {
593606
fn new(
594607
parent: Option<Module<'ra>>,
@@ -739,6 +752,19 @@ struct NameBindingData<'ra> {
739752
/// so we can use referential equality to compare them.
740753
type NameBinding<'ra> = Interned<'ra, NameBindingData<'ra>>;
741754

755+
// Allows us to use Interned without actually enforcing (via Hash/PartialEq/...) uniqueness of the
756+
// contained data.
757+
// FIXME: We may wish to actually have at least debug-level assertions that Interned's guarantees
758+
// are upheld.
759+
impl std::hash::Hash for NameBindingData<'_> {
760+
fn hash<H>(&self, _: &mut H)
761+
where
762+
H: std::hash::Hasher,
763+
{
764+
unreachable!()
765+
}
766+
}
767+
742768
trait ToNameBinding<'ra> {
743769
fn to_name_binding(self, arenas: &'ra ResolverArenas<'ra>) -> NameBinding<'ra>;
744770
}

compiler/rustc_span/src/symbol.rs

+7
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ symbols! {
192192
Capture,
193193
Cell,
194194
Center,
195+
Child,
195196
Cleanup,
196197
Clone,
197198
CoercePointee,
@@ -336,6 +337,7 @@ symbols! {
336337
SliceIter,
337338
Some,
338339
SpanCtxt,
340+
Stdin,
339341
String,
340342
StructuralPartialEq,
341343
SubdiagMessage,
@@ -599,6 +601,9 @@ symbols! {
599601
cfi,
600602
cfi_encoding,
601603
char,
604+
char_is_ascii,
605+
child_id,
606+
child_kill,
602607
client,
603608
clippy,
604609
clobber_abi,
@@ -1468,6 +1473,7 @@ symbols! {
14681473
panic_2015,
14691474
panic_2021,
14701475
panic_abort,
1476+
panic_any,
14711477
panic_bounds_check,
14721478
panic_cannot_unwind,
14731479
panic_const_add_overflow,
@@ -1573,6 +1579,7 @@ symbols! {
15731579
proc_macro_mod,
15741580
proc_macro_non_items,
15751581
proc_macro_path_invoc,
1582+
process_abort,
15761583
process_exit,
15771584
profiler_builtins,
15781585
profiler_runtime,

compiler/rustc_type_ir/src/inherent.rs

+15
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@ pub trait Ty<I: Interner<Ty = Self>>:
126126
matches!(self.kind(), ty::Infer(ty::TyVar(_)))
127127
}
128128

129+
fn is_ty_error(self) -> bool {
130+
matches!(self.kind(), ty::Error(_))
131+
}
132+
129133
fn is_floating_point(self) -> bool {
130134
matches!(self.kind(), ty::Float(_) | ty::Infer(ty::FloatVar(_)))
131135
}
@@ -284,6 +288,10 @@ pub trait Const<I: Interner<Const = Self>>:
284288
fn is_ct_var(self) -> bool {
285289
matches!(self.kind(), ty::ConstKind::Infer(ty::InferConst::Var(_)))
286290
}
291+
292+
fn is_ct_error(self) -> bool {
293+
matches!(self.kind(), ty::ConstKind::Error(_))
294+
}
287295
}
288296

289297
pub trait ValueConst<I: Interner<ValueConst = Self>>: Copy + Debug + Hash + Eq {
@@ -370,6 +378,13 @@ pub trait Term<I: Interner<Term = Self>>:
370378
}
371379
}
372380

381+
fn is_error(self) -> bool {
382+
match self.kind() {
383+
ty::TermKind::Ty(ty) => ty.is_ty_error(),
384+
ty::TermKind::Const(ct) => ct.is_ct_error(),
385+
}
386+
}
387+
373388
fn to_alias_term(self) -> Option<ty::AliasTerm<I>> {
374389
match self.kind() {
375390
ty::TermKind::Ty(ty) => match ty.kind() {

library/core/src/char/methods.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1168,6 +1168,7 @@ impl char {
11681168
#[must_use]
11691169
#[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")]
11701170
#[rustc_const_stable(feature = "const_char_is_ascii", since = "1.32.0")]
1171+
#[cfg_attr(not(test), rustc_diagnostic_item = "char_is_ascii")]
11711172
#[inline]
11721173
pub const fn is_ascii(&self) -> bool {
11731174
*self as u32 <= 0x7F

library/core/src/ub_checks.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ macro_rules! assert_unsafe_precondition {
6565
#[rustc_nounwind]
6666
const fn precondition_check($($name:$ty),*) {
6767
if !$e {
68-
::core::panicking::panic_nounwind(
69-
concat!("unsafe precondition(s) violated: ", $message)
70-
);
68+
::core::panicking::panic_nounwind(concat!("unsafe precondition(s) violated: ", $message,
69+
"\n\nThis indicates a bug in the program. \
70+
This Undefined Behavior check is optional, and cannot be relied on for safety."));
7171
}
7272
}
7373

library/std/src/f16.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1321,12 +1321,14 @@ impl f16 {
13211321
/// ```
13221322
/// #![feature(f16)]
13231323
/// #![feature(float_erf)]
1324+
/// # #[cfg(reliable_f16_math)] {
13241325
/// let x: f16 = 0.123;
13251326
///
13261327
/// let one = x.erf() + x.erfc();
13271328
/// let abs_difference = (one - 1.0).abs();
13281329
///
13291330
/// assert!(abs_difference <= f16::EPSILON);
1331+
/// # }
13301332
/// ```
13311333
#[rustc_allow_incoherent_impl]
13321334
#[must_use = "method returns a new number and does not mutate the original value"]

library/std/src/io/stdio.rs

+1
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ fn handle_ebadf_lazy<T>(r: io::Result<T>, default: impl FnOnce() -> T) -> io::Re
239239
/// }
240240
/// ```
241241
#[stable(feature = "rust1", since = "1.0.0")]
242+
#[cfg_attr(not(test), rustc_diagnostic_item = "Stdin")]
242243
pub struct Stdin {
243244
inner: &'static Mutex<BufReader<StdinRaw>>,
244245
}

library/std/src/os/wasi/fs.rs

-11
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,6 @@ pub trait FileExt {
162162
Ok(())
163163
}
164164

165-
/// Returns the current position within the file.
166-
///
167-
/// This corresponds to the `fd_tell` syscall and is similar to
168-
/// `seek` where you offset 0 bytes from the current position.
169-
#[doc(alias = "fd_tell")]
170-
fn tell(&self) -> io::Result<u64>;
171-
172165
/// Adjusts the flags associated with this file.
173166
///
174167
/// This corresponds to the `fd_fdstat_set_flags` syscall.
@@ -240,10 +233,6 @@ impl FileExt for fs::File {
240233
self.as_inner().as_inner().pwrite(bufs, offset)
241234
}
242235

243-
fn tell(&self) -> io::Result<u64> {
244-
self.as_inner().as_inner().tell()
245-
}
246-
247236
fn fdstat_set_flags(&self, flags: u16) -> io::Result<()> {
248237
self.as_inner().as_inner().set_flags(flags)
249238
}

0 commit comments

Comments
 (0)