Rollup merge of #51401 - estebank:warn-repr, r=cramertj

Warn on `repr` without hints

Fix #51376.
This commit is contained in:
Mark Rousskov 2018-06-08 17:21:05 -06:00 committed by GitHub
commit 898bb78024
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 407 additions and 211 deletions

View file

@ -59,7 +59,9 @@
#![start = "x4300"] //~ WARN unused attribute
// see issue-43106-gating-of-test.rs for crate-level; but non crate-level is below at "4200"
// see issue-43106-gating-of-bench.rs for crate-level; but non crate-level is below at "4100"
#![repr = "3900"] //~ WARN unused attribute
#![repr = "3900"]
//~^ WARN unused attribute
//~| WARN `repr` attribute isn't configurable with a literal
#![path = "3800"] //~ WARN unused attribute
#![abi = "3700"] //~ WARN unused attribute
#![automatically_derived = "3600"] //~ WARN unused attribute
@ -309,20 +311,25 @@ mod bench {
#[repr = "3900"]
//~^ WARN unused attribute
//~| WARN `repr` attribute isn't configurable with a literal
mod repr {
mod inner { #![repr="3900"] }
//~^ WARN unused attribute
//~| WARN `repr` attribute isn't configurable with a literal
#[repr = "3900"] fn f() { }
//~^ WARN unused attribute
//~| WARN `repr` attribute isn't configurable with a literal
struct S;
#[repr = "3900"] type T = S;
//~^ WARN unused attribute
//~| WARN `repr` attribute isn't configurable with a literal
#[repr = "3900"] impl S { }
//~^ WARN unused attribute
//~| WARN `repr` attribute isn't configurable with a literal
}
#[path = "3800"]

View file

@ -0,0 +1,28 @@
// Copyright 2018 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.
// compile-pass
#[repr]
//^ WARN `repr` attribute must have a hint
struct _A {}
#[repr = "B"]
//^ WARN `repr` attribute isn't configurable with a literal
struct _B {}
#[repr = "C"]
//^ WARN `repr` attribute isn't configurable with a literal
struct _C {}
#[repr(C)]
struct _D {}
fn main() {}

View file

@ -0,0 +1,25 @@
warning: `repr` attribute must have a hint
--> $DIR/repr.rs:13:1
|
LL | #[repr]
| ^^^^^^^ needs a hint
|
= note: #[warn(bad_repr)] on by default
= help: valid hints include `#[repr(C)]`, `#[repr(packed)]`, `#[repr(rust)]` and `#[repr(transparent)]`
= note: for more information, visit <https://doc.rust-lang.org/reference/type-layout.html>
warning: `repr` attribute isn't configurable with a literal
--> $DIR/repr.rs:17:1
|
LL | #[repr = "B"]
| ^^^^^^^^^^^^^ needs a hint
|
= help: valid hints include `#[repr(C)]`, `#[repr(packed)]`, `#[repr(rust)]` and `#[repr(transparent)]`
= note: for more information, visit <https://doc.rust-lang.org/reference/type-layout.html>
warning: `repr` attribute isn't configurable with a literal
--> $DIR/repr.rs:21:1
|
LL | #[repr = "C"]
| ^^^^^^^^^^^^^ help: give `repr` a hint: `#[repr(C)]`