mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 23:04:33 +00:00
Improve diagnostic for unexpected feature config name from Cargo
This commit is contained in:
parent
9f15acec47
commit
1c37997fa7
@ -739,6 +739,8 @@ pub trait LintContext {
|
||||
} else {
|
||||
db.span_suggestion(name_span, "there is a config with a similar name", best_match, Applicability::MaybeIncorrect);
|
||||
}
|
||||
} else if name == sym::feature && std::env::var_os("CARGO").is_some() {
|
||||
db.help("consider defining some features in `Cargo.toml`");
|
||||
} else if !possibilities.is_empty() {
|
||||
let mut possibilities = possibilities.iter()
|
||||
.map(Symbol::as_str)
|
||||
|
14
tests/ui/check-cfg/cargo-feature.rs
Normal file
14
tests/ui/check-cfg/cargo-feature.rs
Normal file
@ -0,0 +1,14 @@
|
||||
// This test checks that when no features are passed by Cargo we
|
||||
// suggest adding some in the Cargo.toml instead of vomitting a
|
||||
// list of all the expected names
|
||||
//
|
||||
// check-pass
|
||||
// rustc-env:CARGO=/usr/bin/cargo
|
||||
// compile-flags: --check-cfg=cfg() -Z unstable-options
|
||||
// error-pattern:Cargo.toml
|
||||
|
||||
#[cfg(feature = "serde")]
|
||||
//~^ WARNING unexpected `cfg` condition name
|
||||
fn ser() {}
|
||||
|
||||
fn main() {}
|
11
tests/ui/check-cfg/cargo-feature.stderr
Normal file
11
tests/ui/check-cfg/cargo-feature.stderr
Normal file
@ -0,0 +1,11 @@
|
||||
warning: unexpected `cfg` condition name: `feature`
|
||||
--> $DIR/cargo-feature.rs:10:7
|
||||
|
|
||||
LL | #[cfg(feature = "serde")]
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: consider defining some features in `Cargo.toml`
|
||||
= note: `#[warn(unexpected_cfgs)]` on by default
|
||||
|
||||
warning: 1 warning emitted
|
||||
|
Loading…
Reference in New Issue
Block a user