Rollup merge of #90022 - hkmatsumoto:self-upper-as-generic-parameter, r=jackh726
Explain why `Self` is invalid in generic parameters Close #89985. r? `@estebank`
This commit is contained in:
commit
29fe57def2
3 changed files with 35 additions and 13 deletions
|
@ -92,6 +92,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