Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
c70eb4b
Automatically expand section if url id point to one of its component
GuillaumeGomez Aug 5, 2018
70cafec
improper_ctypes lint for individual foreign items
vpashkov Aug 6, 2018
e8bb7bf
Account for --remap-path-prefix in save-analysis
Xanewok Aug 6, 2018
b011b09
NetBSD: fix signedess of char
jakllsch Aug 5, 2018
2403d91
remove `let x = baz` which was obscuring the real error
nikomatsakis Aug 6, 2018
44d32d4
Avoid unnecessary pattern matching against Option and Result
ljedrz Jul 27, 2018
43850e0
Special case error message for thread-local statics.
davidtwco Aug 6, 2018
6608552
Re-enable drop-locations debuginfo tests.
michaelwoerister Aug 7, 2018
4eb52ff
Re-enable a bunch of debuginfo tests.
michaelwoerister Aug 7, 2018
efda9f8
Added some debug logging.
davidtwco Aug 7, 2018
0e5bda1
Label definition of captured variables in errors.
davidtwco Aug 7, 2018
56232c6
Improved how upvars are detected when presenting errors using prefixes.
davidtwco Aug 7, 2018
5ce865e
Add wasm32 simd128 target feature
gnzlbg Aug 7, 2018
020b073
add wasm_target_feature feature gate
gnzlbg Aug 7, 2018
877c469
Avoid increased alignment of TLS segments on Fuchsia
cramertj Aug 7, 2018
2cdaf3b
add feature-gate test
gnzlbg Aug 8, 2018
f4039af
Suggest comma when missing in macro call
estebank Aug 8, 2018
9876e38
Move SmallVec and ThinVec out of libsyntax
ljedrz Aug 5, 2018
1d436cf
Rollup merge of #52773 - ljedrz:unncecessary_patterns, r=nikomatsakis
cramertj Aug 8, 2018
88c74ef
Rollup merge of #53085 - ljedrz:cleanup_syntax_structures, r=Mark-Sim…
cramertj Aug 8, 2018
556995e
Rollup merge of #53094 - GuillaumeGomez:automatic-expand, r=nrc
cramertj Aug 8, 2018
6420186
Rollup merge of #53100 - VPashkov:issue-52456-improper_ctypes, r=eddyb
cramertj Aug 8, 2018
7683e1b
Rollup merge of #53110 - Xanewok:save-analysis-remap-path, r=nrc
cramertj Aug 8, 2018
b178548
Rollup merge of #53116 - jakllsch:netbsd-unsigned-char, r=alexcrichton
cramertj Aug 8, 2018
132b0b3
Rollup merge of #53129 - nikomatsakis:issue-51172-tweak-test, r=pnkfelix
cramertj Aug 8, 2018
e08561e
Rollup merge of #53131 - davidtwco:issue-52663-thread-local-static, r…
cramertj Aug 8, 2018
ae04dcc
Rollup merge of #53152 - michaelwoerister:reenable-drop-location-debu…
cramertj Aug 8, 2018
1480844
Rollup merge of #53154 - michaelwoerister:reenable-some-debuginfo-tes…
cramertj Aug 8, 2018
e4bc35e
Rollup merge of #53164 - davidtwco:issue-52663-span-decl-captured-var…
cramertj Aug 8, 2018
8f1ca0f
Rollup merge of #53179 - gnzlbg:patch-3, r=alexcrichton
cramertj Aug 8, 2018
51f3003
Rollup merge of #53180 - cramertj:tls-align, r=alexcrichton
cramertj Aug 8, 2018
8e477f4
Rollup merge of #53183 - estebank:println-comma, r=oli-obk
cramertj Aug 8, 2018
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
Suggest comma when missing in macro call
When missing a comma in a macro call, suggest it, regardless of
position. When a macro call doesn't match any of the patterns, check
if the call's token stream could be missing a comma between two idents,
and if so, create a new token stream containing the comma and try to
match against the macro patterns. If successful, emit the suggestion.
  • Loading branch information
estebank committed Aug 8, 2018
commit f4039affa338fc5640c102ac5786a491bc94201f
4 changes: 2 additions & 2 deletions src/libsyntax/ext/tt/macro_rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ fn generic_extension<'cx>(cx: &'cx mut ExtCtxt,
for lhs in lhses { // try each arm's matchers
let lhs_tt = match *lhs {
quoted::TokenTree::Delimited(_, ref delim) => &delim.tts[..],
_ => cx.span_bug(sp, "malformed macro lhs")
_ => continue,
};
match TokenTree::parse(cx, lhs_tt, arg.clone()) {
Success(_) => {
Expand All @@ -191,7 +191,7 @@ fn generic_extension<'cx>(cx: &'cx mut ExtCtxt,
err.span_suggestion_short(
comma_span,
"missing comma here",
",".to_string(),
", ".to_string(),
);
}
}
Expand Down
48 changes: 35 additions & 13 deletions src/libsyntax/tokenstream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,21 +186,43 @@ impl TokenStream {
/// Given a `TokenStream` with a `Stream` of only two arguments, return a new `TokenStream`
/// separating the two arguments with a comma for diagnostic suggestions.
pub(crate) fn add_comma(&self) -> Option<(TokenStream, Span)> {
// Used to suggest if a user writes `println!("{}" a);`
// Used to suggest if a user writes `foo!(a b);`
if let TokenStreamKind::Stream(ref slice) = self.kind {
if slice.len() == 2 {
let comma_span = match slice[0] {
TokenStream { kind: TokenStreamKind::Tree(TokenTree::Token(sp, _)) } |
TokenStream { kind: TokenStreamKind::Tree(TokenTree::Delimited(sp, _)) } => {
sp.shrink_to_hi()
let mut suggestion = None;
let mut iter = slice.iter().enumerate().peekable();
while let Some((pos, ts)) = iter.next() {
if let Some((_, next)) = iter.peek() {
match (ts, next) {
(TokenStream {
kind: TokenStreamKind::Tree(TokenTree::Token(_, token::Token::Comma))
}, _) |
(_, TokenStream {
kind: TokenStreamKind::Tree(TokenTree::Token(_, token::Token::Comma))
}) => {}
(TokenStream {
kind: TokenStreamKind::Tree(TokenTree::Token(sp, _))
}, _) |
(TokenStream {
kind: TokenStreamKind::Tree(TokenTree::Delimited(sp, _))
}, _) => {
let sp = sp.shrink_to_hi();
let comma = TokenStream {
kind: TokenStreamKind::Tree(TokenTree::Token(sp, token::Comma)),
};
suggestion = Some((pos, comma, sp));
}
_ => {}
}
_ => DUMMY_SP,
};
let comma = TokenStream {
kind: TokenStreamKind::Tree(TokenTree::Token(comma_span, token::Comma)),
};
let slice = RcSlice::new(vec![slice[0].clone(), comma, slice[1].clone()]);
return Some((TokenStream { kind: TokenStreamKind::Stream(slice) }, comma_span));
}
}
if let Some((pos, comma, sp)) = suggestion {
let mut new_slice = vec![];
let parts = slice.split_at(pos + 1);
new_slice.extend_from_slice(parts.0);
new_slice.push(comma);
new_slice.extend_from_slice(parts.1);
let slice = RcSlice::new(new_slice);
return Some((TokenStream { kind: TokenStreamKind::Stream(slice) }, sp));
}
}
None
Expand Down
12 changes: 11 additions & 1 deletion src/test/ui/macros/missing-comma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,22 @@
// except according to those terms.

macro_rules! foo {
($a:ident, $b:ident) => ()
($a:ident) => ();
($a:ident, $b:ident) => ();
($a:ident, $b:ident, $c:ident) => ();
($a:ident, $b:ident, $c:ident, $d:ident) => ();
($a:ident, $b:ident, $c:ident, $d:ident, $e:ident) => ();
}

fn main() {
println!("{}" a);
//~^ ERROR expected token: `,`
foo!(a b);
//~^ ERROR no rules expected the token `b`
foo!(a, b, c, d e);
//~^ ERROR no rules expected the token `e`
foo!(a, b, c d, e);
//~^ ERROR no rules expected the token `d`
foo!(a, b, c d e);
//~^ ERROR no rules expected the token `d`
}
28 changes: 25 additions & 3 deletions src/test/ui/macros/missing-comma.stderr
Original file line number Diff line number Diff line change
@@ -1,16 +1,38 @@
error: expected token: `,`
--> $DIR/missing-comma.rs:16:19
--> $DIR/missing-comma.rs:20:19
|
LL | println!("{}" a);
| ^

error: no rules expected the token `b`
--> $DIR/missing-comma.rs:18:12
--> $DIR/missing-comma.rs:22:12
|
LL | foo!(a b);
| -^
| |
| help: missing comma here

error: aborting due to 2 previous errors
error: no rules expected the token `e`
--> $DIR/missing-comma.rs:24:21
|
LL | foo!(a, b, c, d e);
| -^
| |
| help: missing comma here

error: no rules expected the token `d`
--> $DIR/missing-comma.rs:26:18
|
LL | foo!(a, b, c d, e);
| -^
| |
| help: missing comma here

error: no rules expected the token `d`
--> $DIR/missing-comma.rs:28:18
|
LL | foo!(a, b, c d e);
| ^

error: aborting due to 5 previous errors