1- //! Analysis of patterns, notably match exhaustiveness checking.
1+ //! Analysis of patterns, notably match exhaustiveness checking. The main entrypoint for this crate
2+ //! is [`usefulness::compute_match_usefulness`]. For rustc-specific types and entrypoints, see the
3+ //! [`rustc`] module.
24
35// tidy-alphabetical-start
46#![ allow( rustc:: diagnostic_outside_of_impl) ]
@@ -23,14 +25,8 @@ use std::fmt;
2325
2426pub use rustc_index:: { Idx , IndexVec } ; // re-exported to avoid rustc_index version issues
2527
26- #[ cfg( feature = "rustc" ) ]
27- use rustc_middle:: ty:: Ty ;
28- #[ cfg( feature = "rustc" ) ]
29- use rustc_span:: ErrorGuaranteed ;
30-
3128use crate :: constructor:: { Constructor , ConstructorSet , IntRange } ;
3229use crate :: pat:: DeconstructedPat ;
33- use crate :: pat_column:: PatternColumn ;
3430
3531pub trait Captures < ' a > { }
3632impl < ' a , T : ?Sized > Captures < ' a > for T { }
@@ -128,30 +124,3 @@ impl<'p, Cx: PatCx> Clone for MatchArm<'p, Cx> {
128124}
129125
130126impl < ' p , Cx : PatCx > Copy for MatchArm < ' p , Cx > { }
131-
132- /// The entrypoint for this crate. Computes whether a match is exhaustive and which of its arms are
133- /// useful, and runs some lints.
134- #[ cfg( feature = "rustc" ) ]
135- pub fn analyze_match < ' p , ' tcx > (
136- tycx : & rustc:: RustcPatCtxt < ' p , ' tcx > ,
137- arms : & [ rustc:: MatchArm < ' p , ' tcx > ] ,
138- scrut_ty : Ty < ' tcx > ,
139- pattern_complexity_limit : Option < usize > ,
140- ) -> Result < rustc:: UsefulnessReport < ' p , ' tcx > , ErrorGuaranteed > {
141- use lints:: lint_nonexhaustive_missing_variants;
142- use usefulness:: { compute_match_usefulness, PlaceValidity } ;
143-
144- let scrut_ty = tycx. reveal_opaque_ty ( scrut_ty) ;
145- let scrut_validity = PlaceValidity :: from_bool ( tycx. known_valid_scrutinee ) ;
146- let report =
147- compute_match_usefulness ( tycx, arms, scrut_ty, scrut_validity, pattern_complexity_limit) ?;
148-
149- // Run the non_exhaustive_omitted_patterns lint. Only run on refutable patterns to avoid hitting
150- // `if let`s. Only run if the match is exhaustive otherwise the error is redundant.
151- if tycx. refutable && report. non_exhaustiveness_witnesses . is_empty ( ) {
152- let pat_column = PatternColumn :: new ( arms) ;
153- lint_nonexhaustive_missing_variants ( tycx, arms, & pat_column, scrut_ty) ?;
154- }
155-
156- Ok ( report)
157- }
0 commit comments