Skip to content

errors silenced by presence of async function with errors #111537

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

Open
clubby789 opened this issue May 13, 2023 · 1 comment
Open

errors silenced by presence of async function with errors #111537

clubby789 opened this issue May 13, 2023 · 1 comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug.

Comments

@clubby789
Copy link
Contributor

clubby789 commented May 13, 2023

I tried this code:

pub fn bar() {
    match true {};
}

pub async fn foo() {
    match false {};
}

I expected to see this happen: Two error[E0004]: non-exhaustive patterns: type bool is non-empty

Instead, this happened: Only one is reported, in the async function. The error in the async function is still reported if the order is flipped. Making both functions sync or async correctly reports both errors. If there is any code following the faulty match, it is always reported as unreachable, despite no error being emitted for the preceding line in the sync function.

Found in #111533 test

Meta

rustc --version --verbose:

rustc 1.71.0-nightly (4a59ba4d5 2023-05-12)
binary: rustc
commit-hash: 4a59ba4d54a3ec0d8ea1e82b7eeb5c8b0162de04
commit-date: 2023-05-12
host: x86_64-unknown-linux-gnu
release: 1.71.0-nightly
LLVM version: 16.0.2
@clubby789 clubby789 added C-bug Category: This is a bug. A-diagnostics Area: Messages for errors, warnings, and lints labels May 13, 2023
@clubby789
Copy link
Contributor Author

Actually this seems a bit more general.

pub fn bar() {
    usize::MAX + 1;
    return;
}

pub async fn foo() {
    usize::MAX + 1;
    return;
}

only fires one error (in the sync function this time), but two warnings (for unused arithmetic)

This also happens if the errors are slightly different:

pub fn bar() {
    match true {};
    return;
}

pub async fn foo() {
    usize::MAX + 1;
    return;
}
warning: unreachable statement
 --> poc.rs:3:5
  |
2 |     match true {};
  |     ------------- any code following this expression is unreachable
3 |     return;
  |     ^^^^^^^ unreachable statement
  |
  = note: `#[warn(unreachable_code)]` on by default

error[E0004]: non-exhaustive patterns: type `bool` is non-empty
 --> poc.rs:2:11
  |
2 |     match true {};
  |           ^^^^
  |
  = note: the matched value is of type `bool`
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern as shown
  |
2 ~     match true {
3 +         _ => todo!(),
4 ~     };
  |

The match error now only in the sync function, and the unused arithmetic warning is missing

@clubby789 clubby789 changed the title second 'non-empty patterns' error silenced by async function errors silenced by presence of async function with errors May 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

1 participant