Skip to content

Improve panic messages and add #[track_caller] attribute to functions that may panic - #367

Merged
cuviper merged 2 commits into
indexmap-rs:masterfrom
savannstm:better-panics
Jan 20, 2025
Merged

cuviper merged 2 commits into
indexmap-rs:masterfrom
savannstm:better-panics

Conversation

@savannstm

Copy link
Copy Markdown
Contributor

Currently, indexmap panic messages aren't really helpful, and this PR adds #[track_caller] attributes to functions that may panic, for better understanding where to actually look for the panic, and uses the same panic messages that standard collections do with more details.
Seems like #[track_caller] is compatible with no_std, and it shouldn't break anything.

@cuviper cuviper left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like a good idea, thanks!

Comment thread src/map.rs
@@ -1325,7 +1346,7 @@ where
///
/// ***Panics*** if `key` is not present in the map.
fn index(&self, key: &Q) -> &V {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just clarifying for future reference -- our Index and IndexMut implementations don't need #[track_caller] because the trait definition already applies it.

@cuviper
cuviper added this pull request to the merge queue Jan 20, 2025
Merged via the queue into indexmap-rs:master with commit f0ec924 Jan 20, 2025
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.

2 participants