Closed
Description
This unsound program shouldn't compile, but it does: https://play.rust-lang.org/?version=stable&mode=debug&edition=2015&gist=2e0af084bc8b2ec9f440a2c5dab7992f
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() {
// The type parameter `U = &'static &'temporary str` is ill-formed
// because it does not enforce `'temporary: 'static` ...
let val = extend_lt(&String::from("blah blah blah"));
println!("{}", val);
}
I was shocked discovering that. I thought WellFormed(U)
is part of the caller bounds of extend_lt
.
@rustbot label C-bug T-types I-unsound A-lifetimes
Metadata
Metadata
Assignees
Labels
Area: Lifetimes / regionsCategory: This is a bug.Issue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessHigh priorityStatus: This bug is tracked inside the repo by a `known-bug` test.Relevant to the types team, which will review and decide on the PR/issue.Performance or correctness regression from one stable version to another.