forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add known-bug test for unsound issue 104005
- Loading branch information
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |