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

Inclusive range patterns are always output as ..., which is linted against. #650

Closed
jebrosen opened this issue Jun 19, 2019 · 3 comments · Fixed by #652
Closed

Inclusive range patterns are always output as ..., which is linted against. #650

jebrosen opened this issue Jun 19, 2019 · 3 comments · Fixed by #652

Comments

@jebrosen
Copy link
Contributor

At https://github.com/dtolnay/syn/blob/master/src/expr.rs#L3706, ... is output even if the input was ..= in range patterns. It looks like this was decided on in #275.

In rust-lang/rust#61342 the use of ... was upgraded to a warn-by-default lint.

Reproduction example:

#[proc_macro]
pub fn passthru(input: TokenStream) -> TokenStream {
    let parsed: syn::Item = syn::parse(input).unwrap();
    let tokens = quote! { #parsed };
    tokens.into()
}

passthru!{
    fn a() {
        match 1 {
            2..=3 => {},
            _ => {},
        }
    }
}
warning: `...` range patterns are deprecated
  --> consumer2018/src/main.rs:23:14
   |
23 |             2..=3 => {},
   |              ^^^ help: use `..=` for an inclusive range
   |

The error is especially confusing because the Span is preserved.

Discovered via rwf2/Rocket#1033.

@dtolnay
Copy link
Owner

dtolnay commented Jun 19, 2019

I would accept a PR to emit ranges as ..= now that the new syntax is well supported.

@jebrosen
Copy link
Contributor Author

I'd be more than happy to work on adding that.

What is syn's policy on version support for these cases? IOW, does it need to be done conditionally based on whether the running rustc supports ..= in patterns?

@dtolnay
Copy link
Owner

dtolnay commented Jun 19, 2019

Ah, good thought! I would be okay with either way. It would also be fine to make the behavior conditional later only if the simple change turns out to be disruptive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants