@@ -78,7 +78,7 @@ pub(crate) fn add_missing_match_arms(acc: &mut Assists, ctx: &AssistContext) ->
78
78
Peekable < Box < dyn Iterator < Item = ( ast:: Pat , bool ) > > > ,
79
79
bool ,
80
80
) = if let Some ( enum_def) = resolve_enum_def ( & ctx. sema , & expr) {
81
- let is_non_exhaustive = enum_def. is_non_exhaustive ( ctx. db ( ) ) ;
81
+ let is_non_exhaustive = enum_def. is_non_exhaustive ( ctx. db ( ) , module . krate ( ) ) ;
82
82
83
83
let variants = enum_def. variants ( ctx. db ( ) ) ;
84
84
@@ -104,7 +104,7 @@ pub(crate) fn add_missing_match_arms(acc: &mut Assists, ctx: &AssistContext) ->
104
104
( missing_pats. peekable ( ) , is_non_exhaustive)
105
105
} else if let Some ( enum_defs) = resolve_tuple_of_enum_def ( & ctx. sema , & expr) {
106
106
let is_non_exhaustive =
107
- enum_defs. iter ( ) . any ( |enum_def| enum_def. is_non_exhaustive ( ctx. db ( ) ) ) ;
107
+ enum_defs. iter ( ) . any ( |enum_def| enum_def. is_non_exhaustive ( ctx. db ( ) , module . krate ( ) ) ) ;
108
108
109
109
let mut n_arms = 1 ;
110
110
let variants_of_enums: Vec < Vec < ExtendedVariant > > = enum_defs
@@ -301,9 +301,11 @@ fn lift_enum(e: hir::Enum) -> ExtendedEnum {
301
301
}
302
302
303
303
impl ExtendedEnum {
304
- fn is_non_exhaustive ( self , db : & RootDatabase ) -> bool {
304
+ fn is_non_exhaustive ( self , db : & RootDatabase , krate : Crate ) -> bool {
305
305
match self {
306
- ExtendedEnum :: Enum ( e) => e. attrs ( db) . by_key ( "non_exhaustive" ) . exists ( ) ,
306
+ ExtendedEnum :: Enum ( e) => {
307
+ e. attrs ( db) . by_key ( "non_exhaustive" ) . exists ( ) && e. module ( db) . krate ( ) != krate
308
+ }
307
309
_ => false ,
308
310
}
309
311
}
@@ -1657,8 +1659,32 @@ fn foo(t: E) {
1657
1659
}
1658
1660
1659
1661
#[ test]
1660
- fn ignores_doc_hidden_for_crate_local_enums_but_not_non_exhaustive ( ) {
1661
- cov_mark:: check!( added_wildcard_pattern) ;
1662
+ fn ignores_non_exhaustive_for_crate_local_enums ( ) {
1663
+ check_assist (
1664
+ add_missing_match_arms,
1665
+ r#"
1666
+ #[non_exhaustive]
1667
+ enum E { A, B, }
1668
+
1669
+ fn foo(t: E) {
1670
+ match $0t {
1671
+ }
1672
+ }"# ,
1673
+ r#"
1674
+ #[non_exhaustive]
1675
+ enum E { A, B, }
1676
+
1677
+ fn foo(t: E) {
1678
+ match t {
1679
+ $0E::A => todo!(),
1680
+ E::B => todo!(),
1681
+ }
1682
+ }"# ,
1683
+ ) ;
1684
+ }
1685
+
1686
+ #[ test]
1687
+ fn ignores_doc_hidden_and_non_exhaustive_for_crate_local_enums ( ) {
1662
1688
check_assist (
1663
1689
add_missing_match_arms,
1664
1690
r#"
@@ -1677,7 +1703,6 @@ fn foo(t: E) {
1677
1703
match t {
1678
1704
$0E::A => todo!(),
1679
1705
E::B => todo!(),
1680
- _ => todo!(),
1681
1706
}
1682
1707
}"# ,
1683
1708
) ;
0 commit comments