Skip to content

Commit

Permalink
lintify conflicting_repr_hints
Browse files Browse the repository at this point in the history
  • Loading branch information
Centril authored and Mark-Simulacrum committed Feb 21, 2020
1 parent a07f8db commit cdcf45b
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 20 deletions.
21 changes: 12 additions & 9 deletions src/librustc/hir/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use rustc_hir::def_id::DefId;
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
use rustc_hir::DUMMY_HIR_ID;
use rustc_hir::{self, HirId, Item, ItemKind, TraitItem, TraitItemKind};
use rustc_session::lint::builtin::UNUSED_ATTRIBUTES;
use rustc_session::lint::builtin::{CONFLICTING_REPR_HINTS, UNUSED_ATTRIBUTES};
use rustc_span::symbol::sym;
use rustc_span::Span;
use syntax::ast::Attribute;
Expand Down Expand Up @@ -196,7 +196,7 @@ impl CheckAttrVisitor<'tcx> {
self.tcx.codegen_fn_attrs(self.tcx.hir().local_def_id(hir_id));
}

self.check_repr(attrs, span, target, item);
self.check_repr(attrs, span, target, item, hir_id);
self.check_used(attrs, target);
}

Expand Down Expand Up @@ -357,6 +357,7 @@ impl CheckAttrVisitor<'tcx> {
span: &Span,
target: Target,
item: Option<&Item<'_>>,
hir_id: HirId,
) {
// Extract the names of all repr hints, e.g., [foo, bar, align] for:
// ```
Expand Down Expand Up @@ -446,13 +447,15 @@ impl CheckAttrVisitor<'tcx> {
|| (is_simd && is_c)
|| (int_reprs == 1 && is_c && item.map_or(false, |item| is_c_like_enum(item)))
{
struct_span_err!(
self.tcx.sess,
hint_spans.collect::<Vec<Span>>(),
E0566,
"conflicting representation hints",
)
.emit();
self.tcx
.struct_span_lint_hir(
CONFLICTING_REPR_HINTS,
hir_id,
hint_spans.collect::<Vec<Span>>(),
"conflicting representation hints",
)
.code(rustc_errors::error_code!(E0566))
.emit();
}
}

Expand Down
11 changes: 11 additions & 0 deletions src/librustc_session/lint/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ declare_lint! {
};
}

declare_lint! {
pub CONFLICTING_REPR_HINTS,
Deny,
"conflicts between `#[repr(..)]` hints that were previously accepted and used in practice",
@future_incompatible = FutureIncompatibleInfo {
reference: "issue #68585 <https://github.com/rust-lang/rust/issues/68585>",
edition: None,
};
}

declare_lint! {
pub META_VARIABLE_MISUSE,
Allow,
Expand Down Expand Up @@ -520,6 +530,7 @@ declare_lint_pass! {
MACRO_USE_EXTERN_CRATE,
MACRO_EXPANDED_MACRO_EXPORTS_ACCESSED_BY_ABSOLUTE_PATHS,
ILL_FORMED_ATTRIBUTE_INPUT,
CONFLICTING_REPR_HINTS,
META_VARIABLE_MISUSE,
DEPRECATED_IN_FUTURE,
AMBIGUOUS_ASSOCIATED_ITEMS,
Expand Down
2 changes: 2 additions & 0 deletions src/test/ui/conflicting-repr-hints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ enum B {
}

#[repr(C, u64)] //~ ERROR conflicting representation hints
//~^ WARN this was previously accepted
enum C {
C,
}

#[repr(u32, u64)] //~ ERROR conflicting representation hints
//~^ WARN this was previously accepted
enum D {
D,
}
Expand Down
25 changes: 16 additions & 9 deletions src/test/ui/conflicting-repr-hints.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,52 @@ error[E0566]: conflicting representation hints
|
LL | #[repr(C, u64)]
| ^ ^^^
|
= note: `#[deny(conflicting_repr_hints)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #68585 <https://github.com/rust-lang/rust/issues/68585>

error[E0566]: conflicting representation hints
--> $DIR/conflicting-repr-hints.rs:18:8
--> $DIR/conflicting-repr-hints.rs:19:8
|
LL | #[repr(u32, u64)]
| ^^^ ^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #68585 <https://github.com/rust-lang/rust/issues/68585>

error[E0587]: type has conflicting packed and align representation hints
--> $DIR/conflicting-repr-hints.rs:27:1
--> $DIR/conflicting-repr-hints.rs:29:1
|
LL | struct F(i32);
| ^^^^^^^^^^^^^^

error[E0587]: type has conflicting packed and align representation hints
--> $DIR/conflicting-repr-hints.rs:31:1
--> $DIR/conflicting-repr-hints.rs:33:1
|
LL | struct G(i32);
| ^^^^^^^^^^^^^^

error[E0587]: type has conflicting packed and align representation hints
--> $DIR/conflicting-repr-hints.rs:35:1
--> $DIR/conflicting-repr-hints.rs:37:1
|
LL | struct H(i32);
| ^^^^^^^^^^^^^^

error[E0634]: type has conflicting packed representation hints
--> $DIR/conflicting-repr-hints.rs:38:1
--> $DIR/conflicting-repr-hints.rs:40:1
|
LL | struct I(i32);
| ^^^^^^^^^^^^^^

error[E0634]: type has conflicting packed representation hints
--> $DIR/conflicting-repr-hints.rs:42:1
--> $DIR/conflicting-repr-hints.rs:44:1
|
LL | struct J(i32);
| ^^^^^^^^^^^^^^

error[E0587]: type has conflicting packed and align representation hints
--> $DIR/conflicting-repr-hints.rs:48:1
--> $DIR/conflicting-repr-hints.rs:50:1
|
LL | / union X {
LL | |
Expand All @@ -50,7 +57,7 @@ LL | | }
| |_^

error[E0587]: type has conflicting packed and align representation hints
--> $DIR/conflicting-repr-hints.rs:55:1
--> $DIR/conflicting-repr-hints.rs:57:1
|
LL | / union Y {
LL | |
Expand All @@ -59,7 +66,7 @@ LL | | }
| |_^

error[E0587]: type has conflicting packed and align representation hints
--> $DIR/conflicting-repr-hints.rs:62:1
--> $DIR/conflicting-repr-hints.rs:64:1
|
LL | / union Z {
LL | |
Expand Down
1 change: 1 addition & 0 deletions src/test/ui/feature-gates/feature-gate-repr-simd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
struct Foo(u64, u64);

#[repr(C)] //~ ERROR conflicting representation hints
//~^ WARN this was previously accepted
#[repr(simd)] //~ error: SIMD types are experimental
struct Bar(u64, u64);

Expand Down
7 changes: 6 additions & 1 deletion src/test/ui/feature-gates/feature-gate-repr-simd.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ LL | #[repr(simd)]
= help: add `#![feature(repr_simd)]` to the crate attributes to enable

error[E0658]: SIMD types are experimental and possibly buggy
--> $DIR/feature-gate-repr-simd.rs:5:1
--> $DIR/feature-gate-repr-simd.rs:6:1
|
LL | #[repr(simd)]
| ^^^^^^^^^^^^^
Expand All @@ -21,8 +21,13 @@ error[E0566]: conflicting representation hints
|
LL | #[repr(C)]
| ^
LL |
LL | #[repr(simd)]
| ^^^^
|
= note: `#[deny(conflicting_repr_hints)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #68585 <https://github.com/rust-lang/rust/issues/68585>

error: aborting due to 3 previous errors

Expand Down
2 changes: 2 additions & 0 deletions src/test/ui/issues/issue-47094.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#[repr(C, u8)] //~ ERROR conflicting representation hints
//~^ WARN this was previously accepted
enum Foo {
A,
B,
}

#[repr(C)] //~ ERROR conflicting representation hints
//~^ WARN this was previously accepted
#[repr(u8)]
enum Bar {
A,
Expand Down
10 changes: 9 additions & 1 deletion src/test/ui/issues/issue-47094.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,22 @@ error[E0566]: conflicting representation hints
|
LL | #[repr(C, u8)]
| ^ ^^
|
= note: `#[deny(conflicting_repr_hints)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #68585 <https://github.com/rust-lang/rust/issues/68585>

error[E0566]: conflicting representation hints
--> $DIR/issue-47094.rs:7:8
--> $DIR/issue-47094.rs:8:8
|
LL | #[repr(C)]
| ^
LL |
LL | #[repr(u8)]
| ^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #68585 <https://github.com/rust-lang/rust/issues/68585>

error: aborting due to 2 previous errors

Expand Down

0 comments on commit cdcf45b

Please sign in to comment.