Skip to content

Commit dc82736

Browse files
committed
Avoid duplicate large_assignments lints
By checking for overlapping spans.
1 parent 1f56ff8 commit dc82736

File tree

4 files changed

+14
-22
lines changed

4 files changed

+14
-22
lines changed

compiler/rustc_monomorphize/src/collector.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,8 @@ struct MirUsedCollector<'a, 'tcx> {
590590
body: &'a mir::Body<'tcx>,
591591
output: &'a mut MonoItems<'tcx>,
592592
instance: Instance<'tcx>,
593+
/// Spans for move size lints already emitted. Helps avoid duplicate lints.
594+
move_size_spans: Vec<Span>,
593595
}
594596

595597
impl<'a, 'tcx> MirUsedCollector<'a, 'tcx> {
@@ -616,6 +618,11 @@ impl<'a, 'tcx> MirUsedCollector<'a, 'tcx> {
616618
debug!(?layout);
617619
let source_info = self.body.source_info(location);
618620
debug!(?source_info);
621+
for span in &self.move_size_spans {
622+
if span.overlaps(source_info.span) {
623+
return;
624+
}
625+
}
619626
let lint_root = source_info.scope.lint_root(&self.body.source_scopes);
620627
debug!(?lint_root);
621628
let Some(lint_root) = lint_root else {
@@ -636,6 +643,7 @@ impl<'a, 'tcx> MirUsedCollector<'a, 'tcx> {
636643
limit: limit.bytes(),
637644
},
638645
);
646+
self.move_size_spans.push(source_info.span);
639647
}
640648
}
641649

@@ -1373,7 +1381,8 @@ fn collect_used_items<'tcx>(
13731381
output: &mut MonoItems<'tcx>,
13741382
) {
13751383
let body = tcx.instance_mir(instance.def);
1376-
MirUsedCollector { tcx, body: &body, output, instance }.visit_body(&body);
1384+
MirUsedCollector { tcx, body: &body, output, instance, move_size_spans: vec![] }
1385+
.visit_body(&body);
13771386
}
13781387

13791388
#[instrument(skip(tcx, output), level = "debug")]

tests/ui/async-await/large_moves.attribute.stderr

+2-10
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,12 @@ LL | #![deny(large_assignments)]
1212
| ^^^^^^^^^^^^^^^^^
1313

1414
error: moving 10024 bytes
15-
--> $DIR/large_moves.rs:19:13
16-
|
17-
LL | let z = (x, 42);
18-
| ^^^^^^^ value moved from here
19-
|
20-
= note: The current maximum size is 1000, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]`
21-
22-
error: moving 10024 bytes
23-
--> $DIR/large_moves.rs:21:13
15+
--> $DIR/large_moves.rs:20:13
2416
|
2517
LL | let a = z.0;
2618
| ^^^ value moved from here
2719
|
2820
= note: The current maximum size is 1000, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]`
2921

30-
error: aborting due to 3 previous errors
22+
error: aborting due to 2 previous errors
3123

tests/ui/async-await/large_moves.option.stderr

+2-10
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,12 @@ LL | #![deny(large_assignments)]
1212
| ^^^^^^^^^^^^^^^^^
1313

1414
error: moving 10024 bytes
15-
--> $DIR/large_moves.rs:19:13
16-
|
17-
LL | let z = (x, 42);
18-
| ^^^^^^^ value moved from here
19-
|
20-
= note: The current maximum size is 1000, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]`
21-
22-
error: moving 10024 bytes
23-
--> $DIR/large_moves.rs:21:13
15+
--> $DIR/large_moves.rs:20:13
2416
|
2517
LL | let a = z.0;
2618
| ^^^ value moved from here
2719
|
2820
= note: The current maximum size is 1000, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]`
2921

30-
error: aborting due to 3 previous errors
22+
error: aborting due to 2 previous errors
3123

tests/ui/async-await/large_moves.rs

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ fn main() {
1717
dbg!(y);
1818
};
1919
let z = (x, 42); //~ ERROR large_assignments
20-
//~^ ERROR large_assignments
2120
let a = z.0; //~ ERROR large_assignments
2221
let b = z.1;
2322
}

0 commit comments

Comments
 (0)