about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorMatthias Krüger <476013+matthiaskrgr@users.noreply.github.com>2025-04-09 20:23:12 +0200
committerGitHub <noreply@github.com>2025-04-09 20:23:12 +0200
commite962e52725b65afcb23b3f305a5090da8d7f3bb8 (patch)
tree58e90ca25393be7e740e32e4294bd0f452242af5 /tests
parenta8b0d56f6f6b9c953d5d70e1133dd509fc8fe316 (diff)
parent6d71fc15d8983960745bf2f61ab74ca272f0585f (diff)
downloadrust-e962e52725b65afcb23b3f305a5090da8d7f3bb8.tar.gz
rust-e962e52725b65afcb23b3f305a5090da8d7f3bb8.zip
Rollup merge of #139551 - jogru0:121672, r=oli-obk
report call site of inlined scopes for large assignment lints

Addressed issue: #121672
Tracking issue: #83518

r? `@oli-obk`

I tried to follow your comment about what to do [here](https://github.com/rust-lang/rust/issues/121672#issuecomment-1972783675). However, I'm totally unfamiliar with the code so far (this is my first contribution touching compiler code), so I apologize in advance if I did something stupid :sweat_smile:

In particular, I'm not sure I use the _correct_ source scope to look for inline data, as there is a whole `IndexVec` of them. My changes definitely did something, as can be seen by the added ui test. However, the result is not as anticipated in the issue:
```
LL |     let cell = std::cell::UnsafeCell::new(data);
   |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ value moved from here
```
instead of
```
LL |     let cell = std::cell::UnsafeCell::new(data);
   |                                           ^^^^ value moved from here
```
raising my suspicion that maybe I got the wrong source scope.
Diffstat (limited to 'tests')
-rw-r--r--tests/ui/lint/large_assignments/inline_mir.rs24
-rw-r--r--tests/ui/lint/large_assignments/inline_mir.stderr15
2 files changed, 39 insertions, 0 deletions
diff --git a/tests/ui/lint/large_assignments/inline_mir.rs b/tests/ui/lint/large_assignments/inline_mir.rs
new file mode 100644
index 00000000000..fc27b8ff244
--- /dev/null
+++ b/tests/ui/lint/large_assignments/inline_mir.rs
@@ -0,0 +1,24 @@
+#![feature(large_assignments)]
+#![deny(large_assignments)]
+#![move_size_limit = "1000"]
+
+//! Tests that with `-Zinline-mir`, we do NOT get an error that points to the
+//! implementation of `UnsafeCell` since that is not actionable by the user:
+//!
+//! ```text
+//! error: moving 9999 bytes
+//!   --> /rustc/FAKE_PREFIX/library/core/src/cell.rs:2054:9
+//!    |
+//!    = note: value moved from here
+//! ```
+//!
+//! We want the diagnostics to point to the relevant user code.
+
+//@ build-fail
+//@ compile-flags: -Zmir-opt-level=1 -Zinline-mir
+
+pub fn main() {
+    let data = [10u8; 9999];
+    let cell = std::cell::UnsafeCell::new(data); //~ ERROR large_assignments
+    std::hint::black_box(cell);
+}
diff --git a/tests/ui/lint/large_assignments/inline_mir.stderr b/tests/ui/lint/large_assignments/inline_mir.stderr
new file mode 100644
index 00000000000..d9010e24d03
--- /dev/null
+++ b/tests/ui/lint/large_assignments/inline_mir.stderr
@@ -0,0 +1,15 @@
+error: moving 9999 bytes
+  --> $DIR/inline_mir.rs:22:16
+   |
+LL |     let cell = std::cell::UnsafeCell::new(data);
+   |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 lint level is defined here
+  --> $DIR/inline_mir.rs:2:9
+   |
+LL | #![deny(large_assignments)]
+   |         ^^^^^^^^^^^^^^^^^
+
+error: aborting due to 1 previous error
+