8000 Rollup of 6 pull requests by Centril · Pull Request #69271 · rust-lang/rust · GitHub
[go: up one dir, main page]

Skip to content

Rollup of 6 pull requests #69271

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 31 commits into from
Feb 19, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
0663f25
Always qualify literals by type
matthewjasper Feb 3, 2020
f2980e7
Add fast path for is_freeze
matthewjasper Feb 15, 2020
2fd1544
ast: move Generics into AssocItemKinds
Centril Feb 13, 2020
f06df16
ast: colocate AssocItem with ForeignItem
Centril Feb 13, 2020
e2ae717
ast: tweak comments of Foreign/AssocItemKind
Centril Feb 13, 2020
95dc9b9
ast: normalize `ForeignItemKind::Ty` & `AssocItemKind::TyAlias`.
Centril Feb 14, 2020
f3e9763
ast: make `= <expr>;` optional in free statics/consts.
Centril Feb 14, 2020
1c2906e
ast/parser: fuse `static` & `const` grammars in all contexts.
Centril Feb 14, 2020
f8d2264
parse associated statics.
Centril Feb 15, 2020
35884fe
parse extern consts
Centril Feb 15, 2020
91110fd
ast: make ForeignItemKind an alias of AssocItemKind
Centril Feb 15, 2020
0e0c028
fuse extern & associated item parsing up to defaultness
Centril Feb 15, 2020
cf87edf
pprust: unify extern & associated item printing
Centril Feb 15, 2020
5abedd8
visit: unify extern & assoc item visiting
Centril Feb 15, 2020
d6238bd
reject assoc statics & extern consts during parsing
Centril Feb 15, 2020
8000
fe62bed
print_item_const: remove extraneous space
Centril Feb 15, 2020
f12ae4a
ast: tweak AssocItemKind::Macro comment
Centril Feb 15, 2020
8bafe88
Select an appropriate unused lifetime name in suggestion
estebank Feb 14, 2020
045b7d5
ast: add a FIXME
Centril Feb 17, 2020
2e07892
Do not emit note suggesting to implement trait to foreign type
LeSeulArtichaut Feb 16, 2020
0b1e08c
parse: recover `mut (x @ y)` as `(mut x @ mut y)`.
Centril Feb 17, 2020
d33b356
parser: Do not call `bump` recursively
petrochenkov Feb 16, 2020
ed2fd28
parser: Set previous and unnormalized tokens in couple more places
petrochenkov Feb 16, 2020
06fbb0b
parser: Remove `Option`s from unnormalized tokens
petrochenkov Feb 16, 2020
950845c
Add a test for proc macro generating `$ IDENT`
petrochenkov Feb 17, 2020
5e2a095
Rollup merge of #69146 - matthewjasper:literal-qualif, r=eddyb
Centril Feb 18, 2020
981acd9
Rollup merge of #69159 - estebank:use-appropriate-lt-name, r=ecstatic…
Centril Feb 18, 2020
b864d23
Rollup merge of #69194 - Centril:assoc-extern-fuse, r=petrochenkov
Centril Feb 18, 2020
1cf0194
Rollup merge of #69211 - petrochenkov:prevtok, r=Centril
Centril Feb 18, 2020
c499570
Rollup merge of #69217 - LeSeulArtichaut:remove-lint-impl-op, r=estebank
Centril Feb 18, 2020
6c6d45c
Rollup merge of #69236 - Centril:mut-parens-at-recovery, r=estebank
Centril Feb 18, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
parser: Do not call bump recursively
Token normalization is merged directly into `bump`.
Special "unknown macro variable" diagnostic for unexpected `$`s is removed as preventing legal code from compiling.
  • Loading branch information
petrochenkov committed Feb 17, 2020
commit d33b3562e5e888eaffd2f8f1af08ca2afdbe542c
2 changes: 0 additions & 2 deletions src/librustc_expand/mbe/macro_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -856,8 +856,6 @@ fn parse_nt(p: &mut Parser<'_>, sp: Span, name: Symbol) -> Nonterminal {
if name == sym::tt {
return token::NtTT(p.parse_token_tree());
}
// check at the beginning and the parser checks after each bump
p.process_potential_macro_variable();
match parse_nt_inner(p, sp, name) {
Ok(nt) => nt,
Err(mut err) => {
Expand Down
1 change: 0 additions & 1 deletion src/librustc_expand/mbe/macro_rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,6 @@ fn generic_extension<'cx>(
cx.current_expansion.module.mod_path.last().map(|id| id.to_string());
p.last_type_ascription = cx.current_expansion.prior_type_ascription;

p.process_potential_macro_variable();
// Let the context choose how to interpret the result.
// Weird, but useful for X-macros.
return Box::new(ParserAnyMacro {
Expand Down
75 changes: 32 additions & 43 deletions src/librustc_parse/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,8 @@ impl<'a> Parser<'a> {
subparser_name,
};

parser.token = parser.next_tok();
// Make parser point to the first token.
parser.bump();

if let Some(directory) = directory {
parser.directory = directory;
Expand All @@ -418,7 +419,6 @@ impl<'a> Parser<'a> {
}
}

parser.process_potential_macro_variable();
parser
}

Expand All @@ -430,15 +430,15 @@ impl<'a> Parser<'a> {
self.unnormalized_prev_token.as_ref().unwrap_or(&self.prev_token)
}

fn next_tok(&mut self) -> Token {
fn next_tok(&mut self, fallback_span: Span) -> Token {
let mut next = if self.desugar_doc_comments {
self.token_cursor.next_desugared()
} else {
self.token_cursor.next()
};
if next.span.is_dummy() {
// Tweak the location for better diagnostics, but keep syntactic context intact.
next.span = self.unnormalized_token().span.with_ctxt(next.span.ctxt());
next.span = fallback_span.with_ctxt(next.span.ctxt());
}
next
}
Expand Down Expand Up @@ -896,6 +896,24 @@ impl<'a> Parser<'a> {
self.parse_delim_comma_seq(token::Paren, f)
}

// Interpolated identifier (`$i: ident`) and lifetime (`$l: lifetime`)
// tokens are replaced with usual identifier and lifetime tokens,
// so the former are never encountered during normal parsing.
fn normalize_token(token: &Token) -> Option<Token> {
match &token.kind {
token::Interpolated(nt) => match **nt {
token::NtIdent(ident, is_raw) => {
Some(Token::new(token::Ident(ident.name, is_raw), ident.span))
}
token::NtLifetime(ident) => {
Some(Token::new(token::Lifetime(ident.name), ident.span))
}
_ => None,
},
_ => None,
}
}

/// Advance the parser by one token.
pub fn bump(&mut self) {
if self.prev_token.kind == TokenKind::Eof {
Expand All @@ -905,16 +923,17 @@ impl<'a> Parser<'a> {
}

// Update the current and previous tokens.
let next_token = self.next_tok();
self.prev_token = mem::replace(&mut self.token, next_token);
self.prev_token = self.token.take();
self.unnormalized_prev_token = self.unnormalized_token.take();
self.token = self.next_tok(self.unnormalized_prev_token().span);
if let Some(normalized_token) = Self::normalize_token(&self.token) {
self.unnormalized_token = Some(mem::replace(&mut self.token, normalized_token));
}

// Update fields derived from the previous token.
self.prev_span = self.unnormalized_prev_token().span;

self.expected_tokens.clear();
// Check after each token.
self.process_potential_macro_variable();
}

/// Advances the parser using provided token as a next one. Use this when
Expand All @@ -924,9 +943,12 @@ impl<'a> Parser<'a> {
/// Correct token kinds and spans need to be calculated instead.
fn bump_with(&mut self, next: TokenKind, span: Span) {
// Update the current and previous tokens.
let next_token = Token::new(next, span);
self.prev_token = mem::replace(&mut self.token, next_token);
self.prev_token = self.token.take();
self.unnormalized_prev_token = self.unnormalized_token.take();
self.token = Token::new(next, span);
if let Some(normalized_token) = Self::normalize_token(&self.token) {
self.unnormalized_token = Some(mem::replace(&mut self.token, normalized_token));
}

// Update fields derived from the previous token.
self.prev_span = self.unnormalized_prev_token().span.with_hi(span.lo());
Expand Down Expand Up @@ -1066,39 +1088,6 @@ impl<'a> Parser<'a> {
}
}

pub fn process_potential_macro_variable(&mut self) {
let normalized_token = match self.token.kind {
token::Dollar
if self.token.span.from_expansion() && self.look_ahead(1, |t| t.is_ident()) =>
{
self.bump();
let name = match self.token.kind {
token::Ident(name, _) => name,
_ => unreachable!(),
};
let span = self.prev_span.to(self.token.span);
self.struct_span_err(span, &format!("unknown macro variable `{}`", name))
.span_label(span, "unknown macro variable")
.emit();
self.bump();
return;
}
token::Interpolated(ref nt) => {
// Interpolated identifier and lifetime tokens are replaced with usual identifier
// and lifetime tokens, so the former are never encountered during normal parsing.
match **nt {
token::NtIdent(ident, is_raw) => {
Token::new(token::Ident(ident.name, is_raw), ident.span)
}
token::NtLifetime(ident) => Token::new(token::Lifetime(ident.name), ident.span),
_ => return,
}
}
_ => return,
};
self.unnormalized_token = Some(mem::replace(&mut self.token, normalized_token));
}

/// Parses a single token tree from the input.
pub fn parse_token_tree(&mut self) -> TokenTree {
match self.token.kind {
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/issues/issue-6596-1.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
macro_rules! e {
($inp:ident) => (
$nonexistent
//~^ ERROR unknown macro variable `nonexistent`
//~^ ERROR expected expression, found `$`
);
}

Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/issues/issue-6596-1.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error: unknown macro variable `nonexistent`
error: expected expression, found `$`
--> $DIR/issue-6596-1.rs:3:9
|
LL | $nonexistent
| ^^^^^^^^^^^^ unknown macro variable
| ^^^^^^^^^^^^ expected expression
...
LL | e!(foo);
| -------- in this macro invocation
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/issues/issue-6596-2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
macro_rules! g {
($inp:ident) => (
{ $inp $nonexistent }
//~^ ERROR unknown macro variable `nonexistent`
//~^ ERROR expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found `$`
);
}

Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/issues/issue-6596-2.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error: unknown macro variable `nonexistent`
error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found `$`
--> $DIR/issue-6596-2.rs:5:16
|
LL | { $inp $nonexistent }
| ^^^^^^^^^^^^ unknown macro variable
| ^^^^^^^^^^^^ expected one of 8 possible tokens
...
LL | g!(foo);
| -------- in this macro invocation
Expand Down
0