Avoid duplicate large_assignments
lints
By checking for overlapping spans.
This commit is contained in:
parent
1f56ff8f26
commit
dc82736677
4 changed files with 14 additions and 22 deletions
|
@ -590,6 +590,8 @@ struct MirUsedCollector<'a, 'tcx> {
|
||||||
body: &'a mir::Body<'tcx>,
|
body: &'a mir::Body<'tcx>,
|
||||||
output: &'a mut MonoItems<'tcx>,
|
output: &'a mut MonoItems<'tcx>,
|
||||||
instance: Instance<'tcx>,
|
instance: Instance<'tcx>,
|
||||||
|
/// Spans for move size lints already emitted. Helps avoid duplicate lints.
|
||||||
|
move_size_spans: Vec<Span>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'tcx> MirUsedCollector<'a, 'tcx> {
|
impl<'a, 'tcx> MirUsedCollector<'a, 'tcx> {
|
||||||
|
@ -616,6 +618,11 @@ impl<'a, 'tcx> MirUsedCollector<'a, 'tcx> {
|
||||||
debug!(?layout);
|
debug!(?layout);
|
||||||
let source_info = self.body.source_info(location);
|
let source_info = self.body.source_info(location);
|
||||||
debug!(?source_info);
|
debug!(?source_info);
|
||||||
|
for span in &self.move_size_spans {
|
||||||
|
if span.overlaps(source_info.span) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
let lint_root = source_info.scope.lint_root(&self.body.source_scopes);
|
let lint_root = source_info.scope.lint_root(&self.body.source_scopes);
|
||||||
debug!(?lint_root);
|
debug!(?lint_root);
|
||||||
let Some(lint_root) = lint_root else {
|
let Some(lint_root) = lint_root else {
|
||||||
|
@ -636,6 +643,7 @@ impl<'a, 'tcx> MirUsedCollector<'a, 'tcx> {
|
||||||
limit: limit.bytes(),
|
limit: limit.bytes(),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
self.move_size_spans.push(source_info.span);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1373,7 +1381,8 @@ fn collect_used_items<'tcx>(
|
||||||
output: &mut MonoItems<'tcx>,
|
output: &mut MonoItems<'tcx>,
|
||||||
) {
|
) {
|
||||||
let body = tcx.instance_mir(instance.def);
|
let body = tcx.instance_mir(instance.def);
|
||||||
MirUsedCollector { tcx, body: &body, output, instance }.visit_body(&body);
|
MirUsedCollector { tcx, body: &body, output, instance, move_size_spans: vec![] }
|
||||||
|
.visit_body(&body);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[instrument(skip(tcx, output), level = "debug")]
|
#[instrument(skip(tcx, output), level = "debug")]
|
||||||
|
|
|
@ -12,20 +12,12 @@ LL | #![deny(large_assignments)]
|
||||||
| ^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: moving 10024 bytes
|
error: moving 10024 bytes
|
||||||
--> $DIR/large_moves.rs:19:13
|
--> $DIR/large_moves.rs:20:13
|
||||||
|
|
|
||||||
LL | let z = (x, 42);
|
|
||||||
| ^^^^^^^ value moved from here
|
|
||||||
|
|
|
||||||
= note: The current maximum size is 1000, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]`
|
|
||||||
|
|
||||||
error: moving 10024 bytes
|
|
||||||
--> $DIR/large_moves.rs:21:13
|
|
||||||
|
|
|
|
||||||
LL | let a = z.0;
|
LL | let a = z.0;
|
||||||
| ^^^ value moved from here
|
| ^^^ value moved from here
|
||||||
|
|
|
|
||||||
= note: The current maximum size is 1000, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]`
|
= note: The current maximum size is 1000, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]`
|
||||||
|
|
||||||
error: aborting due to 3 previous errors
|
error: aborting due to 2 previous errors
|
||||||
|
|
||||||
|
|
|
@ -12,20 +12,12 @@ LL | #![deny(large_assignments)]
|
||||||
| ^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: moving 10024 bytes
|
error: moving 10024 bytes
|
||||||
--> $DIR/large_moves.rs:19:13
|
--> $DIR/large_moves.rs:20:13
|
||||||
|
|
|
||||||
LL | let z = (x, 42);
|
|
||||||
| ^^^^^^^ value moved from here
|
|
||||||
|
|
|
||||||
= note: The current maximum size is 1000, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]`
|
|
||||||
|
|
||||||
error: moving 10024 bytes
|
|
||||||
--> $DIR/large_moves.rs:21:13
|
|
||||||
|
|
|
|
||||||
LL | let a = z.0;
|
LL | let a = z.0;
|
||||||
| ^^^ value moved from here
|
| ^^^ value moved from here
|
||||||
|
|
|
|
||||||
= note: The current maximum size is 1000, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]`
|
= note: The current maximum size is 1000, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]`
|
||||||
|
|
||||||
error: aborting due to 3 previous errors
|
error: aborting due to 2 previous errors
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,6 @@ fn main() {
|
||||||
dbg!(y);
|
dbg!(y);
|
||||||
};
|
};
|
||||||
let z = (x, 42); //~ ERROR large_assignments
|
let z = (x, 42); //~ ERROR large_assignments
|
||||||
//~^ ERROR large_assignments
|
|
||||||
let a = z.0; //~ ERROR large_assignments
|
let a = z.0; //~ ERROR large_assignments
|
||||||
let b = z.1;
|
let b = z.1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue