Skip to content

Commit e71c0f1

Browse files
committed
Auto merge of #161289 - JonathanBrouwer:rollup-WQrI9Qf, r=JonathanBrouwer
Rollup of 11 pull requests Successful merges: - #161024 (resolving cyclic glob vis-max) - #161231 (passes: `rustc_scalable_vector` fields are not dead) - #161238 (remove scalar size mismatch interpreter error, make it an ICE instead) - #160345 (Resolver: add `checked` methods for `Cm(Ref)Cell`) - #161129 (Avoid ICE when recovering parenthesized type parameters) - #161235 (Compute job time in post-merge-report from the actual GitHub duration) - #161239 (Fix `#[repr(transparent)]` wrapper types not working with `Complex<T>`) - #161244 (Add regression test for indexing an unsized static without a body) - #161257 (Ignore target feature test when LLVM fails to compile minicore) - #161258 (perf: return early from in_external_macro for root contexts) - #161278 (Add regression test for normalization failure on erased closure in async block)
2 parents 444dcce + b255a7e commit e71c0f1

61 files changed

Lines changed: 605 additions & 268 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

compiler/rustc_abi/src/layout/ty.rs

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ pub trait TyAbiInterface<'a, C>: Sized + std::fmt::Debug + std::fmt::Display {
120120
fn is_tuple(this: TyAndLayout<'a, Self>) -> bool;
121121
fn is_unit(this: TyAndLayout<'a, Self>) -> bool;
122122
fn is_transparent(this: TyAndLayout<'a, Self>) -> bool;
123-
fn is_complex_number(this: TyAndLayout<'a, Self>, cx: &C) -> bool;
123+
fn is_complex_number_lang_item(this: TyAndLayout<'a, Self>, cx: &C) -> bool;
124124
fn is_scalable_vector(this: TyAndLayout<'a, Self>) -> bool;
125125
/// See [`TyAndLayout::pass_indirectly_in_non_rustic_abis`] for details.
126126
fn is_pass_indirectly_in_non_rustic_abis_flag_set(this: TyAndLayout<'a, Self>) -> bool;
@@ -228,11 +228,13 @@ impl<'a, Ty> TyAndLayout<'a, Ty> {
228228
Ty::is_transparent(self)
229229
}
230230

231+
/// Returns `true` if this type needs to match the ABI of the C `_Complex` type. See
232+
/// [`TyAndLayout::complex_number_primitive`] for details.
231233
pub fn is_complex_number<C>(self, cx: &C) -> bool
232234
where
233235
Ty: TyAbiInterface<'a, C> + Copy,
234236
{
235-
Ty::is_complex_number(self.peel_transparent_wrappers(cx), cx)
237+
self.complex_number_primitive(cx).is_some()
236238
}
237239

238240
pub fn is_scalable_vector<C>(self) -> bool
@@ -299,23 +301,47 @@ impl<'a, Ty> TyAndLayout<'a, Ty> {
299301
found
300302
}
301303

302-
pub fn complex_float<C>(&self, cx: &C) -> Option<Float>
304+
/// If this type should match the ABI of the C `_Complex` type, returns the primitive that is
305+
/// used for its parts. This only returns `Some(T)` for `core::num::Complex<T>` where `T` is
306+
/// either a float or an integer. `repr(transparent)` wrapper types are automatically handled.
307+
pub fn complex_number_primitive<C>(&self, cx: &C) -> Option<Primitive>
303308
where
304309
Ty: TyAbiInterface<'a, C> + Copy,
305310
{
306-
if !Ty::is_complex_number(*self, cx) {
311+
let complex = self.peel_transparent_wrappers(cx);
312+
if !Ty::is_complex_number_lang_item(complex, cx) {
307313
return None;
308314
}
309315

310-
let BackendRepr::ScalarPair { a, b, .. } = self.backend_repr else {
311-
return None;
312-
};
313-
314-
debug_assert_eq!(a, b);
316+
let part = complex.field(cx, 0).peel_transparent_wrappers(cx);
317+
318+
if let BackendRepr::Scalar(scalar) = part.backend_repr {
319+
// Only Complex<{ float }> and Complex<{ integer }> have special layout.
320+
let primitive = scalar.primitive();
321+
match primitive {
322+
// Explicitly spell out all the float types so that any new ones have to be added to
323+
// one of the match branches.
324+
Primitive::Int(..)
325+
| Primitive::Float(Float::F16 | Float::F32 | Float::F64 | Float::F128) => {
326+
Some(primitive)
327+
}
328+
Primitive::Pointer(..) => None,
329+
}
330+
} else {
331+
None
332+
}
333+
}
315334

316-
match a.primitive() {
317-
Primitive::Float(f) => Some(f),
318-
_ => None,
335+
/// Returns `Some` if this type has the ABI of the C `_Complex` type with float parts. See
336+
/// [`TyAndLayout::complex_number_primitive`] for details.
337+
pub fn complex_float<C>(&self, cx: &C) -> Option<Float>
338+
where
339+
Ty: TyAbiInterface<'a, C> + Copy,
340+
{
341+
if let Some(Primitive::Float(float)) = self.complex_number_primitive(cx) {
342+
Some(float)
343+
} else {
344+
None
319345
}
320346
}
321347

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,9 @@ enum ImplTraitContext {
411411
FeatureGated(ImplTraitPosition, Symbol),
412412
/// `impl Trait` is not accepted in this position.
413413
Disallowed(ImplTraitPosition),
414+
415+
/// An error has already been emitted for this type.
416+
AlreadyErrored(ErrorGuaranteed),
414417
}
415418

416419
/// Position in which `impl Trait` is disallowed.
@@ -1318,11 +1321,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
13181321
span: data.span,
13191322
}
13201323
} else {
1321-
self.emit_bad_parenthesized_trait_in_assoc_ty(data);
1324+
let guar = self.emit_bad_parenthesized_trait_in_assoc_ty(data);
13221325
self.lower_angle_bracketed_parameter_data(
13231326
&data.as_angle_bracketed_args(),
13241327
ParamMode::Explicit,
1325-
itctx,
1328+
ImplTraitContext::AlreadyErrored(guar),
13261329
)
13271330
.0
13281331
}
@@ -1391,7 +1394,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
13911394
}
13921395
}
13931396

1394-
fn emit_bad_parenthesized_trait_in_assoc_ty(&self, data: &ParenthesizedArgs) {
1397+
fn emit_bad_parenthesized_trait_in_assoc_ty(
1398+
&self,
1399+
data: &ParenthesizedArgs,
1400+
) -> ErrorGuaranteed {
13951401
// Suggest removing empty parentheses: "Trait()" -> "Trait"
13961402
let sub = if data.inputs.is_empty() {
13971403
let parentheses_span =
@@ -1412,7 +1418,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
14121418
data.inputs.last().unwrap().span.shrink_to_hi().to(data.inputs_span.shrink_to_hi());
14131419
AssocTyParenthesesSub::NotEmpty { open_param, close_param }
14141420
};
1415-
self.dcx().emit_err(AssocTyParentheses { span: data.span, sub });
1421+
self.dcx().emit_err(AssocTyParentheses { span: data.span, sub })
14161422
}
14171423

14181424
#[instrument(level = "debug", skip(self))]
@@ -1735,6 +1741,15 @@ impl<'hir> LoweringContext<'_, 'hir> {
17351741
});
17361742
hir::TyKind::Err(guar)
17371743
}
1744+
ImplTraitContext::AlreadyErrored(guar) => {
1745+
// `GenericArgs::Parenthesized` stores its inputs as `Param`s, so the def
1746+
// collector visits `impl Trait` in a universal context and creates a
1747+
// `DefKind::TyParam`. During recovery we reinterpret these arguments as
1748+
// angle-bracketed, where lowering may otherwise expect an opaque type.
1749+
// The parenthesized syntax has already been rejected, so avoid lowering
1750+
// this `impl Trait` with the inconsistent `DefKind`.
1751+
hir::TyKind::Err(guar)
1752+
}
17381753
}
17391754
}
17401755
TyKind::Pat(ty, pat) => {

compiler/rustc_ast_lowering/src/path.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,12 +338,14 @@ impl<'hir> LoweringContext<'_, 'hir> {
338338
} else {
339339
None
340340
};
341-
self.dcx().emit_err(GenericTypeWithParentheses { span: data.span, sub });
341+
let guar = self
342+
.dcx()
343+
.emit_err(GenericTypeWithParentheses { span: data.span, sub });
342344
(
343345
self.lower_angle_bracketed_parameter_data(
344346
&data.as_angle_bracketed_args(),
345347
param_mode,
346-
itctx,
348+
ImplTraitContext::AlreadyErrored(guar),
347349
)
348350
.0,
349351
false,

compiler/rustc_const_eval/src/const_eval/eval_queries.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ pub(super) fn op_to_const<'tcx>(
311311
imm.layout.ty,
312312
);
313313
let msg = "`op_to_const` on an immediate scalar pair must only be used on slice references to the beginning of an actual allocation";
314-
let ptr = a.to_pointer(ecx).expect(msg);
314+
let ptr = a.to_pointer(ecx);
315315
let (prov, offset) =
316316
ptr.into_pointer_or_addr().expect(msg).prov_and_relative_offset();
317317
let alloc_id = prov.alloc_id();

compiler/rustc_const_eval/src/const_eval/machine.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,12 +1019,7 @@ impl<'tcx> interpret::Machine<'tcx> for CompileTimeMachine<'tcx> {
10191019
// (Do nothing on `None` provenance, that cannot store immutability anyway.)
10201020
if let ty::Ref(_, ty, mutbl) = val.layout.ty.kind()
10211021
&& *mutbl == Mutability::Not
1022-
&& val
1023-
.to_scalar_and_meta()
1024-
.0
1025-
.to_pointer(ecx)?
1026-
.provenance
1027-
.is_some_and(|p| !p.immutable())
1022+
&& val.to_scalar_and_meta().0.to_pointer(ecx).provenance.is_some_and(|p| !p.immutable())
10281023
{
10291024
// That next check is expensive, that's why we have all the guards above.
10301025
let is_immutable = ty.is_freeze(*ecx.tcx, ecx.typing_env());

compiler/rustc_const_eval/src/interpret/call.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -848,7 +848,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
848848
assert!(receiver_place.layout.is_unsized());
849849

850850
// Get the required information from the vtable.
851-
let vptr = receiver_place.meta().unwrap_meta().to_pointer(self)?;
851+
let vptr = receiver_place.meta().unwrap_meta().to_pointer(self);
852852
let dyn_ty = self.get_ptr_vtable_ty(vptr, Some(receiver_trait))?;
853853
let adjusted_recv = receiver_place.ptr();
854854

compiler/rustc_const_eval/src/interpret/cast.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
293293
assert!(cast_to.ty.is_integral());
294294

295295
let scalar = src.to_scalar();
296-
let ptr = scalar.to_pointer(self)?;
296+
let ptr = scalar.to_pointer(self);
297297
match ptr.into_pointer_or_addr() {
298298
Ok(ptr) => M::expose_provenance(self, ptr.provenance)?,
299299
Err(_) => {} // Do nothing, exposing an invalid pointer (`None` provenance) is a NOP.
@@ -464,8 +464,8 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
464464
}
465465
// Take apart the old pointer, and find the dynamic type.
466466
let (old_data, old_vptr) = val.to_scalar_pair();
467-
let old_data = old_data.to_pointer(self)?;
468-
let old_vptr = old_vptr.to_pointer(self)?;
467+
let old_data = old_data.to_pointer(self);
468+
let old_vptr = old_vptr.to_pointer(self);
469469
let ty = self.get_ptr_vtable_ty(old_vptr, Some(data_a))?;
470470

471471
// Sanity-check that `supertrait_vtable_slot` in this type's vtable indeed produces

compiler/rustc_const_eval/src/interpret/eval_context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
488488
interp_ok(Some((full_size, full_align)))
489489
}
490490
ty::Dynamic(expected_trait, _) => {
491-
let vtable = metadata.unwrap_meta().to_pointer(self)?;
491+
let vtable = metadata.unwrap_meta().to_pointer(self);
492492
// Read size and align from vtable (already checks size).
493493
interp_ok(Some(self.get_vtable_size_and_align(vtable, Some(expected_trait))?))
494494
}

compiler/rustc_const_eval/src/interpret/intrinsics/simd.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
260260
}
261261
Op::SaturatingOp(mir_op) => self.saturating_arith(mir_op, &left, &right)?,
262262
Op::WrappingOffset => {
263-
let ptr = left.to_scalar().to_pointer(self)?;
263+
let ptr = left.to_scalar().to_pointer(self);
264264
let offset_count = right.to_scalar().to_target_isize(self)?;
265265
let pointee_ty = left.layout.ty.builtin_deref(true).unwrap();
266266

compiler/rustc_const_eval/src/interpret/memory.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1641,7 +1641,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
16411641
Ok(int) => interp_ok(int.is_null()),
16421642
Err(_) => {
16431643
// We can't cast this pointer to an integer. Can only happen during CTFE.
1644-
let ptr = scalar.to_pointer(self)?;
1644+
let ptr = scalar.to_pointer(self);
16451645
match self.ptr_try_get_alloc_id(ptr, 0) {
16461646
Ok((alloc_id, offset, _)) => {
16471647
let info = self.get_alloc_info(alloc_id);

0 commit comments

Comments
 (0)