@@ -2788,6 +2788,13 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
2788
2788
visit:: walk_crate ( self , krate) ;
2789
2789
}
2790
2790
2791
+ fn check_if_primitive_type_name ( & self , name : Name , span : Span ) {
2792
+ if let Some ( _) = self . primitive_type_table . primitive_types . get ( & name) {
2793
+ span_err ! ( self . session, span, E0317 ,
2794
+ "user-defined types or type parameters cannot shadow the primitive types" ) ;
2795
+ }
2796
+ }
2797
+
2791
2798
fn resolve_item ( & mut self , item : & Item ) {
2792
2799
let name = item. ident . name ;
2793
2800
@@ -2799,6 +2806,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
2799
2806
// enum item: resolve all the variants' discrs,
2800
2807
// then resolve the ty params
2801
2808
ItemEnum ( ref enum_def, ref generics) => {
2809
+ self . check_if_primitive_type_name ( name, item. span ) ;
2810
+
2802
2811
for variant in & ( * enum_def) . variants {
2803
2812
if let Some ( ref dis_expr) = variant. node . disr_expr {
2804
2813
// resolve the discriminator expr
@@ -2824,6 +2833,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
2824
2833
}
2825
2834
2826
2835
ItemTy ( _, ref generics) => {
2836
+ self . check_if_primitive_type_name ( name, item. span ) ;
2837
+
2827
2838
self . with_type_parameter_rib ( HasTypeParameters ( generics,
2828
2839
TypeSpace ,
2829
2840
item. id ,
@@ -2847,6 +2858,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
2847
2858
}
2848
2859
2849
2860
ItemTrait ( _, ref generics, ref bounds, ref trait_items) => {
2861
+ self . check_if_primitive_type_name ( name, item. span ) ;
2862
+
2850
2863
// Create a new rib for the self type.
2851
2864
let mut self_type_rib = Rib :: new ( ItemRibKind ) ;
2852
2865
@@ -2919,6 +2932,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
2919
2932
}
2920
2933
2921
2934
ItemStruct ( ref struct_def, ref generics) => {
2935
+ self . check_if_primitive_type_name ( name, item. span ) ;
2936
+
2922
2937
self . resolve_struct ( item. id ,
2923
2938
generics,
2924
2939
& struct_def. fields [ ] ) ;
@@ -2972,7 +2987,19 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
2972
2987
} ) ;
2973
2988
}
2974
2989
2975
- ItemExternCrate ( _) | ItemUse ( _) | ItemMac ( ..) => {
2990
+ ItemUse ( ref view_path) => {
2991
+ // check for imports shadowing primitive types
2992
+ if let ast:: ViewPathSimple ( ident, _) = view_path. node {
2993
+ match self . def_map . borrow ( ) . get ( & item. id ) {
2994
+ Some ( & DefTy ( ..) ) | Some ( & DefStruct ( ..) ) | Some ( & DefTrait ( ..) ) | None => {
2995
+ self . check_if_primitive_type_name ( ident. name , item. span ) ;
2996
+ }
2997
+ _ => { }
2998
+ }
2999
+ }
3000
+ }
3001
+
3002
+ ItemExternCrate ( _) | ItemMac ( ..) => {
2976
3003
// do nothing, these are just around to be encoded
2977
3004
}
2978
3005
}
@@ -3114,6 +3141,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
3114
3141
3115
3142
fn resolve_type_parameter ( & mut self ,
3116
3143
type_parameter : & TyParam ) {
3144
+ self . check_if_primitive_type_name ( type_parameter. ident . name , type_parameter. span ) ;
3117
3145
for bound in & * type_parameter. bounds {
3118
3146
self . resolve_type_parameter_bound ( type_parameter. id , bound,
3119
3147
TraitBoundingTypeParameter ) ;
0 commit comments