@@ -5,7 +5,6 @@ use crate::check::FnCtxt;
5
5
use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
6
6
use rustc_errors:: { pluralize, struct_span_err, Applicability , DiagnosticBuilder } ;
7
7
use rustc_hir as hir;
8
- use rustc_hir:: def:: Namespace ;
9
8
use rustc_hir:: def_id:: { DefId , LocalDefId } ;
10
9
use rustc_hir:: lang_items:: LangItem ;
11
10
use rustc_hir:: { ExprKind , Node , QPath } ;
@@ -99,16 +98,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
99
98
CandidateSource :: ImplSource ( impl_did) => {
100
99
// Provide the best span we can. Use the item, if local to crate, else
101
100
// the impl, if local to crate (item may be defaulted), else nothing.
102
- let item = match self
103
- . associated_item ( impl_did, item_name, Namespace :: ValueNS )
104
- . or_else ( || {
105
- let impl_trait_ref = self . tcx . impl_trait_ref ( impl_did) ?;
106
- self . associated_item (
107
- impl_trait_ref. def_id ,
108
- item_name,
109
- Namespace :: ValueNS ,
110
- )
111
- } ) {
101
+ let item = match self . associated_value ( impl_did, item_name) . or_else ( || {
102
+ let impl_trait_ref = self . tcx . impl_trait_ref ( impl_did) ?;
103
+ self . associated_value ( impl_trait_ref. def_id , item_name)
104
+ } ) {
112
105
Some ( item) => item,
113
106
None => continue ,
114
107
} ;
@@ -187,11 +180,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
187
180
}
188
181
}
189
182
CandidateSource :: TraitSource ( trait_did) => {
190
- let item =
191
- match self . associated_item ( trait_did, item_name, Namespace :: ValueNS ) {
192
- Some ( item) => item,
193
- None => continue ,
194
- } ;
183
+ let item = match self . associated_value ( trait_did, item_name) {
184
+ Some ( item) => item,
185
+ None => continue ,
186
+ } ;
195
187
let item_span = self
196
188
. tcx
197
189
. sess
@@ -271,16 +263,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
271
263
// Suggest clamping down the type if the method that is being attempted to
272
264
// be used exists at all, and the type is an ambiguous numeric type
273
265
// ({integer}/{float}).
274
- let mut candidates = all_traits ( self . tcx ) . into_iter ( ) . filter_map ( |info| {
275
- self . associated_item ( info . def_id , item_name , Namespace :: ValueNS )
276
- } ) ;
266
+ let mut candidates = all_traits ( self . tcx )
267
+ . into_iter ( )
268
+ . filter_map ( |info| self . associated_value ( info . def_id , item_name ) ) ;
277
269
// There are methods that are defined on the primitive types and won't be
278
270
// found when exploring `all_traits`, but we also need them to be acurate on
279
271
// our suggestions (#47759).
280
272
let fund_assoc = |opt_def_id : Option < DefId > | {
281
- opt_def_id
282
- . and_then ( |id| self . associated_item ( id, item_name, Namespace :: ValueNS ) )
283
- . is_some ( )
273
+ opt_def_id. and_then ( |id| self . associated_value ( id, item_name) ) . is_some ( )
284
274
} ;
285
275
let lang_items = tcx. lang_items ( ) ;
286
276
let found_candidate = candidates. next ( ) . is_some ( )
@@ -398,11 +388,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
398
388
. inherent_impls ( adt_deref. did )
399
389
. iter ( )
400
390
. filter_map ( |def_id| {
401
- self . associated_item (
402
- * def_id,
403
- item_name,
404
- Namespace :: ValueNS ,
405
- )
391
+ self . associated_value ( * def_id, item_name)
406
392
} )
407
393
. count ( )
408
394
>= 1
@@ -515,9 +501,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
515
501
. iter ( )
516
502
. copied ( )
517
503
. filter ( |def_id| {
518
- if let Some ( assoc) =
519
- self . associated_item ( * def_id, item_name, Namespace :: ValueNS )
520
- {
504
+ if let Some ( assoc) = self . associated_value ( * def_id, item_name) {
521
505
// Check for both mode is the same so we avoid suggesting
522
506
// incorrect associated item.
523
507
match ( mode, assoc. fn_has_self_parameter , source) {
@@ -1588,7 +1572,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1588
1572
}
1589
1573
} ) && ( type_is_local || info. def_id . is_local ( ) )
1590
1574
&& self
1591
- . associated_item ( info. def_id , item_name, Namespace :: ValueNS )
1575
+ . associated_value ( info. def_id , item_name)
1592
1576
. filter ( |item| {
1593
1577
if let ty:: AssocKind :: Fn = item. kind {
1594
1578
let id = item
0 commit comments