Use unsized_feature_enabled helper function

This commit is contained in:
Santiago Pastorino 2020-10-21 07:50:15 -03:00
parent 9584b00b1d
commit 00fd703eb7
No known key found for this signature in database
GPG Key ID: 8131A24E0C79EFAF

View File

@ -974,6 +974,11 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
checker 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 /// Equate the inferred type and the annotated type for user type annotations
fn check_user_type_annotations(&mut self) { fn check_user_type_annotations(&mut self) {
debug!( debug!(
@ -1456,9 +1461,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
} }
self.check_rvalue(body, rv, location); self.check_rvalue(body, rv, location);
if !(self.tcx().features().unsized_locals if !self.unsized_feature_enabled() {
|| self.tcx().features().unsized_fn_params)
{
let trait_ref = ty::TraitRef { let trait_ref = ty::TraitRef {
def_id: tcx.require_lang_item(LangItem::Sized, Some(self.last_span)), def_id: tcx.require_lang_item(LangItem::Sized, Some(self.last_span)),
substs: tcx.mk_substs_trait(place_ty, &[]), substs: tcx.mk_substs_trait(place_ty, &[]),
@ -1721,7 +1724,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
// When `unsized_fn_params` and `unsized_locals` are both not enabled, // When `unsized_fn_params` and `unsized_locals` are both not enabled,
// this check is done at `check_local`. // 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; let span = term.source_info.span;
self.ensure_place_sized(dest_ty, span); self.ensure_place_sized(dest_ty, span);
} }
@ -1884,7 +1887,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
// When `unsized_fn_params` or `unsized_locals` is enabled, only function calls // When `unsized_fn_params` or `unsized_locals` is enabled, only function calls
// and nullary ops are checked in `check_call_dest`. // 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 span = local_decl.source_info.span;
let ty = local_decl.ty; let ty = local_decl.ty;
self.ensure_place_sized(ty, span); self.ensure_place_sized(ty, span);
@ -2026,7 +2029,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
Rvalue::NullaryOp(_, ty) => { Rvalue::NullaryOp(_, ty) => {
// Even with unsized locals cannot box an unsized value. // 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; let span = body.source_info(location).span;
self.ensure_place_sized(ty, span); self.ensure_place_sized(ty, span);
} }