Skip to content

[WIP] Lint self-overlapping or-patterns under guard #143541

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Nadrieril
Copy link
Member

This adds an error on or-patterns under match guard that may cause the guard to be run more than once, such as true | true if f(). This is for crater purposes.

r? ghost

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Jul 6, 2025
@rust-log-analyzer
Copy link
Collaborator

The job x86_64-gnu-tools failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
[RUSTC-TIMING] twox_hash test:false 1.198
   Compiling rustc_proc_macro v0.0.0 (/checkout/compiler/rustc_proc_macro)
[RUSTC-TIMING] rustc_proc_macro test:false 12.774
   Compiling rustc_infer v0.0.0 (/checkout/compiler/rustc_infer)
error: pattern overlaps with or-alternative under a guard
   --> compiler/rustc_infer/src/infer/relate/lattice.rs:154:13
    |
154 |             (&ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }), _)
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
155 |             | (_, &ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }))
    |               ------------------------------------------------------- overlaps with

error: pattern overlaps with or-alternative under a guard
   --> compiler/rustc_infer/src/infer/relate/type_relating.rs:191:13
    |
191 |             (&ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }), _)
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
192 |             | (_, &ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }))
    |               ------------------------------------------------------- overlaps with

[RUSTC-TIMING] rustc_infer test:false 5.485
error: could not compile `rustc_infer` (lib) due to 2 previous errors
warning: build failed, waiting for other jobs to finish...
[RUSTC-TIMING] regex_automata test:false 30.453

@Nadrieril
Copy link
Member Author

@bors try

bors added a commit that referenced this pull request Jul 7, 2025
…, r=<try>

[WIP] Lint self-overlapping or-patterns under guard

This adds an error on or-patterns under match guard that may cause the guard to be run more than once, such as `true | true if f()`. This is for crater purposes.

r? ghost
@bors
Copy link
Collaborator

bors commented Jul 7, 2025

⌛ Trying commit c0fda28 with merge 3ce2ac6...

@bors
Copy link
Collaborator

bors commented Jul 7, 2025

💔 Test failed - checks-actions

@bors bors added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jul 7, 2025
@rust-log-analyzer
Copy link
Collaborator

The job dist-x86_64-linux failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 30.49s
##[endgroup]
[2025-07-07T20:21:10.159Z INFO  opt_dist::timer] Section `Stage 1 (Rustc PGO)` starts
[2025-07-07T20:21:10.159Z INFO  opt_dist::timer] Section `Stage 1 (Rustc PGO) > Build PGO instrumented rustc and LLVM` starts
[2025-07-07T20:21:10.159Z INFO  opt_dist::exec] Executing `RUST_BACKTRACE=full python3 /checkout/x.py build --target x86_64-unknown-linux-gnu --host x86_64-unknown-linux-gnu --stage 2 library/std --set rust.llvm-bitcode-linker=false --set build.extended=false --set rust.codegen-backends=['llvm'] --set rust.deny-warnings=false --rust-profile-generate /tmp/tmp-multistage/opt-artifacts/rustc-pgo --set llvm.thin-lto=false --set llvm.link-shared=true [at /checkout/obj]`
Unknown option: -C
usage: git [--version] [--help] [-c name=value]
           [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
           [-p|--paginate|--no-pager] [--no-replace-objects] [--bare]
           [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
---
   Compiling rustc_pattern_analysis v0.0.0 (/checkout/compiler/rustc_pattern_analysis)
   Compiling rustc_ast_lowering v0.0.0 (/checkout/compiler/rustc_ast_lowering)
   Compiling rustc_query_impl v0.0.0 (/checkout/compiler/rustc_query_impl)
   Compiling rustc_smir v0.0.0 (/checkout/compiler/rustc_smir)
error: pattern overlaps with or-alternative under a guard
   --> compiler/rustc_transmute/src/layout/tree.rs:216:13
    |
216 |             (Self::Seq(elts), other) | (other, Self::Seq(elts)) if elts.len() == 0 => other,
    |             ^^^^^^^^^^^^^^^^^^^^^^^^   ------------------------ overlaps with

error: pattern overlaps with or-alternative under a guard
   --> compiler/rustc_transmute/src/layout/tree.rs:236:13
    |
236 |             (Self::Alt(alts), other) | (other, Self::Alt(alts)) if alts.len() == 0 => other,
    |             ^^^^^^^^^^^^^^^^^^^^^^^^   ------------------------ overlaps with

[RUSTC-TIMING] rustc_transmute test:false 0.419
error: could not compile `rustc_transmute` (lib) due to 2 previous errors
warning: build failed, waiting for other jobs to finish...
error: pattern overlaps with or-alternative under a guard
   --> compiler/rustc_infer/src/infer/relate/lattice.rs:154:13
    |
154 |             (&ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }), _)
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
155 |             | (_, &ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }))
    |               ------------------------------------------------------- overlaps with

error: pattern overlaps with or-alternative under a guard
   --> compiler/rustc_infer/src/infer/relate/type_relating.rs:191:13
    |
191 |             (&ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }), _)
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
192 |             | (_, &ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }))
    |               ------------------------------------------------------- overlaps with

[RUSTC-TIMING] rustc_infer test:false 2.298
error: could not compile `rustc_infer` (lib) due to 2 previous errors
[RUSTC-TIMING] rustc_symbol_mangling test:false 5.993
[RUSTC-TIMING] rustc_smir test:false 6.963
---
[2025-07-07T20:34:16.865Z INFO  opt_dist::utils] Free disk space: 1.28 TiB out of total 2.16 TiB (40.59% used)
Error: Optimized build pipeline has failed

Caused by:
    Command RUST_BACKTRACE=full python3 /checkout/x.py build --target x86_64-unknown-linux-gnu --host x86_64-unknown-linux-gnu --stage 2 library/std --set rust.llvm-bitcode-linker=false --set build.extended=false --set rust.codegen-backends=['llvm'] --set rust.deny-warnings=false --rust-profile-generate /tmp/tmp-multistage/opt-artifacts/rustc-pgo --set llvm.thin-lto=false --set llvm.link-shared=true [at /checkout/obj] has failed with exit code Some(1)

Stack backtrace:
   0: <anyhow::Error>::msg::<alloc::string::String>
             at /rust/deps/anyhow-1.0.98/src/backtrace.rs:27:14
   1: <opt_dist::exec::CmdBuilder>::run
             at /rustc/3ce2ac6487b9c522c8e56d4cfe9c254b5a2adc46/src/tools/opt-dist/src/exec.rs:80:17
   2: <opt_dist::exec::Bootstrap>::run
             at /rustc/3ce2ac6487b9c522c8e56d4cfe9c254b5a2adc46/src/tools/opt-dist/src/exec.rs:189:18
   3: opt_dist::execute_pipeline::{closure#1}::{closure#0}
             at /rustc/3ce2ac6487b9c522c8e56d4cfe9c254b5a2adc46/src/tools/opt-dist/src/main.rs:236:21
   4: <opt_dist::timer::TimerSection>::section::<opt_dist::execute_pipeline::{closure#1}::{closure#0}, ()>
             at /rustc/3ce2ac6487b9c522c8e56d4cfe9c254b5a2adc46/src/tools/opt-dist/src/timer.rs:111:22
   5: opt_dist::execute_pipeline::{closure#1}
             at /rustc/3ce2ac6487b9c522c8e56d4cfe9c254b5a2adc46/src/tools/opt-dist/src/main.rs:225:15
   6: <opt_dist::timer::TimerSection>::section::<opt_dist::execute_pipeline::{closure#1}, opt_dist::training::RustcPGOProfile>
             at /rustc/3ce2ac6487b9c522c8e56d4cfe9c254b5a2adc46/src/tools/opt-dist/src/timer.rs:111:22
   7: opt_dist::execute_pipeline
             at /rustc/3ce2ac6487b9c522c8e56d4cfe9c254b5a2adc46/src/tools/opt-dist/src/main.rs:222:35
   8: opt_dist::main
             at /rustc/3ce2ac6487b9c522c8e56d4cfe9c254b5a2adc46/src/tools/opt-dist/src/main.rs:429:18
   9: <fn() -> core::result::Result<(), anyhow::Error> as core::ops::function::FnOnce<()>>::call_once
             at /rustc/390a0ab5dc4a895235a551e502c3893c3337731d/library/core/src/ops/function.rs:250:5
  10: std::sys::backtrace::__rust_begin_short_backtrace::<fn() -> core::result::Result<(), anyhow::Error>, core::result::Result<(), anyhow::Error>>
             at /rustc/390a0ab5dc4a895235a551e502c3893c3337731d/library/std/src/sys/backtrace.rs:152:18
  11: std::rt::lang_start::<core::result::Result<(), anyhow::Error>>::{closure#0}
             at /rustc/390a0ab5dc4a895235a551e502c3893c3337731d/library/std/src/rt.rs:206:18
  12: core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once
             at /rustc/390a0ab5dc4a895235a551e502c3893c3337731d/library/core/src/ops/function.rs:284:21
  13: std::panicking::catch_unwind::do_call
             at /rustc/390a0ab5dc4a895235a551e502c3893c3337731d/library/std/src/panicking.rs:589:40
  14: std::panicking::catch_unwind
             at /rustc/390a0ab5dc4a895235a551e502c3893c3337731d/library/std/src/panicking.rs:552:19

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants