File tree Expand file tree Collapse file tree 3 files changed +39
-0
lines changed Expand file tree Collapse file tree 3 files changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -68,6 +68,10 @@ impl BuiltinType {
68
68
( name ! [ f32 ] , BuiltinType :: Float ( BuiltinFloat :: F32 ) ) ,
69
69
( name ! [ f64 ] , BuiltinType :: Float ( BuiltinFloat :: F64 ) ) ,
70
70
] ;
71
+
72
+ pub fn by_name ( name : & Name ) -> Option < Self > {
73
+ Self :: ALL . iter ( ) . find_map ( |( n, ty) | if n == name { Some ( * ty) } else { None } )
74
+ }
71
75
}
72
76
73
77
impl AsName for BuiltinType {
Original file line number Diff line number Diff line change @@ -317,6 +317,18 @@ impl Resolver {
317
317
}
318
318
}
319
319
320
+ // If a path of the shape `u16::from_le_bytes` failed to resolve at all, then we fall back
321
+ // to resolving to the primitive type, to allow this to still work in the presence of
322
+ // `use core::u16;`.
323
+ if path. kind == PathKind :: Plain && path. segments ( ) . len ( ) > 1 {
324
+ match BuiltinType :: by_name ( & path. segments ( ) [ 0 ] ) {
325
+ Some ( builtin) => {
326
+ return Some ( ResolveValueResult :: Partial ( TypeNs :: BuiltinType ( builtin) , 1 ) ) ;
327
+ }
328
+ None => { }
329
+ }
330
+ }
331
+
320
332
None
321
333
}
322
334
Original file line number Diff line number Diff line change @@ -1767,3 +1767,26 @@ fn foo() {
1767
1767
"# ,
1768
1768
) ;
1769
1769
}
1770
+
1771
+ #[ test]
1772
+ fn primitive_assoc_fn_shadowed_by_use ( ) {
1773
+ check_types (
1774
+ r#"
1775
+ //- /lib.rs crate:lib deps:core
1776
+ use core::u16;
1777
+
1778
+ fn f() -> u16 {
1779
+ let x = u16::from_le_bytes();
1780
+ x
1781
+ //^ u16
1782
+ }
1783
+
1784
+ //- /core.rs crate:core
1785
+ pub mod u16 {}
1786
+
1787
+ impl u16 {
1788
+ pub fn from_le_bytes() -> Self { 0 }
1789
+ }
1790
+ "# ,
1791
+ )
1792
+ }
You can’t perform that action at this time.
0 commit comments