05e3248a79
This can break code that looked like: impl Foo for Box<Any> { fn f(&self) { ... } } let x: Box<Any + Send> = ...; x.f(); Change such code to: impl Foo for Box<Any> { fn f(&self) { ... } } let x: Box<Any> = ...; x.f(); That is, upcast before calling methods. This is a conservative solution to #5781. A more proper treatment (see the xfail'd `trait-contravariant-self.rs`) would take variance into account. This change fixes the soundness hole. Some library changes had to be made to make this work. In particular, `Box<Any>` is no longer showable, and only `Box<Any+Send>` is showable. Eventually, this restriction can be lifted; for now, it does not prove too onerous, because `Any` is only used for propagating the result of task failure. This patch also adds a test for the variance inference work in #12828, which accidentally landed as part of DST. Closes #5781. [breaking-change]
31 lines
864 B
Rust
31 lines
864 B
Rust
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
|
|
// file at the top-level directory of this distribution and at
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
// option. This file may not be copied, modified, or distributed
|
|
// except according to those terms.
|
|
|
|
// Issue #5781. Tests that subtyping is handled properly in trait matching.
|
|
|
|
trait Make<'a> {
|
|
fn make(x: &'a mut int) -> Self;
|
|
}
|
|
|
|
impl<'a> Make<'a> for &'a mut int {
|
|
fn make(x: &'a mut int) -> &'a mut int {
|
|
x
|
|
}
|
|
}
|
|
|
|
fn f() -> &'static mut int {
|
|
let mut x = 1;
|
|
let y: &'static mut int = Make::make(&mut x); //~ ERROR `x` does not live long enough
|
|
y
|
|
}
|
|
|
|
fn main() {}
|
|
|