From d5128b44510b5fe6594c8291a3a7383b79730b97 Mon Sep 17 00:00:00 2001 From: Xianpeng Shen <3353385+shenxianpeng@users.noreply.github.com> Date: Sun, 29 Nov 2026 15:56:52 +0000 Subject: [PATCH 1/4] fix: add `const` only once when two clang-tidy fixes make the same type const misc-const-correctness inserts `int const *p` and readability-non-const-parameter inserts `const int *p` for the same parameter. Both were applied, making `const int const *p`, which GCC rejects (duplicate `const`). The suggestion and the auto-fix commit showed that code. When two inserted `const` (or `volatile`) qualifiers have only a type name between them, the later one is now skipped (with an INFO log). Qualifiers for different things (eg. `const int *const p` or another parameter) are kept. --- cpp-linter/src/clang_tools/clang_tidy/mod.rs | 35 +++++++++++ cpp-linter/src/clang_tools/clang_tidy/test.rs | 63 ++++++++++++++++++- 2 files changed, 97 insertions(+), 1 deletion(-) diff --git a/cpp-linter/src/clang_tools/clang_tidy/mod.rs b/cpp-linter/src/clang_tools/clang_tidy/mod.rs index 49dacf8d..88778cb2 100644 --- a/cpp-linter/src/clang_tools/clang_tidy/mod.rs +++ b/cpp-linter/src/clang_tools/clang_tidy/mod.rs @@ -588,6 +588,7 @@ pub(super) fn patch_content( replacements.dedup(); let mut patched = Vec::with_capacity(content.len()); let mut cursor = 0; + let mut last_qualifier: Option<(usize, &str)> = None; for replacement in replacements { if replacement.offset < cursor { logs.push(( @@ -599,14 +600,48 @@ pub(super) fn patch_content( )); continue; } + let qualifier = inserted_qualifier(replacement); + if let (Some(qualifier), Some((last_offset, last))) = (qualifier, last_qualifier) + && qualifier == last + && is_same_type(&content[last_offset..replacement.offset]) + { + logs.push(( + log::Level::Info, + format!( + "Skipping a fix that adds `{qualifier}` again to the same type in {}: {replacement:?}", + file.to_string_lossy(), + ), + )); + continue; + } patched.extend_from_slice(&content[cursor..replacement.offset]); patched.extend_from_slice(replacement.text.as_bytes()); cursor = replacement.offset + replacement.length; + last_qualifier = qualifier.map(|qualifier| (cursor, qualifier)); } patched.extend_from_slice(&content[cursor..]); patched } +/// The `const` or `volatile` that a `replacement` only inserts (eg. `" const"`). +fn inserted_qualifier(replacement: &Replacement) -> Option<&str> { + let text = replacement.text.trim(); + (replacement.length == 0 && matches!(text, "const" | "volatile")).then_some(text) +} + +/// Is the `text` between two inserted qualifiers only (part of) one type name? +/// +/// Different checks can make the same type `const` in different places. +/// For example, misc-const-correctness inserts `int const *p` and +/// readability-non-const-parameter inserts `const int *p`; applying both makes +/// `const int const *p`, which compilers reject (duplicate `const`). +/// A `*` or `&` (or anything else) in between means the qualifiers apply to +/// different things (eg. `const int *const p`), so both are kept. +fn is_same_type(text: &[u8]) -> bool { + text.iter() + .all(|b| b.is_ascii_alphanumeric() || matches!(b, b'_' | b':' | b' ' | b'\t')) +} + /// Write the `patched` content of a `file` to the cache. /// /// Returns the path to the cached file. diff --git a/cpp-linter/src/clang_tools/clang_tidy/test.rs b/cpp-linter/src/clang_tools/clang_tidy/test.rs index fc9dc8cc..73ec8f5c 100644 --- a/cpp-linter/src/clang_tools/clang_tidy/test.rs +++ b/cpp-linter/src/clang_tools/clang_tidy/test.rs @@ -19,7 +19,7 @@ use crate::{ use super::{ CLANG_DIAGNOSTICS_URL, ClangCaptureError, CompilationUnit, ExportedFixes, FixPaths, NOTE_HEADER, OtherFileFix, Replacement, TidyAdvice, TidyNotification, apply_fixes, - run_clang_tidy, tally_tidy_advice, tidy_failure, + patch_content, run_clang_tidy, tally_tidy_advice, tidy_failure, }; #[test] @@ -1010,3 +1010,64 @@ fn tidy_with_matching_database() { assert!(!advice.failed); assert_eq!(advice.notes.len(), 1); } + +fn insert(offset: usize, text: &str) -> Replacement { + Replacement { + offset, + length: 0, + text: text.to_string(), + } +} + +/// Two checks can make the same type `const` in different places. +#[test] +fn qualifier_added_once() { + let content = b"int f(int *p, int *q);"; + let mut logs = vec![]; + // `const int const *p` (misc-const-correctness and readability-non-const-parameter) + let fixes = [insert(6, "const "), insert(9, " const")]; + let patched = patch_content(content, &fixes, Path::new("f.cpp"), &mut logs); + assert_eq!(patched, b"int f(const int *p, int *q);"); + assert_eq!(logs.len(), 1); + assert_eq!(logs[0].0, log::Level::Info); + assert!(logs[0].1.contains("adds `const` again"), "{logs:?}"); + + // the same qualifier for different things is kept + let mut logs = vec![]; + let fixes = [ + // `const int *const p`: what the pointer points to, and the pointer + insert(6, "const "), + insert(11, "const "), + // another parameter + insert(14, "const "), + // `volatile` is not `const` + insert(17, " volatile"), + ]; + let patched = patch_content(content, &fixes, Path::new("f.cpp"), &mut logs); + assert_eq!( + String::from_utf8(patched).unwrap(), + "int f(const int *const p, const int volatile *q);" + ); + assert!(logs.is_empty(), "{logs:?}"); +} + +/// The fixes of misc-const-correctness and readability-non-const-parameter for the +/// same parameter make it `const` only once. +#[test] +fn tidy_fixes_add_const_once() { + let tmp_workspace = tempfile::TempDir::with_prefix("cpp-linter-unit-tests_").unwrap(); + fs::write( + tmp_workspace.path().join("demo.cpp"), + "int get(int *p) {\n return *p;\n}\n", + ) + .unwrap(); + let mut clang_params = make_clang_params(tmp_workspace.path(), Some(get_tidy_exe())); + clang_params.tidy_checks = + "-*,misc-const-correctness,readability-non-const-parameter".to_string(); + clang_params.gen_patch = true; + let file = Mutex::new(FileObj::new(PathBuf::from("demo.cpp"))); + let mut file = file.lock().unwrap(); + run_clang_tidy(&mut file, &clang_params).unwrap(); + let patched = fs::read_to_string(file.patched_path.as_ref().unwrap()).unwrap(); + assert_eq!(patched.matches("const").count(), 1, "{patched}"); +} From 0037878e454703ff834428c1792dc17bb9db0205 Mon Sep 17 00:00:00 2001 From: Xianpeng Shen <3353385+shenxianpeng@users.noreply.github.com> Date: Sun, 29 Nov 2026 16:10:27 +0000 Subject: [PATCH 2/4] fix: only skip the misc-const-correctness fix that readability-non-const-parameter also makes Instead of guessing from the text between two inserted qualifiers, skip the "pointee" fix of misc-const-correctness only when readability-non-const-parameter fixes the same parameter. This keeps every other qualifier fix (eg. a pointer hidden in a macro), and no longer rewrites a macro that the parameter's type uses. --- cpp-linter/src/clang_tools/clang_tidy/mod.rs | 76 +++++----- cpp-linter/src/clang_tools/clang_tidy/test.rs | 141 +++++++++++++----- cspell.config.yml | 1 + 3 files changed, 145 insertions(+), 73 deletions(-) diff --git a/cpp-linter/src/clang_tools/clang_tidy/mod.rs b/cpp-linter/src/clang_tools/clang_tidy/mod.rs index 88778cb2..cd646a83 100644 --- a/cpp-linter/src/clang_tools/clang_tidy/mod.rs +++ b/cpp-linter/src/clang_tools/clang_tidy/mod.rs @@ -379,6 +379,8 @@ struct ExportedDiagnostic { #[derive(Deserialize, Debug, Default)] #[serde(rename_all = "PascalCase")] struct ExportedMessage { + #[serde(default)] + message: String, #[serde(default)] file_path: String, #[serde(default)] @@ -474,6 +476,16 @@ fn apply_fixes<'a>( ) -> (Vec, TidyFixes) { let mut tidy_fixes = TidyFixes::default(); for diag in &fixes.diagnostics { + if is_redundant_pointee_fix(diag, &fixes.diagnostics) { + logs.push(( + log::Level::Info, + format!( + "Skipping the fix of {} that readability-non-const-parameter also makes: {}", + diag.diagnostic_name, diag.diagnostic_message.message, + ), + )); + continue; + } let first_other = tidy_fixes.others.len(); let fixed_lines = collect_diagnostic_fixes(diag, paths, content, &mut tidy_fixes, logs); let other_fixes = &mut tidy_fixes.others[first_other..]; @@ -500,6 +512,35 @@ fn apply_fixes<'a>( (patched, tidy_fixes) } +/// Is `diag` a misc-const-correctness fix that a readability-non-const-parameter fix +/// (in `all`) also makes? +/// +/// For a pointer parameter that is only read, both checks make what it points to +/// `const`: misc-const-correctness as `int const *p` and readability-non-const-parameter +/// as `const int *p`. Applying both makes `const int const *p`, which GCC rejects +/// (duplicate `const`). The fix of readability-non-const-parameter is kept, +/// because it also fixes every other declaration of the function, and it does not +/// change a macro that the parameter's type uses (eg. `int PTR p`). +/// +/// Both diagnostics are about the same parameter if readability-non-const-parameter +/// inserts `const` where the misc-const-correctness diagnostic points +/// (the start of that parameter's declaration). +fn is_redundant_pointee_fix(diag: &ExportedDiagnostic, all: &[ExportedDiagnostic]) -> bool { + let msg = &diag.diagnostic_message; + diag.diagnostic_name == "misc-const-correctness" + && msg.message.starts_with("pointee of variable ") + && !msg.replacements.is_empty() + && all.iter().any(|other| { + other.diagnostic_name == "readability-non-const-parameter" + && other.diagnostic_message.replacements.iter().any(|fix| { + fix.file_path == msg.file_path + && fix.offset == msg.file_offset + && fix.length == 0 + && fix.replacement_text.trim() == "const" + }) + }) +} + /// Sort the replacements of one `diag` into [`TidyFixes::own`] or [`TidyFixes::others`]. /// /// Returns the lines (in the analyzed file's `content`) that this diagnostic fixes. @@ -588,7 +629,6 @@ pub(super) fn patch_content( replacements.dedup(); let mut patched = Vec::with_capacity(content.len()); let mut cursor = 0; - let mut last_qualifier: Option<(usize, &str)> = None; for replacement in replacements { if replacement.offset < cursor { logs.push(( @@ -600,48 +640,14 @@ pub(super) fn patch_content( )); continue; } - let qualifier = inserted_qualifier(replacement); - if let (Some(qualifier), Some((last_offset, last))) = (qualifier, last_qualifier) - && qualifier == last - && is_same_type(&content[last_offset..replacement.offset]) - { - logs.push(( - log::Level::Info, - format!( - "Skipping a fix that adds `{qualifier}` again to the same type in {}: {replacement:?}", - file.to_string_lossy(), - ), - )); - continue; - } patched.extend_from_slice(&content[cursor..replacement.offset]); patched.extend_from_slice(replacement.text.as_bytes()); cursor = replacement.offset + replacement.length; - last_qualifier = qualifier.map(|qualifier| (cursor, qualifier)); } patched.extend_from_slice(&content[cursor..]); patched } -/// The `const` or `volatile` that a `replacement` only inserts (eg. `" const"`). -fn inserted_qualifier(replacement: &Replacement) -> Option<&str> { - let text = replacement.text.trim(); - (replacement.length == 0 && matches!(text, "const" | "volatile")).then_some(text) -} - -/// Is the `text` between two inserted qualifiers only (part of) one type name? -/// -/// Different checks can make the same type `const` in different places. -/// For example, misc-const-correctness inserts `int const *p` and -/// readability-non-const-parameter inserts `const int *p`; applying both makes -/// `const int const *p`, which compilers reject (duplicate `const`). -/// A `*` or `&` (or anything else) in between means the qualifiers apply to -/// different things (eg. `const int *const p`), so both are kept. -fn is_same_type(text: &[u8]) -> bool { - text.iter() - .all(|b| b.is_ascii_alphanumeric() || matches!(b, b'_' | b':' | b' ' | b'\t')) -} - /// Write the `patched` content of a `file` to the cache. /// /// Returns the path to the cached file. diff --git a/cpp-linter/src/clang_tools/clang_tidy/test.rs b/cpp-linter/src/clang_tools/clang_tidy/test.rs index 73ec8f5c..7483fbbf 100644 --- a/cpp-linter/src/clang_tools/clang_tidy/test.rs +++ b/cpp-linter/src/clang_tools/clang_tidy/test.rs @@ -19,7 +19,7 @@ use crate::{ use super::{ CLANG_DIAGNOSTICS_URL, ClangCaptureError, CompilationUnit, ExportedFixes, FixPaths, NOTE_HEADER, OtherFileFix, Replacement, TidyAdvice, TidyNotification, apply_fixes, - patch_content, run_clang_tidy, tally_tidy_advice, tidy_failure, + run_clang_tidy, tally_tidy_advice, tidy_failure, }; #[test] @@ -1011,56 +1011,116 @@ fn tidy_with_matching_database() { assert_eq!(advice.notes.len(), 1); } -fn insert(offset: usize, text: &str) -> Replacement { - Replacement { - offset, - length: 0, - text: text.to_string(), +/// A diagnostic of `name` at `offset` that inserts each `(offset, text)` of `fixes`. +fn insert_diag(name: &str, message: &str, offset: usize, fixes: &[(usize, &str)]) -> String { + let mut yml = format!( + " - DiagnosticName: {name}\n DiagnosticMessage:\n \ + Message: \"{message}\"\n FilePath: 'demo.cpp'\n \ + FileOffset: {offset}\n Replacements:" + ); + if fixes.is_empty() { + yml.push_str(" []\n"); + } else { + yml.push('\n'); + } + for (offset, text) in fixes { + yml.push_str(&format!( + " - FilePath: 'demo.cpp'\n Offset: {offset}\n \ + Length: 0\n ReplacementText: '{text}'\n" + )); } + yml } -/// Two checks can make the same type `const` in different places. +/// misc-const-correctness and readability-non-const-parameter both make what a +/// pointer parameter points to `const`, but only one of them is applied. #[test] -fn qualifier_added_once() { - let content = b"int f(int *p, int *q);"; - let mut logs = vec![]; - // `const int const *p` (misc-const-correctness and readability-non-const-parameter) - let fixes = [insert(6, "const "), insert(9, " const")]; - let patched = patch_content(content, &fixes, Path::new("f.cpp"), &mut logs); - assert_eq!(patched, b"int f(const int *p, int *q);"); - assert_eq!(logs.len(), 1); +fn pointee_made_const_once() { + let tmp = tempfile::tempdir().unwrap(); + let target = tmp.path().join("demo.cpp"); + let content = b"int get(int *p);\nint get(int *p) {\n return *p;\n}\n"; + // as exported by clang-tidy 23 (for `p` on line 2) + let pointee = insert_diag( + "misc-const-correctness", + "pointee of variable 'p' of type 'int *' can be declared 'const'", + 25, + &[(12, " const"), (29, " const")], + ); + let parameter = insert_diag( + "readability-non-const-parameter", + "pointer parameter 'p' can be pointer to const", + 30, + &[(8, "const "), (25, "const ")], + ); + // the pointer itself can be `const` too (option WarnPointersAsValues) + let pointer = insert_diag( + "misc-const-correctness", + "variable 'p' of type 'int *' can be declared 'const'", + 25, + &[(30, "const ")], + ); + let build_dir = tmp.path().to_string_lossy(); + let apply = |diagnostics: &[&String]| { + let yml = format!( + "---\nMainSourceFile: 'demo.cpp'\nDiagnostics:\n{}...\n", + diagnostics + .iter() + .map(|diag| format!("{diag} BuildDirectory: '{build_dir}'\n")) + .collect::() + ); + let fixes: ExportedFixes = serde_saphyr::from_str(&yml).unwrap(); + let mut logs = vec![]; + let mut paths = FixPaths::new(&target, tmp.path()); + let (patched, _) = apply_fixes(&fixes, &mut paths, content, &mut [], &mut logs); + (String::from_utf8(patched).unwrap(), logs) + }; + + let (patched, logs) = apply(&[&pointee, ¶meter, &pointer]); + assert_eq!( + patched, + "int get(const int *p);\nint get(const int *const p) {\n return *p;\n}\n" + ); + assert_eq!(logs.len(), 1, "{logs:#?}"); assert_eq!(logs[0].0, log::Level::Info); - assert!(logs[0].1.contains("adds `const` again"), "{logs:?}"); + assert!( + logs[0] + .1 + .contains("readability-non-const-parameter also makes"), + "{logs:#?}" + ); - // the same qualifier for different things is kept - let mut logs = vec![]; - let fixes = [ - // `const int *const p`: what the pointer points to, and the pointer - insert(6, "const "), - insert(11, "const "), - // another parameter - insert(14, "const "), - // `volatile` is not `const` - insert(17, " volatile"), - ]; - let patched = patch_content(content, &fixes, Path::new("f.cpp"), &mut logs); + // without readability-non-const-parameter, misc-const-correctness is applied + // (clang-tidy inserts its `const` right before the `*`) + let (patched, logs) = apply(&[&pointee]); assert_eq!( - String::from_utf8(patched).unwrap(), - "int f(const int *const p, const int volatile *q);" + patched, + "int get(int const*p);\nint get(int const*p) {\n return *p;\n}\n" + ); + assert!(logs.is_empty(), "{logs:#?}"); + + // readability-non-const-parameter about another parameter does not matter + let other = insert_diag( + "readability-non-const-parameter", + "pointer parameter 'q' can be pointer to const", + 30, + &[(8, "const ")], ); - assert!(logs.is_empty(), "{logs:?}"); + let (patched, logs) = apply(&[&pointee, &other]); + assert_eq!( + patched, + "int get(const int const*p);\nint get(int const*p) {\n return *p;\n}\n" + ); + assert!(logs.is_empty(), "{logs:#?}"); } /// The fixes of misc-const-correctness and readability-non-const-parameter for the -/// same parameter make it `const` only once. +/// same parameter make it `const` only once, even if the pointer is a macro. #[test] fn tidy_fixes_add_const_once() { let tmp_workspace = tempfile::TempDir::with_prefix("cpp-linter-unit-tests_").unwrap(); - fs::write( - tmp_workspace.path().join("demo.cpp"), - "int get(int *p) {\n return *p;\n}\n", - ) - .unwrap(); + let source = "int get(int *p);\nint get(int *p) {\n return *p;\n}\n\ + #define PTR *\nint deref(int PTR q) { return *q; }\n"; + fs::write(tmp_workspace.path().join("demo.cpp"), source).unwrap(); let mut clang_params = make_clang_params(tmp_workspace.path(), Some(get_tidy_exe())); clang_params.tidy_checks = "-*,misc-const-correctness,readability-non-const-parameter".to_string(); @@ -1069,5 +1129,10 @@ fn tidy_fixes_add_const_once() { let mut file = file.lock().unwrap(); run_clang_tidy(&mut file, &clang_params).unwrap(); let patched = fs::read_to_string(file.patched_path.as_ref().unwrap()).unwrap(); - assert_eq!(patched.matches("const").count(), 1, "{patched}"); + assert_eq!( + patched, + source + .replace("(int *p)", "(const int *p)") + .replace("(int PTR q)", "(const int PTR q)") + ); } diff --git a/cspell.config.yml b/cspell.config.yml index d17df7ab..c7fe0906 100644 --- a/cspell.config.yml +++ b/cspell.config.yml @@ -93,6 +93,7 @@ words: - peekable - pipx - pkgs + - pointee - posargs - positionals - posix From 15130ad1798f40a26649b93a3247d8d17bbdf47c Mon Sep 17 00:00:00 2001 From: Xianpeng Shen <3353385+shenxianpeng@users.noreply.github.com> Date: Sun, 29 Nov 2026 16:17:48 +0000 Subject: [PATCH 3/4] fix: count the skipped misc-const-correctness diagnostic as fixed readability-non-const-parameter inserts its `const` on the same line, so the PR review shows one suggestion instead of an extra comment that looks unfixed, and the thread comment keeps "(fixable)". --- cpp-linter/src/clang_tools/clang_tidy/mod.rs | 12 ++++++++++++ cpp-linter/src/clang_tools/clang_tidy/test.rs | 6 ++++++ 2 files changed, 18 insertions(+) diff --git a/cpp-linter/src/clang_tools/clang_tidy/mod.rs b/cpp-linter/src/clang_tools/clang_tidy/mod.rs index cd646a83..da47f0b5 100644 --- a/cpp-linter/src/clang_tools/clang_tidy/mod.rs +++ b/cpp-linter/src/clang_tools/clang_tidy/mod.rs @@ -484,6 +484,18 @@ fn apply_fixes<'a>( diag.diagnostic_name, diag.diagnostic_message.message, ), )); + // readability-non-const-parameter inserts its `const` where this diagnostic points, + // so this diagnostic is fixed (on that line) too. + let own_line = paths + .other_file(&diag.build_directory, &diag.diagnostic_message.file_path) + .is_none() + .then(|| offset_to_line(content, diag.diagnostic_message.file_offset)); + if let Some(line) = own_line + && let Some(note) = find_note(diag, paths, content, notes) + && !note.fixed_lines.contains(&line) + { + note.fixed_lines.push(line); + } continue; } let first_other = tidy_fixes.others.len(); diff --git a/cpp-linter/src/clang_tools/clang_tidy/test.rs b/cpp-linter/src/clang_tools/clang_tidy/test.rs index 7483fbbf..cef60c0b 100644 --- a/cpp-linter/src/clang_tools/clang_tidy/test.rs +++ b/cpp-linter/src/clang_tools/clang_tidy/test.rs @@ -1135,4 +1135,10 @@ fn tidy_fixes_add_const_once() { .replace("(int *p)", "(const int *p)") .replace("(int PTR q)", "(const int PTR q)") ); + // the skipped diagnostic is still fixed (by the other fix), eg. for the PR review + let notes = &file.tidy_advice.as_ref().unwrap().notes; + assert!( + notes.iter().all(|note| !note.fixed_lines.is_empty()), + "{notes:#?}" + ); } From fba4ef0387e58158759fcc6f4742d51a0ab3ecff Mon Sep 17 00:00:00 2001 From: Xianpeng Shen <3353385+shenxianpeng@users.noreply.github.com> Date: Sun, 29 Nov 2026 16:30:36 +0000 Subject: [PATCH 4/4] test: cover marking the skipped diagnostic as fixed without clang-tidy 23 CI runs unit tests only with the oldest clang-tidy, which has no misc-const-correctness, so the unit test now checks the fixed lines. --- cpp-linter/src/clang_tools/clang_tidy/test.rs | 35 +++++++++++++------ 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/cpp-linter/src/clang_tools/clang_tidy/test.rs b/cpp-linter/src/clang_tools/clang_tidy/test.rs index cef60c0b..c54e112e 100644 --- a/cpp-linter/src/clang_tools/clang_tidy/test.rs +++ b/cpp-linter/src/clang_tools/clang_tidy/test.rs @@ -1016,13 +1016,8 @@ fn insert_diag(name: &str, message: &str, offset: usize, fixes: &[(usize, &str)] let mut yml = format!( " - DiagnosticName: {name}\n DiagnosticMessage:\n \ Message: \"{message}\"\n FilePath: 'demo.cpp'\n \ - FileOffset: {offset}\n Replacements:" + FileOffset: {offset}\n Replacements:\n" ); - if fixes.is_empty() { - yml.push_str(" []\n"); - } else { - yml.push('\n'); - } for (offset, text) in fixes { yml.push_str(&format!( " - FilePath: 'demo.cpp'\n Offset: {offset}\n \ @@ -1069,13 +1064,31 @@ fn pointee_made_const_once() { .collect::() ); let fixes: ExportedFixes = serde_saphyr::from_str(&yml).unwrap(); + let mut notes = + ["misc-const-correctness", "readability-non-const-parameter"].map(|diagnostic| { + TidyNotification { + line: 2, + diagnostic: diagnostic.to_string(), + ..dummy_note("demo.cpp", vec![]) + } + }); let mut logs = vec![]; let mut paths = FixPaths::new(&target, tmp.path()); - let (patched, _) = apply_fixes(&fixes, &mut paths, content, &mut [], &mut logs); - (String::from_utf8(patched).unwrap(), logs) + let (patched, _) = apply_fixes(&fixes, &mut paths, content, &mut notes, &mut logs); + (String::from_utf8(patched).unwrap(), logs, notes) }; - let (patched, logs) = apply(&[&pointee, ¶meter, &pointer]); + let (patched, logs, notes) = apply(&[&pointee, ¶meter]); + // the skipped diagnostic is still fixed on its line, by the other fix + assert_eq!(notes[0].fixed_lines, vec![2]); + assert_eq!(notes[1].fixed_lines, vec![1, 2]); + assert_eq!( + patched, + "int get(const int *p);\nint get(const int *p) {\n return *p;\n}\n" + ); + assert_eq!(logs.len(), 1, "{logs:#?}"); + + let (patched, logs, _) = apply(&[&pointee, ¶meter, &pointer]); assert_eq!( patched, "int get(const int *p);\nint get(const int *const p) {\n return *p;\n}\n" @@ -1091,7 +1104,7 @@ fn pointee_made_const_once() { // without readability-non-const-parameter, misc-const-correctness is applied // (clang-tidy inserts its `const` right before the `*`) - let (patched, logs) = apply(&[&pointee]); + let (patched, logs, _) = apply(&[&pointee]); assert_eq!( patched, "int get(int const*p);\nint get(int const*p) {\n return *p;\n}\n" @@ -1105,7 +1118,7 @@ fn pointee_made_const_once() { 30, &[(8, "const ")], ); - let (patched, logs) = apply(&[&pointee, &other]); + let (patched, logs, _) = apply(&[&pointee, &other]); assert_eq!( patched, "int get(const int const*p);\nint get(int const*p) {\n return *p;\n}\n"