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

Change default for use_try_shorthand to true? #4205

Closed
jhpratt opened this issue May 25, 2020 · 5 comments
Closed

Change default for use_try_shorthand to true? #4205

jhpratt opened this issue May 25, 2020 · 5 comments

Comments

@jhpratt
Copy link
Member

jhpratt commented May 25, 2020

Given that the try! macro has been deprecated since rustc 1.39.0 (~6 months ago), would it make sense to change the default for this to true? I see there's a 2.0 release upcoming — perhaps that's a decent time to make the change?

@topecongiro
Copy link
Contributor

Sounds good to me.

@topecongiro topecongiro modified the milestone: 2.0.0 May 26, 2020
@topecongiro
Copy link
Contributor

Ah, sorry, I thought that the option is unstable, but it's already stabilized. In that case, I would rather keep the current behavior.

Thank you for your suggestion, but we will close this as won't fix.

@jhpratt
Copy link
Member Author

jhpratt commented May 26, 2020

That's why I'd suggested it as a possible change for 2.0, as I presume breaking changes are fine then?

@jhpratt
Copy link
Member Author

jhpratt commented Jun 29, 2020

Looks like I'm not able to reopen this to address the previous point. @topecongiro can it please be addressed?

@topecongiro
Copy link
Contributor

Sorry for the late reply. As you mentioned, it is possible to add breaking changes to 2.0 release (in fact, we are planning to make quite a few numbers of breaking changes).

I've reconsidered changing the default value of use_try_shorthand. I still think that the default value should be false by default.

There are mainly two reasons. One is that I would like to minimize the possibility of breaking the code or changing the semantic of the code when using the default configuration option. In this regard, converting the try! macro to the ? operator may break the code against something like the following:

macro_rules! try {
    ($val:expr) => {
        println!("{:?}", $val);
    }
}

fn main() -> std::io::Result<()> {
    try!("hello, world");
    Ok(())
}

I understand that the code like this does not appear in practice, though I would like to be conservative here.

Also, I think that converting try! to ? is often a one-time operation, rather than something that needs to be repeated. For historical reasons, rustfmt has this option, but in retrospect, this kind of conversion should be the responsibility of tools like rustfix.

Again, I wholeheartedly thank you for your comment and willingness to improve rustfmt. Your comment allowed me to rethink about this config option.

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

No branches or pull requests

2 participants