-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Pedantic lint: unhandled_must_use #13997
Comments
Note that other solutions exist for the problem you expose. For example, you might want to put a flag inside your structure (or wrap it in another one along that uses As a general remark, if this lint ever exists, it should belong to |
Making this a runtime panic wouldn't be preferred or even viable IMO. It means any missed uses go from stalls (lack of progress over the database) to full crashes. I appreciate the note though. I suggested this for pedantic as I thought pedantic was for explicit opt-in lints which don't make sense to enable as a class due to highly specific/contradictory lints. Apologies if I was in error there. |
I understand. For info, the various categories are detailed here. From what I've seen in many projects, |
While further researching solutions, I noted this topic apparently has had discussion before re: linear types (potentially making this of wider value): https://faultlore.com/blah/linear-rust/#the-checker https://jack.wrenn.fyi/blog/undroppable suggests having the struct Undroppable<T>(T);
impl<T> Drop for Undroppable<T> {
fn drop(&mut self) {
const {
assert!(false);
}
}
}
struct MyStruct;
fn main() {
let x = Undroppable(MyStruct);
let branch = core::hint::black_box(true);
if branch {
core::mem::forget(x);
} else {
core::mem::forget(x);
}
} Setting the inner value of I write this here for the sake of completeness. |
What it does
For the above snippet,
must_use
will not be emitted as a warning because the variable binding is considered usage. The proposed lint would consider any boundmust_use
types at the termination of scope unused. The above example includes the edge-case where the scope has multiple points of potential termination and the binding is used at one location but not the other.I will note this may be hard to implement on any
must_use
type which also implementsCopy
. This either needs to not trigger onmust_use
+Copy
, ignoring that class of types, or determine if the variable was copied, and if so, only continue evaluation for the copies' bindings (if any exist).Alternative name suggestions for the lint welcome. in_scope_must_use? unmoved_must_use?
Advantage
DbTxn
type I have. I once lost days of developer time because I forgot to callcommit
, despite themust_use
present. I would like my clippy to error if I ever don't callcommit
or explicitlydrop
anyDbTxn
.Drawbacks
Example
Could be written as:
The text was updated successfully, but these errors were encountered: