8
8
// option. This file may not be copied, modified, or distributed
9
9
// except according to those terms.
10
10
11
- use borrow_check:: nll:: constraints:: { OutlivesConstraint , ConstraintCategory } ;
11
+ use borrow_check:: nll:: constraints:: { OutlivesConstraint } ;
12
12
use borrow_check:: nll:: region_infer:: RegionInferenceContext ;
13
13
use rustc:: hir:: def_id:: DefId ;
14
14
use rustc:: infer:: error_reporting:: nice_region_error:: NiceRegionError ;
15
15
use rustc:: infer:: InferCtxt ;
16
- use rustc:: mir:: { Location , Mir } ;
16
+ use rustc:: mir:: { ConstraintCategory , Location , Mir } ;
17
17
use rustc:: ty:: { self , RegionVid } ;
18
18
use rustc_data_structures:: indexed_vec:: IndexVec ;
19
19
use rustc_errors:: { Diagnostic , DiagnosticBuilder } ;
@@ -28,22 +28,26 @@ mod var_name;
28
28
29
29
use self :: region_name:: RegionName ;
30
30
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 {
33
37
// Must end with a space. Allows for empty names to be provided.
34
38
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 " ,
44
48
ConstraintCategory :: Boring
45
49
| ConstraintCategory :: BoringNoLocation
46
- | ConstraintCategory :: Internal => write ! ( f , "" ) ,
50
+ | ConstraintCategory :: Internal => "" ,
47
51
}
48
52
}
49
53
}
@@ -358,7 +362,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
358
362
_ => {
359
363
diag. span_label ( span, format ! (
360
364
"{}requires that `{}` must outlive `{}`" ,
361
- category, fr_name, outlived_fr_name,
365
+ category. description ( ) , fr_name, outlived_fr_name,
362
366
) ) ;
363
367
} ,
364
368
}
0 commit comments