-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't haveI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when appliedIssue: The suggestions provided by this Lint cause an ICE/error when applied
Description
Summary
When inside a const fn there are additional restrictions that redundant_guards appears to not consider.
Lint Name
redundant_guards
Reproducer
I tried this code:
pub const fn handle(x: &str) -> u32 {
match x {
y if y.is_empty() => 2,
_ => 3,
}
}
I saw this happen:
warning: redundant guard
--> src/lib.rs:3:14
|
3 | y if y.is_empty() => 2,
| ^^^^^^^^^^^^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_guards
= note: `#[warn(clippy::redundant_guards)]` on by default
help: try
|
3 - y if y.is_empty() => 2,
3 + "" => 2,
|
However applying that suggestion results in:
error[E0015]: cannot match on `str` in constant functions
--> src/lib.rs:3:9
|
3 | "" => 2,
| ^^
|
= note: `str` cannot be compared in compile-time, and therefore cannot be used in `match`es
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
Version
rustc 1.76.0 (07dca489a 2024-02-04)
binary: rustc
commit-hash: 07dca489ac2d933c78d3c5158e3f43beefeb02ce
commit-date: 2024-02-04
host: x86_64-unknown-linux-gnu
release: 1.76.0
LLVM version: 17.0.6
Additional Labels
@rustbot label +I-suggestion-causes-error
not-elm
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't haveI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when appliedIssue: The suggestions provided by this Lint cause an ICE/error when applied