@@ -452,20 +452,22 @@ Late::visit_impl_type (AST::Type &type)
452
452
block_big_self = false ;
453
453
}
454
454
455
- void
456
- Late::visit (AST::TypePath &type)
455
+ template <typename P>
456
+ static void
457
+ resolve_type_path_like (NameResolutionContext &ctx, bool block_big_self,
458
+ P &type)
457
459
{
458
460
// should we add type path resolution in `ForeverStack` directly? Since it's
459
461
// quite more complicated.
460
462
// maybe we can overload `resolve_path<Namespace::Types>` to only do
461
463
// typepath-like path resolution? that sounds good
462
464
463
- DefaultResolver::visit (type);
464
-
465
465
// prevent "impl Self {}" and similar
466
466
if (type.get_segments ().size () == 1
467
- && !type.get_segments ().front ()->is_lang_item ()
468
- && type.get_segments ().front ()->is_big_self_seg () && block_big_self)
467
+ && !unwrap_segment_get_lang_item (type.get_segments ().front ())
468
+ .has_value ()
469
+ && unwrap_type_segment (type.get_segments ().front ()).is_big_self_seg ()
470
+ && block_big_self)
469
471
{
470
472
rust_error_at (type.get_locus (),
471
473
" %<Self%> is not valid in the self type of an impl block" );
@@ -478,17 +480,17 @@ Late::visit (AST::TypePath &type)
478
480
479
481
if (!resolved.has_value ())
480
482
{
481
- if (!ctx.lookup (type.get_segments ().front ()-> get_node_id ( )))
483
+ if (!ctx.lookup (unwrap_segment_node_id ( type.get_segments ().front ())))
482
484
rust_error_at (type.get_locus (), ErrorCode::E0412 ,
483
485
" could not resolve type path %qs" ,
484
- type. make_debug_string ( ).c_str ());
486
+ unwrap_segment_error_string (type ).c_str ());
485
487
return ;
486
488
}
487
489
488
490
if (resolved->is_ambiguous ())
489
491
{
490
492
rust_error_at (type.get_locus (), ErrorCode::E0659 , " %qs is ambiguous" ,
491
- type. make_debug_string ( ).c_str ());
493
+ unwrap_segment_error_string (type ).c_str ());
492
494
return ;
493
495
}
494
496
@@ -504,6 +506,14 @@ Late::visit (AST::TypePath &type)
504
506
Definition (resolved->get_node_id ()));
505
507
}
506
508
509
+ void
510
+ Late::visit (AST::TypePath &type)
511
+ {
512
+ DefaultResolver::visit (type);
513
+
514
+ resolve_type_path_like (ctx, block_big_self, type);
515
+ }
516
+
507
517
void
508
518
Late::visit (AST::Visibility &vis)
509
519
{
@@ -580,10 +590,7 @@ Late::visit (AST::StructExprStruct &s)
580
590
visit_inner_attrs (s);
581
591
DefaultResolver::visit (s.get_struct_name ());
582
592
583
- auto resolved = ctx.resolve_path (s.get_struct_name (), Namespace::Types);
584
-
585
- ctx.map_usage (Usage (s.get_struct_name ().get_node_id ()),
586
- Definition (resolved->get_node_id ()));
593
+ resolve_type_path_like (ctx, block_big_self, s.get_struct_name ());
587
594
}
588
595
589
596
void
@@ -594,10 +601,7 @@ Late::visit (AST::StructExprStructBase &s)
594
601
DefaultResolver::visit (s.get_struct_name ());
595
602
visit (s.get_struct_base ());
596
603
597
- auto resolved = ctx.resolve_path (s.get_struct_name (), Namespace::Types);
598
-
599
- ctx.map_usage (Usage (s.get_struct_name ().get_node_id ()),
600
- Definition (resolved->get_node_id ()));
604
+ resolve_type_path_like (ctx, block_big_self, s.get_struct_name ());
601
605
}
602
606
603
607
void
@@ -611,10 +615,7 @@ Late::visit (AST::StructExprStructFields &s)
611
615
for (auto &field : s.get_fields ())
612
616
visit (field);
613
617
614
- auto resolved = ctx.resolve_path (s.get_struct_name (), Namespace::Types);
615
-
616
- ctx.map_usage (Usage (s.get_struct_name ().get_node_id ()),
617
- Definition (resolved->get_node_id ()));
618
+ resolve_type_path_like (ctx, block_big_self, s.get_struct_name ());
618
619
}
619
620
620
621
// needed because Late::visit (AST::GenericArg &) is non-virtual
0 commit comments