Comment

Comment by demurgos

What I want is something similar to the switch from lexical to non-lexical lifetimes; but for enums and pattern matching. `@` is a construct depending on lexical scoping

In following code, it would be nice if the second match could use the early return from the first match to avoid extra checks. It would also be nice if it worked across function boundaries. It would help removing boilerplate conversions or some `unreachable!()` branches.

    enum Auth { Guest, User(u32), Bot(u32) }
    
    fn check_permissions(Auth &auth) -> Result<Permission, PermissionError> {
    match auth {
        Auth::Guest => return PermissionError::Unauthorized,
        Auth::User(_) | Auth::Bot(_) => { ... }
    // ... 
    match auth {
        Auth::User(_) => {...}
        Auth::Bot(_) => {...}
        // At this point the compiler should know that `Auth::Guest` is not possible
    }
parent demurgos 2 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton