From 092f03a07aa075c6b5cfecc47a8be6e133073819 Mon Sep 17 00:00:00 2001 From: Matthew Jasper Date: Tue, 7 Aug 2018 21:17:59 +0100 Subject: [PATCH] Make assigning to the return type interesting --- .../error_reporting/region_name.rs | 2 +- .../borrow_check/nll/type_check/mod.rs | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/region_name.rs b/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/region_name.rs index 6acf3aadf51..fbecab2dd1f 100644 --- a/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/region_name.rs +++ b/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/region_name.rs @@ -587,7 +587,7 @@ fn give_name_if_anonymous_region_appears_in_output( infcx.extract_type_name(&return_ty) }); - let mir_node_id = tcx.hir.as_local_node_id(mir_def_id).expect("non-local mir"); + let mir_node_id = tcx.hir.as_local_node_id(mir_def_id).expect("non-local mir"); let (return_span, mir_description) = if let hir::ExprKind::Closure(_, _, _, span, gen_move) = tcx.hir.expect_expr(mir_node_id).node 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 eb689f0a9c6..9f790612124 100644 --- a/src/librustc_mir/borrow_check/nll/type_check/mod.rs +++ b/src/librustc_mir/borrow_check/nll/type_check/mod.rs @@ -877,8 +877,9 @@ fn check_stmt(&mut self, mir: &Mir<'tcx>, stmt: &Statement<'tcx>, location: Loca // they are not caused by the user, but rather artifacts // of lowering. Assignments to other sorts of places *are* interesting // though. - let is_temp = if let Place::Local(l) = place { - !mir.local_decls[*l].is_user_variable.is_some() + let is_temp = if let Place::Local(l) = *place { + l != RETURN_PLACE && + !mir.local_decls[l].is_user_variable.is_some() } else { false }; @@ -1119,7 +1120,19 @@ fn check_call_dest( match *destination { Some((ref dest, _target_block)) => { let dest_ty = dest.ty(mir, tcx).to_ty(tcx); - let locations = term_location.interesting(); + let is_temp = if let Place::Local(l) = *dest { + l != RETURN_PLACE && + !mir.local_decls[l].is_user_variable.is_some() + } else { + false + }; + + let locations = if is_temp { + term_location.boring() + } else { + term_location.interesting() + }; + if let Err(terr) = self.sub_types(sig.output(), dest_ty, locations) { span_mirbug!( self, -- 2.44.0