From 7f567ce1d18a3d4579567fae33bfceaa0b18a9ff Mon Sep 17 00:00:00 2001 From: mcarton Date: Sat, 13 Feb 2016 01:38:55 +0100 Subject: [PATCH] Fix false negative with OK_EXPECT --- src/methods.rs | 25 +++++-------------------- tests/compile-fail/methods.rs | 4 +--- 2 files changed, 6 insertions(+), 23 deletions(-) diff --git a/src/methods.rs b/src/methods.rs index 9263d6573..175e3b5c0 100644 --- a/src/methods.rs +++ b/src/methods.rs @@ -274,7 +274,6 @@ declare_lint! { /// println!("{:p} {:p}",*y, z); // prints out the same pointer /// } /// ``` -/// declare_lint! { pub CLONE_DOUBLE_REF, Warn, "using `clone` on `&&T`" } @@ -789,26 +788,12 @@ fn get_error_type<'a>(cx: &LateContext, ty: ty::Ty<'a>) -> Option> { None } -/// This checks whether a given type is known to implement Debug. It's -/// conservative, i.e. it should not return false positives, but will return -/// false negatives. +/// This checks whether a given type is known to implement Debug. fn has_debug_impl<'a, 'b>(ty: ty::Ty<'a>, cx: &LateContext<'b, 'a>) -> bool { - let no_ref_ty = walk_ptrs_ty(ty); - let debug = match cx.tcx.lang_items.debug_trait() { - Some(debug) => debug, - None => return false, - }; - let debug_def = cx.tcx.lookup_trait_def(debug); - let mut debug_impl_exists = false; - debug_def.for_each_relevant_impl(cx.tcx, no_ref_ty, |d| { - let self_ty = &cx.tcx.impl_trait_ref(d).and_then(|im| im.substs.self_ty()); - if let Some(self_ty) = *self_ty { - if !self_ty.flags.get().contains(ty::TypeFlags::HAS_PARAMS) { - debug_impl_exists = true; - } - } - }); - debug_impl_exists + match cx.tcx.lang_items.debug_trait() { + Some(debug) => implements_trait(cx, ty, debug, Some(vec![])), + None => false, + } } #[cfg_attr(rustfmt, rustfmt_skip)] diff --git a/tests/compile-fail/methods.rs b/tests/compile-fail/methods.rs index 4e515c2aa..043f9e7bc 100644 --- a/tests/compile-fail/methods.rs +++ b/tests/compile-fail/methods.rs @@ -274,10 +274,8 @@ fn main() { // the error type implements `Debug` let res2: Result = Ok(0); res2.ok().expect("oh noes!"); - // we currently don't warn if the error type has a type parameter - // (but it would be nice if we did) let res3: Result>= Ok(0); - res3.ok().expect("whoof"); + res3.ok().expect("whoof"); //~ERROR called `ok().expect()` let res4: Result = Ok(0); res4.ok().expect("argh"); //~ERROR called `ok().expect()` let res5: io::Result = Ok(0);