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:
Samuel Tardieu
2026-03-10 17:21:54 +00:00
committed by GitHub
3 changed files with 34 additions and 1 deletions
+2 -1
View File
@@ -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
},
+16
View File
@@ -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,
};
}
+16
View File
@@ -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,
};
}