1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
use check::FnCtxt;
use rustc::hir::map as hir_map;
use rustc::ty::{self, Ty, TyCtxt, ToPolyTraitRef, ToPredicate, TypeFoldable};
use hir::def::Def;
use hir::def_id::{CRATE_DEF_INDEX, DefId};
use middle::lang_items::FnOnceTraitLangItem;
use namespace::Namespace;
use rustc::traits::{Obligation, SelectionContext};
use util::nodemap::FxHashSet;
use syntax::ast;
use syntax::util::lev_distance::find_best_match_for_name;
use errors::DiagnosticBuilder;
use syntax_pos::Span;
use rustc::hir;
use rustc::hir::print;
use rustc::infer::type_variable::TypeVariableOrigin;
use rustc::ty::TyAdt;
use std::cell;
use std::cmp::Ordering;
use super::{MethodError, NoMatchData, CandidateSource};
use super::probe::Mode;
impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
fn is_fn_ty(&self, ty: &Ty<'tcx>, span: Span) -> bool {
let tcx = self.tcx;
match ty.sty {
ty::TyClosure(..) |
ty::TyFnDef(..) |
ty::TyFnPtr(_) => true,
_ => {
let fn_once = match tcx.lang_items().require(FnOnceTraitLangItem) {
Ok(fn_once) => fn_once,
Err(..) => return false,
};
self.autoderef(span, ty).any(|(ty, _)| {
self.probe(|_| {
let fn_once_substs = tcx.mk_substs_trait(ty,
&[self.next_ty_var(TypeVariableOrigin::MiscVariable(span))]);
let trait_ref = ty::TraitRef::new(fn_once, fn_once_substs);
let poly_trait_ref = trait_ref.to_poly_trait_ref();
let obligation =
Obligation::misc(span,
self.body_id,
self.param_env,
poly_trait_ref.to_predicate());
SelectionContext::new(self).evaluate_obligation(&obligation)
})
})
}
}
}
pub fn report_method_error(&self,
span: Span,
rcvr_ty: Ty<'tcx>,
item_name: ast::Name,
rcvr_expr: Option<&hir::Expr>,
error: MethodError<'tcx>,
args: Option<&'gcx [hir::Expr]>) {
if rcvr_ty.references_error() {
return;
}
let report_candidates = |err: &mut DiagnosticBuilder, mut sources: Vec<CandidateSource>| {
sources.sort();
sources.dedup();
let limit = if sources.len() == 5 { 5 } else { 4 };
for (idx, source) in sources.iter().take(limit).enumerate() {
match *source {
CandidateSource::ImplSource(impl_did) => {
let item = self.associated_item(impl_did, item_name, Namespace::Value)
.or_else(|| {
self.associated_item(
self.tcx.impl_trait_ref(impl_did).unwrap().def_id,
item_name,
Namespace::Value,
)
}).unwrap();
let note_span = self.tcx.hir.span_if_local(item.def_id).or_else(|| {
self.tcx.hir.span_if_local(impl_did)
});
let impl_ty = self.impl_self_ty(span, impl_did).ty;
let insertion = match self.tcx.impl_trait_ref(impl_did) {
None => format!(""),
Some(trait_ref) => {
format!(" of the trait `{}`",
self.tcx.item_path_str(trait_ref.def_id))
}
};
let note_str = format!("candidate #{} is defined in an impl{} \
for the type `{}`",
idx + 1,
insertion,
impl_ty);
if let Some(note_span) = note_span {
err.span_note(self.tcx.sess.codemap().def_span(note_span), ¬e_str);
} else {
err.note(¬e_str);
}
}
CandidateSource::TraitSource(trait_did) => {
let item = self
.associated_item(trait_did, item_name, Namespace::Value)
.unwrap();
let item_span = self.tcx.sess.codemap()
.def_span(self.tcx.def_span(item.def_id));
span_note!(err,
item_span,
"candidate #{} is defined in the trait `{}`",
idx + 1,
self.tcx.item_path_str(trait_did));
err.help(&format!("to disambiguate the method call, write `{}::{}({}{})` \
instead",
self.tcx.item_path_str(trait_did),
item_name,
if rcvr_ty.is_region_ptr() && args.is_some() {
if rcvr_ty.is_mutable_pointer() {
"&mut "
} else {
"&"
}
} else {
""
},
args.map(|arg| arg.iter()
.map(|arg| print::to_string(print::NO_ANN,
|s| s.print_expr(arg)))
.collect::<Vec<_>>()
.join(", ")).unwrap_or("...".to_owned())));
}
}
}
if sources.len() > limit {
err.note(&format!("and {} others", sources.len() - limit));
}
};
match error {
MethodError::NoMatch(NoMatchData {
static_candidates: static_sources,
unsatisfied_predicates,
out_of_scope_traits,
lev_candidate,
mode,
..
}) => {
let tcx = self.tcx;
let actual = self.resolve_type_vars_if_possible(&rcvr_ty);
let ty_string = self.ty_to_string(actual);
let is_method = mode == Mode::MethodCall;
let mut suggestion = None;
let type_str = if is_method {
"method"
} else if actual.is_enum() {
if let TyAdt(ref adt_def, _) = actual.sty {
let names = adt_def.variants.iter().map(|s| &s.name);
suggestion = find_best_match_for_name(names,
&item_name.as_str(),
None);
}
"variant"
} else {
match (item_name.as_str().chars().next(), actual.is_fresh_ty()) {
(Some(name), false) if name.is_lowercase() => {
"function or associated item"
}
(Some(_), false) => "associated item",
(Some(_), true) | (None, false) => {
"variant or associated item"
}
(None, true) => "variant",
}
};
let mut err = if !actual.references_error() {
let mut candidates = all_traits(self.tcx)
.filter(|info| {
self.associated_item(info.def_id, item_name, Namespace::Value).is_some()
});
if let (true, false, Some(expr), Some(_)) = (actual.is_numeric(),
actual.has_concrete_skeleton(),
rcvr_expr,
candidates.next()) {
let mut err = struct_span_err!(
tcx.sess,
span,
E0689,
"can't call {} `{}` on ambiguous numeric type `{}`",
type_str,
item_name,
ty_string
);
let concrete_type = if actual.is_integral() {
"i32"
} else {
"f32"
};
match expr.node {
hir::ExprLit(_) => {
let snippet = tcx.sess.codemap().span_to_snippet(expr.span)
.unwrap_or("<numeric literal>".to_string());
err.span_suggestion(expr.span,
&format!("you must specify a concrete type for \
this numeric value, like `{}`",
concrete_type),
format!("{}_{}",
snippet,
concrete_type));
}
hir::ExprPath(ref qpath) => {
if let &hir::QPath::Resolved(_, ref path) = &qpath {
if let hir::def::Def::Local(node_id) = path.def {
let span = tcx.hir.span(node_id);
let snippet = tcx.sess.codemap().span_to_snippet(span)
.unwrap();
err.span_suggestion(span,
&format!("you must specify a type for \
this binding, like `{}`",
concrete_type),
format!("{}: {}",
snippet,
concrete_type));
}
}
}
_ => {}
}
err.emit();
return;
} else {
let mut err = struct_span_err!(
tcx.sess,
span,
E0599,
"no {} named `{}` found for type `{}` in the current scope",
type_str,
item_name,
ty_string
);
if let Some(suggestion) = suggestion {
err.note(&format!("did you mean `{}::{}`?", type_str, suggestion));
}
err
}
} else {
tcx.sess.diagnostic().struct_dummy()
};
if let Some(def) = actual.ty_adt_def() {
if let Some(full_sp) = tcx.hir.span_if_local(def.did) {
let def_sp = tcx.sess.codemap().def_span(full_sp);
err.span_label(def_sp, format!("{} `{}` not found {}",
type_str,
item_name,
if def.is_enum() && !is_method {
"here"
} else {
"for this"
}));
}
}
if let Some(expr) = rcvr_expr {
for (ty, _) in self.autoderef(span, rcvr_ty) {
match ty.sty {
ty::TyAdt(def, substs) if !def.is_enum() => {
if let Some(field) = def.non_enum_variant()
.find_field_named(item_name) {
let snippet = tcx.sess.codemap().span_to_snippet(expr.span);
let expr_string = match snippet {
Ok(expr_string) => expr_string,
_ => "s".into(),
};
let field_ty = field.ty(tcx, substs);
let scope = self.tcx.hir.get_module_parent(self.body_id);
if field.vis.is_accessible_from(scope, self.tcx) {
if self.is_fn_ty(&field_ty, span) {
err.help(&format!("use `({0}.{1})(...)` if you \
meant to call the function \
stored in the `{1}` field",
expr_string,
item_name));
} else {
err.help(&format!("did you mean to write `{0}.{1}` \
instead of `{0}.{1}(...)`?",
expr_string,
item_name));
}
err.span_label(span, "field, not a method");
} else {
err.span_label(span, "private field, not a method");
}
break;
}
}
_ => {}
}
}
} else {
err.span_label(span, format!("{} not found in `{}`", type_str, ty_string));
}
if self.is_fn_ty(&rcvr_ty, span) {
macro_rules! report_function {
($span:expr, $name:expr) => {
err.note(&format!("{} is a function, perhaps you wish to call it",
$name));
}
}
if let Some(expr) = rcvr_expr {
if let Ok(expr_string) = tcx.sess.codemap().span_to_snippet(expr.span) {
report_function!(expr.span, expr_string);
} else if let hir::ExprPath(hir::QPath::Resolved(_, ref path)) = expr.node {
if let Some(segment) = path.segments.last() {
report_function!(expr.span, segment.name);
}
}
}
}
if !static_sources.is_empty() {
err.note("found the following associated functions; to be used as methods, \
functions must have a `self` parameter");
err.help(&format!("try with `{}::{}`", self.ty_to_string(actual), item_name));
report_candidates(&mut err, static_sources);
}
if !unsatisfied_predicates.is_empty() {
let bound_list = unsatisfied_predicates.iter()
.map(|p| format!("`{} : {}`", p.self_ty(), p))
.collect::<Vec<_>>()
.join("\n");
err.note(&format!("the method `{}` exists but the following trait bounds \
were not satisfied:\n{}",
item_name,
bound_list));
}
if actual.is_numeric() && actual.is_fresh() {
} else {
self.suggest_traits_to_import(&mut err,
span,
rcvr_ty,
item_name,
rcvr_expr,
out_of_scope_traits);
}
if let Some(lev_candidate) = lev_candidate {
err.help(&format!("did you mean `{}`?", lev_candidate.name));
}
err.emit();
}
MethodError::Ambiguity(sources) => {
let mut err = struct_span_err!(self.sess(),
span,
E0034,
"multiple applicable items in scope");
err.span_label(span, format!("multiple `{}` found", item_name));
report_candidates(&mut err, sources);
err.emit();
}
MethodError::PrivateMatch(def, out_of_scope_traits) => {
let mut err = struct_span_err!(self.tcx.sess, span, E0624,
"{} `{}` is private", def.kind_name(), item_name);
self.suggest_valid_traits(&mut err, out_of_scope_traits);
err.emit();
}
MethodError::IllegalSizedBound(candidates) => {
let msg = format!("the `{}` method cannot be invoked on a trait object", item_name);
let mut err = self.sess().struct_span_err(span, &msg);
if !candidates.is_empty() {
let help = format!("{an}other candidate{s} {were} found in the following \
trait{s}, perhaps add a `use` for {one_of_them}:",
an = if candidates.len() == 1 {"an" } else { "" },
s = if candidates.len() == 1 { "" } else { "s" },
were = if candidates.len() == 1 { "was" } else { "were" },
one_of_them = if candidates.len() == 1 {
"it"
} else {
"one_of_them"
});
self.suggest_use_candidates(&mut err, help, candidates);
}
err.emit();
}
MethodError::BadReturnType => {
bug!("no return type expectations but got BadReturnType")
}
}
}
fn suggest_use_candidates(&self,
err: &mut DiagnosticBuilder,
mut msg: String,
candidates: Vec<DefId>) {
let module_did = self.tcx.hir.get_module_parent(self.body_id);
let module_id = self.tcx.hir.as_local_node_id(module_did).unwrap();
let krate = self.tcx.hir.krate();
let (span, found_use) = UsePlacementFinder::check(self.tcx, krate, module_id);
if let Some(span) = span {
let path_strings = candidates.iter().map(|did| {
let additional_newline = if found_use {
""
} else {
"\n"
};
format!("use {};\n{}", self.tcx.item_path_str(*did), additional_newline)
}).collect();
err.span_suggestions(span, &msg, path_strings);
} else {
let limit = if candidates.len() == 5 { 5 } else { 4 };
for (i, trait_did) in candidates.iter().take(limit).enumerate() {
msg.push_str(&format!("\ncandidate #{}: `use {};`",
i + 1,
self.tcx.item_path_str(*trait_did)));
}
if candidates.len() > limit {
msg.push_str(&format!("\nand {} others", candidates.len() - limit));
}
err.note(&msg[..]);
}
}
fn suggest_valid_traits(&self,
err: &mut DiagnosticBuilder,
valid_out_of_scope_traits: Vec<DefId>) -> bool {
if !valid_out_of_scope_traits.is_empty() {
let mut candidates = valid_out_of_scope_traits;
candidates.sort();
candidates.dedup();
err.help("items from traits can only be used if the trait is in scope");
let msg = format!("the following {traits_are} implemented but not in scope, \
perhaps add a `use` for {one_of_them}:",
traits_are = if candidates.len() == 1 {
"trait is"
} else {
"traits are"
},
one_of_them = if candidates.len() == 1 {
"it"
} else {
"one of them"
});
self.suggest_use_candidates(err, msg, candidates);
true
} else {
false
}
}
fn suggest_traits_to_import(&self,
err: &mut DiagnosticBuilder,
span: Span,
rcvr_ty: Ty<'tcx>,
item_name: ast::Name,
rcvr_expr: Option<&hir::Expr>,
valid_out_of_scope_traits: Vec<DefId>) {
if self.suggest_valid_traits(err, valid_out_of_scope_traits) {
return;
}
let type_is_local = self.type_derefs_to_local(span, rcvr_ty, rcvr_expr);
let mut candidates = all_traits(self.tcx)
.filter(|info| {
(type_is_local || info.def_id.is_local()) &&
self.associated_item(info.def_id, item_name, Namespace::Value)
.filter(|item| {
item.vis == ty::Visibility::Public || info.def_id.is_local()
})
.is_some()
})
.collect::<Vec<_>>();
if !candidates.is_empty() {
candidates.sort_by(|a, b| a.cmp(b).reverse());
candidates.dedup();
err.help("items from traits can only be used if the trait is implemented and in scope");
let mut msg = format!("the following {traits_define} an item `{name}`, \
perhaps you need to implement {one_of_them}:",
traits_define = if candidates.len() == 1 {
"trait defines"
} else {
"traits define"
},
one_of_them = if candidates.len() == 1 {
"it"
} else {
"one of them"
},
name = item_name);
for (i, trait_info) in candidates.iter().enumerate() {
msg.push_str(&format!("\ncandidate #{}: `{}`",
i + 1,
self.tcx.item_path_str(trait_info.def_id)));
}
err.note(&msg[..]);
}
}
fn type_derefs_to_local(&self,
span: Span,
rcvr_ty: Ty<'tcx>,
rcvr_expr: Option<&hir::Expr>)
-> bool {
fn is_local(ty: Ty) -> bool {
match ty.sty {
ty::TyAdt(def, _) => def.did.is_local(),
ty::TyForeign(did) => did.is_local(),
ty::TyDynamic(ref tr, ..) => tr.principal()
.map_or(false, |p| p.def_id().is_local()),
ty::TyParam(_) => true,
_ => false,
}
}
if rcvr_expr.is_none() {
return is_local(self.resolve_type_vars_with_obligations(rcvr_ty));
}
self.autoderef(span, rcvr_ty).any(|(ty, _)| is_local(ty))
}
}
pub type AllTraitsVec = Vec<DefId>;
#[derive(Copy, Clone)]
pub struct TraitInfo {
pub def_id: DefId,
}
impl TraitInfo {
fn new(def_id: DefId) -> TraitInfo {
TraitInfo { def_id: def_id }
}
}
impl PartialEq for TraitInfo {
fn eq(&self, other: &TraitInfo) -> bool {
self.cmp(other) == Ordering::Equal
}
}
impl Eq for TraitInfo {}
impl PartialOrd for TraitInfo {
fn partial_cmp(&self, other: &TraitInfo) -> Option<Ordering> {
Some(self.cmp(other))
}
}
impl Ord for TraitInfo {
fn cmp(&self, other: &TraitInfo) -> Ordering {
let lhs = (other.def_id.krate, other.def_id);
let rhs = (self.def_id.krate, self.def_id);
lhs.cmp(&rhs)
}
}
pub fn all_traits<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>) -> AllTraits<'a> {
if tcx.all_traits.borrow().is_none() {
use rustc::hir::itemlikevisit;
let mut traits = vec![];
struct Visitor<'a, 'tcx: 'a> {
map: &'a hir_map::Map<'tcx>,
traits: &'a mut AllTraitsVec,
}
impl<'v, 'a, 'tcx> itemlikevisit::ItemLikeVisitor<'v> for Visitor<'a, 'tcx> {
fn visit_item(&mut self, i: &'v hir::Item) {
match i.node {
hir::ItemTrait(..) => {
let def_id = self.map.local_def_id(i.id);
self.traits.push(def_id);
}
_ => {}
}
}
fn visit_trait_item(&mut self, _trait_item: &hir::TraitItem) {
}
fn visit_impl_item(&mut self, _impl_item: &hir::ImplItem) {
}
}
tcx.hir.krate().visit_all_item_likes(&mut Visitor {
map: &tcx.hir,
traits: &mut traits,
});
let mut external_mods = FxHashSet();
fn handle_external_def(tcx: TyCtxt,
traits: &mut AllTraitsVec,
external_mods: &mut FxHashSet<DefId>,
def: Def) {
let def_id = def.def_id();
match def {
Def::Trait(..) => {
traits.push(def_id);
}
Def::Mod(..) => {
if !external_mods.insert(def_id) {
return;
}
for child in tcx.item_children(def_id).iter() {
handle_external_def(tcx, traits, external_mods, child.def)
}
}
_ => {}
}
}
for &cnum in tcx.crates().iter() {
let def_id = DefId {
krate: cnum,
index: CRATE_DEF_INDEX,
};
handle_external_def(tcx, &mut traits, &mut external_mods, Def::Mod(def_id));
}
*tcx.all_traits.borrow_mut() = Some(traits);
}
let borrow = tcx.all_traits.borrow();
assert!(borrow.is_some());
AllTraits {
borrow,
idx: 0,
}
}
pub struct AllTraits<'a> {
borrow: cell::Ref<'a, Option<AllTraitsVec>>,
idx: usize,
}
impl<'a> Iterator for AllTraits<'a> {
type Item = TraitInfo;
fn next(&mut self) -> Option<TraitInfo> {
let AllTraits { ref borrow, ref mut idx } = *self;
borrow.as_ref().unwrap().get(*idx).map(|info| {
*idx += 1;
TraitInfo::new(*info)
})
}
fn size_hint(&self) -> (usize, Option<usize>) {
let len = self.borrow.as_ref().unwrap().len() - self.idx;
(len, Some(len))
}
}
impl<'a> ExactSizeIterator for AllTraits<'a> {}
struct UsePlacementFinder<'a, 'tcx: 'a, 'gcx: 'tcx> {
target_module: ast::NodeId,
span: Option<Span>,
found_use: bool,
tcx: TyCtxt<'a, 'gcx, 'tcx>
}
impl<'a, 'tcx, 'gcx> UsePlacementFinder<'a, 'tcx, 'gcx> {
fn check(
tcx: TyCtxt<'a, 'gcx, 'tcx>,
krate: &'tcx hir::Crate,
target_module: ast::NodeId,
) -> (Option<Span>, bool) {
let mut finder = UsePlacementFinder {
target_module,
span: None,
found_use: false,
tcx,
};
hir::intravisit::walk_crate(&mut finder, krate);
(finder.span, finder.found_use)
}
}
impl<'a, 'tcx, 'gcx> hir::intravisit::Visitor<'tcx> for UsePlacementFinder<'a, 'tcx, 'gcx> {
fn visit_mod(
&mut self,
module: &'tcx hir::Mod,
_: Span,
node_id: ast::NodeId,
) {
if self.span.is_some() {
return;
}
if node_id != self.target_module {
hir::intravisit::walk_mod(self, module, node_id);
return;
}
for item_id in &module.item_ids {
let item = self.tcx.hir.expect_item(item_id.id);
match item.node {
hir::ItemUse(..) => {
if item.span.ctxt().outer().expn_info().is_none() {
self.span = Some(item.span.shrink_to_lo());
self.found_use = true;
return;
}
},
hir::ItemExternCrate(_) => {}
_ => if self.span.map_or(true, |span| item.span < span ) {
if item.span.ctxt().outer().expn_info().is_none() {
if item.attrs.is_empty() {
self.span = Some(item.span.shrink_to_lo());
} else {
for attr in &item.attrs {
if self.span.map_or(true, |span| attr.span < span) {
self.span = Some(attr.span.shrink_to_lo());
}
}
}
}
},
}
}
}
fn nested_visit_map<'this>(
&'this mut self
) -> hir::intravisit::NestedVisitorMap<'this, 'tcx> {
hir::intravisit::NestedVisitorMap::None
}
}