File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments