From f22a80890a5e7245afccef0ab7f7ccc45105df4d Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sun, 16 May 2021 15:35:10 +0200 Subject: [PATCH] Use parse_target_triple in rustdoc --- compiler/rustc_session/src/config.rs | 5 ++++- src/librustdoc/config.rs | 15 +++++---------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index f517c483758..1c6fad2ae8e 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -1507,7 +1507,10 @@ fn collect_print_requests( prints } -fn parse_target_triple(matches: &getopts::Matches, error_format: ErrorOutputType) -> TargetTriple { +pub fn parse_target_triple( + matches: &getopts::Matches, + error_format: ErrorOutputType, +) -> TargetTriple { match matches.opt_str("target") { Some(target) if target.ends_with(".json") => { let path = Path::new(&target); diff --git a/src/librustdoc/config.rs b/src/librustdoc/config.rs index ac863a1b05b..6e1fdf67a65 100644 --- a/src/librustdoc/config.rs +++ b/src/librustdoc/config.rs @@ -6,8 +6,10 @@ use std::path::PathBuf; use std::str::FromStr; use rustc_data_structures::fx::FxHashMap; -use rustc_session::config::{self, parse_crate_types_from_list, parse_externs, CrateType}; -use rustc_session::config::{get_cmd_lint_options, host_triple, nightly_options}; +use rustc_session::config::{ + self, parse_crate_types_from_list, parse_externs, parse_target_triple, CrateType, +}; +use rustc_session::config::{get_cmd_lint_options, nightly_options}; use rustc_session::config::{CodegenOptions, DebuggingOptions, ErrorOutputType, Externs}; use rustc_session::getopts; use rustc_session::lint::Level; @@ -562,14 +564,7 @@ impl Options { } } - let target = - matches.opt_str("target").map_or(TargetTriple::from_triple(host_triple()), |target| { - if target.ends_with(".json") { - TargetTriple::from_path(Path::new(&target)) - } else { - TargetTriple::TargetTriple(target) - } - }); + let target = parse_target_triple(matches, error_format); let show_coverage = matches.opt_present("show-coverage");