-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #7707 - Jarcho:suspicious_else_proc_mac, r=Manishearth
Don't lint `suspicious_else_formatting` inside proc-macros fixes: #7650 I'll add a test for this one soon. changelog: Don't lint `suspicious_else_formatting` inside proc-macros
- Loading branch information
Showing
4 changed files
with
124 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
tests/ui/auxiliary/proc_macro_suspicious_else_formatting.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// compile-flags: --emit=link | ||
// no-prefer-dynamic | ||
|
||
#![crate_type = "proc-macro"] | ||
|
||
extern crate proc_macro; | ||
use proc_macro::{token_stream, Delimiter, Group, Ident, Span, TokenStream, TokenTree}; | ||
use std::iter::FromIterator; | ||
|
||
fn read_ident(iter: &mut token_stream::IntoIter) -> Ident { | ||
match iter.next() { | ||
Some(TokenTree::Ident(i)) => i, | ||
_ => panic!("expected ident"), | ||
} | ||
} | ||
|
||
#[proc_macro_derive(DeriveBadSpan)] | ||
pub fn derive_bad_span(input: TokenStream) -> TokenStream { | ||
let mut input = input.into_iter(); | ||
assert_eq!(read_ident(&mut input).to_string(), "struct"); | ||
let ident = read_ident(&mut input); | ||
let mut tys = match input.next() { | ||
Some(TokenTree::Group(g)) if g.delimiter() == Delimiter::Parenthesis => g.stream().into_iter(), | ||
_ => panic!(), | ||
}; | ||
let field1 = read_ident(&mut tys); | ||
tys.next(); | ||
let field2 = read_ident(&mut tys); | ||
|
||
<TokenStream as FromIterator<TokenTree>>::from_iter( | ||
[ | ||
Ident::new("impl", Span::call_site()).into(), | ||
ident.into(), | ||
Group::new( | ||
Delimiter::Brace, | ||
<TokenStream as FromIterator<TokenTree>>::from_iter( | ||
[ | ||
Ident::new("fn", Span::call_site()).into(), | ||
Ident::new("_foo", Span::call_site()).into(), | ||
Group::new(Delimiter::Parenthesis, TokenStream::new()).into(), | ||
Group::new( | ||
Delimiter::Brace, | ||
<TokenStream as FromIterator<TokenTree>>::from_iter( | ||
[ | ||
Ident::new("if", field1.span()).into(), | ||
Ident::new("true", field1.span()).into(), | ||
{ | ||
let mut group = Group::new(Delimiter::Brace, TokenStream::new()); | ||
group.set_span(field1.span()); | ||
group.into() | ||
}, | ||
Ident::new("if", field2.span()).into(), | ||
Ident::new("true", field2.span()).into(), | ||
{ | ||
let mut group = Group::new(Delimiter::Brace, TokenStream::new()); | ||
group.set_span(field2.span()); | ||
group.into() | ||
}, | ||
] | ||
.iter() | ||
.cloned(), | ||
), | ||
) | ||
.into(), | ||
] | ||
.iter() | ||
.cloned(), | ||
), | ||
) | ||
.into(), | ||
] | ||
.iter() | ||
.cloned(), | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters