Skip to content

Commit

Permalink
Merge pull request rust-lang#3325 from topecongiro/rustcap
Browse files Browse the repository at this point in the history
Update rustc-ap-* crates to 366.0.0
  • Loading branch information
topecongiro authored Feb 7, 2019
2 parents 4ed31b6 + 1ae0326 commit 672f352
Show file tree
Hide file tree
Showing 9 changed files with 232 additions and 237 deletions.
379 changes: 190 additions & 189 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ env_logger = "0.6"
getopts = "0.2"
derive-new = "0.5"
cargo_metadata = "0.7"
rustc-ap-rustc_target = "306.0.0"
rustc-ap-syntax = "306.0.0"
rustc-ap-syntax_pos = "306.0.0"
rustc-ap-rustc_target = "366.0.0"
rustc-ap-syntax = "366.0.0"
rustc-ap-syntax_pos = "366.0.0"
failure = "0.1.3"
bytecount = "0.5"
unicode-width = "0.1.5"
Expand Down
1 change: 0 additions & 1 deletion src/closures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ fn rewrite_closure_with_block(
id: ast::NodeId::root(),
rules: ast::BlockCheckMode::Default,
span: body.span,
recovered: false,
};
let block =
crate::expr::rewrite_block_with_visitor(context, "", &block, None, None, shape, false)?;
Expand Down
1 change: 1 addition & 0 deletions src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ pub fn format_expr(
))
}
}
ast::ExprKind::Err => None,
};

expr_rw
Expand Down
30 changes: 13 additions & 17 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use syntax::parse::token::{BinOpToken, DelimToken, Token};
use syntax::print::pprust;
use syntax::source_map::{BytePos, Span};
use syntax::symbol;
use syntax::tokenstream::{Cursor, ThinTokenStream, TokenStream, TokenTree};
use syntax::tokenstream::{Cursor, TokenStream, TokenTree};
use syntax::ThinVec;
use syntax::{ast, parse, ptr};

Expand Down Expand Up @@ -751,7 +751,7 @@ struct MacroArgParser {
fn last_tok(tt: &TokenTree) -> Token {
match *tt {
TokenTree::Token(_, ref t) => t.clone(),
TokenTree::Delimited(_, ref d) => d.close_token(),
TokenTree::Delimited(_, delim, _) => Token::CloseDelim(delim),
}
}

Expand Down Expand Up @@ -916,11 +916,11 @@ impl MacroArgParser {
}

/// Returns a collection of parsed macro def's arguments.
pub fn parse(mut self, tokens: ThinTokenStream) -> Option<Vec<ParsedMacroArg>> {
pub fn parse(mut self, tokens: TokenStream) -> Option<Vec<ParsedMacroArg>> {
let stream: TokenStream = tokens.into();
let mut iter = stream.trees();

while let Some(ref tok) = iter.next() {
while let Some(tok) = iter.next() {
match tok {
TokenTree::Token(sp, Token::Dollar) => {
// We always want to add a separator before meta variables.
Expand All @@ -937,7 +937,7 @@ impl MacroArgParser {
self.add_meta_variable(&mut iter)?;
}
TokenTree::Token(sp, ref t) => self.update_buffer(sp.lo(), t),
TokenTree::Delimited(delimited_span, delimited) => {
TokenTree::Delimited(delimited_span, delimited, ref tts) => {
if !self.buf.is_empty() {
if next_space(&self.last_tok) == SpaceState::Always {
self.add_separator();
Expand All @@ -949,19 +949,19 @@ impl MacroArgParser {
// Parse the stuff inside delimiters.
let mut parser = MacroArgParser::new();
parser.lo = delimited_span.open.lo();
let delimited_arg = parser.parse(delimited.tts.clone())?;
let delimited_arg = parser.parse(tts.clone())?;

let span = delimited_span.entire();
if self.is_meta_var {
self.add_repeat(delimited_arg, delimited.delim, &mut iter, span)?;
self.add_repeat(delimited_arg, delimited, &mut iter, span)?;
self.is_meta_var = false;
} else {
self.add_delimited(delimited_arg, delimited.delim, span);
self.add_delimited(delimited_arg, delimited, span);
}
}
}

self.set_last_tok(tok);
self.set_last_tok(&tok);
}

// We are left with some stuff in the buffer. Since there is nothing
Expand Down Expand Up @@ -1027,11 +1027,7 @@ fn wrap_macro_args_inner(
//
// We always try and format on one line.
// FIXME: Use multi-line when every thing does not fit on one line.
fn format_macro_args(
context: &RewriteContext,
toks: ThinTokenStream,
shape: Shape,
) -> Option<String> {
fn format_macro_args(context: &RewriteContext, toks: TokenStream, shape: Shape) -> Option<String> {
if !context.config.format_macro_matchers() {
let token_stream: TokenStream = toks.into();
let span = span_for_token_stream(&token_stream);
Expand Down Expand Up @@ -1176,7 +1172,7 @@ impl MacroParser {
let tok = self.toks.next()?;
let (lo, args_paren_kind) = match tok {
TokenTree::Token(..) => return None,
TokenTree::Delimited(delimited_span, ref d) => (delimited_span.open.lo(), d.delim),
TokenTree::Delimited(delimited_span, d, _) => (delimited_span.open.lo(), d),
};
let args = tok.joint().into();
match self.toks.next()? {
Expand All @@ -1185,7 +1181,7 @@ impl MacroParser {
}
let (mut hi, body, whole_body) = match self.toks.next()? {
TokenTree::Token(..) => return None,
TokenTree::Delimited(delimited_span, _) => {
TokenTree::Delimited(delimited_span, ..) => {
let data = delimited_span.entire().data();
(
data.hi,
Expand Down Expand Up @@ -1218,7 +1214,7 @@ struct Macro {
struct MacroBranch {
span: Span,
args_paren_kind: DelimToken,
args: ThinTokenStream,
args: TokenStream,
body: Span,
whole_body: Span,
}
Expand Down
10 changes: 8 additions & 2 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,14 @@ fn rewrite_segment(
.chain(data.bindings.iter().map(|x| SegmentParam::Binding(&*x)))
.collect::<Vec<_>>();

let force_separator =
context.inside_macro() && context.snippet(data.span).starts_with("::");
// HACK: squeeze out the span between the identifier and the parameters.
// The hack is requried so that we don't remove the separator inside macro calls.
// This does not work in the presence of comment, hoping that people are
// sane about where to put their comment.
let separator_snippet = context
.snippet(mk_sp(segment.ident.span.hi(), data.span.lo()))
.trim();
let force_separator = context.inside_macro() && separator_snippet.starts_with("::");
let separator = if path_context == PathContext::Expr || force_separator {
"::"
} else {
Expand Down
28 changes: 3 additions & 25 deletions src/visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

use std::cell::RefCell;

use syntax::attr::HasAttrs;
use syntax::parse::ParseSess;
use syntax::source_map::{self, BytePos, Pos, SourceMap, Span};
use syntax::{ast, visit};
Expand Down Expand Up @@ -152,32 +151,11 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
self.push_str("{");

if let Some(first_stmt) = b.stmts.first() {
let attr_lo = inner_attrs
let hi = inner_attrs
.and_then(|attrs| inner_attributes(attrs).first().map(|attr| attr.span.lo()))
.or_else(|| {
// Attributes for an item in a statement position
// do not belong to the statement. (rust-lang/rust#34459)
if let ast::StmtKind::Item(ref item) = first_stmt.node {
item.attrs.first()
} else {
first_stmt.attrs().first()
}
.and_then(|attr| {
// Some stmts can have embedded attributes.
// e.g. `match { #![attr] ... }`
let attr_lo = attr.span.lo();
if attr_lo < first_stmt.span.lo() {
Some(attr_lo)
} else {
None
}
})
});
.unwrap_or(first_stmt.span().lo());

let snippet = self.snippet(mk_sp(
self.last_pos,
attr_lo.unwrap_or_else(|| first_stmt.span.lo()),
));
let snippet = self.snippet(mk_sp(self.last_pos, hi));
let len = CommentCodeSlices::new(snippet)
.nth(0)
.and_then(|(kind, _, s)| {
Expand Down
7 changes: 7 additions & 0 deletions tests/source/attrib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,3 +211,10 @@ pub struct Params {
all(target_arch = "wasm32", feature = "wasm-bindgen"),
))))]
type Os = NoSource;

// #3313
fn stmt_expr_attributes() {
let foo ;
#[must_use]
foo = false ;
}
7 changes: 7 additions & 0 deletions tests/target/attrib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,3 +246,10 @@ mod issue_2620 {
)
)))]
type Os = NoSource;

// #3313
fn stmt_expr_attributes() {
let foo;
#[must_use]
foo = false;
}

0 comments on commit 672f352

Please sign in to comment.