summaryrefslogtreecommitdiffstats
path: root/src/test/ui/wf/wf-misc-methods-issue-28609.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/ui/wf/wf-misc-methods-issue-28609.rs')
-rw-r--r--src/test/ui/wf/wf-misc-methods-issue-28609.rs74
1 files changed, 74 insertions, 0 deletions
diff --git a/src/test/ui/wf/wf-misc-methods-issue-28609.rs b/src/test/ui/wf/wf-misc-methods-issue-28609.rs
new file mode 100644
index 000000000..050f866e1
--- /dev/null
+++ b/src/test/ui/wf/wf-misc-methods-issue-28609.rs
@@ -0,0 +1,74 @@
+// check that misc. method calls are well-formed
+
+use std::marker::PhantomData;
+use std::ops::{Deref, Shl};
+
+#[derive(Copy, Clone)]
+struct S<'a, 'b: 'a> {
+ marker: PhantomData<&'a &'b ()>,
+ bomb: Option<&'b u32>
+}
+
+type S2<'a> = S<'a, 'a>;
+
+impl<'a, 'b> S<'a, 'b> {
+ fn transmute_inherent(&self, a: &'b u32) -> &'a u32 {
+ a
+ }
+}
+
+fn return_dangling_pointer_inherent(s: S2) -> &u32 {
+ let s = s;
+ s.transmute_inherent(&mut 42) //~ ERROR cannot return value referencing temporary value
+}
+
+impl<'a, 'b> Deref for S<'a, 'b> {
+ type Target = &'a u32;
+ fn deref(&self) -> &&'a u32 {
+ self.bomb.as_ref().unwrap()
+ }
+}
+
+fn return_dangling_pointer_coerce(s: S2) -> &u32 {
+ let four = 4;
+ let mut s = s;
+ s.bomb = Some(&four);
+ &s //~ ERROR cannot return value referencing local variable `four`
+}
+
+fn return_dangling_pointer_unary_op(s: S2) -> &u32 {
+ let four = 4;
+ let mut s = s;
+ s.bomb = Some(&four);
+ &*s //~ ERROR cannot return value referencing local variable `four`
+}
+
+impl<'a, 'b> Shl<&'b u32> for S<'a, 'b> {
+ type Output = &'a u32;
+ fn shl(self, t: &'b u32) -> &'a u32 { t }
+}
+
+fn return_dangling_pointer_binary_op(s: S2) -> &u32 {
+ let s = s;
+ s << &mut 3 //~ ERROR cannot return value referencing temporary value
+}
+
+fn return_dangling_pointer_method(s: S2) -> &u32 {
+ let s = s;
+ s.shl(&mut 3) //~ ERROR cannot return value referencing temporary value
+}
+
+fn return_dangling_pointer_ufcs(s: S2) -> &u32 {
+ let s = s;
+ S2::shl(s, &mut 3) //~ ERROR cannot return value referencing temporary value
+}
+
+fn main() {
+ let s = S { marker: PhantomData, bomb: None };
+ let _inherent_dp = return_dangling_pointer_inherent(s);
+ let _coerce_dp = return_dangling_pointer_coerce(s);
+ let _unary_dp = return_dangling_pointer_unary_op(s);
+ let _binary_dp = return_dangling_pointer_binary_op(s);
+ let _method_dp = return_dangling_pointer_method(s);
+ let _ufcs_dp = return_dangling_pointer_ufcs(s);
+}