about summary refs log tree commit diff
path: root/compiler/rustc_session
diff options
context:
space:
mode:
authorDavid Tolnay <dtolnay@gmail.com>2023-07-16 17:58:46 -0700
committerDavid Tolnay <dtolnay@gmail.com>2023-07-20 11:04:30 -0700
commitf72bdb150180f3fb9ccd6447f13e9e37b3e33e79 (patch)
tree31f91426f15c3b535ce40dbc1fb4aa32947203e8 /compiler/rustc_session
parentc0dc0c6875e1907f1a8d690bae800c9d0c89b4f1 (diff)
downloadrust-f72bdb150180f3fb9ccd6447f13e9e37b3e33e79.tar.gz
rust-f72bdb150180f3fb9ccd6447f13e9e37b3e33e79.zip
Parse --print KIND=PATH command line syntax
Diffstat (limited to 'compiler/rustc_session')
-rw-r--r--compiler/rustc_session/src/config.rs22
1 files changed, 14 insertions, 8 deletions
diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs
index 261d3529b14..738625485c4 100644
--- a/compiler/rustc_session/src/config.rs
+++ b/compiler/rustc_session/src/config.rs
@@ -2011,13 +2011,7 @@ fn parse_output_types(
     if !unstable_opts.parse_only {
         for list in matches.opt_strs("emit") {
             for output_type in list.split(',') {
-                let (shorthand, path) = match output_type.split_once('=') {
-                    None => (output_type, None),
-                    Some((shorthand, "-")) => (shorthand, Some(OutFileName::Stdout)),
-                    Some((shorthand, path)) => {
-                        (shorthand, Some(OutFileName::Real(PathBuf::from(path))))
-                    }
-                };
+                let (shorthand, path) = split_out_file_name(output_type);
                 let output_type = OutputType::from_shorthand(shorthand).unwrap_or_else(|| {
                     handler.early_error(format!(
                         "unknown emission type: `{shorthand}` - expected one of: {display}",
@@ -2034,6 +2028,14 @@ fn parse_output_types(
     OutputTypes(output_types)
 }
 
+fn split_out_file_name(arg: &str) -> (&str, Option<OutFileName>) {
+    match arg.split_once('=') {
+        None => (arg, None),
+        Some((kind, "-")) => (kind, Some(OutFileName::Stdout)),
+        Some((kind, path)) => (kind, Some(OutFileName::Real(PathBuf::from(path)))),
+    }
+}
+
 fn should_override_cgus_and_disable_thinlto(
     handler: &EarlyErrorHandler,
     output_types: &OutputTypes,
@@ -2128,6 +2130,8 @@ fn collect_print_requests(
     ];
 
     prints.extend(matches.opt_strs("print").into_iter().map(|req| {
+        let (req, out) = split_out_file_name(&req);
+
         let kind = match PRINT_KINDS.iter().find(|&&(name, _)| name == req) {
             Some((_, PrintKind::TargetSpec)) => {
                 if unstable_opts.unstable_options {
@@ -2159,7 +2163,9 @@ fn collect_print_requests(
                 ));
             }
         };
-        PrintRequest { kind, out: OutFileName::Stdout }
+
+        let out = out.unwrap_or(OutFileName::Stdout);
+        PrintRequest { kind, out }
     }));
 
     prints