Skip to content

Add #[track_caller] to slice::copy_from_slice #78900

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
daniel5151 opened this issue Nov 9, 2020 · 2 comments
Closed

Add #[track_caller] to slice::copy_from_slice #78900

daniel5151 opened this issue Nov 9, 2020 · 2 comments
Labels
A-slice Area: `[T]` C-enhancement Category: An issue proposing an enhancement or a PR with one. F-track_caller `#![feature(track_caller)]`

Comments

@daniel5151
Copy link

daniel5151 commented Nov 9, 2020

In this trivial case:

fn main() {
    let mut buf = [0; 16];
    buf.copy_from_slice(&[1, 2, 3]);
}

The current panic message is: thread 'main' panicked at 'source slice length (3) does not match destination slice length (16)', /rustc/18bf6b4f01a6feaf7259ba7cdae58031af1b7b39/library/core/src/slice/mod.rs:2517:13

If #[track_caller] is added to slice::copy_from_slice, the panic message could instead be: thread 'main' panicked at 'source slice length (3) does not match destination slice length (16)', example/src/main.rs:3:9

On a related note, slice::clone_from_slice would also benefit from a #[track_caller] annotation as well.

Meta

rustc --version --verbose:

rustc 1.49.0-nightly (1eaadebb3 2020-10-21)
binary: rustc
commit-hash: 1eaadebb3dee31669c7649b32747381d11614fae
commit-date: 2020-10-21
host: x86_64-unknown-linux-gnu
release: 1.49.0-nightly
LLVM version: 11.0
Backtrace

stack backtrace:
   0: rust_begin_unwind
             at /rustc/18bf6b4f01a6feaf7259ba7cdae58031af1b7b39/library/std/src/panicking.rs:475
   1: core::panicking::panic_fmt
             at /rustc/18bf6b4f01a6feaf7259ba7cdae58031af1b7b39/library/core/src/panicking.rs:85
   2: core::slice::<impl [T]>::copy_from_slice::len_mismatch_fail
             at /rustc/18bf6b4f01a6feaf7259ba7cdae58031af1b7b39/library/core/src/slice/mod.rs:2510
   3: core::slice::<impl [T]>::copy_from_slice
             at /rustc/18bf6b4f01a6feaf7259ba7cdae58031af1b7b39/library/core/src/slice/mod.rs:2517
   4: playground::main
             at ./src/main.rs:3
   5: core::ops::function::FnOnce::call_once
             at /rustc/18bf6b4f01a6feaf7259ba7cdae58031af1b7b39/library/core/src/ops/function.rs:227

@daniel5151 daniel5151 added the C-bug Category: This is a bug. label Nov 9, 2020
@camelid camelid added C-enhancement Category: An issue proposing an enhancement or a PR with one. A-slice Area: `[T]` F-track_caller `#![feature(track_caller)]` and removed C-bug Category: This is a bug. labels Nov 9, 2020
@Nugine
Copy link
Contributor

Nugine commented Nov 10, 2022

This issue has been solved by

@daniel5151
Copy link
Author

Ah, so it has!

Well, as OP, I'll just go ahead and close the issue as resolved then :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-slice Area: `[T]` C-enhancement Category: An issue proposing an enhancement or a PR with one. F-track_caller `#![feature(track_caller)]`
Projects
None yet
Development

No branches or pull requests

3 participants