Skip to content

Commit 75f4ee8

Browse files
committed
Auto merge of rust-lang#106025 - matthiaskrgr:rollup-vz5rqah, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - rust-lang#105837 (Don't ICE in `check_must_not_suspend_ty` for mismatched tuple arity) - rust-lang#105932 (Correct branch-protection ModFlagBehavior for Aarch64 on LLVM-15) - rust-lang#105960 (Various cleanups) - rust-lang#105985 (Method chain nitpicks) - rust-lang#105996 (Test that async blocks are `UnwindSafe`) - rust-lang#106012 (Clarify that raw retags are not permitted in Mir) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 8574880 + d0d0ccd commit 75f4ee8

File tree

24 files changed

+181
-99
lines changed

24 files changed

+181
-99
lines changed

compiler/rustc_codegen_llvm/src/context.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -280,29 +280,35 @@ pub unsafe fn create_module<'ll>(
280280
}
281281

282282
if let Some(BranchProtection { bti, pac_ret }) = sess.opts.unstable_opts.branch_protection {
283+
let behavior = if llvm_version >= (15, 0, 0) {
284+
llvm::LLVMModFlagBehavior::Min
285+
} else {
286+
llvm::LLVMModFlagBehavior::Error
287+
};
288+
283289
if sess.target.arch == "aarch64" {
284290
llvm::LLVMRustAddModuleFlag(
285291
llmod,
286-
llvm::LLVMModFlagBehavior::Error,
292+
behavior,
287293
"branch-target-enforcement\0".as_ptr().cast(),
288294
bti.into(),
289295
);
290296
llvm::LLVMRustAddModuleFlag(
291297
llmod,
292-
llvm::LLVMModFlagBehavior::Error,
298+
behavior,
293299
"sign-return-address\0".as_ptr().cast(),
294300
pac_ret.is_some().into(),
295301
);
296302
let pac_opts = pac_ret.unwrap_or(PacRet { leaf: false, key: PAuthKey::A });
297303
llvm::LLVMRustAddModuleFlag(
298304
llmod,
299-
llvm::LLVMModFlagBehavior::Error,
305+
behavior,
300306
"sign-return-address-all\0".as_ptr().cast(),
301307
pac_opts.leaf.into(),
302308
);
303309
llvm::LLVMRustAddModuleFlag(
304310
llmod,
305-
llvm::LLVMModFlagBehavior::Error,
311+
behavior,
306312
"sign-return-address-with-bkey\0".as_ptr().cast(),
307313
u32::from(pac_opts.key == PAuthKey::B),
308314
);

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

+1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ pub enum LLVMModFlagBehavior {
7979
Append = 5,
8080
AppendUnique = 6,
8181
Max = 7,
82+
Min = 8,
8283
}
8384

8485
// Consts for the LLVM CallConv type, pre-cast to usize.

compiler/rustc_const_eval/src/transform/validate.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ use rustc_middle::mir::visit::{PlaceContext, Visitor};
99
use rustc_middle::mir::{
1010
traversal, AggregateKind, BasicBlock, BinOp, Body, BorrowKind, CastKind, CopyNonOverlapping,
1111
Local, Location, MirPass, MirPhase, NonDivergingIntrinsic, Operand, Place, PlaceElem, PlaceRef,
12-
ProjectionElem, RuntimePhase, Rvalue, SourceScope, Statement, StatementKind, Terminator,
13-
TerminatorKind, UnOp, START_BLOCK,
12+
ProjectionElem, RetagKind, RuntimePhase, Rvalue, SourceScope, Statement, StatementKind,
13+
Terminator, TerminatorKind, UnOp, START_BLOCK,
1414
};
1515
use rustc_middle::ty::{self, InstanceDef, ParamEnv, Ty, TyCtxt, TypeVisitable};
1616
use rustc_mir_dataflow::impls::MaybeStorageLive;
@@ -667,10 +667,13 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
667667
self.fail(location, "`Deinit`is not allowed until deaggregation");
668668
}
669669
}
670-
StatementKind::Retag(_, _) => {
670+
StatementKind::Retag(kind, _) => {
671671
// FIXME(JakobDegen) The validator should check that `self.mir_phase <
672672
// DropsLowered`. However, this causes ICEs with generation of drop shims, which
673673
// seem to fail to set their `MirPhase` correctly.
674+
if *kind == RetagKind::Raw || *kind == RetagKind::TwoPhase {
675+
self.fail(location, format!("explicit `{:?}` is forbidden", kind));
676+
}
674677
}
675678
StatementKind::StorageLive(..)
676679
| StatementKind::StorageDead(..)

compiler/rustc_hir_typeck/src/generator_interior/mod.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -607,10 +607,7 @@ fn check_must_not_suspend_ty<'tcx>(
607607
ty::Tuple(fields) => {
608608
let mut has_emitted = false;
609609
let comps = match data.expr.map(|e| &e.kind) {
610-
Some(hir::ExprKind::Tup(comps)) => {
611-
debug_assert_eq!(comps.len(), fields.len());
612-
Some(comps)
613-
}
610+
Some(hir::ExprKind::Tup(comps)) if comps.len() == fields.len() => Some(comps),
614611
_ => None,
615612
};
616613
for (i, ty) in fields.iter().enumerate() {

compiler/rustc_middle/src/hir/map/mod.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ impl<'hir> Map<'hir> {
170170
}
171171

172172
#[inline]
173+
#[track_caller]
173174
pub fn local_def_id(self, hir_id: HirId) -> LocalDefId {
174175
self.opt_local_def_id(hir_id).unwrap_or_else(|| {
175176
bug!(
@@ -310,6 +311,7 @@ impl<'hir> Map<'hir> {
310311
}
311312
}
312313

314+
#[track_caller]
313315
pub fn get_parent_node(self, hir_id: HirId) -> HirId {
314316
self.find_parent_node(hir_id)
315317
.unwrap_or_else(|| bug!("No parent for node {:?}", self.node_to_string(hir_id)))
@@ -334,12 +336,14 @@ impl<'hir> Map<'hir> {
334336
}
335337

336338
/// Retrieves the `Node` corresponding to `id`, panicking if it cannot be found.
339+
#[track_caller]
337340
pub fn get(self, id: HirId) -> Node<'hir> {
338341
self.find(id).unwrap_or_else(|| bug!("couldn't find hir id {} in the HIR map", id))
339342
}
340343

341344
/// Retrieves the `Node` corresponding to `id`, panicking if it cannot be found.
342345
#[inline]
346+
#[track_caller]
343347
pub fn get_by_def_id(self, id: LocalDefId) -> Node<'hir> {
344348
self.find_by_def_id(id).unwrap_or_else(|| bug!("couldn't find {:?} in the HIR map", id))
345349
}
@@ -377,6 +381,7 @@ impl<'hir> Map<'hir> {
377381
self.tcx.hir_owner_nodes(id.hir_id.owner).unwrap().bodies[&id.hir_id.local_id]
378382
}
379383

384+
#[track_caller]
380385
pub fn fn_decl_by_hir_id(self, hir_id: HirId) -> Option<&'hir FnDecl<'hir>> {
381386
if let Some(node) = self.find(hir_id) {
382387
node.fn_decl()
@@ -385,6 +390,7 @@ impl<'hir> Map<'hir> {
385390
}
386391
}
387392

393+
#[track_caller]
388394
pub fn fn_sig_by_hir_id(self, hir_id: HirId) -> Option<&'hir FnSig<'hir>> {
389395
if let Some(node) = self.find(hir_id) {
390396
node.fn_sig()
@@ -393,6 +399,7 @@ impl<'hir> Map<'hir> {
393399
}
394400
}
395401

402+
#[track_caller]
396403
pub fn enclosing_body_owner(self, hir_id: HirId) -> LocalDefId {
397404
for (_, node) in self.parent_iter(hir_id) {
398405
if let Some(body) = associated_body(node) {
@@ -408,7 +415,7 @@ impl<'hir> Map<'hir> {
408415
/// item (possibly associated), a closure, or a `hir::AnonConst`.
409416
pub fn body_owner(self, BodyId { hir_id }: BodyId) -> HirId {
410417
let parent = self.get_parent_node(hir_id);
411-
assert!(self.find(parent).map_or(false, |n| is_body_owner(n, hir_id)));
418+
assert!(self.find(parent).map_or(false, |n| is_body_owner(n, hir_id)), "{hir_id:?}");
412419
parent
413420
}
414421

@@ -419,10 +426,11 @@ impl<'hir> Map<'hir> {
419426
/// Given a `LocalDefId`, returns the `BodyId` associated with it,
420427
/// if the node is a body owner, otherwise returns `None`.
421428
pub fn maybe_body_owned_by(self, id: LocalDefId) -> Option<BodyId> {
422-
self.get_if_local(id.to_def_id()).map(associated_body).flatten()
429+
self.find_by_def_id(id).and_then(associated_body)
423430
}
424431

425432
/// Given a body owner's id, returns the `BodyId` associated with it.
433+
#[track_caller]
426434
pub fn body_owned_by(self, id: LocalDefId) -> BodyId {
427435
self.maybe_body_owned_by(id).unwrap_or_else(|| {
428436
let hir_id = self.local_def_id_to_hir_id(id);

compiler/rustc_middle/src/mir/syntax.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -320,8 +320,10 @@ pub enum StatementKind<'tcx> {
320320
/// <https://internals.rust-lang.org/t/stacked-borrows-an-aliasing-model-for-rust/8153/> for
321321
/// more details.
322322
///
323-
/// For code that is not specific to stacked borrows, you should consider retags to read
324-
/// and modify the place in an opaque way.
323+
/// For code that is not specific to stacked borrows, you should consider retags to read and
324+
/// modify the place in an opaque way.
325+
///
326+
/// Only `RetagKind::Default` and `RetagKind::FnEntry` are permitted.
325327
Retag(RetagKind, Box<Place<'tcx>>),
326328

327329
/// Encodes a user's type ascription. These need to be preserved

compiler/rustc_middle/src/ty/generics.rs

-8
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,6 @@ impl GenericParamDef {
7070
}
7171
}
7272

73-
pub fn has_default(&self) -> bool {
74-
match self.kind {
75-
GenericParamDefKind::Type { has_default, .. }
76-
| GenericParamDefKind::Const { has_default } => has_default,
77-
GenericParamDefKind::Lifetime => false,
78-
}
79-
}
80-
8173
pub fn is_anonymous_lifetime(&self) -> bool {
8274
match self.kind {
8375
GenericParamDefKind::Lifetime => {

compiler/rustc_middle/src/ty/subst.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ impl<'tcx> InternalSubsts<'tcx> {
348348
substs.reserve(defs.params.len());
349349
for param in &defs.params {
350350
let kind = mk_kind(param, substs);
351-
assert_eq!(param.index as usize, substs.len());
351+
assert_eq!(param.index as usize, substs.len(), "{substs:#?}, {defs:#?}");
352352
substs.push(kind);
353353
}
354354
}

compiler/rustc_middle/src/ty/visit.rs

+4-14
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,11 @@ pub trait TypeVisitable<'tcx>: fmt::Debug + Clone {
8888
self.has_vars_bound_at_or_above(ty::INNERMOST)
8989
}
9090

91-
#[instrument(level = "trace", ret)]
9291
fn has_type_flags(&self, flags: TypeFlags) -> bool {
93-
self.visit_with(&mut HasTypeFlagsVisitor { flags }).break_value() == Some(FoundFlags)
92+
let res =
93+
self.visit_with(&mut HasTypeFlagsVisitor { flags }).break_value() == Some(FoundFlags);
94+
trace!(?self, ?flags, ?res, "has_type_flags");
95+
res
9496
}
9597
fn has_projections(&self) -> bool {
9698
self.has_type_flags(TypeFlags::HAS_PROJECTION)
@@ -560,10 +562,8 @@ impl<'tcx> TypeVisitor<'tcx> for HasTypeFlagsVisitor {
560562
type BreakTy = FoundFlags;
561563

562564
#[inline]
563-
#[instrument(skip(self), level = "trace", ret)]
564565
fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
565566
let flags = t.flags();
566-
trace!(t.flags=?t.flags());
567567
if flags.intersects(self.flags) {
568568
ControlFlow::Break(FoundFlags)
569569
} else {
@@ -572,10 +572,8 @@ impl<'tcx> TypeVisitor<'tcx> for HasTypeFlagsVisitor {
572572
}
573573

574574
#[inline]
575-
#[instrument(skip(self), level = "trace", ret)]
576575
fn visit_region(&mut self, r: ty::Region<'tcx>) -> ControlFlow<Self::BreakTy> {
577576
let flags = r.type_flags();
578-
trace!(r.flags=?flags);
579577
if flags.intersects(self.flags) {
580578
ControlFlow::Break(FoundFlags)
581579
} else {
@@ -584,7 +582,6 @@ impl<'tcx> TypeVisitor<'tcx> for HasTypeFlagsVisitor {
584582
}
585583

586584
#[inline]
587-
#[instrument(level = "trace", ret)]
588585
fn visit_const(&mut self, c: ty::Const<'tcx>) -> ControlFlow<Self::BreakTy> {
589586
let flags = FlagComputation::for_const(c);
590587
trace!(r.flags=?flags);
@@ -596,14 +593,7 @@ impl<'tcx> TypeVisitor<'tcx> for HasTypeFlagsVisitor {
596593
}
597594

598595
#[inline]
599-
#[instrument(level = "trace", ret)]
600596
fn visit_predicate(&mut self, predicate: ty::Predicate<'tcx>) -> ControlFlow<Self::BreakTy> {
601-
debug!(
602-
"HasTypeFlagsVisitor: predicate={:?} predicate.flags={:?} self.flags={:?}",
603-
predicate,
604-
predicate.flags(),
605-
self.flags
606-
);
607597
if predicate.flags().intersects(self.flags) {
608598
ControlFlow::Break(FoundFlags)
609599
} else {

compiler/rustc_mir_build/src/build/custom/parse/instruction.rs

-3
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ impl<'tcx, 'body> ParseCtxt<'tcx, 'body> {
1515
@call("mir_retag", args) => {
1616
Ok(StatementKind::Retag(RetagKind::Default, Box::new(self.parse_place(args[0])?)))
1717
},
18-
@call("mir_retag_raw", args) => {
19-
Ok(StatementKind::Retag(RetagKind::Raw, Box::new(self.parse_place(args[0])?)))
20-
},
2118
@call("mir_set_discriminant", args) => {
2219
let place = self.parse_place(args[0])?;
2320
let var = self.parse_integer_literal(args[1])? as u32;

compiler/rustc_trait_selection/src/traits/error_reporting/method_chain.rs

+20-7
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,27 @@ impl<'a, 'tcx> TypeRelation<'tcx> for CollectAllMismatches<'a, 'tcx> {
1414
fn tag(&self) -> &'static str {
1515
"CollectAllMismatches"
1616
}
17+
1718
fn tcx(&self) -> TyCtxt<'tcx> {
1819
self.infcx.tcx
1920
}
21+
2022
fn intercrate(&self) -> bool {
2123
false
2224
}
25+
2326
fn param_env(&self) -> ty::ParamEnv<'tcx> {
2427
self.param_env
2528
}
29+
2630
fn a_is_expected(&self) -> bool {
2731
true
28-
} // irrelevant
32+
}
33+
2934
fn mark_ambiguous(&mut self) {
3035
bug!()
3136
}
37+
3238
fn relate_with_variance<T: Relate<'tcx>>(
3339
&mut self,
3440
_: ty::Variance,
@@ -38,22 +44,28 @@ impl<'a, 'tcx> TypeRelation<'tcx> for CollectAllMismatches<'a, 'tcx> {
3844
) -> RelateResult<'tcx, T> {
3945
self.relate(a, b)
4046
}
47+
4148
fn regions(
4249
&mut self,
4350
a: ty::Region<'tcx>,
4451
_b: ty::Region<'tcx>,
4552
) -> RelateResult<'tcx, ty::Region<'tcx>> {
4653
Ok(a)
4754
}
55+
4856
fn tys(&mut self, a: Ty<'tcx>, b: Ty<'tcx>) -> RelateResult<'tcx, Ty<'tcx>> {
49-
if a == b || matches!(a.kind(), ty::Infer(_)) || matches!(b.kind(), ty::Infer(_)) {
50-
return Ok(a);
51-
}
52-
relate::super_relate_tys(self, a, b).or_else(|e| {
53-
self.errors.push(e);
54-
Ok(a)
57+
self.infcx.probe(|_| {
58+
if a.is_ty_infer() || b.is_ty_infer() {
59+
Ok(a)
60+
} else {
61+
self.infcx.super_combine_tys(self, a, b).or_else(|e| {
62+
self.errors.push(e);
63+
Ok(a)
64+
})
65+
}
5566
})
5667
}
68+
5769
fn consts(
5870
&mut self,
5971
a: ty::Const<'tcx>,
@@ -64,6 +76,7 @@ impl<'a, 'tcx> TypeRelation<'tcx> for CollectAllMismatches<'a, 'tcx> {
6476
}
6577
relate::super_relate_consts(self, a, b) // could do something similar here for constants!
6678
}
79+
6780
fn binders<T: Relate<'tcx>>(
6881
&mut self,
6982
a: ty::Binder<'tcx, T>,

0 commit comments

Comments
 (0)