-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Closed
Copy link
Labels
A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.P-mediumMedium priorityMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
(Spawned off of #62411 (comment))
Consider this code (play):
struct Sum(u32, u32);
impl PartialEq for Sum {
fn eq(&self, other: &Self) -> bool { self.0 + self.1 == other.0 + other.1 }
}
impl Eq for Sum { }
#[derive(PartialEq, Eq)]
enum Eek {
TheConst,
UnusedByTheConst(Sum)
}
const THE_CONST: Eek = Eek::TheConst;
pub fn main() {
match Eek::UnusedByTheConst(Sum(1,2)) {
THE_CONST => { println!("Hello"); }
_ => { println!("Gbye"); }
}
}
In stable and beta, it compiles without warning.
In nightly, it compiles with the following diagnostic warning (#62411):
warning: to use a constant of type `Sum` in a pattern, `Sum` must be annotated with `#[derive(PartialEq, Eq)]`
--> src/main.rs:19:9
|
19 | THE_CONST => { println!("Hello"); }
| ^^^^^^^^^
|
= note: #[warn(indirect_structural_match)] on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #62411 <https://github.com/rust-lang/rust/issues/62411>
This is probably not what we want for this lint: It is entirely reasonable for the user to assume that the structural_match check is based solely on the ADT's that one encounters when traversing the const expression itself, and one should ignore any unused enum variants that are only tangentially related to the const.
Metadata
Metadata
Assignees
Labels
A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.P-mediumMedium priorityMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.