Skip to content

Commit 7bb6510

Browse files
committed
Auto merge of #126093 - cuviper:beta-next, r=cuviper
[beta] backports - Fix insufficient logic when searching for the underlying allocation #124761 - Handle field projections like slice indexing in invalid_reference_casting #124908 - Handle Deref expressions in invalid_reference_casting #124978 - Fix ICE in non-operand `aggregate_raw_ptr` instrinsic codegen #125184 - Wrap Context.ext in AssertUnwindSafe #125392 - Revert problematic opaque type change #125489 - ast: Revert a breaking attribute visiting order change #125734 - Update to LLVM 18.1.7 #126061 - Revert "Disallow ambiguous attributes on expressions" on beta #126102 / #126101 - Silence double-symlink errors while building solaris toolchain #126011 r? cuviper
2 parents 81ed1ce + c689624 commit 7bb6510

37 files changed

+508
-248
lines changed

compiler/rustc_ast/src/visit.rs

Lines changed: 1 addition & 1 deletion
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

Lines changed: 5 additions & 1 deletion
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

Lines changed: 2 additions & 15 deletions
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

Lines changed: 10 additions & 0 deletions
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

Lines changed: 0 additions & 2 deletions
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

Lines changed: 0 additions & 9 deletions
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

Lines changed: 13 additions & 19 deletions
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

Lines changed: 7 additions & 4 deletions
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

Lines changed: 1 addition & 1 deletion
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.

0 commit comments

Comments
 (0)