about summary refs log tree commit diff
diff options
context:
space:
mode:
authorwhtahy <whtahy@users.noreply.github.com>2023-04-22 13:57:34 -0400
committerwhtahy <whtahy@users.noreply.github.com>2023-04-22 13:57:34 -0400
commitebe61cefc4fa30f0a719892d544abcaee25da44c (patch)
tree88bc72cd91a9d971e4b9f35147e37e506908c50a
parent6f6550f156eb6ea18e90db1712b30460613ad4a8 (diff)
downloadrust-ebe61cefc4fa30f0a719892d544abcaee25da44c.tar.gz
rust-ebe61cefc4fa30f0a719892d544abcaee25da44c.zip
add known-bug test for unsound issue 104005
-rw-r--r--tests/ui/wf/wf-in-fn-type-implicit.rs37
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/ui/wf/wf-in-fn-type-implicit.rs b/tests/ui/wf/wf-in-fn-type-implicit.rs
new file mode 100644
index 00000000000..c5ff92c8875
--- /dev/null
+++ b/tests/ui/wf/wf-in-fn-type-implicit.rs
@@ -0,0 +1,37 @@
+// check-pass
+// known-bug: #104005
+
+// Should fail. Function type parameters with implicit type annotations are not
+// checked for well-formedness, which allows incorrect borrowing.
+
+// In contrast, user annotations are always checked for well-formedness, and the
+// commented code below is correctly rejected by the borrow checker.
+
+use std::fmt::Display;
+
+trait Displayable {
+    fn display(self) -> Box<dyn Display>;
+}
+
+impl<T: Display> Displayable for (T, Option<&'static T>) {
+    fn display(self) -> Box<dyn Display> {
+        Box::new(self.0)
+    }
+}
+
+fn extend_lt<T, U>(val: T) -> Box<dyn Display>
+where
+    (T, Option<U>): Displayable,
+{
+    Displayable::display((val, None))
+}
+
+fn main() {
+    // *incorrectly* compiles
+    let val = extend_lt(&String::from("blah blah blah"));
+    println!("{}", val);
+
+    // *correctly* fails to compile
+    // let val = extend_lt::<_, &_>(&String::from("blah blah blah"));
+    // println!("{}", val);
+}