-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Panic on relm macro with "there must be a else
here" message
#3741
Comments
Small repro proc-derive for what I think is the same issue: //test_derive/src/lib.rs
//dependencies for test_derive:
//proc-macro2 = "0.4"
//quote = "0.6"
//syn = "0.15"
extern crate proc_macro;
use quote::quote_spanned;
#[proc_macro_derive(Test)]
pub fn derive_test(input_stream: proc_macro::TokenStream) -> proc_macro::TokenStream {
let input: syn::DeriveInput = syn::parse(input_stream).unwrap();
let name = input.ident;
let span = name.span();
let mut cases = Vec::new();
for i in 0..3 {
cases.push(quote_spanned!{span=>
if n == #i {
println!("case {}", #i);
} else
});
}
quote_spanned!(span=>
fn code(n: i32) {
#(#cases)*
{
println!("no case matched");
}
}
).into()
} //src/main.rs
use test_derive::Test;
#[derive(Test)]
struct Test();
fn main() {
code(2);
} Both splitting the quote into multiple pieces and applying a span ( |
Minimized example from @SNCPlay42's code: //test_macro/src/lib.rs
//dependencies for test_macro:
//proc-macro2 = "0.4"
//quote = "0.6"
extern crate proc_macro;
use quote::{quote, quote_spanned};
#[proc_macro]
pub fn macro_test(input_stream: proc_macro::TokenStream) -> proc_macro::TokenStream {
let first_token = input_stream.into_iter().next().unwrap();
let span: proc_macro2::Span = first_token.span().into();
let clause = quote_spanned!(span=> {});
quote!(
fn code() {
if true #clause else #clause
}
).into()
}
//src/lib.rs
test_macro::macro_test!(2); Both if and else clauses need to have a span from the input stream to trigger ICE. |
A zero crates.io dependency version of the minimal example above: //test_macro/src/lib.rs
//no dependencies for test_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()),
])
})),
])
}
//src/lib.rs
test_macro::macro_test!(2); |
Taken from work on rust-lang/rust-clippy#3741. I think this is a useful test to have because it tests * the `run-pass` header * the `aux-build` header, building auxiliary files * the `no-prefer-dynamic` header * proc-macro crate interactions with all of the above * running of UI tests that include auxiliary files There's no tests for any of the above right now.
Fix ICE in suspicious_else_formatting Fixes #3741
I'm still getting a panic in the latest version, however the error message seems to have changed:
$ cargo clippy -V
clippy 0.0.212 (d516925e 2019-04-12) |
Huh, that should definitely be fixed, I'll have another look, thanks! |
This was causing two different ICEs in rust-lang#3741. The first was fixed in rust-lang#3925. The second one is fixed with this commit: We just don't `expect` anymore. If the snippet doesn't contain an `else`, we stop emitting the lint because it's not a suspiciously formatted else anyway.
Thanks a lot for the fix! It's working with #3960 :-) |
Remove `except` in suspicious_else_formatting 96c34e8 contains the fix: This was causing two different ICEs in #3741. The first was fixed in #3925. The second one is fixed with this commit: We just don't `expect` anymore. If the snippet doesn't contain an `else`, we stop emitting the lint because it's not a suspiciously formatted else anyway. Unfortunately I wasn't able to provide a minimal test case, but I think it's fine since it's just ignoring the `None` case now. And ad27e3f cleans up the lint code to use `if_chain`. Fixes #3741 once more.
Taken from work on rust-lang/rust-clippy#3741. I think this is a useful test to have because it tests * the `run-pass` header * the `aux-build` header, building auxiliary files * the `no-prefer-dynamic` header * proc-macro crate interactions with all of the above * running of UI tests that include auxiliary files There's no tests for any of the above right now.
Taken from work on rust-lang/rust-clippy#3741. I think this is a useful test to have because it tests * the `run-pass` header * the `aux-build` header, building auxiliary files * the `no-prefer-dynamic` header * proc-macro crate interactions with all of the above * running of UI tests that include auxiliary files There's no tests for any of the above right now.
Taken from work on rust-lang/rust-clippy#3741. I think this is a useful test to have because it tests * the `run-pass` header * the `aux-build` header, building auxiliary files * the `no-prefer-dynamic` header * proc-macro crate interactions with all of the above * running of UI tests that include auxiliary files There's no tests for any of the above right now.
Now that rust-lang/rust-clippy#3741 has been fixed this should work.
clippy 0.0.212 (1b89724 2019-01-15)
When using clippy on a project with
#[widget]
macro from "relm" crate I get the following panic:Normal
cargo build
works just fineI've created small project where this crash can be easily reproduced.
Here are repro steps:
Thank you!
The text was updated successfully, but these errors were encountered: