Skip to content

Commit 7bb6510

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 - Revert "Disallow ambiguous attributes on expressions" on beta rust-lang#126102 / rust-lang#126101 - Silence double-symlink errors while building solaris toolchain rust-lang#126011 r? cuviper
2 parents 81ed1ce + c689624 commit 7bb6510

37 files changed

+508
-248
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

compiler/rustc_parse/messages.ftl

-2
Original file line numberDiff line numberDiff line change
@@ -624,8 +624,6 @@ parse_or_pattern_not_allowed_in_let_binding = top-level or-patterns are not allo
624624
parse_out_of_range_hex_escape = out of range hex escape
625625
.label = must be a character in the range [\x00-\x7f]
626626
627-
parse_outer_attr_ambiguous = ambiguous outer attributes
628-
629627
parse_outer_attr_explanation = outer attributes, like `#[test]`, annotate the item following them
630628
631629
parse_outer_attribute_not_allowed_on_if_else = outer attributes are not allowed on `if` and `else` branches

compiler/rustc_parse/src/errors.rs

-9
Original file line numberDiff line numberDiff line change
@@ -495,15 +495,6 @@ pub(crate) struct OuterAttributeNotAllowedOnIfElse {
495495
pub attributes: Span,
496496
}
497497

498-
#[derive(Diagnostic)]
499-
#[diag(parse_outer_attr_ambiguous)]
500-
pub(crate) struct AmbiguousOuterAttributes {
501-
#[primary_span]
502-
pub span: Span,
503-
#[subdiagnostic]
504-
pub sugg: WrapInParentheses,
505-
}
506-
507498
#[derive(Diagnostic)]
508499
#[diag(parse_missing_in_in_for_loop)]
509500
pub(crate) struct MissingInInForLoop {

compiler/rustc_parse/src/parser/expr.rs

+13-19
Original file line numberDiff line numberDiff line change
@@ -327,9 +327,7 @@ impl<'a> Parser<'a> {
327327
this.parse_expr_assoc_with(prec + prec_adjustment, LhsExpr::NotYetParsed)
328328
})?;
329329

330-
self.error_ambiguous_outer_attrs(&lhs, lhs_span, rhs.span);
331-
let span = lhs_span.to(rhs.span);
332-
330+
let span = self.mk_expr_sp(&lhs, lhs_span, rhs.span);
333331
lhs = match op {
334332
AssocOp::Add
335333
| AssocOp::Subtract
@@ -428,18 +426,6 @@ impl<'a> Parser<'a> {
428426
});
429427
}
430428

431-
fn error_ambiguous_outer_attrs(&self, lhs: &P<Expr>, lhs_span: Span, rhs_span: Span) {
432-
if let Some(attr) = lhs.attrs.iter().find(|a| a.style == AttrStyle::Outer) {
433-
self.dcx().emit_err(errors::AmbiguousOuterAttributes {
434-
span: attr.span.to(rhs_span),
435-
sugg: errors::WrapInParentheses::Expression {
436-
left: attr.span.shrink_to_lo(),
437-
right: lhs_span.shrink_to_hi(),
438-
},
439-
});
440-
}
441-
}
442-
443429
/// Possibly translate the current token to an associative operator.
444430
/// The method does not advance the current token.
445431
///
@@ -520,8 +506,7 @@ impl<'a> Parser<'a> {
520506
None
521507
};
522508
let rhs_span = rhs.as_ref().map_or(cur_op_span, |x| x.span);
523-
self.error_ambiguous_outer_attrs(&lhs, lhs.span, rhs_span);
524-
let span = lhs.span.to(rhs_span);
509+
let span = self.mk_expr_sp(&lhs, lhs.span, rhs_span);
525510
let limits =
526511
if op == AssocOp::DotDot { RangeLimits::HalfOpen } else { RangeLimits::Closed };
527512
let range = self.mk_range(Some(lhs), rhs, limits);
@@ -737,8 +722,7 @@ impl<'a> Parser<'a> {
737722
expr_kind: fn(P<Expr>, P<Ty>) -> ExprKind,
738723
) -> PResult<'a, P<Expr>> {
739724
let mk_expr = |this: &mut Self, lhs: P<Expr>, rhs: P<Ty>| {
740-
this.error_ambiguous_outer_attrs(&lhs, lhs_span, rhs.span);
741-
this.mk_expr(lhs_span.to(rhs.span), expr_kind(lhs, rhs))
725+
this.mk_expr(this.mk_expr_sp(&lhs, lhs_span, rhs.span), expr_kind(lhs, rhs))
742726
};
743727

744728
// Save the state of the parser before parsing type normally, in case there is a
@@ -3829,6 +3813,16 @@ impl<'a> Parser<'a> {
38293813
self.mk_expr(span, ExprKind::Err(guar))
38303814
}
38313815

3816+
/// Create expression span ensuring the span of the parent node
3817+
/// is larger than the span of lhs and rhs, including the attributes.
3818+
fn mk_expr_sp(&self, lhs: &P<Expr>, lhs_span: Span, rhs_span: Span) -> Span {
3819+
lhs.attrs
3820+
.iter()
3821+
.find(|a| a.style == AttrStyle::Outer)
3822+
.map_or(lhs_span, |a| a.span)
3823+
.to(rhs_span)
3824+
}
3825+
38323826
fn collect_tokens_for_expr(
38333827
&mut self,
38343828
attrs: AttrWrapper,

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

src/ci/docker/host-x86_64/dist-various-2/build-solaris-toolchain.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ apt-get clean
5454
# This makes all those symlinks.
5555
for lib in $(find -name '*.so.*'); do
5656
target=${lib%.so.*}.so
57-
[ -e $target ] || ln -s ${lib##*/} $target
57+
ln -s ${lib##*/} $target || echo "warning: silenced error symlinking $lib"
5858
done
5959

6060
# Remove Solaris 11 functions that are optionally used by libbacktrace.

src/tools/clippy/tests/ui/cfg_attr_rustfmt.fixed

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ fn foo(
1616

1717
fn skip_on_statements() {
1818
#[rustfmt::skip]
19-
{ 5+3; }
19+
5+3;
2020
}
2121

2222
#[rustfmt::skip]
@@ -33,11 +33,11 @@ mod foo {
3333
#[clippy::msrv = "1.29"]
3434
fn msrv_1_29() {
3535
#[cfg_attr(rustfmt, rustfmt::skip)]
36-
{ 1+29; }
36+
1+29;
3737
}
3838

3939
#[clippy::msrv = "1.30"]
4040
fn msrv_1_30() {
4141
#[rustfmt::skip]
42-
{ 1+30; }
42+
1+30;
4343
}

src/tools/clippy/tests/ui/cfg_attr_rustfmt.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ fn foo(
1616

1717
fn skip_on_statements() {
1818
#[cfg_attr(rustfmt, rustfmt::skip)]
19-
{ 5+3; }
19+
5+3;
2020
}
2121

2222
#[cfg_attr(rustfmt, rustfmt_skip)]
@@ -33,11 +33,11 @@ mod foo {
3333
#[clippy::msrv = "1.29"]
3434
fn msrv_1_29() {
3535
#[cfg_attr(rustfmt, rustfmt::skip)]
36-
{ 1+29; }
36+
1+29;
3737
}
3838

3939
#[clippy::msrv = "1.30"]
4040
fn msrv_1_30() {
4141
#[cfg_attr(rustfmt, rustfmt::skip)]
42-
{ 1+30; }
42+
1+30;
4343
}
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

src/tools/rustfmt/tests/source/attrib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,8 @@ type Os = NoSource;
214214
// #3313
215215
fn stmt_expr_attributes() {
216216
let foo ;
217-
(#[must_use]
218-
foo) = false ;
217+
#[must_use]
218+
foo = false ;
219219
}
220220

221221
// #3509

src/tools/rustfmt/tests/target/attrib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,8 @@ type Os = NoSource;
248248
// #3313
249249
fn stmt_expr_attributes() {
250250
let foo;
251-
(#[must_use]
252-
foo) = false;
251+
#[must_use]
252+
foo = false;
253253
}
254254

255255
// #3509
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+
}

0 commit comments

Comments
 (0)