Skip to content

Match guards are silently ignored #4957

Description

@u7k4rs6

Summary

Match guards are parsed and name resolved, but never type checked or compiled. An arm with a guard is taken whenever its pattern matches, and the guard never runs. Pattern support (#2082) lists guards as not done yet, but right now they compile without any error, so the program just behaves differently.

Reproducer

I tried this code:

#![feature(no_core)]
#![no_core]

fn never() -> bool {
    false
}

fn main() -> i32 {
    match 0 {
        0 if never() => 1,
        _ => 0,
    }
}

Does the code make use of any (1.49) nightly feature ?

  • Nightly

Godbolt link

No response

Actual behavior

The program exits with 1, and never is never called. A guard that isn't a bool, like 0 if 5 => ..., is accepted too.

Expected behavior

The guard runs, is false, and the program exits with 0.

GCC Version

36b5a15

Activity

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

      Issue actions