2020-02-29 03:56:37 +00:00
|
|
|
// Issue #53114: NLL's borrow check had some deviations from the old borrow
|
|
|
|
// checker, and both had some deviations from our ideal state. This test
|
2020-03-05 18:52:10 +00:00
|
|
|
// captures the behavior of how `_` bindings are handled with respect to how we
|
2020-02-29 03:56:37 +00:00
|
|
|
// flag expressions that are meant to request unsafe blocks.
|
|
|
|
|
2022-06-30 02:33:18 +00:00
|
|
|
#[derive(Copy, Clone)]
|
2020-02-29 03:56:37 +00:00
|
|
|
struct I(i64);
|
2022-06-30 02:33:18 +00:00
|
|
|
#[derive(Copy, Clone)]
|
2020-02-29 03:56:37 +00:00
|
|
|
struct F(f64);
|
|
|
|
|
|
|
|
union U { a: I, b: F }
|
|
|
|
|
|
|
|
#[repr(packed)]
|
|
|
|
struct P {
|
|
|
|
a: &'static i8,
|
|
|
|
b: &'static u32,
|
|
|
|
}
|
|
|
|
|
|
|
|
fn let_wild_gets_unsafe_field() {
|
|
|
|
let u1 = U { a: I(0) };
|
|
|
|
let u2 = U { a: I(1) };
|
|
|
|
let p = P { a: &2, b: &3 };
|
2022-03-27 16:42:19 +00:00
|
|
|
let _ = &p.b; //~ ERROR reference to packed field
|
2022-09-06 16:41:01 +00:00
|
|
|
let _ = u1.a; //~ ERROR [E0133]
|
2020-02-29 03:56:37 +00:00
|
|
|
let _ = &u2.a; //~ ERROR [E0133]
|
|
|
|
|
|
|
|
// variation on above with `_` in substructure
|
2022-03-27 16:42:19 +00:00
|
|
|
let (_,) = (&p.b,); //~ ERROR reference to packed field
|
2020-02-29 03:56:37 +00:00
|
|
|
let (_,) = (u1.a,); //~ ERROR [E0133]
|
|
|
|
let (_,) = (&u2.a,); //~ ERROR [E0133]
|
|
|
|
}
|
|
|
|
|
2022-10-18 18:41:14 +00:00
|
|
|
fn let_ascribe_gets_unsafe_field() {
|
|
|
|
let u1 = U { a: I(0) };
|
|
|
|
let u2 = U { a: I(1) };
|
|
|
|
let p = P { a: &2, b: &3 };
|
|
|
|
let _: _ = &p.b; //~ ERROR reference to packed field
|
|
|
|
let _: _ = u1.a; //~ ERROR [E0133]
|
|
|
|
let _: _ = &u2.a; //~ ERROR [E0133]
|
|
|
|
|
|
|
|
// variation on above with `_` in substructure
|
|
|
|
let (_,): _ = (&p.b,); //~ ERROR reference to packed field
|
|
|
|
let (_,): _ = (u1.a,); //~ ERROR [E0133]
|
|
|
|
let (_,): _ = (&u2.a,); //~ ERROR [E0133]
|
|
|
|
}
|
|
|
|
|
2020-02-29 03:56:37 +00:00
|
|
|
fn match_unsafe_field_to_wild() {
|
|
|
|
let u1 = U { a: I(0) };
|
|
|
|
let u2 = U { a: I(1) };
|
|
|
|
let p = P { a: &2, b: &3 };
|
2022-03-27 16:42:19 +00:00
|
|
|
match &p.b { _ => { } } //~ ERROR reference to packed field
|
2020-02-29 03:56:37 +00:00
|
|
|
match u1.a { _ => { } } //~ ERROR [E0133]
|
|
|
|
match &u2.a { _ => { } } //~ ERROR [E0133]
|
|
|
|
|
|
|
|
// variation on above with `_` in substructure
|
2022-03-27 16:42:19 +00:00
|
|
|
match (&p.b,) { (_,) => { } } //~ ERROR reference to packed field
|
2020-02-29 03:56:37 +00:00
|
|
|
match (u1.a,) { (_,) => { } } //~ ERROR [E0133]
|
|
|
|
match (&u2.a,) { (_,) => { } } //~ ERROR [E0133]
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() { }
|