diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2025-09-25 11:33:58 +0200 |
|---|---|---|
| committer | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2025-09-27 11:29:50 +0200 |
| commit | 9362ab549f87e535eeba12c5d42f584ff55ff886 (patch) | |
| tree | 83deb2aadf960653d22d990e2afe80126135ccc0 /compiler/rustc_passes/src | |
| parent | 653e1036ed5a343a7be7b2a73096c138efc51523 (diff) | |
| download | rust-9362ab549f87e535eeba12c5d42f584ff55ff886.tar.gz rust-9362ab549f87e535eeba12c5d42f584ff55ff886.zip | |
Improve code and fix typo
Diffstat (limited to 'compiler/rustc_passes/src')
| -rw-r--r-- | compiler/rustc_passes/src/check_attr.rs | 41 | ||||
| -rw-r--r-- | compiler/rustc_passes/src/errors.rs | 8 |
2 files changed, 17 insertions, 32 deletions
diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index 88b49c781e7..4ea237cfa03 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -1160,7 +1160,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { } } - /// Check that the `#![doc(auto_cfg(..))]` attribute has expected input. + /// Check that the `#![doc(auto_cfg)]` attribute has the expected input. fn check_doc_auto_cfg(&self, meta: &MetaItem, hir_id: HirId) { match &meta.kind { MetaItemKind::Word => {} @@ -1176,7 +1176,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { } MetaItemKind::List(list) => { for item in list { - let Some(attr_name) = item.name() else { + let Some(attr_name @ (sym::hide | sym::show)) = item.name() else { self.tcx.emit_node_span_lint( INVALID_DOC_ATTRIBUTES, hir_id, @@ -1185,36 +1185,21 @@ impl<'tcx> CheckAttrVisitor<'tcx> { ); continue; }; - if attr_name != sym::hide && attr_name != sym::show { - self.tcx.emit_node_span_lint( - INVALID_DOC_ATTRIBUTES, - hir_id, - meta.span, - errors::DocAutoCfgExpectsHideOrShow, - ); - } else if let Some(list) = item.meta_item_list() { + if let Some(list) = item.meta_item_list() { for item in list { - if item.meta_item_list().is_some() { - self.tcx.emit_node_span_lint( - INVALID_DOC_ATTRIBUTES, - hir_id, - item.span(), - errors::DocAutoCfgHideShowUnexpectedItem { - attr_name: attr_name.as_str(), - }, - ); - } else if match item { - MetaItemInner::Lit(_) => true, - // We already checked above that it's not a list. - MetaItemInner::MetaItem(meta) => meta.path.segments.len() != 1, - } { + let valid = item.meta_item().is_some_and(|meta| { + meta.path.segments.len() == 1 + && matches!( + &meta.kind, + MetaItemKind::Word | MetaItemKind::NameValue(_) + ) + }); + if !valid { self.tcx.emit_node_span_lint( INVALID_DOC_ATTRIBUTES, hir_id, item.span(), - errors::DocAutoCfgHideShowUnexpectedItem { - attr_name: attr_name.as_str(), - }, + errors::DocAutoCfgHideShowUnexpectedItem { attr_name }, ); } } @@ -1223,7 +1208,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { INVALID_DOC_ATTRIBUTES, hir_id, meta.span, - errors::DocAutoCfgHideShowExpectsList { attr_name: attr_name.as_str() }, + errors::DocAutoCfgHideShowExpectsList { attr_name }, ); } } diff --git a/compiler/rustc_passes/src/errors.rs b/compiler/rustc_passes/src/errors.rs index 1d2428c4f9a..f0726014e0a 100644 --- a/compiler/rustc_passes/src/errors.rs +++ b/compiler/rustc_passes/src/errors.rs @@ -318,14 +318,14 @@ pub(crate) struct DocAutoCfgExpectsHideOrShow; #[derive(LintDiagnostic)] #[diag(passes_doc_auto_cfg_hide_show_expects_list)] -pub(crate) struct DocAutoCfgHideShowExpectsList<'a> { - pub attr_name: &'a str, +pub(crate) struct DocAutoCfgHideShowExpectsList { + pub attr_name: Symbol, } #[derive(LintDiagnostic)] #[diag(passes_doc_auto_cfg_hide_show_unexpected_item)] -pub(crate) struct DocAutoCfgHideShowUnexpectedItem<'a> { - pub attr_name: &'a str, +pub(crate) struct DocAutoCfgHideShowUnexpectedItem { + pub attr_name: Symbol, } #[derive(LintDiagnostic)] |
