Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions compiler/rustc_attr_parsing/src/attributes/cfg_select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,9 @@ fn lint_unreachable(
}
}
}
Some(_) => { /* for now we don't bother solving these */ }
Some(_) => {
// FIXME(https://github.com/rust-lang/rust/pull/149960#issuecomment-3780301699): expand capabilities.
}
},
CfgEntry::Not(inner, _) => match &**inner {
CfgEntry::NameValue { name, value: None, .. } => {
Expand All @@ -247,7 +249,9 @@ fn lint_unreachable(
}
}
}
_ => { /* for now we don't bother solving these */ }
_ => {
// FIXME(https://github.com/rust-lang/rust/pull/149960#issuecomment-3780301699): expand capabilities.
}
},
CfgEntry::All(_, _) | CfgEntry::Any(_, _) => {
/* for now we don't bother solving these */
Expand Down
29 changes: 13 additions & 16 deletions compiler/rustc_attr_parsing/src/check_cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ fn to_check_cfg_arg(name: Ident, value: Option<Symbol>, quotes: EscapeQuotes) ->
if let Some(value) = value {
let value = str::escape_debug(value.as_str()).to_string();
let values = match quotes {
EscapeQuotes::Yes => format!("\\\"{}\\\"", value.replace("\"", "\\\\\\\\\"")),
EscapeQuotes::Yes => format!("\\\"{}\\\"", value.replace('"', "\\\\\\\\\"")),
EscapeQuotes::No => format!("\"{value}\""),
};
format!("cfg({name}, values({values}))")
Expand Down Expand Up @@ -182,15 +182,15 @@ pub(crate) fn unexpected_cfg_name(
possibilities.sort_by_key(|s| s.as_str());

let get_possibilities_sub = || {
if !possibilities.is_empty() {
if possibilities.is_empty() {
None
} else {
let possibilities =
possibilities.iter().copied().cloned().collect::<Vec<_>>().into();
possibilities.iter().copied().copied().collect::<Vec<_>>().into();
Some(diagnostics::unexpected_cfg_name::ExpectedValues {
best_match,
possibilities,
})
} else {
None
}
};

Expand Down Expand Up @@ -249,15 +249,15 @@ pub(crate) fn unexpected_cfg_name(

let (possibilities, and_more) =
sort_and_truncate_possibilities(sess, possibilities, FilterWellKnownNames::Yes);
let expected_names = if !possibilities.is_empty() {
let expected_names = if possibilities.is_empty() {
None
} else {
let possibilities: Vec<_> =
possibilities.into_iter().map(|s| Ident::new(s, name_span)).collect();
Some(diagnostics::unexpected_cfg_name::ExpectedNames {
possibilities: possibilities.into(),
and_more,
})
} else {
None
};
diagnostics::unexpected_cfg_name::CodeSuggestion::SimilarValues {
with_similar_values: similar_values,
Expand Down Expand Up @@ -351,14 +351,12 @@ pub(crate) fn unexpected_cfg_value(

let suggestion = if let Some((value, value_span)) = value {
// Suggest the most probable if we found one
if let Some(best_match) = find_best_match_for_name(&possibilities, value, None) {
Some(diagnostics::unexpected_cfg_value::ChangeValueSuggestion::SimilarName {
find_best_match_for_name(&possibilities, value, None).map(|best_match| {
diagnostics::unexpected_cfg_value::ChangeValueSuggestion::SimilarName {
span: value_span,
best_match,
})
} else {
None
}
}
})
} else if let &[first_possibility] = &possibilities[..] {
Some(diagnostics::unexpected_cfg_value::ChangeValueSuggestion::SpecifyValue {
span: name_span.shrink_to_hi(),
Expand Down Expand Up @@ -450,8 +448,7 @@ fn possible_well_known_names_for_cfg_value(sess: &Session, value: Symbol) -> Vec
sess.check_config
.expecteds
.get(*name)
.map(|expected_values| expected_values.contains(&Some(value)))
.unwrap_or_default()
.is_some_and(|expected_values| expected_values.contains(&Some(value)))
})
.copied()
.collect::<Vec<_>>();
Expand Down
26 changes: 11 additions & 15 deletions compiler/rustc_attr_parsing/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ pub(super) struct GroupTypeInnerAccept {
}

pub(crate) type AcceptFn =
Box<dyn for<'sess, 'a> Fn(&mut AcceptContext<'_, 'sess>, &ArgParser) + Send + Sync>;
Box<dyn for<'sess> Fn(&mut AcceptContext<'_, 'sess>, &ArgParser) + Send + Sync>;
pub(crate) type FinalizeFn = fn(&mut FinalizeContext<'_, '_>) -> Option<AttributeKind>;

macro_rules! attribute_parsers {
Expand Down Expand Up @@ -463,7 +463,7 @@ impl<'f, 'sess: 'f> AcceptContext<'f, 'sess> {
AttributeDiagnosticContext { ctx: self, custom_suggestions: Vec::new() }
}

/// Asserts that this MetaItem is a list that contains a single element. Emits an error and
/// Asserts that this `MetaItem` is a list that contains a single element. Emits an error and
/// returns `None` if it is not the case.
///
/// Some examples:
Expand Down Expand Up @@ -668,11 +668,7 @@ impl ExpectNameValue for MetaItemParser {
cx.adcx().expected_name_value(self.span(), name);
}

let Some((word, arg)) = word.zip(arg) else {
return None;
};

Some((word, arg))
word.zip(arg)
}
}

Expand Down Expand Up @@ -740,7 +736,7 @@ impl<'f, 'sess> Deref for AcceptContext<'f, 'sess> {
}
}

impl<'f, 'sess> DerefMut for AcceptContext<'f, 'sess> {
impl DerefMut for AcceptContext<'_, '_> {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.shared
}
Expand Down Expand Up @@ -841,7 +837,7 @@ pub enum ShouldEmit {
}

impl ShouldEmit {
pub(crate) fn emit_err(&self, diag: Diag<'_>) -> ErrorGuaranteed {
pub(crate) fn emit_err(self, diag: Diag<'_>) -> ErrorGuaranteed {
match self {
ShouldEmit::EarlyFatal { .. } if diag.level() == Level::DelayedBug => diag.emit(),
ShouldEmit::EarlyFatal { .. } => diag.upgrade_to_fatal().emit(),
Expand All @@ -865,16 +861,16 @@ impl<'a, 'f, 'sess: 'f> AttributeDiagnosticContext<'a, 'f, 'sess> {
span: Span,
reason: AttributeParseErrorReason<'_>,
) -> ErrorGuaranteed {
let suggestions = if !self.custom_suggestions.is_empty() {
AttributeParseErrorSuggestions::CreatedByParser(mem::take(&mut self.custom_suggestions))
} else {
let suggestions = if self.custom_suggestions.is_empty() {
AttributeParseErrorSuggestions::CreatedByTemplate(self.template_suggestions())
} else {
AttributeParseErrorSuggestions::CreatedByParser(mem::take(&mut self.custom_suggestions))
};

self.emit_err(AttributeParseError {
span,
attr_span: self.attr_span,
template: self.template.clone(),
template: *self.template,
path: self.attr_path.clone(),
description: self.parsed_description,
reason,
Expand Down Expand Up @@ -1125,15 +1121,15 @@ impl<'a, 'f, 'sess: 'f> AttributeDiagnosticContext<'a, 'f, 'sess> {
}
}

impl<'a, 'f, 'sess: 'f> Deref for AttributeDiagnosticContext<'a, 'f, 'sess> {
impl<'f, 'sess: 'f> Deref for AttributeDiagnosticContext<'_, 'f, 'sess> {
type Target = AcceptContext<'f, 'sess>;

fn deref(&self) -> &Self::Target {
self.ctx
}
}

impl<'a, 'f, 'sess: 'f> DerefMut for AttributeDiagnosticContext<'a, 'f, 'sess> {
impl<'f, 'sess: 'f> DerefMut for AttributeDiagnosticContext<'_, 'f, 'sess> {
fn deref_mut(&mut self) -> &mut Self::Target {
self.ctx
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_attr_parsing/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl IllFormedAttributeInput {
Self {
num_suggestions: suggestions.len(),
suggestions: DiagArgValue::StrListSepByAnd(
suggestions.into_iter().map(|s| format!("`{s}`").into()).collect(),
suggestions.iter().map(|s| format!("`{s}`").into()).collect(),
),
has_docs: docs.is_some(),
docs: docs.unwrap_or(""),
Expand Down
11 changes: 5 additions & 6 deletions compiler/rustc_attr_parsing/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl<'sess> AttributeParser<'sess> {
/// errors will be emitted as a delayed bugs. in other words, we *expect* attributes parsed
/// with `parse_limited` to be reparsed later during ast lowering where we *do* emit the errors
///
/// Due to this function not taking in RegisteredTools, *do not* use this for parsing any lint attributes
/// Due to this function not taking in `RegisteredTools`, *do not* use this for parsing any lint attributes
pub fn parse_limited(
sess: &'sess Session,
attrs: &[ast::Attribute],
Expand All @@ -86,7 +86,7 @@ impl<'sess> AttributeParser<'sess> {
/// This does the same as `parse_limited`, except it has a `should_emit` parameter which allows it to emit errors.
/// Usually you want `parse_limited`, which emits no errors.
///
/// Due to this function not taking in RegisteredTools, *do not* use this for parsing any lint attributes
/// Due to this function not taking in `RegisteredTools`, *do not* use this for parsing any lint attributes
pub fn parse_limited_should_emit(
sess: &'sess Session,
attrs: &[ast::Attribute],
Expand Down Expand Up @@ -256,7 +256,7 @@ impl<'sess> AttributeParser<'sess> {
}

pub(crate) fn sess(&self) -> &'sess Session {
&self.sess
self.sess
}

pub(crate) fn features(&self) -> &'sess Features {
Expand Down Expand Up @@ -328,7 +328,6 @@ impl<'sess> AttributeParser<'sess> {
}
ast::AttrKind::Synthetic(synthetic) => {
synthetic_attr_state.accept_synthetic_attr(attr_span, lower_span, synthetic);
continue;
}
ast::AttrKind::Normal(n) => {
attr_paths.push(PathParser(&n.item.path));
Expand All @@ -347,7 +346,7 @@ impl<'sess> AttributeParser<'sess> {
);
self.check_attribute_stability(&attr_path, attr_span, accept.stability);
if let [part] = parts.as_slice() {
debug_assert!(BUILTIN_ATTRIBUTE_MAP.contains(&part));
debug_assert!(BUILTIN_ATTRIBUTE_MAP.contains(part));
}

let Some(args) = ArgParser::from_attr_args(
Expand Down Expand Up @@ -417,7 +416,7 @@ impl<'sess> AttributeParser<'sess> {
Self::check_target(&accept.allowed_targets, "", &mut cx);
#[cfg(debug_assertions)]
if !cx.shared.has_lint_been_emitted.load(Ordering::Relaxed) {
cx.shared.cx.check_args_used(&attr, &args)
cx.shared.cx.check_args_used(attr, &args)
}
} else {
let attr = AttrItem {
Expand Down
Loading
Loading