@@ -325,8 +325,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
325325 }
326326 match ( old_binding. is_glob_import ( ) , binding. is_glob_import ( ) ) {
327327 ( true , true ) => {
328- // FIXME: remove `!binding.is_ambiguity ()` after delete the warning ambiguity.
329- if !binding. is_ambiguity ( )
328+ // FIXME: remove `!binding.is_ambiguity_recursive ()` after delete the warning ambiguity.
329+ if !binding. is_ambiguity_recursive ( )
330330 && let NameBindingKind :: Import { import : old_import, .. } =
331331 old_binding. kind
332332 && let NameBindingKind :: Import { import, .. } = binding. kind
@@ -337,21 +337,17 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
337337 // imported from the same glob-import statement.
338338 resolution. binding = Some ( binding) ;
339339 } else if res != old_binding. res ( ) {
340- let binding = if warn_ambiguity {
341- this . warn_ambiguity ( AmbiguityKind :: GlobVsGlob , old_binding , binding )
342- } else {
343- this . ambiguity ( AmbiguityKind :: GlobVsGlob , old_binding , binding)
344- } ;
345- resolution . binding = Some ( binding ) ;
340+ resolution . binding = Some ( this . new_ambiguity_binding (
341+ AmbiguityKind :: GlobVsGlob ,
342+ old_binding ,
343+ binding,
344+ warn_ambiguity ,
345+ ) ) ;
346346 } else if !old_binding. vis . is_at_least ( binding. vis , this. tcx ) {
347347 // We are glob-importing the same item but with greater visibility.
348348 resolution. binding = Some ( binding) ;
349- } else if binding. is_ambiguity ( ) {
350- resolution. binding =
351- Some ( self . arenas . alloc_name_binding ( NameBindingData {
352- warn_ambiguity : true ,
353- ..( * binding) . clone ( )
354- } ) ) ;
349+ } else if binding. is_ambiguity_recursive ( ) {
350+ resolution. binding = Some ( this. new_warn_ambiguity_binding ( binding) ) ;
355351 }
356352 }
357353 ( old_glob @ true , false ) | ( old_glob @ false , true ) => {
@@ -361,24 +357,26 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
361357 && nonglob_binding. expansion != LocalExpnId :: ROOT
362358 && glob_binding. res ( ) != nonglob_binding. res ( )
363359 {
364- resolution. binding = Some ( this. ambiguity (
360+ resolution. binding = Some ( this. new_ambiguity_binding (
365361 AmbiguityKind :: GlobVsExpanded ,
366362 nonglob_binding,
367363 glob_binding,
364+ false ,
368365 ) ) ;
369366 } else {
370367 resolution. binding = Some ( nonglob_binding) ;
371368 }
372369
373- if let Some ( old_binding ) = resolution. shadowed_glob {
374- assert ! ( old_binding . is_glob_import( ) ) ;
375- if glob_binding. res ( ) != old_binding . res ( ) {
376- resolution. shadowed_glob = Some ( this. ambiguity (
370+ if let Some ( old_shadowed_glob ) = resolution. shadowed_glob {
371+ assert ! ( old_shadowed_glob . is_glob_import( ) ) ;
372+ if glob_binding. res ( ) != old_shadowed_glob . res ( ) {
373+ resolution. shadowed_glob = Some ( this. new_ambiguity_binding (
377374 AmbiguityKind :: GlobVsGlob ,
378- old_binding ,
375+ old_shadowed_glob ,
379376 glob_binding,
377+ false ,
380378 ) ) ;
381- } else if !old_binding . vis . is_at_least ( binding. vis , this. tcx ) {
379+ } else if !old_shadowed_glob . vis . is_at_least ( binding. vis , this. tcx ) {
382380 resolution. shadowed_glob = Some ( glob_binding) ;
383381 }
384382 } else {
@@ -397,29 +395,21 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
397395 } )
398396 }
399397
400- fn ambiguity (
398+ fn new_ambiguity_binding (
401399 & self ,
402- kind : AmbiguityKind ,
400+ ambiguity_kind : AmbiguityKind ,
403401 primary_binding : NameBinding < ' a > ,
404402 secondary_binding : NameBinding < ' a > ,
403+ warn_ambiguity : bool ,
405404 ) -> NameBinding < ' a > {
406- self . arenas . alloc_name_binding ( NameBindingData {
407- ambiguity : Some ( ( secondary_binding, kind) ) ,
408- ..( * primary_binding) . clone ( )
409- } )
405+ let ambiguity = Some ( ( secondary_binding, ambiguity_kind) ) ;
406+ let data = NameBindingData { ambiguity, warn_ambiguity, ..* primary_binding } ;
407+ self . arenas . alloc_name_binding ( data)
410408 }
411409
412- fn warn_ambiguity (
413- & self ,
414- kind : AmbiguityKind ,
415- primary_binding : NameBinding < ' a > ,
416- secondary_binding : NameBinding < ' a > ,
417- ) -> NameBinding < ' a > {
418- self . arenas . alloc_name_binding ( NameBindingData {
419- ambiguity : Some ( ( secondary_binding, kind) ) ,
420- warn_ambiguity : true ,
421- ..( * primary_binding) . clone ( )
422- } )
410+ fn new_warn_ambiguity_binding ( & self , binding : NameBinding < ' a > ) -> NameBinding < ' a > {
411+ assert ! ( binding. is_ambiguity_recursive( ) ) ;
412+ self . arenas . alloc_name_binding ( NameBindingData { warn_ambiguity : true , ..* binding } )
423413 }
424414
425415 // Use `f` to mutate the resolution of the name in the module.
@@ -1381,8 +1371,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
13811371 target_bindings[ ns] . get ( ) ,
13821372 ) {
13831373 Ok ( other_binding) => {
1384- is_redundant =
1385- binding . res ( ) == other_binding . res ( ) && !other_binding. is_ambiguity ( ) ;
1374+ is_redundant = binding . res ( ) == other_binding . res ( )
1375+ && !other_binding. is_ambiguity_recursive ( ) ;
13861376 if is_redundant {
13871377 redundant_span[ ns] =
13881378 Some ( ( other_binding. span , other_binding. is_import ( ) ) ) ;
@@ -1455,7 +1445,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
14551445 . resolution ( import. parent_scope . module , key)
14561446 . borrow ( )
14571447 . binding ( )
1458- . is_some_and ( |binding| binding. is_warn_ambiguity ( ) ) ;
1448+ . is_some_and ( |binding| binding. warn_ambiguity_recursive ( ) ) ;
14591449 let _ = self . try_define (
14601450 import. parent_scope . module ,
14611451 key,
@@ -1480,7 +1470,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
14801470
14811471 module. for_each_child ( self , |this, ident, _, binding| {
14821472 let res = binding. res ( ) . expect_non_local ( ) ;
1483- let error_ambiguity = binding. is_ambiguity ( ) && !binding. warn_ambiguity ;
1473+ let error_ambiguity = binding. is_ambiguity_recursive ( ) && !binding. warn_ambiguity ;
14841474 if res != def:: Res :: Err && !error_ambiguity {
14851475 let mut reexport_chain = SmallVec :: new ( ) ;
14861476 let mut next_binding = binding;
0 commit comments