From 8147d17d8e3ac5c5dc9562862050f0876c556e88 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Wed, 6 Jun 2018 09:52:26 -0400 Subject: [PATCH] make `normalize` take ownership of the thing to be normalized --- .../nll/type_check/input_output.rs | 4 ++-- .../borrow_check/nll/type_check/mod.rs | 18 +++++++++--------- .../borrow_check/nll/type_check/type_op.rs | 1 + 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/librustc_mir/borrow_check/nll/type_check/input_output.rs b/src/librustc_mir/borrow_check/nll/type_check/input_output.rs index be0a2494b04..708ff4aa2ba 100644 --- a/src/librustc_mir/borrow_check/nll/type_check/input_output.rs +++ b/src/librustc_mir/borrow_check/nll/type_check/input_output.rs @@ -51,7 +51,7 @@ pub(super) fn equate_inputs_and_outputs( // Equate expected input tys with those in the MIR. let argument_locals = (1..).map(Local::new); for (&unnormalized_input_ty, local) in unnormalized_input_tys.iter().zip(argument_locals) { - let input_ty = self.normalize(&unnormalized_input_ty, Locations::All); + let input_ty = self.normalize(unnormalized_input_ty, Locations::All); let mir_input_ty = mir.local_decls[local].ty; self.equate_normalized_input_or_output(input_ty, mir_input_ty); } @@ -71,7 +71,7 @@ pub(super) fn equate_inputs_and_outputs( "equate_inputs_and_outputs: unnormalized_output_ty={:?}", unnormalized_output_ty ); - let output_ty = self.normalize(&unnormalized_output_ty, Locations::All); + let output_ty = self.normalize(unnormalized_output_ty, Locations::All); debug!( "equate_inputs_and_outputs: normalized output_ty={:?}", output_ty diff --git a/src/librustc_mir/borrow_check/nll/type_check/mod.rs b/src/librustc_mir/borrow_check/nll/type_check/mod.rs index 5e9b3ad5054..d9e3ecb8f85 100644 --- a/src/librustc_mir/borrow_check/nll/type_check/mod.rs +++ b/src/librustc_mir/borrow_check/nll/type_check/mod.rs @@ -289,7 +289,7 @@ fn sanitize_constant(&mut self, constant: &Constant<'tcx>, location: Location) { let instantiated_predicates = tcx.predicates_of(def_id).instantiate(tcx, substs); let predicates = - type_checker.normalize(&instantiated_predicates.predicates, location); + type_checker.normalize(instantiated_predicates.predicates, location); type_checker.prove_predicates(predicates, location); } @@ -346,7 +346,7 @@ fn sanitize_place( Place::Static(box Static { def_id, ty: sty }) => { let sty = self.sanitize_type(place, sty); let ty = self.tcx().type_of(def_id); - let ty = self.cx.normalize(&ty, location); + let ty = self.cx.normalize(ty, location); if let Err(terr) = self.cx.eq_types(ty, sty, location.at_self()) { span_mirbug!( self, @@ -1023,7 +1023,7 @@ fn check_terminator( LateBoundRegionConversionTime::FnCall, &sig, ); - let sig = self.normalize(&sig, term_location); + let sig = self.normalize(sig, term_location); self.check_call_dest(mir, term, &sig, destination, term_location); self.prove_predicates( @@ -1311,7 +1311,7 @@ fn aggregate_field_ty( let variant = &def.variants[variant_index]; let adj_field_index = active_field_index.unwrap_or(field_index); if let Some(field) = variant.fields.get(adj_field_index) { - Ok(self.normalize(&field.ty(tcx, substs), location)) + Ok(self.normalize(field.ty(tcx, substs), location)) } else { Err(FieldAccessError::OutOfRange { field_count: variant.fields.len(), @@ -1385,7 +1385,7 @@ fn check_rvalue(&mut self, mir: &Mir<'tcx>, rvalue: &Rvalue<'tcx>, location: Loc // function definition. When we extract the // signature, it comes from the `fn_sig` query, // and hence may contain unnormalized results. - let fn_sig = self.normalize(&fn_sig, location); + let fn_sig = self.normalize(fn_sig, location); let ty_fn_ptr_from = tcx.mk_fn_ptr(fn_sig); @@ -1430,7 +1430,7 @@ fn check_rvalue(&mut self, mir: &Mir<'tcx>, rvalue: &Rvalue<'tcx>, location: Loc // function definition. When we extract the // signature, it comes from the `fn_sig` query, // and hence may contain unnormalized results. - let fn_sig = self.normalize(&fn_sig, location); + let fn_sig = self.normalize(fn_sig, location); let ty_fn_ptr_from = tcx.safe_to_unsafe_fn_ty(fn_sig); @@ -1576,7 +1576,7 @@ fn prove_aggregate_predicates( AggregateKind::Array(_) | AggregateKind::Tuple => ty::InstantiatedPredicates::empty(), }; - let predicates = self.normalize(&instantiated_predicates.predicates, location); + let predicates = self.normalize(instantiated_predicates.predicates, location); debug!("prove_aggregate_predicates: predicates={:?}", predicates); self.prove_predicates(predicates, location); } @@ -1644,7 +1644,7 @@ fn typeck_mir(&mut self, mir: &Mir<'tcx>) { } } - fn normalize(&mut self, value: &T, location: impl ToLocations) -> T + fn normalize(&mut self, value: T, location: impl ToLocations) -> T where T: fmt::Debug + TypeFoldable<'tcx>, { @@ -1661,7 +1661,7 @@ fn normalize(&mut self, value: &T, location: impl ToLocations) -> T let Normalized { value, obligations } = this .infcx .at(&ObligationCause::dummy(), this.param_env) - .normalize(value) + .normalize(&value) .unwrap_or_else(|NoSolution| { span_bug!( this.last_span, diff --git a/src/librustc_mir/borrow_check/nll/type_check/type_op.rs b/src/librustc_mir/borrow_check/nll/type_check/type_op.rs index 0b35f3501fc..602abbdd4e7 100644 --- a/src/librustc_mir/borrow_check/nll/type_check/type_op.rs +++ b/src/librustc_mir/borrow_check/nll/type_check/type_op.rs @@ -19,6 +19,7 @@ pub(super) trait TypeOp<'gcx, 'tcx> { /// Micro-optimization point: true if this is trivially true. fn trivial_noop(&self) -> Option; + /// Produce a description of the operation for the debug logs. fn perform( self, type_checker: &mut TypeChecker<'_, 'gcx, 'tcx>, -- GitLab