Skip to content

Commit eb4860c

Browse files
authored
Rollup merge of rust-lang#60186 - estebank:accept-suffix, r=nikomatsakis
Temporarily accept [i|u][32|size] suffixes on a tuple index and warn Fix rust-lang#60138. rust-lang#59553 will need to be kept open to track the change back to rejecting this code a few versions down thee line.
2 parents 31a5371 + 4c01573 commit eb4860c

File tree

1 file changed

+31
-3
lines changed

1 file changed

+31
-3
lines changed

src/libsyntax/parse/parser.rs

+31-3
Original file line numberDiff line numberDiff line change
@@ -1145,9 +1145,34 @@ impl<'a> Parser<'a> {
11451145
if text.is_empty() {
11461146
self.span_bug(sp, "found empty literal suffix in Some")
11471147
}
1148-
self.struct_span_err(sp, &format!("suffixes on {} are invalid", kind))
1149-
.span_label(sp, format!("invalid suffix `{}`", text))
1150-
.emit();
1148+
let mut err = if kind == "a tuple index" &&
1149+
["i32", "u32", "isize", "usize"].contains(&text.to_string().as_str())
1150+
{
1151+
// #59553: warn instead of reject out of hand to allow the fix to percolate
1152+
// through the ecosystem when people fix their macros
1153+
let mut err = self.struct_span_warn(
1154+
sp,
1155+
&format!("suffixes on {} are invalid", kind),
1156+
);
1157+
err.note(&format!(
1158+
"`{}` is *temporarily* accepted on tuple index fields as it was \
1159+
incorrectly accepted on stable for a few releases",
1160+
text,
1161+
));
1162+
err.help(
1163+
"on proc macros, you'll want to use `syn::Index::from` or \
1164+
`proc_macro::Literal::*_unsuffixed` for code that will desugar \
1165+
to tuple field access",
1166+
);
1167+
err.note(
1168+
"for more context, see https://github.com/rust-lang/rust/issues/60210",
1169+
);
1170+
err
1171+
} else {
1172+
self.struct_span_err(sp, &format!("suffixes on {} are invalid", kind))
1173+
};
1174+
err.span_label(sp, format!("invalid suffix `{}`", text));
1175+
err.emit();
11511176
}
11521177
}
11531178
}
@@ -1455,6 +1480,9 @@ impl<'a> Parser<'a> {
14551480
fn struct_span_err<S: Into<MultiSpan>>(&self, sp: S, m: &str) -> DiagnosticBuilder<'a> {
14561481
self.sess.span_diagnostic.struct_span_err(sp, m)
14571482
}
1483+
fn struct_span_warn<S: Into<MultiSpan>>(&self, sp: S, m: &str) -> DiagnosticBuilder<'a> {
1484+
self.sess.span_diagnostic.struct_span_warn(sp, m)
1485+
}
14581486
crate fn span_bug<S: Into<MultiSpan>>(&self, sp: S, m: &str) -> ! {
14591487
self.sess.span_diagnostic.span_bug(sp, m)
14601488
}

0 commit comments

Comments
 (0)