Skip to content

Commit

Permalink
Auto merge of rust-lang#120852 - matthiaskrgr:rollup-01pr8gj, r=matth…
Browse files Browse the repository at this point in the history
…iaskrgr

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
  • Loading branch information
bors committed Feb 9, 2024
2 parents f4cfd87 + 3c1b7a7 commit de9f05a
Show file tree
Hide file tree
Showing 195 changed files with 4,726 additions and 872 deletions.
10 changes: 5 additions & 5 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ checksum = "2da6da31387c7e4ef160ffab6d5e7f00c42626fe39aea70a7b0f1773f7dd6c1b"

[[package]]
name = "clippy"
version = "0.1.77"
version = "0.1.78"
dependencies = [
"anstream",
"clippy_config",
Expand Down Expand Up @@ -584,7 +584,7 @@ dependencies = [

[[package]]
name = "clippy_config"
version = "0.1.77"
version = "0.1.78"
dependencies = [
"rustc-semver",
"serde",
Expand All @@ -607,7 +607,7 @@ dependencies = [

[[package]]
name = "clippy_lints"
version = "0.1.77"
version = "0.1.78"
dependencies = [
"arrayvec",
"cargo_metadata 0.18.0",
Expand All @@ -632,7 +632,7 @@ dependencies = [

[[package]]
name = "clippy_utils"
version = "0.1.77"
version = "0.1.78"
dependencies = [
"arrayvec",
"clippy_config",
Expand Down Expand Up @@ -1003,7 +1003,7 @@ checksum = "a0afaad2b26fa326569eb264b1363e8ae3357618c43982b3f285f0774ce76b69"

[[package]]
name = "declare_clippy_lint"
version = "0.1.77"
version = "0.1.78"
dependencies = [
"itertools",
"quote",
Expand Down
1 change: 0 additions & 1 deletion RELEASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ Language
--------
- [Document Rust ABI compatibility between various types](https://github.com/rust-lang/rust/pull/115476/)
- [Also: guarantee that char and u32 are ABI-compatible](https://github.com/rust-lang/rust/pull/118032/)
- [Warn against ambiguous wide pointer comparisons](https://github.com/rust-lang/rust/pull/117758/)
- [Add lint `ambiguous_wide_pointer_comparisons` that supersedes `clippy::vtable_address_comparisons`](https://github.com/rust-lang/rust/pull/117758)

<a id="1.76.0-Compiler"></a>
Expand Down
5 changes: 4 additions & 1 deletion compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@ pub fn type_di_node<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>, t: Ty<'tcx>) -> &'ll D
}
ty::FnDef(..) | ty::FnPtr(_) => build_subroutine_type_di_node(cx, unique_type_id),
ty::Closure(..) => build_closure_env_di_node(cx, unique_type_id),
ty::CoroutineClosure(..) => build_closure_env_di_node(cx, unique_type_id),
ty::Coroutine(..) => enums::build_coroutine_di_node(cx, unique_type_id),
ty::Adt(def, ..) => match def.adt_kind() {
AdtKind::Struct => build_struct_type_di_node(cx, unique_type_id),
Expand Down Expand Up @@ -1068,6 +1069,7 @@ fn build_upvar_field_di_nodes<'ll, 'tcx>(
let (&def_id, up_var_tys) = match closure_or_coroutine_ty.kind() {
ty::Coroutine(def_id, args) => (def_id, args.as_coroutine().prefix_tys()),
ty::Closure(def_id, args) => (def_id, args.as_closure().upvar_tys()),
ty::CoroutineClosure(def_id, args) => (def_id, args.as_coroutine_closure().upvar_tys()),
_ => {
bug!(
"build_upvar_field_di_nodes() called with non-closure-or-coroutine-type: {:?}",
Expand Down Expand Up @@ -1153,7 +1155,8 @@ fn build_closure_env_di_node<'ll, 'tcx>(
unique_type_id: UniqueTypeId<'tcx>,
) -> DINodeCreationResult<'ll> {
let closure_env_type = unique_type_id.expect_ty();
let &ty::Closure(def_id, _args) = closure_env_type.kind() else {
let &(ty::Closure(def_id, _) | ty::CoroutineClosure(def_id, _)) = closure_env_type.kind()
else {
bug!("build_closure_env_di_node() called with non-closure-type: {:?}", closure_env_type)
};
let containing_scope = get_namespace_for_item(cx, def_id);
Expand Down
6 changes: 2 additions & 4 deletions compiler/rustc_codegen_llvm/src/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1985,10 +1985,9 @@ fn generic_simd_intrinsic<'ll, 'tcx>(

match in_elem.kind() {
ty::RawPtr(p) => {
let (metadata, check_sized) = p.ty.ptr_metadata_ty(bx.tcx, |ty| {
let metadata = p.ty.ptr_metadata_ty(bx.tcx, |ty| {
bx.tcx.normalize_erasing_regions(ty::ParamEnv::reveal_all(), ty)
});
assert!(!check_sized); // we are in codegen, so we shouldn't see these types
require!(
metadata.is_unit(),
InvalidMonomorphization::CastFatPointer { span, name, ty: in_elem }
Expand All @@ -2000,10 +1999,9 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
}
match out_elem.kind() {
ty::RawPtr(p) => {
let (metadata, check_sized) = p.ty.ptr_metadata_ty(bx.tcx, |ty| {
let metadata = p.ty.ptr_metadata_ty(bx.tcx, |ty| {
bx.tcx.normalize_erasing_regions(ty::ParamEnv::reveal_all(), ty)
});
assert!(!check_sized); // we are in codegen, so we shouldn't see these types
require!(
metadata.is_unit(),
InvalidMonomorphization::CastFatPointer { span, name, ty: out_elem }
Expand Down
7 changes: 1 addition & 6 deletions compiler/rustc_const_eval/src/interpret/terminator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,12 +377,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
// to fields, which can yield non-normalized types. So we need to provide a
// normalization function.
let normalize = |ty| self.tcx.normalize_erasing_regions(self.param_env, ty);
let (meta, only_if_sized) = ty.ptr_metadata_ty(*self.tcx, normalize);
assert!(
!only_if_sized,
"there should be no more 'maybe has that metadata' types during interpretation"
);
meta
ty.ptr_metadata_ty(*self.tcx, normalize)
};
return Ok(meta_ty(caller) == meta_ty(callee));
}
Expand Down
26 changes: 24 additions & 2 deletions compiler/rustc_hir_typeck/src/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,13 +448,35 @@ impl<'a, 'tcx> CastCheck<'tcx> {
);
}
}
let msg = "an `as` expression can only be used to convert between primitive \
types or to coerce to a specific trait object";

let (msg, note) = if let ty::Adt(adt, _) = self.expr_ty.kind()
&& adt.is_enum()
&& self.cast_ty.is_numeric()
{
(
"an `as` expression can be used to convert enum types to numeric \
types only if the enum type is unit-only or field-less",
Some(
"see https://doc.rust-lang.org/reference/items/enumerations.html#casting for more information",
),
)
} else {
(
"an `as` expression can only be used to convert between primitive \
types or to coerce to a specific trait object",
None,
)
};

if label {
err.span_label(self.span, msg);
} else {
err.note(msg);
}

if let Some(note) = note {
err.note(note);
}
} else {
err.span_label(self.span, "invalid cast");
}
Expand Down
48 changes: 32 additions & 16 deletions compiler/rustc_middle/src/ty/sty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2279,12 +2279,12 @@ impl<'tcx> Ty<'tcx> {
}

/// Returns the type of metadata for (potentially fat) pointers to this type,
/// and a boolean signifying if this is conditional on this type being `Sized`.
pub fn ptr_metadata_ty(
/// or the struct tail if the metadata type cannot be determined.
pub fn ptr_metadata_ty_or_tail(
self,
tcx: TyCtxt<'tcx>,
normalize: impl FnMut(Ty<'tcx>) -> Ty<'tcx>,
) -> (Ty<'tcx>, bool) {
) -> Result<Ty<'tcx>, Ty<'tcx>> {
let tail = tcx.struct_tail_with_normalize(self, normalize, || {});
match tail.kind() {
// Sized types
Expand All @@ -2307,31 +2307,47 @@ impl<'tcx> Ty<'tcx> {
| ty::Error(_)
// Extern types have metadata = ().
| ty::Foreign(..)
// `dyn*` has no metadata
// `dyn*` has metadata = ().
| ty::Dynamic(_, _, ty::DynStar)
// If returned by `struct_tail_without_normalization` this is a unit struct
// If returned by `struct_tail_with_normalize` this is a unit struct
// without any fields, or not a struct, and therefore is Sized.
| ty::Adt(..)
// If returned by `struct_tail_without_normalization` this is the empty tuple,
// If returned by `struct_tail_with_normalize` this is the empty tuple,
// a.k.a. unit type, which is Sized
| ty::Tuple(..) => (tcx.types.unit, false),
| ty::Tuple(..) => Ok(tcx.types.unit),

ty::Str | ty::Slice(_) => Ok(tcx.types.usize),

ty::Str | ty::Slice(_) => (tcx.types.usize, false),
ty::Dynamic(_, _, ty::Dyn) => {
let dyn_metadata = tcx.require_lang_item(LangItem::DynMetadata, None);
(tcx.type_of(dyn_metadata).instantiate(tcx, &[tail.into()]), false)
},
Ok(tcx.type_of(dyn_metadata).instantiate(tcx, &[tail.into()]))
}

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

ty::Infer(ty::TyVar(_))
| ty::Bound(..)
| ty::Placeholder(..)
| ty::Infer(ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => {
bug!("`ptr_metadata_ty` applied to unexpected type: {:?} (tail = {:?})", self, tail)
}
| ty::Infer(ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => bug!(
"`ptr_metadata_ty_or_tail` applied to unexpected type: {self:?} (tail = {tail:?})"
),
}
}

/// Returns the type of metadata for (potentially fat) pointers to this type.
/// Causes an ICE if the metadata type cannot be determined.
pub fn ptr_metadata_ty(
self,
tcx: TyCtxt<'tcx>,
normalize: impl FnMut(Ty<'tcx>) -> Ty<'tcx>,
) -> Ty<'tcx> {
match self.ptr_metadata_ty_or_tail(tcx, normalize) {
Ok(metadata) => metadata,
Err(tail) => bug!(
"`ptr_metadata_ty` failed to get metadata for type: {self:?} (tail = {tail:?})"
),
}
}

Expand Down

0 comments on commit de9f05a

Please sign in to comment.