Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Parse --print KIND=PATH command line syntax
  • Loading branch information
dtolnay committed Jul 20, 2023
commit f72bdb150180f3fb9ccd6447f13e9e37b3e33e79
22 changes: 14 additions & 8 deletions compiler/rustc_session/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}",
Expand All @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -2159,7 +2163,9 @@ fn collect_print_requests(
));
}
};
PrintRequest { kind, out: OutFileName::Stdout }

let out = out.unwrap_or(OutFileName::Stdout);
PrintRequest { kind, out }
}));

prints
Expand Down