@@ -8,17 +8,17 @@ use crate::errors::{
88 ItemsInTraitsAreNotImportable ,
99} ;
1010use crate :: Determinacy :: { self , * } ;
11- use crate :: Namespace :: * ;
1211use crate :: { module_to_string, names_to_string, ImportSuggestion } ;
1312use crate :: { AmbiguityKind , BindingKey , ModuleKind , ResolutionError , Resolver , Segment } ;
1413use crate :: { Finalize , Module , ModuleOrUniformRoot , ParentScope , PerNS , ScopeSet } ;
1514use crate :: { NameBinding , NameBindingData , NameBindingKind , PathResult } ;
15+ use crate :: { Namespace :: * , ToNameBinding } ;
1616
1717use rustc_ast:: NodeId ;
1818use rustc_data_structures:: fx:: FxHashSet ;
1919use rustc_data_structures:: intern:: Interned ;
2020use 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 } ;
2222use rustc_middle:: metadata:: ModChild ;
2323use rustc_middle:: metadata:: Reexport ;
2424use rustc_middle:: span_bug;
@@ -295,6 +295,27 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
295295 } )
296296 }
297297
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+
298319 /// Define the name or return the existing binding if there is a collision.
299320 /// `update` indicates if the definition is a redefinition of an existing binding.
300321 pub ( crate ) fn try_define (
0 commit comments