diff --git a/compiler/rustc_mir_build/src/thir/pattern/check_match.rs b/compiler/rustc_mir_build/src/thir/pattern/check_match.rs index 317b8dc205e..205ad850c0c 100644 --- a/compiler/rustc_mir_build/src/thir/pattern/check_match.rs +++ b/compiler/rustc_mir_build/src/thir/pattern/check_match.rs @@ -390,10 +390,11 @@ fn check_arms<'p, 'tcx>( } } Useful(unreachables) => { - for set in unreachables { - for span in set { - unreachable_pattern(cx.tcx, span, id, None); - } + let mut unreachables: Vec<_> = unreachables.into_iter().flatten().collect(); + // Emit lints in the order in which they occur in the file. + unreachables.sort_unstable(); + for span in unreachables { + unreachable_pattern(cx.tcx, span, id, None); } } UsefulWithWitness(_) => bug!(), diff --git a/src/test/ui/or-patterns/exhaustiveness-unreachable-pattern.stderr b/src/test/ui/or-patterns/exhaustiveness-unreachable-pattern.stderr index 3956a42c536..e968310d108 100644 --- a/src/test/ui/or-patterns/exhaustiveness-unreachable-pattern.stderr +++ b/src/test/ui/or-patterns/exhaustiveness-unreachable-pattern.stderr @@ -76,18 +76,18 @@ error: unreachable pattern LL | (1 | 1,) => {} | ^ -error: unreachable pattern - --> $DIR/exhaustiveness-unreachable-pattern.rs:55:15 - | -LL | | 0] => {} - | ^ - error: unreachable pattern --> $DIR/exhaustiveness-unreachable-pattern.rs:53:15 | LL | | 0 | ^ +error: unreachable pattern + --> $DIR/exhaustiveness-unreachable-pattern.rs:55:15 + | +LL | | 0] => {} + | ^ + error: unreachable pattern --> $DIR/exhaustiveness-unreachable-pattern.rs:63:10 |