address review comments
This commit is contained in:
parent
30bb7045d6
commit
4970127c33
15 changed files with 30 additions and 35 deletions
|
|
@ -468,9 +468,6 @@ parse_invalid_dyn_keyword = invalid `dyn` keyword
|
|||
parse_invalid_expression_in_let_else = a `{$operator}` expression cannot be directly assigned in `let...else`
|
||||
parse_invalid_identifier_with_leading_number = identifiers cannot start with a number
|
||||
|
||||
parse_invalid_label =
|
||||
invalid label name `{$name}`
|
||||
|
||||
parse_invalid_literal_suffix_on_tuple_index = suffixes on a tuple index are invalid
|
||||
.label = invalid suffix `{$suffix}`
|
||||
.tuple_exception_line_1 = `{$suffix}` is *temporarily* accepted on tuple index fields as it was incorrectly accepted on stable for a few releases
|
||||
|
|
@ -500,6 +497,8 @@ parse_invalid_unicode_escape = invalid unicode character escape
|
|||
parse_invalid_variable_declaration =
|
||||
invalid variable declaration
|
||||
|
||||
parse_keyword_label = labels cannot use keyword names
|
||||
|
||||
parse_keyword_lifetime =
|
||||
lifetimes cannot use keyword names
|
||||
|
||||
|
|
|
|||
|
|
@ -2228,11 +2228,10 @@ pub(crate) struct KeywordLifetime {
|
|||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(parse_invalid_label)]
|
||||
pub(crate) struct InvalidLabel {
|
||||
#[diag(parse_keyword_label)]
|
||||
pub(crate) struct KeywordLabel {
|
||||
#[primary_span]
|
||||
pub span: Span,
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
|
|
|
|||
|
|
@ -3094,13 +3094,7 @@ impl<'a> Parser<'a> {
|
|||
if let Some((ident, is_raw)) = self.token.lifetime() {
|
||||
// Disallow `'fn`, but with a better error message than `expect_lifetime`.
|
||||
if matches!(is_raw, IdentIsRaw::No) && ident.without_first_quote().is_reserved() {
|
||||
self.dcx().emit_err(errors::InvalidLabel {
|
||||
span: ident.span,
|
||||
// `IntoDiagArg` prints the symbol as if it was an ident,
|
||||
// so `'break` is printed as `r#break`. We don't want that
|
||||
// here so convert to string eagerly.
|
||||
name: ident.without_first_quote().name.to_string(),
|
||||
});
|
||||
self.dcx().emit_err(errors::KeywordLabel { span: ident.span });
|
||||
}
|
||||
|
||||
self.bump();
|
||||
|
|
|
|||
|
|
@ -1479,8 +1479,7 @@ impl<'a> Parser<'a> {
|
|||
pub(super) fn expect_lifetime(&mut self) -> Lifetime {
|
||||
if let Some((ident, is_raw)) = self.token.lifetime() {
|
||||
if matches!(is_raw, IdentIsRaw::No)
|
||||
&& ident.without_first_quote().is_reserved()
|
||||
&& ![kw::UnderscoreLifetime, kw::StaticLifetime].contains(&ident.name)
|
||||
&& ident.without_first_quote().is_reserved_lifetime()
|
||||
{
|
||||
self.dcx().emit_err(errors::KeywordLifetime { span: ident.span });
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3045,13 +3045,17 @@ impl Ident {
|
|||
self.name.can_be_raw() && self.is_reserved()
|
||||
}
|
||||
|
||||
/// Given the name of a lifetime without the first quote (`'`),
|
||||
/// returns whether the lifetime name is reserved (therefore invalid)
|
||||
pub fn is_reserved_lifetime(self) -> bool {
|
||||
self.is_reserved() && ![kw::Underscore, kw::Static].contains(&self.name)
|
||||
}
|
||||
|
||||
pub fn is_raw_lifetime_guess(self) -> bool {
|
||||
// this should be kept consistent with `Parser::expect_lifetime` found under
|
||||
// compiler/rustc_parse/src/parser/ty.rs
|
||||
let name_without_apostrophe = self.without_first_quote();
|
||||
name_without_apostrophe.name != self.name
|
||||
&& ![kw::UnderscoreLifetime, kw::StaticLifetime].contains(&self.name)
|
||||
&& name_without_apostrophe.is_raw_guess()
|
||||
&& name_without_apostrophe.name.can_be_raw()
|
||||
&& name_without_apostrophe.is_reserved_lifetime()
|
||||
}
|
||||
|
||||
pub fn guess_print_mode(self) -> IdentPrintMode {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
fn main() {
|
||||
[(); &(&'static: loop { |x| {}; }) as *const _ as usize]
|
||||
//~^ ERROR: invalid label name `static`
|
||||
//~^ ERROR: labels cannot use keyword names
|
||||
//~| ERROR: type annotations needed
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
error: invalid label name `static`
|
||||
error: labels cannot use keyword names
|
||||
--> $DIR/issue-52437.rs:2:13
|
||||
|
|
||||
LL | [(); &(&'static: loop { |x| {}; }) as *const _ as usize]
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
fn main() {
|
||||
'break: loop { //~ ERROR invalid label name `break`
|
||||
'break: loop { //~ ERROR labels cannot use keyword names
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
error: invalid label name `break`
|
||||
error: labels cannot use keyword names
|
||||
--> $DIR/issue-46311.rs:2:5
|
||||
|
|
||||
LL | 'break: loop {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
fn main() {
|
||||
'static: loop { //~ ERROR invalid label name `static`
|
||||
break 'static //~ ERROR invalid label name `static`
|
||||
'static: loop { //~ ERROR labels cannot use keyword names
|
||||
break 'static //~ ERROR labels cannot use keyword names
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
error: invalid label name `static`
|
||||
error: labels cannot use keyword names
|
||||
--> $DIR/label-static.rs:2:5
|
||||
|
|
||||
LL | 'static: loop {
|
||||
| ^^^^^^^
|
||||
|
||||
error: invalid label name `static`
|
||||
error: labels cannot use keyword names
|
||||
--> $DIR/label-static.rs:3:15
|
||||
|
|
||||
LL | break 'static
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
fn main() {
|
||||
'_: loop { //~ ERROR invalid label name `_`
|
||||
break '_ //~ ERROR invalid label name `_`
|
||||
'_: loop { //~ ERROR labels cannot use keyword names
|
||||
break '_ //~ ERROR labels cannot use keyword names
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
error: invalid label name `_`
|
||||
error: labels cannot use keyword names
|
||||
--> $DIR/label-underscore.rs:2:5
|
||||
|
|
||||
LL | '_: loop {
|
||||
| ^^
|
||||
|
||||
error: invalid label name `_`
|
||||
error: labels cannot use keyword names
|
||||
--> $DIR/label-underscore.rs:3:15
|
||||
|
|
||||
LL | break '_
|
||||
|
|
|
|||
|
|
@ -24,14 +24,14 @@ fn main() {
|
|||
//~| HELP use `::<...>` instead of `<...>` to specify lifetime, type, or const arguments
|
||||
//~| ERROR expected
|
||||
//~| HELP add `'` to close the char literal
|
||||
//~| ERROR invalid label name
|
||||
//~| ERROR labels cannot use keyword names
|
||||
|
||||
f<'_>();
|
||||
//~^ ERROR comparison operators cannot be chained
|
||||
//~| HELP use `::<...>` instead of `<...>` to specify lifetime, type, or const arguments
|
||||
//~| ERROR expected
|
||||
//~| HELP add `'` to close the char literal
|
||||
//~| ERROR invalid label name
|
||||
//~| ERROR labels cannot use keyword names
|
||||
|
||||
let _ = f<u8>;
|
||||
//~^ ERROR comparison operators cannot be chained
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ help: use `::<...>` instead of `<...>` to specify lifetime, type, or const argum
|
|||
LL | let _ = f::<u8, i8>();
|
||||
| ++
|
||||
|
||||
error: invalid label name `_`
|
||||
error: labels cannot use keyword names
|
||||
--> $DIR/require-parens-for-chained-comparison.rs:22:15
|
||||
|
|
||||
LL | let _ = f<'_, i8>();
|
||||
|
|
@ -81,7 +81,7 @@ help: use `::<...>` instead of `<...>` to specify lifetime, type, or const argum
|
|||
LL | let _ = f::<'_, i8>();
|
||||
| ++
|
||||
|
||||
error: invalid label name `_`
|
||||
error: labels cannot use keyword names
|
||||
--> $DIR/require-parens-for-chained-comparison.rs:29:7
|
||||
|
|
||||
LL | f<'_>();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue