Explain why Self
is invalid in generic parameters
This commit is contained in:
parent
d45ed7502a
commit
a72dd4a5b9
3 changed files with 35 additions and 13 deletions
|
@ -89,6 +89,19 @@ impl<'a> Parser<'a> {
|
|||
let attrs = self.parse_outer_attributes()?;
|
||||
let param =
|
||||
self.collect_tokens_trailing_token(attrs, ForceCollect::No, |this, attrs| {
|
||||
if this.eat_keyword_noexpect(kw::SelfUpper) {
|
||||
// `Self` as a generic param is invalid. Here we emit the diagnostic and continue parsing
|
||||
// as if `Self` never existed.
|
||||
this.struct_span_err(
|
||||
this.prev_token.span,
|
||||
"unexpected keyword `Self` in generic parameters",
|
||||
)
|
||||
.note("you cannot use `Self` as a generic parameter because it is reserved for associated items")
|
||||
.emit();
|
||||
|
||||
this.eat(&token::Comma);
|
||||
}
|
||||
|
||||
let param = if this.check_lifetime() {
|
||||
let lifetime = this.expect_lifetime();
|
||||
// Parse lifetime parameter.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue