Skip to content
Open
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
27 changes: 8 additions & 19 deletions compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ impl AttributeParser for NakedParser {
if other_attr.word_is(sym::target_feature) {
if !cx.features().naked_functions_target_feature() {
feature_err(
&cx.sess(),
cx.sess(),
sym::naked_functions_target_feature,
other_attr.span(),
"`#[target_feature(/* ... */)]` is currently unstable on `#[naked]` functions",
Expand Down Expand Up @@ -396,7 +396,7 @@ impl AttributeParser for UsedParser {
Some(sym::compiler) => {
if !cx.features().used_with_arg() {
feature_err(
&cx.sess(),
cx.sess(),
sym::used_with_arg,
cx.attr_span,
"`#[used(compiler)]` is currently unstable",
Expand All @@ -408,7 +408,7 @@ impl AttributeParser for UsedParser {
Some(sym::linker) => {
if !cx.features().used_with_arg() {
feature_err(
&cx.sess(),
cx.sess(),
sym::used_with_arg,
cx.attr_span,
"`#[used(linker)]` is currently unstable",
Expand Down Expand Up @@ -503,7 +503,7 @@ fn parse_tf_attribute(
let Some(value_str) = cx.expect_string_literal(value) else {
return features;
};
for feature in value_str.as_str().split(",") {
for feature in value_str.as_str().split(',') {
features.push((Symbol::intern(feature), item.span()));
}
}
Expand Down Expand Up @@ -602,7 +602,7 @@ impl SingleAttributeParser for InstrumentFnParser {
const STABILITY: AttributeStability = unstable!(instrument_fn);

fn convert(cx: &mut AcceptContext<'_, '_>, args: &ArgParser) -> Option<AttributeKind> {
let instrument = match args {
match args {
ArgParser::NameValue(nv) => match nv.value_as_str() {
Some(sym::on) => Some(AttributeKind::InstrumentFn(InstrumentFnAttr::On)),
Some(sym::off) => Some(AttributeKind::InstrumentFn(InstrumentFnAttr::Off)),
Expand All @@ -621,8 +621,7 @@ impl SingleAttributeParser for InstrumentFnParser {
cx.adcx().expected_specific_argument_strings(span, &[sym::on, sym::off]);
None
}
};
instrument
}
}
}

Expand Down Expand Up @@ -673,14 +672,7 @@ impl SingleAttributeParser for SanitizeParser {
let is_on = match value.value_as_str() {
Some(sym::on) => true,
Some(sym::off) => false,
Some(_) => {
cx.adcx().expected_specific_argument_strings(
value.value_span,
&[sym::on, sym::off],
);
return;
}
None => {
_ => {
cx.adcx().expected_specific_argument_strings(
value.value_span,
&[sym::on, sym::off],
Expand Down Expand Up @@ -737,7 +729,6 @@ impl SingleAttributeParser for SanitizeParser {
sym::realtime,
],
);
continue;
}
}
}
Expand Down Expand Up @@ -809,9 +800,7 @@ impl SingleAttributeParser for PatchableFunctionEntryParser {
}

for item in meta_item_list.mixed() {
let Some((ident, value)) = cx.expect_name_value(item, item.span(), None) else {
return None;
};
let (ident, value) = cx.expect_name_value(item, item.span(), None)?;

let attrib_to_write = match ident.name {
sym::prefix_nops => {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_attr_parsing/src/attributes/deprecation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ fn get(
if let Some(value_str) = v.value_as_ident() {
Some(value_str)
} else {
cx.adcx().expected_string_literal(v.value_span, Some(&v.value_as_lit()));
cx.adcx().expected_string_literal(v.value_span, Some(v.value_as_lit()));
None
}
}
Expand Down
39 changes: 19 additions & 20 deletions compiler/rustc_attr_parsing/src/attributes/diagnostic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub(crate) enum Mode {
}

impl Mode {
fn as_str(&self) -> &'static str {
fn as_str(self) -> &'static str {
match self {
Self::RustcOnUnimplemented => "rustc_on_unimplemented",
Self::DiagnosticOnUnimplemented => "diagnostic::on_unimplemented",
Expand All @@ -61,7 +61,7 @@ impl Mode {
}
}

fn expected_options(&self) -> &'static str {
fn expected_options(self) -> &'static str {
const DEFAULT: &str =
"at least one of the `message`, `note` and `label` options are expected";
const DIAGNOSTIC_ON_TYPE_ERROR_EXPECTED_OPTIONS: &str =
Expand All @@ -70,33 +70,33 @@ impl Mode {
Self::RustcOnUnimplemented => {
"see <https://rustc-dev-guide.rust-lang.org/diagnostics.html#rustc_on_unimplemented>"
}
Self::DiagnosticOnUnimplemented => DEFAULT,
Self::DiagnosticOnConst => DEFAULT,
Self::DiagnosticOnMove => DEFAULT,
Self::DiagnosticOnUnknown => DEFAULT,
Self::DiagnosticOnUnmatchedArgs => DEFAULT,
Self::DiagnosticOnUnimplemented
| Self::DiagnosticOnConst
| Self::DiagnosticOnMove
| Self::DiagnosticOnUnknown
| Self::DiagnosticOnUnmatchedArgs => DEFAULT,
Self::DiagnosticOnTypeError => DIAGNOSTIC_ON_TYPE_ERROR_EXPECTED_OPTIONS,
}
}

fn allowed_options(&self) -> &'static str {
fn allowed_options(self) -> &'static str {
const DEFAULT: &str = "only `message`, `note` and `label` are allowed as options";
const DIAGNOSTIC_ON_TYPE_ERROR_ALLOWED_OPTIONS: &str =
"only `note` is allowed as option for `diagnostic::on_type_error`";
match self {
Self::RustcOnUnimplemented => {
"see <https://rustc-dev-guide.rust-lang.org/diagnostics.html#rustc_on_unimplemented>"
}
Self::DiagnosticOnUnimplemented => DEFAULT,
Self::DiagnosticOnConst => DEFAULT,
Self::DiagnosticOnMove => DEFAULT,
Self::DiagnosticOnUnknown => DEFAULT,
Self::DiagnosticOnUnmatchedArgs => DEFAULT,
Self::DiagnosticOnUnimplemented
| Self::DiagnosticOnConst
| Self::DiagnosticOnMove
| Self::DiagnosticOnUnknown
| Self::DiagnosticOnUnmatchedArgs => DEFAULT,
Self::DiagnosticOnTypeError => DIAGNOSTIC_ON_TYPE_ERROR_ALLOWED_OPTIONS,
}
}

fn allowed_format_arguments(&self) -> &'static str {
fn allowed_format_arguments(self) -> &'static str {
match self {
Self::RustcOnUnimplemented => {
"see <https://rustc-dev-guide.rust-lang.org/diagnostics.html#rustc_on_unimplemented> for allowed format arguments"
Expand Down Expand Up @@ -356,12 +356,11 @@ fn parse_directive_items<'p>(
if is_root {
let items = or_malformed!(item.args().as_list()?);
let mut iter = items.mixed();
let filter: &MetaItemOrLitParser = match iter.next() {
Some(c) => c,
None => {
cx.emit_err(InvalidOnClause::Empty { span });
continue;
}
let filter = if let Some(c) = iter.next() {
c
} else {
cx.emit_err(InvalidOnClause::Empty { span });
continue;
};

let filter = parse_filter(filter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl AttributeParser for OpaqueParser {
AllowedTargets::AllowListWarnRest(&[Allow(Target::MacroDef)]);

fn finalize(self, _cx: &FinalizeContext<'_, '_>) -> Option<AttributeKind> {
if let Some(_) = self.attr_span { Some(AttributeKind::Opaque) } else { None }
if self.attr_span.is_some() { Some(AttributeKind::Opaque) } else { None }
}
}

Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_attr_parsing/src/attributes/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ impl SingleAttributeParser for InlineParser {
}
_ => {
cx.adcx().expected_specific_argument(l.span(), &[sym::always, sym::never]);
return None;
None
}
}
}
ArgParser::NameValue(_) => {
cx.adcx().warn_ill_formed_attribute_input(ILL_FORMED_ATTRIBUTE_INPUT);
return None;
None
}
}
}
Expand Down
25 changes: 14 additions & 11 deletions compiler/rustc_attr_parsing/src/attributes/link_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,13 @@ impl CombineAttributeParser for LinkParser {
let mut verbatim = None;
if let Some((modifiers, span)) = modifiers {
for modifier in modifiers.as_str().split(',') {
let (modifier, value): (Symbol, bool) = match modifier.strip_prefix(&['+', '-']) {
Some(m) => (Symbol::intern(m), modifier.starts_with('+')),
None => {
let (modifier, value): (Symbol, bool) =
if let Some(m) = modifier.strip_prefix(['+', '-']) {
(Symbol::intern(m), modifier.starts_with('+'))
} else {
cx.emit_err(InvalidLinkModifier { span });
continue;
}
};
};

macro report_unstable_modifier($feature: ident) {
if !features.$feature() {
Expand Down Expand Up @@ -196,9 +196,14 @@ impl CombineAttributeParser for LinkParser {
cx.emit_err(WholeArchiveNeedsStatic { span });
}

(sym::as_dash_needed, Some(NativeLibKind::Dylib { as_needed }))
| (sym::as_dash_needed, Some(NativeLibKind::Framework { as_needed }))
| (sym::as_dash_needed, Some(NativeLibKind::RawDylib { as_needed })) => {
(
sym::as_dash_needed,
Some(
NativeLibKind::Dylib { as_needed }
| NativeLibKind::Framework { as_needed }
| NativeLibKind::RawDylib { as_needed },
),
) => {
report_unstable_modifier!(native_link_modifiers_as_needed);
assign_modifier(as_needed)
}
Expand Down Expand Up @@ -667,9 +672,7 @@ impl SingleAttributeParser for LinkageParser {
fn convert(cx: &mut AcceptContext<'_, '_>, args: &ArgParser) -> Option<AttributeKind> {
let name_value = cx.expect_name_value(args, cx.attr_span, Some(sym::linkage))?;

let Some(value) = cx.expect_string_literal(name_value) else {
return None;
};
let value = cx.expect_string_literal(name_value)?;

// Use the names from src/llvm/docs/LangRef.rst here. Most types are only
// applicable to variable declarations and may not really make sense for
Expand Down
12 changes: 6 additions & 6 deletions compiler/rustc_attr_parsing/src/attributes/macro_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,12 @@ impl SingleAttributeParser for MacroExportParser {
cx.adcx().warn_ill_formed_attribute_input(INVALID_MACRO_EXPORT_ARGUMENTS);
return None;
};
match l.meta_item_no_args().and_then(|i| i.path().word_sym()) {
Some(sym::local_inner_macros) => true,
_ => {
cx.adcx().warn_ill_formed_attribute_input(INVALID_MACRO_EXPORT_ARGUMENTS);
return None;
}
if l.meta_item_no_args().is_some_and(|m| m.path().word_is(sym::local_inner_macros))
{
true
} else {
cx.adcx().warn_ill_formed_attribute_input(INVALID_MACRO_EXPORT_ARGUMENTS);
return None;
}
}
ArgParser::NameValue(nv) => {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_attr_parsing/src/attributes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ impl OnDuplicate {
this: unused,
other: used,
name: Symbol::intern(
&P::PATH.into_iter().map(|i| i.to_string()).collect::<Vec<_>>().join(".."),
&P::PATH.iter().map(|i| i.to_string()).collect::<Vec<_>>().join(".."),
),
});
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_attr_parsing/src/attributes/repr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl CombineAttributeParser for ReprParser {
cx.adcx().expected_identifier(param.span());
continue;
};
reprs.extend(parse_repr(cx, &item).map(|r| (r, param.span())));
reprs.extend(parse_repr(cx, item).map(|r| (r, param.span())));
}
reprs
}
Expand Down Expand Up @@ -144,7 +144,7 @@ fn parse_repr(cx: &mut AcceptContext<'_, '_>, param: &MetaItemParser) -> Option<
Some(sym::simd) => {
if cx.features.is_some_and(|feats| !feats.repr_simd()) {
feature_err(
&cx.sess(),
cx.sess(),
sym::repr_simd,
param.span(),
"SIMD types are experimental and possibly buggy",
Expand Down
22 changes: 11 additions & 11 deletions compiler/rustc_attr_parsing/src/attributes/stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,10 +309,10 @@ pub(crate) fn parse_stability(
let word = param.path().word();
match word.map(|i| i.name) {
Some(sym::feature) => {
insert_value_into_option_or_error(cx, &param, &mut feature, word.unwrap())?
insert_value_into_option_or_error(cx, param, &mut feature, word.unwrap())?
}
Some(sym::since) => {
insert_value_into_option_or_error(cx, &param, &mut since, word.unwrap())?
insert_value_into_option_or_error(cx, param, &mut since, word.unwrap())?
}
_ => {
cx.adcx().expected_specific_argument(param_span, &[sym::feature, sym::since]);
Expand Down Expand Up @@ -376,13 +376,13 @@ pub(crate) fn parse_unstability(
let word = param.path().word();
match word.map(|i| i.name) {
Some(sym::feature) => {
insert_value_into_option_or_error(cx, &param, &mut feature, word.unwrap())?
insert_value_into_option_or_error(cx, param, &mut feature, word.unwrap())?
}
Some(sym::reason) => {
insert_value_into_option_or_error(cx, &param, &mut reason, word.unwrap())?
insert_value_into_option_or_error(cx, param, &mut reason, word.unwrap())?
}
Some(sym::issue) => {
insert_value_into_option_or_error(cx, &param, &mut issue, word.unwrap())?;
insert_value_into_option_or_error(cx, param, &mut issue, word.unwrap())?;

// These unwraps are safe because `insert_value_into_option_or_error` ensures the meta item
// is a name/value pair string literal.
Expand All @@ -406,10 +406,10 @@ pub(crate) fn parse_unstability(
};
}
Some(sym::implied_by) => {
insert_value_into_option_or_error(cx, &param, &mut implied_by, word.unwrap())?
insert_value_into_option_or_error(cx, param, &mut implied_by, word.unwrap())?
}
Some(sym::old_name) => {
insert_value_into_option_or_error(cx, &param, &mut old_name, word.unwrap())?
insert_value_into_option_or_error(cx, param, &mut old_name, word.unwrap())?
}
_ => {
cx.adcx().expected_specific_argument(
Expand Down Expand Up @@ -493,10 +493,10 @@ impl CombineAttributeParser for UnstableRemovedParser {
return None;
};
match word.name {
sym::feature => insert_value_into_option_or_error(cx, &param, &mut feature, word)?,
sym::since => insert_value_into_option_or_error(cx, &param, &mut since, word)?,
sym::reason => insert_value_into_option_or_error(cx, &param, &mut reason, word)?,
sym::link => insert_value_into_option_or_error(cx, &param, &mut link, word)?,
sym::feature => insert_value_into_option_or_error(cx, param, &mut feature, word)?,
sym::since => insert_value_into_option_or_error(cx, param, &mut since, word)?,
sym::reason => insert_value_into_option_or_error(cx, param, &mut reason, word)?,
sym::link => insert_value_into_option_or_error(cx, param, &mut link, word)?,
_ => {
cx.adcx().expected_specific_argument(
param.span(),
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_attr_parsing/src/attributes/unroll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl SingleAttributeParser for UnrollParser {
ArgParser::NameValue(_) => {
let inner_span = cx.inner_span;
cx.adcx().expected_list_or_no_args(inner_span);
return None;
None
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_attr_parsing/src/attributes/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::session_diagnostics::LimitInvalid;

/// Parse a rustc version number written inside string literal in an attribute,
/// like appears in `since = "1.0.0"`. Suffixes like "-dev" and "-nightly" are
/// not accepted in this position, unlike when parsing CFG_RELEASE.
/// not accepted in this position, unlike when parsing `CFG_RELEASE`.
pub fn parse_version(s: Symbol) -> Option<RustcVersion> {
let mut components = s.as_str().split('-');
let d = components.next()?;
Expand Down Expand Up @@ -70,7 +70,7 @@ impl AcceptContext<'_, '_> {
IntErrorKind::Zero => {
panic!("zero is a valid `limit` so should have returned Ok() when parsing")
}
kind => panic!("unimplemented IntErrorKind variant: {:?}", kind),
kind => panic!("unimplemented IntErrorKind variant: {kind:?}"),
},
};

Expand Down
Loading