diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2020-02-15 22:21:00 +0100 |
|---|---|---|
| committer | Mazdak Farrokhzad <twingoow@gmail.com> | 2020-02-15 22:21:00 +0100 |
| commit | d6238bd8d4fe283968abbf46357c8e56f283b65b (patch) | |
| tree | c6acbcaf3fe6c10cf44c972afa1df223bed981fd /src/librustc_parse/parser | |
| parent | 5abedd81e04dc1b76db423ca351ef5d3056a6f97 (diff) | |
| download | rust-d6238bd8d4fe283968abbf46357c8e56f283b65b.tar.gz rust-d6238bd8d4fe283968abbf46357c8e56f283b65b.zip | |
reject assoc statics & extern consts during parsing
Diffstat (limited to 'src/librustc_parse/parser')
| -rw-r--r-- | src/librustc_parse/parser/item.rs | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/src/librustc_parse/parser/item.rs b/src/librustc_parse/parser/item.rs index 20d6182ddc1..da72da04365 100644 --- a/src/librustc_parse/parser/item.rs +++ b/src/librustc_parse/parser/item.rs @@ -643,9 +643,16 @@ impl<'a> Parser<'a> { if !item.attrs.iter().any(|attr| attr.style == AttrStyle::Inner) { item.tokens = Some(tokens); } + self.error_on_assoc_static(&item); Ok(P(item)) } + fn error_on_assoc_static(&self, item: &AssocItem) { + if let AssocItemKind::Static(..) = item.kind { + self.struct_span_err(item.span, "associated `static` items are not allowed").emit(); + } + } + fn parse_assoc_item_( &mut self, at_end: &mut bool, @@ -868,7 +875,25 @@ impl<'a> Parser<'a> { let lo = self.token.span; let vis = self.parse_visibility(FollowedByType::No)?; let (ident, kind) = self.parse_assoc_item_kind(at_end, &mut attrs, |_| true, &vis)?; - Ok(P(self.mk_item(lo, ident, kind, vis, attrs))) + let item = self.mk_item(lo, ident, kind, vis, attrs); + self.error_on_foreign_const(&item); + Ok(P(item)) + } + + fn error_on_foreign_const(&self, item: &ForeignItem) { + if let AssocItemKind::Const(..) = item.kind { + self.struct_span_err(item.ident.span, "extern items cannot be `const`") + .span_suggestion( + item.span.with_hi(item.ident.span.lo()), + "try using a static value", + "static ".to_string(), + Applicability::MachineApplicable, + ) + .note( + "for more information, visit https://doc.rust-lang.org/std/keyword.extern.html", + ) + .emit(); + } } fn is_static_global(&mut self) -> bool { |
