mirror of https://github.com/rust-lang/cargo
test(rustfix): demonstrate duplicate suggestions
This commit is contained in:
parent
bd1cf584af
commit
5b05a3bb5a
|
@ -0,0 +1,17 @@
|
|||
// This fixes rust-lang/rust#123304.
|
||||
// If that lint stops emitting duplicate suggestions,
|
||||
// we might need to find a substitution.
|
||||
#![warn(unsafe_op_in_unsafe_fn)]
|
||||
|
||||
macro_rules! foo {
|
||||
($x:ident) => {
|
||||
pub unsafe fn $x() { unsafe { unsafe {
|
||||
let _ = String::new().as_mut_vec();
|
||||
}}}
|
||||
};
|
||||
}
|
||||
|
||||
fn main() {
|
||||
foo!(a);
|
||||
foo!(b);
|
||||
}
|
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,17 @@
|
|||
// This fixes rust-lang/rust#123304.
|
||||
// If that lint stops emitting duplicate suggestions,
|
||||
// we might need to find a substitution.
|
||||
#![warn(unsafe_op_in_unsafe_fn)]
|
||||
|
||||
macro_rules! foo {
|
||||
($x:ident) => {
|
||||
pub unsafe fn $x() {
|
||||
let _ = String::new().as_mut_vec();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
fn main() {
|
||||
foo!(a);
|
||||
foo!(b);
|
||||
}
|
|
@ -1897,3 +1897,48 @@ warning: `foo` (lib) generated 1 warning (run `cargo fix --lib -p foo` to apply
|
|||
")
|
||||
.run();
|
||||
}
|
||||
|
||||
// This fixes rust-lang/rust#123304.
|
||||
// If that lint stops emitting duplicate suggestions,
|
||||
// we might need to find a substitution.
|
||||
#[cargo_test]
|
||||
fn fix_only_once_for_duplicates() {
|
||||
let p = project()
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
r#"
|
||||
#![warn(unsafe_op_in_unsafe_fn)]
|
||||
|
||||
macro_rules! foo {
|
||||
($x:ident) => {
|
||||
pub unsafe fn $x() {
|
||||
let _ = String::new().as_mut_vec();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
foo!(a);
|
||||
foo!(b);
|
||||
"#,
|
||||
)
|
||||
.build();
|
||||
|
||||
p.cargo("fix --allow-no-vcs")
|
||||
.with_stderr_contains(
|
||||
"\
|
||||
[CHECKING] foo v0.0.1 ([CWD])
|
||||
[FIXED] src/lib.rs (2 fixes)
|
||||
",
|
||||
)
|
||||
.with_stderr_contains("[WARNING] unnecessary `unsafe` block[..]")
|
||||
.run();
|
||||
|
||||
assert_eq!(
|
||||
p.read_file("src/lib.rs").matches("unsafe").count(),
|
||||
5,
|
||||
"unsafe keyword in src/lib.rs:\n\
|
||||
2 in lint name;\n\
|
||||
1 from original unsafe fn;\n\
|
||||
2 from newly-applied unsafe blocks"
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue