Skip to content

Commit

Permalink
Auto merge of rust-lang#126093 - cuviper:beta-next, r=cuviper
Browse files Browse the repository at this point in the history
[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
  • Loading branch information
bors committed Jun 7, 2024
2 parents 81ed1ce + c689624 commit 7bb6510
Show file tree
Hide file tree
Showing 37 changed files with 508 additions and 248 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_ast/src/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -826,10 +826,10 @@ pub fn walk_assoc_item<'a, V: Visitor<'a>>(
ctxt: AssocCtxt,
) -> V::Result {
let &Item { id: _, span: _, ident, ref vis, ref attrs, ref kind, tokens: _ } = item;
walk_list!(visitor, visit_attribute, attrs);
try_visit!(visitor.visit_vis(vis));
try_visit!(visitor.visit_ident(ident));
try_visit!(kind.walk(item, ctxt, visitor));
walk_list!(visitor, visit_attribute, attrs);
V::Result::output()
}

Expand Down
6 changes: 5 additions & 1 deletion compiler/rustc_codegen_ssa/src/mir/rvalue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,11 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
bx.write_operand_repeatedly(cg_elem, count, dest);
}

mir::Rvalue::Aggregate(ref kind, ref operands) => {
// This implementation does field projection, so never use it for `RawPtr`,
// which will always be fine with the `codegen_rvalue_operand` path below.
mir::Rvalue::Aggregate(ref kind, ref operands)
if !matches!(**kind, mir::AggregateKind::RawPtr(..)) =>
{
let (variant_index, variant_dest, active_field_index) = match **kind {
mir::AggregateKind::Adt(_, variant_index, _, _, active_field_index) => {
let variant_dest = dest.project_downcast(bx, variant_index);
Expand Down
17 changes: 2 additions & 15 deletions compiler/rustc_infer/src/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -945,27 +945,14 @@ impl<'tcx> InferCtxt<'tcx> {
(&ty::Infer(ty::TyVar(a_vid)), &ty::Infer(ty::TyVar(b_vid))) => {
return Err((a_vid, b_vid));
}
// We don't silently want to constrain hidden types here, so we assert that either one side is
// an infer var, so it'll get constrained to whatever the other side is, or there are no opaque
// types involved.
// We don't expect this to actually get hit, but if it does, we now at least know how to write
// a test for it.
(_, ty::Infer(ty::TyVar(_))) => {}
(ty::Infer(ty::TyVar(_)), _) => {}
_ if r_a != r_b && (r_a, r_b).has_opaque_types() => {
span_bug!(
cause.span(),
"opaque types got hidden types registered from within subtype predicate: {r_a:?} vs {r_b:?}"
)
}
_ => {}
}

self.enter_forall(predicate, |ty::SubtypePredicate { a_is_expected, a, b }| {
if a_is_expected {
Ok(self.at(cause, param_env).sub(DefineOpaqueTypes::Yes, a, b))
Ok(self.at(cause, param_env).sub(DefineOpaqueTypes::No, a, b))
} else {
Ok(self.at(cause, param_env).sup(DefineOpaqueTypes::Yes, b, a))
Ok(self.at(cause, param_env).sup(DefineOpaqueTypes::No, b, a))
}
})
}
Expand Down
10 changes: 10 additions & 0 deletions compiler/rustc_lint/src/reference_casting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,16 @@ fn is_cast_to_bigger_memory_layout<'tcx>(
let e_alloc = cx.expr_or_init(e);
let e_alloc =
if let ExprKind::AddrOf(_, _, inner_expr) = e_alloc.kind { inner_expr } else { e_alloc };

// if the current expr looks like this `&mut expr[index]` then just looking
// at `expr[index]` won't give us the underlying allocation, so we just skip it
// the same logic applies field access `&mut expr.field` and reborrows `&mut *expr`.
if let ExprKind::Index(..) | ExprKind::Field(..) | ExprKind::Unary(UnOp::Deref, ..) =
e_alloc.kind
{
return None;
}

let alloc_ty = cx.typeck_results().node_type(e_alloc.hir_id);

// if we do not find it we bail out, as this may not be UB
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_parse/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -624,8 +624,6 @@ parse_or_pattern_not_allowed_in_let_binding = top-level or-patterns are not allo
parse_out_of_range_hex_escape = out of range hex escape
.label = must be a character in the range [\x00-\x7f]
parse_outer_attr_ambiguous = ambiguous outer attributes
parse_outer_attr_explanation = outer attributes, like `#[test]`, annotate the item following them
parse_outer_attribute_not_allowed_on_if_else = outer attributes are not allowed on `if` and `else` branches
Expand Down
9 changes: 0 additions & 9 deletions compiler/rustc_parse/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -495,15 +495,6 @@ pub(crate) struct OuterAttributeNotAllowedOnIfElse {
pub attributes: Span,
}

#[derive(Diagnostic)]
#[diag(parse_outer_attr_ambiguous)]
pub(crate) struct AmbiguousOuterAttributes {
#[primary_span]
pub span: Span,
#[subdiagnostic]
pub sugg: WrapInParentheses,
}

#[derive(Diagnostic)]
#[diag(parse_missing_in_in_for_loop)]
pub(crate) struct MissingInInForLoop {
Expand Down
32 changes: 13 additions & 19 deletions compiler/rustc_parse/src/parser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,9 +327,7 @@ impl<'a> Parser<'a> {
this.parse_expr_assoc_with(prec + prec_adjustment, LhsExpr::NotYetParsed)
})?;

self.error_ambiguous_outer_attrs(&lhs, lhs_span, rhs.span);
let span = lhs_span.to(rhs.span);

let span = self.mk_expr_sp(&lhs, lhs_span, rhs.span);
lhs = match op {
AssocOp::Add
| AssocOp::Subtract
Expand Down Expand Up @@ -428,18 +426,6 @@ impl<'a> Parser<'a> {
});
}

fn error_ambiguous_outer_attrs(&self, lhs: &P<Expr>, lhs_span: Span, rhs_span: Span) {
if let Some(attr) = lhs.attrs.iter().find(|a| a.style == AttrStyle::Outer) {
self.dcx().emit_err(errors::AmbiguousOuterAttributes {
span: attr.span.to(rhs_span),
sugg: errors::WrapInParentheses::Expression {
left: attr.span.shrink_to_lo(),
right: lhs_span.shrink_to_hi(),
},
});
}
}

/// Possibly translate the current token to an associative operator.
/// The method does not advance the current token.
///
Expand Down Expand Up @@ -520,8 +506,7 @@ impl<'a> Parser<'a> {
None
};
let rhs_span = rhs.as_ref().map_or(cur_op_span, |x| x.span);
self.error_ambiguous_outer_attrs(&lhs, lhs.span, rhs_span);
let span = lhs.span.to(rhs_span);
let span = self.mk_expr_sp(&lhs, lhs.span, rhs_span);
let limits =
if op == AssocOp::DotDot { RangeLimits::HalfOpen } else { RangeLimits::Closed };
let range = self.mk_range(Some(lhs), rhs, limits);
Expand Down Expand Up @@ -737,8 +722,7 @@ impl<'a> Parser<'a> {
expr_kind: fn(P<Expr>, P<Ty>) -> ExprKind,
) -> PResult<'a, P<Expr>> {
let mk_expr = |this: &mut Self, lhs: P<Expr>, rhs: P<Ty>| {
this.error_ambiguous_outer_attrs(&lhs, lhs_span, rhs.span);
this.mk_expr(lhs_span.to(rhs.span), expr_kind(lhs, rhs))
this.mk_expr(this.mk_expr_sp(&lhs, lhs_span, rhs.span), expr_kind(lhs, rhs))
};

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

/// Create expression span ensuring the span of the parent node
/// is larger than the span of lhs and rhs, including the attributes.
fn mk_expr_sp(&self, lhs: &P<Expr>, lhs_span: Span, rhs_span: Span) -> Span {
lhs.attrs
.iter()
.find(|a| a.style == AttrStyle::Outer)
.map_or(lhs_span, |a| a.span)
.to(rhs_span)
}

fn collect_tokens_for_expr(
&mut self,
attrs: AttrWrapper,
Expand Down
11 changes: 7 additions & 4 deletions library/core/src/task/wake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::mem::transmute;
use crate::any::Any;
use crate::fmt;
use crate::marker::PhantomData;
use crate::panic::AssertUnwindSafe;
use crate::ptr;

/// A `RawWaker` allows the implementor of a task executor to create a [`Waker`]
Expand Down Expand Up @@ -236,7 +237,7 @@ enum ExtData<'a> {
pub struct Context<'a> {
waker: &'a Waker,
local_waker: &'a LocalWaker,
ext: ExtData<'a>,
ext: AssertUnwindSafe<ExtData<'a>>,
// Ensure we future-proof against variance changes by forcing
// the lifetime to be invariant (argument-position lifetimes
// are contravariant while return-position lifetimes are
Expand Down Expand Up @@ -279,7 +280,9 @@ impl<'a> Context<'a> {
#[unstable(feature = "context_ext", issue = "123392")]
#[rustc_const_unstable(feature = "const_waker", issue = "102012")]
pub const fn ext(&mut self) -> &mut dyn Any {
match &mut self.ext {
// FIXME: this field makes Context extra-weird about unwind safety
// can we justify AssertUnwindSafe if we stabilize this? do we care?
match &mut *self.ext {
ExtData::Some(data) => *data,
ExtData::None(unit) => unit,
}
Expand Down Expand Up @@ -353,7 +356,7 @@ impl<'a> ContextBuilder<'a> {
#[rustc_const_unstable(feature = "const_waker", issue = "102012")]
#[unstable(feature = "context_ext", issue = "123392")]
pub const fn from(cx: &'a mut Context<'_>) -> Self {
let ext = match &mut cx.ext {
let ext = match &mut *cx.ext {
ExtData::Some(ext) => ExtData::Some(*ext),
ExtData::None(()) => ExtData::None(()),
};
Expand Down Expand Up @@ -396,7 +399,7 @@ impl<'a> ContextBuilder<'a> {
#[rustc_const_unstable(feature = "const_waker", issue = "102012")]
pub const fn build(self) -> Context<'a> {
let ContextBuilder { waker, local_waker, ext, _marker, _marker2 } = self;
Context { waker, local_waker, ext, _marker, _marker2 }
Context { waker, local_waker, ext: AssertUnwindSafe(ext), _marker, _marker2 }
}
}

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

# Remove Solaris 11 functions that are optionally used by libbacktrace.
Expand Down
6 changes: 3 additions & 3 deletions src/tools/clippy/tests/ui/cfg_attr_rustfmt.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fn foo(

fn skip_on_statements() {
#[rustfmt::skip]
{ 5+3; }
5+3;
}

#[rustfmt::skip]
Expand All @@ -33,11 +33,11 @@ mod foo {
#[clippy::msrv = "1.29"]
fn msrv_1_29() {
#[cfg_attr(rustfmt, rustfmt::skip)]
{ 1+29; }
1+29;
}

#[clippy::msrv = "1.30"]
fn msrv_1_30() {
#[rustfmt::skip]
{ 1+30; }
1+30;
}
6 changes: 3 additions & 3 deletions src/tools/clippy/tests/ui/cfg_attr_rustfmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fn foo(

fn skip_on_statements() {
#[cfg_attr(rustfmt, rustfmt::skip)]
{ 5+3; }
5+3;
}

#[cfg_attr(rustfmt, rustfmt_skip)]
Expand All @@ -33,11 +33,11 @@ mod foo {
#[clippy::msrv = "1.29"]
fn msrv_1_29() {
#[cfg_attr(rustfmt, rustfmt::skip)]
{ 1+29; }
1+29;
}

#[clippy::msrv = "1.30"]
fn msrv_1_30() {
#[cfg_attr(rustfmt, rustfmt::skip)]
{ 1+30; }
1+30;
}
48 changes: 24 additions & 24 deletions src/tools/clippy/tests/ui/tabs_in_doc_comments.stderr
Original file line number Diff line number Diff line change
@@ -1,53 +1,53 @@
error: using tabs in doc comments is not recommended
--> tests/ui/tabs_in_doc_comments.rs:6:5
--> tests/ui/tabs_in_doc_comments.rs:10:9
|
LL | /// - first one
| ^^^^ help: consider using four spaces per tab
LL | /// - First String:
| ^^^^ help: consider using four spaces per tab
|
= note: `-D clippy::tabs-in-doc-comments` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::tabs_in_doc_comments)]`

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

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

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

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

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

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

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

error: aborting due to 8 previous errors

4 changes: 2 additions & 2 deletions src/tools/rustfmt/tests/source/attrib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,8 @@ type Os = NoSource;
// #3313
fn stmt_expr_attributes() {
let foo ;
(#[must_use]
foo) = false ;
#[must_use]
foo = false ;
}

// #3509
Expand Down
4 changes: 2 additions & 2 deletions src/tools/rustfmt/tests/target/attrib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,8 @@ type Os = NoSource;
// #3313
fn stmt_expr_attributes() {
let foo;
(#[must_use]
foo) = false;
#[must_use]
foo = false;
}

// #3509
Expand Down
23 changes: 23 additions & 0 deletions tests/codegen/intrinsics/aggregate-thin-pointer.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//@ compile-flags: -O -C no-prepopulate-passes -Z mir-enable-passes=-InstSimplify
//@ only-64bit (so I don't need to worry about usize)

#![crate_type = "lib"]
#![feature(core_intrinsics)]

use std::intrinsics::aggregate_raw_ptr;

// InstSimplify replaces these with casts if it can, which means they're almost
// never seen in codegen, but PR#121571 found a way, so add a test for it.

#[inline(never)]
pub fn opaque(_p: &*const i32) {}

// CHECK-LABEL: @thin_ptr_via_aggregate(
#[no_mangle]
pub unsafe fn thin_ptr_via_aggregate(p: *const ()) {
// CHECK: %mem = alloca
// CHECK: store ptr %p, ptr %mem
// CHECK: call {{.+}}aggregate_thin_pointer{{.+}} %mem)
let mem = aggregate_raw_ptr(p, ());
opaque(&mem);
}
Loading

0 comments on commit 7bb6510

Please sign in to comment.