Skip to content

Commit c0e02e2

Browse files
committed
Unimplement unsized_locals
1 parent 6c8138d commit c0e02e2

File tree

85 files changed

+458
-822
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+458
-822
lines changed

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -373,8 +373,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
373373
}
374374

375375
fn unsized_feature_enabled(&self) -> bool {
376-
let features = self.tcx().features();
377-
features.unsized_locals() || features.unsized_fn_params()
376+
self.tcx().features().unsized_fn_params()
378377
}
379378

380379
/// Equate the inferred type and the annotated type for user type annotations
@@ -957,7 +956,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
957956
}
958957
}
959958

960-
// When `unsized_fn_params` or `unsized_locals` is enabled, only function calls
959+
// When `unsized_fn_params` is enabled, only function calls
961960
// and nullary ops are checked in `check_call_dest`.
962961
if !self.unsized_feature_enabled() {
963962
match self.body.local_kind(local) {
@@ -1941,7 +1940,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
19411940
);
19421941
}
19431942

1944-
// When `unsized_fn_params` and `unsized_locals` are both not enabled,
1943+
// When `unsized_fn_params` is not enabled,
19451944
// this check is done at `check_local`.
19461945
if self.unsized_feature_enabled() {
19471946
let span = term.source_info.span;

compiler/rustc_codegen_cranelift/example/arbitrary_self_types_pointers_and_wrappers.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@ impl<T: CoerceUnsized<U>, U> CoerceUnsized<Wrapper<U>> for Wrapper<T> {}
3232
impl<T: DispatchFromDyn<U>, U> DispatchFromDyn<Wrapper<U>> for Wrapper<T> {}
3333

3434
trait Trait {
35-
// This method isn't object-safe yet. Unsized by-value `self` is object-safe (but not callable
36-
// without unsized_locals), but wrappers around `Self` currently are not.
37-
// FIXME (mikeyhew) uncomment this when unsized rvalues object-safety is implemented
38-
// fn wrapper(self: Wrapper<Self>) -> i32;
3935
fn ptr_wrapper(self: Ptr<Wrapper<Self>>) -> i32;
4036
fn wrapper_ptr(self: Wrapper<Ptr<Self>>) -> i32;
4137
fn wrapper_ptr_wrapper(self: Wrapper<Ptr<Wrapper<Self>>>) -> i32;

compiler/rustc_codegen_gcc/example/arbitrary_self_types_pointers_and_wrappers.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,6 @@ impl<T: DispatchFromDyn<U>, U> DispatchFromDyn<Wrapper<U>> for Wrapper<T> {}
3737

3838

3939
trait Trait {
40-
// This method isn't object-safe yet. Unsized by-value `self` is object-safe (but not callable
41-
// without unsized_locals), but wrappers around `Self` currently are not.
42-
// FIXME (mikeyhew) uncomment this when unsized rvalues object-safety is implemented
43-
// fn wrapper(self: Wrapper<Self>) -> i32;
4440
fn ptr_wrapper(self: Ptr<Wrapper<Self>>) -> i32;
4541
fn wrapper_ptr(self: Wrapper<Ptr<Self>>) -> i32;
4642
fn wrapper_ptr_wrapper(self: Wrapper<Ptr<Wrapper<Self>>>) -> i32;

compiler/rustc_feature/src/removed.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,8 @@ declare_features! (
263263
/// Allows unnamed fields of struct and union type
264264
(removed, unnamed_fields, "1.83.0", Some(49804), Some("feature needs redesign"), 131045),
265265
(removed, unsafe_no_drop_flag, "1.0.0", None, None),
266+
/// Allows unsized rvalues at arguments and parameters.
267+
(removed, unsized_locals, "CURRENT_RUSTC_VERSION", Some(48055), Some("removed due to implementation concerns; see https://github.com/rust-lang/rust/issues/111942")),
266268
(removed, unsized_tuple_coercion, "1.87.0", Some(42877),
267269
Some("The feature restricts possible layouts for tuples, and this restriction is not worth it."), 137728),
268270
/// Allows `union` fields that don't implement `Copy` as long as they don't have any drop glue.

compiler/rustc_feature/src/unstable.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -665,8 +665,6 @@ declare_features! (
665665
(incomplete, unsized_const_params, "1.82.0", Some(95174)),
666666
/// Allows unsized fn parameters.
667667
(internal, unsized_fn_params, "1.49.0", Some(48055)),
668-
/// Allows unsized rvalues at arguments and parameters.
669-
(incomplete, unsized_locals, "1.30.0", Some(48055)),
670668
/// Allows using the `#[used(linker)]` (or `#[used(compiler)]`) attribute.
671669
(unstable, used_with_arg, "1.60.0", Some(93798)),
672670
/// Allows use of attributes in `where` clauses.

compiler/rustc_hir_typeck/src/coercion.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1662,9 +1662,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
16621662
blk_id,
16631663
expression,
16641664
);
1665-
if !fcx.tcx.features().unsized_locals() {
1666-
unsized_return = self.is_return_ty_definitely_unsized(fcx);
1667-
}
1665+
unsized_return = self.is_return_ty_definitely_unsized(fcx);
16681666
}
16691667
ObligationCauseCode::ReturnValue(return_expr_id) => {
16701668
err = self.report_return_mismatched_types(
@@ -1676,9 +1674,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
16761674
return_expr_id,
16771675
expression,
16781676
);
1679-
if !fcx.tcx.features().unsized_locals() {
1680-
unsized_return = self.is_return_ty_definitely_unsized(fcx);
1681-
}
1677+
unsized_return = self.is_return_ty_definitely_unsized(fcx);
16821678
}
16831679
ObligationCauseCode::MatchExpressionArm(box MatchExpressionArmCause {
16841680
arm_span,

compiler/rustc_hir_typeck/src/expr.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -809,9 +809,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
809809
);
810810
}
811811
}
812-
// Here we want to prevent struct constructors from returning unsized types.
813-
// There were two cases this happened: fn pointer coercion in stable
814-
// and usual function call in presence of unsized_locals.
812+
// Here we want to prevent struct constructors from returning unsized types,
813+
// which can happen with fn pointer coercion on stable.
815814
// Also, as we just want to check sizedness, instead of introducing
816815
// placeholder lifetimes with probing, we just replace higher lifetimes
817816
// with fresh vars.

compiler/rustc_hir_typeck/src/gather_locals.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ impl<'a, 'tcx> Visitor<'tcx> for GatherLocalsVisitor<'a, 'tcx> {
202202
),
203203
);
204204
}
205-
} else if !self.fcx.tcx.features().unsized_locals() {
205+
} else {
206206
self.fcx.require_type_is_sized(
207207
var_ty,
208208
p.span,

compiler/rustc_hir_typeck/src/upvar.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
492492
let final_upvar_tys = self.final_upvar_tys(closure_def_id);
493493
debug!(?closure_hir_id, ?args, ?final_upvar_tys);
494494

495-
if self.tcx.features().unsized_locals() || self.tcx.features().unsized_fn_params() {
495+
if self.tcx.features().unsized_fn_params() {
496496
for capture in
497497
self.typeck_results.borrow().closure_min_captures_flattened(closure_def_id)
498498
{

compiler/rustc_middle/src/mir/syntax.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,13 +1133,6 @@ pub type AssertMessage<'tcx> = AssertKind<Operand<'tcx>>;
11331133
/// Each local naturally corresponds to the place `Place { local, projection: [] }`. This place has
11341134
/// the address of the local's allocation and the type of the local.
11351135
///
1136-
/// **Needs clarification:** Unsized locals seem to present a bit of an issue. Their allocation
1137-
/// can't actually be created on `StorageLive`, because it's unclear how big to make the allocation.
1138-
/// Furthermore, MIR produces assignments to unsized locals, although that is not permitted under
1139-
/// `#![feature(unsized_locals)]` in Rust. Besides just putting "unsized locals are special and
1140-
/// different" in a bunch of places, I (JakobDegen) don't know how to incorporate this behavior into
1141-
/// the current MIR semantics in a clean way - possibly this needs some design work first.
1142-
///
11431136
/// For places that are not locals, ie they have a non-empty list of projections, we define the
11441137
/// values as a function of the parent place, that is the place with its last [`ProjectionElem`]
11451138
/// stripped. The way this is computed of course depends on the kind of that last projection

0 commit comments

Comments
 (0)