-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Description
Clippy suggests changing working
to broken
, which changes behavior of the add_location function since it's now emitting a location in libcore rather than in my code. This probably deserves a comment in the code anyway so humans don't clean things up, but I don't want to write a comment and an allow.
Should be detectable if the function being called inside the closure is marked track_caller.
#[track_caller]
fn add_location(s: u32) -> String {
format!("{} @ {:?}", s, std::panic::Location::caller())
}
fn broken(r: Result<(), u32>) -> Result<(), String> {
// broken code, erases the caller location
r.map_err(add_location)
}
fn working(r: Result<(), u32>) -> Result<(), String> {
r.map_err(|e| add_location(e))
}
fn main() {
assert!(dbg!(broken(Err(0)).unwrap_err()).contains("core/src/ops/function.rs"));
assert!(dbg!(working(Err(0)).unwrap_err()).contains("src/main.rs"));
}
Metadata
Metadata
Assignees
Labels
No labels