Auto merge of #118071 - Urgau:check-cfg-cargo-feature, r=petrochenkov

Remove `feature` from the list of well known check-cfg name

This PR removes `feature` from the list of well known check-cfg.

This is done for multiple reasons:
 - Cargo is the source of truth, rustc shouldn't have any knowledge of it
 - It creates a conflict between Cargo and rustc when there are no features defined.
   In this case Cargo won't pass any `--check-cfg` for `feature` since no feature will ever be passed, but rustc by having in it's list adds a implicit `cfg(feature, values(any()))` which is completely wrong. Having any cfg `feature` is unexpected not allow any `feature` value.

While doing this, I took the opportunity to specialise the diagnostic a bit for the case above.

r? `@petrochenkov`
This commit is contained in:
bors 2023-11-22 07:31:13 +00:00
commit 855c6836b7
15 changed files with 80 additions and 19 deletions

View file

@ -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)