Skip to content
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

Rollup of 9 pull requests #64944

Closed
wants to merge 50 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
2cb460e
Use `saturating_sub` where applicable
AnthonyMikh Sep 25, 2019
e9a93be
Use `max` instead of `if`s
AnthonyMikh Sep 25, 2019
4fc5650
Simplify Unicode-aware trimming
AnthonyMikh Sep 25, 2019
d6327e8
Use map + sum instead of fold for computing Unicode width
AnthonyMikh Sep 25, 2019
aef169b
Use Option::map_or where applicable
AnthonyMikh Sep 25, 2019
9b447e2
Unify order of variables in chained comparison
AnthonyMikh Sep 25, 2019
f93827f
Simplify `Emitter::fix_multispan_in_std_macros`
AnthonyMikh Sep 25, 2019
ea32862
Use `sort_by_key` rather than `sort_by`
AnthonyMikh Sep 25, 2019
7a0725f
Simplify `style_or_override`
AnthonyMikh Sep 25, 2019
75a7c27
Revert "Simplify Unicode-aware trimming"
AnthonyMikh Sep 26, 2019
3eba6c1
syntax: recover trailing `|` in or-patterns.
Centril Sep 29, 2019
d938a80
Fixed grammar for some `time` fn calls and a diagnostic.
alexreg Sep 30, 2019
fdd1a62
Added backticks for one diagnostic message.
alexreg Sep 30, 2019
8a4af2f
Fixed weird non-sequential indices for serialisation of `SourceFile` …
alexreg Sep 30, 2019
13b61b5
Fixed grammar in one diagnostic and blessed tests.
alexreg Sep 29, 2019
49c6c86
Fixed stylistic convention for one diagnostic and blessed tests.
alexreg Sep 30, 2019
33ed03f
Cleaned up a few doc comments in libfmt_macros.
alexreg Sep 30, 2019
349259d
Stabilize macros in `extern` blocks
petrochenkov Aug 26, 2019
5ae38bb
Stabilize proc macros in type positions
petrochenkov Aug 27, 2019
b04d5f7
Upgrade Emscripten targets to use upstream LLVM backend
tlively Aug 17, 2019
535d474
syntax: Split `ast::Attribute` into container and inner parts
petrochenkov Aug 17, 2019
576c215
Add test for #50571
JohnTitor Sep 30, 2019
bc25746
Add test for #58022
JohnTitor Sep 30, 2019
9c73131
Add test for #58344
JohnTitor Sep 30, 2019
957986d
syntax: Support modern attribute syntax in the `meta` matcher
petrochenkov Aug 17, 2019
870b47f
typeck: silence unreachable code from await
davidtwco Sep 30, 2019
7dc953b
Simplify code for special case of annotation
AnthonyMikh Sep 30, 2019
6b6a79b
Simplify `EmitterWriter::get_multispan_max_line_num`
AnthonyMikh Sep 30, 2019
7b4c5c6
Simplify `EmitterWriter::get_max_line_num`
AnthonyMikh Sep 30, 2019
21724ed
Update doc comment for `style_or_override`
AnthonyMikh Sep 30, 2019
7a807c5
Simplify `EmitterWriter::emit_suggestion_default`
AnthonyMikh Sep 30, 2019
9d73176
Remove redundant `.iter_mut()`
AnthonyMikh Sep 30, 2019
55b5428
Simplify a conditional in `collect_annotations`
AnthonyMikh Sep 30, 2019
6ea4a52
Address review comments
petrochenkov Sep 30, 2019
bb44288
Use pattern matching instead of indexing tuples
AnthonyMikh Sep 30, 2019
e5db5b3
(fmt) remove trailing whitespaces
AnthonyMikh Sep 30, 2019
61bc38e
Fix errors
AnthonyMikh Sep 30, 2019
515262c
Ascript type explicitly
AnthonyMikh Sep 30, 2019
fdce416
Hint type for `.sum()`
AnthonyMikh Oct 1, 2019
50c2a58
Fix borrowck errors
AnthonyMikh Oct 1, 2019
13e9b3d
Deduplicate closure type errors
estebank Oct 1, 2019
2aafa46
Rollup merge of #63649 - tlively:emscripten-upstream-upgrade, r=alexc…
Centril Oct 1, 2019
3ca5804
Rollup merge of #63674 - petrochenkov:meta2, r=Centril
Centril Oct 1, 2019
8bae91d
Rollup merge of #63931 - petrochenkov:stabmac, r=Centril
Centril Oct 1, 2019
8206e61
Rollup merge of #64887 - Centril:recover-trailing-vert, r=estebank
Centril Oct 1, 2019
857b2b9
Rollup merge of #64907 - alexreg:tidy-up, r=Mark-Simulacrum
Centril Oct 1, 2019
0aaab33
Rollup merge of #64928 - JohnTitor:add-some-tests, r=Centril
Centril Oct 1, 2019
cac592f
Rollup merge of #64930 - davidtwco:issue-61798-diverging-await, r=pet…
Centril Oct 1, 2019
3ff0f33
Rollup merge of #64935 - AnthonyMikh:librustc_errors/emmiter__code-cl…
Centril Oct 1, 2019
7ca64cc
Rollup merge of #64937 - estebank:dedup-closure-err, r=Centril
Centril Oct 1, 2019
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
16 changes: 11 additions & 5 deletions src/libsyntax/attr/mod.rs
Original file line number Diff line number Diff line change
@@ -255,9 +255,8 @@ impl MetaItem {
}
}

impl Attribute {
/// Extracts the `MetaItem` from inside this `Attribute`.
pub fn meta(&self) -> Option<MetaItem> {
impl AttrItem {
crate fn meta(&self, span: Span) -> Option<MetaItem> {
let mut tokens = self.tokens.trees().peekable();
Some(MetaItem {
path: self.path.clone(),
@@ -269,9 +268,16 @@ impl Attribute {
} else {
return None;
},
span: self.span,
span,
})
}
}

impl Attribute {
/// Extracts the MetaItem from inside this Attribute.
pub fn meta(&self) -> Option<MetaItem> {
self.item.meta(self.span)
}

pub fn parse<'a, T, F>(&self, sess: &'a ParseSess, mut f: F) -> PResult<'a, T>
where F: FnMut(&mut Parser<'a>) -> PResult<'a, T>,
@@ -524,7 +530,7 @@ impl MetaItem {
}
Some(TokenTree::Token(Token { kind: token::Interpolated(nt), .. })) => match *nt {
token::Nonterminal::NtIdent(ident, _) => Path::from_ident(ident),
token::Nonterminal::NtMeta(ref meta) => return Some(meta.clone()),
token::Nonterminal::NtMeta(ref item) => return item.meta(item.path.span),
token::Nonterminal::NtPath(ref path) => path.clone(),
_ => return None,
},
8 changes: 4 additions & 4 deletions src/libsyntax/config.rs
Original file line number Diff line number Diff line change
@@ -122,8 +122,8 @@ impl<'a> StripUnconfigured<'a> {

while !parser.check(&token::CloseDelim(token::Paren)) {
let lo = parser.token.span.lo();
let (path, tokens) = parser.parse_meta_item_unrestricted()?;
expanded_attrs.push((path, tokens, parser.prev_span.with_lo(lo)));
let item = parser.parse_attr_item()?;
expanded_attrs.push((item, parser.prev_span.with_lo(lo)));
parser.expect_one_of(&[token::Comma], &[token::CloseDelim(token::Paren)])?;
}

@@ -150,8 +150,8 @@ impl<'a> StripUnconfigured<'a> {
// `cfg_attr` inside of another `cfg_attr`. E.g.
// `#[cfg_attr(false, cfg_attr(true, some_attr))]`.
expanded_attrs.into_iter()
.flat_map(|(path, tokens, span)| self.process_cfg_attr(ast::Attribute {
item: ast::AttrItem { path, tokens },
.flat_map(|(item, span)| self.process_cfg_attr(ast::Attribute {
item,
id: attr::mk_attr_id(),
style: attr.style,
is_sugared_doc: false,
2 changes: 1 addition & 1 deletion src/libsyntax/ext/mbe/macro_parser.rs
Original file line number Diff line number Diff line change
@@ -924,7 +924,7 @@ fn parse_nt(p: &mut Parser<'_>, sp: Span, name: Symbol) -> Nonterminal {
FatalError.raise()
}
sym::path => token::NtPath(panictry!(p.parse_path(PathStyle::Type))),
sym::meta => token::NtMeta(panictry!(p.parse_meta_item())),
sym::meta => token::NtMeta(panictry!(p.parse_attr_item())),
sym::vis => token::NtVis(panictry!(p.parse_visibility(true))),
sym::lifetime => if p.check_lifetime() {
token::NtLifetime(p.expect_lifetime().ident)
5 changes: 4 additions & 1 deletion src/libsyntax/mut_visit.rs
Original file line number Diff line number Diff line change
@@ -682,7 +682,10 @@ pub fn noop_visit_interpolated<T: MutVisitor>(nt: &mut token::Nonterminal, vis:
token::NtIdent(ident, _is_raw) => vis.visit_ident(ident),
token::NtLifetime(ident) => vis.visit_ident(ident),
token::NtLiteral(expr) => vis.visit_expr(expr),
token::NtMeta(meta) => vis.visit_meta_item(meta),
token::NtMeta(AttrItem { path, tokens }) => {
vis.visit_path(path);
vis.visit_tts(tokens);
}
token::NtPath(path) => vis.visit_path(path),
token::NtTT(tt) => vis.visit_tt(tt),
token::NtImplItem(item) =>
31 changes: 18 additions & 13 deletions src/libsyntax/parse/attr.rs
Original file line number Diff line number Diff line change
@@ -90,7 +90,7 @@ impl<'a> Parser<'a> {
debug!("parse_attribute_with_inner_parse_policy: inner_parse_policy={:?} self.token={:?}",
inner_parse_policy,
self.token);
let (span, path, tokens, style) = match self.token.kind {
let (span, item, style) = match self.token.kind {
token::Pound => {
let lo = self.token.span;
self.bump();
@@ -107,7 +107,7 @@ impl<'a> Parser<'a> {
};

self.expect(&token::OpenDelim(token::Bracket))?;
let (path, tokens) = self.parse_meta_item_unrestricted()?;
let item = self.parse_attr_item()?;
self.expect(&token::CloseDelim(token::Bracket))?;
let hi = self.prev_span;

@@ -142,7 +142,7 @@ impl<'a> Parser<'a> {
}
}

(attr_sp, path, tokens, style)
(attr_sp, item, style)
}
_ => {
let token_str = self.this_token_to_string();
@@ -151,7 +151,7 @@ impl<'a> Parser<'a> {
};

Ok(ast::Attribute {
item: ast::AttrItem { path, tokens },
item,
id: attr::mk_attr_id(),
style,
is_sugared_doc: false,
@@ -168,17 +168,17 @@ impl<'a> Parser<'a> {
/// PATH
/// PATH `=` TOKEN_TREE
/// The delimiters or `=` are still put into the resulting token stream.
pub fn parse_meta_item_unrestricted(&mut self) -> PResult<'a, (ast::Path, TokenStream)> {
let meta = match self.token.kind {
pub fn parse_attr_item(&mut self) -> PResult<'a, ast::AttrItem> {
let item = match self.token.kind {
token::Interpolated(ref nt) => match **nt {
Nonterminal::NtMeta(ref meta) => Some(meta.clone()),
Nonterminal::NtMeta(ref item) => Some(item.clone()),
_ => None,
},
_ => None,
};
Ok(if let Some(meta) = meta {
Ok(if let Some(item) = item {
self.bump();
(meta.path, meta.kind.tokens(meta.span))
item
} else {
let path = self.parse_path(PathStyle::Mod)?;
let tokens = if self.check(&token::OpenDelim(DelimToken::Paren)) ||
@@ -205,7 +205,7 @@ impl<'a> Parser<'a> {
} else {
TokenStream::empty()
};
(path, tokens)
ast::AttrItem { path, tokens }
})
}

@@ -273,9 +273,14 @@ impl<'a> Parser<'a> {
_ => None,
};

if let Some(meta) = nt_meta {
self.bump();
return Ok(meta);
if let Some(item) = nt_meta {
return match item.meta(item.path.span) {
Some(meta) => {
self.bump();
Ok(meta)
}
None => self.unexpected(),
}
}

let lo = self.token.span;
6 changes: 3 additions & 3 deletions src/libsyntax/parse/parser/path.rs
Original file line number Diff line number Diff line change
@@ -114,9 +114,9 @@ impl<'a> Parser<'a> {
pub fn parse_path_allowing_meta(&mut self, style: PathStyle) -> PResult<'a, Path> {
let meta_ident = match self.token.kind {
token::Interpolated(ref nt) => match **nt {
token::NtMeta(ref meta) => match meta.kind {
ast::MetaItemKind::Word => Some(meta.path.clone()),
_ => None,
token::NtMeta(ref item) => match item.tokens.is_empty() {
true => Some(item.path.clone()),
false => None,
},
_ => None,
},
2 changes: 1 addition & 1 deletion src/libsyntax/parse/token.rs
Original file line number Diff line number Diff line change
@@ -687,7 +687,7 @@ pub enum Nonterminal {
NtLifetime(ast::Ident),
NtLiteral(P<ast::Expr>),
/// Stuff inside brackets for attributes
NtMeta(ast::MetaItem),
NtMeta(ast::AttrItem),
NtPath(ast::Path),
NtVis(ast::Visibility),
NtTT(TokenTree),
40 changes: 22 additions & 18 deletions src/libsyntax/print/pprust.rs
Original file line number Diff line number Diff line change
@@ -324,7 +324,7 @@ fn token_to_string_ext(token: &Token, convert_dollar_crate: bool) -> String {
crate fn nonterminal_to_string(nt: &Nonterminal) -> String {
match *nt {
token::NtExpr(ref e) => expr_to_string(e),
token::NtMeta(ref e) => meta_item_to_string(e),
token::NtMeta(ref e) => attr_item_to_string(e),
token::NtTy(ref e) => ty_to_string(e),
token::NtPath(ref e) => path_to_string(e),
token::NtItem(ref e) => item_to_string(e),
@@ -412,8 +412,8 @@ pub fn meta_list_item_to_string(li: &ast::NestedMetaItem) -> String {
to_string(|s| s.print_meta_list_item(li))
}

pub fn meta_item_to_string(mi: &ast::MetaItem) -> String {
to_string(|s| s.print_meta_item(mi))
fn attr_item_to_string(ai: &ast::AttrItem) -> String {
to_string(|s| s.print_attr_item(ai, ai.path.span))
}

pub fn attribute_to_string(attr: &ast::Attribute) -> String {
@@ -629,24 +629,28 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
ast::AttrStyle::Inner => self.word("#!["),
ast::AttrStyle::Outer => self.word("#["),
}
self.ibox(0);
match attr.tokens.trees().next() {
Some(TokenTree::Delimited(_, delim, tts)) => {
self.print_mac_common(
Some(MacHeader::Path(&attr.path)), false, None, delim, tts, true, attr.span
);
}
tree => {
self.print_path(&attr.path, false, 0);
if tree.is_some() {
self.space();
self.print_tts(attr.tokens.clone(), true);
}
self.print_attr_item(&attr.item, attr.span);
self.word("]");
}
}

fn print_attr_item(&mut self, item: &ast::AttrItem, span: Span) {
self.ibox(0);
match item.tokens.trees().next() {
Some(TokenTree::Delimited(_, delim, tts)) => {
self.print_mac_common(
Some(MacHeader::Path(&item.path)), false, None, delim, tts, true, span
);
}
tree => {
self.print_path(&item.path, false, 0);
if tree.is_some() {
self.space();
self.print_tts(item.tokens.clone(), true);
}
}
self.end();
self.word("]");
}
self.end();
}

fn print_meta_list_item(&mut self, item: &ast::NestedMetaItem) {
4 changes: 2 additions & 2 deletions src/libsyntax_ext/cmdline_attrs.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Attributes injected into the crate root from command line using `-Z crate-attr`.

use syntax::ast::{self, AttrStyle};
use syntax::ast::{self, AttrItem, AttrStyle};
use syntax::attr::mk_attr;
use syntax::panictry;
use syntax::parse::{self, token, ParseSess};
@@ -15,7 +15,7 @@ pub fn inject(mut krate: ast::Crate, parse_sess: &ParseSess, attrs: &[String]) -
);

let start_span = parser.token.span;
let (path, tokens) = panictry!(parser.parse_meta_item_unrestricted());
let AttrItem { path, tokens } = panictry!(parser.parse_attr_item());
let end_span = parser.token.span;
if parser.token != token::Eof {
parse_sess.span_diagnostic
4 changes: 2 additions & 2 deletions src/test/ui/cfg/cfg_stmt_expr.rs
Original file line number Diff line number Diff line change
@@ -57,7 +57,7 @@ fn main() {
// check that macro expanded code works

macro_rules! if_cfg {
($cfg:meta $ib:block else $eb:block) => {
($cfg:meta? $ib:block else $eb:block) => {
{
let r;
#[cfg($cfg)]
@@ -69,7 +69,7 @@ fn main() {
}
}

let n = if_cfg!(unset {
let n = if_cfg!(unset? {
413
} else {
612
6 changes: 0 additions & 6 deletions src/test/ui/macros/macro-first-set.rs
Original file line number Diff line number Diff line change
@@ -252,12 +252,6 @@ test_path!(::std);
test_path!(std::u8,);
test_path!(any, super, super::super::self::path, X<Y>::Z<'a, T=U>);

macro_rules! test_meta_block {
($($m:meta)* $b:block) => {};
}

test_meta_block!(windows {});

macro_rules! test_lifetime {
(1. $($l:lifetime)* $($b:block)*) => {};
(2. $($b:block)* $($l:lifetime)*) => {};