274274use std:: iter:: once;
275275
276276use hir_def:: { AdtId , DefWithBodyId , HasModule , ModuleId } ;
277- use once_cell:: unsync:: OnceCell ;
278277use smallvec:: { smallvec, SmallVec } ;
279278use typed_arena:: Arena ;
280279
@@ -290,7 +289,7 @@ pub(crate) struct MatchCheckCtx<'a, 'p> {
290289 pub ( crate ) db : & ' a dyn HirDatabase ,
291290 /// Lowered patterns from arms plus generated by the check.
292291 pub ( crate ) pattern_arena : & ' p Arena < DeconstructedPat < ' p > > ,
293- feature_exhaustive_patterns : OnceCell < bool > ,
292+ exhaustive_patterns : bool ,
294293}
295294
296295impl < ' a , ' p > MatchCheckCtx < ' a , ' p > {
@@ -300,7 +299,9 @@ impl<'a, 'p> MatchCheckCtx<'a, 'p> {
300299 db : & ' a dyn HirDatabase ,
301300 pattern_arena : & ' p Arena < DeconstructedPat < ' p > > ,
302301 ) -> Self {
303- Self { module, body, db, pattern_arena, feature_exhaustive_patterns : Default :: default ( ) }
302+ let def_map = db. crate_def_map ( module. krate ( ) ) ;
303+ let exhaustive_patterns = def_map. is_unstable_feature_enabled ( "exhaustive_patterns" ) ;
304+ Self { module, body, db, pattern_arena, exhaustive_patterns }
304305 }
305306
306307 pub ( super ) fn is_uninhabited ( & self , ty : & Ty ) -> bool {
@@ -326,20 +327,7 @@ impl<'a, 'p> MatchCheckCtx<'a, 'p> {
326327
327328 // Rust's unstable feature described as "Allows exhaustive pattern matching on types that contain uninhabited types."
328329 pub ( super ) fn feature_exhaustive_patterns ( & self ) -> bool {
329- * self . feature_exhaustive_patterns . get_or_init ( || {
330- let def_map = self . db . crate_def_map ( self . module . krate ( ) ) ;
331- let root_mod = def_map. module_id ( def_map. root ( ) ) ;
332- let rood_attrs = self . db . attrs ( root_mod. into ( ) ) ;
333- let mut nightly_features = rood_attrs
334- . by_key ( "feature" )
335- . attrs ( )
336- . map ( |attr| attr. parse_path_comma_token_tree ( ) )
337- . flatten ( )
338- . flatten ( ) ;
339- nightly_features. any (
340- |feat| matches ! ( feat. segments( ) , [ name] if name. to_smol_str( ) == "exhaustive_patterns" ) ,
341- )
342- } )
330+ self . exhaustive_patterns
343331 }
344332}
345333
0 commit comments