diff options
| author | bors <bors@rust-lang.org> | 2022-05-31 01:17:00 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-05-31 01:17:00 +0000 |
| commit | 47365c0d656e2e55d1b6b9dad92842540e3ed1af (patch) | |
| tree | d894135259174abd7972b44c9b07ed8118b522f6 /compiler/rustc_parse | |
| parent | 7be9ec27652f2c3b820d341158b0e005f42e248e (diff) | |
| parent | b3dc31ca9ce37a586b0d73a737aa9841671fd7c1 (diff) | |
| download | rust-47365c0d656e2e55d1b6b9dad92842540e3ed1af.tar.gz rust-47365c0d656e2e55d1b6b9dad92842540e3ed1af.zip | |
Auto merge of #97566 - compiler-errors:rollup-qfxw4j8, r=compiler-errors
Rollup of 6 pull requests Successful merges: - #89685 (refactor: VecDeques Iter fields to private) - #97172 (Optimize the diagnostic generation for `extern unsafe`) - #97395 (Miri call ABI check: ensure type size+align stay the same) - #97431 (don't do `Sized` and other return type checks on RPIT's real type) - #97555 (Source code page: line number click adds `NaN`) - #97558 (Fix typos in comment) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_parse')
| -rw-r--r-- | compiler/rustc_parse/src/parser/item.rs | 41 |
1 files changed, 15 insertions, 26 deletions
diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs index e99347206fe..6720399aacb 100644 --- a/compiler/rustc_parse/src/parser/item.rs +++ b/compiler/rustc_parse/src/parser/item.rs @@ -996,35 +996,24 @@ impl<'a> Parser<'a> { fn parse_item_foreign_mod( &mut self, attrs: &mut Vec<Attribute>, - unsafety: Unsafe, + mut unsafety: Unsafe, ) -> PResult<'a, ItemInfo> { - let sp_start = self.prev_token.span; let abi = self.parse_abi(); // ABI? - match self.parse_item_list(attrs, |p| p.parse_foreign_item(ForceCollect::No)) { - Ok(items) => { - let module = ast::ForeignMod { unsafety, abi, items }; - Ok((Ident::empty(), ItemKind::ForeignMod(module))) - } - Err(mut err) => { - let current_qual_sp = self.prev_token.span; - let current_qual_sp = current_qual_sp.to(sp_start); - if let Ok(current_qual) = self.span_to_snippet(current_qual_sp) { - // FIXME(davidtwco): avoid depending on the error message text - if err.message[0].0.expect_str() == "expected `{`, found keyword `unsafe`" { - let invalid_qual_sp = self.token.uninterpolated_span(); - let invalid_qual = self.span_to_snippet(invalid_qual_sp).unwrap(); - - err.span_suggestion( - current_qual_sp.to(invalid_qual_sp), - &format!("`{}` must come before `{}`", invalid_qual, current_qual), - format!("{} {}", invalid_qual, current_qual), - Applicability::MachineApplicable, - ).note("keyword order for functions declaration is `pub`, `default`, `const`, `async`, `unsafe`, `extern`"); - } - } - Err(err) - } + if unsafety == Unsafe::No + && self.token.is_keyword(kw::Unsafe) + && self.look_ahead(1, |t| t.kind == token::OpenDelim(Delimiter::Brace)) + { + let mut err = self.expect(&token::OpenDelim(Delimiter::Brace)).unwrap_err(); + err.emit(); + unsafety = Unsafe::Yes(self.token.span); + self.eat_keyword(kw::Unsafe); } + let module = ast::ForeignMod { + unsafety, + abi, + items: self.parse_item_list(attrs, |p| p.parse_foreign_item(ForceCollect::No))?, + }; + Ok((Ident::empty(), ItemKind::ForeignMod(module))) } /// Parses a foreign item (one in an `extern { ... }` block). |
