@@ -5,6 +5,7 @@ use std::marker::PhantomData;
55use std:: ops:: { Deref , DerefMut } ;
66use std:: panic;
77use std:: path:: PathBuf ;
8+ use std:: str:: FromStr ;
89use std:: thread:: panicking;
910
1011use rustc_data_structures:: fx:: FxIndexMap ;
@@ -263,6 +264,38 @@ pub struct DiagInner {
263264 /// With `-Ztrack_diagnostics` enabled,
264265 /// we print where in rustc this error was emitted.
265266 pub ( crate ) emitted_at : DiagLocation ,
267+ /// Used to avoid lints which would affect MSRV
268+ pub rust_version : Option < RustVersion > ,
269+ }
270+
271+ #[ derive( Copy , Clone , Debug , Encodable , Decodable , PartialEq , Eq , PartialOrd , Ord ) ]
272+ pub struct RustVersion {
273+ pub major : u64 ,
274+ pub minor : u64 ,
275+ pub patch : u64 ,
276+ }
277+
278+ impl FromStr for RustVersion {
279+ type Err = ( ) ;
280+
281+ fn from_str ( s : & str ) -> Result < Self , Self :: Err > {
282+ fn get_number ( s : & str ) -> Result < ( u64 , & str ) , ( ) > {
283+ let end = s. chars ( ) . take_while ( char:: is_ascii_digit) . count ( ) ;
284+ if end == 0 {
285+ return Err ( ( ) ) ;
286+ }
287+ // `is_ascii_digit` ensures that this will be on a char boundary
288+ let ( num, rest) = s. split_at ( end) ;
289+ Ok ( ( num. parse ( ) . map_err ( |_| ( ) ) ?, rest) )
290+ }
291+
292+ let ( major, s) = get_number ( s) ?;
293+ let s = s. strip_prefix ( "." ) . ok_or ( ( ) ) ?;
294+ let ( minor, s) = get_number ( s) ?;
295+ let s = s. strip_prefix ( "." ) . ok_or ( ( ) ) ?;
296+ let ( patch, _) = get_number ( s) ?;
297+ Ok ( Self { major, minor, patch } )
298+ }
266299}
267300
268301impl DiagInner {
@@ -287,6 +320,7 @@ impl DiagInner {
287320 is_lint : None ,
288321 long_ty_path : None ,
289322 emitted_at : DiagLocation :: caller ( ) ,
323+ rust_version : None ,
290324 }
291325 }
292326
@@ -377,6 +411,10 @@ impl DiagInner {
377411 self . args = std:: mem:: take ( & mut self . reserved_args ) ;
378412 }
379413
414+ pub fn set_rust_version ( & mut self , version : RustVersion ) {
415+ self . rust_version = Some ( version) ;
416+ }
417+
380418 pub fn emitted_at_sub_diag ( & self ) -> Subdiag {
381419 let track = format ! ( "-Ztrack-diagnostics: created at {}" , self . emitted_at) ;
382420 Subdiag {
@@ -410,6 +448,7 @@ impl DiagInner {
410448 // omit self.sort_span
411449 & self . is_lint ,
412450 // omit self.emitted_at
451+ // omit rust_version
413452 )
414453 }
415454}
0 commit comments