Skip to content

Commit ebe61ce

Browse files
committed
add known-bug test for unsound issue 104005
1 parent 6f6550f commit ebe61ce

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

tests/ui/wf/wf-in-fn-type-implicit.rs

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// check-pass
2+
// known-bug: #104005
3+
4+
// Should fail. Function type parameters with implicit type annotations are not
5+
// checked for well-formedness, which allows incorrect borrowing.
6+
7+
// In contrast, user annotations are always checked for well-formedness, and the
8+
// commented code below is correctly rejected by the borrow checker.
9+
10+
use std::fmt::Display;
11+
12+
trait Displayable {
13+
fn display(self) -> Box<dyn Display>;
14+
}
15+
16+
impl<T: Display> Displayable for (T, Option<&'static T>) {
17+
fn display(self) -> Box<dyn Display> {
18+
Box::new(self.0)
19+
}
20+
}
21+
22+
fn extend_lt<T, U>(val: T) -> Box<dyn Display>
23+
where
24+
(T, Option<U>): Displayable,
25+
{
26+
Displayable::display((val, None))
27+
}
28+
29+
fn main() {
30+
// *incorrectly* compiles
31+
let val = extend_lt(&String::from("blah blah blah"));
32+
println!("{}", val);
33+
34+
// *correctly* fails to compile
35+
// let val = extend_lt::<_, &_>(&String::from("blah blah blah"));
36+
// println!("{}", val);
37+
}

0 commit comments

Comments
 (0)