diff options
Diffstat (limited to 'src')
7 files changed, 88 insertions, 104 deletions
diff --git a/src/librustc/infer/error_reporting/mod.rs b/src/librustc/infer/error_reporting/mod.rs index e3bbdab4fd9..a24eeb32842 100644 --- a/src/librustc/infer/error_reporting/mod.rs +++ b/src/librustc/infer/error_reporting/mod.rs @@ -455,11 +455,10 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { TypeError::Sorts(ref exp_found) => { // if they are both "path types", there's a chance of ambiguity // due to different versions of the same crate - match (&exp_found.expected.sty, &exp_found.found.sty) { - (&ty::Adt(exp_adt, _), &ty::Adt(found_adt, _)) => { - report_path_match(err, exp_adt.did, found_adt.did); - } - _ => (), + if let (&ty::Adt(exp_adt, _), &ty::Adt(found_adt, _)) + = (&exp_found.expected.sty, &exp_found.found.sty) + { + report_path_match(err, exp_adt.did, found_adt.did); } } TypeError::Traits(ref exp_found) => { diff --git a/src/librustc/infer/error_reporting/nice_region_error/outlives_closure.rs b/src/librustc/infer/error_reporting/nice_region_error/outlives_closure.rs index 5c27cdb6fb5..009a8235681 100644 --- a/src/librustc/infer/error_reporting/nice_region_error/outlives_closure.rs +++ b/src/librustc/infer/error_reporting/nice_region_error/outlives_closure.rs @@ -58,18 +58,17 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> { &RegionKind::ReFree(ref free_region)) = (&sub_origin, sup_region) { let hir = &self.tcx.hir; if let Some(node_id) = hir.as_local_node_id(free_region.scope) { - match hir.get(node_id) { - Node::Expr(Expr { - node: Closure(_, _, _, closure_span, None), - .. - }) => { - let sup_sp = sup_origin.span(); - let origin_sp = origin.span(); - let mut err = self.tcx.sess.struct_span_err( - sup_sp, - "borrowed data cannot be stored outside of its closure"); - err.span_label(sup_sp, "cannot be stored outside of its closure"); - if origin_sp == sup_sp || origin_sp.contains(sup_sp) { + if let Node::Expr(Expr { + node: Closure(_, _, _, closure_span, None), + .. + }) = hir.get(node_id) { + let sup_sp = sup_origin.span(); + let origin_sp = origin.span(); + let mut err = self.tcx.sess.struct_span_err( + sup_sp, + "borrowed data cannot be stored outside of its closure"); + err.span_label(sup_sp, "cannot be stored outside of its closure"); + if origin_sp == sup_sp || origin_sp.contains(sup_sp) { // // sup_sp == origin.span(): // // let mut x = None; @@ -87,11 +86,11 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> { // ------------ ... because it cannot outlive this closure // f = Some(x); // ^ cannot be stored outside of its closure - err.span_label(*external_span, - "borrowed data cannot be stored into here..."); - err.span_label(*closure_span, - "...because it cannot outlive this closure"); - } else { + err.span_label(*external_span, + "borrowed data cannot be stored into here..."); + err.span_label(*closure_span, + "...because it cannot outlive this closure"); + } else { // FIXME: the wording for this case could be much improved // // let mut lines_to_use: Vec<&CrateId> = Vec::new(); @@ -102,18 +101,16 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> { // ...so that variable is valid at time of its declaration // lines_to_use.push(installed_id); // ^^^^^^^^^^^^ cannot be stored outside of its closure - err.span_label(origin_sp, - "cannot infer an appropriate lifetime..."); - err.span_label(*external_span, - "...so that variable is valid at time of its \ - declaration"); - err.span_label(*closure_span, - "borrowed data cannot outlive this closure"); - } - err.emit(); - return Some(ErrorReported); + err.span_label(origin_sp, + "cannot infer an appropriate lifetime..."); + err.span_label(*external_span, + "...so that variable is valid at time of its \ + declaration"); + err.span_label(*closure_span, + "borrowed data cannot outlive this closure"); } - _ => {} + err.emit(); + return Some(ErrorReported); } } } diff --git a/src/librustc/infer/error_reporting/nice_region_error/static_impl_trait.rs b/src/librustc/infer/error_reporting/nice_region_error/static_impl_trait.rs index 3393eb65089..766173bf662 100644 --- a/src/librustc/infer/error_reporting/nice_region_error/static_impl_trait.rs +++ b/src/librustc/infer/error_reporting/nice_region_error/static_impl_trait.rs @@ -20,64 +20,62 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> { /// Print the error message for lifetime errors when the return type is a static impl Trait. pub(super) fn try_report_static_impl_trait(&self) -> Option<ErrorReported> { if let Some(ref error) = self.error { - match error.clone() { - RegionResolutionError::SubSupConflict( + if let RegionResolutionError::SubSupConflict( var_origin, sub_origin, sub_r, sup_origin, sup_r, - ) => { - let anon_reg_sup = self.tcx.is_suitable_region(sup_r)?; - if sub_r == &RegionKind::ReStatic && - self.tcx.return_type_impl_trait(anon_reg_sup.def_id).is_some() - { - let sp = var_origin.span(); - let return_sp = sub_origin.span(); - let mut err = self.tcx.sess.struct_span_err( - sp, - "cannot infer an appropriate lifetime", + ) = error.clone() + { + let anon_reg_sup = self.tcx.is_suitable_region(sup_r)?; + if sub_r == &RegionKind::ReStatic && + self.tcx.return_type_impl_trait(anon_reg_sup.def_id).is_some() + { + let sp = var_origin.span(); + let return_sp = sub_origin.span(); + let mut err = self.tcx.sess.struct_span_err( + sp, + "cannot infer an appropriate lifetime", + ); + err.span_label( + return_sp, + "this return type evaluates to the `'static` lifetime...", + ); + err.span_label( + sup_origin.span(), + "...but this borrow...", + ); + + let (lifetime, lt_sp_opt) = self.tcx.msg_span_from_free_region(sup_r); + if let Some(lifetime_sp) = lt_sp_opt { + err.span_note( + lifetime_sp, + &format!("...can't outlive {}", lifetime), ); - err.span_label( + } + + let lifetime_name = match sup_r { + RegionKind::ReFree(FreeRegion { + bound_region: BoundRegion::BrNamed(_, ref name), .. + }) => name.to_string(), + _ => "'_".to_owned(), + }; + if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(return_sp) { + err.span_suggestion_with_applicability( return_sp, - "this return type evaluates to the `'static` lifetime...", + &format!( + "you can add a constraint to the return type to make it last \ + less than `'static` and match {}", + lifetime, + ), + format!("{} + {}", snippet, lifetime_name), + Applicability::Unspecified, ); - err.span_label( - sup_origin.span(), - "...but this borrow...", - ); - - let (lifetime, lt_sp_opt) = self.tcx.msg_span_from_free_region(sup_r); - if let Some(lifetime_sp) = lt_sp_opt { - err.span_note( - lifetime_sp, - &format!("...can't outlive {}", lifetime), - ); - } - - let lifetime_name = match sup_r { - RegionKind::ReFree(FreeRegion { - bound_region: BoundRegion::BrNamed(_, ref name), .. - }) => name.to_string(), - _ => "'_".to_owned(), - }; - if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(return_sp) { - err.span_suggestion_with_applicability( - return_sp, - &format!( - "you can add a constraint to the return type to make it last \ - less than `'static` and match {}", - lifetime, - ), - format!("{} + {}", snippet, lifetime_name), - Applicability::Unspecified, - ); - } - err.emit(); - return Some(ErrorReported); } + err.emit(); + return Some(ErrorReported); } - _ => {} } } None diff --git a/src/librustc/infer/error_reporting/nice_region_error/util.rs b/src/librustc/infer/error_reporting/nice_region_error/util.rs index afc50fe1151..76a780a5a05 100644 --- a/src/librustc/infer/error_reporting/nice_region_error/util.rs +++ b/src/librustc/infer/error_reporting/nice_region_error/util.rs @@ -119,16 +119,13 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> { decl: &hir::FnDecl, ) -> Option<Span> { let ret_ty = self.tcx.type_of(scope_def_id); - match ret_ty.sty { - ty::FnDef(_, _) => { - let sig = ret_ty.fn_sig(self.tcx); - let late_bound_regions = self.tcx - .collect_referenced_late_bound_regions(&sig.output()); - if late_bound_regions.iter().any(|r| *r == br) { - return Some(decl.output.span()); - } + if let ty::FnDef(_, _) = ret_ty.sty { + let sig = ret_ty.fn_sig(self.tcx); + let late_bound_regions = self.tcx + .collect_referenced_late_bound_regions(&sig.output()); + if late_bound_regions.iter().any(|r| *r == br) { + return Some(decl.output.span()); } - _ => {} } None } diff --git a/src/librustc/infer/lexical_region_resolve/graphviz.rs b/src/librustc/infer/lexical_region_resolve/graphviz.rs index f605da584b2..e4705df2eea 100644 --- a/src/librustc/infer/lexical_region_resolve/graphviz.rs +++ b/src/librustc/infer/lexical_region_resolve/graphviz.rs @@ -112,12 +112,9 @@ pub fn maybe_print_constraints_for<'a, 'gcx, 'tcx>( } }; - match dump_region_data_to(region_rels, ®ion_data.constraints, &output_path) { - Ok(()) => {} - Err(e) => { - let msg = format!("io error dumping region constraints: {}", e); - tcx.sess.err(&msg) - } + if let Err(e) = dump_region_data_to(region_rels, ®ion_data.constraints, &output_path) { + let msg = format!("io error dumping region constraints: {}", e); + tcx.sess.err(&msg) } } diff --git a/src/librustc/infer/region_constraints/mod.rs b/src/librustc/infer/region_constraints/mod.rs index bc9027a0825..1a79ca21128 100644 --- a/src/librustc/infer/region_constraints/mod.rs +++ b/src/librustc/infer/region_constraints/mod.rs @@ -661,11 +661,10 @@ impl<'tcx> RegionConstraintCollector<'tcx> { debug!("RegionConstraintCollector: add_verify({:?})", verify); // skip no-op cases known to be satisfied - match verify.bound { - VerifyBound::AllBounds(ref bs) if bs.len() == 0 => { + if let VerifyBound::AllBounds(ref bs) = verify.bound { + if bs.len() == 0 { return; } - _ => {} } let index = self.data.verifys.len(); diff --git a/src/librustc/infer/type_variable.rs b/src/librustc/infer/type_variable.rs index b1e4fc7c7fc..970b6e096ff 100644 --- a/src/librustc/infer/type_variable.rs +++ b/src/librustc/infer/type_variable.rs @@ -273,11 +273,8 @@ impl<'tcx> TypeVariableTable<'tcx> { pub fn rollback_to(&mut self, s: Snapshot<'tcx>) { debug!("rollback_to{:?}", { for action in self.values.actions_since_snapshot(&s.snapshot) { - match *action { - sv::UndoLog::NewElem(index) => { - debug!("inference variable _#{}t popped", index) - } - _ => { } + if let sv::UndoLog::NewElem(index) = *action { + debug!("inference variable _#{}t popped", index) } } }); |
