1+ use rustc_errors:: { Applicability , Diag } ;
2+ use rustc_span:: Span ;
13use serde:: de:: { self , Deserializer , Visitor } ;
24use serde:: { Deserialize , Serialize , ser} ;
35use std:: collections:: HashMap ;
@@ -13,7 +15,11 @@ pub struct Rename {
1315#[ serde( untagged) ]
1416pub enum DisallowedPath {
1517 Simple ( String ) ,
16- WithReason { path : String , reason : Option < String > } ,
18+ WithReason {
19+ path : String ,
20+ reason : Option < String > ,
21+ replacement : Option < String > ,
22+ } ,
1723}
1824
1925impl DisallowedPath {
@@ -23,12 +29,34 @@ impl DisallowedPath {
2329 path
2430 }
2531
32+ pub fn diag_amendment ( & self , span : Span ) -> impl FnOnce ( & mut Diag < ' _ , ( ) > ) + use < ' _ > {
33+ move |diag| {
34+ if let Some ( replacement) = self . replacement ( ) {
35+ diag. span_suggestion (
36+ span,
37+ self . reason ( ) . map_or_else ( || String :: from ( "use" ) , ToOwned :: to_owned) ,
38+ replacement,
39+ Applicability :: MachineApplicable ,
40+ ) ;
41+ } else if let Some ( reason) = self . reason ( ) {
42+ diag. note ( reason. to_owned ( ) ) ;
43+ }
44+ }
45+ }
46+
2647 pub fn reason ( & self ) -> Option < & str > {
2748 match & self {
2849 Self :: WithReason { reason, .. } => reason. as_deref ( ) ,
2950 Self :: Simple ( _) => None ,
3051 }
3152 }
53+
54+ fn replacement ( & self ) -> Option < & str > {
55+ match & self {
56+ Self :: WithReason { replacement, .. } => replacement. as_deref ( ) ,
57+ Self :: Simple ( _) => None ,
58+ }
59+ }
3260}
3361
3462#[ derive( Clone , Copy , Debug , PartialEq , Eq , Deserialize , Serialize ) ]
0 commit comments