@@ -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,9 @@ 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) => e. attrs ( db) . by_key ( "non_exhaustive" ) . exists ( ) && e . module ( db ) . krate ( ) != krate ,
307
307
_ => false ,
308
308
}
309
309
}
@@ -1657,8 +1657,32 @@ fn foo(t: E) {
1657
1657
}
1658
1658
1659
1659
#[ test]
1660
- fn ignores_doc_hidden_for_crate_local_enums_but_not_non_exhaustive ( ) {
1661
- cov_mark:: check!( added_wildcard_pattern) ;
1660
+ fn ignores_non_exhaustive_for_crate_local_enums ( ) {
1661
+ check_assist (
1662
+ add_missing_match_arms,
1663
+ r#"
1664
+ #[non_exhaustive]
1665
+ enum E { A, B, }
1666
+
1667
+ fn foo(t: E) {
1668
+ match $0t {
1669
+ }
1670
+ }"# ,
1671
+ r#"
1672
+ #[non_exhaustive]
1673
+ enum E { A, B, }
1674
+
1675
+ fn foo(t: E) {
1676
+ match t {
1677
+ $0E::A => todo!(),
1678
+ E::B => todo!(),
1679
+ }
1680
+ }"# ,
1681
+ ) ;
1682
+ }
1683
+
1684
+ #[ test]
1685
+ fn ignores_doc_hidden_and_non_exhaustive_for_crate_local_enums ( ) {
1662
1686
check_assist (
1663
1687
add_missing_match_arms,
1664
1688
r#"
@@ -1677,7 +1701,6 @@ fn foo(t: E) {
1677
1701
match t {
1678
1702
$0E::A => todo!(),
1679
1703
E::B => todo!(),
1680
- _ => todo!(),
1681
1704
}
1682
1705
}"# ,
1683
1706
) ;
0 commit comments