Uh oh!
There was an error while loading. Please reload this page.
Implement Error for TryReserveError - #69792
Conversation
| @@ -77,6 +78,22 @@ impl From<LayoutErr> for TryReserveError { | |||
| } | |||
There was a problem hiding this comment.
Maybe it's possible to return the LayoutErr as cause and source of the TryReserveError when passed here, although it would make the struct bigger.
Uh oh!
There was an error while loading. Please reload this page.
| TryReserveError::CapacityOverflow => { | ||
| " because the computed capacity exceeded the collection's maximum" | ||
| } | ||
| TryReserveError::AllocError { .. } => " because the memory allocator returned a error", |
There was a problem hiding this comment.
I do dislike that this isn't formatted consistently, but rustfmt formatted it this way.
There was a problem hiding this comment.
The cleaner approach would be to move the match out of the write_str call and just assign the string to a variable IMO.
There was a problem hiding this comment.
It doesn't help with the formatting though, rustfmt transforms this:
#[unstable(feature = "try_reserve", reason = "new API", issue = "48043")]implDisplayforTryReserveError{fnfmt(&self,fmt:&mut core::fmt::Formatter<'_>,) -> core::result::Result<(), core::fmt::Error>{
fmt.write_str("memory allocation failed")?;let reason = match&self{TryReserveError::CapacityOverflow => " because the computed capacity exceeded the collection's maximum",TryReserveError::AllocError{ .. } => {" because the memory allocator returned a error"}};
fmt.write_str(reason)}}Into this:
#[unstable(feature = "try_reserve", reason = "new API", issue = "48043")]implDisplayforTryReserveError{fnfmt(&self,fmt:&mut core::fmt::Formatter<'_>,) -> core::result::Result<(), core::fmt::Error>{
fmt.write_str("memory allocation failed")?;let reason = match&self{TryReserveError::CapacityOverflow => {" because the computed capacity exceeded the collection's maximum"}TryReserveError::AllocError{ .. } => " because the memory allocator returned a error",};
fmt.write_str(reason)}}There was a problem hiding this comment.
I tried to submit code in which both statements used braces, but that makes one of the checks fail.
There was a problem hiding this comment.
I think it's fine now, btw, it's a really minor issue.
Uh oh!
There was an error while loading. Please reload this page.
rust-highfive
commented
Mar 11, 2020
The job Click to expand the log.I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
sfackler
commented
Mar 12, 2020
@bors r+ rollup |
bors
commented
Mar 12, 2020
📌 Commit 2c90a37 has been approved by |
Rollup of 10 pull requests Successful merges: - #68899 (Add Display and Error impls for proc_macro::LexError) - #69011 (Document unsafe blocks in core::fmt) - #69674 (Rename DefKind::Method and TraitItemKind::Method ) - #69705 (Toolstate: remove redundant beta-week check.) - #69722 (Tweak output for invalid negative impl AST errors) - #69747 (Rename rustc guide) - #69792 (Implement Error for TryReserveError) - #69830 (miri: ICE on invalid terminators) - #69921 (rustdoc: remove unused import) - #69945 (update outdated comment) Failed merges: r? @ghost
I noticed that the Error trait wasn't implemented for TryReserveError. (#48043)
Not sure if the error messages and code style are 100% correct, it's my first time contributing to the Rust std.