Skip to content

Commit da507c3

Browse files
committed
Turn invalid index suffixes into hard errors
1 parent 70a5591 commit da507c3

File tree

7 files changed

+75
-140
lines changed

7 files changed

+75
-140
lines changed

compiler/rustc_parse/messages.ftl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -473,9 +473,6 @@ parse_invalid_label =
473473
474474
parse_invalid_literal_suffix_on_tuple_index = suffixes on a tuple index are invalid
475475
.label = invalid suffix `{$suffix}`
476-
.tuple_exception_line_1 = `{$suffix}` is *temporarily* accepted on tuple index fields as it was incorrectly accepted on stable for a few releases
477-
.tuple_exception_line_2 = on proc macros, you'll want to use `syn::Index::from` or `proc_macro::Literal::*_unsuffixed` for code that will desugar to tuple field access
478-
.tuple_exception_line_3 = see issue #60210 <https://github.com/rust-lang/rust/issues/60210> for more information
479476
480477
parse_invalid_logical_operator = `{$incorrect}` is not a logical operator
481478
.note = unlike in e.g., Python and PHP, `&&` and `||` are used for logical operators

compiler/rustc_parse/src/errors.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,10 +1016,6 @@ pub(crate) struct InvalidLiteralSuffixOnTupleIndex {
10161016
#[label]
10171017
pub span: Span,
10181018
pub suffix: Symbol,
1019-
#[help(parse_tuple_exception_line_1)]
1020-
#[help(parse_tuple_exception_line_2)]
1021-
#[help(parse_tuple_exception_line_3)]
1022-
pub exception: bool,
10231019
}
10241020

10251021
#[derive(Diagnostic)]

compiler/rustc_parse/src/parser/expr.rs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2226,21 +2226,7 @@ impl<'a> Parser<'a> {
22262226
}
22272227

22282228
pub(super) fn expect_no_tuple_index_suffix(&self, span: Span, suffix: Symbol) {
2229-
if [sym::i32, sym::u32, sym::isize, sym::usize].contains(&suffix) {
2230-
// #59553: warn instead of reject out of hand to allow the fix to percolate
2231-
// through the ecosystem when people fix their macros
2232-
self.dcx().emit_warn(errors::InvalidLiteralSuffixOnTupleIndex {
2233-
span,
2234-
suffix,
2235-
exception: true,
2236-
});
2237-
} else {
2238-
self.dcx().emit_err(errors::InvalidLiteralSuffixOnTupleIndex {
2239-
span,
2240-
suffix,
2241-
exception: false,
2242-
});
2243-
}
2229+
self.dcx().emit_err(errors::InvalidLiteralSuffixOnTupleIndex { span, suffix });
22442230
}
22452231

22462232
/// Matches `'-' lit | lit` (cf. `ast_validation::AstValidator::check_expr_within_pat`).

tests/ui/parser/tuple-index-suffix-proc-macro.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@ fn main() {
1111
struct TupStruct(i32);
1212
let tup_struct = TupStruct(42);
1313

14-
// #60186 carve outs `{i,u}{32,usize}` as non-lint pseudo-FCW warnings.
14+
// Previously, #60186 had carve outs for `{i,u}{32,usize}` as non-lint pseudo-FCW warnings. Now,
15+
// they all hard error.
1516

1617
aux::bad_tup_indexing!(0usize);
17-
//~^ WARN suffixes on a tuple index are invalid
18+
//~^ ERROR suffixes on a tuple index are invalid
1819
aux::bad_tup_struct_indexing!(tup_struct, 0isize);
19-
//~^ WARN suffixes on a tuple index are invalid
20+
//~^ ERROR suffixes on a tuple index are invalid
2021

2122
// Not part of the #60186 carve outs.
2223

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,26 @@
1-
warning: suffixes on a tuple index are invalid
2-
--> $DIR/tuple-index-suffix-proc-macro.rs:16:28
1+
error: suffixes on a tuple index are invalid
2+
--> $DIR/tuple-index-suffix-proc-macro.rs:17:28
33
|
44
LL | aux::bad_tup_indexing!(0usize);
55
| ^^^^^^ invalid suffix `usize`
6-
|
7-
= help: `usize` is *temporarily* accepted on tuple index fields as it was incorrectly accepted on stable for a few releases
8-
= help: on proc macros, you'll want to use `syn::Index::from` or `proc_macro::Literal::*_unsuffixed` for code that will desugar to tuple field access
9-
= help: see issue #60210 <https://github.com/rust-lang/rust/issues/60210> for more information
106

11-
warning: suffixes on a tuple index are invalid
12-
--> $DIR/tuple-index-suffix-proc-macro.rs:18:47
7+
error: suffixes on a tuple index are invalid
8+
--> $DIR/tuple-index-suffix-proc-macro.rs:19:47
139
|
1410
LL | aux::bad_tup_struct_indexing!(tup_struct, 0isize);
1511
| ^^^^^^ invalid suffix `isize`
16-
|
17-
= help: `isize` is *temporarily* accepted on tuple index fields as it was incorrectly accepted on stable for a few releases
18-
= help: on proc macros, you'll want to use `syn::Index::from` or `proc_macro::Literal::*_unsuffixed` for code that will desugar to tuple field access
19-
= help: see issue #60210 <https://github.com/rust-lang/rust/issues/60210> for more information
2012

2113
error: suffixes on a tuple index are invalid
22-
--> $DIR/tuple-index-suffix-proc-macro.rs:23:28
14+
--> $DIR/tuple-index-suffix-proc-macro.rs:24:28
2315
|
2416
LL | aux::bad_tup_indexing!(0u8);
2517
| ^^^ invalid suffix `u8`
2618

2719
error: suffixes on a tuple index are invalid
28-
--> $DIR/tuple-index-suffix-proc-macro.rs:25:47
20+
--> $DIR/tuple-index-suffix-proc-macro.rs:26:47
2921
|
3022
LL | aux::bad_tup_struct_indexing!(tup_struct, 0u64);
3123
| ^^^^ invalid suffix `u64`
3224

33-
error: aborting due to 2 previous errors; 2 warnings emitted
25+
error: aborting due to 4 previous errors
3426

tests/ui/parser/tuple-index-suffix.rs

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,36 @@
11
//! See #60210.
22
//!
33
//! Check that we hard error on invalid suffixes in tuple indexing subexpressions and struct numeral
4-
//! field names, modulo carve-outs for `{i,u}{32,usize}` at warning level to mitigate ecosystem
5-
//! impact.
4+
//! field names.
65
76
struct X(i32,i32,i32);
87

98
fn main() {
109
let tup_struct = X(1, 2, 3);
1110
let invalid_tup_struct_suffix = tup_struct.0suffix;
1211
//~^ ERROR suffixes on a tuple index are invalid
13-
let carve_out_tup_struct_suffix = tup_struct.0i32;
14-
//~^ WARN suffixes on a tuple index are invalid
12+
let previous_carve_out_tup_struct_suffix = tup_struct.0i32;
13+
//~^ ERROR suffixes on a tuple index are invalid
1514

1615
let tup = (1, 2, 3);
1716
let invalid_tup_suffix = tup.0suffix;
1817
//~^ ERROR suffixes on a tuple index are invalid
19-
let carve_out_tup_suffix = tup.0u32;
20-
//~^ WARN suffixes on a tuple index are invalid
18+
let previous_carve_out_tup_suffix = tup.0u32;
19+
//~^ ERROR suffixes on a tuple index are invalid
2120

2221
numeral_struct_field_name_suffix_invalid();
23-
numeral_struct_field_name_suffix_carve_out();
22+
numeral_struct_field_name_suffix_previous_carve_out();
2423
}
2524

26-
// Very limited carve outs as a ecosystem impact mitigation implemented in #60186. *Only*
27-
// `{i,u}{32,usize}` suffixes are temporarily accepted.
28-
fn carve_outs() {
29-
// Ok, only pseudo-FCW warnings.
25+
// Previously, there were very limited carve outs as a ecosystem impact mitigation implemented in
26+
// #60186. *Only* `{i,u}{32,usize}` suffixes were temporarily accepted. Now, they all hard error.
27+
fn previous_carve_outs() {
28+
// Previously temporarily accepted by a pseudo-FCW, now hard error.
3029

31-
let carve_out_i32 = (42,).0i32; //~ WARN suffixes on a tuple index are invalid
32-
let carve_out_i32 = (42,).0u32; //~ WARN suffixes on a tuple index are invalid
33-
let carve_out_isize = (42,).0isize; //~ WARN suffixes on a tuple index are invalid
34-
let carve_out_usize = (42,).0usize; //~ WARN suffixes on a tuple index are invalid
30+
let previous_carve_out_i32 = (42,).0i32; //~ ERROR suffixes on a tuple index are invalid
31+
let previous_carve_out_i32 = (42,).0u32; //~ ERROR suffixes on a tuple index are invalid
32+
let previous_carve_out_isize = (42,).0isize; //~ ERROR suffixes on a tuple index are invalid
33+
let previous_carve_out_usize = (42,).0usize; //~ ERROR suffixes on a tuple index are invalid
3534

3635
// Not part of the carve outs!
3736
let error_i8 = (42,).0i8; //~ ERROR suffixes on a tuple index are invalid
@@ -53,12 +52,12 @@ fn numeral_struct_field_name_suffix_invalid() {
5352
}
5453
}
5554

56-
fn numeral_struct_field_name_suffix_carve_out() {
55+
fn numeral_struct_field_name_suffix_previous_carve_out() {
5756
let carve_out_struct_name = X { 0u32: 0, 1: 1, 2: 2 };
58-
//~^ WARN suffixes on a tuple index are invalid
57+
//~^ ERROR suffixes on a tuple index are invalid
5958
match carve_out_struct_name {
6059
X { 0u32: _, .. } => {}
61-
//~^ WARN suffixes on a tuple index are invalid
60+
//~^ ERROR suffixes on a tuple index are invalid
6261
}
6362
}
6463

@@ -67,9 +66,9 @@ fn offset_of_suffix() {
6766
#[repr(C)]
6867
pub struct Struct<T>(u8, T);
6968

70-
// Carve outs
69+
// Previous pseudo-FCW carve outs
7170
assert_eq!(std::mem::offset_of!(Struct<u32>, 0usize), 0);
72-
//~^ WARN suffixes on a tuple index are invalid
71+
//~^ ERROR suffixes on a tuple index are invalid
7372

7473
// Not part of carve outs
7574
assert_eq!(std::mem::offset_of!(Struct<u32>, 0u8), 0);
Lines changed: 44 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,170 +1,134 @@
11
error: suffixes on a tuple index are invalid
2-
--> $DIR/tuple-index-suffix.rs:11:48
2+
--> $DIR/tuple-index-suffix.rs:10:48
33
|
44
LL | let invalid_tup_struct_suffix = tup_struct.0suffix;
55
| ^^^^^^^ invalid suffix `suffix`
66

7-
warning: suffixes on a tuple index are invalid
8-
--> $DIR/tuple-index-suffix.rs:13:50
9-
|
10-
LL | let carve_out_tup_struct_suffix = tup_struct.0i32;
11-
| ^^^^ invalid suffix `i32`
7+
error: suffixes on a tuple index are invalid
8+
--> $DIR/tuple-index-suffix.rs:12:59
129
|
13-
= help: `i32` is *temporarily* accepted on tuple index fields as it was incorrectly accepted on stable for a few releases
14-
= help: on proc macros, you'll want to use `syn::Index::from` or `proc_macro::Literal::*_unsuffixed` for code that will desugar to tuple field access
15-
= help: see issue #60210 <https://github.com/rust-lang/rust/issues/60210> for more information
10+
LL | let previous_carve_out_tup_struct_suffix = tup_struct.0i32;
11+
| ^^^^ invalid suffix `i32`
1612

1713
error: suffixes on a tuple index are invalid
18-
--> $DIR/tuple-index-suffix.rs:17:34
14+
--> $DIR/tuple-index-suffix.rs:16:34
1915
|
2016
LL | let invalid_tup_suffix = tup.0suffix;
2117
| ^^^^^^^ invalid suffix `suffix`
2218

23-
warning: suffixes on a tuple index are invalid
24-
--> $DIR/tuple-index-suffix.rs:19:36
25-
|
26-
LL | let carve_out_tup_suffix = tup.0u32;
27-
| ^^^^ invalid suffix `u32`
19+
error: suffixes on a tuple index are invalid
20+
--> $DIR/tuple-index-suffix.rs:18:45
2821
|
29-
= help: `u32` is *temporarily* accepted on tuple index fields as it was incorrectly accepted on stable for a few releases
30-
= help: on proc macros, you'll want to use `syn::Index::from` or `proc_macro::Literal::*_unsuffixed` for code that will desugar to tuple field access
31-
= help: see issue #60210 <https://github.com/rust-lang/rust/issues/60210> for more information
22+
LL | let previous_carve_out_tup_suffix = tup.0u32;
23+
| ^^^^ invalid suffix `u32`
3224

33-
warning: suffixes on a tuple index are invalid
34-
--> $DIR/tuple-index-suffix.rs:31:31
35-
|
36-
LL | let carve_out_i32 = (42,).0i32;
37-
| ^^^^ invalid suffix `i32`
25+
error: suffixes on a tuple index are invalid
26+
--> $DIR/tuple-index-suffix.rs:30:40
3827
|
39-
= help: `i32` is *temporarily* accepted on tuple index fields as it was incorrectly accepted on stable for a few releases
40-
= help: on proc macros, you'll want to use `syn::Index::from` or `proc_macro::Literal::*_unsuffixed` for code that will desugar to tuple field access
41-
= help: see issue #60210 <https://github.com/rust-lang/rust/issues/60210> for more information
28+
LL | let previous_carve_out_i32 = (42,).0i32;
29+
| ^^^^ invalid suffix `i32`
4230

43-
warning: suffixes on a tuple index are invalid
44-
--> $DIR/tuple-index-suffix.rs:32:31
45-
|
46-
LL | let carve_out_i32 = (42,).0u32;
47-
| ^^^^ invalid suffix `u32`
31+
error: suffixes on a tuple index are invalid
32+
--> $DIR/tuple-index-suffix.rs:31:40
4833
|
49-
= help: `u32` is *temporarily* accepted on tuple index fields as it was incorrectly accepted on stable for a few releases
50-
= help: on proc macros, you'll want to use `syn::Index::from` or `proc_macro::Literal::*_unsuffixed` for code that will desugar to tuple field access
51-
= help: see issue #60210 <https://github.com/rust-lang/rust/issues/60210> for more information
34+
LL | let previous_carve_out_i32 = (42,).0u32;
35+
| ^^^^ invalid suffix `u32`
5236

53-
warning: suffixes on a tuple index are invalid
54-
--> $DIR/tuple-index-suffix.rs:33:33
55-
|
56-
LL | let carve_out_isize = (42,).0isize;
57-
| ^^^^^^ invalid suffix `isize`
37+
error: suffixes on a tuple index are invalid
38+
--> $DIR/tuple-index-suffix.rs:32:42
5839
|
59-
= help: `isize` is *temporarily* accepted on tuple index fields as it was incorrectly accepted on stable for a few releases
60-
= help: on proc macros, you'll want to use `syn::Index::from` or `proc_macro::Literal::*_unsuffixed` for code that will desugar to tuple field access
61-
= help: see issue #60210 <https://github.com/rust-lang/rust/issues/60210> for more information
40+
LL | let previous_carve_out_isize = (42,).0isize;
41+
| ^^^^^^ invalid suffix `isize`
6242

63-
warning: suffixes on a tuple index are invalid
64-
--> $DIR/tuple-index-suffix.rs:34:33
65-
|
66-
LL | let carve_out_usize = (42,).0usize;
67-
| ^^^^^^ invalid suffix `usize`
43+
error: suffixes on a tuple index are invalid
44+
--> $DIR/tuple-index-suffix.rs:33:42
6845
|
69-
= help: `usize` is *temporarily* accepted on tuple index fields as it was incorrectly accepted on stable for a few releases
70-
= help: on proc macros, you'll want to use `syn::Index::from` or `proc_macro::Literal::*_unsuffixed` for code that will desugar to tuple field access
71-
= help: see issue #60210 <https://github.com/rust-lang/rust/issues/60210> for more information
46+
LL | let previous_carve_out_usize = (42,).0usize;
47+
| ^^^^^^ invalid suffix `usize`
7248

7349
error: suffixes on a tuple index are invalid
74-
--> $DIR/tuple-index-suffix.rs:37:26
50+
--> $DIR/tuple-index-suffix.rs:36:26
7551
|
7652
LL | let error_i8 = (42,).0i8;
7753
| ^^^ invalid suffix `i8`
7854

7955
error: suffixes on a tuple index are invalid
80-
--> $DIR/tuple-index-suffix.rs:38:26
56+
--> $DIR/tuple-index-suffix.rs:37:26
8157
|
8258
LL | let error_u8 = (42,).0u8;
8359
| ^^^ invalid suffix `u8`
8460

8561
error: suffixes on a tuple index are invalid
86-
--> $DIR/tuple-index-suffix.rs:39:27
62+
--> $DIR/tuple-index-suffix.rs:38:27
8763
|
8864
LL | let error_i16 = (42,).0i16;
8965
| ^^^^ invalid suffix `i16`
9066

9167
error: suffixes on a tuple index are invalid
92-
--> $DIR/tuple-index-suffix.rs:40:27
68+
--> $DIR/tuple-index-suffix.rs:39:27
9369
|
9470
LL | let error_u16 = (42,).0u16;
9571
| ^^^^ invalid suffix `u16`
9672

9773
error: suffixes on a tuple index are invalid
98-
--> $DIR/tuple-index-suffix.rs:41:27
74+
--> $DIR/tuple-index-suffix.rs:40:27
9975
|
10076
LL | let error_i64 = (42,).0i64;
10177
| ^^^^ invalid suffix `i64`
10278

10379
error: suffixes on a tuple index are invalid
104-
--> $DIR/tuple-index-suffix.rs:42:27
80+
--> $DIR/tuple-index-suffix.rs:41:27
10581
|
10682
LL | let error_u64 = (42,).0u64;
10783
| ^^^^ invalid suffix `u64`
10884

10985
error: suffixes on a tuple index are invalid
110-
--> $DIR/tuple-index-suffix.rs:43:28
86+
--> $DIR/tuple-index-suffix.rs:42:28
11187
|
11288
LL | let error_i128 = (42,).0i128;
11389
| ^^^^^ invalid suffix `i128`
11490

11591
error: suffixes on a tuple index are invalid
116-
--> $DIR/tuple-index-suffix.rs:44:28
92+
--> $DIR/tuple-index-suffix.rs:43:28
11793
|
11894
LL | let error_u128 = (42,).0u128;
11995
| ^^^^^ invalid suffix `u128`
12096

12197
error: suffixes on a tuple index are invalid
122-
--> $DIR/tuple-index-suffix.rs:48:35
98+
--> $DIR/tuple-index-suffix.rs:47:35
12399
|
124100
LL | let invalid_struct_name = X { 0suffix: 0, 1: 1, 2: 2 };
125101
| ^^^^^^^ invalid suffix `suffix`
126102

127103
error: suffixes on a tuple index are invalid
128-
--> $DIR/tuple-index-suffix.rs:51:13
104+
--> $DIR/tuple-index-suffix.rs:50:13
129105
|
130106
LL | X { 0suffix: _, .. } => {}
131107
| ^^^^^^^ invalid suffix `suffix`
132108

133-
warning: suffixes on a tuple index are invalid
134-
--> $DIR/tuple-index-suffix.rs:57:37
109+
error: suffixes on a tuple index are invalid
110+
--> $DIR/tuple-index-suffix.rs:56:37
135111
|
136112
LL | let carve_out_struct_name = X { 0u32: 0, 1: 1, 2: 2 };
137113
| ^^^^ invalid suffix `u32`
138-
|
139-
= help: `u32` is *temporarily* accepted on tuple index fields as it was incorrectly accepted on stable for a few releases
140-
= help: on proc macros, you'll want to use `syn::Index::from` or `proc_macro::Literal::*_unsuffixed` for code that will desugar to tuple field access
141-
= help: see issue #60210 <https://github.com/rust-lang/rust/issues/60210> for more information
142114

143-
warning: suffixes on a tuple index are invalid
144-
--> $DIR/tuple-index-suffix.rs:60:13
115+
error: suffixes on a tuple index are invalid
116+
--> $DIR/tuple-index-suffix.rs:59:13
145117
|
146118
LL | X { 0u32: _, .. } => {}
147119
| ^^^^ invalid suffix `u32`
148-
|
149-
= help: `u32` is *temporarily* accepted on tuple index fields as it was incorrectly accepted on stable for a few releases
150-
= help: on proc macros, you'll want to use `syn::Index::from` or `proc_macro::Literal::*_unsuffixed` for code that will desugar to tuple field access
151-
= help: see issue #60210 <https://github.com/rust-lang/rust/issues/60210> for more information
152120

153-
warning: suffixes on a tuple index are invalid
154-
--> $DIR/tuple-index-suffix.rs:71:50
121+
error: suffixes on a tuple index are invalid
122+
--> $DIR/tuple-index-suffix.rs:70:50
155123
|
156124
LL | assert_eq!(std::mem::offset_of!(Struct<u32>, 0usize), 0);
157125
| ^^^^^^ invalid suffix `usize`
158-
|
159-
= help: `usize` is *temporarily* accepted on tuple index fields as it was incorrectly accepted on stable for a few releases
160-
= help: on proc macros, you'll want to use `syn::Index::from` or `proc_macro::Literal::*_unsuffixed` for code that will desugar to tuple field access
161-
= help: see issue #60210 <https://github.com/rust-lang/rust/issues/60210> for more information
162126

163127
error: suffixes on a tuple index are invalid
164-
--> $DIR/tuple-index-suffix.rs:75:50
128+
--> $DIR/tuple-index-suffix.rs:74:50
165129
|
166130
LL | assert_eq!(std::mem::offset_of!(Struct<u32>, 0u8), 0);
167131
| ^^^ invalid suffix `u8`
168132

169-
error: aborting due to 13 previous errors; 9 warnings emitted
133+
error: aborting due to 22 previous errors
170134

0 commit comments

Comments
 (0)