diff --git a/compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs b/compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs index 15c4714624a63..28016aec48a50 100644 --- a/compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs +++ b/compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs @@ -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", @@ -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", @@ -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", @@ -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())); } } @@ -602,7 +602,7 @@ impl SingleAttributeParser for InstrumentFnParser { const STABILITY: AttributeStability = unstable!(instrument_fn); fn convert(cx: &mut AcceptContext<'_, '_>, args: &ArgParser) -> Option { - 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)), @@ -621,8 +621,7 @@ impl SingleAttributeParser for InstrumentFnParser { cx.adcx().expected_specific_argument_strings(span, &[sym::on, sym::off]); None } - }; - instrument + } } } @@ -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], @@ -737,7 +729,6 @@ impl SingleAttributeParser for SanitizeParser { sym::realtime, ], ); - continue; } } } @@ -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 => { diff --git a/compiler/rustc_attr_parsing/src/attributes/deprecation.rs b/compiler/rustc_attr_parsing/src/attributes/deprecation.rs index d401aafed7bec..25835c1ed8b04 100644 --- a/compiler/rustc_attr_parsing/src/attributes/deprecation.rs +++ b/compiler/rustc_attr_parsing/src/attributes/deprecation.rs @@ -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 } } diff --git a/compiler/rustc_attr_parsing/src/attributes/diagnostic/mod.rs b/compiler/rustc_attr_parsing/src/attributes/diagnostic/mod.rs index 2486b5e3a65ed..a3a15978d2a37 100644 --- a/compiler/rustc_attr_parsing/src/attributes/diagnostic/mod.rs +++ b/compiler/rustc_attr_parsing/src/attributes/diagnostic/mod.rs @@ -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", @@ -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 = @@ -70,16 +70,16 @@ impl Mode { Self::RustcOnUnimplemented => { "see " } - 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`"; @@ -87,16 +87,16 @@ impl Mode { Self::RustcOnUnimplemented => { "see " } - 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 for allowed format arguments" @@ -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); diff --git a/compiler/rustc_attr_parsing/src/attributes/diagnostic/opaque.rs b/compiler/rustc_attr_parsing/src/attributes/diagnostic/opaque.rs index 0a18b69dda0ed..64c5ed704f8c5 100644 --- a/compiler/rustc_attr_parsing/src/attributes/diagnostic/opaque.rs +++ b/compiler/rustc_attr_parsing/src/attributes/diagnostic/opaque.rs @@ -45,7 +45,7 @@ impl AttributeParser for OpaqueParser { AllowedTargets::AllowListWarnRest(&[Allow(Target::MacroDef)]); fn finalize(self, _cx: &FinalizeContext<'_, '_>) -> Option { - if let Some(_) = self.attr_span { Some(AttributeKind::Opaque) } else { None } + if self.attr_span.is_some() { Some(AttributeKind::Opaque) } else { None } } } diff --git a/compiler/rustc_attr_parsing/src/attributes/inline.rs b/compiler/rustc_attr_parsing/src/attributes/inline.rs index d3b632fae99d9..45d93e215c781 100644 --- a/compiler/rustc_attr_parsing/src/attributes/inline.rs +++ b/compiler/rustc_attr_parsing/src/attributes/inline.rs @@ -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 } } } diff --git a/compiler/rustc_attr_parsing/src/attributes/link_attrs.rs b/compiler/rustc_attr_parsing/src/attributes/link_attrs.rs index 07713590ff2e9..851e6e451f358 100644 --- a/compiler/rustc_attr_parsing/src/attributes/link_attrs.rs +++ b/compiler/rustc_attr_parsing/src/attributes/link_attrs.rs @@ -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() { @@ -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) } @@ -667,9 +672,7 @@ impl SingleAttributeParser for LinkageParser { fn convert(cx: &mut AcceptContext<'_, '_>, args: &ArgParser) -> Option { 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 diff --git a/compiler/rustc_attr_parsing/src/attributes/macro_attrs.rs b/compiler/rustc_attr_parsing/src/attributes/macro_attrs.rs index f49a7e674d560..17123f67cf276 100644 --- a/compiler/rustc_attr_parsing/src/attributes/macro_attrs.rs +++ b/compiler/rustc_attr_parsing/src/attributes/macro_attrs.rs @@ -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) => { diff --git a/compiler/rustc_attr_parsing/src/attributes/mod.rs b/compiler/rustc_attr_parsing/src/attributes/mod.rs index 0adae406df5c6..885b35d353ef7 100644 --- a/compiler/rustc_attr_parsing/src/attributes/mod.rs +++ b/compiler/rustc_attr_parsing/src/attributes/mod.rs @@ -247,7 +247,7 @@ impl OnDuplicate { this: unused, other: used, name: Symbol::intern( - &P::PATH.into_iter().map(|i| i.to_string()).collect::>().join(".."), + &P::PATH.iter().map(|i| i.to_string()).collect::>().join(".."), ), }); } diff --git a/compiler/rustc_attr_parsing/src/attributes/repr.rs b/compiler/rustc_attr_parsing/src/attributes/repr.rs index dfb7ce5e7b2f4..bb0da73df015c 100644 --- a/compiler/rustc_attr_parsing/src/attributes/repr.rs +++ b/compiler/rustc_attr_parsing/src/attributes/repr.rs @@ -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 } @@ -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", diff --git a/compiler/rustc_attr_parsing/src/attributes/stability.rs b/compiler/rustc_attr_parsing/src/attributes/stability.rs index 0cfb68d523f9b..1ff0cb26ac8d9 100644 --- a/compiler/rustc_attr_parsing/src/attributes/stability.rs +++ b/compiler/rustc_attr_parsing/src/attributes/stability.rs @@ -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, ¶m, &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, ¶m, &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]); @@ -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, ¶m, &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, ¶m, &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, ¶m, &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. @@ -406,10 +406,10 @@ pub(crate) fn parse_unstability( }; } Some(sym::implied_by) => { - insert_value_into_option_or_error(cx, ¶m, &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, ¶m, &mut old_name, word.unwrap())? + insert_value_into_option_or_error(cx, param, &mut old_name, word.unwrap())? } _ => { cx.adcx().expected_specific_argument( @@ -493,10 +493,10 @@ impl CombineAttributeParser for UnstableRemovedParser { return None; }; match word.name { - sym::feature => insert_value_into_option_or_error(cx, ¶m, &mut feature, word)?, - sym::since => insert_value_into_option_or_error(cx, ¶m, &mut since, word)?, - sym::reason => insert_value_into_option_or_error(cx, ¶m, &mut reason, word)?, - sym::link => insert_value_into_option_or_error(cx, ¶m, &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(), diff --git a/compiler/rustc_attr_parsing/src/attributes/unroll.rs b/compiler/rustc_attr_parsing/src/attributes/unroll.rs index 50c73ca041cdd..3438fc044ec55 100644 --- a/compiler/rustc_attr_parsing/src/attributes/unroll.rs +++ b/compiler/rustc_attr_parsing/src/attributes/unroll.rs @@ -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 } } } diff --git a/compiler/rustc_attr_parsing/src/attributes/util.rs b/compiler/rustc_attr_parsing/src/attributes/util.rs index 47a8ac4ce51a8..b58489712fa52 100644 --- a/compiler/rustc_attr_parsing/src/attributes/util.rs +++ b/compiler/rustc_attr_parsing/src/attributes/util.rs @@ -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 { let mut components = s.as_str().split('-'); let d = components.next()?; @@ -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:?}"), }, };