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

Switch non exhaustive syntax tree enums to use #[non_exhaustive] #1067

Merged
merged 1 commit into from
Mar 27, 2022

Conversation

dtolnay
Copy link
Owner

@dtolnay dtolnay commented Sep 22, 2021

This follows through on the comments on the __TestExhaustive variants promising that their purpose will be substituted with a deny(reachable) rustc lint once one is available.

syn/src/expr.rs

Lines 247 to 251 in ac68efa

// Once `deny(reachable)` is available in rustc, Expr will be
// reimplemented as a non_exhaustive enum.
// https://github.com/rust-lang/rust/issues/44109#issuecomment-521781237
#[doc(hidden)]
__TestExhaustive(crate::private),

That lint is now landing as non_exhaustive_omitted_patterns in Rust 1.57. The correct way to use it for checking exhaustivity of a match is:

match expr {
    Expr::Array(e) => {...}
    Expr::Assign(e) => {...}
    ...
    Expr::Yield(e) => {...}

    #[cfg_attr(test, deny(non_exhaustive_omitted_patterns))]
    _ => { /* some sane fallback */ }
}

@dtolnay
Copy link
Owner Author

dtolnay commented Sep 22, 2021

Closing, to be reopened when 1.57.0 stable is out.

@dtolnay dtolnay closed this Sep 22, 2021
@dtolnay dtolnay reopened this Mar 27, 2022
This follows through on the comments on the __TestExhaustive variants
promising that their purpose will be substituted with a deny(reachable)
rustc lint once one is available.

That lint is now landing as non_exhaustive_omitted_patterns in Rust 1.57.
The correct way to use it for checking exhaustivity of a match is:

    match expr {
        Expr::Array(e) => {...}
        Expr::Assign(e) => {...}
        ...
        Expr::Yield(e) => {...}

        #[cfg_attr(test, deny(non_exhaustive_omitted_patterns))]
        _ => { /* some sane fallback */ }
    }
@dtolnay dtolnay merged commit be520c1 into master Mar 27, 2022
@dtolnay dtolnay deleted the nonexhaustive branch March 27, 2022 21:33
Repository owner locked and limited conversation to collaborators Mar 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant