14
14
#![ feature( iter_intersperse) ]
15
15
#![ feature( let_chains) ]
16
16
#![ feature( never_type) ]
17
+ #![ feature( rustc_attrs) ]
17
18
#![ recursion_limit = "256" ]
18
19
#![ allow( rustdoc:: private_intra_doc_links) ]
19
20
#![ allow( rustc:: potential_query_instability) ]
@@ -61,7 +62,7 @@ use rustc_span::{Span, DUMMY_SP};
61
62
use smallvec:: { smallvec, SmallVec } ;
62
63
use std:: cell:: { Cell , RefCell } ;
63
64
use std:: collections:: BTreeSet ;
64
- use std:: { fmt, ptr } ;
65
+ use std:: fmt;
65
66
66
67
use diagnostics:: { ImportSuggestion , LabelSuggestion , Suggestion } ;
67
68
use imports:: { Import , ImportData , ImportKind , NameResolution } ;
@@ -365,7 +366,7 @@ impl<'a> LexicalScopeBinding<'a> {
365
366
}
366
367
}
367
368
368
- #[ derive( Copy , Clone , Debug ) ]
369
+ #[ derive( Copy , Clone , PartialEq , Debug ) ]
369
370
enum ModuleOrUniformRoot < ' a > {
370
371
/// Regular module.
371
372
Module ( Module < ' a > ) ,
@@ -383,23 +384,6 @@ enum ModuleOrUniformRoot<'a> {
383
384
CurrentScope ,
384
385
}
385
386
386
- impl ModuleOrUniformRoot < ' _ > {
387
- fn same_def ( lhs : Self , rhs : Self ) -> bool {
388
- match ( lhs, rhs) {
389
- ( ModuleOrUniformRoot :: Module ( lhs) , ModuleOrUniformRoot :: Module ( rhs) ) => {
390
- ptr:: eq ( lhs, rhs)
391
- }
392
- (
393
- ModuleOrUniformRoot :: CrateRootAndExternPrelude ,
394
- ModuleOrUniformRoot :: CrateRootAndExternPrelude ,
395
- )
396
- | ( ModuleOrUniformRoot :: ExternPrelude , ModuleOrUniformRoot :: ExternPrelude )
397
- | ( ModuleOrUniformRoot :: CurrentScope , ModuleOrUniformRoot :: CurrentScope ) => true ,
398
- _ => false ,
399
- }
400
- }
401
- }
402
-
403
387
#[ derive( Debug ) ]
404
388
enum PathResult < ' a > {
405
389
Module ( ModuleOrUniformRoot < ' a > ) ,
@@ -530,7 +514,9 @@ struct ModuleData<'a> {
530
514
expansion : ExpnId ,
531
515
}
532
516
533
- type Module < ' a > = & ' a ModuleData < ' a > ;
517
+ #[ derive( Clone , Copy , PartialEq ) ]
518
+ #[ rustc_pass_by_value]
519
+ struct Module < ' a > ( Interned < ' a , ModuleData < ' a > > ) ;
534
520
535
521
impl < ' a > ModuleData < ' a > {
536
522
fn new (
@@ -558,8 +544,10 @@ impl<'a> ModuleData<'a> {
558
544
expansion,
559
545
}
560
546
}
547
+ }
561
548
562
- fn for_each_child < ' tcx , R , F > ( & ' a self , resolver : & mut R , mut f : F )
549
+ impl < ' a > Module < ' a > {
550
+ fn for_each_child < ' tcx , R , F > ( self , resolver : & mut R , mut f : F )
563
551
where
564
552
R : AsMut < Resolver < ' a , ' tcx > > ,
565
553
F : FnMut ( & mut R , Ident , Namespace , NameBinding < ' a > ) ,
@@ -572,7 +560,7 @@ impl<'a> ModuleData<'a> {
572
560
}
573
561
574
562
/// This modifies `self` in place. The traits will be stored in `self.traits`.
575
- fn ensure_traits < ' tcx , R > ( & ' a self , resolver : & mut R )
563
+ fn ensure_traits < ' tcx , R > ( self , resolver : & mut R )
576
564
where
577
565
R : AsMut < Resolver < ' a , ' tcx > > ,
578
566
{
@@ -591,35 +579,35 @@ impl<'a> ModuleData<'a> {
591
579
}
592
580
}
593
581
594
- fn res ( & self ) -> Option < Res > {
582
+ fn res ( self ) -> Option < Res > {
595
583
match self . kind {
596
584
ModuleKind :: Def ( kind, def_id, _) => Some ( Res :: Def ( kind, def_id) ) ,
597
585
_ => None ,
598
586
}
599
587
}
600
588
601
589
// Public for rustdoc.
602
- fn def_id ( & self ) -> DefId {
590
+ fn def_id ( self ) -> DefId {
603
591
self . opt_def_id ( ) . expect ( "`ModuleData::def_id` is called on a block module" )
604
592
}
605
593
606
- fn opt_def_id ( & self ) -> Option < DefId > {
594
+ fn opt_def_id ( self ) -> Option < DefId > {
607
595
match self . kind {
608
596
ModuleKind :: Def ( _, def_id, _) => Some ( def_id) ,
609
597
_ => None ,
610
598
}
611
599
}
612
600
613
601
// `self` resolves to the first module ancestor that `is_normal`.
614
- fn is_normal ( & self ) -> bool {
602
+ fn is_normal ( self ) -> bool {
615
603
matches ! ( self . kind, ModuleKind :: Def ( DefKind :: Mod , _, _) )
616
604
}
617
605
618
- fn is_trait ( & self ) -> bool {
606
+ fn is_trait ( self ) -> bool {
619
607
matches ! ( self . kind, ModuleKind :: Def ( DefKind :: Trait , _, _) )
620
608
}
621
609
622
- fn nearest_item_scope ( & ' a self ) -> Module < ' a > {
610
+ fn nearest_item_scope ( self ) -> Module < ' a > {
623
611
match self . kind {
624
612
ModuleKind :: Def ( DefKind :: Enum | DefKind :: Trait , ..) => {
625
613
self . parent . expect ( "enum or trait module without a parent" )
@@ -630,15 +618,15 @@ impl<'a> ModuleData<'a> {
630
618
631
619
/// The [`DefId`] of the nearest `mod` item ancestor (which may be this module).
632
620
/// This may be the crate root.
633
- fn nearest_parent_mod ( & self ) -> DefId {
621
+ fn nearest_parent_mod ( self ) -> DefId {
634
622
match self . kind {
635
623
ModuleKind :: Def ( DefKind :: Mod , def_id, _) => def_id,
636
624
_ => self . parent . expect ( "non-root module without parent" ) . nearest_parent_mod ( ) ,
637
625
}
638
626
}
639
627
640
- fn is_ancestor_of ( & self , mut other : & Self ) -> bool {
641
- while !ptr :: eq ( self , other) {
628
+ fn is_ancestor_of ( self , mut other : Self ) -> bool {
629
+ while self != other {
642
630
if let Some ( parent) = other. parent {
643
631
other = parent;
644
632
} else {
@@ -649,7 +637,15 @@ impl<'a> ModuleData<'a> {
649
637
}
650
638
}
651
639
652
- impl < ' a > fmt:: Debug for ModuleData < ' a > {
640
+ impl < ' a > std:: ops:: Deref for Module < ' a > {
641
+ type Target = ModuleData < ' a > ;
642
+
643
+ fn deref ( & self ) -> & Self :: Target {
644
+ & self . 0
645
+ }
646
+ }
647
+
648
+ impl < ' a > fmt:: Debug for Module < ' a > {
653
649
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
654
650
write ! ( f, "{:?}" , self . res( ) )
655
651
}
@@ -810,10 +806,9 @@ impl<'a> NameBindingData<'a> {
810
806
NameBindingKind :: Import { import, .. } => {
811
807
matches ! ( import. kind, ImportKind :: ExternCrate { .. } )
812
808
}
813
- NameBindingKind :: Module ( & ModuleData {
814
- kind : ModuleKind :: Def ( DefKind :: Mod , def_id, _) ,
815
- ..
816
- } ) => def_id. is_crate_root ( ) ,
809
+ NameBindingKind :: Module ( module)
810
+ if let ModuleKind :: Def ( DefKind :: Mod , def_id, _) = module. kind
811
+ => def_id. is_crate_root ( ) ,
817
812
_ => false ,
818
813
}
819
814
}
@@ -1102,8 +1097,13 @@ impl<'a> ResolverArenas<'a> {
1102
1097
no_implicit_prelude : bool ,
1103
1098
module_map : & mut FxHashMap < DefId , Module < ' a > > ,
1104
1099
) -> Module < ' a > {
1105
- let module =
1106
- self . modules . alloc ( ModuleData :: new ( parent, kind, expn_id, span, no_implicit_prelude) ) ;
1100
+ let module = Module ( Interned :: new_unchecked ( self . modules . alloc ( ModuleData :: new (
1101
+ parent,
1102
+ kind,
1103
+ expn_id,
1104
+ span,
1105
+ no_implicit_prelude,
1106
+ ) ) ) ) ;
1107
1107
let def_id = module. opt_def_id ( ) ;
1108
1108
if def_id. map_or ( true , |def_id| def_id. is_local ( ) ) {
1109
1109
self . local_modules . borrow_mut ( ) . push ( module) ;
@@ -1647,7 +1647,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1647
1647
module. populate_on_access . set ( false ) ;
1648
1648
self . build_reduced_graph_external ( module) ;
1649
1649
}
1650
- & module. lazy_resolutions
1650
+ & module. 0 . 0 . lazy_resolutions
1651
1651
}
1652
1652
1653
1653
fn resolution (
@@ -1827,7 +1827,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1827
1827
1828
1828
fn set_binding_parent_module ( & mut self , binding : NameBinding < ' a > , module : Module < ' a > ) {
1829
1829
if let Some ( old_module) = self . binding_parent_modules . insert ( binding, module) {
1830
- if !ptr :: eq ( module, old_module) {
1830
+ if module != old_module {
1831
1831
span_bug ! ( binding. span, "parent module is reset for binding" ) ;
1832
1832
}
1833
1833
}
@@ -1847,7 +1847,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1847
1847
) {
1848
1848
( Some ( macro_rules) , Some ( modularized) ) => {
1849
1849
macro_rules. nearest_parent_mod ( ) == modularized. nearest_parent_mod ( )
1850
- && modularized. is_ancestor_of ( macro_rules)
1850
+ && modularized. is_ancestor_of ( * macro_rules)
1851
1851
}
1852
1852
_ => false ,
1853
1853
}
0 commit comments