also lint diverging methods

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

View File

@ -133,7 +133,15 @@ impl<'a, 'tcx, 'v> Visitor<'v> for DivergenceVisitor<'a, 'tcx> {
},
_ => {},
},
ExprMethodCall(..) => { /* TODO */ },
ExprMethodCall(..) => {
let method_call = ty::MethodCall::expr(e.id);
let borrowed_table = self.0.tcx.tables.borrow();
let method_type = borrowed_table.method_map.get(&method_call).expect("This should never happen.");
let result_ty = method_type.ty.fn_ret();
if let ty::TyNever = self.0.tcx.erase_late_bound_regions(&result_ty).sty {
self.report_diverging_sub_expr(e);
}
},
_ => {
// do not lint expressions referencing objects of type `!`, as that required a diverging expression to begin with
},

View File

@ -5,10 +5,17 @@
#[allow(empty_loop)]
fn diverge() -> ! { loop {} }
struct A;
impl A {
fn foo(&self) -> ! { diverge() }
}
#[allow(unused_variables, unnecessary_operation)]
fn main() {
let b = true;
b || diverge(); //~ ERROR sub-expression diverges
b || A.foo(); //~ ERROR sub-expression diverges
let y = (5, diverge(), 6); //~ ERROR sub-expression diverges
println!("{}", y.1);
}