@@ -91,14 +91,21 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
91
91
CandidateSource :: ImplSource ( impl_did) => {
92
92
// Provide the best span we can. Use the item, if local to crate, else
93
93
// the impl, if local to crate (item may be defaulted), else nothing.
94
- let item = self . associated_item ( impl_did, item_name, Namespace :: Value )
95
- . or_else ( || {
96
- self . associated_item (
97
- self . tcx . impl_trait_ref ( impl_did) . unwrap ( ) . def_id ,
98
- item_name,
99
- Namespace :: Value ,
100
- )
101
- } ) . unwrap ( ) ;
94
+ let item = match self . associated_item (
95
+ impl_did,
96
+ item_name,
97
+ Namespace :: Value ,
98
+ ) . or_else ( || {
99
+ let impl_trait_ref = self . tcx . impl_trait_ref ( impl_did) ?;
100
+ self . associated_item (
101
+ impl_trait_ref. def_id ,
102
+ item_name,
103
+ Namespace :: Value ,
104
+ )
105
+ } ) {
106
+ Some ( item) => item,
107
+ None => continue ,
108
+ } ;
102
109
let note_span = self . tcx . hir ( ) . span_if_local ( item. def_id ) . or_else ( || {
103
110
self . tcx . hir ( ) . span_if_local ( impl_did)
104
111
} ) ;
@@ -132,9 +139,14 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
132
139
}
133
140
}
134
141
CandidateSource :: TraitSource ( trait_did) => {
135
- let item = self
136
- . associated_item ( trait_did, item_name, Namespace :: Value )
137
- . unwrap ( ) ;
142
+ let item = match self . associated_item (
143
+ trait_did,
144
+ item_name,
145
+ Namespace :: Value )
146
+ {
147
+ Some ( item) => item,
148
+ None => continue ,
149
+ } ;
138
150
let item_span = self . tcx . sess . source_map ( )
139
151
. def_span ( self . tcx . def_span ( item. def_id ) ) ;
140
152
if sources. len ( ) > 1 {
@@ -251,8 +263,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
251
263
if let & QPath :: Resolved ( _, ref path) = & qpath {
252
264
if let hir:: def:: Res :: Local ( hir_id) = path. res {
253
265
let span = tcx. hir ( ) . span_by_hir_id ( hir_id) ;
254
- let snippet = tcx. sess . source_map ( ) . span_to_snippet ( span)
255
- . unwrap ( ) ;
266
+ let snippet = tcx. sess . source_map ( ) . span_to_snippet ( span) ;
256
267
let filename = tcx. sess . source_map ( ) . span_to_filename ( span) ;
257
268
258
269
let parent_node = self . tcx . hir ( ) . get_by_hir_id (
@@ -263,12 +274,12 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
263
274
concrete_type,
264
275
) ;
265
276
266
- match ( filename, parent_node) {
277
+ match ( filename, parent_node, snippet ) {
267
278
( FileName :: Real ( _) , Node :: Local ( hir:: Local {
268
279
source : hir:: LocalSource :: Normal ,
269
280
ty,
270
281
..
271
- } ) ) => {
282
+ } ) , Ok ( ref snippet ) ) => {
272
283
err. span_suggestion (
273
284
// account for `let x: _ = 42;`
274
285
// ^^^^
@@ -375,14 +386,14 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
375
386
self . tcx . hir ( ) . get_parent_node_by_hir_id ( expr. hir_id ) ,
376
387
) ;
377
388
378
- let span = call_expr. span . trim_start ( item_name. span ) . unwrap ( ) ;
379
-
380
- err . span_suggestion (
381
- span ,
382
- "remove the arguments" ,
383
- String :: new ( ) ,
384
- Applicability :: MaybeIncorrect ,
385
- ) ;
389
+ if let Some ( span) = call_expr. span . trim_start ( item_name. span ) {
390
+ err . span_suggestion (
391
+ span ,
392
+ "remove the arguments" ,
393
+ String :: new ( ) ,
394
+ Applicability :: MaybeIncorrect ,
395
+ ) ;
396
+ }
386
397
}
387
398
}
388
399
0 commit comments