]> git.lizzy.rs Git - rust.git/blob - src/test/ui/span/wf-method-late-bound-regions.rs
Rollup merge of #87922 - Manishearth:c-enum-target-spec, r=nagisa,eddyb
[rust.git] / src / test / ui / span / wf-method-late-bound-regions.rs
1 // A method's receiver must be well-formed, even if it has late-bound regions.
2 // Because of this, a method's substs being well-formed does not imply that
3 // the method's implied bounds are met.
4
5 struct Foo<'b>(Option<&'b ()>);
6
7 trait Bar<'b> {
8     fn xmute<'a>(&'a self, u: &'b u32) -> &'a u32;
9 }
10
11 impl<'b> Bar<'b> for Foo<'b> {
12     fn xmute<'a>(&'a self, u: &'b u32) -> &'a u32 { u }
13 }
14
15 fn main() {
16     let f = Foo(None);
17     let f2 = f;
18     let dangling = {
19         let pointer = Box::new(42);
20         f2.xmute(&pointer)
21     };
22     //~^^ ERROR `pointer` does not live long enough
23     println!("{}", dangling);
24 }