Skip to content
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

split_at_mut should #[track_caller] #83378

Closed
ruza-net opened this issue Mar 22, 2021 · 4 comments
Closed

split_at_mut should #[track_caller] #83378

ruza-net opened this issue Mar 22, 2021 · 4 comments
Labels
C-bug Category: This is a bug. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@ruza-net
Copy link

ruza-net commented Mar 22, 2021

When split_at_mut is called with mid > len, an internal assertion fails. However, it doesn't track its caller, so RUST_BACKTRACE=1 is required to determine the call site.

I tried this code:

fn main() {
    let mut x = [1];
    
    x.split_at_mut(2);
}

I expected to see this happen:

An error of the form thread 'main' panicked at 'split index (is 2) should be <= len (is 1)'.

Instead, this happened:

thread 'main' panicked at 'assertion failed: mid <= self.len()', /rustc/cb75ad5db02783e8b0222fee363c5f63f7e2cf5b/library/core/src/slice/mod.rs:1279:9

Meta

This occurs on stable (1.50.0), beta (1.51.0-beta.8) and nightly (1.53.0-nightly 2021-03-21).

Tested on playground.

@ruza-net ruza-net added the C-bug Category: This is a bug. label Mar 22, 2021
@jyn514
Copy link
Member

jyn514 commented Mar 22, 2021

@ruza-net are you interested in adding this yourself? It should be pretty simple :) just add it to library/core/src/slice/mod.rs like it says in the panic.

@jyn514 jyn514 added the T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. label Mar 22, 2021
@Rustin170506
Copy link
Member

@rustbot claim

I would like to try this.

@slightlyoutofphase
Copy link
Contributor

slightlyoutofphase commented Mar 23, 2021

I think you need to alter the actual assertion to produce formatted output to truly get what you stated as "expected" though, don't you? Something like this:

let len = self.len();
assert!(
    mid <= len,
    "split index (is {}) should be <= len (is {}))",
    mid,
    len
);

All #[track_caller] alone will do is make the existing assertion print out like this: thread 'main' panicked at 'assertion failed: mid <= self.len()', src/your_file.rs:line:column.

@Rustin170506 Rustin170506 removed their assignment Jul 20, 2021
@Nugine
Copy link
Contributor

Nugine commented Nov 11, 2022

This issue has been solved by

@jyn514 jyn514 closed this as completed Nov 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants