This commit is contained in:
Protryon 2021-03-22 07:06:51 -07:00
parent 5985d8da41
commit ee877be2a6
2 changed files with 10 additions and 0 deletions

View File

@ -89,4 +89,11 @@ impl SyntaxError {
span,
)
}
pub fn illegal_self_const(span: &Span) -> Self {
Self::new_from_span(
"cannot have const self".to_string(),
span,
)
}
}

View File

@ -331,6 +331,9 @@ impl ParserContext {
self.expect_ident()?
};
if name.name.as_ref() == "self" {
if let Some(const_) = const_.as_ref() {
return Err(SyntaxError::illegal_self_const(&(&name.span + &const_.span)))
}
if let Some(mutable) = &mutable {
name.span = &mutable.span + &name.span;
name.name = "mut self".to_string().into();