about summary refs log tree commit diff
path: root/compiler
diff options
context:
space:
mode:
Diffstat (limited to 'compiler')
-rw-r--r--compiler/rustc_lint/messages.ftl2
-rw-r--r--compiler/rustc_lint/src/early/diagnostics.rs6
-rw-r--r--compiler/rustc_lint/src/early/diagnostics/check_cfg.rs16
-rw-r--r--compiler/rustc_lint/src/lints.rs3
4 files changed, 16 insertions, 11 deletions
diff --git a/compiler/rustc_lint/messages.ftl b/compiler/rustc_lint/messages.ftl
index 01d9ac20fae..48d6d6bbf67 100644
--- a/compiler/rustc_lint/messages.ftl
+++ b/compiler/rustc_lint/messages.ftl
@@ -806,7 +806,7 @@ lint_unexpected_cfg_add_build_rs_println = or consider adding `{$build_rs_printl
 lint_unexpected_cfg_add_cargo_feature = consider using a Cargo feature instead
 lint_unexpected_cfg_add_cargo_toml_lint_cfg = or consider adding in `Cargo.toml` the `check-cfg` lint config for the lint:{$cargo_toml_lint_cfg}
 lint_unexpected_cfg_add_cmdline_arg = to expect this configuration use `{$cmdline_arg}`
-lint_unexpected_cfg_cargo_update = the {$macro_kind} `{$macro_name}` may come from an old version of it's defining crate, try updating your dependencies with `cargo update`
+lint_unexpected_cfg_cargo_update = the {$macro_kind} `{$macro_name}` may come from an old version of the `{$crate_name}` crate, try updating your dependency with `cargo update -p {$crate_name}`
 
 lint_unexpected_cfg_define_features = consider defining some features in `Cargo.toml`
 lint_unexpected_cfg_doc_cargo = see <https://doc.rust-lang.org/nightly/rustc/check-cfg/cargo-specifics.html> for more information about checking conditional configuration
diff --git a/compiler/rustc_lint/src/early/diagnostics.rs b/compiler/rustc_lint/src/early/diagnostics.rs
index 7f136672a47..b0fb1e4af76 100644
--- a/compiler/rustc_lint/src/early/diagnostics.rs
+++ b/compiler/rustc_lint/src/early/diagnostics.rs
@@ -21,7 +21,7 @@ mod check_cfg;
 
 pub(super) fn decorate_lint(
     sess: &Session,
-    _tcx: Option<TyCtxt<'_>>,
+    tcx: Option<TyCtxt<'_>>,
     diagnostic: BuiltinLintDiag,
     diag: &mut Diag<'_, ()>,
 ) {
@@ -205,10 +205,10 @@ pub(super) fn decorate_lint(
             .decorate_lint(diag);
         }
         BuiltinLintDiag::UnexpectedCfgName(name, value) => {
-            check_cfg::unexpected_cfg_name(sess, name, value).decorate_lint(diag);
+            check_cfg::unexpected_cfg_name(sess, tcx, name, value).decorate_lint(diag);
         }
         BuiltinLintDiag::UnexpectedCfgValue(name, value) => {
-            check_cfg::unexpected_cfg_value(sess, name, value).decorate_lint(diag);
+            check_cfg::unexpected_cfg_value(sess, tcx, name, value).decorate_lint(diag);
         }
         BuiltinLintDiag::DeprecatedWhereclauseLocation(left_sp, sugg) => {
             let suggestion = match sugg {
diff --git a/compiler/rustc_lint/src/early/diagnostics/check_cfg.rs b/compiler/rustc_lint/src/early/diagnostics/check_cfg.rs
index 63a722f6067..033c0fa4c88 100644
--- a/compiler/rustc_lint/src/early/diagnostics/check_cfg.rs
+++ b/compiler/rustc_lint/src/early/diagnostics/check_cfg.rs
@@ -1,5 +1,6 @@
 use rustc_hir::def_id::LOCAL_CRATE;
 use rustc_middle::bug;
+use rustc_middle::ty::TyCtxt;
 use rustc_session::Session;
 use rustc_session::config::ExpectedValues;
 use rustc_span::edit_distance::find_best_match_for_name;
@@ -73,17 +74,20 @@ fn rustc_macro_help(span: Span) -> Option<lints::UnexpectedCfgRustcMacroHelp> {
     }
 }
 
-fn cargo_macro_help(span: Span) -> Option<lints::UnexpectedCfgCargoMacroHelp> {
+fn cargo_macro_help(
+    tcx: Option<TyCtxt<'_>>,
+    span: Span,
+) -> Option<lints::UnexpectedCfgCargoMacroHelp> {
     let oexpn = span.ctxt().outer_expn_data();
     if let Some(def_id) = oexpn.macro_def_id
         && let ExpnKind::Macro(macro_kind, macro_name) = oexpn.kind
         && def_id.krate != LOCAL_CRATE
+        && let Some(tcx) = tcx
     {
         Some(lints::UnexpectedCfgCargoMacroHelp {
             macro_kind: macro_kind.descr(),
             macro_name,
-            // FIXME: Get access to a `TyCtxt` from an `EarlyContext`
-            // crate_name: cx.tcx.crate_name(def_id.krate),
+            crate_name: tcx.crate_name(def_id.krate),
         })
     } else {
         None
@@ -92,6 +96,7 @@ fn cargo_macro_help(span: Span) -> Option<lints::UnexpectedCfgCargoMacroHelp> {
 
 pub(super) fn unexpected_cfg_name(
     sess: &Session,
+    tcx: Option<TyCtxt<'_>>,
     (name, name_span): (Symbol, Span),
     value: Option<(Symbol, Span)>,
 ) -> lints::UnexpectedCfgName {
@@ -223,7 +228,7 @@ pub(super) fn unexpected_cfg_name(
         };
         lints::unexpected_cfg_name::InvocationHelp::Cargo {
             help,
-            macro_help: cargo_macro_help(name_span),
+            macro_help: cargo_macro_help(tcx, name_span),
         }
     } else {
         let help = lints::UnexpectedCfgRustcHelp::new(&inst(EscapeQuotes::No));
@@ -238,6 +243,7 @@ pub(super) fn unexpected_cfg_name(
 
 pub(super) fn unexpected_cfg_value(
     sess: &Session,
+    tcx: Option<TyCtxt<'_>>,
     (name, name_span): (Symbol, Span),
     value: Option<(Symbol, Span)>,
 ) -> lints::UnexpectedCfgValue {
@@ -339,7 +345,7 @@ pub(super) fn unexpected_cfg_value(
         };
         lints::unexpected_cfg_value::InvocationHelp::Cargo {
             help,
-            macro_help: cargo_macro_help(name_span),
+            macro_help: cargo_macro_help(tcx, name_span),
         }
     } else {
         let help = if can_suggest_adding_value {
diff --git a/compiler/rustc_lint/src/lints.rs b/compiler/rustc_lint/src/lints.rs
index 5da9f6d2053..4977b3971bd 100644
--- a/compiler/rustc_lint/src/lints.rs
+++ b/compiler/rustc_lint/src/lints.rs
@@ -2187,8 +2187,7 @@ pub(crate) struct UnexpectedCfgRustcMacroHelp {
 pub(crate) struct UnexpectedCfgCargoMacroHelp {
     pub macro_kind: &'static str,
     pub macro_name: Symbol,
-    // FIXME: Figure out a way to get the crate name
-    // crate_name: String,
+    pub crate_name: Symbol,
 }
 
 #[derive(LintDiagnostic)]