-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Underscore binding does not warn about lifetime violation #68502
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
Comments
Another example: fn foo() {
struct NoCopy;
let x = NoCopy;
drop(x);
let _ = x;
} with the MIR: fn foo() -> () {
let mut _0: (); // return place in scope 0 at src/lib.rs:1:10: 1:10
let _1: foo::NoCopy; // "x" in scope 0 at src/lib.rs:3:9: 3:10
let _2: (); // in scope 0 at src/lib.rs:4:5: 4:12
let mut _3: foo::NoCopy; // in scope 0 at src/lib.rs:4:10: 4:11
scope 1 {
scope 2 {
}
}
bb0: {
StorageLive(_1); // bb0[0]: scope 0 at src/lib.rs:3:9: 3:10
StorageLive(_2); // bb0[1]: scope 1 at src/lib.rs:4:5: 4:12
StorageLive(_3); // bb0[2]: scope 1 at src/lib.rs:4:10: 4:11
_3 = move _1; // bb0[3]: scope 1 at src/lib.rs:4:10: 4:11
_2 = const std::mem::drop::<foo::NoCopy>(move _3) -> bb1; // bb0[4]: scope 1 at src/lib.rs:4:5: 4:12
// ty::Const
// + ty: fn(foo::NoCopy) {std::mem::drop::<foo::NoCopy>}
// + val: Scalar(<ZST>)
// mir::Constant
// + span: src/lib.rs:4:5: 4:9
// + literal: Const { ty: fn(foo::NoCopy) {std::mem::drop::<foo::NoCopy>}, val: Scalar(<ZST>) }
}
bb1: {
StorageDead(_3); // bb1[0]: scope 1 at src/lib.rs:4:11: 4:12
StorageDead(_2); // bb1[1]: scope 1 at src/lib.rs:4:12: 4:13
StorageDead(_1); // bb1[2]: scope 0 at src/lib.rs:6:1: 6:2
return; // bb1[3]: scope 0 at src/lib.rs:6:2: 6:2
}
} Compare this with if you had added bb1: {
StorageDead(_3); // bb1[0]: scope 1 at src/lib.rs:5:11: 5:12
StorageDead(_2); // bb1[1]: scope 1 at src/lib.rs:5:12: 5:13
StorageLive(_4); // bb1[2]: scope 1 at src/lib.rs:6:9: 6:10
_4 = _1; // bb1[3]: scope 1 at src/lib.rs:6:13: 6:14
StorageDead(_4); // bb1[4]: scope 1 at src/lib.rs:7:1: 7:2
StorageDead(_1); // bb1[5]: scope 0 at src/lib.rs:7:1: 7:2
return; // bb1[6]: scope 0 at src/lib.rs:7:2: 7:2
} As you can see, in the first MIR output, there is no So yes, this is by design. |
Ah, interesting, I suppose this ties in with the discussion back in #10488, where the conclusion was that |
This code, as expected, fails to compile:
with
But this code compiles just fine:
even though
y
is "used" after its referent has been dropped. Is this expected behavior?The text was updated successfully, but these errors were encountered: