Skip to content

Commit

Permalink
Use unsized_feature_enabled helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
spastorino committed Oct 27, 2020
1 parent 9584b00 commit 00fd703
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions compiler/rustc_mir/src/borrow_check/type_check/mod.rs
Expand Up @@ -974,6 +974,11 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
checker
}

fn unsized_feature_enabled(&self) -> bool {
let features = self.tcx().features();
features.unsized_locals || features.unsized_fn_params
}

/// Equate the inferred type and the annotated type for user type annotations
fn check_user_type_annotations(&mut self) {
debug!(
Expand Down Expand Up @@ -1456,9 +1461,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
}

self.check_rvalue(body, rv, location);
if !(self.tcx().features().unsized_locals
|| self.tcx().features().unsized_fn_params)
{
if !self.unsized_feature_enabled() {
let trait_ref = ty::TraitRef {
def_id: tcx.require_lang_item(LangItem::Sized, Some(self.last_span)),
substs: tcx.mk_substs_trait(place_ty, &[]),
Expand Down Expand Up @@ -1721,7 +1724,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {

// When `unsized_fn_params` and `unsized_locals` are both not enabled,
// this check is done at `check_local`.
if self.tcx().features().unsized_locals || self.tcx().features().unsized_fn_params {
if self.unsized_feature_enabled() {
let span = term.source_info.span;
self.ensure_place_sized(dest_ty, span);
}
Expand Down Expand Up @@ -1884,7 +1887,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {

// When `unsized_fn_params` or `unsized_locals` is enabled, only function calls
// and nullary ops are checked in `check_call_dest`.
if !(self.tcx().features().unsized_locals || self.tcx().features().unsized_fn_params) {
if !self.unsized_feature_enabled() {
let span = local_decl.source_info.span;
let ty = local_decl.ty;
self.ensure_place_sized(ty, span);
Expand Down Expand Up @@ -2026,7 +2029,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {

Rvalue::NullaryOp(_, ty) => {
// Even with unsized locals cannot box an unsized value.
if self.tcx().features().unsized_locals || self.tcx().features().unsized_fn_params {
if self.unsized_feature_enabled() {
let span = body.source_info(location).span;
self.ensure_place_sized(ty, span);
}
Expand Down

0 comments on commit 00fd703

Please sign in to comment.