mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 06:44:35 +00:00
Fix handling of macro arguments within the `dropping_copy_types lint
This commit is contained in:
parent
e08b80c0fb
commit
6a878a9630
@ -151,10 +151,11 @@ impl<'tcx> LateLintPass<'tcx> for DropForgetUseless {
|
|||||||
&& let Node::Stmt(stmt) = node
|
&& let Node::Stmt(stmt) = node
|
||||||
&& let StmtKind::Semi(e) = stmt.kind
|
&& let StmtKind::Semi(e) = stmt.kind
|
||||||
&& e.hir_id == expr.hir_id
|
&& e.hir_id == expr.hir_id
|
||||||
|
&& let Some(arg_span) = arg.span.find_ancestor_inside(expr.span)
|
||||||
{
|
{
|
||||||
UseLetUnderscoreIgnoreSuggestion::Suggestion {
|
UseLetUnderscoreIgnoreSuggestion::Suggestion {
|
||||||
start_span: expr.span.shrink_to_lo().until(arg.span),
|
start_span: expr.span.shrink_to_lo().until(arg_span),
|
||||||
end_span: arg.span.shrink_to_hi().until(expr.span.shrink_to_hi()),
|
end_span: arg_span.shrink_to_hi().until(expr.span.shrink_to_hi()),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
UseLetUnderscoreIgnoreSuggestion::Note
|
UseLetUnderscoreIgnoreSuggestion::Note
|
||||||
|
12
tests/ui/lint/dropping_copy_types-macros.fixed
Normal file
12
tests/ui/lint/dropping_copy_types-macros.fixed
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
//@ check-fail
|
||||||
|
//@ run-rustfix
|
||||||
|
|
||||||
|
#![deny(dropping_copy_types)]
|
||||||
|
|
||||||
|
use std::fmt::Write;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let mut msg = String::new();
|
||||||
|
let _ = writeln!(&mut msg, "test");
|
||||||
|
//~^ ERROR calls to `std::mem::drop`
|
||||||
|
}
|
12
tests/ui/lint/dropping_copy_types-macros.rs
Normal file
12
tests/ui/lint/dropping_copy_types-macros.rs
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
//@ check-fail
|
||||||
|
//@ run-rustfix
|
||||||
|
|
||||||
|
#![deny(dropping_copy_types)]
|
||||||
|
|
||||||
|
use std::fmt::Write;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let mut msg = String::new();
|
||||||
|
drop(writeln!(&mut msg, "test"));
|
||||||
|
//~^ ERROR calls to `std::mem::drop`
|
||||||
|
}
|
21
tests/ui/lint/dropping_copy_types-macros.stderr
Normal file
21
tests/ui/lint/dropping_copy_types-macros.stderr
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
error: calls to `std::mem::drop` with a value that implements `Copy` does nothing
|
||||||
|
--> $DIR/dropping_copy_types-macros.rs:10:5
|
||||||
|
|
|
||||||
|
LL | drop(writeln!(&mut msg, "test"));
|
||||||
|
| ^^^^^--------------------------^
|
||||||
|
| |
|
||||||
|
| argument has type `Result<(), std::fmt::Error>`
|
||||||
|
|
|
||||||
|
note: the lint level is defined here
|
||||||
|
--> $DIR/dropping_copy_types-macros.rs:4:9
|
||||||
|
|
|
||||||
|
LL | #![deny(dropping_copy_types)]
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^
|
||||||
|
help: use `let _ = ...` to ignore the expression or result
|
||||||
|
|
|
||||||
|
LL - drop(writeln!(&mut msg, "test"));
|
||||||
|
LL + let _ = writeln!(&mut msg, "test");
|
||||||
|
|
|
||||||
|
|
||||||
|
error: aborting due to 1 previous error
|
||||||
|
|
Loading…
Reference in New Issue
Block a user