1
Fork 0

Remove --extern-location and all associated code

`--extern-location` was an experiment to investigate the best way to
generate useful diagnostics for unused dependency warnings by enabling a
build system to identify the corresponding build config.

While I did successfully use this, I've since been convinced the
alternative `--json unused-externs` mechanism is the way to go, and
there's no point in having two mechanisms with basically the same
functionality.

This effectively reverts https://github.com/rust-lang/rust/pull/72603
This commit is contained in:
Jeremy Fitzhardinge 2022-04-14 23:07:57 -07:00 committed by Jeremy Fitzhardinge
parent e7575f9670
commit 1be1157d75
36 changed files with 6 additions and 517 deletions

View file

@ -15,8 +15,6 @@ use rustc_target::abi::{Align, TargetDataLayout};
use rustc_target::spec::{LinkerFlavor, SplitDebuginfo, Target, TargetTriple, TargetWarnings};
use rustc_target::spec::{PanicStrategy, SanitizerSet, TARGETS};
use rustc_serialize::json;
use crate::parse::{CrateCheckConfig, CrateConfig};
use rustc_feature::UnstableFeatures;
use rustc_span::edition::{Edition, DEFAULT_EDITION, EDITION_NAME_LIST, LATEST_STABLE_EDITION};
@ -460,9 +458,6 @@ impl OutputTypes {
#[derive(Clone)]
pub struct Externs(BTreeMap<String, ExternEntry>);
#[derive(Clone)]
pub struct ExternDepSpecs(BTreeMap<String, ExternDepSpec>);
#[derive(Clone, Debug)]
pub struct ExternEntry {
pub location: ExternLocation,
@ -494,27 +489,6 @@ pub enum ExternLocation {
ExactPaths(BTreeSet<CanonicalizedPath>),
}
/// Supplied source location of a dependency - for example in a build specification
/// file like Cargo.toml. We support several syntaxes: if it makes sense to reference
/// a file and line, then the build system can specify that. On the other hand, it may
/// make more sense to have an arbitrary raw string.
#[derive(Clone, PartialEq)]
pub enum ExternDepSpec {
/// Raw string
Raw(String),
/// Raw data in json format
Json(json::Json),
}
impl<'a> From<&'a ExternDepSpec> for rustc_lint_defs::ExternDepSpec {
fn from(from: &'a ExternDepSpec) -> Self {
match from {
ExternDepSpec::Raw(s) => rustc_lint_defs::ExternDepSpec::Raw(s.clone()),
ExternDepSpec::Json(json) => rustc_lint_defs::ExternDepSpec::Json(json.clone()),
}
}
}
impl Externs {
/// Used for testing.
pub fn new(data: BTreeMap<String, ExternEntry>) -> Externs {
@ -547,25 +521,6 @@ impl ExternEntry {
}
}
impl ExternDepSpecs {
pub fn new(data: BTreeMap<String, ExternDepSpec>) -> ExternDepSpecs {
ExternDepSpecs(data)
}
pub fn get(&self, key: &str) -> Option<&ExternDepSpec> {
self.0.get(key)
}
}
impl fmt::Display for ExternDepSpec {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
ExternDepSpec::Raw(raw) => fmt.write_str(raw),
ExternDepSpec::Json(json) => json::as_json(json).fmt(fmt),
}
}
}
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
pub enum PrintRequest {
FileNames,
@ -785,7 +740,6 @@ impl Default for Options {
cg: Default::default(),
error_format: ErrorOutputType::default(),
externs: Externs(BTreeMap::new()),
extern_dep_specs: ExternDepSpecs(BTreeMap::new()),
crate_name: None,
libs: Vec::new(),
unstable_features: UnstableFeatures::Disallow,
@ -1454,12 +1408,6 @@ pub fn rustc_optgroups() -> Vec<RustcOptGroup> {
"Specify where an external rust library is located",
"NAME[=PATH]",
),
opt::multi_s(
"",
"extern-location",
"Location where an external crate dependency is specified",
"NAME=LOCATION",
),
opt::opt_s("", "sysroot", "Override the system root", "PATH"),
opt::multi("Z", "", "Set internal debugging options", "FLAG"),
opt::opt_s(
@ -2221,68 +2169,6 @@ pub fn parse_externs(
Externs(externs)
}
fn parse_extern_dep_specs(
matches: &getopts::Matches,
debugging_opts: &DebuggingOptions,
error_format: ErrorOutputType,
) -> ExternDepSpecs {
let is_unstable_enabled = debugging_opts.unstable_options;
let mut map = BTreeMap::new();
for arg in matches.opt_strs("extern-location") {
if !is_unstable_enabled {
early_error(
error_format,
"`--extern-location` option is unstable: set `-Z unstable-options`",
);
}
let mut parts = arg.splitn(2, '=');
let name = parts.next().unwrap_or_else(|| {
early_error(error_format, "`--extern-location` value must not be empty")
});
let loc = parts.next().unwrap_or_else(|| {
early_error(
error_format,
&format!("`--extern-location`: specify location for extern crate `{name}`"),
)
});
let locparts: Vec<_> = loc.split(':').collect();
let spec = match &locparts[..] {
["raw", ..] => {
// Don't want `:` split string
let raw = loc.splitn(2, ':').nth(1).unwrap_or_else(|| {
early_error(error_format, "`--extern-location`: missing `raw` location")
});
ExternDepSpec::Raw(raw.to_string())
}
["json", ..] => {
// Don't want `:` split string
let raw = loc.splitn(2, ':').nth(1).unwrap_or_else(|| {
early_error(error_format, "`--extern-location`: missing `json` location")
});
let json = json::from_str(raw).unwrap_or_else(|_| {
early_error(
error_format,
&format!("`--extern-location`: malformed json location `{raw}`"),
)
});
ExternDepSpec::Json(json)
}
[bad, ..] => early_error(
error_format,
&format!("unknown location type `{bad}`: use `raw` or `json`"),
),
[] => early_error(error_format, "missing location specification"),
};
map.insert(name.to_string(), spec);
}
ExternDepSpecs::new(map)
}
fn parse_remap_path_prefix(
matches: &getopts::Matches,
debugging_opts: &DebuggingOptions,
@ -2525,7 +2411,6 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
}
let externs = parse_externs(matches, &debugging_opts, error_format);
let extern_dep_specs = parse_extern_dep_specs(matches, &debugging_opts, error_format);
let crate_name = matches.opt_str("crate-name");
@ -2601,7 +2486,6 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
error_format,
externs,
unstable_features: UnstableFeatures::from_environment(crate_name.as_deref()),
extern_dep_specs,
crate_name,
libs,
debug_assertions,

View file

@ -183,7 +183,6 @@ top_level_options!(
borrowck_mode: BorrowckMode [UNTRACKED],
cg: CodegenOptions [SUBSTRUCT],
externs: Externs [UNTRACKED],
extern_dep_specs: ExternDepSpecs [UNTRACKED],
crate_name: Option<String> [TRACKED],
/// Indicates how the compiler should treat unstable features.
unstable_features: UnstableFeatures [TRACKED],