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

rustfix: Autofix try! macro in edition lint to use ? operator #65148

Closed
tesuji opened this issue Oct 6, 2019 · 10 comments
Closed

rustfix: Autofix try! macro in edition lint to use ? operator #65148

tesuji opened this issue Oct 6, 2019 · 10 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-edition-2018 Area: The 2018 edition A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-feature-request Category: A feature request, i.e: not implemented / a PR. T-lang Relevant to the language team, which will review and decide on the PR/issue.

Comments

@tesuji
Copy link
Contributor

tesuji commented Oct 6, 2019

Now try! macro has been deprecated in #62672. I think it's time to automatically
fix try!(expr) to expr? in edition lint.

@tesuji

This comment has been minimized.

@rustbot rustbot added A-diagnostics Area: Messages for errors, warnings, and lints A-edition-2018-lints A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 6, 2019
@jonas-schievink jonas-schievink added the C-feature-request Category: A feature request, i.e: not implemented / a PR. label Oct 6, 2019
@jugglerchris
Copy link
Contributor

I've got code with a load of r#try so this one's bugging me. :-)

I'm interested in working on it if no-one else is. I haven't worked on rustc so there'll be some learning for me to do first.

@taiki-e
Copy link
Member

taiki-e commented Oct 10, 2019

FYI: rustfmt already provides a feature to replace try!(expr) to expr?.: https://github.com/rust-lang/rustfmt/blob/master/Configurations.md#use_try_shorthand

@Centril
Copy link
Contributor

Centril commented Oct 12, 2019

iirc we took a fairly explicit decision to migrate to r#try!(...) because migrating to ? can break code. And we cannot be sure everyone has migrated to 2018. cc @rust-lang/lang

@Centril Centril added T-lang Relevant to the language team, which will review and decide on the PR/issue. I-nominated and removed T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 12, 2019
@tesuji
Copy link
Contributor Author

tesuji commented Oct 12, 2019

But this is edition lint for anyone want to migrate from 2015 to 2018 edition.

@jugglerchris
Copy link
Contributor

@Centril under what circumstances can ? break code compared to r#try!(...)?

@Centril
Copy link
Contributor

Centril commented Oct 12, 2019

The lowering of ? has ::from(...) and uses type inference more as compared to try!(...).

@nikomatsakis
Copy link
Contributor

We discussed this in our lang team meeting on 2019-10-17. We concluded that we would prefer not to try to create such a lint. In short, nothing has changed since the Edition handover: it is still hard to get this lint correct and it doesn't seem worth the effort to maintain it (and fix the inevitable bugs). We prefer the rustfmt "normalize try!" option. Hence, I'm going to close the issue for now. Thanks for the suggestion @lzutao.

@joshtriplett
Copy link
Member

@nikomatsakis The one downside of using rustfmt for this: it's difficult to disable the rest of rustfmt, if you don't want to combine reformatting your code with substantive changes to your code. Would it be possible to add (and document) a method for converting try! to ? without reformatting code?

@nikomatsakis
Copy link
Contributor

@joshtriplett Personally, I think you should reformat the rest of your code first, and then enable the rustfmt option to convert try! to ? (I don't believe it does that by default). Of course, I'm presuming that you want to reformat your code (which I think everyone should, though I realize others will disagree). But I think that the set of people who don't want to reformat their code is fairly small -- and the set than then further want to remove r#try smaller still. This all argues that supporting a lint in the compiler is pretty overkill.

That said, I think that there used to be some tool for converting try! to ? that we used back when ? was first introduced. Probably it could be dusted off and put to use again. I don't remember much about it though -- I want to say @japaric wrote it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-edition-2018 Area: The 2018 edition A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-feature-request Category: A feature request, i.e: not implemented / a PR. T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

9 participants