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

Fix ICE in suspicious_else_formatting #3925

merged 3 commits into from Apr 9, 2019
Changes from all commits
File filter
Filter file types
Failed to load comments.
Jump to
Jump to file
Failed to load files.


Just for now

@@ -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;
@@ -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 {
@@ -0,0 +1,37 @@
// no-prefer-dynamic
This conversation was marked as resolved by phansch

This comment has been minimized.


phansch Apr 8, 2019
Author Member

I should figure out why this is needed and document it here.

// ^ 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.

#![crate_type = "proc-macro"]

extern crate proc_macro;

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

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

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());

TokenTree::Ident(Ident::new("if", Span::call_site())),
TokenTree::Ident(Ident::new("true", Span::call_site())),
TokenTree::Ident(Ident::new("else", Span::call_site())),
@@ -0,0 +1,12 @@
// run-pass


extern crate proc_macro_crash;
use proc_macro_crash::macro_test;

fn main() {