@@ -38,7 +38,7 @@ impl PlaceExprSubSegment {
3838}
3939
4040/// An expression that can be the target of a `Definition`.
41- #[ derive( Eq , PartialEq , Debug , Hash ) ]
41+ #[ derive( Eq , PartialEq , Debug ) ]
4242pub struct PlaceExpr {
4343 root_name : Name ,
4444 sub_segments : SmallVec < [ PlaceExprSubSegment ; 1 ] > ,
@@ -342,6 +342,7 @@ impl PlaceExprWithFlags {
342342#[ derive( Clone , Copy , Eq , PartialEq , Debug , Hash ) ]
343343pub struct PlaceExprRef < ' a > {
344344 pub ( crate ) root_name : & ' a Name ,
345+ /// Sub-segments is empty for a simple target (e.g. `foo`).
345346 pub ( crate ) sub_segments : & ' a [ PlaceExprSubSegment ] ,
346347}
347348
@@ -708,13 +709,13 @@ impl PlaceTable {
708709 let place_expr: PlaceExprRef = place_expr. into ( ) ;
709710
710711 let mut hasher = FxHasher :: default ( ) ;
711- place_expr . root_name . as_str ( ) . hash ( & mut hasher ) ;
712- for segment in place_expr . sub_segments {
713- match segment {
714- PlaceExprSubSegment :: Member ( name ) => name . hash ( & mut hasher ) ,
715- PlaceExprSubSegment :: IntSubscript ( int ) => int . hash ( & mut hasher) ,
716- PlaceExprSubSegment :: StringSubscript ( string ) => string . hash ( & mut hasher ) ,
717- }
712+
713+ // Special case for simple names (e.g. "foo"). Only hash the name so
714+ // that a lookup by name can find it (see `place_by_name`).
715+ if place_expr . sub_segments . is_empty ( ) {
716+ place_expr . root_name . as_str ( ) . hash ( & mut hasher) ;
717+ } else {
718+ place_expr . hash ( & mut hasher ) ;
718719 }
719720 hasher. finish ( )
720721 }
0 commit comments