mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-01 06:51:58 +00:00
also lint diverging methods
This commit is contained in:
parent
a2257280ec
commit
e6bfe4b514
@ -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
|
||||
},
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user