diff --git a/clippy_utils/src/consts.rs b/clippy_utils/src/consts.rs index 19278708a36a..51db6b6b64c7 100644 --- a/clippy_utils/src/consts.rs +++ b/clippy_utils/src/consts.rs @@ -841,7 +841,8 @@ fn fetch_path(&self, qpath: &QPath<'_>, id: HirId) -> Option { && 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 }, diff --git a/tests/ui/match_same_arms.fixed b/tests/ui/match_same_arms.fixed index 8b16fd3193f5..b0ab833c7835 100644 --- a/tests/ui/match_same_arms.fixed +++ b/tests/ui/match_same_arms.fixed @@ -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, + }; +} diff --git a/tests/ui/match_same_arms.rs b/tests/ui/match_same_arms.rs index 3b2d585c579d..9c7899122afb 100644 --- a/tests/ui/match_same_arms.rs +++ b/tests/ui/match_same_arms.rs @@ -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, + }; +}