Skip to content

Support overriding the ? behavior locally (by redefining the try! macro) #71643

Closed
@stevenroose

Description

@stevenroose

When the ? operator was implemented, it looks like it was meant to be equivalent to the try! macro.

This has the nice property that overriding the try! macro in your own project, allows you to capture all the ? invocations and add additional logic like logging file and line number or wrapping that information into a new error object.

Sadly it seems that the ? operator is no longer equivalent to the try! macro. So overriding try! does not change the behavior of ? in your project. It would be awesome if this would be made possible.

Activity

jonas-schievink

jonas-schievink commented on Apr 28, 2020

@jonas-schievink
Contributor

This is covered partially by #42327, and anything beyond that would require an RFC, so closing in favor of that.

stevenroose

stevenroose commented on Apr 28, 2020

@stevenroose
Author

How would it work for the trait to know the file and line number where the error was generated?

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @stevenroose@jonas-schievink

        Issue actions

          Support overriding the ? behavior locally (by redefining the try! macro) · Issue #71643 · rust-lang/rust