@@ -2616,27 +2616,37 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
2616
2616
2617
2617
// Try to find a path to an item in a module.
2618
2618
let last_ident = segments. last ( ) . unwrap ( ) . identifier ;
2619
+ // Resolve a single identifier with fallback to primitive types
2620
+ let resolve_identifier_with_fallback = |this : & mut Self , record_used| {
2621
+ let def = this. resolve_identifier ( last_ident, namespace, record_used) ;
2622
+ match def {
2623
+ None | Some ( LocalDef { def : Def :: Mod ( ..) , ..} ) if namespace == TypeNS =>
2624
+ this. primitive_type_table
2625
+ . primitive_types
2626
+ . get ( & last_ident. unhygienic_name )
2627
+ . map_or ( def, |prim_ty| Some ( LocalDef :: from_def ( Def :: PrimTy ( * prim_ty) ) ) ) ,
2628
+ _ => def
2629
+ }
2630
+ } ;
2631
+
2619
2632
if segments. len ( ) == 1 {
2620
2633
// In `a(::assoc_item)*` `a` cannot be a module. If `a` does resolve to a module we
2621
2634
// don't report an error right away, but try to fallback to a primitive type.
2622
2635
// So, we are still able to successfully resolve something like
2623
2636
//
2624
2637
// use std::u8; // bring module u8 in scope
2625
2638
// fn f() -> u8 { // OK, resolves to primitive u8, not to std::u8
2626
- // u8::MAX // OK, resolves to associated constant <u8>::MAX ,
2627
- // // not to non-existent std::u8::MAX
2639
+ // u8::max_value() // OK, resolves to associated function <u8>::max_value ,
2640
+ // // not to non-existent std::u8::max_value
2628
2641
// }
2629
2642
//
2630
2643
// Such behavior is required for backward compatibility.
2631
2644
// The same fallback is used when `a` resolves to nothing.
2632
- let unqualified_def = self . resolve_identifier_with_fallback ( last_ident, namespace, true ) ;
2633
- return unqualified_def. and_then ( |def| self . adjust_local_def ( def, span) )
2634
- . map ( |def| {
2635
- PathResolution :: new ( def, path_depth)
2636
- } ) ;
2645
+ let unqualified_def = resolve_identifier_with_fallback ( self , true ) ;
2646
+ return unqualified_def. and_then ( |def| self . adjust_local_def ( def, span) ) . map ( mk_res) ;
2637
2647
}
2638
2648
2639
- let unqualified_def = self . resolve_identifier_with_fallback ( last_ident , namespace , false ) ;
2649
+ let unqualified_def = resolve_identifier_with_fallback ( self , false ) ;
2640
2650
let def = self . resolve_module_relative_path ( span, segments, namespace) ;
2641
2651
match ( def, unqualified_def) {
2642
2652
( Some ( d) , Some ( ref ud) ) if d == ud. def => {
@@ -2652,28 +2662,6 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
2652
2662
def. map ( mk_res)
2653
2663
}
2654
2664
2655
- // Resolve a single identifier with fallback to primitive types
2656
- fn resolve_identifier_with_fallback ( & mut self ,
2657
- identifier : hir:: Ident ,
2658
- namespace : Namespace ,
2659
- check_ribs : bool ,
2660
- record_used : bool )
2661
- -> Option < LocalDef > {
2662
- let def = self . resolve_identifier ( identifier, namespace, check_ribs, record_used) ;
2663
- match def {
2664
- None | Some ( LocalDef { def : Def :: Mod ( ..) , ..} ) if namespace == TypeNS => {
2665
- if let Some ( & prim_ty) = self . primitive_type_table
2666
- . primitive_types
2667
- . get ( & identifier. unhygienic_name ) {
2668
- Some ( LocalDef :: from_def ( Def :: PrimTy ( prim_ty) ) )
2669
- } else {
2670
- def
2671
- }
2672
- }
2673
- _ => def
2674
- }
2675
- }
2676
-
2677
2665
// Resolve a single identifier
2678
2666
fn resolve_identifier ( & mut self ,
2679
2667
identifier : hir:: Ident ,
0 commit comments