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
14 changes: 12 additions & 2 deletions clippy_config/src/conf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,12 @@ define_Conf! {
#[lints(inconsistent_struct_constructor)]
check_inconsistent_struct_field_initializers("check-inconsistent-struct-field-initializers"): bool = false,
/// Whether to also run the listed lints on private items.
#[lints(missing_errors_doc, missing_panics_doc, missing_safety_doc, unnecessary_safety_doc)]
#[lints(
missing_errors_doc,
missing_panics_doc,
missing_safety_doc,
unnecessary_safety_doc,
)]
check_private_items("check-private-items"): bool = false,
/// The maximum cognitive complexity a function can have
#[lints(cognitive_complexity)]
Expand Down Expand Up @@ -572,7 +577,12 @@ define_Conf! {
#[lints(large_futures)]
future_size_threshold("future-size-threshold"): u64 = 16 * 1024,
/// A list of paths to types that should be treated as if they do not contain interior mutability
#[lints(borrow_interior_mutable_const, declare_interior_mutable_const, ifs_same_cond, mutable_key_type)]
#[lints(
borrow_interior_mutable_const,
declare_interior_mutable_const,
ifs_same_cond,
mutable_key_type,
)]
ignore_interior_mutability("ignore-interior-mutability"): Vec<String> = DEFAULT_IGNORE_INTERIOR_MUTABILITY,
/// Sets the scope ("crate", "file", or "module") in which duplicate inherent `impl` blocks for the same type are linted.
#[lints(multiple_inherent_impl)]
Expand Down
1 change: 0 additions & 1 deletion clippy_dev/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ annotate-snippets = { version = "0.12.10", features = ["simd"] }
anstream = "0.6.20"
chrono = { version = "0.4.38", default-features = false, features = ["clock"] }
clap = { version = "4.4", features = ["derive"] }
indoc = "1.0"
itertools = "0.15"
memchr = "2.7.6"
opener = "0.8"
Expand Down
21 changes: 13 additions & 8 deletions clippy_dev/src/diag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl DiagCx {
.with_name("internal error")
.primary_title("errors were expected, but failed to occur"),
),
mk_loc_group(),
mk_loc_group(Location::caller()),
]);
}
process::exit(1);
Expand Down Expand Up @@ -92,9 +92,7 @@ fn mk_spanned_secondary<'a>(level: Level<'a>, sp: Span<'a>, msg: impl Into<Cow<'
.element(sp_to_snip(AnnotationKind::Context, sp))
}

#[track_caller]
fn mk_loc_group() -> Group<'static> {
let loc = Location::caller();
fn mk_loc_group<'a>(loc: &Location<'a>) -> Group<'a> {
Level::INFO.secondary_title("error created here").element(
Origin::path(loc.file())
.line(loc.line() as usize)
Expand All @@ -112,14 +110,21 @@ impl DiagCx {

#[track_caller]
pub fn emit_spanned_err<'a>(&mut self, sp: Span<'a>, msg: impl Into<Cow<'a, str>>) {
self.emit_err(&[mk_spanned_primary(Level::ERROR, sp, msg.into()), mk_loc_group()]);
self.emit_err(&[
mk_spanned_primary(Level::ERROR, sp, msg.into()),
mk_loc_group(Location::caller()),
]);
}

pub fn emit_spanned_err_loc<'a>(&mut self, sp: Span<'a>, msg: impl Into<Cow<'a, str>>, loc: &Location<'_>) {
self.emit_err(&[mk_spanned_primary(Level::ERROR, sp, msg.into()), mk_loc_group(loc)]);
}

#[track_caller]
pub fn emit_spanless_err<'a>(&mut self, msg: impl Into<Cow<'a, str>>) {
self.emit_err(&[
Group::with_title(Level::ERROR.primary_title(msg.into())),
mk_loc_group(),
mk_loc_group(Location::caller()),
]);
}

Expand All @@ -133,7 +138,7 @@ impl DiagCx {
self.emit_err(&[
mk_spanned_primary(Level::ERROR, sp, "duplicate lint name declared"),
mk_spanned_secondary(Level::NOTE, first_sp, "previous declaration here"),
mk_loc_group(),
mk_loc_group(Location::caller()),
]);
}

Expand All @@ -142,7 +147,7 @@ impl DiagCx {
self.emit_err(&[
mk_spanned_primary(Level::ERROR, sp, "not a clippy lint name"),
Group::with_title(Level::HELP.secondary_title("add the `clippy::` tool prefix")),
mk_loc_group(),
mk_loc_group(Location::caller()),
]);
}

Expand Down
29 changes: 13 additions & 16 deletions clippy_dev/src/edit_lints.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::ir::{ActiveLintData, DeprecatedLintData, Lint, LintData, LintName, ParsedLints, RenamedLintData};
use crate::parse::cursor::{self, Capture, Cursor};
use crate::parse::{ActiveLint, DeprecatedLint, Lint, LintData, LintName, ParseCx, ParsedLints, RenamedLint};
use crate::utils::{
ErrAction, FileUpdater, UpdateMode, UpdateStatus, Version, delete_dir_if_exists, delete_file_if_exists,
expect_action, try_rename_dir, try_rename_file, walk_dir_no_dot_or_target,
};
use crate::{SourceFile, Span};
use crate::{ParseCx, SourceFile, Span};
use core::mem;
use rustc_lexer::TokenKind;
use std::collections::hash_map::Entry;
Expand All @@ -31,10 +31,8 @@ pub fn deprecate<'cx, 'env: 'cx>(cx: ParseCx<'cx>, clippy_version: Version, name
lint.get_mut(),
Lint {
name_sp: Span::new(data.deprecated_file, 0..0),
data: LintData::Deprecated(DeprecatedLint {
reason,
version: cx.str_buf.alloc_display(cx.arena, clippy_version.rust_display()),
}),
version: cx.str_buf.alloc_display(cx.arena, clippy_version.rust_display()),
data: LintData::Deprecated(DeprecatedLintData { reason }),
},
);
let LintData::Active(prev_lint_data) = prev_lint.data else {
Expand Down Expand Up @@ -65,9 +63,9 @@ pub fn uplift<'cx, 'env: 'cx>(cx: ParseCx<'cx>, clippy_version: Version, old_nam
lint.get_mut(),
Lint {
name_sp: Span::new(data.deprecated_file, 0..0),
data: LintData::Renamed(RenamedLint {
version: cx.str_buf.alloc_display(cx.arena, clippy_version.rust_display()),
data: LintData::Renamed(RenamedLintData {
new_name: LintName::new_rustc(new_name),
version: cx.str_buf.alloc_display(cx.arena, clippy_version.rust_display()),
}),
},
);
Expand Down Expand Up @@ -117,9 +115,9 @@ pub fn rename<'cx, 'env: 'cx>(cx: ParseCx<'cx>, clippy_version: Version, old_nam
lint.get_mut(),
Lint {
name_sp: Span::new(data.deprecated_file, 0..0),
data: LintData::Renamed(RenamedLint {
version: cx.str_buf.alloc_display(cx.arena, clippy_version.rust_display()),
data: LintData::Renamed(RenamedLintData {
new_name: LintName::new_clippy(new_name),
version: cx.str_buf.alloc_display(cx.arena, clippy_version.rust_display()),
}),
},
);
Expand Down Expand Up @@ -173,14 +171,14 @@ pub fn rename<'cx, 'env: 'cx>(cx: ParseCx<'cx>, clippy_version: Version, old_nam
fn remove_lint_declaration(
name: &str,
lint_file: &SourceFile<'_>,
lint_data: &ActiveLint<'_>,
lint_data: &ActiveLintData<'_>,
data: &ParsedLints<'_>,
updater: &mut FileUpdater,
) -> bool {
let delete_mod = if data.lints.iter().all(|(_, l)| l.name_sp.file != lint_file) {
delete_file_if_exists(lint_file.path.get())
} else {
updater.update_file(lint_file.path.get(), &mut |_, src, dst| -> UpdateStatus {
updater.change_file(lint_file.path.get(), |src, dst| {
let mut start = &src[..lint_data.decl_range.start as usize];
if start.ends_with("\n\n") {
start = &start[..start.len() - 1];
Expand All @@ -191,7 +189,6 @@ fn remove_lint_declaration(
}
dst.push_str(start);
dst.push_str(end);
UpdateStatus::Changed
});
false
};
Expand Down Expand Up @@ -341,30 +338,30 @@ fn snake_to_pascal(s: &str) -> String {
fn uplift_update_fn<'a>(
old_name: &'a str,
new_name: &'a str,
remove_mod: bool,
mut remove_mod: bool,
) -> impl use<'a> + FnMut(&Path, &str, &mut String) -> UpdateStatus {
move |_, src, dst| {
let mut copy_pos = 0u32;
let mut changed = false;
let mut cursor = Cursor::new(src);
while let Some(ident) = cursor.find_capture_ident() {
match cursor.get_text(ident) {
"mod" if remove_mod && cursor.eat_ident(old_name) && cursor.eat_semi() => {
"pub" if remove_mod && cursor.eat_ident("mod") && cursor.eat_ident(old_name) && cursor.eat_semi() => {
dst.push_str(&src[copy_pos as usize..ident.pos as usize]);
dst.push_str(new_name);
copy_pos = cursor.pos();
if src[copy_pos as usize..].starts_with('\n') {
copy_pos += 1;
}
changed = true;
remove_mod = false;
},
"clippy" if cursor.eat_double_colon() && cursor.eat_ident(old_name) => {
dst.push_str(&src[copy_pos as usize..ident.pos as usize]);
dst.push_str(new_name);
copy_pos = cursor.pos();
changed = true;
},

_ => {},
}
}
Expand Down
Loading