Skip to content

Uses of "do catch" suggest non-working "try" instead #53672

Closed

Description

@RalfJung

I have code like this

    let action : Result<Action, Error> = do catch {
        let signed_action = base64::decode(form.signed_action.as_str())?;
        let signed_action: SignedAction = deserialize_from_slice(signed_action.as_slice())?;
        signed_action.verify(&config.secrets.action_signing_key)?
    };

after updating nightly, this does not compile any more. It says

error: found removed `do catch` syntax
   --> src/routes.rs:164:42
    |
164 |     let action : Result<Action, Error> = do catch {
    |                                          ^^
    |
    = help: Following RFC #2388, the new non-placeholder syntax is `try`

So I tried

    let action : Result<Action, Error> = try {
        let signed_action = base64::decode(form.signed_action.as_str())?;
        let signed_action: SignedAction = deserialize_from_slice(signed_action.as_slice())?;
        signed_action.verify(&config.secrets.action_signing_key)?
    };

but that does not compile either

error: expected identifier, found keyword `let`
   --> src/routes.rs:164:9
    |
163 |     let action : Result<Action, Error> = try {
    |                                          --- while parsing this struct
164 |         let signed_action = base64::decode(form.signed_action.as_str())?;
    |         ^^^ expected identifier, found keyword

I have also tried try catch, to no avail.

At the very least, the error message about "do catch" needs to be improved, as its advise is clearly incorrect. But also, I wonder what I should do now :D I guess I'll use an immediately-applied closure again...

Activity

  1. added
    A-diagnosticsArea: Messages for errors, warnings, and lints
    C-enhancementCategory: An issue proposing an enhancement or a PR with one.
    on Aug 24, 2018
  2. added
    C-bugCategory: This is a bug.
    and removed
    A-diagnosticsArea: Messages for errors, warnings, and lints
    C-enhancementCategory: An issue proposing an enhancement or a PR with one.
    on Aug 25, 2018
  3. Centril commented on Aug 25, 2018

    @Centril
    Contributor
  4. scottmcm commented on Aug 25, 2018

    @scottmcm
    Member

    @RalfJung Oh, right, the error message should mention that you need to be in the 2018 edition.

    (I could also make do catch or do try work temporarily in 2015, I suppose...)

  5. self-assigned this
    on Aug 25, 2018
  6. durka commented on Aug 25, 2018

    @durka
    Contributor

    So is do catch going to be removed from 2015 with no replacement? That's not very nice.

  7. Centril commented on Aug 27, 2018

    @Centril
    Contributor

    @durka It was never the plan to stabilize do catch; it was always a temporary syntax.

  8. scottmcm commented on Aug 27, 2018

    @scottmcm
    Member

    @durka Do you have a case where you have nightly 2015 code that cannot migrate to nightly 2018?

  9. jonhoo commented on Sep 6, 2018

    @jonhoo
    Contributor

    I'm confused. Even with

    #![feature(rust_2018_preview)]

    the syntax

    let foo: Result<_, _> = try {
        // ...
    };

    still does not work?

  10. jonhoo commented on Sep 6, 2018

    @jonhoo
    Contributor

    Ahh, it looks like you also need edition = 2018 in your Cargo.toml as outlined in the transition guide.

  11. varkor commented on Sep 13, 2018

    @varkor
    Contributor

    This was very confusing to run into (for some reason this error occurs on Travis, but not locally for me). It'd make much more sense to me to allow do catch before the 2018 edition.

  12. added 2 commits that reference this issue on Feb 22, 2019
    52fd337
    bcb7dce
  13. scottmcm commented on Feb 23, 2019

    @scottmcm
    Member

    I've closed this now that there's an additional message about the edition on try. That's not amazing, but this is also a nightly-only thing.

    Have you perchance been able to use try{} in nightly 2018 edition now, @RalfJung?

  14. RalfJung commented on Feb 23, 2019

    @RalfJung
    MemberAuthor

    Have you perchance been able to use try{} in nightly 2018 edition now, @RalfJung?

    Yes, they seem to work as intended. :)

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

Metadata

Metadata

Assignees

Labels

C-bugCategory: This is a bug.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions