Check all repr hints together when checking for mis-applied attributes

Fixes #47094

Besides fixing that bug, this change has a user-visible effect on the spans in the "incompatible repr hints" warning and another error: they now point at `foo` and/or `bar` in `repr(foo, bar)` instead of the whole attribute. This is sometimes more precise (e.g., `#[repr(C, packed)]` on an enum points at the `packed`) but sometimes not. I moved a compile-fail test to a ui test to illustrate how it now looks in the common case of only one attribute.
This commit is contained in:
Robin Kruppe 2018-01-01 21:42:12 +01:00
parent 00fbfcce96
commit 03936115ef
7 changed files with 130 additions and 44 deletions

View file

@ -8,7 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![allow(dead_code)]
#![feature(attr_literals)]
#![feature(repr_simd)]

View file

@ -0,0 +1,42 @@
error[E0517]: attribute should be applied to struct, enum or union
--> $DIR/attr-usage-repr.rs:14:8
|
14 | #[repr(C)] //~ ERROR: attribute should be applied to struct, enum or union
| ^
15 | fn f() {}
| --------- not a struct, enum or union
error[E0517]: attribute should be applied to enum
--> $DIR/attr-usage-repr.rs:26:8
|
26 | #[repr(i8)] //~ ERROR: attribute should be applied to enum
| ^^
27 | struct SInt(f64, f64);
| ---------------------- not an enum
error[E0517]: attribute should be applied to struct or union
--> $DIR/attr-usage-repr.rs:32:8
|
32 | #[repr(align(8))] //~ ERROR: attribute should be applied to struct
| ^^^^^^^^
33 | enum EAlign { A, B }
| -------------------- not a struct or union
error[E0517]: attribute should be applied to struct or union
--> $DIR/attr-usage-repr.rs:35:8
|
35 | #[repr(packed)] //~ ERROR: attribute should be applied to struct
| ^^^^^^
36 | enum EPacked { A, B }
| --------------------- not a struct or union
error[E0517]: attribute should be applied to struct
--> $DIR/attr-usage-repr.rs:38:8
|
38 | #[repr(simd)] //~ ERROR: attribute should be applied to struct
| ^^^^
39 | enum ESimd { A, B }
| ------------------- not a struct
error: aborting due to 5 previous errors

View file

@ -13,7 +13,6 @@
#[repr(simd)]
#[derive(Copy, Clone)]
#[repr(C)]
struct LocalSimd(u8, u8);
extern {

View file

@ -1,15 +1,15 @@
error: use of SIMD type `LocalSimd` in FFI is highly experimental and may result in invalid code
--> $DIR/feature-gate-simd-ffi.rs:20:17
--> $DIR/feature-gate-simd-ffi.rs:19:17
|
20 | fn baz() -> LocalSimd; //~ ERROR use of SIMD type
19 | fn baz() -> LocalSimd; //~ ERROR use of SIMD type
| ^^^^^^^^^
|
= help: add #![feature(simd_ffi)] to the crate attributes to enable
error: use of SIMD type `LocalSimd` in FFI is highly experimental and may result in invalid code
--> $DIR/feature-gate-simd-ffi.rs:21:15
--> $DIR/feature-gate-simd-ffi.rs:20:15
|
21 | fn qux(x: LocalSimd); //~ ERROR use of SIMD type
20 | fn qux(x: LocalSimd); //~ ERROR use of SIMD type
| ^^^^^^^^^
|
= help: add #![feature(simd_ffi)] to the crate attributes to enable

View file

@ -0,0 +1,26 @@
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// must-compile-successfully
#[repr(C,u8)]
enum Foo {
A,
B,
}
#[repr(C)]
#[repr(u8)]
enum Bar {
A,
B,
}
fn main() {}

View file

@ -0,0 +1,14 @@
warning[E0566]: conflicting representation hints
--> $DIR/issue-47094.rs:13:8
|
13 | #[repr(C,u8)]
| ^ ^^
warning[E0566]: conflicting representation hints
--> $DIR/issue-47094.rs:19:8
|
19 | #[repr(C)]
| ^
20 | #[repr(u8)]
| ^^