From 82ccb6582a76d72fb5abaf7195dc7a653f1aa54b Mon Sep 17 00:00:00 2001 From: Jeremy Fitzhardinge Date: Mon, 25 May 2020 16:21:25 -0700 Subject: [PATCH] Add `--extern-loc` to augment unused crate dependency diagnostics This allows a build system to indicate a location in its own dependency specification files (eg Cargo's `Cargo.toml`) which can be reported along side any unused crate dependency. This supports several types of location: - 'json' - provide some json-structured data, which is included in the json diagnostics in a `tool_metadata` field - 'raw' - emit the provided string into the output. This also appears as a json string in `tool_metadata`. If no `--extern-location` is explicitly provided then a default json entry of the form `"tool_metadata":{"name":,"path":}` is emitted. --- Cargo.lock | 5 +- compiler/rustc_errors/src/diagnostic.rs | 24 ++++ compiler/rustc_errors/src/json.rs | 6 + compiler/rustc_errors/src/lib.rs | 35 +++++- compiler/rustc_lint/Cargo.toml | 1 + compiler/rustc_lint/src/context.rs | 31 ++++- compiler/rustc_lint_defs/src/lib.rs | 9 ++ compiler/rustc_metadata/src/creader.rs | 27 +++- compiler/rustc_session/src/config.rs | 116 ++++++++++++++++++ compiler/rustc_session/src/options.rs | 1 + .../src/compiler-flags/extern-location.md | 31 +++++ .../ui/json-bom-plus-crlf-multifile.stderr | 16 +-- src/test/ui/json-bom-plus-crlf.stderr | 16 +-- src/test/ui/json-short.stderr | 4 +- .../lint/unused_parens_json_suggestion.stderr | 4 +- ...nused_parens_remove_json_suggestion.stderr | 22 ++-- src/test/ui/lint/use_suggestion_json.stderr | 12 +- src/test/ui/terminal-width/flag-json.stderr | 6 +- .../extern-loc-bad-loctype.rs | 8 ++ .../extern-loc-bad-loctype.stderr | 2 + .../unused-crate-deps/extern-loc-defl-json.rs | 10 ++ .../extern-loc-defl-json.stderr | 17 +++ .../extern-loc-json-bad-json.rs | 8 ++ .../extern-loc-json-bad-json.stderr | 2 + .../unused-crate-deps/extern-loc-json-json.rs | 10 ++ .../extern-loc-json-json.stderr | 17 +++ .../ui/unused-crate-deps/extern-loc-json.rs | 10 ++ .../unused-crate-deps/extern-loc-json.stderr | 15 +++ .../extern-loc-missing-loc.rs | 8 ++ .../extern-loc-missing-loc.stderr | 2 + .../extern-loc-missing-loctype.rs | 8 ++ .../extern-loc-missing-loctype.stderr | 2 + .../unused-crate-deps/extern-loc-raw-json.rs | 10 ++ .../extern-loc-raw-json.stderr | 17 +++ .../extern-loc-raw-missing-loc.rs | 8 ++ .../extern-loc-raw-missing-loc.stderr | 2 + .../ui/unused-crate-deps/extern-loc-raw.rs | 10 ++ .../unused-crate-deps/extern-loc-raw.stderr | 15 +++ src/test/ui/unused-crate-deps/libfib.stderr | 1 + src/test/ui/unused-crate-deps/test.mk | 7 ++ .../unused-crate-deps/unused-aliases.stderr | 1 + .../ui/unused-crate-deps/warn-attr.stderr | 1 + .../warn-cmdline-static.stderr | 1 + .../ui/unused-crate-deps/warn-cmdline.stderr | 1 + 44 files changed, 512 insertions(+), 47 deletions(-) create mode 100644 src/doc/unstable-book/src/compiler-flags/extern-location.md create mode 100644 src/test/ui/unused-crate-deps/extern-loc-bad-loctype.rs create mode 100644 src/test/ui/unused-crate-deps/extern-loc-bad-loctype.stderr create mode 100644 src/test/ui/unused-crate-deps/extern-loc-defl-json.rs create mode 100644 src/test/ui/unused-crate-deps/extern-loc-defl-json.stderr create mode 100644 src/test/ui/unused-crate-deps/extern-loc-json-bad-json.rs create mode 100644 src/test/ui/unused-crate-deps/extern-loc-json-bad-json.stderr create mode 100644 src/test/ui/unused-crate-deps/extern-loc-json-json.rs create mode 100644 src/test/ui/unused-crate-deps/extern-loc-json-json.stderr create mode 100644 src/test/ui/unused-crate-deps/extern-loc-json.rs create mode 100644 src/test/ui/unused-crate-deps/extern-loc-json.stderr create mode 100644 src/test/ui/unused-crate-deps/extern-loc-missing-loc.rs create mode 100644 src/test/ui/unused-crate-deps/extern-loc-missing-loc.stderr create mode 100644 src/test/ui/unused-crate-deps/extern-loc-missing-loctype.rs create mode 100644 src/test/ui/unused-crate-deps/extern-loc-missing-loctype.stderr create mode 100644 src/test/ui/unused-crate-deps/extern-loc-raw-json.rs create mode 100644 src/test/ui/unused-crate-deps/extern-loc-raw-json.stderr create mode 100644 src/test/ui/unused-crate-deps/extern-loc-raw-missing-loc.rs create mode 100644 src/test/ui/unused-crate-deps/extern-loc-raw-missing-loc.stderr create mode 100644 src/test/ui/unused-crate-deps/extern-loc-raw.rs create mode 100644 src/test/ui/unused-crate-deps/extern-loc-raw.stderr create mode 100644 src/test/ui/unused-crate-deps/test.mk diff --git a/Cargo.lock b/Cargo.lock index 6f29120455e..fd23b2764c0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -726,9 +726,9 @@ dependencies = [ [[package]] name = "const_fn" -version = "0.4.2" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce90df4c658c62f12d78f7508cf92f9173e5184a539c10bfe54a3107b3ffd0f2" +checksum = "c478836e029dcef17fb47c89023448c64f781a046e0300e257ad8225ae59afab" [[package]] name = "constant_time_eq" @@ -3914,6 +3914,7 @@ dependencies = [ "rustc_index", "rustc_middle", "rustc_parse_format", + "rustc_serialize", "rustc_session", "rustc_span", "rustc_target", diff --git a/compiler/rustc_errors/src/diagnostic.rs b/compiler/rustc_errors/src/diagnostic.rs index e61476bf23e..ef4a45cab41 100644 --- a/compiler/rustc_errors/src/diagnostic.rs +++ b/compiler/rustc_errors/src/diagnostic.rs @@ -4,7 +4,9 @@ use crate::Substitution; use crate::SubstitutionPart; use crate::SuggestionStyle; +use crate::ToolMetadata; use rustc_lint_defs::Applicability; +use rustc_serialize::json::Json; use rustc_span::{MultiSpan, Span, DUMMY_SP}; use std::fmt; @@ -303,6 +305,7 @@ pub fn multipart_suggestion( msg: msg.to_owned(), style: SuggestionStyle::ShowCode, applicability, + tool_metadata: Default::default(), }); self } @@ -328,6 +331,7 @@ pub fn multipart_suggestions( msg: msg.to_owned(), style: SuggestionStyle::ShowCode, applicability, + tool_metadata: Default::default(), }); self } @@ -354,6 +358,7 @@ pub fn tool_only_multipart_suggestion( msg: msg.to_owned(), style: SuggestionStyle::CompletelyHidden, applicability, + tool_metadata: Default::default(), }); self } @@ -408,6 +413,7 @@ pub fn span_suggestion_with_style( msg: msg.to_owned(), style, applicability, + tool_metadata: Default::default(), }); self } @@ -446,6 +452,7 @@ pub fn span_suggestions( msg: msg.to_owned(), style: SuggestionStyle::ShowCode, applicability, + tool_metadata: Default::default(), }); self } @@ -515,6 +522,23 @@ pub fn tool_only_span_suggestion( self } + /// Adds a suggestion intended only for a tool. The intent is that the metadata encodes + /// the suggestion in a tool-specific way, as it may not even directly involve Rust code. + pub fn tool_only_suggestion_with_metadata( + &mut self, + msg: &str, + applicability: Applicability, + tool_metadata: Json, + ) { + self.suggestions.push(CodeSuggestion { + substitutions: vec![], + msg: msg.to_owned(), + style: SuggestionStyle::CompletelyHidden, + applicability, + tool_metadata: ToolMetadata::new(tool_metadata), + }) + } + pub fn set_span>(&mut self, sp: S) -> &mut Self { self.span = sp.into(); if let Some(span) = self.span.primary_span() { diff --git a/compiler/rustc_errors/src/json.rs b/compiler/rustc_errors/src/json.rs index d57beb1148a..89e844879f7 100644 --- a/compiler/rustc_errors/src/json.rs +++ b/compiler/rustc_errors/src/json.rs @@ -14,6 +14,7 @@ use crate::emitter::{Emitter, HumanReadableErrorType}; use crate::registry::Registry; use crate::DiagnosticId; +use crate::ToolMetadata; use crate::{CodeSuggestion, SubDiagnostic}; use rustc_lint_defs::{Applicability, FutureBreakage}; @@ -180,6 +181,8 @@ struct Diagnostic { children: Vec, /// The message as rustc would render it. rendered: Option, + /// Extra tool metadata + tool_metadata: ToolMetadata, } #[derive(Encodable)] @@ -269,6 +272,7 @@ fn from_errors_diagnostic(diag: &crate::Diagnostic, je: &JsonEmitter) -> Diagnos spans: DiagnosticSpan::from_suggestion(sugg, je), children: vec![], rendered: None, + tool_metadata: sugg.tool_metadata.clone(), }); // generate regular command line output and store it in the json @@ -312,6 +316,7 @@ fn flush(&mut self) -> io::Result<()> { .chain(sugg) .collect(), rendered: Some(output), + tool_metadata: ToolMetadata::default(), } } @@ -327,6 +332,7 @@ fn from_sub_diagnostic(diag: &SubDiagnostic, je: &JsonEmitter) -> Diagnostic { .unwrap_or_else(|| DiagnosticSpan::from_multispan(&diag.span, je)), children: vec![], rendered: None, + tool_metadata: ToolMetadata::default(), } } } diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index aa882332099..73ddf507723 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -23,10 +23,13 @@ use rustc_data_structures::AtomicRef; use rustc_lint_defs::FutureBreakage; pub use rustc_lint_defs::{pluralize, Applicability}; +use rustc_serialize::json::Json; +use rustc_serialize::{Decodable, Decoder, Encodable, Encoder}; use rustc_span::source_map::SourceMap; use rustc_span::{Loc, MultiSpan, Span}; use std::borrow::Cow; +use std::hash::{Hash, Hasher}; use std::panic; use std::path::Path; use std::{error, fmt}; @@ -73,6 +76,35 @@ fn hide_inline(&self) -> bool { } } +#[derive(Clone, Debug, PartialEq, Default)] +pub struct ToolMetadata(pub Option); + +impl ToolMetadata { + fn new(json: Json) -> Self { + ToolMetadata(Some(json)) + } +} + +impl Hash for ToolMetadata { + fn hash(&self, _state: &mut H) {} +} + +// Doesn't really need to round-trip +impl Decodable for ToolMetadata { + fn decode(_d: &mut D) -> Result { + Ok(ToolMetadata(None)) + } +} + +impl Encodable for ToolMetadata { + fn encode(&self, e: &mut S) -> Result<(), S::Error> { + match &self.0 { + None => e.emit_unit(), + Some(json) => json.encode(e), + } + } +} + #[derive(Clone, Debug, PartialEq, Hash, Encodable, Decodable)] pub struct CodeSuggestion { /// Each substitute can have multiple variants due to multiple @@ -106,6 +138,8 @@ pub struct CodeSuggestion { /// which are useful for users but not useful for /// tools like rustfix pub applicability: Applicability, + /// Tool-specific metadata + pub tool_metadata: ToolMetadata, } #[derive(Clone, Debug, PartialEq, Hash, Encodable, Decodable)] @@ -775,7 +809,6 @@ fn emit_diagnostic(&mut self, diagnostic: &Diagnostic) { } let already_emitted = |this: &mut Self| { - use std::hash::Hash; let mut hasher = StableHasher::new(); diagnostic.hash(&mut hasher); let diagnostic_hash = hasher.finish(); diff --git a/compiler/rustc_lint/Cargo.toml b/compiler/rustc_lint/Cargo.toml index c56eb09b634..90badd3d573 100644 --- a/compiler/rustc_lint/Cargo.toml +++ b/compiler/rustc_lint/Cargo.toml @@ -19,5 +19,6 @@ rustc_data_structures = { path = "../rustc_data_structures" } rustc_feature = { path = "../rustc_feature" } rustc_index = { path = "../rustc_index" } rustc_session = { path = "../rustc_session" } +rustc_serialize = { path = "../rustc_serialize" } rustc_trait_selection = { path = "../rustc_trait_selection" } rustc_parse_format = { path = "../rustc_parse_format" } diff --git a/compiler/rustc_lint/src/context.rs b/compiler/rustc_lint/src/context.rs index 254220839aa..b8db51f590d 100644 --- a/compiler/rustc_lint/src/context.rs +++ b/compiler/rustc_lint/src/context.rs @@ -21,7 +21,9 @@ use rustc_ast as ast; use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::sync; -use rustc_errors::{add_elided_lifetime_in_path_suggestion, struct_span_err, Applicability}; +use rustc_errors::{ + add_elided_lifetime_in_path_suggestion, struct_span_err, Applicability, SuggestionStyle, +}; use rustc_hir as hir; use rustc_hir::def::Res; use rustc_hir::def_id::{CrateNum, DefId}; @@ -32,7 +34,8 @@ use rustc_middle::ty::layout::{LayoutError, TyAndLayout}; use rustc_middle::ty::print::with_no_trimmed_paths; use rustc_middle::ty::{self, print::Printer, subst::GenericArg, Ty, TyCtxt}; -use rustc_session::lint::BuiltinLintDiagnostics; +use rustc_serialize::json::Json; +use rustc_session::lint::{BuiltinLintDiagnostics, ExternDepSpec}; use rustc_session::lint::{FutureIncompatibleInfo, Level, Lint, LintBuffer, LintId}; use rustc_session::Session; use rustc_session::SessionLintStore; @@ -639,6 +642,30 @@ fn lookup_with_diagnostics( BuiltinLintDiagnostics::LegacyDeriveHelpers(span) => { db.span_label(span, "the attribute is introduced here"); } + BuiltinLintDiagnostics::ExternDepSpec(krate, loc) => { + let json = match loc { + ExternDepSpec::Json(json) => { + db.help(&format!("remove unnecessary dependency `{}`", krate)); + json + } + ExternDepSpec::Raw(raw) => { + db.help(&format!("remove unnecessary dependency `{}` at `{}`", krate, raw)); + db.span_suggestion_with_style( + DUMMY_SP, + "raw extern location", + raw.clone(), + Applicability::Unspecified, + SuggestionStyle::CompletelyHidden, + ); + Json::String(raw) + } + }; + db.tool_only_suggestion_with_metadata( + "json extern location", + Applicability::Unspecified, + json + ); + } } // Rewrap `db`, and pass control to the user. decorate(LintDiagnosticBuilder::new(db)); diff --git a/compiler/rustc_lint_defs/src/lib.rs b/compiler/rustc_lint_defs/src/lib.rs index 594e2cbd3ae..4c7d3f6c8c0 100644 --- a/compiler/rustc_lint_defs/src/lib.rs +++ b/compiler/rustc_lint_defs/src/lib.rs @@ -4,6 +4,7 @@ pub use self::Level::*; use rustc_ast::node_id::{NodeId, NodeMap}; use rustc_data_structures::stable_hasher::{HashStable, StableHasher, ToStableHashKey}; +use rustc_serialize::json::Json; use rustc_span::edition::Edition; use rustc_span::{sym, symbol::Ident, MultiSpan, Span, Symbol}; use rustc_target::spec::abi::Abi; @@ -239,6 +240,13 @@ fn to_stable_hash_key(&self, _: &HCX) -> &'static str { } } +// Duplicated from rustc_session::config::ExternDepSpec to avoid cyclic dependency +#[derive(PartialEq)] +pub enum ExternDepSpec { + Json(Json), + Raw(String), +} + // This could be a closure, but then implementing derive trait // becomes hacky (and it gets allocated). #[derive(PartialEq)] @@ -257,6 +265,7 @@ pub enum BuiltinLintDiagnostics { UnusedDocComment(Span), PatternsInFnsWithoutBody(Span, Ident), LegacyDeriveHelpers(Span), + ExternDepSpec(String, ExternDepSpec), } /// Lints that are buffered up early on in the `Session` before the diff --git a/compiler/rustc_metadata/src/creader.rs b/compiler/rustc_metadata/src/creader.rs index e3fbd1a2b29..63c6f369eb6 100644 --- a/compiler/rustc_metadata/src/creader.rs +++ b/compiler/rustc_metadata/src/creader.rs @@ -16,8 +16,9 @@ use rustc_middle::middle::cstore::{CrateDepKind, CrateSource, ExternCrate}; use rustc_middle::middle::cstore::{ExternCrateSource, MetadataLoaderDyn}; use rustc_middle::ty::TyCtxt; +use rustc_serialize::json::ToJson; use rustc_session::config::{self, CrateType, ExternLocation}; -use rustc_session::lint; +use rustc_session::lint::{self, BuiltinLintDiagnostics, ExternDepSpec}; use rustc_session::output::validate_crate_name; use rustc_session::search_paths::PathKind; use rustc_session::{CrateDisambiguator, Session}; @@ -27,6 +28,7 @@ use rustc_target::spec::{PanicStrategy, TargetTriple}; use proc_macro::bridge::client::ProcMacro; +use std::collections::BTreeMap; use std::path::Path; use std::{cmp, env}; use tracing::{debug, info}; @@ -871,8 +873,25 @@ fn report_unused_deps(&mut self, krate: &ast::Crate) { // Don't worry about pathless `--extern foo` sysroot references continue; } - if !self.used_extern_options.contains(&Symbol::intern(name)) { - self.sess.parse_sess.buffer_lint( + if self.used_extern_options.contains(&Symbol::intern(name)) { + continue; + } + + // Got a real unused --extern + let diag = match self.sess.opts.extern_dep_specs.get(name) { + Some(loc) => BuiltinLintDiagnostics::ExternDepSpec(name.clone(), loc.into()), + None => { + // If we don't have a specific location, provide a json encoding of the `--extern` + // option. + let meta: BTreeMap = + std::iter::once(("name".to_string(), name.to_string())).collect(); + BuiltinLintDiagnostics::ExternDepSpec( + name.clone(), + ExternDepSpec::Json(meta.to_json()), + ) + } + }; + self.sess.parse_sess.buffer_lint_with_diagnostic( lint::builtin::UNUSED_CRATE_DEPENDENCIES, span, ast::CRATE_NODE_ID, @@ -881,8 +900,8 @@ fn report_unused_deps(&mut self, krate: &ast::Crate) { name, self.local_crate_name, name), + diag, ); - } } } diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index 9d73c3b4424..e9ea0ab6f98 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -15,6 +15,8 @@ use rustc_target::abi::{Align, TargetDataLayout}; use rustc_target::spec::{SplitDebuginfo, Target, TargetTriple}; +use rustc_serialize::json; + use crate::parse::CrateConfig; use rustc_feature::UnstableFeatures; use rustc_span::edition::{Edition, DEFAULT_EDITION, EDITION_NAME_LIST}; @@ -408,6 +410,9 @@ pub fn should_link(&self) -> bool { #[derive(Clone)] pub struct Externs(BTreeMap); +#[derive(Clone)] +pub struct ExternDepSpecs(BTreeMap); + #[derive(Clone, Debug)] pub struct ExternEntry { pub location: ExternLocation, @@ -439,6 +444,27 @@ pub enum ExternLocation { ExactPaths(BTreeSet), } +/// 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 { pub fn new(data: BTreeMap) -> Externs { Externs(data) @@ -466,6 +492,25 @@ pub fn files(&self) -> Option> { } } +impl ExternDepSpecs { + pub fn new(data: BTreeMap) -> 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, @@ -679,6 +724,7 @@ fn default() -> Options { cg: basic_codegen_options(), error_format: ErrorOutputType::default(), externs: Externs(BTreeMap::new()), + extern_dep_specs: ExternDepSpecs(BTreeMap::new()), crate_name: None, alt_std_name: None, libs: Vec::new(), @@ -1105,6 +1151,12 @@ pub fn rustc_optgroups() -> Vec { "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( @@ -1727,6 +1779,68 @@ 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 `{}`: use `raw` or `json`", bad), + ), + [] => early_error(error_format, "missing location specification"), + }; + + map.insert(name.to_string(), spec); + } + + ExternDepSpecs::new(map) +} + fn parse_remap_path_prefix( matches: &getopts::Matches, error_format: ErrorOutputType, @@ -1888,6 +2002,7 @@ 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"); @@ -1924,6 +2039,7 @@ 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, alt_std_name: None, libs, diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index 779e0421636..f78df8a7e29 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -112,6 +112,7 @@ pub struct Options { borrowck_mode: BorrowckMode [UNTRACKED], cg: CodegenOptions [TRACKED], externs: Externs [UNTRACKED], + extern_dep_specs: ExternDepSpecs [UNTRACKED], crate_name: Option [TRACKED], // An optional name to use as the crate for std during std injection, // written `extern crate name as std`. Defaults to `std`. Used by diff --git a/src/doc/unstable-book/src/compiler-flags/extern-location.md b/src/doc/unstable-book/src/compiler-flags/extern-location.md new file mode 100644 index 00000000000..1c80d5426bf --- /dev/null +++ b/src/doc/unstable-book/src/compiler-flags/extern-location.md @@ -0,0 +1,31 @@ +# `extern-location` + +MCP for this feature: [#303] + +[#303]: https://github.com/rust-lang/compiler-team/issues/303 + +------------------------ + +The `unused-extern-crates` lint reports when a crate was specified on the rustc +command-line with `--extern name=path` but no symbols were referenced in it. +This is useful to know, but it's hard to map that back to a specific place a user +or tool could fix (ie, to remove the unused dependency). + +The `--extern-location` flag allows the build system to associate a location with +the `--extern` option, which is then emitted as part of the diagnostics. This location +is abstract and just round-tripped through rustc; the compiler never attempts to +interpret it in any way. + +There are two supported forms of location: a bare string, or a blob of json: +- `--extern-location foo=raw:Makefile:123` would associate the raw string `Makefile:123` +- `--extern-location 'bar=json:{"target":"//my_project:library","dep":"//common:serde"}` would + associate the json structure with `--extern bar=`, indicating which dependency of + which rule introduced the unused extern crate. + +This primarily intended to be used with tooling - for example a linter which can automatically +remove unused dependencies - rather than being directly presented to users. + +`raw` locations are presented as part of the normal rendered diagnostics and included in +the json form. `json` locations are only included in the json form of diagnostics, +as a `tool_metadata` field. For `raw` locations `tool_metadata` is simply a json string, +whereas `json` allows the rustc invoker to fully control its form and content. diff --git a/src/test/ui/json-bom-plus-crlf-multifile.stderr b/src/test/ui/json-bom-plus-crlf-multifile.stderr index da8849a8284..747bf88e45d 100644 --- a/src/test/ui/json-bom-plus-crlf-multifile.stderr +++ b/src/test/ui/json-bom-plus-crlf-multifile.stderr @@ -24,8 +24,8 @@ This error occurs when an expression was used in a place where the compiler expected an expression of a different type. It can occur in several cases, the most common being when calling a function and passing an argument which has a different type than the matching type in the function declaration. -"},"level":"error","spans":[{"file_name":"$DIR/json-bom-plus-crlf-multifile-aux.rs","byte_start":621,"byte_end":622,"line_start":17,"line_end":17,"column_start":22,"column_end":23,"is_primary":true,"text":[{"text":" let s : String = 1; // Error in the middle of line.","highlight_start":22,"highlight_end":23}],"label":"expected struct `String`, found integer","suggested_replacement":null,"suggestion_applicability":null,"expansion":null},{"file_name":"$DIR/json-bom-plus-crlf-multifile-aux.rs","byte_start":612,"byte_end":618,"line_start":17,"line_end":17,"column_start":13,"column_end":19,"is_primary":false,"text":[{"text":" let s : String = 1; // Error in the middle of line.","highlight_start":13,"highlight_end":19}],"label":"expected due to this","suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[{"message":"try using a conversion method","code":null,"level":"help","spans":[{"file_name":"$DIR/json-bom-plus-crlf-multifile-aux.rs","byte_start":621,"byte_end":622,"line_start":17,"line_end":17,"column_start":22,"column_end":23,"is_primary":true,"text":[{"text":" let s : String = 1; // Error in the middle of line.","highlight_start":22,"highlight_end":23}],"label":null,"suggested_replacement":"1.to_string()","suggestion_applicability":"MaybeIncorrect","expansion":null}],"children":[],"rendered":null}],"rendered":"$DIR/json-bom-plus-crlf-multifile-aux.rs:17:22: error[E0308]: mismatched types -"} +"},"level":"error","spans":[{"file_name":"$DIR/json-bom-plus-crlf-multifile-aux.rs","byte_start":621,"byte_end":622,"line_start":17,"line_end":17,"column_start":22,"column_end":23,"is_primary":true,"text":[{"text":" let s : String = 1; // Error in the middle of line.","highlight_start":22,"highlight_end":23}],"label":"expected struct `String`, found integer","suggested_replacement":null,"suggestion_applicability":null,"expansion":null},{"file_name":"$DIR/json-bom-plus-crlf-multifile-aux.rs","byte_start":612,"byte_end":618,"line_start":17,"line_end":17,"column_start":13,"column_end":19,"is_primary":false,"text":[{"text":" let s : String = 1; // Error in the middle of line.","highlight_start":13,"highlight_end":19}],"label":"expected due to this","suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[{"message":"try using a conversion method","code":null,"level":"help","spans":[{"file_name":"$DIR/json-bom-plus-crlf-multifile-aux.rs","byte_start":621,"byte_end":622,"line_start":17,"line_end":17,"column_start":22,"column_end":23,"is_primary":true,"text":[{"text":" let s : String = 1; // Error in the middle of line.","highlight_start":22,"highlight_end":23}],"label":null,"suggested_replacement":"1.to_string()","suggestion_applicability":"MaybeIncorrect","expansion":null}],"children":[],"rendered":null,"tool_metadata":null}],"rendered":"$DIR/json-bom-plus-crlf-multifile-aux.rs:17:22: error[E0308]: mismatched types +","tool_metadata":null} {"message":"mismatched types","code":{"code":"E0308","explanation":"Expected type did not match the received type. Erroneous code examples: @@ -52,8 +52,8 @@ This error occurs when an expression was used in a place where the compiler expected an expression of a different type. It can occur in several cases, the most common being when calling a function and passing an argument which has a different type than the matching type in the function declaration. -"},"level":"error","spans":[{"file_name":"$DIR/json-bom-plus-crlf-multifile-aux.rs","byte_start":681,"byte_end":682,"line_start":19,"line_end":19,"column_start":22,"column_end":23,"is_primary":true,"text":[{"text":" let s : String = 1","highlight_start":22,"highlight_end":23}],"label":"expected struct `String`, found integer","suggested_replacement":null,"suggestion_applicability":null,"expansion":null},{"file_name":"$DIR/json-bom-plus-crlf-multifile-aux.rs","byte_start":672,"byte_end":678,"line_start":19,"line_end":19,"column_start":13,"column_end":19,"is_primary":false,"text":[{"text":" let s : String = 1","highlight_start":13,"highlight_end":19}],"label":"expected due to this","suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[{"message":"try using a conversion method","code":null,"level":"help","spans":[{"file_name":"$DIR/json-bom-plus-crlf-multifile-aux.rs","byte_start":681,"byte_end":682,"line_start":19,"line_end":19,"column_start":22,"column_end":23,"is_primary":true,"text":[{"text":" let s : String = 1","highlight_start":22,"highlight_end":23}],"label":null,"suggested_replacement":"1.to_string()","suggestion_applicability":"MaybeIncorrect","expansion":null}],"children":[],"rendered":null}],"rendered":"$DIR/json-bom-plus-crlf-multifile-aux.rs:19:22: error[E0308]: mismatched types -"} +"},"level":"error","spans":[{"file_name":"$DIR/json-bom-plus-crlf-multifile-aux.rs","byte_start":681,"byte_end":682,"line_start":19,"line_end":19,"column_start":22,"column_end":23,"is_primary":true,"text":[{"text":" let s : String = 1","highlight_start":22,"highlight_end":23}],"label":"expected struct `String`, found integer","suggested_replacement":null,"suggestion_applicability":null,"expansion":null},{"file_name":"$DIR/json-bom-plus-crlf-multifile-aux.rs","byte_start":672,"byte_end":678,"line_start":19,"line_end":19,"column_start":13,"column_end":19,"is_primary":false,"text":[{"text":" let s : String = 1","highlight_start":13,"highlight_end":19}],"label":"expected due to this","suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[{"message":"try using a conversion method","code":null,"level":"help","spans":[{"file_name":"$DIR/json-bom-plus-crlf-multifile-aux.rs","byte_start":681,"byte_end":682,"line_start":19,"line_end":19,"column_start":22,"column_end":23,"is_primary":true,"text":[{"text":" let s : String = 1","highlight_start":22,"highlight_end":23}],"label":null,"suggested_replacement":"1.to_string()","suggestion_applicability":"MaybeIncorrect","expansion":null}],"children":[],"rendered":null,"tool_metadata":null}],"rendered":"$DIR/json-bom-plus-crlf-multifile-aux.rs:19:22: error[E0308]: mismatched types +","tool_metadata":null} {"message":"mismatched types","code":{"code":"E0308","explanation":"Expected type did not match the received type. Erroneous code examples: @@ -80,8 +80,8 @@ This error occurs when an expression was used in a place where the compiler expected an expression of a different type. It can occur in several cases, the most common being when calling a function and passing an argument which has a different type than the matching type in the function declaration. -"},"level":"error","spans":[{"file_name":"$DIR/json-bom-plus-crlf-multifile-aux.rs","byte_start":745,"byte_end":746,"line_start":23,"line_end":23,"column_start":1,"column_end":2,"is_primary":true,"text":[{"text":"1; // Error after the newline.","highlight_start":1,"highlight_end":2}],"label":"expected struct `String`, found integer","suggested_replacement":null,"suggestion_applicability":null,"expansion":null},{"file_name":"$DIR/json-bom-plus-crlf-multifile-aux.rs","byte_start":735,"byte_end":741,"line_start":22,"line_end":22,"column_start":13,"column_end":19,"is_primary":false,"text":[{"text":" let s : String =","highlight_start":13,"highlight_end":19}],"label":"expected due to this","suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[{"message":"try using a conversion method","code":null,"level":"help","spans":[{"file_name":"$DIR/json-bom-plus-crlf-multifile-aux.rs","byte_start":745,"byte_end":746,"line_start":23,"line_end":23,"column_start":1,"column_end":2,"is_primary":true,"text":[{"text":"1; // Error after the newline.","highlight_start":1,"highlight_end":2}],"label":null,"suggested_replacement":"1.to_string()","suggestion_applicability":"MaybeIncorrect","expansion":null}],"children":[],"rendered":null}],"rendered":"$DIR/json-bom-plus-crlf-multifile-aux.rs:23:1: error[E0308]: mismatched types -"} +"},"level":"error","spans":[{"file_name":"$DIR/json-bom-plus-crlf-multifile-aux.rs","byte_start":745,"byte_end":746,"line_start":23,"line_end":23,"column_start":1,"column_end":2,"is_primary":true,"text":[{"text":"1; // Error after the newline.","highlight_start":1,"highlight_end":2}],"label":"expected struct `String`, found integer","suggested_replacement":null,"suggestion_applicability":null,"expansion":null},{"file_name":"$DIR/json-bom-plus-crlf-multifile-aux.rs","byte_start":735,"byte_end":741,"line_start":22,"line_end":22,"column_start":13,"column_end":19,"is_primary":false,"text":[{"text":" let s : String =","highlight_start":13,"highlight_end":19}],"label":"expected due to this","suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[{"message":"try using a conversion method","code":null,"level":"help","spans":[{"file_name":"$DIR/json-bom-plus-crlf-multifile-aux.rs","byte_start":745,"byte_end":746,"line_start":23,"line_end":23,"column_start":1,"column_end":2,"is_primary":true,"text":[{"text":"1; // Error after the newline.","highlight_start":1,"highlight_end":2}],"label":null,"suggested_replacement":"1.to_string()","suggestion_applicability":"MaybeIncorrect","expansion":null}],"children":[],"rendered":null,"tool_metadata":null}],"rendered":"$DIR/json-bom-plus-crlf-multifile-aux.rs:23:1: error[E0308]: mismatched types +","tool_metadata":null} {"message":"mismatched types","code":{"code":"E0308","explanation":"Expected type did not match the received type. Erroneous code examples: @@ -109,6 +109,6 @@ expected an expression of a different type. It can occur in several cases, the most common being when calling a function and passing an argument which has a different type than the matching type in the function declaration. "},"level":"error","spans":[{"file_name":"$DIR/json-bom-plus-crlf-multifile-aux.rs","byte_start":801,"byte_end":809,"line_start":25,"line_end":26,"column_start":22,"column_end":6,"is_primary":true,"text":[{"text":" let s : String = (","highlight_start":22,"highlight_end":23},{"text":" ); // Error spanning the newline.","highlight_start":1,"highlight_end":6}],"label":"expected struct `String`, found `()`","suggested_replacement":null,"suggestion_applicability":null,"expansion":null},{"file_name":"$DIR/json-bom-plus-crlf-multifile-aux.rs","byte_start":792,"byte_end":798,"line_start":25,"line_end":25,"column_start":13,"column_end":19,"is_primary":false,"text":[{"text":" let s : String = (","highlight_start":13,"highlight_end":19}],"label":"expected due to this","suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[],"rendered":"$DIR/json-bom-plus-crlf-multifile-aux.rs:25:22: error[E0308]: mismatched types -"} +","tool_metadata":null} {"message":"aborting due to 4 previous errors","code":null,"level":"error","spans":[],"children":[],"rendered":"error: aborting due to 4 previous errors -"} +","tool_metadata":null} diff --git a/src/test/ui/json-bom-plus-crlf.stderr b/src/test/ui/json-bom-plus-crlf.stderr index 811206f9aa0..55a509fb9d9 100644 --- a/src/test/ui/json-bom-plus-crlf.stderr +++ b/src/test/ui/json-bom-plus-crlf.stderr @@ -24,8 +24,8 @@ This error occurs when an expression was used in a place where the compiler expected an expression of a different type. It can occur in several cases, the most common being when calling a function and passing an argument which has a different type than the matching type in the function declaration. -"},"level":"error","spans":[{"file_name":"$DIR/json-bom-plus-crlf.rs","byte_start":606,"byte_end":607,"line_start":16,"line_end":16,"column_start":22,"column_end":23,"is_primary":true,"text":[{"text":" let s : String = 1; // Error in the middle of line.","highlight_start":22,"highlight_end":23}],"label":"expected struct `String`, found integer","suggested_replacement":null,"suggestion_applicability":null,"expansion":null},{"file_name":"$DIR/json-bom-plus-crlf.rs","byte_start":597,"byte_end":603,"line_start":16,"line_end":16,"column_start":13,"column_end":19,"is_primary":false,"text":[{"text":" let s : String = 1; // Error in the middle of line.","highlight_start":13,"highlight_end":19}],"label":"expected due to this","suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[{"message":"try using a conversion method","code":null,"level":"help","spans":[{"file_name":"$DIR/json-bom-plus-crlf.rs","byte_start":606,"byte_end":607,"line_start":16,"line_end":16,"column_start":22,"column_end":23,"is_primary":true,"text":[{"text":" let s : String = 1; // Error in the middle of line.","highlight_start":22,"highlight_end":23}],"label":null,"suggested_replacement":"1.to_string()","suggestion_applicability":"MaybeIncorrect","expansion":null}],"children":[],"rendered":null}],"rendered":"$DIR/json-bom-plus-crlf.rs:16:22: error[E0308]: mismatched types -"} +"},"level":"error","spans":[{"file_name":"$DIR/json-bom-plus-crlf.rs","byte_start":606,"byte_end":607,"line_start":16,"line_end":16,"column_start":22,"column_end":23,"is_primary":true,"text":[{"text":" let s : String = 1; // Error in the middle of line.","highlight_start":22,"highlight_end":23}],"label":"expected struct `String`, found integer","suggested_replacement":null,"suggestion_applicability":null,"expansion":null},{"file_name":"$DIR/json-bom-plus-crlf.rs","byte_start":597,"byte_end":603,"line_start":16,"line_end":16,"column_start":13,"column_end":19,"is_primary":false,"text":[{"text":" let s : String = 1; // Error in the middle of line.","highlight_start":13,"highlight_end":19}],"label":"expected due to this","suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[{"message":"try using a conversion method","code":null,"level":"help","spans":[{"file_name":"$DIR/json-bom-plus-crlf.rs","byte_start":606,"byte_end":607,"line_start":16,"line_end":16,"column_start":22,"column_end":23,"is_primary":true,"text":[{"text":" let s : String = 1; // Error in the middle of line.","highlight_start":22,"highlight_end":23}],"label":null,"suggested_replacement":"1.to_string()","suggestion_applicability":"MaybeIncorrect","expansion":null}],"children":[],"rendered":null,"tool_metadata":null}],"rendered":"$DIR/json-bom-plus-crlf.rs:16:22: error[E0308]: mismatched types +","tool_metadata":null} {"message":"mismatched types","code":{"code":"E0308","explanation":"Expected type did not match the received type. Erroneous code examples: @@ -52,8 +52,8 @@ This error occurs when an expression was used in a place where the compiler expected an expression of a different type. It can occur in several cases, the most common being when calling a function and passing an argument which has a different type than the matching type in the function declaration. -"},"level":"error","spans":[{"file_name":"$DIR/json-bom-plus-crlf.rs","byte_start":666,"byte_end":667,"line_start":18,"line_end":18,"column_start":22,"column_end":23,"is_primary":true,"text":[{"text":" let s : String = 1","highlight_start":22,"highlight_end":23}],"label":"expected struct `String`, found integer","suggested_replacement":null,"suggestion_applicability":null,"expansion":null},{"file_name":"$DIR/json-bom-plus-crlf.rs","byte_start":657,"byte_end":663,"line_start":18,"line_end":18,"column_start":13,"column_end":19,"is_primary":false,"text":[{"text":" let s : String = 1","highlight_start":13,"highlight_end":19}],"label":"expected due to this","suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[{"message":"try using a conversion method","code":null,"level":"help","spans":[{"file_name":"$DIR/json-bom-plus-crlf.rs","byte_start":666,"byte_end":667,"line_start":18,"line_end":18,"column_start":22,"column_end":23,"is_primary":true,"text":[{"text":" let s : String = 1","highlight_start":22,"highlight_end":23}],"label":null,"suggested_replacement":"1.to_string()","suggestion_applicability":"MaybeIncorrect","expansion":null}],"children":[],"rendered":null}],"rendered":"$DIR/json-bom-plus-crlf.rs:18:22: error[E0308]: mismatched types -"} +"},"level":"error","spans":[{"file_name":"$DIR/json-bom-plus-crlf.rs","byte_start":666,"byte_end":667,"line_start":18,"line_end":18,"column_start":22,"column_end":23,"is_primary":true,"text":[{"text":" let s : String = 1","highlight_start":22,"highlight_end":23}],"label":"expected struct `String`, found integer","suggested_replacement":null,"suggestion_applicability":null,"expansion":null},{"file_name":"$DIR/json-bom-plus-crlf.rs","byte_start":657,"byte_end":663,"line_start":18,"line_end":18,"column_start":13,"column_end":19,"is_primary":false,"text":[{"text":" let s : String = 1","highlight_start":13,"highlight_end":19}],"label":"expected due to this","suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[{"message":"try using a conversion method","code":null,"level":"help","spans":[{"file_name":"$DIR/json-bom-plus-crlf.rs","byte_start":666,"byte_end":667,"line_start":18,"line_end":18,"column_start":22,"column_end":23,"is_primary":true,"text":[{"text":" let s : String = 1","highlight_start":22,"highlight_end":23}],"label":null,"suggested_replacement":"1.to_string()","suggestion_applicability":"MaybeIncorrect","expansion":null}],"children":[],"rendered":null,"tool_metadata":null}],"rendered":"$DIR/json-bom-plus-crlf.rs:18:22: error[E0308]: mismatched types +","tool_metadata":null} {"message":"mismatched types","code":{"code":"E0308","explanation":"Expected type did not match the received type. Erroneous code examples: @@ -80,8 +80,8 @@ This error occurs when an expression was used in a place where the compiler expected an expression of a different type. It can occur in several cases, the most common being when calling a function and passing an argument which has a different type than the matching type in the function declaration. -"},"level":"error","spans":[{"file_name":"$DIR/json-bom-plus-crlf.rs","byte_start":730,"byte_end":731,"line_start":22,"line_end":22,"column_start":1,"column_end":2,"is_primary":true,"text":[{"text":"1; // Error after the newline.","highlight_start":1,"highlight_end":2}],"label":"expected struct `String`, found integer","suggested_replacement":null,"suggestion_applicability":null,"expansion":null},{"file_name":"$DIR/json-bom-plus-crlf.rs","byte_start":720,"byte_end":726,"line_start":21,"line_end":21,"column_start":13,"column_end":19,"is_primary":false,"text":[{"text":" let s : String =","highlight_start":13,"highlight_end":19}],"label":"expected due to this","suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[{"message":"try using a conversion method","code":null,"level":"help","spans":[{"file_name":"$DIR/json-bom-plus-crlf.rs","byte_start":730,"byte_end":731,"line_start":22,"line_end":22,"column_start":1,"column_end":2,"is_primary":true,"text":[{"text":"1; // Error after the newline.","highlight_start":1,"highlight_end":2}],"label":null,"suggested_replacement":"1.to_string()","suggestion_applicability":"MaybeIncorrect","expansion":null}],"children":[],"rendered":null}],"rendered":"$DIR/json-bom-plus-crlf.rs:22:1: error[E0308]: mismatched types -"} +"},"level":"error","spans":[{"file_name":"$DIR/json-bom-plus-crlf.rs","byte_start":730,"byte_end":731,"line_start":22,"line_end":22,"column_start":1,"column_end":2,"is_primary":true,"text":[{"text":"1; // Error after the newline.","highlight_start":1,"highlight_end":2}],"label":"expected struct `String`, found integer","suggested_replacement":null,"suggestion_applicability":null,"expansion":null},{"file_name":"$DIR/json-bom-plus-crlf.rs","byte_start":720,"byte_end":726,"line_start":21,"line_end":21,"column_start":13,"column_end":19,"is_primary":false,"text":[{"text":" let s : String =","highlight_start":13,"highlight_end":19}],"label":"expected due to this","suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[{"message":"try using a conversion method","code":null,"level":"help","spans":[{"file_name":"$DIR/json-bom-plus-crlf.rs","byte_start":730,"byte_end":731,"line_start":22,"line_end":22,"column_start":1,"column_end":2,"is_primary":true,"text":[{"text":"1; // Error after the newline.","highlight_start":1,"highlight_end":2}],"label":null,"suggested_replacement":"1.to_string()","suggestion_applicability":"MaybeIncorrect","expansion":null}],"children":[],"rendered":null,"tool_metadata":null}],"rendered":"$DIR/json-bom-plus-crlf.rs:22:1: error[E0308]: mismatched types +","tool_metadata":null} {"message":"mismatched types","code":{"code":"E0308","explanation":"Expected type did not match the received type. Erroneous code examples: @@ -109,6 +109,6 @@ expected an expression of a different type. It can occur in several cases, the most common being when calling a function and passing an argument which has a different type than the matching type in the function declaration. "},"level":"error","spans":[{"file_name":"$DIR/json-bom-plus-crlf.rs","byte_start":786,"byte_end":794,"line_start":24,"line_end":25,"column_start":22,"column_end":6,"is_primary":true,"text":[{"text":" let s : String = (","highlight_start":22,"highlight_end":23},{"text":" ); // Error spanning the newline.","highlight_start":1,"highlight_end":6}],"label":"expected struct `String`, found `()`","suggested_replacement":null,"suggestion_applicability":null,"expansion":null},{"file_name":"$DIR/json-bom-plus-crlf.rs","byte_start":777,"byte_end":783,"line_start":24,"line_end":24,"column_start":13,"column_end":19,"is_primary":false,"text":[{"text":" let s : String = (","highlight_start":13,"highlight_end":19}],"label":"expected due to this","suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[],"rendered":"$DIR/json-bom-plus-crlf.rs:24:22: error[E0308]: mismatched types -"} +","tool_metadata":null} {"message":"aborting due to 4 previous errors","code":null,"level":"error","spans":[],"children":[],"rendered":"error: aborting due to 4 previous errors -"} +","tool_metadata":null} diff --git a/src/test/ui/json-short.stderr b/src/test/ui/json-short.stderr index 3bd85b083d0..23d150f2054 100644 --- a/src/test/ui/json-short.stderr +++ b/src/test/ui/json-short.stderr @@ -14,6 +14,6 @@ If you don't know the basics of Rust, you can look at the [rust-book]: https://doc.rust-lang.org/book/ "},"level":"error","spans":[{"file_name":"$DIR/json-short.rs","byte_start":62,"byte_end":62,"line_start":1,"line_end":1,"column_start":63,"column_end":63,"is_primary":true,"text":[{"text":"// compile-flags: --json=diagnostic-short --error-format=json","highlight_start":63,"highlight_end":63}],"label":"consider adding a `main` function to `$DIR/json-short.rs`","suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[],"rendered":"$DIR/json-short.rs:1:63: error[E0601]: `main` function not found in crate `json_short` -"} +","tool_metadata":null} {"message":"aborting due to previous error","code":null,"level":"error","spans":[],"children":[],"rendered":"error: aborting due to previous error -"} +","tool_metadata":null} diff --git a/src/test/ui/lint/unused_parens_json_suggestion.stderr b/src/test/ui/lint/unused_parens_json_suggestion.stderr index 09f0fc90032..468f2fc726c 100644 --- a/src/test/ui/lint/unused_parens_json_suggestion.stderr +++ b/src/test/ui/lint/unused_parens_json_suggestion.stderr @@ -10,7 +10,7 @@ note: the lint level is defined here LL | #![deny(unused_parens)] | ^^^^^^^^^^^^^ -"} +","tool_metadata":null} {"message":"aborting due to previous error","code":null,"level":"error","spans":[],"children":[],"rendered":"error: aborting due to previous error -"} +","tool_metadata":null} diff --git a/src/test/ui/lint/unused_parens_remove_json_suggestion.stderr b/src/test/ui/lint/unused_parens_remove_json_suggestion.stderr index 5fb67fd7c95..a5ff4f8eb9e 100644 --- a/src/test/ui/lint/unused_parens_remove_json_suggestion.stderr +++ b/src/test/ui/lint/unused_parens_remove_json_suggestion.stderr @@ -10,63 +10,63 @@ note: the lint level is defined here LL | #![deny(unused_parens)] | ^^^^^^^^^^^^^ -"} +","tool_metadata":null} {"message":"unnecessary parentheses around `if` condition","code":{"code":"unused_parens","explanation":null},"level":"error","spans":[{"file_name":"$DIR/unused_parens_remove_json_suggestion.rs","byte_start":631,"byte_end":634,"line_start":28,"line_end":28,"column_start":7,"column_end":10,"is_primary":true,"text":[{"text":" if(c) { --> $DIR/unused_parens_remove_json_suggestion.rs:28:7 | LL | if(c) { | ^^^ help: remove these parentheses -"} +","tool_metadata":null} {"message":"unnecessary parentheses around `if` condition","code":{"code":"unused_parens","explanation":null},"level":"error","spans":[{"file_name":"$DIR/unused_parens_remove_json_suggestion.rs","byte_start":711,"byte_end":714,"line_start":32,"line_end":32,"column_start":8,"column_end":11,"is_primary":true,"text":[{"text":" if (c){ --> $DIR/unused_parens_remove_json_suggestion.rs:32:8 | LL | if (c){ | ^^^ help: remove these parentheses -"} -{"message":"unnecessary parentheses around `while` condition","code":{"code":"unused_parens","explanation":null},"level":"error","spans":[{"file_name":"$DIR/unused_parens_remove_json_suggestion.rs","byte_start":793,"byte_end":808,"line_start":36,"line_end":36,"column_start":11,"column_end":26,"is_primary":true,"text":[{"text":" while (false && true){","highlight_start":11,"highlight_end":26}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[{"message":"remove these parentheses","code":null,"level":"help","spans":[{"file_name":"$DIR/unused_parens_remove_json_suggestion.rs","byte_start":793,"byte_end":808,"line_start":36,"line_end":36,"column_start":11,"column_end":26,"is_primary":true,"text":[{"text":" while (false && true){","highlight_start":11,"highlight_end":26}],"label":null,"suggested_replacement":"false && true ","suggestion_applicability":"MachineApplicable","expansion":null}],"children":[],"rendered":null}],"rendered":"error: unnecessary parentheses around `while` condition +","tool_metadata":null} +{"message":"unnecessary parentheses around `while` condition","code":{"code":"unused_parens","explanation":null},"level":"error","spans":[{"file_name":"$DIR/unused_parens_remove_json_suggestion.rs","byte_start":793,"byte_end":808,"line_start":36,"line_end":36,"column_start":11,"column_end":26,"is_primary":true,"text":[{"text":" while (false && true){","highlight_start":11,"highlight_end":26}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[{"message":"remove these parentheses","code":null,"level":"help","spans":[{"file_name":"$DIR/unused_parens_remove_json_suggestion.rs","byte_start":793,"byte_end":808,"line_start":36,"line_end":36,"column_start":11,"column_end":26,"is_primary":true,"text":[{"text":" while (false && true){","highlight_start":11,"highlight_end":26}],"label":null,"suggested_replacement":"false && true ","suggestion_applicability":"MachineApplicable","expansion":null}],"children":[],"rendered":null,"tool_metadata":null}],"rendered":"error: unnecessary parentheses around `while` condition --> $DIR/unused_parens_remove_json_suggestion.rs:36:11 | LL | while (false && true){ | ^^^^^^^^^^^^^^^ help: remove these parentheses -"} +","tool_metadata":null} {"message":"unnecessary parentheses around `if` condition","code":{"code":"unused_parens","explanation":null},"level":"error","spans":[{"file_name":"$DIR/unused_parens_remove_json_suggestion.rs","byte_start":821,"byte_end":824,"line_start":37,"line_end":37,"column_start":12,"column_end":15,"is_primary":true,"text":[{"text":" if (c) { --> $DIR/unused_parens_remove_json_suggestion.rs:37:12 | LL | if (c) { | ^^^ help: remove these parentheses -"} +","tool_metadata":null} {"message":"unnecessary parentheses around `while` condition","code":{"code":"unused_parens","explanation":null},"level":"error","spans":[{"file_name":"$DIR/unused_parens_remove_json_suggestion.rs","byte_start":918,"byte_end":933,"line_start":43,"line_end":43,"column_start":10,"column_end":25,"is_primary":true,"text":[{"text":" while(true && false) { --> $DIR/unused_parens_remove_json_suggestion.rs:43:10 | LL | while(true && false) { | ^^^^^^^^^^^^^^^ help: remove these parentheses -"} +","tool_metadata":null} {"message":"unnecessary parentheses around `for` iterator expression","code":{"code":"unused_parens","explanation":null},"level":"error","spans":[{"file_name":"$DIR/unused_parens_remove_json_suggestion.rs","byte_start":987,"byte_end":995,"line_start":44,"line_end":44,"column_start":18,"column_end":26,"is_primary":true,"text":[{"text":" for _ in (0 .. 3){ --> $DIR/unused_parens_remove_json_suggestion.rs:44:18 | LL | for _ in (0 .. 3){ | ^^^^^^^^ help: remove these parentheses -"} +","tool_metadata":null} {"message":"unnecessary parentheses around `for` iterator expression","code":{"code":"unused_parens","explanation":null},"level":"error","spans":[{"file_name":"$DIR/unused_parens_remove_json_suggestion.rs","byte_start":1088,"byte_end":1096,"line_start":49,"line_end":49,"column_start":14,"column_end":22,"is_primary":true,"text":[{"text":" for _ in (0 .. 3) { --> $DIR/unused_parens_remove_json_suggestion.rs:49:14 | LL | for _ in (0 .. 3) { | ^^^^^^^^ help: remove these parentheses -"} +","tool_metadata":null} {"message":"unnecessary parentheses around `while` condition","code":{"code":"unused_parens","explanation":null},"level":"error","spans":[{"file_name":"$DIR/unused_parens_remove_json_suggestion.rs","byte_start":1147,"byte_end":1162,"line_start":50,"line_end":50,"column_start":15,"column_end":30,"is_primary":true,"text":[{"text":" while (true && false) { --> $DIR/unused_parens_remove_json_suggestion.rs:50:15 | LL | while (true && false) { | ^^^^^^^^^^^^^^^ help: remove these parentheses -"} +","tool_metadata":null} {"message":"aborting due to 9 previous errors","code":null,"level":"error","spans":[],"children":[],"rendered":"error: aborting due to 9 previous errors -"} +","tool_metadata":null} diff --git a/src/test/ui/lint/use_suggestion_json.stderr b/src/test/ui/lint/use_suggestion_json.stderr index 21342e2ef37..6e225a91439 100644 --- a/src/test/ui/lint/use_suggestion_json.stderr +++ b/src/test/ui/lint/use_suggestion_json.stderr @@ -376,7 +376,8 @@ mod foo { } ], "children": [], - "rendered": null + "rendered": null, + "tool_metadata": null } ], "rendered": "\u001b[0m\u001b[1m\u001b[38;5;9merror[E0412]\u001b[0m\u001b[0m\u001b[1m: cannot find type `Iter` in this scope\u001b[0m @@ -397,7 +398,8 @@ mod foo { \u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m \u001b[0m and 8 other candidates\u001b[0m -" +", + "tool_metadata": null } { "message": "aborting due to previous error", @@ -407,7 +409,8 @@ mod foo { "children": [], "rendered": "\u001b[0m\u001b[1m\u001b[38;5;9merror\u001b[0m\u001b[0m\u001b[1m: aborting due to previous error\u001b[0m -" +", + "tool_metadata": null } { "message": "For more information about this error, try `rustc --explain E0412`.", @@ -416,5 +419,6 @@ mod foo { "spans": [], "children": [], "rendered": "\u001b[0m\u001b[1mFor more information about this error, try `rustc --explain E0412`.\u001b[0m -" +", + "tool_metadata": null } diff --git a/src/test/ui/terminal-width/flag-json.stderr b/src/test/ui/terminal-width/flag-json.stderr index 93c246cb3f5..76cb5bfb3b6 100644 --- a/src/test/ui/terminal-width/flag-json.stderr +++ b/src/test/ui/terminal-width/flag-json.stderr @@ -32,9 +32,9 @@ LL | ..._: () = 42; | | | expected due to this -"} +","tool_metadata":null} {"message":"aborting due to previous error","code":null,"level":"error","spans":[],"children":[],"rendered":"error: aborting due to previous error -"} +","tool_metadata":null} {"message":"For more information about this error, try `rustc --explain E0308`.","code":null,"level":"failure-note","spans":[],"children":[],"rendered":"For more information about this error, try `rustc --explain E0308`. -"} +","tool_metadata":null} diff --git a/src/test/ui/unused-crate-deps/extern-loc-bad-loctype.rs b/src/test/ui/unused-crate-deps/extern-loc-bad-loctype.rs new file mode 100644 index 00000000000..3e1527e2c2e --- /dev/null +++ b/src/test/ui/unused-crate-deps/extern-loc-bad-loctype.rs @@ -0,0 +1,8 @@ +// --extern-location with bad location type + +// aux-crate:bar=bar.rs +// compile-flags:--extern-location bar=badloc:in-the-test-file + +#![warn(unused_crate_dependencies)] + +fn main() {} diff --git a/src/test/ui/unused-crate-deps/extern-loc-bad-loctype.stderr b/src/test/ui/unused-crate-deps/extern-loc-bad-loctype.stderr new file mode 100644 index 00000000000..12378f12557 --- /dev/null +++ b/src/test/ui/unused-crate-deps/extern-loc-bad-loctype.stderr @@ -0,0 +1,2 @@ +error: unknown location type `badloc`: use `raw` or `json` + diff --git a/src/test/ui/unused-crate-deps/extern-loc-defl-json.rs b/src/test/ui/unused-crate-deps/extern-loc-defl-json.rs new file mode 100644 index 00000000000..a023f535b81 --- /dev/null +++ b/src/test/ui/unused-crate-deps/extern-loc-defl-json.rs @@ -0,0 +1,10 @@ +// Default extern location from name and path if one isn't specified + +// check-pass +// aux-crate:bar=bar.rs +// compile-flags:--error-format json + +#![warn(unused_crate_dependencies)] +//~^ WARNING external crate `bar` unused in + +fn main() {} diff --git a/src/test/ui/unused-crate-deps/extern-loc-defl-json.stderr b/src/test/ui/unused-crate-deps/extern-loc-defl-json.stderr new file mode 100644 index 00000000000..6f51c5a1e73 --- /dev/null +++ b/src/test/ui/unused-crate-deps/extern-loc-defl-json.stderr @@ -0,0 +1,17 @@ +{"message":"external crate `bar` unused in `extern_loc_defl_json`: remove the dependency or add `use bar as _;`","code":{"code":"unused_crate_dependencies","explanation":null},"level":"warning","spans":[{"file_name":"$DIR/extern-loc-defl-json.rs","byte_start":146,"byte_end":146,"line_start":7,"line_end":7,"column_start":1,"column_end":1,"is_primary":true,"text":[{"text":"#![warn(unused_crate_dependencies)]","highlight_start":1,"highlight_end":1}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[{"message":"the lint level is defined here","code":null,"level":"note","spans":[{"file_name":"$DIR/extern-loc-defl-json.rs","byte_start":154,"byte_end":179,"line_start":7,"line_end":7,"column_start":9,"column_end":34,"is_primary":true,"text":[{"text":"#![warn(unused_crate_dependencies)]","highlight_start":9,"highlight_end":34}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[],"rendered":null,"tool_metadata":null},{"message":"remove unnecessary dependency `bar`","code":null,"level":"help","spans":[],"children":[],"rendered":null,"tool_metadata":null},{"message":"json extern location","code":null,"level":"help","spans":[],"children":[],"rendered":null,"tool_metadata":{"name":"bar"}}],"rendered":"warning: external crate `bar` unused in `extern_loc_defl_json`: remove the dependency or add `use bar as _;` + --> $DIR/extern-loc-defl-json.rs:7:1 + | +LL | #![warn(unused_crate_dependencies)] + | ^ + | +note: the lint level is defined here + --> $DIR/extern-loc-defl-json.rs:7:9 + | +LL | #![warn(unused_crate_dependencies)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + = help: remove unnecessary dependency `bar` + +","tool_metadata":null} +{"message":"1 warning emitted","code":null,"level":"warning","spans":[],"children":[],"rendered":"warning: 1 warning emitted + +","tool_metadata":null} diff --git a/src/test/ui/unused-crate-deps/extern-loc-json-bad-json.rs b/src/test/ui/unused-crate-deps/extern-loc-json-bad-json.rs new file mode 100644 index 00000000000..6fdf710a126 --- /dev/null +++ b/src/test/ui/unused-crate-deps/extern-loc-json-bad-json.rs @@ -0,0 +1,8 @@ +// --extern-location with a raw reference + +// aux-crate:bar=bar.rs +// compile-flags:--extern-location bar=json:[{"malformed + +#![warn(unused_crate_dependencies)] + +fn main() {} diff --git a/src/test/ui/unused-crate-deps/extern-loc-json-bad-json.stderr b/src/test/ui/unused-crate-deps/extern-loc-json-bad-json.stderr new file mode 100644 index 00000000000..20d606372e0 --- /dev/null +++ b/src/test/ui/unused-crate-deps/extern-loc-json-bad-json.stderr @@ -0,0 +1,2 @@ +error: `--extern-location`: malformed json location `[{"malformed` + diff --git a/src/test/ui/unused-crate-deps/extern-loc-json-json.rs b/src/test/ui/unused-crate-deps/extern-loc-json-json.rs new file mode 100644 index 00000000000..02a9869151f --- /dev/null +++ b/src/test/ui/unused-crate-deps/extern-loc-json-json.rs @@ -0,0 +1,10 @@ +// --extern-location with a raw reference + +// check-pass +// aux-crate:bar=bar.rs +// compile-flags:--extern-location bar=json:{"key":123,"value":{}} --error-format json + +#![warn(unused_crate_dependencies)] +//~^ WARNING external crate `bar` unused in + +fn main() {} diff --git a/src/test/ui/unused-crate-deps/extern-loc-json-json.stderr b/src/test/ui/unused-crate-deps/extern-loc-json-json.stderr new file mode 100644 index 00000000000..e0d14aad5df --- /dev/null +++ b/src/test/ui/unused-crate-deps/extern-loc-json-json.stderr @@ -0,0 +1,17 @@ +{"message":"external crate `bar` unused in `extern_loc_json_json`: remove the dependency or add `use bar as _;`","code":{"code":"unused_crate_dependencies","explanation":null},"level":"warning","spans":[{"file_name":"$DIR/extern-loc-json-json.rs","byte_start":169,"byte_end":169,"line_start":7,"line_end":7,"column_start":1,"column_end":1,"is_primary":true,"text":[{"text":"#![warn(unused_crate_dependencies)]","highlight_start":1,"highlight_end":1}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[{"message":"the lint level is defined here","code":null,"level":"note","spans":[{"file_name":"$DIR/extern-loc-json-json.rs","byte_start":177,"byte_end":202,"line_start":7,"line_end":7,"column_start":9,"column_end":34,"is_primary":true,"text":[{"text":"#![warn(unused_crate_dependencies)]","highlight_start":9,"highlight_end":34}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[],"rendered":null,"tool_metadata":null},{"message":"remove unnecessary dependency `bar`","code":null,"level":"help","spans":[],"children":[],"rendered":null,"tool_metadata":null},{"message":"json extern location","code":null,"level":"help","spans":[],"children":[],"rendered":null,"tool_metadata":{"key":123,"value":{}}}],"rendered":"warning: external crate `bar` unused in `extern_loc_json_json`: remove the dependency or add `use bar as _;` + --> $DIR/extern-loc-json-json.rs:7:1 + | +LL | #![warn(unused_crate_dependencies)] + | ^ + | +note: the lint level is defined here + --> $DIR/extern-loc-json-json.rs:7:9 + | +LL | #![warn(unused_crate_dependencies)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + = help: remove unnecessary dependency `bar` + +","tool_metadata":null} +{"message":"1 warning emitted","code":null,"level":"warning","spans":[],"children":[],"rendered":"warning: 1 warning emitted + +","tool_metadata":null} diff --git a/src/test/ui/unused-crate-deps/extern-loc-json.rs b/src/test/ui/unused-crate-deps/extern-loc-json.rs new file mode 100644 index 00000000000..212610d532e --- /dev/null +++ b/src/test/ui/unused-crate-deps/extern-loc-json.rs @@ -0,0 +1,10 @@ +// --extern-location with a raw reference + +// check-pass +// aux-crate:bar=bar.rs +// compile-flags:--extern-location bar=json:{"key":123,"value":{}} + +#![warn(unused_crate_dependencies)] +//~^ WARNING external crate `bar` unused in + +fn main() {} diff --git a/src/test/ui/unused-crate-deps/extern-loc-json.stderr b/src/test/ui/unused-crate-deps/extern-loc-json.stderr new file mode 100644 index 00000000000..a6bbc0da1c6 --- /dev/null +++ b/src/test/ui/unused-crate-deps/extern-loc-json.stderr @@ -0,0 +1,15 @@ +warning: external crate `bar` unused in `extern_loc_json`: remove the dependency or add `use bar as _;` + --> $DIR/extern-loc-json.rs:7:1 + | +LL | #![warn(unused_crate_dependencies)] + | ^ + | +note: the lint level is defined here + --> $DIR/extern-loc-json.rs:7:9 + | +LL | #![warn(unused_crate_dependencies)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + = help: remove unnecessary dependency `bar` + +warning: 1 warning emitted + diff --git a/src/test/ui/unused-crate-deps/extern-loc-missing-loc.rs b/src/test/ui/unused-crate-deps/extern-loc-missing-loc.rs new file mode 100644 index 00000000000..9339a004d3b --- /dev/null +++ b/src/test/ui/unused-crate-deps/extern-loc-missing-loc.rs @@ -0,0 +1,8 @@ +// --extern-location with a raw reference + +// aux-crate:bar=bar.rs +// compile-flags:--extern-location bar + +#![warn(unused_crate_dependencies)] + +fn main() {} diff --git a/src/test/ui/unused-crate-deps/extern-loc-missing-loc.stderr b/src/test/ui/unused-crate-deps/extern-loc-missing-loc.stderr new file mode 100644 index 00000000000..4584fbfb67f --- /dev/null +++ b/src/test/ui/unused-crate-deps/extern-loc-missing-loc.stderr @@ -0,0 +1,2 @@ +error: `--extern-location`: specify location for extern crate `bar` + diff --git a/src/test/ui/unused-crate-deps/extern-loc-missing-loctype.rs b/src/test/ui/unused-crate-deps/extern-loc-missing-loctype.rs new file mode 100644 index 00000000000..4768365a653 --- /dev/null +++ b/src/test/ui/unused-crate-deps/extern-loc-missing-loctype.rs @@ -0,0 +1,8 @@ +// --extern-location with no type + +// aux-crate:bar=bar.rs +// compile-flags:--extern-location bar=missing-loc-type + +#![warn(unused_crate_dependencies)] + +fn main() {} diff --git a/src/test/ui/unused-crate-deps/extern-loc-missing-loctype.stderr b/src/test/ui/unused-crate-deps/extern-loc-missing-loctype.stderr new file mode 100644 index 00000000000..d0c36ebeb14 --- /dev/null +++ b/src/test/ui/unused-crate-deps/extern-loc-missing-loctype.stderr @@ -0,0 +1,2 @@ +error: unknown location type `missing-loc-type`: use `raw` or `json` + diff --git a/src/test/ui/unused-crate-deps/extern-loc-raw-json.rs b/src/test/ui/unused-crate-deps/extern-loc-raw-json.rs new file mode 100644 index 00000000000..207615ccc87 --- /dev/null +++ b/src/test/ui/unused-crate-deps/extern-loc-raw-json.rs @@ -0,0 +1,10 @@ +// --extern-location with a raw reference + +// check-pass +// aux-crate:bar=bar.rs +// compile-flags:--extern-location bar=raw:in-the-test-file --error-format json + +#![warn(unused_crate_dependencies)] +//~^ WARNING external crate `bar` unused in + +fn main() {} diff --git a/src/test/ui/unused-crate-deps/extern-loc-raw-json.stderr b/src/test/ui/unused-crate-deps/extern-loc-raw-json.stderr new file mode 100644 index 00000000000..6edf6335a9f --- /dev/null +++ b/src/test/ui/unused-crate-deps/extern-loc-raw-json.stderr @@ -0,0 +1,17 @@ +{"message":"external crate `bar` unused in `extern_loc_raw_json`: remove the dependency or add `use bar as _;`","code":{"code":"unused_crate_dependencies","explanation":null},"level":"warning","spans":[{"file_name":"$DIR/extern-loc-raw-json.rs","byte_start":162,"byte_end":162,"line_start":7,"line_end":7,"column_start":1,"column_end":1,"is_primary":true,"text":[{"text":"#![warn(unused_crate_dependencies)]","highlight_start":1,"highlight_end":1}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[{"message":"the lint level is defined here","code":null,"level":"note","spans":[{"file_name":"$DIR/extern-loc-raw-json.rs","byte_start":170,"byte_end":195,"line_start":7,"line_end":7,"column_start":9,"column_end":34,"is_primary":true,"text":[{"text":"#![warn(unused_crate_dependencies)]","highlight_start":9,"highlight_end":34}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[],"rendered":null,"tool_metadata":null},{"message":"remove unnecessary dependency `bar` at `in-the-test-file`","code":null,"level":"help","spans":[],"children":[],"rendered":null,"tool_metadata":null},{"message":"raw extern location","code":null,"level":"help","spans":[{"file_name":"$DIR/extern-loc-raw-json.rs","byte_start":0,"byte_end":0,"line_start":1,"line_end":1,"column_start":1,"column_end":1,"is_primary":true,"text":[],"label":null,"suggested_replacement":"in-the-test-file","suggestion_applicability":"Unspecified","expansion":null}],"children":[],"rendered":null,"tool_metadata":null},{"message":"json extern location","code":null,"level":"help","spans":[],"children":[],"rendered":null,"tool_metadata":"in-the-test-file"}],"rendered":"warning: external crate `bar` unused in `extern_loc_raw_json`: remove the dependency or add `use bar as _;` + --> $DIR/extern-loc-raw-json.rs:7:1 + | +LL | #![warn(unused_crate_dependencies)] + | ^ + | +note: the lint level is defined here + --> $DIR/extern-loc-raw-json.rs:7:9 + | +LL | #![warn(unused_crate_dependencies)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + = help: remove unnecessary dependency `bar` at `in-the-test-file` + +","tool_metadata":null} +{"message":"1 warning emitted","code":null,"level":"warning","spans":[],"children":[],"rendered":"warning: 1 warning emitted + +","tool_metadata":null} diff --git a/src/test/ui/unused-crate-deps/extern-loc-raw-missing-loc.rs b/src/test/ui/unused-crate-deps/extern-loc-raw-missing-loc.rs new file mode 100644 index 00000000000..65b64268394 --- /dev/null +++ b/src/test/ui/unused-crate-deps/extern-loc-raw-missing-loc.rs @@ -0,0 +1,8 @@ +// --extern-location with a raw reference + +// aux-crate:bar=bar.rs +// compile-flags:--extern-location bar=raw + +#![warn(unused_crate_dependencies)] + +fn main() {} diff --git a/src/test/ui/unused-crate-deps/extern-loc-raw-missing-loc.stderr b/src/test/ui/unused-crate-deps/extern-loc-raw-missing-loc.stderr new file mode 100644 index 00000000000..4b51266e4f6 --- /dev/null +++ b/src/test/ui/unused-crate-deps/extern-loc-raw-missing-loc.stderr @@ -0,0 +1,2 @@ +error: `--extern-location`: missing `raw` location + diff --git a/src/test/ui/unused-crate-deps/extern-loc-raw.rs b/src/test/ui/unused-crate-deps/extern-loc-raw.rs new file mode 100644 index 00000000000..fc3fed1e10e --- /dev/null +++ b/src/test/ui/unused-crate-deps/extern-loc-raw.rs @@ -0,0 +1,10 @@ +// --extern-location with a raw reference + +// check-pass +// aux-crate:bar=bar.rs +// compile-flags:--extern-location bar=raw:in-the-test-file + +#![warn(unused_crate_dependencies)] +//~^ WARNING external crate `bar` unused in + +fn main() {} diff --git a/src/test/ui/unused-crate-deps/extern-loc-raw.stderr b/src/test/ui/unused-crate-deps/extern-loc-raw.stderr new file mode 100644 index 00000000000..2cdd0055866 --- /dev/null +++ b/src/test/ui/unused-crate-deps/extern-loc-raw.stderr @@ -0,0 +1,15 @@ +warning: external crate `bar` unused in `extern_loc_raw`: remove the dependency or add `use bar as _;` + --> $DIR/extern-loc-raw.rs:7:1 + | +LL | #![warn(unused_crate_dependencies)] + | ^ + | +note: the lint level is defined here + --> $DIR/extern-loc-raw.rs:7:9 + | +LL | #![warn(unused_crate_dependencies)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + = help: remove unnecessary dependency `bar` at `in-the-test-file` + +warning: 1 warning emitted + diff --git a/src/test/ui/unused-crate-deps/libfib.stderr b/src/test/ui/unused-crate-deps/libfib.stderr index 15833126bd6..479f51bff46 100644 --- a/src/test/ui/unused-crate-deps/libfib.stderr +++ b/src/test/ui/unused-crate-deps/libfib.stderr @@ -5,6 +5,7 @@ LL | pub fn fib(n: u32) -> Vec { | ^ | = note: requested on the command line with `-W unused-crate-dependencies` + = help: remove unnecessary dependency `bar` warning: 1 warning emitted diff --git a/src/test/ui/unused-crate-deps/test.mk b/src/test/ui/unused-crate-deps/test.mk new file mode 100644 index 00000000000..0b98b4e44fb --- /dev/null +++ b/src/test/ui/unused-crate-deps/test.mk @@ -0,0 +1,7 @@ +# Everyone uses make for building Rust + +foo: bar.rlib + $(RUSTC) --crate-type bin --extern bar=bar.rlib + +%.rlib: %.rs + $(RUSTC) --crate-type lib $< diff --git a/src/test/ui/unused-crate-deps/unused-aliases.stderr b/src/test/ui/unused-crate-deps/unused-aliases.stderr index c8c6c4507b0..1142d156d0e 100644 --- a/src/test/ui/unused-crate-deps/unused-aliases.stderr +++ b/src/test/ui/unused-crate-deps/unused-aliases.stderr @@ -9,6 +9,7 @@ note: the lint level is defined here | LL | #![warn(unused_crate_dependencies)] | ^^^^^^^^^^^^^^^^^^^^^^^^^ + = help: remove unnecessary dependency `barbar` warning: 1 warning emitted diff --git a/src/test/ui/unused-crate-deps/warn-attr.stderr b/src/test/ui/unused-crate-deps/warn-attr.stderr index 0d38315704b..29667d9525c 100644 --- a/src/test/ui/unused-crate-deps/warn-attr.stderr +++ b/src/test/ui/unused-crate-deps/warn-attr.stderr @@ -9,6 +9,7 @@ note: the lint level is defined here | LL | #![warn(unused_crate_dependencies)] | ^^^^^^^^^^^^^^^^^^^^^^^^^ + = help: remove unnecessary dependency `bar` warning: 1 warning emitted diff --git a/src/test/ui/unused-crate-deps/warn-cmdline-static.stderr b/src/test/ui/unused-crate-deps/warn-cmdline-static.stderr index 65956461d64..2c0c9215129 100644 --- a/src/test/ui/unused-crate-deps/warn-cmdline-static.stderr +++ b/src/test/ui/unused-crate-deps/warn-cmdline-static.stderr @@ -5,6 +5,7 @@ LL | fn main() {} | ^ | = note: requested on the command line with `-W unused-crate-dependencies` + = help: remove unnecessary dependency `bar` warning: 1 warning emitted diff --git a/src/test/ui/unused-crate-deps/warn-cmdline.stderr b/src/test/ui/unused-crate-deps/warn-cmdline.stderr index ea675ba9a1e..2cd49218f5a 100644 --- a/src/test/ui/unused-crate-deps/warn-cmdline.stderr +++ b/src/test/ui/unused-crate-deps/warn-cmdline.stderr @@ -5,6 +5,7 @@ LL | fn main() {} | ^ | = note: requested on the command line with `-W unused-crate-dependencies` + = help: remove unnecessary dependency `bar` warning: 1 warning emitted