Skip to content

Commit 1852728

Browse files
committed
Auto merge of rust-lang#123230 - matthiaskrgr:rollup-4twuzj4, r=matthiaskrgr
Rollup of 5 pull requests Successful merges: - rust-lang#121573 (unix_sigpipe: Add test for SIGPIPE disposition in child processes) - rust-lang#123170 (Replace regions in const canonical vars' types with `'static` in next-solver canonicalizer) - rust-lang#123200 (KCFI: Require -C panic=abort) - rust-lang#123201 (Improve wording in std::any explanation) - rust-lang#123224 (compiletest: print reason for failing to read tests) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 40116ad + 9b067df commit 1852728

File tree

20 files changed

+234
-79
lines changed

20 files changed

+234
-79
lines changed

compiler/rustc_middle/src/ty/region.rs

+4
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,10 @@ impl<'tcx> rustc_type_ir::new::Region<TyCtxt<'tcx>> for Region<'tcx> {
140140
fn new_anon_bound(tcx: TyCtxt<'tcx>, debruijn: ty::DebruijnIndex, var: ty::BoundVar) -> Self {
141141
Region::new_bound(tcx, debruijn, ty::BoundRegion { var, kind: ty::BoundRegionKind::BrAnon })
142142
}
143+
144+
fn new_static(tcx: TyCtxt<'tcx>) -> Self {
145+
tcx.lifetimes.re_static
146+
}
143147
}
144148

145149
/// Region utilities

compiler/rustc_next_trait_solver/src/canonicalizer.rs

+58-31
Original file line numberDiff line numberDiff line change
@@ -296,10 +296,7 @@ impl<Infcx: InferCtxtLike<Interner = I>, I: Interner> TypeFolder<I>
296296
Region::new_anon_bound(self.interner(), self.binder_index, var)
297297
}
298298

299-
fn fold_ty(&mut self, t: I::Ty) -> I::Ty
300-
where
301-
I::Ty: TypeSuperFoldable<I>,
302-
{
299+
fn fold_ty(&mut self, t: I::Ty) -> I::Ty {
303300
let kind = match t.kind() {
304301
ty::Infer(i) => match i {
305302
ty::TyVar(vid) => {
@@ -378,47 +375,48 @@ impl<Infcx: InferCtxtLike<Interner = I>, I: Interner> TypeFolder<I>
378375
Ty::new_anon_bound(self.interner(), self.binder_index, var)
379376
}
380377

381-
fn fold_const(&mut self, c: I::Const) -> I::Const
382-
where
383-
I::Const: TypeSuperFoldable<I>,
384-
{
378+
fn fold_const(&mut self, c: I::Const) -> I::Const {
379+
// We could canonicalize all consts with static types, but the only ones we
380+
// *really* need to worry about are the ones that we end up putting into `CanonicalVarKind`
381+
// since canonical vars can't reference other canonical vars.
382+
let ty = c
383+
.ty()
384+
.fold_with(&mut RegionsToStatic { interner: self.interner(), binder: ty::INNERMOST });
385385
let kind = match c.kind() {
386-
ty::ConstKind::Infer(i) => {
387-
// FIXME: we should fold the ty too eventually
388-
match i {
389-
ty::InferConst::Var(vid) => {
390-
assert_eq!(
391-
self.infcx.root_ct_var(vid),
392-
vid,
393-
"region vid should have been resolved fully before canonicalization"
394-
);
395-
assert_eq!(
396-
self.infcx.probe_ct_var(vid),
397-
None,
398-
"region vid should have been resolved fully before canonicalization"
399-
);
400-
CanonicalVarKind::Const(self.infcx.universe_of_ct(vid).unwrap(), c.ty())
401-
}
402-
ty::InferConst::EffectVar(_) => CanonicalVarKind::Effect,
403-
ty::InferConst::Fresh(_) => todo!(),
386+
ty::ConstKind::Infer(i) => match i {
387+
ty::InferConst::Var(vid) => {
388+
assert_eq!(
389+
self.infcx.root_ct_var(vid),
390+
vid,
391+
"region vid should have been resolved fully before canonicalization"
392+
);
393+
assert_eq!(
394+
self.infcx.probe_ct_var(vid),
395+
None,
396+
"region vid should have been resolved fully before canonicalization"
397+
);
398+
CanonicalVarKind::Const(self.infcx.universe_of_ct(vid).unwrap(), ty)
404399
}
405-
}
400+
ty::InferConst::EffectVar(_) => CanonicalVarKind::Effect,
401+
ty::InferConst::Fresh(_) => todo!(),
402+
},
406403
ty::ConstKind::Placeholder(placeholder) => match self.canonicalize_mode {
407404
CanonicalizeMode::Input => CanonicalVarKind::PlaceholderConst(
408405
PlaceholderLike::new(placeholder.universe(), self.variables.len().into()),
409-
c.ty(),
406+
ty,
410407
),
411408
CanonicalizeMode::Response { .. } => {
412-
CanonicalVarKind::PlaceholderConst(placeholder, c.ty())
409+
CanonicalVarKind::PlaceholderConst(placeholder, ty)
413410
}
414411
},
415412
ty::ConstKind::Param(_) => match self.canonicalize_mode {
416413
CanonicalizeMode::Input => CanonicalVarKind::PlaceholderConst(
417414
PlaceholderLike::new(ty::UniverseIndex::ROOT, self.variables.len().into()),
418-
c.ty(),
415+
ty,
419416
),
420417
CanonicalizeMode::Response { .. } => panic!("param ty in response: {c:?}"),
421418
},
419+
// FIXME: See comment above -- we could fold the region separately or something.
422420
ty::ConstKind::Bound(_, _)
423421
| ty::ConstKind::Unevaluated(_)
424422
| ty::ConstKind::Value(_)
@@ -435,6 +433,35 @@ impl<Infcx: InferCtxtLike<Interner = I>, I: Interner> TypeFolder<I>
435433
}),
436434
);
437435

438-
Const::new_anon_bound(self.interner(), self.binder_index, var, c.ty())
436+
Const::new_anon_bound(self.interner(), self.binder_index, var, ty)
437+
}
438+
}
439+
440+
struct RegionsToStatic<I> {
441+
interner: I,
442+
binder: ty::DebruijnIndex,
443+
}
444+
445+
impl<I: Interner> TypeFolder<I> for RegionsToStatic<I> {
446+
fn interner(&self) -> I {
447+
self.interner
448+
}
449+
450+
fn fold_binder<T>(&mut self, t: I::Binder<T>) -> I::Binder<T>
451+
where
452+
T: TypeFoldable<I>,
453+
I::Binder<T>: TypeSuperFoldable<I>,
454+
{
455+
self.binder.shift_in(1);
456+
let t = t.fold_with(self);
457+
self.binder.shift_out(1);
458+
t
459+
}
460+
461+
fn fold_region(&mut self, r: I::Region) -> I::Region {
462+
match r.kind() {
463+
ty::ReBound(db, _) if self.binder > db => r,
464+
_ => Region::new_static(self.interner()),
465+
}
439466
}
440467
}

compiler/rustc_session/messages.ftl

+2
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ session_sanitizer_cfi_requires_lto = `-Zsanitizer=cfi` requires `-Clto` or `-Cli
9696
9797
session_sanitizer_cfi_requires_single_codegen_unit = `-Zsanitizer=cfi` with `-Clto` requires `-Ccodegen-units=1`
9898
99+
session_sanitizer_kcfi_requires_panic_abort = `-Z sanitizer=kcfi` requires `-C panic=abort`
100+
99101
session_sanitizer_not_supported = {$us} sanitizer is not supported for this target
100102
101103
session_sanitizers_not_supported = {$us} sanitizers are not supported for this target

compiler/rustc_session/src/errors.rs

+4
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,10 @@ pub(crate) struct SanitizerCfiGeneralizePointersRequiresCfi;
145145
#[diag(session_sanitizer_cfi_normalize_integers_requires_cfi)]
146146
pub(crate) struct SanitizerCfiNormalizeIntegersRequiresCfi;
147147

148+
#[derive(Diagnostic)]
149+
#[diag(session_sanitizer_kcfi_requires_panic_abort)]
150+
pub(crate) struct SanitizerKcfiRequiresPanicAbort;
151+
148152
#[derive(Diagnostic)]
149153
#[diag(session_split_lto_unit_requires_lto)]
150154
pub(crate) struct SplitLtoUnitRequiresLto;

compiler/rustc_session/src/session.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1211,6 +1211,11 @@ fn validate_commandline_args_with_session_available(sess: &Session) {
12111211
sess.dcx().emit_err(errors::SanitizerCfiRequiresLto);
12121212
}
12131213

1214+
// KCFI requires panic=abort
1215+
if sess.is_sanitizer_kcfi_enabled() && sess.panic_strategy() != PanicStrategy::Abort {
1216+
sess.dcx().emit_err(errors::SanitizerKcfiRequiresPanicAbort);
1217+
}
1218+
12141219
// LLVM CFI using rustc LTO requires a single codegen unit.
12151220
if sess.is_sanitizer_cfi_enabled()
12161221
&& sess.lto() == config::Lto::Fat

compiler/rustc_type_ir/src/fold.rs

+11-40
Original file line numberDiff line numberDiff line change
@@ -136,31 +136,21 @@ pub trait TypeFolder<I: Interner>: FallibleTypeFolder<I, Error = Never> {
136136
t.super_fold_with(self)
137137
}
138138

139-
fn fold_ty(&mut self, t: I::Ty) -> I::Ty
140-
where
141-
I::Ty: TypeSuperFoldable<I>,
142-
{
139+
fn fold_ty(&mut self, t: I::Ty) -> I::Ty {
143140
t.super_fold_with(self)
144141
}
145142

146143
// The default region folder is a no-op because `Region` is non-recursive
147-
// and has no `super_fold_with` method to call. That also explains the
148-
// lack of `I::Region: TypeSuperFoldable<I>` bound on this method.
144+
// and has no `super_fold_with` method to call.
149145
fn fold_region(&mut self, r: I::Region) -> I::Region {
150146
r
151147
}
152148

153-
fn fold_const(&mut self, c: I::Const) -> I::Const
154-
where
155-
I::Const: TypeSuperFoldable<I>,
156-
{
149+
fn fold_const(&mut self, c: I::Const) -> I::Const {
157150
c.super_fold_with(self)
158151
}
159152

160-
fn fold_predicate(&mut self, p: I::Predicate) -> I::Predicate
161-
where
162-
I::Predicate: TypeSuperFoldable<I>,
163-
{
153+
fn fold_predicate(&mut self, p: I::Predicate) -> I::Predicate {
164154
p.super_fold_with(self)
165155
}
166156
}
@@ -185,31 +175,21 @@ pub trait FallibleTypeFolder<I: Interner>: Sized {
185175
t.try_super_fold_with(self)
186176
}
187177

188-
fn try_fold_ty(&mut self, t: I::Ty) -> Result<I::Ty, Self::Error>
189-
where
190-
I::Ty: TypeSuperFoldable<I>,
191-
{
178+
fn try_fold_ty(&mut self, t: I::Ty) -> Result<I::Ty, Self::Error> {
192179
t.try_super_fold_with(self)
193180
}
194181

195182
// The default region folder is a no-op because `Region` is non-recursive
196-
// and has no `super_fold_with` method to call. That also explains the
197-
// lack of `I::Region: TypeSuperFoldable<I>` bound on this method.
183+
// and has no `super_fold_with` method to call.
198184
fn try_fold_region(&mut self, r: I::Region) -> Result<I::Region, Self::Error> {
199185
Ok(r)
200186
}
201187

202-
fn try_fold_const(&mut self, c: I::Const) -> Result<I::Const, Self::Error>
203-
where
204-
I::Const: TypeSuperFoldable<I>,
205-
{
188+
fn try_fold_const(&mut self, c: I::Const) -> Result<I::Const, Self::Error> {
206189
c.try_super_fold_with(self)
207190
}
208191

209-
fn try_fold_predicate(&mut self, p: I::Predicate) -> Result<I::Predicate, Self::Error>
210-
where
211-
I::Predicate: TypeSuperFoldable<I>,
212-
{
192+
fn try_fold_predicate(&mut self, p: I::Predicate) -> Result<I::Predicate, Self::Error> {
213193
p.try_super_fold_with(self)
214194
}
215195
}
@@ -234,28 +214,19 @@ where
234214
Ok(self.fold_binder(t))
235215
}
236216

237-
fn try_fold_ty(&mut self, t: I::Ty) -> Result<I::Ty, Never>
238-
where
239-
I::Ty: TypeSuperFoldable<I>,
240-
{
217+
fn try_fold_ty(&mut self, t: I::Ty) -> Result<I::Ty, Never> {
241218
Ok(self.fold_ty(t))
242219
}
243220

244221
fn try_fold_region(&mut self, r: I::Region) -> Result<I::Region, Never> {
245222
Ok(self.fold_region(r))
246223
}
247224

248-
fn try_fold_const(&mut self, c: I::Const) -> Result<I::Const, Never>
249-
where
250-
I::Const: TypeSuperFoldable<I>,
251-
{
225+
fn try_fold_const(&mut self, c: I::Const) -> Result<I::Const, Never> {
252226
Ok(self.fold_const(c))
253227
}
254228

255-
fn try_fold_predicate(&mut self, p: I::Predicate) -> Result<I::Predicate, Never>
256-
where
257-
I::Predicate: TypeSuperFoldable<I>,
258-
{
229+
fn try_fold_predicate(&mut self, p: I::Predicate) -> Result<I::Predicate, Never> {
259230
Ok(self.fold_predicate(p))
260231
}
261232
}

compiler/rustc_type_ir/src/interner.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ use smallvec::SmallVec;
22
use std::fmt::Debug;
33
use std::hash::Hash;
44

5+
use crate::fold::TypeSuperFoldable;
56
use crate::visit::{Flags, TypeSuperVisitable, TypeVisitable};
67
use crate::{
78
new, BoundVar, BoundVars, CanonicalVarInfo, ConstKind, DebugWithInfcx, RegionKind, TyKind,
89
UniverseIndex,
910
};
1011

11-
pub trait Interner: Sized {
12+
pub trait Interner: Sized + Copy {
1213
type DefId: Copy + Debug + Hash + Eq;
1314
type AdtDef: Copy + Debug + Hash + Eq;
1415

@@ -34,6 +35,7 @@ pub trait Interner: Sized {
3435
+ Into<Self::GenericArg>
3536
+ IntoKind<Kind = TyKind<Self>>
3637
+ TypeSuperVisitable<Self>
38+
+ TypeSuperFoldable<Self>
3739
+ Flags
3840
+ new::Ty<Self>;
3941
type Tys: Copy + Debug + Hash + Eq + IntoIterator<Item = Self::Ty>;
@@ -57,6 +59,7 @@ pub trait Interner: Sized {
5759
+ IntoKind<Kind = ConstKind<Self>>
5860
+ ConstTy<Self>
5961
+ TypeSuperVisitable<Self>
62+
+ TypeSuperFoldable<Self>
6063
+ Flags
6164
+ new::Const<Self>;
6265
type AliasConst: Copy + DebugWithInfcx<Self> + Hash + Eq;
@@ -82,7 +85,13 @@ pub trait Interner: Sized {
8285
type PlaceholderRegion: Copy + Debug + Hash + Eq + PlaceholderLike;
8386

8487
// Predicates
85-
type Predicate: Copy + Debug + Hash + Eq + TypeSuperVisitable<Self> + Flags;
88+
type Predicate: Copy
89+
+ Debug
90+
+ Hash
91+
+ Eq
92+
+ TypeSuperVisitable<Self>
93+
+ TypeSuperFoldable<Self>
94+
+ Flags;
8695
type TraitPredicate: Copy + Debug + Hash + Eq;
8796
type RegionOutlivesPredicate: Copy + Debug + Hash + Eq;
8897
type TypeOutlivesPredicate: Copy + Debug + Hash + Eq;

compiler/rustc_type_ir/src/new.rs

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ pub trait Ty<I: Interner<Ty = Self>> {
66

77
pub trait Region<I: Interner<Region = Self>> {
88
fn new_anon_bound(interner: I, debruijn: DebruijnIndex, var: BoundVar) -> Self;
9+
10+
fn new_static(interner: I) -> Self;
911
}
1012

1113
pub trait Const<I: Interner<Const = Self>> {

library/core/src/any.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,18 @@
4040
//!
4141
//! ## Examples
4242
//!
43-
//! Consider a situation where we want to log out a value passed to a function.
44-
//! We know the value we're working on implements Debug, but we don't know its
43+
//! Consider a situation where we want to log a value passed to a function.
44+
//! We know the value we're working on implements `Debug`, but we don't know its
4545
//! concrete type. We want to give special treatment to certain types: in this
46-
//! case printing out the length of String values prior to their value.
46+
//! case printing out the length of `String` values prior to their value.
4747
//! We don't know the concrete type of our value at compile time, so we need to
4848
//! use runtime reflection instead.
4949
//!
5050
//! ```rust
5151
//! use std::fmt::Debug;
5252
//! use std::any::Any;
5353
//!
54-
//! // Logger function for any type that implements Debug.
54+
//! // Logger function for any type that implements `Debug`.
5555
//! fn log<T: Any + Debug>(value: &T) {
5656
//! let value_any = value as &dyn Any;
5757
//!

src/tools/compiletest/src/lib.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,9 @@ pub fn make_tests(
571571
&modified_tests,
572572
&mut poisoned,
573573
)
574-
.unwrap_or_else(|_| panic!("Could not read tests from {}", config.src_base.display()));
574+
.unwrap_or_else(|reason| {
575+
panic!("Could not read tests from {}: {reason}", config.src_base.display())
576+
});
575577

576578
if poisoned {
577579
eprintln!();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// It is UB to unwind out of `fn start()` according to
2+
// https://doc.rust-lang.org/beta/unstable-book/language-features/start.html so
3+
// panic with abort to avoid UB:
4+
//@ compile-flags: -Cpanic=abort
5+
//@ no-prefer-dynamic so panic=abort works
6+
7+
#![feature(start, rustc_private)]
8+
9+
extern crate libc;
10+
11+
// Use #[start] so we don't have a runtime that messes with SIGPIPE.
12+
#[start]
13+
fn start(argc: isize, argv: *const *const u8) -> isize {
14+
assert_eq!(argc, 2, "Must pass SIG_IGN or SIG_DFL as first arg");
15+
let arg1 = unsafe { std::ffi::CStr::from_ptr(*argv.offset(1) as *const libc::c_char) }
16+
.to_str()
17+
.unwrap();
18+
19+
let expected = match arg1 {
20+
"SIG_IGN" => libc::SIG_IGN,
21+
"SIG_DFL" => libc::SIG_DFL,
22+
arg => panic!("Must pass SIG_IGN or SIG_DFL as first arg. Got: {}", arg),
23+
};
24+
25+
let actual = unsafe {
26+
let mut actual: libc::sigaction = std::mem::zeroed();
27+
libc::sigaction(libc::SIGPIPE, std::ptr::null(), &mut actual);
28+
actual.sa_sigaction
29+
};
30+
31+
assert_eq!(actual, expected, "actual and expected SIGPIPE disposition in child differs");
32+
33+
0
34+
}

0 commit comments

Comments
 (0)