Skip to content

Commit cb5fcc8

Browse files
committed
Fix rustdoc and clippy
1 parent a556c9b commit cb5fcc8

22 files changed

+96
-73
lines changed

src/librustdoc/clean/mod.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2714,13 +2714,13 @@ fn add_without_unwanted_attributes<'hir>(
27142714
import_parent: Option<DefId>,
27152715
) {
27162716
for attr in new_attrs {
2717-
if matches!(attr.kind, hir::AttrKind::DocComment(..)) {
2717+
if attr.is_doc_comment() {
27182718
attrs.push((Cow::Borrowed(attr), import_parent));
27192719
continue;
27202720
}
27212721
let mut attr = attr.clone();
2722-
match attr.kind {
2723-
hir::AttrKind::Normal(ref mut normal) => {
2722+
match attr {
2723+
hir::Attribute::Unparsed(ref mut normal) => {
27242724
if let [ident] = &*normal.path.segments {
27252725
let ident = ident.name;
27262726
if ident == sym::doc {
@@ -2732,7 +2732,11 @@ fn add_without_unwanted_attributes<'hir>(
27322732
}
27332733
}
27342734
}
2735-
_ => unreachable!(),
2735+
hir::Attribute::Parsed(..) => {
2736+
if is_inline {
2737+
attrs.push((Cow::Owned(attr), import_parent));
2738+
}
2739+
}
27362740
}
27372741
}
27382742
}

src/librustdoc/clean/types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ impl ExternalCrate {
268268
let attr_value = attr.value_str().expect("syntax should already be validated");
269269
let Some(prim) = PrimitiveType::from_symbol(attr_value) else {
270270
span_bug!(
271-
attr.span,
271+
attr.span(),
272272
"primitive `{attr_value}` is not a member of `PrimitiveType`"
273273
);
274274
};

src/librustdoc/doctest/rust.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ impl HirCollector<'_> {
123123
.iter()
124124
.find(|attr| attr.doc_str().is_some())
125125
.map(|attr| {
126-
attr.span.ctxt().outer_expn().expansion_cause().unwrap_or(attr.span)
126+
attr.span().ctxt().outer_expn().expansion_cause().unwrap_or(attr.span())
127127
})
128128
.unwrap_or(DUMMY_SP)
129129
};

src/tools/clippy/clippy_lints/src/attrs/inline_always.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub(super) fn check(cx: &LateContext<'_>, span: Span, name: Symbol, attrs: &[Att
2020
span_lint(
2121
cx,
2222
INLINE_ALWAYS,
23-
attr.span,
23+
attr.span(),
2424
format!("you have declared `#[inline(always)]` on `{name}`. This is usually a bad idea"),
2525
);
2626
}

src/tools/clippy/clippy_lints/src/attrs/unnecessary_clippy_cfg.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub(super) fn check(
1515
) {
1616
if cfg_attr.has_name(sym::clippy)
1717
&& let Some(ident) = behind_cfg_attr.ident()
18-
&& Level::from_symbol(ident.name, Some(attr.id)).is_some()
18+
&& Level::from_symbol(ident.name, || Some(attr.id)).is_some()
1919
&& let Some(items) = behind_cfg_attr.meta_item_list()
2020
{
2121
let nb_items = items.len();

src/tools/clippy/clippy_lints/src/attrs/utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub(super) fn is_word(nmi: &MetaItemInner, expected: Symbol) -> bool {
1717
}
1818

1919
pub(super) fn is_lint_level(symbol: Symbol, attr_id: AttrId) -> bool {
20-
Level::from_symbol(symbol, Some(attr_id)).is_some()
20+
Level::from_symbol(symbol, || Some(attr_id)).is_some()
2121
}
2222

2323
pub(super) fn is_relevant_item(cx: &LateContext<'_>, item: &Item<'_>) -> bool {

src/tools/clippy/clippy_lints/src/disallowed_macros.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
use clippy_config::Conf;
23
use clippy_config::types::create_disallowed_map;
34
use clippy_utils::diagnostics::{span_lint_and_then, span_lint_hir_and_then};
@@ -116,6 +117,7 @@ impl DisallowedMacros {
116117
}
117118
}
118119

120+
// TODO: early pass?
119121
impl_lint_pass!(DisallowedMacros => [DISALLOWED_MACROS]);
120122

121123
impl LateLintPass<'_> for DisallowedMacros {

src/tools/clippy/clippy_lints/src/doc/empty_line_after.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ use clippy_utils::diagnostics::span_lint_and_then;
22
use clippy_utils::source::{SpanRangeExt, snippet_indent};
33
use clippy_utils::tokenize_with_text;
44
use itertools::Itertools;
5-
use rustc_ast::AttrStyle;
65
use rustc_ast::token::CommentKind;
6+
use rustc_ast::AttrStyle;
77
use rustc_errors::{Applicability, Diag, SuggestionStyle};
8-
use rustc_hir::{AttrKind, Attribute, ItemKind, Node};
8+
use rustc_hir::{Attribute, ItemKind, Node};
9+
use rustc_attr_parsing::AttributeKind;
910
use rustc_lexer::TokenKind;
1011
use rustc_lint::LateContext;
1112
use rustc_span::{BytePos, ExpnKind, InnerSpan, Span, SpanData};
@@ -67,14 +68,14 @@ impl Stop {
6768
}
6869

6970
fn from_attr(cx: &LateContext<'_>, attr: &Attribute) -> Option<Self> {
70-
let SpanData { lo, hi, .. } = attr.span.data();
71+
let SpanData { lo, hi, .. } = attr.span().data();
7172
let file = cx.tcx.sess.source_map().lookup_source_file(lo);
7273

7374
Some(Self {
74-
span: attr.span,
75-
kind: match attr.kind {
76-
AttrKind::Normal(_) => StopKind::Attr,
77-
AttrKind::DocComment(comment_kind, _) => StopKind::Doc(comment_kind),
75+
span: attr.span(),
76+
kind: match attr {
77+
Attribute::Parsed(AttributeKind::DocComment{kind, ..}) => StopKind::Doc(*kind),
78+
_ => StopKind::Attr,
7879
},
7980
first: file.lookup_line(file.relative_position(lo))?,
8081
last: file.lookup_line(file.relative_position(hi))?,
@@ -300,7 +301,7 @@ fn check_gaps(cx: &LateContext<'_>, gaps: &[Gap<'_>]) -> bool {
300301
pub(super) fn check(cx: &LateContext<'_>, attrs: &[Attribute]) -> bool {
301302
let mut outer = attrs
302303
.iter()
303-
.filter(|attr| attr.style == AttrStyle::Outer && !attr.span.from_expansion())
304+
.filter(|attr| attr.style() == AttrStyle::Outer && !attr.span().from_expansion())
304305
.map(|attr| Stop::from_attr(cx, attr))
305306
.collect::<Option<Vec<_>>>()
306307
.unwrap_or_default();

src/tools/clippy/clippy_lints/src/doc/include_in_doc_without_cfg.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
use clippy_utils::diagnostics::span_lint_and_sugg;
22
use clippy_utils::source::snippet_opt;
3-
use rustc_ast::AttrStyle;
43
use rustc_errors::Applicability;
5-
use rustc_hir::{AttrArgs, AttrKind, Attribute};
6-
use rustc_lint::LateContext;
4+
use rustc_lint::EarlyContext;
5+
use rustc_ast::{Attribute, AttrKind, AttrArgs, AttrStyle};
76

87
use super::DOC_INCLUDE_WITHOUT_CFG;
98

10-
pub fn check(cx: &LateContext<'_>, attrs: &[Attribute]) {
9+
pub fn check(cx: &EarlyContext<'_>, attrs: &[Attribute]) {
1110
for attr in attrs {
1211
if !attr.span.from_expansion()
1312
&& let AttrKind::Normal(ref item) = attr.kind
1413
&& attr.doc_str().is_some()
15-
&& let AttrArgs::Eq { expr: meta, .. } = &item.args
14+
&& let AttrArgs::Eq { expr: meta, .. } = &item.item.args
1615
&& !attr.span.contains(meta.span)
1716
// Since the `include_str` is already expanded at this point, we can only take the
1817
// whole attribute snippet and then modify for our suggestion.

src/tools/clippy/clippy_lints/src/doc/mod.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use rustc_data_structures::fx::FxHashSet;
2020
use rustc_errors::Applicability;
2121
use rustc_hir::intravisit::{self, Visitor};
2222
use rustc_hir::{AnonConst, Attribute, Expr, ImplItemKind, ItemKind, Node, Safety, TraitItemKind};
23-
use rustc_lint::{LateContext, LateLintPass, LintContext};
23+
use rustc_lint::{EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintContext};
2424
use rustc_middle::hir::nested_filter;
2525
use rustc_middle::lint::in_external_macro;
2626
use rustc_middle::ty;
@@ -623,6 +623,13 @@ impl_lint_pass!(Documentation => [
623623
DOC_INCLUDE_WITHOUT_CFG,
624624
]);
625625

626+
627+
impl EarlyLintPass for Documentation {
628+
fn check_attributes(&mut self, cx: &EarlyContext<'_>, attrs: &[rustc_ast::Attribute]) {
629+
include_in_doc_without_cfg::check(cx, attrs);
630+
}
631+
}
632+
626633
impl<'tcx> LateLintPass<'tcx> for Documentation {
627634
fn check_attributes(&mut self, cx: &LateContext<'tcx>, attrs: &'tcx [Attribute]) {
628635
let Some(headers) = check_attrs(cx, &self.valid_idents, attrs) else {
@@ -750,14 +757,13 @@ fn check_attrs(cx: &LateContext<'_>, valid_idents: &FxHashSet<String>, attrs: &[
750757
Some(("fake".into(), "fake".into()))
751758
}
752759

753-
include_in_doc_without_cfg::check(cx, attrs);
754760
if suspicious_doc_comments::check(cx, attrs) || empty_line_after::check(cx, attrs) || is_doc_hidden(attrs) {
755761
return None;
756762
}
757763

758764
let (fragments, _) = attrs_to_doc_fragments(
759765
attrs.iter().filter_map(|attr| {
760-
if in_external_macro(cx.sess(), attr.span) {
766+
if in_external_macro(cx.sess(), attr.span()) {
761767
None
762768
} else {
763769
Some((attr, None))

0 commit comments

Comments
 (0)