diff options
| author | Urgau <urgau@numericable.fr> | 2024-11-19 21:23:54 +0100 |
|---|---|---|
| committer | Urgau <urgau@numericable.fr> | 2024-11-19 22:48:36 +0100 |
| commit | 0ab3ae81a59aba3fed45d5894e931d4250c18aa8 (patch) | |
| tree | 1aa035e63ee1e8cfc907e41d9c126aabe4fdf38e | |
| parent | 44c166e9ace21835b2794005573c2b1964e29acc (diff) | |
| download | rust-0ab3ae81a59aba3fed45d5894e931d4250c18aa8.tar.gz rust-0ab3ae81a59aba3fed45d5894e931d4250c18aa8.zip | |
Disable most Cargo check-cfg help in external macros
| -rw-r--r-- | compiler/rustc_lint/src/context/diagnostics/check_cfg.rs | 13 | ||||
| -rw-r--r-- | tests/ui/check-cfg/report-in-external-macros.cargo.stderr | 6 |
2 files changed, 10 insertions, 9 deletions
diff --git a/compiler/rustc_lint/src/context/diagnostics/check_cfg.rs b/compiler/rustc_lint/src/context/diagnostics/check_cfg.rs index 16994846545..4ab30ce32ee 100644 --- a/compiler/rustc_lint/src/context/diagnostics/check_cfg.rs +++ b/compiler/rustc_lint/src/context/diagnostics/check_cfg.rs @@ -85,6 +85,7 @@ pub(super) fn unexpected_cfg_name( }; let is_from_cargo = rustc_session::utils::was_invoked_from_cargo(); + let is_from_external_macro = rustc_middle::lint::in_external_macro(sess, name_span); let mut is_feature_cfg = name == sym::feature; let code_sugg = if is_feature_cfg && is_from_cargo { @@ -185,7 +186,11 @@ pub(super) fn unexpected_cfg_name( }; let invocation_help = if is_from_cargo { - let sub = if !is_feature_cfg { Some(cargo_help_sub(sess, &inst)) } else { None }; + let sub = if !is_feature_cfg && !is_from_external_macro { + Some(cargo_help_sub(sess, &inst)) + } else { + None + }; lints::unexpected_cfg_name::InvocationHelp::Cargo { sub } } else { lints::unexpected_cfg_name::InvocationHelp::Rustc(lints::UnexpectedCfgRustcHelp::new( @@ -216,7 +221,9 @@ pub(super) fn unexpected_cfg_value( .copied() .flatten() .collect(); + let is_from_cargo = rustc_session::utils::was_invoked_from_cargo(); + let is_from_external_macro = rustc_middle::lint::in_external_macro(sess, name_span); // Show the full list if all possible values for a given name, but don't do it // for names as the possibilities could be very long @@ -284,13 +291,13 @@ pub(super) fn unexpected_cfg_value( }; let invocation_help = if is_from_cargo { - let help = if name == sym::feature { + let help = if name == sym::feature && !is_from_external_macro { if let Some((value, _value_span)) = value { Some(lints::unexpected_cfg_value::CargoHelp::AddFeature { value }) } else { Some(lints::unexpected_cfg_value::CargoHelp::DefineFeatures) } - } else if can_suggest_adding_value { + } else if can_suggest_adding_value && !is_from_external_macro { Some(lints::unexpected_cfg_value::CargoHelp::Other(cargo_help_sub(sess, &inst))) } else { None diff --git a/tests/ui/check-cfg/report-in-external-macros.cargo.stderr b/tests/ui/check-cfg/report-in-external-macros.cargo.stderr index 98c7a068347..0858b01e309 100644 --- a/tests/ui/check-cfg/report-in-external-macros.cargo.stderr +++ b/tests/ui/check-cfg/report-in-external-macros.cargo.stderr @@ -5,11 +5,6 @@ LL | cfg_macro::my_lib_macro!(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: expected names are: `clippy`, `debug_assertions`, `doc`, `doctest`, `feature`, `fmt_debug`, `miri`, `overflow_checks`, `panic`, `proc_macro`, `relocation_model`, `rustfmt`, `sanitize`, `sanitizer_cfi_generalize_pointers`, `sanitizer_cfi_normalize_integers`, `target_abi`, `target_arch`, `target_endian`, `target_env`, `target_family`, `target_feature`, `target_has_atomic`, `target_has_atomic_equal_alignment`, `target_has_atomic_load_store`, `target_os`, `target_pointer_width`, `target_thread_local`, `target_vendor`, `test`, `ub_checks`, `unix`, and `windows` - = help: consider using a Cargo feature instead - = help: or consider adding in `Cargo.toml` the `check-cfg` lint config for the lint: - [lints.rust] - unexpected_cfgs = { level = "warn", check-cfg = ['cfg(my_lib_cfg)'] } - = help: or consider adding `println!("cargo::rustc-check-cfg=cfg(my_lib_cfg)");` to the top of the `build.rs` = note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg/cargo-specifics.html> for more information about checking conditional configuration = note: `#[warn(unexpected_cfgs)]` on by default = note: this warning originates in the macro `cfg_macro::my_lib_macro` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -31,7 +26,6 @@ LL | cfg_macro::my_lib_macro_feature!(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: no expected values for `feature` - = help: consider adding `UNEXPECTED_FEATURE` as a feature in `Cargo.toml` = note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg/cargo-specifics.html> for more information about checking conditional configuration = note: this warning originates in the macro `cfg_macro::my_lib_macro_feature` (in Nightly builds, run with -Z macro-backtrace for more info) |
