1- use std:: fmt:: Display ;
21use std:: ops:: Range ;
32
43use apollo_compiler:: parser:: LineColumn ;
@@ -70,22 +69,22 @@ impl ErrorReporter {
7069 ( self . errors , self . hints )
7170 }
7271
73- pub ( crate ) fn report_mismatch_error < D : Display , S , L > (
72+ pub ( crate ) fn report_mismatch_error < D , S > (
7473 & mut self ,
7574 error : CompositionError ,
7675 mismatched_element : & D ,
7776 subgraph_elements : & Sources < S > ,
7877 supergraph_mismatch_accessor : impl Fn ( & D ) -> Option < String > ,
7978 subgraph_mismatch_accessor : impl Fn ( & S , usize ) -> Option < String > ,
8079 ) {
81- self . report_mismatch :: < D , S , L > (
80+ self . report_mismatch :: < D , S > (
8281 Some ( mismatched_element) ,
8382 subgraph_elements,
8483 supergraph_mismatch_accessor,
8584 subgraph_mismatch_accessor,
8685 |elt, names| format ! ( "{} in {}" , elt, names. unwrap_or( "undefined" . to_string( ) ) ) ,
8786 |elt, names| format ! ( "{elt} in {names}" ) ,
88- |myself, distribution, _ | {
87+ |myself, distribution| {
8988 let distribution_str = join_strings (
9089 distribution. iter ( ) ,
9190 JoinStringsOptions {
@@ -101,20 +100,20 @@ impl ErrorReporter {
101100 ) ;
102101 }
103102
104- pub ( crate ) fn report_mismatch_error_without_supergraph < T : Display , U > (
103+ pub ( crate ) fn report_mismatch_error_without_supergraph < T > (
105104 & mut self ,
106105 error : CompositionError ,
107106 subgraph_elements : & Sources < T > ,
108107 mismatch_accessor : impl Fn ( & T , usize ) -> Option < String > ,
109108 ) {
110- self . report_mismatch :: < String , T , U > (
109+ self . report_mismatch :: < String , T > (
111110 None ,
112111 subgraph_elements,
113112 |_| None ,
114113 mismatch_accessor,
115114 |_, _| String :: new ( ) ,
116115 |elt, names| format ! ( "{elt} in {names}" ) ,
117- |myself, distribution, _ : Vec < U > | {
116+ |myself, distribution| {
118117 let distribution_str = join_strings (
119118 distribution. iter ( ) ,
120119 JoinStringsOptions {
@@ -131,7 +130,7 @@ impl ErrorReporter {
131130 }
132131
133132 #[ allow( clippy:: too_many_arguments) ]
134- pub ( crate ) fn report_mismatch_error_with_specifics < D : Display , S , L > (
133+ pub ( crate ) fn report_mismatch_error_with_specifics < D , S > (
135134 & mut self ,
136135 error : CompositionError ,
137136 mismatched_element : & D ,
@@ -142,14 +141,14 @@ impl ErrorReporter {
142141 other_elements_printer : impl Fn ( & str , & str ) -> String ,
143142 include_missing_sources : bool ,
144143 ) {
145- self . report_mismatch :: < D , S , L > (
144+ self . report_mismatch :: < D , S > (
146145 Some ( mismatched_element) ,
147146 subgraph_elements,
148147 supergraph_mismatch_accessor,
149148 subgraph_mismatch_accessor,
150149 supergraph_element_printer,
151150 other_elements_printer,
152- |myself, mut distribution, _ | {
151+ |myself, mut distribution| {
153152 let mut distribution_str = distribution. remove ( 0 ) ;
154153 distribution_str. push_str ( & join_strings (
155154 distribution. iter ( ) ,
@@ -167,7 +166,7 @@ impl ErrorReporter {
167166 }
168167
169168 #[ allow( clippy:: too_many_arguments) ]
170- pub ( crate ) fn report_mismatch_hint < D : Display , S , L > (
169+ pub ( crate ) fn report_mismatch_hint < D , S > (
171170 & mut self ,
172171 code : HintCode ,
173172 message : String ,
@@ -180,14 +179,14 @@ impl ErrorReporter {
180179 include_missing_sources : bool ,
181180 no_end_of_message_dot : bool ,
182181 ) {
183- self . report_mismatch :: < D , S , L > (
182+ self . report_mismatch :: < D , S > (
184183 Some ( supergraph_element) ,
185184 subgraph_elements,
186185 supergraph_element_to_string,
187186 subgraph_element_to_string,
188187 supergraph_element_printer,
189188 other_elements_printer,
190- |myself, mut distribution, _ | {
189+ |myself, mut distribution| {
191190 let mut distribution_str = distribution. remove ( 0 ) ;
192191 distribution_str. push_str ( & join_strings (
193192 distribution. iter ( ) ,
@@ -211,11 +210,8 @@ impl ErrorReporter {
211210
212211 /// Reports a mismatch between a supergraph element and subgraph elements.
213212 /// Not meant to be used directly: use `report_mismatch_error` or `report_mismatch_hint` instead.
214- ///
215- /// TODO: The generic parameter `L` is meant to represent AST nodes (or locations) that are attached to error messages.
216- /// When we decide on an implementation for those, they should be added to `ast_nodes` below.
217213 #[ allow( clippy:: too_many_arguments) ]
218- fn report_mismatch < D : Display , S , L > (
214+ fn report_mismatch < D , S > (
219215 & mut self ,
220216 supergraph_element : Option < & D > ,
221217 subgraph_elements : & Sources < S > ,
@@ -227,12 +223,10 @@ impl ErrorReporter {
227223 subgraph_mismatch_accessor : impl Fn ( & S , usize ) -> Option < String > ,
228224 supergraph_element_printer : impl Fn ( & str , Option < String > ) -> String ,
229225 other_elements_printer : impl Fn ( & str , & str ) -> String ,
230- reporter : impl FnOnce ( & mut Self , Vec < String > , Vec < L > ) ,
226+ reporter : impl FnOnce ( & mut Self , Vec < String > ) ,
231227 include_missing_sources : bool ,
232228 ) {
233229 let mut distribution_map = Default :: default ( ) ;
234- #[ allow( unused_mut) ] // We need this to be mutable when we decide how to handle AST nodes
235- let mut locations: Vec < L > = Vec :: new ( ) ;
236230 let process_subgraph_element =
237231 |name : & str ,
238232 idx : usize ,
@@ -244,7 +238,6 @@ impl ErrorReporter {
244238 . or_default ( )
245239 . push ( name. to_string ( ) ) ;
246240 }
247- // TODO: Get AST node equivalent and push onto `locations`
248241 } ;
249242 if include_missing_sources {
250243 for ( i, name) in self . names . iter ( ) . enumerate ( ) {
@@ -267,13 +260,11 @@ impl ErrorReporter {
267260 let supergraph_mismatch = supergraph_element
268261 . and_then ( supergraph_mismatch_accessor)
269262 . unwrap_or_default ( ) ;
270- assert ! (
271- distribution_map. len( ) > 1 ,
272- "Should not have been called for {}" ,
273- supergraph_element
274- . map( |elt| elt. to_string( ) )
275- . unwrap_or_else( || "undefined" . to_string( ) )
276- ) ;
263+ if distribution_map. len ( ) <= 1 {
264+ tracing:: warn!(
265+ "report_mismatch called but no mismatch found for element {supergraph_mismatch}" ,
266+ ) ;
267+ }
277268 let mut distribution = Vec :: new ( ) ;
278269 let subgraphs_like_supergraph = distribution_map. get ( & supergraph_mismatch) ;
279270 // We always add the "supergraph" first (proper formatting of hints rely on this in particular)
@@ -288,6 +279,6 @@ impl ErrorReporter {
288279 let names_str = human_readable_subgraph_names ( names. iter ( ) ) ;
289280 distribution. push ( other_elements_printer ( v, & names_str) ) ;
290281 }
291- reporter ( self , distribution, locations ) ;
282+ reporter ( self , distribution) ;
292283 }
293284}
0 commit comments