Skip to content

Improve slice indexing assertion #29984

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

Merged
merged 2 commits into from
Nov 23, 2015
Merged

Conversation

Manishearth
Copy link
Member

I'd like to have the message print out the index and length values like it does elsewhere, but I'm not sure how to do that without affecting perf here. Will assert!(cond, "index out of bounds got {} but len is ", idx, len) make things slower? It calls panic_fmt which is marked as cold but also calls format_args!, and I don't know if that allocates or does any heavy lifting.

cc @alexcrichton @gankro

@rust-highfive
Copy link
Contributor

r? @alexcrichton

(rust_highfive has picked a reviewer for you, use r? to override)

@bluss
Copy link
Member

bluss commented Nov 22, 2015

str uses a separate function to put the formatting there

@alexcrichton
Copy link
Member

Yeah I think the str strategy would be appropriate here for some good messages. There's no concern really about performance here, LLVM typically does the correct thing, but it could accidentally be easy to inflate code sizes with lots of fancy asserts.

If, however, a concrete function in libcore were provided (e.g. not generic), then it could be as fancy as it wants!

@Manishearth
Copy link
Member Author

That should be marked cold, right?

@Gankra
Copy link
Contributor

Gankra commented Nov 23, 2015

@Manishearth might as well.

@Manishearth Manishearth force-pushed the slice-assert branch 2 times, most recently from cae8692 to a1ff4b4 Compare November 23, 2015 04:08
@Manishearth
Copy link
Member Author

Updated. Error message could be improved.

@Manishearth Manishearth mentioned this pull request Nov 23, 2015
@alexcrichton
Copy link
Member

@bors: r+ 5c873be

@bors
Copy link
Collaborator

bors commented Nov 23, 2015

⌛ Testing commit 5c873be with merge 4891c00...

bors added a commit that referenced this pull request Nov 23, 2015
I'd like to have the message print out the index and length values like it does elsewhere, but I'm not sure how to do that without affecting perf here. Will `assert!(cond, "index out of bounds got {} but len is ", idx, len)` make things slower? It calls `panic_fmt` which is marked as cold but also calls `format_args!`, and I don't know if that allocates or does any heavy lifting.

cc @alexcrichton @gankro
@bors bors merged commit 5c873be into rust-lang:master Nov 23, 2015
@Manishearth Manishearth deleted the slice-assert branch December 2, 2016 19:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants