From c861e24e7251fcbf0cbb8b85c676afe6b901f8af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Fri, 27 Sep 2019 18:42:30 -0700 Subject: [PATCH] clean up --- src/librustc/hir/map/mod.rs | 4 ++-- src/librustc_typeck/check/coercion.rs | 11 +++-------- src/librustc_typeck/check/mod.rs | 16 ++++++++++------ 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index ce09ea8a5d6..a1011697ef1 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -830,11 +830,11 @@ impl<'hir> Map<'hir> { Node::ForeignItem(_) | Node::TraitItem(_) | Node::ImplItem(_) => break, - Node::Expr(expr) => match expr.node { + Node::Expr(expr) => match expr.kind { ExprKind::Match(_, _, _) => return Some(expr), _ => {} }, - Node::Stmt(stmt) => match stmt.node { + Node::Stmt(stmt) => match stmt.kind { StmtKind::Local(_) => break, _ => {} } diff --git a/src/librustc_typeck/check/coercion.rs b/src/librustc_typeck/check/coercion.rs index 1c7b765b746..56962d53a64 100644 --- a/src/librustc_typeck/check/coercion.rs +++ b/src/librustc_typeck/check/coercion.rs @@ -51,7 +51,7 @@ //! we may want to adjust precisely when coercions occur. use crate::check::{FnCtxt, Needs}; -use errors::{Applicability, DiagnosticBuilder}; +use errors::DiagnosticBuilder; use rustc::hir; use rustc::hir::def_id::DefId; use rustc::hir::ptr::P; @@ -1311,13 +1311,8 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> { pointing_at_return_type, ) { if match_expr.span.desugaring_kind().is_none() { - err.span_laber(match_expr.span, "expected this to be `()`"); - err.span_suggestion_short( - match_expr.span.shrink_to_hi(), - "consider using a semicolon here", - ";".to_string(), - Applicability::MachineApplicable, - ); + err.span_label(match_expr.span, "expected this to be `()`"); + fcx.suggest_semicolon_at_end(match_expr.span, &mut err); } } fcx.get_node_fn_decl(parent).map(|(fn_decl, _, is_main)| (fn_decl, is_main)) diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 610f32cc8f8..7560a72c890 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -3858,6 +3858,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } } + fn suggest_semicolon_at_end(&self, span: Span, err: &mut DiagnosticBuilder<'_>) { + err.span_suggestion_short( + span.shrink_to_hi(), + "consider using a semicolon here", + ";".to_string(), + Applicability::MachineApplicable, + ); + } + pub fn check_stmt(&self, stmt: &'tcx hir::Stmt) { // Don't do all the complex logic below for `DeclItem`. match stmt.kind { @@ -3883,12 +3892,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // Check with expected type of `()`. self.check_expr_has_type_or_error(&expr, self.tcx.mk_unit(), |err| { - err.span_suggestion_short( - expr.span.shrink_to_hi(), - "consider using a semicolon here", - ";".to_string(), - Applicability::MachineApplicable, - ); + self.suggest_semicolon_at_end(expr.span, err); }); } hir::StmtKind::Semi(ref expr) => {