Skip to content

Commit de9f05a

Browse files
committed
Auto merge of rust-lang#120852 - matthiaskrgr:rollup-01pr8gj, r=matthiaskrgr
Rollup of 11 pull requests Successful merges: - rust-lang#120351 (Implement SystemTime for UEFI) - rust-lang#120354 (improve normalization of `Pointee::Metadata`) - rust-lang#120776 (Move path implementations into `sys`) - rust-lang#120790 (better error message on download CI LLVM failure) - rust-lang#120806 (Clippy subtree update) - rust-lang#120815 (Improve `Option::inspect` docs) - rust-lang#120822 (Emit more specific diagnostics when enums fail to cast with `as`) - rust-lang#120827 (Print image input file and checksum in CI only) - rust-lang#120836 (hide impls if trait bound is proven from env) - rust-lang#120844 (Build DebugInfo for async closures) - rust-lang#120851 (Remove duplicate release note) r? `@ghost` `@rustbot` modify labels: rollup
2 parents f4cfd87 + 3c1b7a7 commit de9f05a

File tree

195 files changed

+4726
-872
lines changed

Some content is hidden

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

195 files changed

+4726
-872
lines changed

Cargo.lock

+5-5
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ checksum = "2da6da31387c7e4ef160ffab6d5e7f00c42626fe39aea70a7b0f1773f7dd6c1b"
556556

557557
[[package]]
558558
name = "clippy"
559-
version = "0.1.77"
559+
version = "0.1.78"
560560
dependencies = [
561561
"anstream",
562562
"clippy_config",
@@ -584,7 +584,7 @@ dependencies = [
584584

585585
[[package]]
586586
name = "clippy_config"
587-
version = "0.1.77"
587+
version = "0.1.78"
588588
dependencies = [
589589
"rustc-semver",
590590
"serde",
@@ -607,7 +607,7 @@ dependencies = [
607607

608608
[[package]]
609609
name = "clippy_lints"
610-
version = "0.1.77"
610+
version = "0.1.78"
611611
dependencies = [
612612
"arrayvec",
613613
"cargo_metadata 0.18.0",
@@ -632,7 +632,7 @@ dependencies = [
632632

633633
[[package]]
634634
name = "clippy_utils"
635-
version = "0.1.77"
635+
version = "0.1.78"
636636
dependencies = [
637637
"arrayvec",
638638
"clippy_config",
@@ -1003,7 +1003,7 @@ checksum = "a0afaad2b26fa326569eb264b1363e8ae3357618c43982b3f285f0774ce76b69"
10031003

10041004
[[package]]
10051005
name = "declare_clippy_lint"
1006-
version = "0.1.77"
1006+
version = "0.1.78"
10071007
dependencies = [
10081008
"itertools",
10091009
"quote",

RELEASES.md

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ Language
77
--------
88
- [Document Rust ABI compatibility between various types](https://github.com/rust-lang/rust/pull/115476/)
99
- [Also: guarantee that char and u32 are ABI-compatible](https://github.com/rust-lang/rust/pull/118032/)
10-
- [Warn against ambiguous wide pointer comparisons](https://github.com/rust-lang/rust/pull/117758/)
1110
- [Add lint `ambiguous_wide_pointer_comparisons` that supersedes `clippy::vtable_address_comparisons`](https://github.com/rust-lang/rust/pull/117758)
1211

1312
<a id="1.76.0-Compiler"></a>

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,7 @@ pub fn type_di_node<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>, t: Ty<'tcx>) -> &'ll D
461461
}
462462
ty::FnDef(..) | ty::FnPtr(_) => build_subroutine_type_di_node(cx, unique_type_id),
463463
ty::Closure(..) => build_closure_env_di_node(cx, unique_type_id),
464+
ty::CoroutineClosure(..) => build_closure_env_di_node(cx, unique_type_id),
464465
ty::Coroutine(..) => enums::build_coroutine_di_node(cx, unique_type_id),
465466
ty::Adt(def, ..) => match def.adt_kind() {
466467
AdtKind::Struct => build_struct_type_di_node(cx, unique_type_id),
@@ -1068,6 +1069,7 @@ fn build_upvar_field_di_nodes<'ll, 'tcx>(
10681069
let (&def_id, up_var_tys) = match closure_or_coroutine_ty.kind() {
10691070
ty::Coroutine(def_id, args) => (def_id, args.as_coroutine().prefix_tys()),
10701071
ty::Closure(def_id, args) => (def_id, args.as_closure().upvar_tys()),
1072+
ty::CoroutineClosure(def_id, args) => (def_id, args.as_coroutine_closure().upvar_tys()),
10711073
_ => {
10721074
bug!(
10731075
"build_upvar_field_di_nodes() called with non-closure-or-coroutine-type: {:?}",
@@ -1153,7 +1155,8 @@ fn build_closure_env_di_node<'ll, 'tcx>(
11531155
unique_type_id: UniqueTypeId<'tcx>,
11541156
) -> DINodeCreationResult<'ll> {
11551157
let closure_env_type = unique_type_id.expect_ty();
1156-
let &ty::Closure(def_id, _args) = closure_env_type.kind() else {
1158+
let &(ty::Closure(def_id, _) | ty::CoroutineClosure(def_id, _)) = closure_env_type.kind()
1159+
else {
11571160
bug!("build_closure_env_di_node() called with non-closure-type: {:?}", closure_env_type)
11581161
};
11591162
let containing_scope = get_namespace_for_item(cx, def_id);

compiler/rustc_codegen_llvm/src/intrinsic.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -1985,10 +1985,9 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
19851985

19861986
match in_elem.kind() {
19871987
ty::RawPtr(p) => {
1988-
let (metadata, check_sized) = p.ty.ptr_metadata_ty(bx.tcx, |ty| {
1988+
let metadata = p.ty.ptr_metadata_ty(bx.tcx, |ty| {
19891989
bx.tcx.normalize_erasing_regions(ty::ParamEnv::reveal_all(), ty)
19901990
});
1991-
assert!(!check_sized); // we are in codegen, so we shouldn't see these types
19921991
require!(
19931992
metadata.is_unit(),
19941993
InvalidMonomorphization::CastFatPointer { span, name, ty: in_elem }
@@ -2000,10 +1999,9 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
20001999
}
20012000
match out_elem.kind() {
20022001
ty::RawPtr(p) => {
2003-
let (metadata, check_sized) = p.ty.ptr_metadata_ty(bx.tcx, |ty| {
2002+
let metadata = p.ty.ptr_metadata_ty(bx.tcx, |ty| {
20042003
bx.tcx.normalize_erasing_regions(ty::ParamEnv::reveal_all(), ty)
20052004
});
2006-
assert!(!check_sized); // we are in codegen, so we shouldn't see these types
20072005
require!(
20082006
metadata.is_unit(),
20092007
InvalidMonomorphization::CastFatPointer { span, name, ty: out_elem }

compiler/rustc_const_eval/src/interpret/terminator.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -377,12 +377,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
377377
// to fields, which can yield non-normalized types. So we need to provide a
378378
// normalization function.
379379
let normalize = |ty| self.tcx.normalize_erasing_regions(self.param_env, ty);
380-
let (meta, only_if_sized) = ty.ptr_metadata_ty(*self.tcx, normalize);
381-
assert!(
382-
!only_if_sized,
383-
"there should be no more 'maybe has that metadata' types during interpretation"
384-
);
385-
meta
380+
ty.ptr_metadata_ty(*self.tcx, normalize)
386381
};
387382
return Ok(meta_ty(caller) == meta_ty(callee));
388383
}

compiler/rustc_hir_typeck/src/cast.rs

+24-2
Original file line numberDiff line numberDiff line change
@@ -448,13 +448,35 @@ impl<'a, 'tcx> CastCheck<'tcx> {
448448
);
449449
}
450450
}
451-
let msg = "an `as` expression can only be used to convert between primitive \
452-
types or to coerce to a specific trait object";
451+
452+
let (msg, note) = if let ty::Adt(adt, _) = self.expr_ty.kind()
453+
&& adt.is_enum()
454+
&& self.cast_ty.is_numeric()
455+
{
456+
(
457+
"an `as` expression can be used to convert enum types to numeric \
458+
types only if the enum type is unit-only or field-less",
459+
Some(
460+
"see https://doc.rust-lang.org/reference/items/enumerations.html#casting for more information",
461+
),
462+
)
463+
} else {
464+
(
465+
"an `as` expression can only be used to convert between primitive \
466+
types or to coerce to a specific trait object",
467+
None,
468+
)
469+
};
470+
453471
if label {
454472
err.span_label(self.span, msg);
455473
} else {
456474
err.note(msg);
457475
}
476+
477+
if let Some(note) = note {
478+
err.note(note);
479+
}
458480
} else {
459481
err.span_label(self.span, "invalid cast");
460482
}

compiler/rustc_middle/src/ty/sty.rs

+32-16
Original file line numberDiff line numberDiff line change
@@ -2279,12 +2279,12 @@ impl<'tcx> Ty<'tcx> {
22792279
}
22802280

22812281
/// Returns the type of metadata for (potentially fat) pointers to this type,
2282-
/// and a boolean signifying if this is conditional on this type being `Sized`.
2283-
pub fn ptr_metadata_ty(
2282+
/// or the struct tail if the metadata type cannot be determined.
2283+
pub fn ptr_metadata_ty_or_tail(
22842284
self,
22852285
tcx: TyCtxt<'tcx>,
22862286
normalize: impl FnMut(Ty<'tcx>) -> Ty<'tcx>,
2287-
) -> (Ty<'tcx>, bool) {
2287+
) -> Result<Ty<'tcx>, Ty<'tcx>> {
22882288
let tail = tcx.struct_tail_with_normalize(self, normalize, || {});
22892289
match tail.kind() {
22902290
// Sized types
@@ -2307,31 +2307,47 @@ impl<'tcx> Ty<'tcx> {
23072307
| ty::Error(_)
23082308
// Extern types have metadata = ().
23092309
| ty::Foreign(..)
2310-
// `dyn*` has no metadata
2310+
// `dyn*` has metadata = ().
23112311
| ty::Dynamic(_, _, ty::DynStar)
2312-
// If returned by `struct_tail_without_normalization` this is a unit struct
2312+
// If returned by `struct_tail_with_normalize` this is a unit struct
23132313
// without any fields, or not a struct, and therefore is Sized.
23142314
| ty::Adt(..)
2315-
// If returned by `struct_tail_without_normalization` this is the empty tuple,
2315+
// If returned by `struct_tail_with_normalize` this is the empty tuple,
23162316
// a.k.a. unit type, which is Sized
2317-
| ty::Tuple(..) => (tcx.types.unit, false),
2317+
| ty::Tuple(..) => Ok(tcx.types.unit),
2318+
2319+
ty::Str | ty::Slice(_) => Ok(tcx.types.usize),
23182320

2319-
ty::Str | ty::Slice(_) => (tcx.types.usize, false),
23202321
ty::Dynamic(_, _, ty::Dyn) => {
23212322
let dyn_metadata = tcx.require_lang_item(LangItem::DynMetadata, None);
2322-
(tcx.type_of(dyn_metadata).instantiate(tcx, &[tail.into()]), false)
2323-
},
2323+
Ok(tcx.type_of(dyn_metadata).instantiate(tcx, &[tail.into()]))
2324+
}
23242325

2325-
// type parameters only have unit metadata if they're sized, so return true
2326-
// to make sure we double check this during confirmation
2327-
ty::Param(_) | ty::Alias(..) => (tcx.types.unit, true),
2326+
// We don't know the metadata of `self`, but it must be equal to the
2327+
// metadata of `tail`.
2328+
ty::Param(_) | ty::Alias(..) => Err(tail),
23282329

23292330
ty::Infer(ty::TyVar(_))
23302331
| ty::Bound(..)
23312332
| ty::Placeholder(..)
2332-
| ty::Infer(ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => {
2333-
bug!("`ptr_metadata_ty` applied to unexpected type: {:?} (tail = {:?})", self, tail)
2334-
}
2333+
| ty::Infer(ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => bug!(
2334+
"`ptr_metadata_ty_or_tail` applied to unexpected type: {self:?} (tail = {tail:?})"
2335+
),
2336+
}
2337+
}
2338+
2339+
/// Returns the type of metadata for (potentially fat) pointers to this type.
2340+
/// Causes an ICE if the metadata type cannot be determined.
2341+
pub fn ptr_metadata_ty(
2342+
self,
2343+
tcx: TyCtxt<'tcx>,
2344+
normalize: impl FnMut(Ty<'tcx>) -> Ty<'tcx>,
2345+
) -> Ty<'tcx> {
2346+
match self.ptr_metadata_ty_or_tail(tcx, normalize) {
2347+
Ok(metadata) => metadata,
2348+
Err(tail) => bug!(
2349+
"`ptr_metadata_ty` failed to get metadata for type: {self:?} (tail = {tail:?})"
2350+
),
23352351
}
23362352
}
23372353

0 commit comments

Comments
 (0)