| 
6 | 6 | 
  | 
7 | 7 | #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]  | 
8 | 8 | #![feature(once_cell)]  | 
 | 9 | +#![feature(decl_macro)]  | 
9 | 10 | #![recursion_limit = "256"]  | 
10 | 11 | #![allow(rustc::potential_query_instability)]  | 
11 | 12 | #![deny(rustc::untranslatable_diagnostic)]  | 
@@ -753,20 +754,41 @@ fn print_crate_info(  | 
753 | 754 | }  | 
754 | 755 | 
 
  | 
755 | 756 | /// Prints version information  | 
756 |  | -pub fn version(binary: &str, matches: &getopts::Matches) {  | 
 | 757 | +///  | 
 | 758 | +/// NOTE: this is a macro to support drivers built at a different time than the main `rustc_driver` crate.  | 
 | 759 | +pub macro version($binary: literal, $matches: expr) {  | 
 | 760 | +    fn unw(x: Option<&str>) -> &str {  | 
 | 761 | +        x.unwrap_or("unknown")  | 
 | 762 | +    }  | 
 | 763 | +    $crate::version_at_macro_invocation(  | 
 | 764 | +        $binary,  | 
 | 765 | +        $matches,  | 
 | 766 | +        unw(option_env!("CFG_VERSION")),  | 
 | 767 | +        unw(option_env!("CFG_VER_HASH")),  | 
 | 768 | +        unw(option_env!("CFG_VER_DATE")),  | 
 | 769 | +        unw(option_env!("CFG_RELEASE")),  | 
 | 770 | +    )  | 
 | 771 | +}  | 
 | 772 | + | 
 | 773 | +#[doc(hidden)] // use the macro instead  | 
 | 774 | +pub fn version_at_macro_invocation(  | 
 | 775 | +    binary: &str,  | 
 | 776 | +    matches: &getopts::Matches,  | 
 | 777 | +    version: &str,  | 
 | 778 | +    commit_hash: &str,  | 
 | 779 | +    commit_date: &str,  | 
 | 780 | +    release: &str,  | 
 | 781 | +) {  | 
757 | 782 |     let verbose = matches.opt_present("verbose");  | 
758 | 783 | 
 
  | 
759 |  | -    println!("{} {}", binary, util::version_str().unwrap_or("unknown version"));  | 
 | 784 | +    println!("{} {}", binary, version);  | 
760 | 785 | 
 
  | 
761 | 786 |     if verbose {  | 
762 |  | -        fn unw(x: Option<&str>) -> &str {  | 
763 |  | -            x.unwrap_or("unknown")  | 
764 |  | -        }  | 
765 | 787 |         println!("binary: {}", binary);  | 
766 |  | -        println!("commit-hash: {}", unw(util::commit_hash_str()));  | 
767 |  | -        println!("commit-date: {}", unw(util::commit_date_str()));  | 
 | 788 | +        println!("commit-hash: {}", commit_hash);  | 
 | 789 | +        println!("commit-date: {}", commit_date);  | 
768 | 790 |         println!("host: {}", config::host_triple());  | 
769 |  | -        println!("release: {}", unw(util::release_str()));  | 
 | 791 | +        println!("release: {}", release);  | 
770 | 792 | 
 
  | 
771 | 793 |         let debug_flags = matches.opt_strs("Z");  | 
772 | 794 |         let backend_name = debug_flags.iter().find_map(|x| x.strip_prefix("codegen-backend="));  | 
@@ -1082,7 +1104,7 @@ pub fn handle_options(args: &[String]) -> Option<getopts::Matches> {  | 
1082 | 1104 |     }  | 
1083 | 1105 | 
 
  | 
1084 | 1106 |     if matches.opt_present("version") {  | 
1085 |  | -        version("rustc", &matches);  | 
 | 1107 | +        version!("rustc", &matches);  | 
1086 | 1108 |         return None;  | 
1087 | 1109 |     }  | 
1088 | 1110 | 
 
  | 
@@ -1227,7 +1249,7 @@ pub fn report_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str) {  | 
1227 | 1249 |         format!("we would appreciate a bug report: {}", bug_report_url).into(),  | 
1228 | 1250 |         format!(  | 
1229 | 1251 |             "rustc {} running on {}",  | 
1230 |  | -            util::version_str().unwrap_or("unknown_version"),  | 
 | 1252 | +            util::version_str!().unwrap_or("unknown_version"),  | 
1231 | 1253 |             config::host_triple()  | 
1232 | 1254 |         )  | 
1233 | 1255 |         .into(),  | 
 | 
0 commit comments