-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #56219 - arielb1:never-coerce-box, r=nikomatsakis
trigger unsized coercions keyed on Sized bounds This PR causes unsized coercions to not be disabled by `$0: Unsize<dyn Object>` coercion obligations when we have an `$0: Sized` obligation somewhere. This should be mostly backwards-compatible, because in these cases not doing the unsize coercion should have caused the `$0: Sized` obligation to fail. Note that `X: Unsize<dyn Object>` obligations can't fail *as obligations* if `X: Sized` holds, so this still maintains some version of monotonicity (I think that an unsized coercion can't be converted to no coercion by unifying type variables). Fixes #49593 (unblocking never_type). r? @eddyb cc @nikomatsakis
- Loading branch information
Showing
5 changed files
with
172 additions
and
65 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
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
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
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
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,62 @@ | ||
// Copyright 2018 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. | ||
|
||
// compile-pass | ||
|
||
#![feature(never_type)] | ||
#![allow(unreachable_code)] | ||
|
||
use std::error::Error; | ||
use std::mem; | ||
|
||
fn raw_ptr_box<T>(t: T) -> *mut T { | ||
panic!() | ||
} | ||
|
||
fn foo(x: !) -> Box<dyn Error> { | ||
/* *mut $0 is coerced to Box<dyn Error> here */ Box::<_ /* ! */>::new(x) | ||
} | ||
|
||
fn foo_raw_ptr(x: !) -> *mut dyn Error { | ||
/* *mut $0 is coerced to *mut Error here */ raw_ptr_box::<_ /* ! */>(x) | ||
} | ||
|
||
fn no_coercion(d: *mut dyn Error) -> *mut dyn Error { | ||
/* an unsize coercion won't compile here, and it is indeed not used | ||
because there is nothing requiring the _ to be Sized */ | ||
d as *mut _ | ||
} | ||
|
||
trait Xyz {} | ||
struct S; | ||
struct T; | ||
impl Xyz for S {} | ||
impl Xyz for T {} | ||
|
||
fn foo_no_never() { | ||
let mut x /* : Option<S> */ = None; | ||
let mut first_iter = false; | ||
loop { | ||
if !first_iter { | ||
let y: Box<dyn Xyz> | ||
= /* Box<$0> is coerced to Box<Xyz> here */ Box::new(x.unwrap()); | ||
} | ||
|
||
x = Some(S); | ||
first_iter = true; | ||
} | ||
|
||
let mut y : Option<S> = None; | ||
// assert types are equal | ||
mem::swap(&mut x, &mut y); | ||
} | ||
|
||
fn main() { | ||
} |