-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Improve ManuallyDrop suggestion #90901
Conversation
r? @jackh726 (rust-highfive has picked a reviewer for you, use r? to override) |
r? @estebank |
let (field_span, ty_span) = | ||
// We are currently checking the type this field came from, so it must be local. | ||
if let Node::Field(field) = tcx.hir().get_if_local(field.did).unwrap() { | ||
(field.span, field.ty.span) | ||
} else { | ||
unreachable!("mir field has to correspond to hir field"); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let (field_span, ty_span) = | |
// We are currently checking the type this field came from, so it must be local. | |
if let Node::Field(field) = tcx.hir().get_if_local(field.did).unwrap() { | |
(field.span, field.ty.span) | |
} else { | |
unreachable!("mir field has to correspond to hir field"); | |
}; | |
let (field_span, ty_span) = match tcx.hir().get_if_local(field.did) { | |
// We are currently checking the type this field came from, so it must be local. | |
Some(Node::Field(field)) => (field.span, field.ty.span), | |
_ => unreachable!("mir field has to correspond to hir field"), | |
}; |
.span_note(field_span, "`std::mem::ManuallyDrop` can be used to wrap the type") | ||
.multipart_suggestion_verbose( | ||
"wrap the type with `std::mem::ManuallyDrop` and ensure it is manually dropped", | ||
vec![(ty_span, format!("std::mem::ManuallyDrop<{}>", field_ty))], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
vec![(ty_span, format!("std::mem::ManuallyDrop<{}>", field_ty))], | |
vec![ | |
(ty_span.shrink_to_lo(), "std::mem::ManuallyDrop<".to_string()), | |
(ty_span.shrink_to_hi(), ">".to_string()), | |
], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh thats clever!
This is ready for rereview |
@bors r+ |
📌 Commit 62acf7f has been approved by |
…estebank Improve ManuallyDrop suggestion closes rust-lang#90585 * Fixes the recommended change to use ManuallyDrop as per the issue * Changes the note to a help * improves the span so it only points at the type.
…askrgr Rollup of 8 pull requests Successful merges: - rust-lang#89610 (warn on must_use use on async fn's) - rust-lang#90667 (Improve diagnostics when a static lifetime is expected) - rust-lang#90687 (Permit const panics in stable const contexts in stdlib) - rust-lang#90772 (Add Vec::retain_mut) - rust-lang#90861 (Print escaped string if char literal has multiple characters, but only one printable character) - rust-lang#90884 (Fix span for non-satisfied trivial trait bounds) - rust-lang#90900 (Remove workaround for the forward progress handling in LLVM) - rust-lang#90901 (Improve ManuallyDrop suggestion) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
closes #90585