Skip to content

Commit c20ba65

Browse files
committed
Guarantee rustc_dump_user_substs error order.
This commit buffers the errors output by the `rustc_dump_user_substs` attribute so that they can be output in order of span and would therefore be consistent.
1 parent 0bfe184 commit c20ba65

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

src/librustc_typeck/check/writeback.rs

+16-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// substitutions.
44

55
use check::FnCtxt;
6+
use errors::DiagnosticBuilder;
67
use rustc::hir;
78
use rustc::hir::def_id::{DefId, DefIndex};
89
use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor};
@@ -357,6 +358,7 @@ impl<'cx, 'gcx, 'tcx> WritebackCx<'cx, 'gcx, 'tcx> {
357358
debug_assert_eq!(fcx_tables.local_id_root, self.tables.local_id_root);
358359
let common_local_id_root = fcx_tables.local_id_root.unwrap();
359360

361+
let mut errors_buffer = Vec::new();
360362
for (&local_id, c_ty) in fcx_tables.user_provided_types().iter() {
361363
let hir_id = hir::HirId {
362364
owner: common_local_id_root.index,
@@ -382,10 +384,23 @@ impl<'cx, 'gcx, 'tcx> WritebackCx<'cx, 'gcx, 'tcx> {
382384
// This is a unit-testing mechanism.
383385
let node_id = self.tcx().hir().hir_to_node_id(hir_id);
384386
let span = self.tcx().hir().span(node_id);
385-
self.tcx().sess.span_err(span, &format!("user substs: {:?}", user_substs));
387+
// We need to buffer the errors in order to guarantee a consistent
388+
// order when emitting them.
389+
let err = self.tcx().sess.struct_span_err(
390+
span,
391+
&format!("user substs: {:?}", user_substs)
392+
);
393+
err.buffer(&mut errors_buffer);
386394
}
387395
}
388396
}
397+
398+
if !errors_buffer.is_empty() {
399+
errors_buffer.sort_by_key(|diag| diag.span.primary_span());
400+
for diag in errors_buffer.drain(..) {
401+
DiagnosticBuilder::new_diagnostic(self.tcx().sess.diagnostic(), diag).emit();
402+
}
403+
}
389404
}
390405

391406
fn visit_user_provided_sigs(&mut self) {
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error: user substs: UserSubsts { substs: [^0, ^1, u32], user_self_ty: None }
2-
--> $DIR/dump-fn-method.rs:44:5
1+
error: user substs: UserSubsts { substs: [u32], user_self_ty: None }
2+
--> $DIR/dump-fn-method.rs:26:13
33
|
4-
LL | y.method::<u32>(44, 66); //~ ERROR [^0, ^1, u32]
5-
| ^^^^^^^^^^^^^^^^^^^^^^^
4+
LL | let x = foo::<u32>; //~ ERROR [u32]
5+
| ^^^^^^^^^^
66

77
error: user substs: UserSubsts { substs: [^0, u32, ^1], user_self_ty: None }
88
--> $DIR/dump-fn-method.rs:32:13
@@ -16,11 +16,11 @@ error: user substs: UserSubsts { substs: [u8, u16, u32], user_self_ty: None }
1616
LL | let x = <u8 as Bazoom<u16>>::method::<u32>; //~ ERROR [u8, u16, u32]
1717
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1818

19-
error: user substs: UserSubsts { substs: [u32], user_self_ty: None }
20-
--> $DIR/dump-fn-method.rs:26:13
19+
error: user substs: UserSubsts { substs: [^0, ^1, u32], user_self_ty: None }
20+
--> $DIR/dump-fn-method.rs:44:5
2121
|
22-
LL | let x = foo::<u32>; //~ ERROR [u32]
23-
| ^^^^^^^^^^
22+
LL | y.method::<u32>(44, 66); //~ ERROR [^0, ^1, u32]
23+
| ^^^^^^^^^^^^^^^^^^^^^^^
2424

2525
error: aborting due to 4 previous errors
2626

0 commit comments

Comments
 (0)