Skip to content

Commit

Permalink
fix error (maybe), use short/inline suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukas Markeffsky committed Jun 13, 2022
1 parent 09c6c54 commit bd3d1ae
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 45 deletions.
30 changes: 15 additions & 15 deletions compiler/rustc_typeck/src/check/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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,
);
Expand Down
45 changes: 15 additions & 30 deletions src/test/ui/repr/repr-transparent.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -21,35 +21,26 @@ LL | pub struct StructWithProjection(f32, <f32 as Mirror>::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<T>(ZstAlign32<T>, 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>([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
Expand Down Expand Up @@ -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<T> {
LL | Foo { bar: ZstAlign32<T>, 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<T> {
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
Expand Down

0 comments on commit bd3d1ae

Please sign in to comment.