88// option. This file may not be copied, modified, or distributed
99// except according to those terms.
1010
11- use borrow_check:: nll:: constraints:: { OutlivesConstraint , ConstraintCategory } ;
11+ use borrow_check:: nll:: constraints:: { OutlivesConstraint } ;
1212use borrow_check:: nll:: region_infer:: RegionInferenceContext ;
1313use rustc:: hir:: def_id:: DefId ;
1414use rustc:: infer:: error_reporting:: nice_region_error:: NiceRegionError ;
1515use rustc:: infer:: InferCtxt ;
16- use rustc:: mir:: { Location , Mir } ;
16+ use rustc:: mir:: { ConstraintCategory , Location , Mir } ;
1717use rustc:: ty:: { self , RegionVid } ;
1818use rustc_data_structures:: indexed_vec:: IndexVec ;
1919use rustc_errors:: { Diagnostic , DiagnosticBuilder } ;
@@ -28,22 +28,26 @@ mod var_name;
2828
2929use self :: region_name:: RegionName ;
3030
31- impl fmt:: Display for ConstraintCategory {
32- fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
31+ trait ConstraintDescription {
32+ fn description ( & self ) -> & ' static str ;
33+ }
34+
35+ impl ConstraintDescription for ConstraintCategory {
36+ fn description ( & self ) -> & ' static str {
3337 // Must end with a space. Allows for empty names to be provided.
3438 match self {
35- ConstraintCategory :: Assignment => write ! ( f , "assignment " ) ,
36- ConstraintCategory :: Return => write ! ( f , "returning this value " ) ,
37- ConstraintCategory :: Cast => write ! ( f , "cast " ) ,
38- ConstraintCategory :: CallArgument => write ! ( f , "argument " ) ,
39- ConstraintCategory :: TypeAnnotation => write ! ( f , "type annotation " ) ,
40- ConstraintCategory :: ClosureBounds => write ! ( f , "closure body " ) ,
41- ConstraintCategory :: SizedBound => write ! ( f , "proving this value is `Sized` " ) ,
42- ConstraintCategory :: CopyBound => write ! ( f , "copying this value " ) ,
43- ConstraintCategory :: OpaqueType => write ! ( f , "opaque type " ) ,
39+ ConstraintCategory :: Assignment => "assignment " ,
40+ ConstraintCategory :: Return => "returning this value " ,
41+ ConstraintCategory :: Cast => "cast " ,
42+ ConstraintCategory :: CallArgument => "argument " ,
43+ ConstraintCategory :: TypeAnnotation => "type annotation " ,
44+ ConstraintCategory :: ClosureBounds => "closure body " ,
45+ ConstraintCategory :: SizedBound => "proving this value is `Sized` " ,
46+ ConstraintCategory :: CopyBound => "copying this value " ,
47+ ConstraintCategory :: OpaqueType => "opaque type " ,
4448 ConstraintCategory :: Boring
4549 | ConstraintCategory :: BoringNoLocation
46- | ConstraintCategory :: Internal => write ! ( f , "" ) ,
50+ | ConstraintCategory :: Internal => "" ,
4751 }
4852 }
4953}
@@ -358,7 +362,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
358362 _ => {
359363 diag. span_label ( span, format ! (
360364 "{}requires that `{}` must outlive `{}`" ,
361- category, fr_name, outlived_fr_name,
365+ category. description ( ) , fr_name, outlived_fr_name,
362366 ) ) ;
363367 } ,
364368 }
0 commit comments