Skip to content

Commit cf04547

Browse files
committed
Address code review comments
1 parent de42ac3 commit cf04547

File tree

27 files changed

+199
-261
lines changed

27 files changed

+199
-261
lines changed

compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ use rustc_session::lint::builtin::{
1919
DEPRECATED_WHERE_CLAUSE_LOCATION, MISSING_ABI, PATTERNS_IN_FNS_WITHOUT_BODY,
2020
};
2121
use rustc_session::lint::{BuiltinLintDiagnostics, LintBuffer};
22-
use rustc_session::parse::feature_err;
2322
use rustc_session::Session;
2423
use rustc_span::source_map::Spanned;
2524
use rustc_span::symbol::{kw, sym, Ident};
@@ -754,19 +753,7 @@ impl<'a> AstValidator<'a> {
754753
self.maybe_lint_missing_abi(sig_span, ty.id);
755754
}
756755
}
757-
TyKind::TraitObject(ref bounds, syntax, ..) => {
758-
if syntax == TraitObjectSyntax::DynStar
759-
&& !self.session.features_untracked().dyn_star
760-
{
761-
feature_err(
762-
&self.session.parse_sess,
763-
sym::dyn_star,
764-
ty.span,
765-
"dyn* trait objects are unstable",
766-
)
767-
.emit();
768-
}
769-
756+
TyKind::TraitObject(ref bounds, ..) => {
770757
let mut any_lifetime_bounds = false;
771758
for bound in bounds {
772759
if let GenericBound::Outlives(ref lifetime) = *bound {

compiler/rustc_ast_passes/src/feature_gate.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,9 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
573573
ast::TyKind::Never => {
574574
gate_feature_post!(&self, never_type, ty.span, "the `!` type is experimental");
575575
}
576+
ast::TyKind::TraitObject(_, ast::TraitObjectSyntax::DynStar, ..) => {
577+
gate_feature_post!(&self, dyn_star, ty.span, "dyn* trait objects are unstable");
578+
}
576579
_ => {}
577580
}
578581
visit::walk_ty(self, ty)

compiler/rustc_codegen_cranelift/src/value_and_place.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -816,6 +816,7 @@ pub(crate) fn assert_assignable<'tcx>(
816816
// fn(&T) -> for<'l> fn(&'l T) is allowed
817817
}
818818
(&ty::Dynamic(from_traits, _, _from_kind), &ty::Dynamic(to_traits, _, _to_kind)) => {
819+
// FIXME(dyn-star): Do the right thing with DynKinds
819820
for (from, to) in from_traits.iter().zip(to_traits) {
820821
let from =
821822
fx.tcx.normalize_erasing_late_bound_regions(ParamEnv::reveal_all(), from);

compiler/rustc_codegen_ssa/src/mir/block.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
367367
bx.ret(llval);
368368
}
369369

370-
#[tracing::instrument(level = "debug", skip(self, helper, bx))]
370+
#[tracing::instrument(level = "trace", skip(self, helper, bx))]
371371
fn codegen_drop_terminator(
372372
&mut self,
373373
helper: TerminatorCodegenHelper<'tcx>,

compiler/rustc_const_eval/src/interpret/cast.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,10 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
113113
if let ty::Dynamic(data, _, ty::DynStar) = cast_ty.kind() {
114114
// Initial cast from sized to dyn trait
115115
let vtable = self.get_vtable_ptr(src.layout.ty, data.principal())?;
116-
let ptr = self.read_immediate(src)?.to_scalar();
117-
// FIXME(dyn-star): This should not use new_dyn_trait, but
118-
// it does exactly the same thing (makes a scalar pair)...
119-
// so maybe we should just duplicate/rename the function.
120-
let val = Immediate::new_dyn_trait(ptr, vtable, &*self.tcx);
116+
let vtable = Scalar::from_maybe_pointer(vtable, self);
117+
let data = self.read_immediate(src)?.to_scalar();
118+
let _assert_pointer_sized = data.to_pointer(self)?;
119+
let val = Immediate::ScalarPair(data, vtable);
121120
self.write_immediate(val, dest)?;
122121
} else {
123122
bug!()
@@ -327,7 +326,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
327326
let new_vptr = self.get_vtable_ptr(ty, data_b.principal())?;
328327
self.write_immediate(Immediate::new_dyn_trait(old_data, new_vptr, self), dest)
329328
}
330-
(_, &ty::Dynamic(ref data, _, _repr)) => {
329+
(_, &ty::Dynamic(ref data, _, ty::Dyn)) => {
331330
// Initial cast from sized to dyn trait
332331
let vtable = self.get_vtable_ptr(src_pointee_ty, data.principal())?;
333332
let ptr = self.read_scalar(src)?;

compiler/rustc_const_eval/src/transform/validate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
570570
}
571571
}
572572
CastKind::DynStar => {
573-
// FIXME: make sure nothing needs to be done here.
573+
// FIXME(dyn-star): make sure nothing needs to be done here.
574574
}
575575
// Nothing to check here
576576
CastKind::PointerFromExposedAddress

compiler/rustc_feature/src/active.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ declare_features! (
381381
/// Allows `#[doc(masked)]`.
382382
(active, doc_masked, "1.21.0", Some(44027), None),
383383
/// Allows `dyn* Trait` objects.
384-
(active, dyn_star, "1.65.0", Some(91611), None),
384+
(incomplete, dyn_star, "CURRENT_RUSTC_VERSION", Some(91611), None),
385385
/// Allows `X..Y` patterns.
386386
(active, exclusive_range_pattern, "1.11.0", Some(37854), None),
387387
/// Allows exhaustive pattern matching on types that contain uninhabited types.

compiler/rustc_middle/src/ty/layout.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -626,11 +626,11 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
626626
}
627627

628628
ty::Dynamic(_, _, ty::DynStar) => {
629-
let mut pointer = scalar_unit(Int(dl.ptr_sized_integer(), false));
630-
pointer.valid_range_mut().start = 1;
629+
let mut data = scalar_unit(Int(dl.ptr_sized_integer(), false));
630+
data.valid_range_mut().start = 0;
631631
let mut vtable = scalar_unit(Pointer);
632632
vtable.valid_range_mut().start = 1;
633-
tcx.intern_layout(self.scalar_pair(pointer, vtable))
633+
tcx.intern_layout(self.scalar_pair(data, vtable))
634634
}
635635

636636
// Arrays and slices.
@@ -2474,8 +2474,7 @@ where
24742474

24752475
match tcx.struct_tail_erasing_lifetimes(pointee, cx.param_env()).kind() {
24762476
ty::Slice(_) | ty::Str => TyMaybeWithLayout::Ty(tcx.types.usize),
2477-
// FIXME(eholk): Do the right thing with trait object representation
2478-
ty::Dynamic(_, _, _repr) => {
2477+
ty::Dynamic(_, _, ty::Dyn) => {
24792478
TyMaybeWithLayout::Ty(tcx.mk_imm_ref(
24802479
tcx.lifetimes.re_static,
24812480
tcx.mk_array(tcx.types.usize, 3),
@@ -3379,7 +3378,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
33793378
Ok(self.tcx.arena.alloc(fn_abi))
33803379
}
33813380

3382-
#[tracing::instrument(level = "debug", skip(self))]
3381+
#[tracing::instrument(level = "trace", skip(self))]
33833382
fn fn_abi_adjust_for_abi(
33843383
&self,
33853384
fn_abi: &mut FnAbi<'tcx, Ty<'tcx>>,

compiler/rustc_monomorphize/src/collector.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,9 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
699699
// This could also be a different Unsize instruction, like
700700
// from a fixed sized array to a slice. But we are only
701701
// interested in things that produce a vtable.
702-
if (target_ty.is_trait() || target_ty.is_dyn_star()) && !source_ty.is_trait() {
702+
if (target_ty.is_trait() && !source_ty.is_trait())
703+
|| (target_ty.is_dyn_star() && !source_ty.is_dyn_star())
704+
{
703705
create_mono_items_for_vtable_methods(
704706
self.tcx,
705707
target_ty,

compiler/rustc_parse/src/parser/ty.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -579,9 +579,7 @@ impl<'a> Parser<'a> {
579579
self.bump(); // `dyn`
580580

581581
// parse dyn* types
582-
let dyn_star = matches!(self.token.kind, TokenKind::BinOp(token::Star));
583-
let syntax = if dyn_star {
584-
self.bump(); // `*`
582+
let syntax = if self.eat(&TokenKind::BinOp(token::Star)) {
585583
TraitObjectSyntax::DynStar
586584
} else {
587585
TraitObjectSyntax::Dyn

0 commit comments

Comments
 (0)