Improve handling of raw-idents in check-cfg
This commit is contained in:
parent
46b0f8bafc
commit
89f04c2521
5 changed files with 133 additions and 4 deletions
|
@ -2,6 +2,7 @@ use rustc_middle::bug;
|
|||
use rustc_session::config::ExpectedValues;
|
||||
use rustc_session::Session;
|
||||
use rustc_span::edit_distance::find_best_match_for_name;
|
||||
use rustc_span::symbol::Ident;
|
||||
use rustc_span::{sym, Span, Symbol};
|
||||
|
||||
use crate::lints;
|
||||
|
@ -30,7 +31,7 @@ enum EscapeQuotes {
|
|||
No,
|
||||
}
|
||||
|
||||
fn to_check_cfg_arg(name: Symbol, value: Option<Symbol>, quotes: EscapeQuotes) -> String {
|
||||
fn to_check_cfg_arg(name: Ident, value: Option<Symbol>, quotes: EscapeQuotes) -> String {
|
||||
if let Some(value) = value {
|
||||
let value = str::escape_debug(value.as_str()).to_string();
|
||||
let values = match quotes {
|
||||
|
@ -110,6 +111,7 @@ pub(super) fn unexpected_cfg_name(
|
|||
}
|
||||
};
|
||||
|
||||
let best_match = Ident::new(best_match, name_span);
|
||||
if let Some((value, value_span)) = value {
|
||||
if best_match_values.contains(&Some(value)) {
|
||||
lints::unexpected_cfg_name::CodeSuggestion::SimilarNameAndValue {
|
||||
|
@ -163,6 +165,8 @@ pub(super) fn unexpected_cfg_name(
|
|||
};
|
||||
let expected_names = if !possibilities.is_empty() {
|
||||
let (possibilities, and_more) = sort_and_truncate_possibilities(sess, possibilities);
|
||||
let possibilities: Vec<_> =
|
||||
possibilities.into_iter().map(|s| Ident::new(s, name_span)).collect();
|
||||
Some(lints::unexpected_cfg_name::ExpectedNames {
|
||||
possibilities: possibilities.into(),
|
||||
and_more,
|
||||
|
@ -176,7 +180,9 @@ pub(super) fn unexpected_cfg_name(
|
|||
}
|
||||
};
|
||||
|
||||
let inst = |escape_quotes| to_check_cfg_arg(name, value.map(|(v, _s)| v), escape_quotes);
|
||||
let inst = |escape_quotes| {
|
||||
to_check_cfg_arg(Ident::new(name, name_span), value.map(|(v, _s)| v), escape_quotes)
|
||||
};
|
||||
|
||||
let invocation_help = if is_from_cargo {
|
||||
let sub = if !is_feature_cfg { Some(cargo_help_sub(sess, &inst)) } else { None };
|
||||
|
@ -273,7 +279,9 @@ pub(super) fn unexpected_cfg_value(
|
|||
|| (matches!(sess.psess.unstable_features, rustc_feature::UnstableFeatures::Cheat)
|
||||
&& !sess.opts.unstable_opts.ui_testing);
|
||||
|
||||
let inst = |escape_quotes| to_check_cfg_arg(name, value.map(|(v, _s)| v), escape_quotes);
|
||||
let inst = |escape_quotes| {
|
||||
to_check_cfg_arg(Ident::new(name, name_span), value.map(|(v, _s)| v), escape_quotes)
|
||||
};
|
||||
|
||||
let invocation_help = if is_from_cargo {
|
||||
let help = if name == sym::feature {
|
||||
|
|
|
@ -2180,6 +2180,7 @@ pub(crate) struct UnexpectedCfgName {
|
|||
pub(crate) mod unexpected_cfg_name {
|
||||
use rustc_errors::DiagSymbolList;
|
||||
use rustc_macros::Subdiagnostic;
|
||||
use rustc_span::symbol::Ident;
|
||||
use rustc_span::{Span, Symbol};
|
||||
|
||||
#[derive(Subdiagnostic)]
|
||||
|
@ -2260,7 +2261,7 @@ pub(crate) mod unexpected_cfg_name {
|
|||
#[derive(Subdiagnostic)]
|
||||
#[help_once(lint_unexpected_cfg_name_expected_names)]
|
||||
pub(crate) struct ExpectedNames {
|
||||
pub possibilities: DiagSymbolList,
|
||||
pub possibilities: DiagSymbolList<Ident>,
|
||||
pub and_more: usize,
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue