Skip to content

Rollup of 6 pull requests #69851

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 38 commits into from
Mar 9, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
f63b88c
Permit attributes on 'if' expressions
Aaron1011 Feb 16, 2020
e912d9d
Test #[allow(unused)] on `if` expression
Aaron1011 Feb 16, 2020
e9ec47b
Test that stmt_expr_attrs properly gates if-attrs
Aaron1011 Feb 19, 2020
9a299e4
Test trying to cfg-remove an `if` expression
Aaron1011 Feb 19, 2020
b00f674
Remove recovery test
Aaron1011 Feb 19, 2020
e11cdfd
Add run-pass test suggested by @joshtriplett
Aaron1011 Feb 19, 2020
7f19358
Move if-attr tests to their own directory
Aaron1011 Feb 19, 2020
1b681d6
Test that cfg-gated if-exprs are not type-checked
Aaron1011 Feb 19, 2020
37c2c38
Extent pretty-print test
Aaron1011 Feb 19, 2020
66b152c
Fix tabs
Aaron1011 Feb 19, 2020
e50fd5a
Update stderr
Aaron1011 Mar 4, 2020
0468929
move error allocation test to error.rs
RalfJung Mar 4, 2020
938f852
miri validation: debug-complain about unexpected errors
RalfJung Mar 4, 2020
4971d03
fix some cases of unexpected exceptions leaving validation
RalfJung Mar 5, 2020
85e1466
Fix typo
RalfJung Mar 6, 2020
ed3014a
use static strings instead of tcx
RalfJung Mar 6, 2020
af0c44c
Add test for issue-54239
JohnTitor Mar 9, 2020
fc8be08
Add test for issue-57200
JohnTitor Mar 9, 2020
437c07f
Add test for issue-57201
JohnTitor Mar 9, 2020
0005f29
Add test for issue-60473
JohnTitor Mar 9, 2020
95d4785
Add test for issue-64620
JohnTitor Mar 9, 2020
579ce86
Add test for issue-67166
JohnTitor Mar 9, 2020
58303b7
Use slices in preference to 0-terminated strings
tmiasko Mar 6, 2020
e54a829
Avoid unnecessary interning of enum variant part id
tmiasko Mar 6, 2020
676b9bc
unix: Don't override existing SIGSEGV/BUS handlers
cuviper Mar 3, 2020
ef98ec0
Add FIXMEs
JohnTitor Mar 9, 2020
925e9a2
rustc_parse: Use `Token::ident` where possible
petrochenkov Mar 4, 2020
f4a03c4
rustc_ast: Introduce `Token::uninterpolated_span`
petrochenkov Mar 4, 2020
43b27df
rustc_ast: Introduce `Token::uninterpolate`
petrochenkov Mar 7, 2020
5d7f67d
rustc_parse: Remove `Parser::normalized(_prev)_token`
petrochenkov Mar 7, 2020
9be233c
Use `Token::uninterpolate` in couple more places matching on `(Nt)Ident`
petrochenkov Mar 7, 2020
7a30bb1
Address review comments
petrochenkov Mar 9, 2020
4ec9975
Rollup merge of #69201 - Aaron1011:feature/permit-if-attr, r=Centril
Centril Mar 9, 2020
eaf6905
Rollup merge of #69685 - cuviper:soft-segv, r=sfackler
Centril Mar 9, 2020
c9bbfb9
Rollup merge of #69762 - RalfJung:validity-errors, r=oli-obk
Centril Mar 9, 2020
2409e70
Rollup merge of #69779 - tmiasko:di-cstr, r=nagisa
Centril Mar 9, 2020
2677d59
Rollup merge of #69801 - petrochenkov:nonorm, r=Centril
Centril Mar 9, 2020
7e903f8
Rollup merge of #69842 - JohnTitor:more-tests, r=Centril
Centril Mar 9, 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
Use Token::uninterpolate in couple more places matching on (Nt)Ident
  • Loading branch information
petrochenkov committed Mar 9, 2020
commit 9be233cbfe134f032ed2d50f7cc66e901bbe3f6f
5 changes: 2 additions & 3 deletions src/librustc_ast/attr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ impl MetaItem {
I: Iterator<Item = TokenTree>,
{
// FIXME: Share code with `parse_path`.
let path = match tokens.next() {
let path = match tokens.next().map(TokenTree::uninterpolate) {
Some(TokenTree::Token(Token { kind: kind @ token::Ident(..), span }))
| Some(TokenTree::Token(Token { kind: kind @ token::ModSep, span })) => 'arm: {
let mut segments = if let token::Ident(name, _) = kind {
Expand All @@ -457,7 +457,7 @@ impl MetaItem {
};
loop {
if let Some(TokenTree::Token(Token { kind: token::Ident(name, _), span })) =
tokens.next()
tokens.next().map(TokenTree::uninterpolate)
{
segments.push(PathSegment::from_ident(Ident::new(name, span)));
} else {
Expand All @@ -474,7 +474,6 @@ impl MetaItem {
Path { span, segments }
}
Some(TokenTree::Token(Token { kind: token::Interpolated(nt), .. })) => match *nt {
token::Nonterminal::NtIdent(ident, _) => Path::from_ident(ident),
token::Nonterminal::NtMeta(ref item) => return item.meta(item.path.span),
token::Nonterminal::NtPath(ref path) => path.clone(),
_ => return None,
Expand Down
32 changes: 11 additions & 21 deletions src/librustc_ast/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ impl Token {

/// Returns `true` if the token can appear at the start of an expression.
pub fn can_begin_expr(&self) -> bool {
match self.kind {
match self.uninterpolate().kind {
Ident(name, is_raw) =>
ident_can_begin_expr(name, self.span, is_raw), // value name or keyword
OpenDelim(..) | // tuple, array or block
Expand All @@ -375,12 +375,10 @@ impl Token {
Lifetime(..) | // labeled loop
Pound => true, // expression attributes
Interpolated(ref nt) => match **nt {
NtIdent(ident, is_raw) => ident_can_begin_expr(ident.name, ident.span, is_raw),
NtLiteral(..) |
NtExpr(..) |
NtBlock(..) |
NtPath(..) |
NtLifetime(..) => true,
NtPath(..) => true,
_ => false,
},
_ => false,
Expand All @@ -389,7 +387,7 @@ impl Token {

/// Returns `true` if the token can appear at the start of a type.
pub fn can_begin_type(&self) -> bool {
match self.kind {
match self.uninterpolate().kind {
Ident(name, is_raw) =>
ident_can_begin_type(name, self.span, is_raw), // type name or keyword
OpenDelim(Paren) | // tuple
Expand All @@ -403,8 +401,7 @@ impl Token {
Lt | BinOp(Shl) | // associated path
ModSep => true, // global path
Interpolated(ref nt) => match **nt {
NtIdent(ident, is_raw) => ident_can_begin_type(ident.name, ident.span, is_raw),
NtTy(..) | NtPath(..) | NtLifetime(..) => true,
NtTy(..) | NtPath(..) => true,
_ => false,
},
_ => false,
Expand Down Expand Up @@ -445,11 +442,10 @@ impl Token {
///
/// Keep this in sync with `Lit::from_token`.
pub fn can_begin_literal_or_bool(&self) -> bool {
match self.kind {
match self.uninterpolate().kind {
Literal(..) | BinOp(Minus) => true,
Ident(name, false) if name.is_bool_lit() => true,
Interpolated(ref nt) => match &**nt {
NtIdent(ident, false) if ident.name.is_bool_lit() => true,
NtExpr(e) | NtLiteral(e) => matches!(e.kind, ast::ExprKind::Lit(_)),
_ => false,
},
Expand All @@ -475,24 +471,18 @@ impl Token {

/// Returns an identifier if this token is an identifier.
pub fn ident(&self) -> Option<(ast::Ident, /* is_raw */ bool)> {
match self.kind {
Ident(name, is_raw) => Some((ast::Ident::new(name, self.span), is_raw)),
Interpolated(ref nt) => match **nt {
NtIdent(ident, is_raw) => Some((ident, is_raw)),
_ => None,
},
let token = self.uninterpolate();
match token.kind {
Ident(name, is_raw) => Some((ast::Ident::new(name, token.span), is_raw)),
_ => None,
}
}

/// Returns a lifetime identifier if this token is a lifetime.
pub fn lifetime(&self) -> Option<ast::Ident> {
match self.kind {
Lifetime(name) => Some(ast::Ident::new(name, self.span)),
Interpolated(ref nt) => match **nt {
NtLifetime(ident) => Some(ident),
_ => None,
},
let token = self.uninterpolate();
match token.kind {
Lifetime(name) => Some(ast::Ident::new(name, token.span)),
_ => None,
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/librustc_ast/tokenstream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,13 @@ impl TokenTree {
pub fn close_tt(span: DelimSpan, delim: DelimToken) -> TokenTree {
TokenTree::token(token::CloseDelim(delim), span.close)
}

pub fn uninterpolate(self) -> TokenTree {
match self {
TokenTree::Token(token) => TokenTree::Token(token.uninterpolate().into_owned()),
tt => tt,
}
}
}

impl<CTX> HashStable<CTX> for TokenStream
Expand Down
15 changes: 4 additions & 11 deletions src/librustc_ast/util/literal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,23 +191,16 @@ impl Lit {
///
/// Keep this in sync with `Token::can_begin_literal_or_bool`.
pub fn from_token(token: &Token) -> Result<Lit, LitError> {
let lit = match token.kind {
let lit = match token.uninterpolate().kind {
token::Ident(name, false) if name.is_bool_lit() => {
token::Lit::new(token::Bool, name, None)
}
token::Literal(lit) => lit,
token::Interpolated(ref nt) => {
match &**nt {
token::NtIdent(ident, false) if ident.name.is_bool_lit() => {
let lit = token::Lit::new(token::Bool, ident.name, None);
return Lit::from_lit_token(lit, ident.span);
if let token::NtExpr(expr) | token::NtLiteral(expr) = &**nt {
if let ast::ExprKind::Lit(lit) = &expr.kind {
return Ok(lit.clone());
}
token::NtExpr(expr) | token::NtLiteral(expr) => {
if let ast::ExprKind::Lit(lit) = &expr.kind {
return Ok(lit.clone());
}
}
_ => {}
}
return Err(LitError::NotLiteral);
}
Expand Down
3 changes: 1 addition & 2 deletions src/librustc_parse/parser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ macro_rules! maybe_whole_expr {
AttrVec::new(),
));
}
// N.B., `NtIdent(ident)` is normalized to `Ident` in `fn bump`.
_ => {}
};
}
Expand Down Expand Up @@ -482,7 +481,7 @@ impl<'a> Parser<'a> {
}

fn is_mistaken_not_ident_negation(&self) -> bool {
let token_cannot_continue_expr = |t: &Token| match t.kind {
let token_cannot_continue_expr = |t: &Token| match t.uninterpolate().kind {
// These tokens can start an expression after `!`, but
// can't continue an expression after an ident
token::Ident(name, is_raw) => token::ident_can_begin_expr(name, t.span, is_raw),
Expand Down
2 changes: 2 additions & 0 deletions src/librustc_parse/parser/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1544,6 +1544,8 @@ impl<'a> Parser<'a> {

let is_name_required = match self.token.kind {
token::DotDotDot => false,
// FIXME: Consider using interpolated token for this edition check,
// it should match the intent of edition hygiene better.
_ => req_name(self.token.uninterpolate().span.edition()),
};
let (pat, ty) = if is_name_required || self.is_named_param() {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_parse/parser/pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ impl<'a> Parser<'a> {
/// Note that there are more tokens such as `@` for which we know that the `|`
/// is an illegal parse. However, the user's intent is less clear in that case.
fn recover_trailing_vert(&mut self, lo: Option<Span>) -> bool {
let is_end_ahead = self.look_ahead(1, |token| match &token.kind {
let is_end_ahead = self.look_ahead(1, |token| match &token.uninterpolate().kind {
token::FatArrow // e.g. `a | => 0,`.
| token::Ident(kw::If, false) // e.g. `a | if expr`.
| token::Eq // e.g. `let a | = 0`.
Expand Down