@@ -4,7 +4,6 @@ use rustc_lint::{LateContext, LintContext};
4
4
use rustc_middle:: lint:: in_external_macro;
5
5
use rustc_middle:: ty:: { self , Ty } ;
6
6
use rustc_span:: { sym, Span } ;
7
- use rustc_typeck:: hir_ty_to_ty;
8
7
9
8
use clippy_utils:: diagnostics:: { span_lint_and_help, span_lint_and_then} ;
10
9
use clippy_utils:: trait_ref_of_method;
@@ -17,11 +16,12 @@ use super::{RESULT_LARGE_ERR, RESULT_UNIT_ERR};
17
16
fn result_err_ty < ' tcx > (
18
17
cx : & LateContext < ' tcx > ,
19
18
decl : & hir:: FnDecl < ' tcx > ,
19
+ id : hir:: def_id:: LocalDefId ,
20
20
item_span : Span ,
21
21
) -> Option < ( & ' tcx hir:: Ty < ' tcx > , Ty < ' tcx > ) > {
22
22
if !in_external_macro ( cx. sess ( ) , item_span)
23
23
&& let hir:: FnRetTy :: Return ( hir_ty) = decl. output
24
- && let ty = hir_ty_to_ty ( cx. tcx , hir_ty )
24
+ && let ty = cx . tcx . erase_late_bound_regions ( cx. tcx . fn_sig ( id ) . output ( ) )
25
25
&& is_type_diagnostic_item ( cx, ty, sym:: Result )
26
26
&& let ty:: Adt ( _, substs) = ty. kind ( )
27
27
{
@@ -34,7 +34,7 @@ fn result_err_ty<'tcx>(
34
34
35
35
pub ( super ) fn check_item < ' tcx > ( cx : & LateContext < ' tcx > , item : & hir:: Item < ' tcx > , large_err_threshold : u64 ) {
36
36
if let hir:: ItemKind :: Fn ( ref sig, _generics, _) = item. kind
37
- && let Some ( ( hir_ty, err_ty) ) = result_err_ty ( cx, sig. decl , item. span )
37
+ && let Some ( ( hir_ty, err_ty) ) = result_err_ty ( cx, sig. decl , item. def_id , item . span )
38
38
{
39
39
if cx. access_levels . is_exported ( item. def_id ) {
40
40
let fn_header_span = item. span . with_hi ( sig. decl . output . span ( ) . hi ( ) ) ;
@@ -47,7 +47,7 @@ pub(super) fn check_item<'tcx>(cx: &LateContext<'tcx>, item: &hir::Item<'tcx>, l
47
47
pub ( super ) fn check_impl_item < ' tcx > ( cx : & LateContext < ' tcx > , item : & hir:: ImplItem < ' tcx > , large_err_threshold : u64 ) {
48
48
// Don't lint if method is a trait's implementation, we can't do anything about those
49
49
if let hir:: ImplItemKind :: Fn ( ref sig, _) = item. kind
50
- && let Some ( ( hir_ty, err_ty) ) = result_err_ty ( cx, sig. decl , item. span )
50
+ && let Some ( ( hir_ty, err_ty) ) = result_err_ty ( cx, sig. decl , item. def_id , item . span )
51
51
&& trait_ref_of_method ( cx, item. def_id ) . is_none ( )
52
52
{
53
53
if cx. access_levels . is_exported ( item. def_id ) {
@@ -61,7 +61,7 @@ pub(super) fn check_impl_item<'tcx>(cx: &LateContext<'tcx>, item: &hir::ImplItem
61
61
pub ( super ) fn check_trait_item < ' tcx > ( cx : & LateContext < ' tcx > , item : & hir:: TraitItem < ' tcx > , large_err_threshold : u64 ) {
62
62
if let hir:: TraitItemKind :: Fn ( ref sig, _) = item. kind {
63
63
let fn_header_span = item. span . with_hi ( sig. decl . output . span ( ) . hi ( ) ) ;
64
- if let Some ( ( hir_ty, err_ty) ) = result_err_ty ( cx, sig. decl , item. span ) {
64
+ if let Some ( ( hir_ty, err_ty) ) = result_err_ty ( cx, sig. decl , item. def_id , item . span ) {
65
65
if cx. access_levels . is_exported ( item. def_id ) {
66
66
check_result_unit_err ( cx, err_ty, fn_header_span) ;
67
67
}
0 commit comments