rust/tests/ui/issues/issue-11740.rs
许杰友 Jieyou Xu (Joe) edafbaffb2
Adjust UI tests for unit_bindings
- Either explicitly annotate `let x: () = expr;` where `x` has unit
  type, or remove the unit binding to leave only `expr;` instead.
- Fix disjoint-capture-in-same-closure test
2023-06-12 20:24:48 +08:00

29 lines
559 B
Rust

// check-pass
// revisions: mir thir
// [thir]compile-flags: -Zthir-unsafeck
struct Attr {
name: String,
value: String,
}
struct Element {
attrs: Vec<Box<Attr>>,
}
impl Element {
pub unsafe fn get_attr<'a>(&'a self, name: &str) {
self.attrs
.iter()
.find(|attr| {
let attr: &&Box<Attr> = std::mem::transmute(attr);
true
});
}
}
fn main() {
let element = Element { attrs: Vec::new() };
unsafe { let () = element.get_attr("foo"); };
}