-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #103386 - compiler-errors:no-coerceunsized-to-dynstar…
…, r=eholk Don't allow `CoerceUnsized` into `dyn*` (except for trait upcasting) This makes sure we don't accidentally allow coercions like `Box<T>` -> `Box<dyn* Trait>`, or in the case of this ICE, `&T` to `&dyn* Trait`. These coercions don't make sense, at least not via the `CoerceUnsized` trait. Fixes #102172 Fixes #102429
- Loading branch information
Showing
5 changed files
with
53 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// check-pass | ||
|
||
#![feature(dyn_star)] | ||
#![allow(incomplete_features)] | ||
|
||
trait AddOne { | ||
fn add1(&mut self) -> usize; | ||
} | ||
|
||
impl AddOne for usize { | ||
fn add1(&mut self) -> usize { | ||
*self += 1; | ||
*self | ||
} | ||
} | ||
|
||
fn add_one(i: &mut (dyn* AddOne + '_)) -> usize { | ||
i.add1() | ||
} | ||
|
||
fn main() { | ||
let mut x = 42usize as dyn* AddOne; | ||
|
||
println!("{}", add_one(&mut x)); | ||
println!("{}", add_one(&mut x)); | ||
} |
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,9 @@ | ||
#![feature(dyn_star)] | ||
#![allow(incomplete_features)] | ||
|
||
use std::fmt::Debug; | ||
|
||
fn main() { | ||
let i = 42 as &dyn* Debug; | ||
//~^ ERROR non-primitive cast: `i32` as `&dyn* Debug` | ||
} |
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,9 @@ | ||
error[E0605]: non-primitive cast: `i32` as `&dyn* Debug` | ||
--> $DIR/unsize-into-ref-dyn-star.rs:7:13 | ||
| | ||
LL | let i = 42 as &dyn* Debug; | ||
| ^^^^^^^^^^^^^^^^^ an `as` expression can only be used to convert between primitive types or to coerce to a specific trait object | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0605`. |