Skip to content

Commit df6254f

Browse files
committed
report call site of inlined scopes for large assignment lints
1 parent f820b75 commit df6254f

File tree

3 files changed

+56
-3
lines changed

3 files changed

+56
-3
lines changed

Diff for: compiler/rustc_monomorphize/src/mono_checks/move_check.rs

+17-3
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,27 @@ impl<'tcx> MoveCheckVisitor<'tcx> {
162162
// but correct span? This would make the lint at least accept crate-level lint attributes.
163163
return;
164164
};
165+
166+
// If the source scope is inlined by the MIR inliner, report the lint on the call site.
167+
let reported_span = self
168+
.body
169+
.source_scopes
170+
.get(source_info.scope)
171+
.and_then(|source_scope_data| source_scope_data.inlined)
172+
.map(|(_, call_site)| call_site)
173+
.unwrap_or(span);
174+
165175
self.tcx.emit_node_span_lint(
166176
LARGE_ASSIGNMENTS,
167177
lint_root,
168-
span,
169-
LargeAssignmentsLint { span, size: too_large_size.bytes(), limit: limit as u64 },
178+
reported_span,
179+
LargeAssignmentsLint {
180+
span: reported_span,
181+
size: too_large_size.bytes(),
182+
limit: limit as u64,
183+
},
170184
);
171-
self.move_size_spans.push(span);
185+
self.move_size_spans.push(reported_span);
172186
}
173187
}
174188

Diff for: tests/ui/lint/large_assignments/inline_mir.rs

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#![feature(large_assignments)]
2+
#![deny(large_assignments)]
3+
#![move_size_limit = "1000"]
4+
5+
//! Tests that with `-Zinline-mir`, we do NOT get an error that points to the
6+
//! implementation of `UnsafeCell` since that is not actionable by the user:
7+
//!
8+
//! ```text
9+
//! error: moving 9999 bytes
10+
//! --> /rustc/FAKE_PREFIX/library/core/src/cell.rs:2054:9
11+
//! |
12+
//! = note: value moved from here
13+
//! ```
14+
//!
15+
//! We want the diagnostics to point to the relevant user code.
16+
17+
//@ build-fail
18+
//@ compile-flags: -Zmir-opt-level=1 -Zinline-mir
19+
20+
pub fn main() {
21+
let data = [10u8; 9999];
22+
let cell = std::cell::UnsafeCell::new(data); //~ ERROR large_assignments
23+
std::hint::black_box(cell);
24+
}

Diff for: tests/ui/lint/large_assignments/inline_mir.stderr

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error: moving 9999 bytes
2+
--> $DIR/inline_mir.rs:22:16
3+
|
4+
LL | let cell = std::cell::UnsafeCell::new(data);
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ value moved from here
6+
|
7+
= note: The current maximum size is 1000, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]`
8+
note: the lint level is defined here
9+
--> $DIR/inline_mir.rs:2:9
10+
|
11+
LL | #![deny(large_assignments)]
12+
| ^^^^^^^^^^^^^^^^^
13+
14+
error: aborting due to 1 previous error
15+

0 commit comments

Comments
 (0)