@@ -78,7 +78,7 @@ pub(crate) fn add_missing_match_arms(acc: &mut Assists, ctx: &AssistContext) ->
7878 Peekable < Box < dyn Iterator < Item = ( ast:: Pat , bool ) > > > ,
7979 bool ,
8080 ) = 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 ( ) ) ;
8282
8383 let variants = enum_def. variants ( ctx. db ( ) ) ;
8484
@@ -104,7 +104,7 @@ pub(crate) fn add_missing_match_arms(acc: &mut Assists, ctx: &AssistContext) ->
104104 ( missing_pats. peekable ( ) , is_non_exhaustive)
105105 } else if let Some ( enum_defs) = resolve_tuple_of_enum_def ( & ctx. sema , & expr) {
106106 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 ( ) ) ) ;
108108
109109 let mut n_arms = 1 ;
110110 let variants_of_enums: Vec < Vec < ExtendedVariant > > = enum_defs
@@ -301,9 +301,11 @@ fn lift_enum(e: hir::Enum) -> ExtendedEnum {
301301}
302302
303303impl ExtendedEnum {
304- fn is_non_exhaustive ( self , db : & RootDatabase ) -> bool {
304+ fn is_non_exhaustive ( self , db : & RootDatabase , krate : Crate ) -> bool {
305305 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+ }
307309 _ => false ,
308310 }
309311 }
@@ -1657,8 +1659,32 @@ fn foo(t: E) {
16571659 }
16581660
16591661 #[ 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 ( ) {
16621688 check_assist (
16631689 add_missing_match_arms,
16641690 r#"
@@ -1677,7 +1703,6 @@ fn foo(t: E) {
16771703 match t {
16781704 $0E::A => todo!(),
16791705 E::B => todo!(),
1680- _ => todo!(),
16811706 }
16821707}"# ,
16831708 ) ;
0 commit comments