@@ -43,21 +43,34 @@ pub(super) struct ResolvePathResult {
4343 pub ( super ) resolved_def : PerNs ,
4444 pub ( super ) segment_index : Option < usize > ,
4545 pub ( super ) reached_fixedpoint : ReachedFixedPoint ,
46- pub ( super ) from_differing_crate : bool ,
46+ pub ( super ) prefix_info : ResolvePathResultPrefixInfo ,
47+ }
48+
49+ #[ derive( Debug , Clone , Copy , PartialEq , Eq ) ]
50+ pub enum ResolvePathResultPrefixInfo {
51+ None ,
52+ DifferingCrate ,
53+ /// Path of the form `Enum::Variant` (and not `Variant` alone).
54+ Enum ,
4755}
4856
4957impl ResolvePathResult {
5058 fn empty ( reached_fixedpoint : ReachedFixedPoint ) -> ResolvePathResult {
51- ResolvePathResult :: new ( PerNs :: none ( ) , reached_fixedpoint, None , false )
59+ ResolvePathResult :: new (
60+ PerNs :: none ( ) ,
61+ reached_fixedpoint,
62+ None ,
63+ ResolvePathResultPrefixInfo :: None ,
64+ )
5265 }
5366
5467 fn new (
5568 resolved_def : PerNs ,
5669 reached_fixedpoint : ReachedFixedPoint ,
5770 segment_index : Option < usize > ,
58- from_differing_crate : bool ,
71+ prefix_info : ResolvePathResultPrefixInfo ,
5972 ) -> ResolvePathResult {
60- ResolvePathResult { resolved_def, segment_index, reached_fixedpoint, from_differing_crate }
73+ ResolvePathResult { resolved_def, segment_index, reached_fixedpoint, prefix_info }
6174 }
6275}
6376
@@ -157,7 +170,17 @@ impl DefMap {
157170 if result. reached_fixedpoint == ReachedFixedPoint :: No {
158171 result. reached_fixedpoint = new. reached_fixedpoint ;
159172 }
160- result. from_differing_crate |= new. from_differing_crate ;
173+ result. prefix_info = match ( result. prefix_info , new. prefix_info ) {
174+ ( ResolvePathResultPrefixInfo :: None , it) => it,
175+ ( ResolvePathResultPrefixInfo :: DifferingCrate , _) => {
176+ ResolvePathResultPrefixInfo :: DifferingCrate
177+ }
178+ (
179+ ResolvePathResultPrefixInfo :: Enum ,
180+ ResolvePathResultPrefixInfo :: DifferingCrate ,
181+ ) => ResolvePathResultPrefixInfo :: DifferingCrate ,
182+ ( ResolvePathResultPrefixInfo :: Enum , _) => ResolvePathResultPrefixInfo :: Enum ,
183+ } ;
161184 result. segment_index = match ( result. segment_index , new. segment_index ) {
162185 ( Some ( idx) , None ) => Some ( idx) ,
163186 ( Some ( old) , Some ( new) ) => Some ( old. max ( new) ) ,
@@ -403,14 +426,14 @@ impl DefMap {
403426
404427 fn resolve_remaining_segments < ' a > (
405428 & self ,
406- segments : impl Iterator < Item = ( usize , & ' a Name ) > ,
429+ mut segments : impl Iterator < Item = ( usize , & ' a Name ) > ,
407430 mut curr_per_ns : PerNs ,
408431 path : & ModPath ,
409432 db : & dyn DefDatabase ,
410433 shadow : BuiltinShadowMode ,
411434 original_module : LocalModuleId ,
412435 ) -> ResolvePathResult {
413- for ( i, segment) in segments {
436+ while let Some ( ( i, segment) ) = segments. next ( ) {
414437 let curr = match curr_per_ns. take_types_full ( ) {
415438 Some ( r) => r,
416439 None => {
@@ -443,7 +466,7 @@ impl DefMap {
443466 def,
444467 ReachedFixedPoint :: Yes ,
445468 s. map ( |s| s + i) ,
446- true ,
469+ ResolvePathResultPrefixInfo :: DifferingCrate ,
447470 ) ;
448471 }
449472
@@ -488,17 +511,28 @@ impl DefMap {
488511 ) ,
489512 } )
490513 } ) ;
491- match res {
492- Some ( res) => res,
493- None => {
494- return ResolvePathResult :: new (
495- PerNs :: types ( e. into ( ) , curr. vis , curr. import ) ,
496- ReachedFixedPoint :: Yes ,
497- Some ( i) ,
498- false ,
499- )
514+ // FIXME: Need to filter visibility here and below? Not sure.
515+ return match res {
516+ Some ( res) => {
517+ if segments. next ( ) . is_some ( ) {
518+ // Enum variants are in value namespace, segments left => no resolution.
519+ ResolvePathResult :: empty ( ReachedFixedPoint :: No )
520+ } else {
521+ ResolvePathResult :: new (
522+ res,
523+ ReachedFixedPoint :: Yes ,
524+ None ,
525+ ResolvePathResultPrefixInfo :: Enum ,
526+ )
527+ }
500528 }
501- }
529+ None => ResolvePathResult :: new (
530+ PerNs :: types ( e. into ( ) , curr. vis , curr. import ) ,
531+ ReachedFixedPoint :: Yes ,
532+ Some ( i) ,
533+ ResolvePathResultPrefixInfo :: None ,
534+ ) ,
535+ } ;
502536 }
503537 s => {
504538 // could be an inherent method call in UFCS form
@@ -513,7 +547,7 @@ impl DefMap {
513547 PerNs :: types ( s, curr. vis , curr. import ) ,
514548 ReachedFixedPoint :: Yes ,
515549 Some ( i) ,
516- false ,
550+ ResolvePathResultPrefixInfo :: None ,
517551 ) ;
518552 }
519553 } ;
@@ -522,7 +556,12 @@ impl DefMap {
522556 . filter_visibility ( |vis| vis. is_visible_from_def_map ( db, self , original_module) ) ;
523557 }
524558
525- ResolvePathResult :: new ( curr_per_ns, ReachedFixedPoint :: Yes , None , false )
559+ ResolvePathResult :: new (
560+ curr_per_ns,
561+ ReachedFixedPoint :: Yes ,
562+ None ,
563+ ResolvePathResultPrefixInfo :: None ,
564+ )
526565 }
527566
528567 fn resolve_name_in_module (
0 commit comments