From bd3d1ae1ebbd417c8a702911100af8a8ca309aae Mon Sep 17 00:00:00 2001 From: Lukas Markeffsky <@> Date: Mon, 13 Jun 2022 23:32:04 +0200 Subject: [PATCH] fix error (maybe), use short/inline suggestions --- compiler/rustc_typeck/src/check/check.rs | 30 ++++++++-------- src/test/ui/repr/repr-transparent.stderr | 45 ++++++++---------------- 2 files changed, 30 insertions(+), 45 deletions(-) diff --git a/compiler/rustc_typeck/src/check/check.rs b/compiler/rustc_typeck/src/check/check.rs index 4888d38d49daf..97c0afa960041 100644 --- a/compiler/rustc_typeck/src/check/check.rs +++ b/compiler/rustc_typeck/src/check/check.rs @@ -21,7 +21,7 @@ use rustc_middle::ty::layout::{LayoutError, MAX_SIMD_LANES}; use rustc_middle::ty::subst::GenericArgKind; use rustc_middle::ty::util::{Discr, IntTypeExt}; use rustc_middle::ty::{ - self, ParamEnv, ToPredicate, Ty, TyCtxt, TyKind, TypeFoldable, TypeSuperFoldable, + self, Array, ParamEnv, ToPredicate, Ty, TyCtxt, TypeFoldable, TypeSuperFoldable, }; use rustc_session::lint::builtin::{UNINHABITED_STATIC, UNSUPPORTED_CALLING_CONVENTIONS}; use rustc_span::symbol::sym; @@ -1206,17 +1206,17 @@ pub(super) fn check_packed(tcx: TyCtxt<'_>, sp: Span, def: ty::AdtDef<'_>) { for attr in tcx.get_attrs(def.did(), sym::repr) { for r in attr::parse_repr_attr(&tcx.sess, attr) { if let attr::ReprPacked(pack) = r - && let Some(repr_pack) = repr.pack - && pack as u64 != repr_pack.bytes() - { - struct_span_err!( - tcx.sess, - sp, - E0634, - "type has conflicting packed representation hints" - ) - .emit(); - } + && let Some(repr_pack) = repr.pack + && pack as u64 != repr_pack.bytes() + { + struct_span_err!( + tcx.sess, + sp, + E0634, + "type has conflicting packed representation hints" + ) + .emit(); + } } } if repr.align.is_some() { @@ -1330,7 +1330,7 @@ pub(super) fn check_transparent<'tcx>(tcx: TyCtxt<'tcx>, sp: Span, adt: ty::AdtD // We are currently checking the type this field came from, so it must be local let span = tcx.hir().span_if_local(field.did).unwrap(); let array_len = match ty.kind() { - TyKind::Array(_, len) => len.try_eval_usize(tcx, param_env), + Array(_, len) => len.try_eval_usize(tcx, param_env), _ => None, }; let zst = array_len == Some(0) || layout.map_or(false, |layout| layout.is_zst()); @@ -1365,9 +1365,9 @@ pub(super) fn check_transparent<'tcx>(tcx: TyCtxt<'tcx>, sp: Span, adt: ty::AdtD { for item in item_list { if item.name_or_empty() == sym::transparent { - err.span_suggestion_verbose( + err.span_suggestion_short( item.span(), - "Try using `#[repc(C)]` instead", + "Try using `repr(C)` instead", "C", Applicability::MachineApplicable, ); diff --git a/src/test/ui/repr/repr-transparent.stderr b/src/test/ui/repr/repr-transparent.stderr index d1e6b68f4c7e4..af95f173a7b98 100644 --- a/src/test/ui/repr/repr-transparent.stderr +++ b/src/test/ui/repr/repr-transparent.stderr @@ -21,35 +21,26 @@ LL | pub struct StructWithProjection(f32, ::It); error[E0691]: zero-sized field in transparent struct has alignment larger than 1 --> $DIR/repr-transparent.rs:36:32 | +LL | #[repr(transparent)] + | ----------- help: Try using `repr(C)` instead LL | struct NontrivialAlignZst(u32, [u16; 0]); | ^^^^^^^^ has alignment larger than 1 - | -help: Try using `#[repc(C)]` instead - | -LL | #[repr(C)] - | ~ error[E0691]: zero-sized field in transparent struct has alignment larger than 1 --> $DIR/repr-transparent.rs:42:24 | +LL | #[repr(transparent)] + | ----------- help: Try using `repr(C)` instead LL | struct GenericAlign(ZstAlign32, u32); | ^^^^^^^^^^^^^ has alignment larger than 1 - | -help: Try using `#[repc(C)]` instead - | -LL | #[repr(C)] - | ~ error[E0691]: zero-sized field in transparent struct has alignment larger than 1 --> $DIR/repr-transparent.rs:45:33 | +LL | #[repr(transparent)] + | ----------- help: Try using `repr(C)` instead LL | struct GenericAlignZeroArray([T; 0], u32); | ^^^^^^ may have alignment larger than 1 - | -help: Try using `#[repc(C)]` instead - | -LL | #[repr(C)] - | ~ error[E0084]: unsupported representation for zero-variant enum --> $DIR/repr-transparent.rs:47:1 @@ -88,35 +79,29 @@ LL | Bar, error[E0691]: zero-sized field in transparent enum has alignment larger than 1 --> $DIR/repr-transparent.rs:74:14 | +LL | #[repr(transparent)] + | ----------- help: Try using `repr(C)` instead +LL | enum NontrivialAlignZstEnum { LL | Foo(u32, [u16; 0]), | ^^^^^^^^ has alignment larger than 1 - | -help: Try using `#[repc(C)]` instead - | -LL | #[repr(C)] - | ~ error[E0691]: zero-sized field in transparent enum has alignment larger than 1 --> $DIR/repr-transparent.rs:79:11 | +LL | #[repr(transparent)] + | ----------- help: Try using `repr(C)` instead +LL | enum GenericAlignEnum { LL | Foo { bar: ZstAlign32, baz: u32 } | ^^^^^^^^^^^^^^^^^^ has alignment larger than 1 - | -help: Try using `#[repc(C)]` instead - | -LL | #[repr(C)] - | ~ error[E0691]: zero-sized field in transparent enum has alignment larger than 1 --> $DIR/repr-transparent.rs:84:11 | +LL | #[repr(transparent)] + | ----------- help: Try using `repr(C)` instead +LL | enum GenericAlignEnumZeroArray { LL | Foo { bar: [T; 0], baz: u32 } | ^^^^^^^^^^^ may have alignment larger than 1 - | -help: Try using `#[repc(C)]` instead - | -LL | #[repr(C)] - | ~ error[E0690]: transparent union needs at most one non-zero-sized field, but has 2 --> $DIR/repr-transparent.rs:93:1