Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 0a031c5

Browse files
committedDec 14, 2024
Auto merge of rust-lang#134305 - matthiaskrgr:rollup-bja3lsz, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - rust-lang#133221 (Add external macros specific diagnostics for check-cfg) - rust-lang#133386 (Update linux_musl base to dynamically link the crt by default) - rust-lang#134191 (Make some types and methods related to Polonius + Miri public) - rust-lang#134227 (Update wasi-sdk used to build WASI targets) - rust-lang#134279 ((Re-)return adjustment target if adjust kind is never-to-any) - rust-lang#134295 (Encode coroutine-closures in SMIR) r? `@ghost` `@rustbot` modify labels: rollup
2 parents f1ec5d6 + b0597b4 commit 0a031c5

File tree

55 files changed

+592
-72
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+592
-72
lines changed
 

‎compiler/rustc_lint/messages.ftl

+4
Original file line numberDiff line numberDiff line change
@@ -806,10 +806,14 @@ lint_unexpected_cfg_add_build_rs_println = or consider adding `{$build_rs_printl
806806
lint_unexpected_cfg_add_cargo_feature = consider using a Cargo feature instead
807807
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}
808808
lint_unexpected_cfg_add_cmdline_arg = to expect this configuration use `{$cmdline_arg}`
809+
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`
810+
809811
lint_unexpected_cfg_define_features = consider defining some features in `Cargo.toml`
810812
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
811813
lint_unexpected_cfg_doc_rustc = see <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more information about checking conditional configuration
812814
815+
lint_unexpected_cfg_from_external_macro_origin = using a cfg inside a {$macro_kind} will use the cfgs from the destination crate and not the ones from the defining crate
816+
lint_unexpected_cfg_from_external_macro_refer = try refering to `{$macro_name}` crate for guidance on how handle this unexpected cfg
813817
lint_unexpected_cfg_name = unexpected `cfg` condition name: `{$name}`
814818
lint_unexpected_cfg_name_expected_names = expected names are: {$possibilities}{$and_more ->
815819
[0] {""}

‎compiler/rustc_lint/src/context/diagnostics/check_cfg.rs

+58-10
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
use rustc_hir::def_id::LOCAL_CRATE;
12
use rustc_middle::bug;
23
use rustc_session::Session;
34
use rustc_session::config::ExpectedValues;
45
use rustc_span::edit_distance::find_best_match_for_name;
56
use rustc_span::symbol::Ident;
6-
use rustc_span::{Span, Symbol, sym};
7+
use rustc_span::{ExpnKind, Span, Symbol, sym};
78

89
use crate::lints;
910

@@ -60,6 +61,35 @@ fn cargo_help_sub(
6061
}
6162
}
6263

64+
fn rustc_macro_help(span: Span) -> Option<lints::UnexpectedCfgRustcMacroHelp> {
65+
let oexpn = span.ctxt().outer_expn_data();
66+
if let Some(def_id) = oexpn.macro_def_id
67+
&& let ExpnKind::Macro(macro_kind, macro_name) = oexpn.kind
68+
&& def_id.krate != LOCAL_CRATE
69+
{
70+
Some(lints::UnexpectedCfgRustcMacroHelp { macro_kind: macro_kind.descr(), macro_name })
71+
} else {
72+
None
73+
}
74+
}
75+
76+
fn cargo_macro_help(span: Span) -> Option<lints::UnexpectedCfgCargoMacroHelp> {
77+
let oexpn = span.ctxt().outer_expn_data();
78+
if let Some(def_id) = oexpn.macro_def_id
79+
&& let ExpnKind::Macro(macro_kind, macro_name) = oexpn.kind
80+
&& def_id.krate != LOCAL_CRATE
81+
{
82+
Some(lints::UnexpectedCfgCargoMacroHelp {
83+
macro_kind: macro_kind.descr(),
84+
macro_name,
85+
// FIXME: Get access to a `TyCtxt` from an `EarlyContext`
86+
// crate_name: cx.tcx.crate_name(def_id.krate),
87+
})
88+
} else {
89+
None
90+
}
91+
}
92+
6393
pub(super) fn unexpected_cfg_name(
6494
sess: &Session,
6595
(name, name_span): (Symbol, Span),
@@ -85,6 +115,7 @@ pub(super) fn unexpected_cfg_name(
85115
};
86116

87117
let is_from_cargo = rustc_session::utils::was_invoked_from_cargo();
118+
let is_from_external_macro = rustc_middle::lint::in_external_macro(sess, name_span);
88119
let mut is_feature_cfg = name == sym::feature;
89120

90121
let code_sugg = if is_feature_cfg && is_from_cargo {
@@ -185,12 +216,21 @@ pub(super) fn unexpected_cfg_name(
185216
};
186217

187218
let invocation_help = if is_from_cargo {
188-
let sub = if !is_feature_cfg { Some(cargo_help_sub(sess, &inst)) } else { None };
189-
lints::unexpected_cfg_name::InvocationHelp::Cargo { sub }
219+
let help = if !is_feature_cfg && !is_from_external_macro {
220+
Some(cargo_help_sub(sess, &inst))
221+
} else {
222+
None
223+
};
224+
lints::unexpected_cfg_name::InvocationHelp::Cargo {
225+
help,
226+
macro_help: cargo_macro_help(name_span),
227+
}
190228
} else {
191-
lints::unexpected_cfg_name::InvocationHelp::Rustc(lints::UnexpectedCfgRustcHelp::new(
192-
&inst(EscapeQuotes::No),
193-
))
229+
let help = lints::UnexpectedCfgRustcHelp::new(&inst(EscapeQuotes::No));
230+
lints::unexpected_cfg_name::InvocationHelp::Rustc {
231+
help,
232+
macro_help: rustc_macro_help(name_span),
233+
}
194234
};
195235

196236
lints::UnexpectedCfgName { code_sugg, invocation_help, name }
@@ -216,7 +256,9 @@ pub(super) fn unexpected_cfg_value(
216256
.copied()
217257
.flatten()
218258
.collect();
259+
219260
let is_from_cargo = rustc_session::utils::was_invoked_from_cargo();
261+
let is_from_external_macro = rustc_middle::lint::in_external_macro(sess, name_span);
220262

221263
// Show the full list if all possible values for a given name, but don't do it
222264
// for names as the possibilities could be very long
@@ -284,25 +326,31 @@ pub(super) fn unexpected_cfg_value(
284326
};
285327

286328
let invocation_help = if is_from_cargo {
287-
let help = if name == sym::feature {
329+
let help = if name == sym::feature && !is_from_external_macro {
288330
if let Some((value, _value_span)) = value {
289331
Some(lints::unexpected_cfg_value::CargoHelp::AddFeature { value })
290332
} else {
291333
Some(lints::unexpected_cfg_value::CargoHelp::DefineFeatures)
292334
}
293-
} else if can_suggest_adding_value {
335+
} else if can_suggest_adding_value && !is_from_external_macro {
294336
Some(lints::unexpected_cfg_value::CargoHelp::Other(cargo_help_sub(sess, &inst)))
295337
} else {
296338
None
297339
};
298-
lints::unexpected_cfg_value::InvocationHelp::Cargo(help)
340+
lints::unexpected_cfg_value::InvocationHelp::Cargo {
341+
help,
342+
macro_help: cargo_macro_help(name_span),
343+
}
299344
} else {
300345
let help = if can_suggest_adding_value {
301346
Some(lints::UnexpectedCfgRustcHelp::new(&inst(EscapeQuotes::No)))
302347
} else {
303348
None
304349
};
305-
lints::unexpected_cfg_value::InvocationHelp::Rustc(help)
350+
lints::unexpected_cfg_value::InvocationHelp::Rustc {
351+
help,
352+
macro_help: rustc_macro_help(name_span),
353+
}
306354
};
307355

308356
lints::UnexpectedCfgValue {
There was a problem loading the remainder of the diff.

0 commit comments

Comments
 (0)
Failed to load comments.