don't lint expressions referencing ! objects, just expressions creating them

This commit is contained in:
Oliver Schneider 2016-09-13 12:41:20 +02:00
parent f469860dc2
commit a2257280ec
No known key found for this signature in database
GPG key ID: 56D6EEA0FC67AC46
2 changed files with 3 additions and 6 deletions

View file

@ -122,9 +122,6 @@ impl<'a, 'tcx> DivergenceVisitor<'a, 'tcx> {
impl<'a, 'tcx, 'v> Visitor<'v> for DivergenceVisitor<'a, 'tcx> {
fn visit_expr(&mut self, e: &'v Expr) {
// this match can be replaced by just the default arm, once
// https://github.com/rust-lang/rust/issues/35121 makes sure that
// ! is propagated properly
match e.node {
ExprAgain(_) |
ExprBreak(_) |
@ -137,8 +134,8 @@ impl<'a, 'tcx, 'v> Visitor<'v> for DivergenceVisitor<'a, 'tcx> {
_ => {},
},
ExprMethodCall(..) => { /* TODO */ },
_ => if let ty::TyNever = self.0.tcx.expr_ty(e).sty {
self.report_diverging_sub_expr(e);
_ => {
// do not lint expressions referencing objects of type `!`, as that required a diverging expression to begin with
},
}
self.maybe_walk_expr(e);

View file

@ -10,5 +10,5 @@ fn main() {
let b = true;
b || diverge(); //~ ERROR sub-expression diverges
let y = (5, diverge(), 6); //~ ERROR sub-expression diverges
println!("{}", y.1); //~ ERROR sub-expression diverges
println!("{}", y.1);
}