Skip to content

Commit 8f1857a

Browse files
authored
Rollup merge of rust-lang#68586 - Centril:repr-deny, r=pnkfelix
Make conflicting_repr_hints a deny-by-default c-future-compat lint Closes rust-lang#68428. cc rust-lang#68585. r? @petrochenkov @pnkfelix
2 parents 36fd7b9 + 979f5b4 commit 8f1857a

8 files changed

+59
-20
lines changed

src/librustc/hir/check_attr.rs

+12-9
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use rustc_hir::def_id::DefId;
1414
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
1515
use rustc_hir::DUMMY_HIR_ID;
1616
use rustc_hir::{self, HirId, Item, ItemKind, TraitItem, TraitItemKind};
17-
use rustc_session::lint::builtin::UNUSED_ATTRIBUTES;
17+
use rustc_session::lint::builtin::{CONFLICTING_REPR_HINTS, UNUSED_ATTRIBUTES};
1818
use rustc_span::symbol::sym;
1919
use rustc_span::Span;
2020
use syntax::ast::Attribute;
@@ -196,7 +196,7 @@ impl CheckAttrVisitor<'tcx> {
196196
self.tcx.codegen_fn_attrs(self.tcx.hir().local_def_id(hir_id));
197197
}
198198

199-
self.check_repr(attrs, span, target, item);
199+
self.check_repr(attrs, span, target, item, hir_id);
200200
self.check_used(attrs, target);
201201
}
202202

@@ -357,6 +357,7 @@ impl CheckAttrVisitor<'tcx> {
357357
span: &Span,
358358
target: Target,
359359
item: Option<&Item<'_>>,
360+
hir_id: HirId,
360361
) {
361362
// Extract the names of all repr hints, e.g., [foo, bar, align] for:
362363
// ```
@@ -446,13 +447,15 @@ impl CheckAttrVisitor<'tcx> {
446447
|| (is_simd && is_c)
447448
|| (int_reprs == 1 && is_c && item.map_or(false, |item| is_c_like_enum(item)))
448449
{
449-
struct_span_err!(
450-
self.tcx.sess,
451-
hint_spans.collect::<Vec<Span>>(),
452-
E0566,
453-
"conflicting representation hints",
454-
)
455-
.emit();
450+
self.tcx
451+
.struct_span_lint_hir(
452+
CONFLICTING_REPR_HINTS,
453+
hir_id,
454+
hint_spans.collect::<Vec<Span>>(),
455+
"conflicting representation hints",
456+
)
457+
.code(rustc_errors::error_code!(E0566))
458+
.emit();
456459
}
457460
}
458461

src/librustc_session/lint/builtin.rs

+11
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@ declare_lint! {
1818
};
1919
}
2020

21+
declare_lint! {
22+
pub CONFLICTING_REPR_HINTS,
23+
Deny,
24+
"conflicts between `#[repr(..)]` hints that were previously accepted and used in practice",
25+
@future_incompatible = FutureIncompatibleInfo {
26+
reference: "issue #68585 <https://github.com/rust-lang/rust/issues/68585>",
27+
edition: None,
28+
};
29+
}
30+
2131
declare_lint! {
2232
pub META_VARIABLE_MISUSE,
2333
Allow,
@@ -520,6 +530,7 @@ declare_lint_pass! {
520530
MACRO_USE_EXTERN_CRATE,
521531
MACRO_EXPANDED_MACRO_EXPORTS_ACCESSED_BY_ABSOLUTE_PATHS,
522532
ILL_FORMED_ATTRIBUTE_INPUT,
533+
CONFLICTING_REPR_HINTS,
523534
META_VARIABLE_MISUSE,
524535
DEPRECATED_IN_FUTURE,
525536
AMBIGUOUS_ASSOCIATED_ITEMS,

src/test/ui/conflicting-repr-hints.rs

+2
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ enum B {
1111
}
1212

1313
#[repr(C, u64)] //~ ERROR conflicting representation hints
14+
//~^ WARN this was previously accepted
1415
enum C {
1516
C,
1617
}
1718

1819
#[repr(u32, u64)] //~ ERROR conflicting representation hints
20+
//~^ WARN this was previously accepted
1921
enum D {
2022
D,
2123
}

src/test/ui/conflicting-repr-hints.stderr

+16-9
Original file line numberDiff line numberDiff line change
@@ -3,45 +3,52 @@ error[E0566]: conflicting representation hints
33
|
44
LL | #[repr(C, u64)]
55
| ^ ^^^
6+
|
7+
= note: `#[deny(conflicting_repr_hints)]` on by default
8+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
9+
= note: for more information, see issue #68585 <https://github.com/rust-lang/rust/issues/68585>
610

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

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

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

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

3138
error[E0634]: type has conflicting packed representation hints
32-
--> $DIR/conflicting-repr-hints.rs:38:1
39+
--> $DIR/conflicting-repr-hints.rs:40:1
3340
|
3441
LL | struct I(i32);
3542
| ^^^^^^^^^^^^^^
3643

3744
error[E0634]: type has conflicting packed representation hints
38-
--> $DIR/conflicting-repr-hints.rs:42:1
45+
--> $DIR/conflicting-repr-hints.rs:44:1
3946
|
4047
LL | struct J(i32);
4148
| ^^^^^^^^^^^^^^
4249

4350
error[E0587]: type has conflicting packed and align representation hints
44-
--> $DIR/conflicting-repr-hints.rs:48:1
51+
--> $DIR/conflicting-repr-hints.rs:50:1
4552
|
4653
LL | / union X {
4754
LL | |
@@ -50,7 +57,7 @@ LL | | }
5057
| |_^
5158

5259
error[E0587]: type has conflicting packed and align representation hints
53-
--> $DIR/conflicting-repr-hints.rs:55:1
60+
--> $DIR/conflicting-repr-hints.rs:57:1
5461
|
5562
LL | / union Y {
5663
LL | |
@@ -59,7 +66,7 @@ LL | | }
5966
| |_^
6067

6168
error[E0587]: type has conflicting packed and align representation hints
62-
--> $DIR/conflicting-repr-hints.rs:62:1
69+
--> $DIR/conflicting-repr-hints.rs:64:1
6370
|
6471
LL | / union Z {
6572
LL | |

src/test/ui/feature-gates/feature-gate-repr-simd.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
struct Foo(u64, u64);
33

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

src/test/ui/feature-gates/feature-gate-repr-simd.stderr

+6-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ LL | #[repr(simd)]
88
= help: add `#![feature(repr_simd)]` to the crate attributes to enable
99

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

2732
error: aborting due to 3 previous errors
2833

src/test/ui/issues/issue-47094.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
#[repr(C, u8)] //~ ERROR conflicting representation hints
2+
//~^ WARN this was previously accepted
23
enum Foo {
34
A,
45
B,
56
}
67

78
#[repr(C)] //~ ERROR conflicting representation hints
9+
//~^ WARN this was previously accepted
810
#[repr(u8)]
911
enum Bar {
1012
A,

src/test/ui/issues/issue-47094.stderr

+9-1
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,22 @@ error[E0566]: conflicting representation hints
33
|
44
LL | #[repr(C, u8)]
55
| ^ ^^
6+
|
7+
= note: `#[deny(conflicting_repr_hints)]` on by default
8+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
9+
= note: for more information, see issue #68585 <https://github.com/rust-lang/rust/issues/68585>
610

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

1523
error: aborting due to 2 previous errors
1624

0 commit comments

Comments
 (0)