Skip to content

Commit f6a07d1

Browse files
committed
Auto merge of rust-lang#101212 - eholk:dyn-star, r=compiler-errors
Initial implementation of dyn* This PR adds extremely basic and incomplete support for [dyn*](https://smallcultfollowing.com/babysteps//blog/2022/03/29/dyn-can-we-make-dyn-sized/). The goal is to get something in tree behind a flag to make collaboration easier, and also to make sure the implementation so far is not unreasonable. This PR does quite a few things: * Introduce `dyn_star` feature flag * Adds parsing for `dyn* Trait` types * Defines `dyn* Trait` as a sized type * Adds support for explicit casts, like `42usize as dyn* Debug` * Including const evaluation of such casts * Adds codegen for drop glue so things are cleaned up properly when a `dyn* Trait` object goes out of scope * Adds codegen for method calls, at least for methods that take `&self` Quite a bit is still missing, but this gives us a starting point. Note that this is never intended to become stable surface syntax for Rust, but rather `dyn*` is planned to be used as an implementation detail for async functions in dyn traits. Joint work with `@nikomatsakis` and `@compiler-errors.` r? `@bjorn3`
2 parents cf043f6 + 27e91b6 commit f6a07d1

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

clippy_lints/src/transmute/utils.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use rustc_hir::Expr;
22
use rustc_lint::LateContext;
33
use rustc_middle::ty::{cast::CastKind, Ty};
44
use rustc_span::DUMMY_SP;
5-
use rustc_typeck::check::{cast::CastCheck, FnCtxt, Inherited};
5+
use rustc_typeck::check::{cast::{self, CastCheckResult}, FnCtxt, Inherited};
66

77
// check if the component types of the transmuted collection and the result have different ABI,
88
// size or alignment
@@ -53,7 +53,7 @@ fn check_cast<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>, from_ty: Ty<'tcx>
5353
"Newly created FnCtxt contained errors"
5454
);
5555

56-
if let Ok(check) = CastCheck::new(
56+
if let CastCheckResult::Deferred(check) = cast::check_cast(
5757
&fn_ctxt, e, from_ty, to_ty,
5858
// We won't show any error to the user, so we don't care what the span is here.
5959
DUMMY_SP, DUMMY_SP,

clippy_utils/src/qualify_min_const_fn.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ fn check_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, span: Span) -> McfResult {
8282
ty::FnPtr(..) => {
8383
return Err((span, "function pointers in const fn are unstable".into()));
8484
},
85-
ty::Dynamic(preds, _) => {
85+
ty::Dynamic(preds, _, _) => {
8686
for pred in preds.iter() {
8787
match pred.skip_binder() {
8888
ty::ExistentialPredicate::AutoTrait(_) | ty::ExistentialPredicate::Projection(_) => {
@@ -161,6 +161,10 @@ fn check_rvalue<'tcx>(
161161
Rvalue::Cast(CastKind::PointerExposeAddress, _, _) => {
162162
Err((span, "casting pointers to ints is unstable in const fn".into()))
163163
},
164+
Rvalue::Cast(CastKind::DynStar, _, _) => {
165+
// FIXME(dyn-star)
166+
unimplemented!()
167+
},
164168
// binops are fine on integers
165169
Rvalue::BinaryOp(_, box (lhs, rhs)) | Rvalue::CheckedBinaryOp(_, box (lhs, rhs)) => {
166170
check_operand(tcx, lhs, span, body)?;
@@ -221,7 +225,6 @@ fn check_statement<'tcx>(
221225
check_operand(tcx, src, span, body)?;
222226
check_operand(tcx, count, span, body)
223227
},
224-
225228
// These are all NOPs
226229
StatementKind::StorageLive(_)
227230
| StatementKind::StorageDead(_)

clippy_utils/src/ty.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool {
201201
}
202202
false
203203
},
204-
ty::Dynamic(binder, _) => {
204+
ty::Dynamic(binder, _, _) => {
205205
for predicate in binder.iter() {
206206
if let ty::ExistentialPredicate::Trait(ref trait_ref) = predicate.skip_binder() {
207207
if cx.tcx.has_attr(trait_ref.def_id, sym::must_use) {
@@ -579,7 +579,7 @@ pub fn ty_sig<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option<ExprFnSig<'t
579579
ty::FnDef(id, subs) => Some(ExprFnSig::Sig(cx.tcx.bound_fn_sig(id).subst(cx.tcx, subs), Some(id))),
580580
ty::Opaque(id, _) => sig_from_bounds(cx, ty, cx.tcx.item_bounds(id), cx.tcx.opt_parent(id)),
581581
ty::FnPtr(sig) => Some(ExprFnSig::Sig(sig, None)),
582-
ty::Dynamic(bounds, _) => {
582+
ty::Dynamic(bounds, _, _) => {
583583
let lang_items = cx.tcx.lang_items();
584584
match bounds.principal() {
585585
Some(bound)

0 commit comments

Comments
 (0)