@@ -2,9 +2,12 @@ use rustc_ast::{BorrowKind, UnOp};
2
2
use rustc_hir:: { Expr , ExprKind , Mutability } ;
3
3
use rustc_middle:: ty:: adjustment:: { Adjust , Adjustment , AutoBorrow , OverloadedDeref } ;
4
4
use rustc_session:: { declare_lint, declare_lint_pass} ;
5
- use rustc_span:: { kw , sym} ;
5
+ use rustc_span:: sym;
6
6
7
- use crate :: lints:: { ImplicitUnsafeAutorefsDiag , ImplicitUnsafeAutorefsSuggestion } ;
7
+ use crate :: lints:: {
8
+ ImplicitUnsafeAutorefsDiag , ImplicitUnsafeAutorefsMethodNote , ImplicitUnsafeAutorefsOrigin ,
9
+ ImplicitUnsafeAutorefsSuggestion ,
10
+ } ;
8
11
use crate :: { LateContext , LateLintPass , LintContext } ;
9
12
10
13
declare_lint ! {
@@ -98,8 +101,8 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitAutorefs {
98
101
peel_place_mappers ( inner) . kind
99
102
// 1. Deref of a raw pointer.
100
103
&& typeck. expr_ty ( dereferenced) . is_raw_ptr ( )
101
- // PERF: 5. b. A method call annotated with `#[rustc_no_implicit_refs]`
102
104
&& let method_did = match expr. kind {
105
+ // PERF: 5. b. A method call annotated with `#[rustc_no_implicit_refs]`
103
106
ExprKind :: MethodCall ( ..) => cx. typeck_results ( ) . type_dependent_def_id ( expr. hir_id ) ,
104
107
_ => None ,
105
108
}
@@ -111,11 +114,18 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitAutorefs {
111
114
ImplicitUnsafeAutorefsDiag {
112
115
raw_ptr_span : dereferenced. span ,
113
116
raw_ptr_ty : typeck. expr_ty ( dereferenced) ,
114
- autoref_span : inner. span ,
115
- autoref_ty : typeck. expr_ty_adjusted ( inner) ,
116
- method_def_span : method_did. map ( |did| cx. tcx . def_span ( did) ) ,
117
- method_name : method_did. map ( |did| cx. tcx . item_name ( did) ) . unwrap_or ( kw:: Empty ) ,
118
- through_overloaded_deref,
117
+ origin : if through_overloaded_deref {
118
+ ImplicitUnsafeAutorefsOrigin :: OverloadedDeref
119
+ } else {
120
+ ImplicitUnsafeAutorefsOrigin :: Autoref {
121
+ autoref_span : inner. span ,
122
+ autoref_ty : typeck. expr_ty_adjusted ( inner) ,
123
+ }
124
+ } ,
125
+ method : method_did. map ( |did| ImplicitUnsafeAutorefsMethodNote {
126
+ def_span : cx. tcx . def_span ( did) ,
127
+ method_name : cx. tcx . item_name ( did) ,
128
+ } ) ,
119
129
suggestion : ImplicitUnsafeAutorefsSuggestion {
120
130
mutbl : borrow_mutbl. ref_prefix_str ( ) ,
121
131
deref : if is_coming_from_deref { "*" } else { "" } ,
@@ -151,7 +161,8 @@ fn peel_derefs_adjustments<'a>(mut adjs: &'a [Adjustment<'a>]) -> &'a [Adjustmen
151
161
152
162
/// Test if some adjustment has some implicit borrow.
153
163
///
154
- /// Returns `Some(mutability)` if the argument adjustment has implicit borrow in it.
164
+ /// Returns `Some((mutability, was_an_overloaded_deref))` if the argument adjustment is
165
+ /// an implicit borrow (or has an implicit borrow via an overloaded deref).
155
166
fn has_implicit_borrow ( Adjustment { kind, .. } : & Adjustment < ' _ > ) -> Option < ( Mutability , bool ) > {
156
167
match kind {
157
168
& Adjust :: Deref ( Some ( OverloadedDeref { mutbl, .. } ) ) => Some ( ( mutbl, true ) ) ,
0 commit comments