Skip to content

Commit

Permalink
Auto merge of rust-lang#3925 - phansch:3741, r=flip1995
Browse files Browse the repository at this point in the history
Fix ICE in suspicious_else_formatting

Fixes rust-lang#3741
  • Loading branch information
bors committed Apr 9, 2019
2 parents 949f584 + 3ab8038 commit 37f5c1e
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
3 changes: 2 additions & 1 deletion clippy_lints/src/formatting.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::utils::{differing_macro_contexts, in_macro, snippet_opt, span_note_and_lint};
use rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass};
use rustc::lint::{in_external_macro, EarlyContext, EarlyLintPass, LintArray, LintPass};
use rustc::{declare_tool_lint, lint_array};
use syntax::ast;
use syntax::ptr::P;
Expand Down Expand Up @@ -150,6 +150,7 @@ fn check_else(cx: &EarlyContext<'_>, expr: &ast::Expr) {
if (is_block(else_) || unsugar_if(else_).is_some())
&& !differing_macro_contexts(then.span, else_.span)
&& !in_macro(then.span)
&& !in_external_macro(cx.sess, expr.span)
{
// workaround for rust-lang/rust#43081
if expr.span.lo().0 == 0 && expr.span.hi().0 == 0 {
Expand Down
37 changes: 37 additions & 0 deletions tests/ui/crashes/auxiliary/proc_macro_crash.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// no-prefer-dynamic
// ^ compiletest by default builds all aux files as dylibs, but we don't want that for proc-macro
// crates. If we don't set this, compiletest will override the `crate_type` attribute below and
// compile this as dylib. Removing this then causes the test to fail because a `dylib` crate can't
// contain a proc-macro.

#![feature(repr128)]
#![crate_type = "proc-macro"]

extern crate proc_macro;

use proc_macro::{Delimiter, Group, Ident, Span, TokenStream, TokenTree};
use std::iter::FromIterator;

#[proc_macro]
pub fn macro_test(input_stream: TokenStream) -> TokenStream {
let first_token = input_stream.into_iter().next().unwrap();
let span = first_token.span();

TokenStream::from_iter(vec![
TokenTree::Ident(Ident::new("fn", Span::call_site())),
TokenTree::Ident(Ident::new("code", Span::call_site())),
TokenTree::Group(Group::new(Delimiter::Parenthesis, TokenStream::new())),
TokenTree::Group(Group::new(Delimiter::Brace, {
let mut clause = Group::new(Delimiter::Brace, TokenStream::new());
clause.set_span(span);

TokenStream::from_iter(vec![
TokenTree::Ident(Ident::new("if", Span::call_site())),
TokenTree::Ident(Ident::new("true", Span::call_site())),
TokenTree::Group(clause.clone()),
TokenTree::Ident(Ident::new("else", Span::call_site())),
TokenTree::Group(clause.clone()),
])
})),
])
}
12 changes: 12 additions & 0 deletions tests/ui/crashes/ice-3741.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// aux-build:proc_macro_crash.rs
// run-pass

#![feature(proc_macro_hygiene)]
#![warn(clippy::suspicious_else_formatting)]

extern crate proc_macro_crash;
use proc_macro_crash::macro_test;

fn main() {
macro_test!(2);
}

0 comments on commit 37f5c1e

Please sign in to comment.