1 // check that misc. method calls are well-formed
3 use std::marker::PhantomData;
4 use std::ops::{Deref, Shl};
8 marker: PhantomData<&'a &'b ()>,
12 type S2<'a> = S<'a, 'a>;
14 impl<'a, 'b> S<'a, 'b> {
15 fn transmute_inherent(&self, a: &'b u32) -> &'a u32 {
20 fn return_dangling_pointer_inherent(s: S2) -> &u32 {
22 s.transmute_inherent(&mut 42) //~ ERROR cannot return value referencing temporary value
25 impl<'a, 'b> Deref for S<'a, 'b> {
26 type Target = &'a u32;
27 fn deref(&self) -> &&'a u32 {
28 self.bomb.as_ref().unwrap()
32 fn return_dangling_pointer_coerce(s: S2) -> &u32 {
36 &s //~ ERROR cannot return value referencing local variable `four`
39 fn return_dangling_pointer_unary_op(s: S2) -> &u32 {
43 &*s //~ ERROR cannot return value referencing local variable `four`
46 impl<'a, 'b> Shl<&'b u32> for S<'a, 'b> {
47 type Output = &'a u32;
48 fn shl(self, t: &'b u32) -> &'a u32 { t }
51 fn return_dangling_pointer_binary_op(s: S2) -> &u32 {
53 s << &mut 3 //~ ERROR cannot return value referencing temporary value
56 fn return_dangling_pointer_method(s: S2) -> &u32 {
58 s.shl(&mut 3) //~ ERROR cannot return value referencing temporary value
61 fn return_dangling_pointer_ufcs(s: S2) -> &u32 {
63 S2::shl(s, &mut 3) //~ ERROR cannot return value referencing temporary value
67 let s = S { marker: PhantomData, bomb: None };
68 let _inherent_dp = return_dangling_pointer_inherent(s);
69 let _coerce_dp = return_dangling_pointer_coerce(s);
70 let _unary_dp = return_dangling_pointer_unary_op(s);
71 let _binary_dp = return_dangling_pointer_binary_op(s);
72 let _method_dp = return_dangling_pointer_method(s);
73 let _ufcs_dp = return_dangling_pointer_ufcs(s);