@@ -8,17 +8,17 @@ use crate::errors::{
8
8
ItemsInTraitsAreNotImportable ,
9
9
} ;
10
10
use crate :: Determinacy :: { self , * } ;
11
- use crate :: Namespace :: * ;
12
11
use crate :: { module_to_string, names_to_string, ImportSuggestion } ;
13
12
use crate :: { AmbiguityKind , BindingKey , ModuleKind , ResolutionError , Resolver , Segment } ;
14
13
use crate :: { Finalize , Module , ModuleOrUniformRoot , ParentScope , PerNS , ScopeSet } ;
15
14
use crate :: { NameBinding , NameBindingData , NameBindingKind , PathResult } ;
15
+ use crate :: { Namespace :: * , ToNameBinding } ;
16
16
17
17
use rustc_ast:: NodeId ;
18
18
use rustc_data_structures:: fx:: FxHashSet ;
19
19
use rustc_data_structures:: intern:: Interned ;
20
20
use rustc_errors:: { codes:: * , pluralize, struct_span_code_err, Applicability , MultiSpan } ;
21
- use rustc_hir:: def:: { self , DefKind , PartialRes } ;
21
+ use rustc_hir:: def:: { self , DefKind , Namespace , PartialRes } ;
22
22
use rustc_middle:: metadata:: ModChild ;
23
23
use rustc_middle:: metadata:: Reexport ;
24
24
use rustc_middle:: span_bug;
@@ -295,6 +295,27 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
295
295
} )
296
296
}
297
297
298
+ /// Defines `name` in namespace `ns` of module `parent` to be `def` if it is not yet defined;
299
+ /// otherwise, reports an error.
300
+ pub ( crate ) fn define < T > ( & mut self , parent : Module < ' a > , ident : Ident , ns : Namespace , def : T )
301
+ where
302
+ T : ToNameBinding < ' a > ,
303
+ {
304
+ let binding = def. to_name_binding ( self . arenas ) ;
305
+ let key = self . new_disambiguated_key ( ident, ns) ;
306
+ if let Err ( old_binding) = self . try_define ( parent, key, binding, false ) {
307
+ self . update_resolution ( parent, key, false , |this, resolution| {
308
+ if let NameBindingKind :: Res ( _) = binding. kind {
309
+ resolution. binding = Some ( this. arenas . alloc_name_binding ( NameBindingData {
310
+ kind : NameBindingKind :: Res ( Res :: Err ) ,
311
+ ..( * binding) . clone ( )
312
+ } ) ) ;
313
+ }
314
+ } ) ;
315
+ self . report_conflict ( parent, ident, ns, old_binding, binding) ;
316
+ }
317
+ }
318
+
298
319
/// Define the name or return the existing binding if there is a collision.
299
320
/// `update` indicates if the definition is a redefinition of an existing binding.
300
321
pub ( crate ) fn try_define (
0 commit comments