mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-07 17:18:32 +03:00
Fix match_same_arms FP with associated consts (#16701)
Closes rust-lang/rust-clippy#16698 changelog: [`match_same_arms`] fix FP with associated consts
This commit is contained in:
@@ -841,7 +841,8 @@ fn fetch_path(&self, qpath: &QPath<'_>, id: HirId) -> Option<ConstValue> {
|
||||
&& ty.span.ctxt() == self.ctxt.get()
|
||||
&& ty_name.ident.span.ctxt() == self.ctxt.get()
|
||||
&& matches!(ty_path.res, Res::PrimTy(_))
|
||||
&& let Some((DefKind::AssocConst { .. }, did)) = self.typeck.type_dependent_def(id) =>
|
||||
&& let Some((DefKind::AssocConst { .. }, did)) = self.typeck.type_dependent_def(id)
|
||||
&& self.tcx.inherent_impl_of_assoc(did).is_some() =>
|
||||
{
|
||||
did
|
||||
},
|
||||
|
||||
@@ -156,3 +156,19 @@ fn issue16678() {
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
fn issue16698() {
|
||||
trait Foo {
|
||||
const X: u8;
|
||||
}
|
||||
impl Foo for u8 {
|
||||
const X: u8 = 2;
|
||||
}
|
||||
impl Foo for i8 {
|
||||
const X: u8 = 2;
|
||||
}
|
||||
match true {
|
||||
false => u8::X,
|
||||
true => i8::X,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -165,3 +165,19 @@ fn wrapper(_arg: ()) {
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
fn issue16698() {
|
||||
trait Foo {
|
||||
const X: u8;
|
||||
}
|
||||
impl Foo for u8 {
|
||||
const X: u8 = 2;
|
||||
}
|
||||
impl Foo for i8 {
|
||||
const X: u8 = 2;
|
||||
}
|
||||
match true {
|
||||
false => u8::X,
|
||||
true => i8::X,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user