diff --git a/src/librustc/middle/liveness.rs b/src/librustc/middle/liveness.rs index 3b56597d353a3..45ccbea206ba5 100644 --- a/src/librustc/middle/liveness.rs +++ b/src/librustc/middle/liveness.rs @@ -1483,7 +1483,14 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { None if !body.stmts.is_empty() => match body.stmts.first().unwrap().node { hir::StmtSemi(ref e, _) => { - self.ir.tcx.expr_ty(&**e) == t_ret + match (&self.ir.tcx.expr_ty(&**e).sty, &t_ret.sty) { + // Type inference causes unsuffixed integer literals + // to be evaluated as i32 values. We still want to + // inform the user of a semicolon in this case. + (&ty::TyInt(ast::TyI32), &ty::TyInt(..)) => true, + (&ty::TyInt(ast::TyI32), &ty::TyUint(..)) => true, + (a, b) => (a == b), + } }, _ => false }, diff --git a/src/test/compile-fail/missing-semicolon.rs b/src/test/compile-fail/missing-semicolon.rs new file mode 100644 index 0000000000000..8104f89bcded8 --- /dev/null +++ b/src/test/compile-fail/missing-semicolon.rs @@ -0,0 +1,17 @@ +// Copyright 2012 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// error-pattern:consider removing this semicolon + +fn foo() -> u16 { + 1234; +} + +fn main() { }