@@ -1274,6 +1274,31 @@ impl LinkCollector<'_, '_> {
12741274 }
12751275 }
12761276
1277+ /// This method checks specifically if a primitive has a potential ambiguity with a local module.
1278+ /// Returns `true` if an error was emitted.
1279+ fn check_mod_primitive_ambiguity (
1280+ & self ,
1281+ res : & mut Res ,
1282+ path_str : & str ,
1283+ disambiguator : Option < Disambiguator > ,
1284+ diag_info : & DiagnosticInfo < ' _ > ,
1285+ ) -> bool {
1286+ if !matches ! ( res, Res :: Primitive ( _) )
1287+ && let Some ( prim) = resolve_primitive ( path_str, TypeNS )
1288+ {
1289+ // `prim@char`
1290+ if matches ! ( disambiguator, Some ( Disambiguator :: Primitive ) ) {
1291+ * res = prim;
1292+ } else {
1293+ // `[char]` when a `char` module is in scope
1294+ let candidates = & [ ( * res, res. def_id ( self . cx . tcx ) ) , ( prim, None ) ] ;
1295+ ambiguity_error ( self . cx , diag_info, path_str, candidates, true ) ;
1296+ return true ;
1297+ }
1298+ }
1299+ false
1300+ }
1301+
12771302 fn compute_link (
12781303 & mut self ,
12791304 mut res : Res ,
@@ -1286,21 +1311,19 @@ impl LinkCollector<'_, '_> {
12861311 // Check for a primitive which might conflict with a module
12871312 // Report the ambiguity and require that the user specify which one they meant.
12881313 // FIXME: could there ever be a primitive not in the type namespace?
1289- if matches ! (
1290- disambiguator,
1291- None | Some ( Disambiguator :: Namespace ( Namespace :: TypeNS ) | Disambiguator :: Primitive )
1292- ) && !matches ! ( res, Res :: Primitive ( _) )
1293- && let Some ( prim) = resolve_primitive ( path_str, TypeNS )
1294- {
1295- // `prim@char`
1296- if matches ! ( disambiguator, Some ( Disambiguator :: Primitive ) ) {
1297- res = prim;
1298- } else {
1299- // `[char]` when a `char` module is in scope
1300- let candidates = & [ ( res, res. def_id ( self . cx . tcx ) ) , ( prim, None ) ] ;
1301- ambiguity_error ( self . cx , & diag_info, path_str, candidates, true ) ;
1302- return None ;
1314+ let emitted_error = match disambiguator {
1315+ None | Some ( Disambiguator :: Primitive ) => {
1316+ self . check_mod_primitive_ambiguity ( & mut res, path_str, disambiguator, & diag_info)
1317+ }
1318+ Some ( Disambiguator :: Namespace ( Namespace :: TypeNS ) )
1319+ if !matches ! ( res, Res :: Def ( DefKind :: TyAlias , _) ) =>
1320+ {
1321+ self . check_mod_primitive_ambiguity ( & mut res, path_str, disambiguator, & diag_info)
13031322 }
1323+ _ => false ,
1324+ } ;
1325+ if emitted_error {
1326+ return None ;
13041327 }
13051328
13061329 match res {
0 commit comments