Skip to content

Commit 99edcad

Browse files
authored
r? @ghost changelog: none
2 parents d61e73a + 28d62f0 commit 99edcad

26 files changed

+108
-89
lines changed

clippy_dev/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ clap = { version = "4.4", features = ["derive"] }
1010
indoc = "1.0"
1111
itertools = "0.12"
1212
opener = "0.7"
13+
rustc-literal-escaper = "0.0.5"
1314
walkdir = "2.3"
1415

1516
[package.metadata.rust-analyzer]

clippy_dev/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ extern crate rustc_arena;
2222
#[expect(unused_extern_crates, reason = "required to link to rustc crates")]
2323
extern crate rustc_driver;
2424
extern crate rustc_lexer;
25-
extern crate rustc_literal_escaper;
2625

2726
pub mod deprecate_lint;
2827
pub mod dogfood;

clippy_lints/src/doc/doc_suspicious_footnotes.rs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use clippy_utils::diagnostics::span_lint_and_then;
22
use rustc_ast::attr::AttributeExt as _;
3-
use rustc_ast::token::CommentKind;
3+
use rustc_ast::token::{CommentKind, DocFragmentKind};
44
use rustc_errors::Applicability;
5+
use rustc_hir::attrs::AttributeKind;
56
use rustc_hir::{AttrStyle, Attribute};
67
use rustc_lint::{LateContext, LintContext};
7-
use rustc_resolve::rustdoc::DocFragmentKind;
88

99
use std::ops::Range;
1010

@@ -43,13 +43,24 @@ pub fn check(cx: &LateContext<'_>, doc: &str, range: Range<usize>, fragments: &F
4343
span,
4444
"looks like a footnote ref, but has no matching footnote",
4545
|diag| {
46-
if this_fragment.kind == DocFragmentKind::SugaredDoc {
47-
let (doc_attr, (_, doc_attr_comment_kind), attr_style) = attrs
46+
if let DocFragmentKind::Sugared(_) = this_fragment.kind {
47+
let (doc_attr, doc_attr_comment_kind, attr_style) = attrs
4848
.iter()
49-
.filter(|attr| attr.span().overlaps(this_fragment.span))
49+
.filter(|attr| {
50+
matches!(
51+
attr,
52+
Attribute::Parsed(AttributeKind::DocComment { span, .. })
53+
if span.overlaps(this_fragment.span),
54+
)
55+
})
5056
.rev()
5157
.find_map(|attr| {
52-
Some((attr, attr.doc_str_and_comment_kind()?, attr.doc_resolution_scope()?))
58+
let (_, fragment) = attr.doc_str_and_fragment_kind()?;
59+
let fragment = match fragment {
60+
DocFragmentKind::Sugared(kind) => kind,
61+
DocFragmentKind::Raw(_) => CommentKind::Line,
62+
};
63+
Some((attr, fragment, attr.doc_resolution_scope()?))
5364
})
5465
.unwrap();
5566
let (to_add, terminator) = match (doc_attr_comment_kind, attr_style) {

clippy_lints/src/doc/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,7 @@ fn check_attrs(cx: &LateContext<'_>, valid_idents: &FxHashSet<String>, attrs: &[
861861

862862
let (fragments, _) = attrs_to_doc_fragments(
863863
attrs.iter().filter_map(|attr| {
864-
if attr.doc_str_and_comment_kind().is_none() || attr.span().in_external_macro(cx.sess().source_map()) {
864+
if attr.doc_str_and_fragment_kind().is_none() || attr.span().in_external_macro(cx.sess().source_map()) {
865865
None
866866
} else {
867867
Some((attr, None))

clippy_lints/src/doc/suspicious_doc_comments.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use clippy_utils::diagnostics::span_lint_and_then;
22
use rustc_ast::AttrStyle;
3-
use rustc_ast::token::CommentKind;
3+
use rustc_ast::token::{CommentKind, DocFragmentKind};
44
use rustc_errors::Applicability;
55
use rustc_hir::Attribute;
66
use rustc_hir::attrs::AttributeKind;
@@ -39,15 +39,15 @@ fn collect_doc_replacements(attrs: &[Attribute]) -> Vec<(Span, String)> {
3939
.filter_map(|attr| {
4040
if let Attribute::Parsed(AttributeKind::DocComment {
4141
style: AttrStyle::Outer,
42-
kind,
42+
kind: DocFragmentKind::Sugared(comment_kind),
4343
comment,
4444
..
4545
}) = attr
4646
&& let Some(com) = comment.as_str().strip_prefix('!')
4747
{
48-
let sugg = match kind {
49-
CommentKind::Line => format!("//!{com}"),
48+
let sugg = match comment_kind {
5049
CommentKind::Block => format!("/*!{com}*/"),
50+
CommentKind::Line => format!("//!{com}"),
5151
};
5252
Some((attr.span(), sugg))
5353
} else {

clippy_lints/src/methods/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -889,7 +889,7 @@ declare_clippy_lint! {
889889
/// ```
890890
#[clippy::version = "pre 1.29.0"]
891891
pub SEARCH_IS_SOME,
892-
complexity,
892+
nursery,
893893
"using an iterator or string search followed by `is_some()` or `is_none()`, which is more succinctly expressed as a call to `any()` or `contains()` (with negation in case of `is_none()`)"
894894
}
895895

clippy_lints/src/module_style.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ pub struct ModStyle {
8181

8282
impl EarlyLintPass for ModStyle {
8383
fn check_crate(&mut self, cx: &EarlyContext<'_>, _: &ast::Crate) {
84-
self.working_dir = cx.sess().opts.working_dir.local_path().map(Path::to_path_buf);
84+
self.working_dir = cx.sess().source_map().working_dir().local_path().map(Path::to_path_buf);
8585
}
8686

8787
fn check_item(&mut self, cx: &EarlyContext<'_>, item: &ast::Item) {

clippy_lints/src/utils/author.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> {
319319
chain!(self, "let ConstArgKind::Anon({anon_const}) = {const_arg}.kind");
320320
self.body(field!(anon_const.body));
321321
},
322+
ConstArgKind::Struct(..) => chain!(self, "let ConstArgKind::Struct(..) = {const_arg}.kind"),
322323
ConstArgKind::Infer(..) => chain!(self, "let ConstArgKind::Infer(..) = {const_arg}.kind"),
323324
ConstArgKind::Error(..) => chain!(self, "let ConstArgKind::Error(..) = {const_arg}.kind"),
324325
}

clippy_lints_internal/src/almost_standard_lint_formulation.rs

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
use crate::lint_without_lint_pass::is_lint_ref_type;
22
use clippy_utils::diagnostics::span_lint_and_help;
33
use regex::Regex;
4+
use rustc_ast::token::DocFragmentKind;
45
use rustc_hir::{Attribute, Item, ItemKind, Mutability};
56
use rustc_lint::{LateContext, LateLintPass};
67
use rustc_session::{declare_tool_lint, impl_lint_pass};
8+
use rustc_span::{Span, Symbol};
79

810
declare_tool_lint! {
911
/// ### What it does
@@ -46,28 +48,22 @@ impl<'tcx> LateLintPass<'tcx> for AlmostStandardFormulation {
4648
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
4749
let mut check_next = false;
4850
if let ItemKind::Static(Mutability::Not, _, ty, _) = item.kind {
49-
let lines = cx
50-
.tcx
51-
.hir_attrs(item.hir_id())
52-
.iter()
53-
.filter_map(|attr| Attribute::doc_str(attr).map(|sym| (sym, attr)));
51+
let lines = cx.tcx.hir_attrs(item.hir_id()).iter().filter_map(doc_attr);
5452
if is_lint_ref_type(cx, ty) {
55-
for (line, attr) in lines {
53+
for (line, span) in lines {
5654
let cur_line = line.as_str().trim();
5755
if check_next && !cur_line.is_empty() {
5856
for formulation in &self.standard_formulations {
5957
let starts_with_correct_formulation = cur_line.starts_with(formulation.correction);
6058
if !starts_with_correct_formulation && formulation.wrong_pattern.is_match(cur_line) {
61-
if let Some(ident) = attr.ident() {
62-
span_lint_and_help(
63-
cx,
64-
ALMOST_STANDARD_LINT_FORMULATION,
65-
ident.span,
66-
"non-standard lint formulation",
67-
None,
68-
format!("consider using `{}`", formulation.correction),
69-
);
70-
}
59+
span_lint_and_help(
60+
cx,
61+
ALMOST_STANDARD_LINT_FORMULATION,
62+
span,
63+
"non-standard lint formulation",
64+
None,
65+
format!("consider using `{}`", formulation.correction),
66+
);
7167
return;
7268
}
7369
}
@@ -84,3 +80,10 @@ impl<'tcx> LateLintPass<'tcx> for AlmostStandardFormulation {
8480
}
8581
}
8682
}
83+
84+
fn doc_attr(attr: &Attribute) -> Option<(Symbol, Span)> {
85+
match Attribute::doc_str_and_fragment_kind(attr) {
86+
Some((symbol, DocFragmentKind::Raw(span))) => Some((symbol, span)),
87+
_ => None,
88+
}
89+
}

clippy_utils/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ This crate is only guaranteed to build with this `nightly` toolchain:
88

99
<!-- begin autogenerated nightly -->
1010
```
11-
nightly-2025-12-11
11+
nightly-2025-12-25
1212
```
1313
<!-- end autogenerated nightly -->
1414

0 commit comments

Comments
 (0)