3232 ) -> Self {
3333 Self { src, dst, scope, assume, context }
3434 }
35-
36- // FIXME(bryangarza): Delete this when all usages are removed
37- pub ( crate ) fn map_layouts < F , M > (
38- self ,
39- f : F ,
40- ) -> Result < MaybeTransmutableQuery < M , C > , Answer < <C as QueryContext >:: Ref > >
41- where
42- F : FnOnce (
43- L ,
44- L ,
45- <C as QueryContext >:: Scope ,
46- & C ,
47- ) -> Result < ( M , M ) , Answer < <C as QueryContext >:: Ref > > ,
48- {
49- let Self { src, dst, scope, assume, context } = self ;
50-
51- let ( src, dst) = f ( src, dst, scope, & context) ?;
52-
53- Ok ( MaybeTransmutableQuery { src, dst, scope, assume, context } )
54- }
5535}
5636
5737// FIXME: Nix this cfg, so we can write unit tests independently of rustc
@@ -107,42 +87,42 @@ where
10787 #[ instrument( level = "debug" , skip( self ) , fields( src = ?self . src, dst = ?self . dst) ) ]
10888 pub ( crate ) fn answer ( self ) -> Answer < <C as QueryContext >:: Ref > {
10989 let assume_visibility = self . assume . safety ;
110- // FIXME(bryangarza): Refactor this code to get rid of `map_layouts`
111- let query_or_answer = self . map_layouts ( |src, dst, scope, context| {
112- // Remove all `Def` nodes from `src`, without checking their visibility.
113- let src = src. prune ( & |def| true ) ;
11490
115- trace ! ( ? src, "pruned src" ) ;
91+ let Self { src, dst , scope , assume , context } = self ;
11692
117- // Remove all `Def` nodes from `dst`, additionally...
118- let dst = if assume_visibility {
119- // ...if visibility is assumed, don't check their visibility.
120- dst. prune ( & |def| true )
121- } else {
122- // ...otherwise, prune away all unreachable paths through the `Dst` layout.
123- dst. prune ( & |def| context. is_accessible_from ( def, scope) )
124- } ;
93+ // Remove all `Def` nodes from `src`, without checking their visibility.
94+ let src = src. prune ( & |def| true ) ;
12595
126- trace ! ( ?dst , "pruned dst " ) ;
96+ trace ! ( ?src , "pruned src " ) ;
12797
128- // Convert `src` from a tree-based representation to an NFA-based representation.
129- // If the conversion fails because `src` is uninhabited, conclude that the transmutation
130- // is acceptable, because instances of the `src` type do not exist.
131- let src = Nfa :: from_tree ( src) . map_err ( |Uninhabited | Answer :: Yes ) ?;
98+ // Remove all `Def` nodes from `dst`, additionally...
99+ let dst = if assume_visibility {
100+ // ...if visibility is assumed, don't check their visibility.
101+ dst. prune ( & |def| true )
102+ } else {
103+ // ...otherwise, prune away all unreachable paths through the `Dst` layout.
104+ dst. prune ( & |def| context. is_accessible_from ( def, scope) )
105+ } ;
132106
133- // Convert `dst` from a tree-based representation to an NFA-based representation.
134- // If the conversion fails because `src` is uninhabited, conclude that the transmutation
135- // is unacceptable, because instances of the `dst` type do not exist.
136- let dst =
137- Nfa :: from_tree ( dst) . map_err ( |Uninhabited | Answer :: No ( Reason :: DstIsPrivate ) ) ?;
107+ trace ! ( ?dst, "pruned dst" ) ;
138108
139- Ok ( ( src, dst) )
140- } ) ;
109+ // Convert `src` from a tree-based representation to an NFA-based representation.
110+ // If the conversion fails because `src` is uninhabited, conclude that the transmutation
111+ // is acceptable, because instances of the `src` type do not exist.
112+ let src = match Nfa :: from_tree ( src) {
113+ Ok ( src) => src,
114+ Err ( Uninhabited ) => return Answer :: Yes ,
115+ } ;
141116
142- match query_or_answer {
143- Ok ( query) => query. answer ( ) ,
144- Err ( answer) => answer,
145- }
117+ // Convert `dst` from a tree-based representation to an NFA-based representation.
118+ // If the conversion fails because `src` is uninhabited, conclude that the transmutation
119+ // is unacceptable, because instances of the `dst` type do not exist.
120+ let dst = match Nfa :: from_tree ( dst) {
121+ Ok ( dst) => dst,
122+ Err ( Uninhabited ) => return Answer :: No ( Reason :: DstIsPrivate ) ,
123+ } ;
124+
125+ MaybeTransmutableQuery { src, dst, scope, assume, context } . answer ( )
146126 }
147127}
148128
@@ -156,41 +136,19 @@ where
156136 #[ inline( always) ]
157137 #[ instrument( level = "debug" , skip( self ) , fields( src = ?self . src, dst = ?self . dst) ) ]
158138 pub ( crate ) fn answer ( self ) -> Answer < <C as QueryContext >:: Ref > {
159- // FIXME(bryangarza): Refactor this code to get rid of `map_layouts`
160- let query_or_answer = self
161- . map_layouts ( |src, dst, scope, context| Ok ( ( Dfa :: from_nfa ( src) , Dfa :: from_nfa ( dst) ) ) ) ;
162-
163- match query_or_answer {
164- Ok ( query) => query. answer ( ) ,
165- Err ( answer) => answer,
166- }
139+ let Self { src, dst, scope, assume, context } = self ;
140+ let src = Dfa :: from_nfa ( src) ;
141+ let dst = Dfa :: from_nfa ( dst) ;
142+ MaybeTransmutableQuery { src, dst, scope, assume, context } . answer ( )
167143 }
168144}
169145
170146impl < C > MaybeTransmutableQuery < Dfa < <C as QueryContext >:: Ref > , C >
171147where
172148 C : QueryContext ,
173149{
174- /// Answers whether a `Nfa` is transmutable into another `Nfa`.
175- ///
176- /// This method converts `src` and `dst` to DFAs, then computes an answer using those DFAs.
150+ /// Answers whether a `Dfa` is transmutable into another `Dfa`.
177151 pub ( crate ) fn answer ( self ) -> Answer < <C as QueryContext >:: Ref > {
178- MaybeTransmutableQuery {
179- src : & self . src ,
180- dst : & self . dst ,
181- scope : self . scope ,
182- assume : self . assume ,
183- context : self . context ,
184- }
185- . answer ( )
186- }
187- }
188-
189- impl < ' l , C > MaybeTransmutableQuery < & ' l Dfa < <C as QueryContext >:: Ref > , C >
190- where
191- C : QueryContext ,
192- {
193- pub ( crate ) fn answer ( & mut self ) -> Answer < <C as QueryContext >:: Ref > {
194152 self . answer_memo ( & mut Map :: default ( ) , self . src . start , self . dst . start )
195153 }
196154
0 commit comments