Skip to content

Commit 49f3109

Browse files
committed
Auto merge of rust-lang#126093 - cuviper:beta-next, r=cuviper
[beta] backports - Fix insufficient logic when searching for the underlying allocation rust-lang#124761 - Handle field projections like slice indexing in invalid_reference_casting rust-lang#124908 - Handle Deref expressions in invalid_reference_casting rust-lang#124978 - Fix ICE in non-operand `aggregate_raw_ptr` instrinsic codegen rust-lang#125184 - Wrap Context.ext in AssertUnwindSafe rust-lang#125392 - Revert problematic opaque type change rust-lang#125489 - ast: Revert a breaking attribute visiting order change rust-lang#125734 - Update to LLVM 18.1.7 rust-lang#126061 r? cuviper
2 parents 81ed1ce + ac45caa commit 49f3109

21 files changed

+458
-106
lines changed

compiler/rustc_ast/src/visit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -826,10 +826,10 @@ pub fn walk_assoc_item<'a, V: Visitor<'a>>(
826826
ctxt: AssocCtxt,
827827
) -> V::Result {
828828
let &Item { id: _, span: _, ident, ref vis, ref attrs, ref kind, tokens: _ } = item;
829-
walk_list!(visitor, visit_attribute, attrs);
830829
try_visit!(visitor.visit_vis(vis));
831830
try_visit!(visitor.visit_ident(ident));
832831
try_visit!(kind.walk(item, ctxt, visitor));
832+
walk_list!(visitor, visit_attribute, attrs);
833833
V::Result::output()
834834
}
835835

compiler/rustc_codegen_ssa/src/mir/rvalue.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,11 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
120120
bx.write_operand_repeatedly(cg_elem, count, dest);
121121
}
122122

123-
mir::Rvalue::Aggregate(ref kind, ref operands) => {
123+
// This implementation does field projection, so never use it for `RawPtr`,
124+
// which will always be fine with the `codegen_rvalue_operand` path below.
125+
mir::Rvalue::Aggregate(ref kind, ref operands)
126+
if !matches!(**kind, mir::AggregateKind::RawPtr(..)) =>
127+
{
124128
let (variant_index, variant_dest, active_field_index) = match **kind {
125129
mir::AggregateKind::Adt(_, variant_index, _, _, active_field_index) => {
126130
let variant_dest = dest.project_downcast(bx, variant_index);

compiler/rustc_infer/src/infer/mod.rs

+2-15
Original file line numberDiff line numberDiff line change
@@ -945,27 +945,14 @@ impl<'tcx> InferCtxt<'tcx> {
945945
(&ty::Infer(ty::TyVar(a_vid)), &ty::Infer(ty::TyVar(b_vid))) => {
946946
return Err((a_vid, b_vid));
947947
}
948-
// We don't silently want to constrain hidden types here, so we assert that either one side is
949-
// an infer var, so it'll get constrained to whatever the other side is, or there are no opaque
950-
// types involved.
951-
// We don't expect this to actually get hit, but if it does, we now at least know how to write
952-
// a test for it.
953-
(_, ty::Infer(ty::TyVar(_))) => {}
954-
(ty::Infer(ty::TyVar(_)), _) => {}
955-
_ if r_a != r_b && (r_a, r_b).has_opaque_types() => {
956-
span_bug!(
957-
cause.span(),
958-
"opaque types got hidden types registered from within subtype predicate: {r_a:?} vs {r_b:?}"
959-
)
960-
}
961948
_ => {}
962949
}
963950

964951
self.enter_forall(predicate, |ty::SubtypePredicate { a_is_expected, a, b }| {
965952
if a_is_expected {
966-
Ok(self.at(cause, param_env).sub(DefineOpaqueTypes::Yes, a, b))
953+
Ok(self.at(cause, param_env).sub(DefineOpaqueTypes::No, a, b))
967954
} else {
968-
Ok(self.at(cause, param_env).sup(DefineOpaqueTypes::Yes, b, a))
955+
Ok(self.at(cause, param_env).sup(DefineOpaqueTypes::No, b, a))
969956
}
970957
})
971958
}

compiler/rustc_lint/src/reference_casting.rs

+10
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,16 @@ fn is_cast_to_bigger_memory_layout<'tcx>(
198198
let e_alloc = cx.expr_or_init(e);
199199
let e_alloc =
200200
if let ExprKind::AddrOf(_, _, inner_expr) = e_alloc.kind { inner_expr } else { e_alloc };
201+
202+
// if the current expr looks like this `&mut expr[index]` then just looking
203+
// at `expr[index]` won't give us the underlying allocation, so we just skip it
204+
// the same logic applies field access `&mut expr.field` and reborrows `&mut *expr`.
205+
if let ExprKind::Index(..) | ExprKind::Field(..) | ExprKind::Unary(UnOp::Deref, ..) =
206+
e_alloc.kind
207+
{
208+
return None;
209+
}
210+
201211
let alloc_ty = cx.typeck_results().node_type(e_alloc.hir_id);
202212

203213
// if we do not find it we bail out, as this may not be UB

library/core/src/task/wake.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use crate::mem::transmute;
55
use crate::any::Any;
66
use crate::fmt;
77
use crate::marker::PhantomData;
8+
use crate::panic::AssertUnwindSafe;
89
use crate::ptr;
910

1011
/// A `RawWaker` allows the implementor of a task executor to create a [`Waker`]
@@ -236,7 +237,7 @@ enum ExtData<'a> {
236237
pub struct Context<'a> {
237238
waker: &'a Waker,
238239
local_waker: &'a LocalWaker,
239-
ext: ExtData<'a>,
240+
ext: AssertUnwindSafe<ExtData<'a>>,
240241
// Ensure we future-proof against variance changes by forcing
241242
// the lifetime to be invariant (argument-position lifetimes
242243
// are contravariant while return-position lifetimes are
@@ -279,7 +280,9 @@ impl<'a> Context<'a> {
279280
#[unstable(feature = "context_ext", issue = "123392")]
280281
#[rustc_const_unstable(feature = "const_waker", issue = "102012")]
281282
pub const fn ext(&mut self) -> &mut dyn Any {
282-
match &mut self.ext {
283+
// FIXME: this field makes Context extra-weird about unwind safety
284+
// can we justify AssertUnwindSafe if we stabilize this? do we care?
285+
match &mut *self.ext {
283286
ExtData::Some(data) => *data,
284287
ExtData::None(unit) => unit,
285288
}
@@ -353,7 +356,7 @@ impl<'a> ContextBuilder<'a> {
353356
#[rustc_const_unstable(feature = "const_waker", issue = "102012")]
354357
#[unstable(feature = "context_ext", issue = "123392")]
355358
pub const fn from(cx: &'a mut Context<'_>) -> Self {
356-
let ext = match &mut cx.ext {
359+
let ext = match &mut *cx.ext {
357360
ExtData::Some(ext) => ExtData::Some(*ext),
358361
ExtData::None(()) => ExtData::None(()),
359362
};
@@ -396,7 +399,7 @@ impl<'a> ContextBuilder<'a> {
396399
#[rustc_const_unstable(feature = "const_waker", issue = "102012")]
397400
pub const fn build(self) -> Context<'a> {
398401
let ContextBuilder { waker, local_waker, ext, _marker, _marker2 } = self;
399-
Context { waker, local_waker, ext, _marker, _marker2 }
402+
Context { waker, local_waker, ext: AssertUnwindSafe(ext), _marker, _marker2 }
400403
}
401404
}
402405

Original file line numberDiff line numberDiff line change
@@ -1,53 +1,53 @@
11
error: using tabs in doc comments is not recommended
2-
--> tests/ui/tabs_in_doc_comments.rs:6:5
2+
--> tests/ui/tabs_in_doc_comments.rs:10:9
33
|
4-
LL | /// - first one
5-
| ^^^^ help: consider using four spaces per tab
4+
LL | /// - First String:
5+
| ^^^^ help: consider using four spaces per tab
66
|
77
= note: `-D clippy::tabs-in-doc-comments` implied by `-D warnings`
88
= help: to override `-D warnings` add `#[allow(clippy::tabs_in_doc_comments)]`
99

1010
error: using tabs in doc comments is not recommended
11-
--> tests/ui/tabs_in_doc_comments.rs:6:13
11+
--> tests/ui/tabs_in_doc_comments.rs:11:9
1212
|
13-
LL | /// - first one
14-
| ^^^^^^^^ help: consider using four spaces per tab
13+
LL | /// - needs to be inside here
14+
| ^^^^^^^^ help: consider using four spaces per tab
1515

1616
error: using tabs in doc comments is not recommended
17-
--> tests/ui/tabs_in_doc_comments.rs:7:5
17+
--> tests/ui/tabs_in_doc_comments.rs:14:9
1818
|
19-
LL | /// - second one
20-
| ^^^^ help: consider using four spaces per tab
19+
LL | /// - Second String:
20+
| ^^^^ help: consider using four spaces per tab
2121

2222
error: using tabs in doc comments is not recommended
23-
--> tests/ui/tabs_in_doc_comments.rs:7:14
23+
--> tests/ui/tabs_in_doc_comments.rs:15:9
2424
|
25-
LL | /// - second one
26-
| ^^^^ help: consider using four spaces per tab
25+
LL | /// - needs to be inside here
26+
| ^^^^^^^^ help: consider using four spaces per tab
2727

2828
error: using tabs in doc comments is not recommended
29-
--> tests/ui/tabs_in_doc_comments.rs:10:9
29+
--> tests/ui/tabs_in_doc_comments.rs:6:5
3030
|
31-
LL | /// - First String:
32-
| ^^^^ help: consider using four spaces per tab
31+
LL | /// - first one
32+
| ^^^^ help: consider using four spaces per tab
3333

3434
error: using tabs in doc comments is not recommended
35-
--> tests/ui/tabs_in_doc_comments.rs:11:9
35+
--> tests/ui/tabs_in_doc_comments.rs:6:13
3636
|
37-
LL | /// - needs to be inside here
38-
| ^^^^^^^^ help: consider using four spaces per tab
37+
LL | /// - first one
38+
| ^^^^^^^^ help: consider using four spaces per tab
3939

4040
error: using tabs in doc comments is not recommended
41-
--> tests/ui/tabs_in_doc_comments.rs:14:9
41+
--> tests/ui/tabs_in_doc_comments.rs:7:5
4242
|
43-
LL | /// - Second String:
44-
| ^^^^ help: consider using four spaces per tab
43+
LL | /// - second one
44+
| ^^^^ help: consider using four spaces per tab
4545

4646
error: using tabs in doc comments is not recommended
47-
--> tests/ui/tabs_in_doc_comments.rs:15:9
47+
--> tests/ui/tabs_in_doc_comments.rs:7:14
4848
|
49-
LL | /// - needs to be inside here
50-
| ^^^^^^^^ help: consider using four spaces per tab
49+
LL | /// - second one
50+
| ^^^^ help: consider using four spaces per tab
5151

5252
error: aborting due to 8 previous errors
5353

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//@ compile-flags: -O -C no-prepopulate-passes -Z mir-enable-passes=-InstSimplify
2+
//@ only-64bit (so I don't need to worry about usize)
3+
4+
#![crate_type = "lib"]
5+
#![feature(core_intrinsics)]
6+
7+
use std::intrinsics::aggregate_raw_ptr;
8+
9+
// InstSimplify replaces these with casts if it can, which means they're almost
10+
// never seen in codegen, but PR#121571 found a way, so add a test for it.
11+
12+
#[inline(never)]
13+
pub fn opaque(_p: &*const i32) {}
14+
15+
// CHECK-LABEL: @thin_ptr_via_aggregate(
16+
#[no_mangle]
17+
pub unsafe fn thin_ptr_via_aggregate(p: *const ()) {
18+
// CHECK: %mem = alloca
19+
// CHECK: store ptr %p, ptr %mem
20+
// CHECK: call {{.+}}aggregate_thin_pointer{{.+}} %mem)
21+
let mem = aggregate_raw_ptr(p, ());
22+
opaque(&mem);
23+
}

tests/ui/async-await/async-is-unwindsafe.rs

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ fn main() {
1111

1212
is_unwindsafe(async {
1313
//~^ ERROR the type `&mut Context<'_>` may not be safely transferred across an unwind boundary
14-
//~| ERROR the type `&mut (dyn Any + 'static)` may not be safely transferred across an unwind boundary
1514
use std::ptr::null;
1615
use std::task::{Context, RawWaker, RawWakerVTable, Waker};
1716
let waker = unsafe {

tests/ui/async-await/async-is-unwindsafe.stderr

+6-37
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,19 @@ LL | is_unwindsafe(async {
66
| |_____|
77
| ||
88
LL | ||
9-
LL | ||
109
LL | || use std::ptr::null;
10+
LL | || use std::task::{Context, RawWaker, RawWakerVTable, Waker};
1111
... ||
1212
LL | || drop(cx_ref);
1313
LL | || });
1414
| ||_____-^ `&mut Context<'_>` may not be safely transferred across an unwind boundary
1515
| |_____|
16-
| within this `{async block@$DIR/async-is-unwindsafe.rs:12:19: 30:6}`
16+
| within this `{async block@$DIR/async-is-unwindsafe.rs:12:19: 29:6}`
1717
|
18-
= help: within `{async block@$DIR/async-is-unwindsafe.rs:12:19: 30:6}`, the trait `UnwindSafe` is not implemented for `&mut Context<'_>`, which is required by `{async block@$DIR/async-is-unwindsafe.rs:12:19: 30:6}: UnwindSafe`
18+
= help: within `{async block@$DIR/async-is-unwindsafe.rs:12:19: 29:6}`, the trait `UnwindSafe` is not implemented for `&mut Context<'_>`, which is required by `{async block@$DIR/async-is-unwindsafe.rs:12:19: 29:6}: UnwindSafe`
19+
= note: `UnwindSafe` is implemented for `&Context<'_>`, but not for `&mut Context<'_>`
1920
note: future does not implement `UnwindSafe` as this value is used across an await
20-
--> $DIR/async-is-unwindsafe.rs:26:18
21+
--> $DIR/async-is-unwindsafe.rs:25:18
2122
|
2223
LL | let cx_ref = &mut cx;
2324
| ------ has type `&mut Context<'_>` which does not implement `UnwindSafe`
@@ -30,38 +31,6 @@ note: required by a bound in `is_unwindsafe`
3031
LL | fn is_unwindsafe(_: impl std::panic::UnwindSafe) {}
3132
| ^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `is_unwindsafe`
3233

33-
error[E0277]: the type `&mut (dyn Any + 'static)` may not be safely transferred across an unwind boundary
34-
--> $DIR/async-is-unwindsafe.rs:12:5
35-
|
36-
LL | is_unwindsafe(async {
37-
| _____^_____________-
38-
| |_____|
39-
| ||
40-
LL | ||
41-
LL | ||
42-
LL | || use std::ptr::null;
43-
... ||
44-
LL | || drop(cx_ref);
45-
LL | || });
46-
| ||_____-^ `&mut (dyn Any + 'static)` may not be safely transferred across an unwind boundary
47-
| |_____|
48-
| within this `{async block@$DIR/async-is-unwindsafe.rs:12:19: 30:6}`
49-
|
50-
= help: within `{async block@$DIR/async-is-unwindsafe.rs:12:19: 30:6}`, the trait `UnwindSafe` is not implemented for `&mut (dyn Any + 'static)`, which is required by `{async block@$DIR/async-is-unwindsafe.rs:12:19: 30:6}: UnwindSafe`
51-
note: future does not implement `UnwindSafe` as this value is used across an await
52-
--> $DIR/async-is-unwindsafe.rs:26:18
53-
|
54-
LL | let mut cx = Context::from_waker(&waker);
55-
| ------ has type `Context<'_>` which does not implement `UnwindSafe`
56-
...
57-
LL | async {}.await; // this needs an inner await point
58-
| ^^^^^ await occurs here, with `mut cx` maybe used later
59-
note: required by a bound in `is_unwindsafe`
60-
--> $DIR/async-is-unwindsafe.rs:3:26
61-
|
62-
LL | fn is_unwindsafe(_: impl std::panic::UnwindSafe) {}
63-
| ^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `is_unwindsafe`
64-
65-
error: aborting due to 2 previous errors
34+
error: aborting due to 1 previous error
6635

6736
For more information about this error, try `rustc --explain E0277`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//@ run-pass
2+
// Tests against a regression surfaced by crater in https://github.com/rust-lang/rust/issues/125193
3+
// Unwind Safety is not a very coherent concept, but we'd prefer no regressions until we kibosh it
4+
// and this is an unstable feature anyways sooo...
5+
6+
use std::panic::UnwindSafe;
7+
use std::task::Context;
8+
9+
fn unwind_safe<T: UnwindSafe>() {}
10+
11+
fn main() {
12+
unwind_safe::<Context<'_>>(); // test UnwindSafe
13+
unwind_safe::<&Context<'_>>(); // test RefUnwindSafe
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#![doc = in_root!()] // FIXME, this is a bug
2+
#![doc = in_mod!()] //~ ERROR cannot find macro `in_mod` in this scope
3+
#![doc = in_mod_escape!()] // FIXME, this is a bug
4+
#![doc = in_block!()] //~ ERROR cannot find macro `in_block` in this scope
5+
6+
#[doc = in_root!()] //~ ERROR cannot find macro `in_root` in this scope
7+
#[doc = in_mod!()] //~ ERROR cannot find macro `in_mod` in this scope
8+
#[doc = in_mod_escape!()] //~ ERROR cannot find macro `in_mod_escape` in this scope
9+
#[doc = in_block!()] //~ ERROR cannot find macro `in_block` in this scope
10+
fn before() {
11+
#![doc = in_root!()] //~ ERROR cannot find macro `in_root` in this scope
12+
#![doc = in_mod!()] //~ ERROR cannot find macro `in_mod` in this scope
13+
#![doc = in_mod_escape!()] //~ ERROR cannot find macro `in_mod_escape` in this scope
14+
#![doc = in_block!()] //~ ERROR cannot find macro `in_block` in this scope
15+
}
16+
17+
macro_rules! in_root { () => { "" } }
18+
19+
mod macros_stay {
20+
#![doc = in_mod!()] // FIXME, this is a bug
21+
22+
macro_rules! in_mod { () => { "" } }
23+
24+
#[doc = in_mod!()] // OK
25+
fn f() {
26+
#![doc = in_mod!()] // OK
27+
}
28+
}
29+
30+
#[macro_use]
31+
mod macros_escape {
32+
#![doc = in_mod_escape!()] // FIXME, this is a bug
33+
34+
macro_rules! in_mod_escape { () => { "" } }
35+
36+
#[doc = in_mod_escape!()] // OK
37+
fn f() {
38+
#![doc = in_mod_escape!()] // OK
39+
}
40+
}
41+
42+
fn block() {
43+
#![doc = in_block!()] //~ ERROR cannot find macro `in_block` in this scope
44+
45+
macro_rules! in_block { () => { "" } }
46+
47+
#[doc = in_block!()] // OK
48+
fn f() {
49+
#![doc = in_block!()] // OK
50+
}
51+
}
52+
53+
#[doc = in_root!()] // OK
54+
#[doc = in_mod!()] //~ ERROR cannot find macro `in_mod` in this scope
55+
#[doc = in_mod_escape!()] // OK
56+
#[doc = in_block!()] //~ ERROR cannot find macro `in_block` in this scope
57+
fn after() {
58+
#![doc = in_root!()] // OK
59+
#![doc = in_mod!()] //~ ERROR cannot find macro `in_mod` in this scope
60+
#![doc = in_mod_escape!()] // OK
61+
#![doc = in_block!()] //~ ERROR cannot find macro `in_block` in this scope
62+
}
63+
64+
fn main() {}

0 commit comments

Comments
 (0)