Address nits, add test for implicit dyn-star coercion without feature gate
This commit is contained in:
parent
0cb217d29b
commit
8c7e836abb
6 changed files with 50 additions and 3 deletions
|
@ -270,8 +270,11 @@ pub fn cast_to_dyn_star<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
|
||||||
dst_ty: Ty<'tcx>,
|
dst_ty: Ty<'tcx>,
|
||||||
old_info: Option<Bx::Value>,
|
old_info: Option<Bx::Value>,
|
||||||
) -> (Bx::Value, Bx::Value) {
|
) -> (Bx::Value, Bx::Value) {
|
||||||
debug!("unsize_ptr: {:?} => {:?}", src_ty_and_layout.ty, dst_ty);
|
debug!("cast_to_dyn_star: {:?} => {:?}", src_ty_and_layout.ty, dst_ty);
|
||||||
assert!(matches!(dst_ty.kind(), ty::Dynamic(_, _, ty::DynStar)));
|
assert!(
|
||||||
|
matches!(dst_ty.kind(), ty::Dynamic(_, _, ty::DynStar)),
|
||||||
|
"destination type must be a dyn*"
|
||||||
|
);
|
||||||
// FIXME(dyn-star): this is probably not the best way to check if this is
|
// FIXME(dyn-star): this is probably not the best way to check if this is
|
||||||
// a pointer, and really we should ensure that the value is a suitable
|
// a pointer, and really we should ensure that the value is a suitable
|
||||||
// pointer earlier in the compilation process.
|
// pointer earlier in the compilation process.
|
||||||
|
|
|
@ -777,6 +777,8 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check the obligations of the cast -- for example, when casting
|
||||||
|
// `usize` to `dyn* Clone + 'static`:
|
||||||
let obligations = predicates
|
let obligations = predicates
|
||||||
.iter()
|
.iter()
|
||||||
.map(|predicate| {
|
.map(|predicate| {
|
||||||
|
@ -787,7 +789,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
|
||||||
let predicate = predicate.with_self_ty(self.tcx, a);
|
let predicate = predicate.with_self_ty(self.tcx, a);
|
||||||
Obligation::new(self.cause.clone(), self.param_env, predicate)
|
Obligation::new(self.cause.clone(), self.param_env, predicate)
|
||||||
})
|
})
|
||||||
// Enforce the region bound `'static` (e.g., `usize: 'static`, in our example).
|
// Enforce the region bound (e.g., `usize: 'static`, in our example).
|
||||||
.chain([Obligation::new(
|
.chain([Obligation::new(
|
||||||
self.cause.clone(),
|
self.cause.clone(),
|
||||||
self.param_env,
|
self.param_env,
|
||||||
|
|
10
src/test/ui/dyn-star/auxiliary/dyn-star-foreign.rs
Normal file
10
src/test/ui/dyn-star/auxiliary/dyn-star-foreign.rs
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
#![feature(dyn_star)]
|
||||||
|
#![allow(incomplete_features)]
|
||||||
|
|
||||||
|
use std::fmt::Display;
|
||||||
|
|
||||||
|
pub fn require_dyn_star_display(_: dyn* Display) {}
|
||||||
|
|
||||||
|
fn works_locally() {
|
||||||
|
require_dyn_star_display(1usize);
|
||||||
|
}
|
|
@ -8,6 +8,11 @@ fn make_dyn_star(i: usize) {
|
||||||
let _dyn_i: dyn* Debug = i;
|
let _dyn_i: dyn* Debug = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn make_dyn_star_explicit(i: usize) {
|
||||||
|
let _dyn_i: dyn* Debug = i as dyn* Debug;
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
make_dyn_star(42);
|
make_dyn_star(42);
|
||||||
|
make_dyn_star_explicit(42);
|
||||||
}
|
}
|
||||||
|
|
8
src/test/ui/dyn-star/no-implicit-dyn-star.rs
Normal file
8
src/test/ui/dyn-star/no-implicit-dyn-star.rs
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
// aux-build:dyn-star-foreign.rs
|
||||||
|
|
||||||
|
extern crate dyn_star_foreign;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
dyn_star_foreign::require_dyn_star_display(1usize);
|
||||||
|
//~^ ERROR mismatched types
|
||||||
|
}
|
19
src/test/ui/dyn-star/no-implicit-dyn-star.stderr
Normal file
19
src/test/ui/dyn-star/no-implicit-dyn-star.stderr
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
error[E0308]: mismatched types
|
||||||
|
--> $DIR/no-implicit-dyn-star.rs:6:48
|
||||||
|
|
|
||||||
|
LL | dyn_star_foreign::require_dyn_star_display(1usize);
|
||||||
|
| ------------------------------------------ ^^^^^^ expected trait object `dyn std::fmt::Display`, found `usize`
|
||||||
|
| |
|
||||||
|
| arguments to this function are incorrect
|
||||||
|
|
|
||||||
|
= note: expected trait object `(dyn* std::fmt::Display + 'static)`
|
||||||
|
found type `usize`
|
||||||
|
note: function defined here
|
||||||
|
--> $DIR/auxiliary/dyn-star-foreign.rs:6:8
|
||||||
|
|
|
||||||
|
LL | pub fn require_dyn_star_display(_: dyn* Display) {}
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0308`.
|
Loading…
Add table
Add a link
Reference in a new issue