Skip to content

Commit b218a02

Browse files
committed
Auto merge of #45519 - michaelwoerister:dedup-errors, r=arielb1
Don't emit the same compiler diagnostic twice. This PR makes the compiler filter out diagnostic messages that have already been emitted during the same compilation session.
2 parents b0b80f8 + 9736474 commit b218a02

File tree

60 files changed

+83
-154
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+83
-154
lines changed

src/Cargo.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/etc/generate-deriving-span-tests.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474

7575
ENUM_TUPLE, ENUM_STRUCT, STRUCT_FIELDS, STRUCT_TUPLE = range(4)
7676

77-
def create_test_case(type, trait, super_traits, number_of_errors):
77+
def create_test_case(type, trait, super_traits, error_count):
7878
string = [ENUM_STRING, ENUM_STRUCT_VARIANT_STRING, STRUCT_STRING, STRUCT_TUPLE_STRING][type]
7979
all_traits = ','.join([trait] + super_traits)
8080
super_traits = ','.join(super_traits)
@@ -113,7 +113,7 @@ def write_file(name, string):
113113

114114
for (trait, supers, errs) in [('Clone', [], 1),
115115
('PartialEq', [], 2),
116-
('PartialOrd', ['PartialEq'], 9),
116+
('PartialOrd', ['PartialEq'], 3),
117117
('Eq', ['PartialEq'], 1),
118118
('Ord', ['Eq', 'PartialOrd', 'PartialEq'], 1),
119119
('Debug', [], 1),

src/librustc_errors/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ crate-type = ["dylib"]
1111
[dependencies]
1212
serialize = { path = "../libserialize" }
1313
syntax_pos = { path = "../libsyntax_pos" }
14+
rustc_data_structures = { path = "../librustc_data_structures" }

src/librustc_errors/diagnostic.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use syntax_pos::{MultiSpan, Span};
1717
use snippet::Style;
1818

1919
#[must_use]
20-
#[derive(Clone, Debug, PartialEq, RustcEncodable, RustcDecodable)]
20+
#[derive(Clone, Debug, PartialEq, Hash, RustcEncodable, RustcDecodable)]
2121
pub struct Diagnostic {
2222
pub level: Level,
2323
pub message: Vec<(String, Style)>,
@@ -28,7 +28,7 @@ pub struct Diagnostic {
2828
}
2929

3030
/// For example a note attached to an error.
31-
#[derive(Clone, Debug, PartialEq, RustcEncodable, RustcDecodable)]
31+
#[derive(Clone, Debug, PartialEq, Hash, RustcEncodable, RustcDecodable)]
3232
pub struct SubDiagnostic {
3333
pub level: Level,
3434
pub message: Vec<(String, Style)>,

src/librustc_errors/lib.rs

+31-6
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@
1818
#![feature(range_contains)]
1919
#![cfg_attr(unix, feature(libc))]
2020
#![feature(conservative_impl_trait)]
21+
#![feature(i128_type)]
2122

2223
extern crate term;
2324
#[cfg(unix)]
2425
extern crate libc;
26+
extern crate rustc_data_structures;
2527
extern crate serialize as rustc_serialize;
2628
extern crate syntax_pos;
2729

@@ -31,6 +33,9 @@ use self::Level::*;
3133

3234
use emitter::{Emitter, EmitterWriter};
3335

36+
use rustc_data_structures::fx::FxHashSet;
37+
use rustc_data_structures::stable_hasher::StableHasher;
38+
3439
use std::borrow::Cow;
3540
use std::cell::{RefCell, Cell};
3641
use std::mem;
@@ -47,7 +52,7 @@ mod lock;
4752

4853
use syntax_pos::{BytePos, Loc, FileLinesResult, FileMap, FileName, MultiSpan, Span, NO_EXPANSION};
4954

50-
#[derive(Clone, Debug, PartialEq, RustcEncodable, RustcDecodable)]
55+
#[derive(Clone, Debug, PartialEq, Hash, RustcEncodable, RustcDecodable)]
5156
pub enum RenderSpan {
5257
/// A FullSpan renders with both with an initial line for the
5358
/// message, prefixed by file:linenum, followed by a summary of
@@ -61,7 +66,7 @@ pub enum RenderSpan {
6166
Suggestion(CodeSuggestion),
6267
}
6368

64-
#[derive(Clone, Debug, PartialEq, RustcEncodable, RustcDecodable)]
69+
#[derive(Clone, Debug, PartialEq, Hash, RustcEncodable, RustcDecodable)]
6570
pub struct CodeSuggestion {
6671
/// Each substitute can have multiple variants due to multiple
6772
/// applicable suggestions
@@ -86,7 +91,7 @@ pub struct CodeSuggestion {
8691
pub show_code_when_inline: bool,
8792
}
8893

89-
#[derive(Clone, Debug, PartialEq, RustcEncodable, RustcDecodable)]
94+
#[derive(Clone, Debug, PartialEq, Hash, RustcEncodable, RustcDecodable)]
9095
/// See the docs on `CodeSuggestion::substitutions`
9196
pub struct Substitution {
9297
pub span: Span,
@@ -271,6 +276,11 @@ pub struct Handler {
271276
continue_after_error: Cell<bool>,
272277
delayed_span_bug: RefCell<Option<Diagnostic>>,
273278
tracked_diagnostics: RefCell<Option<Vec<Diagnostic>>>,
279+
280+
// This set contains a hash of every diagnostic that has been emitted by
281+
// this handler. These hashes is used to avoid emitting the same error
282+
// twice.
283+
emitted_diagnostics: RefCell<FxHashSet<u128>>,
274284
}
275285

276286
impl Handler {
@@ -295,6 +305,7 @@ impl Handler {
295305
continue_after_error: Cell::new(true),
296306
delayed_span_bug: RefCell::new(None),
297307
tracked_diagnostics: RefCell::new(None),
308+
emitted_diagnostics: RefCell::new(FxHashSet()),
298309
}
299310
}
300311

@@ -559,15 +570,29 @@ impl Handler {
559570
}
560571

561572
fn emit_db(&self, db: &DiagnosticBuilder) {
573+
let diagnostic = &**db;
574+
562575
if let Some(ref mut list) = *self.tracked_diagnostics.borrow_mut() {
563-
list.push((**db).clone());
576+
list.push(diagnostic.clone());
577+
}
578+
579+
let diagnostic_hash = {
580+
use std::hash::Hash;
581+
let mut hasher = StableHasher::new();
582+
diagnostic.hash(&mut hasher);
583+
hasher.finish()
584+
};
585+
586+
// Only emit the diagnostic if we haven't already emitted an equivalent
587+
// one:
588+
if self.emitted_diagnostics.borrow_mut().insert(diagnostic_hash) {
589+
self.emitter.borrow_mut().emit(db);
564590
}
565-
self.emitter.borrow_mut().emit(db);
566591
}
567592
}
568593

569594

570-
#[derive(Copy, PartialEq, Clone, Debug, RustcEncodable, RustcDecodable)]
595+
#[derive(Copy, PartialEq, Clone, Hash, Debug, RustcEncodable, RustcDecodable)]
571596
pub enum Level {
572597
Bug,
573598
Fatal,

src/librustc_errors/snippet.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ pub struct StyledString {
203203
pub style: Style,
204204
}
205205

206-
#[derive(Copy, Clone, Debug, PartialEq, RustcEncodable, RustcDecodable)]
206+
#[derive(Copy, Clone, Debug, PartialEq, Hash, RustcEncodable, RustcDecodable)]
207207
pub enum Style {
208208
HeaderMsg,
209209
LineAndColumn,

src/test/compile-fail/E0017.rs

-6
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,9 @@ const C: i32 = 2;
1313

1414
const CR: &'static mut i32 = &mut C; //~ ERROR E0017
1515
//~| NOTE constants require immutable values
16-
//~| ERROR E0017
17-
//~| NOTE constants require immutable values
1816
static STATIC_REF: &'static mut i32 = &mut X; //~ ERROR E0017
19-
//~| NOTE statics require immutable values
20-
//~| ERROR E0017
2117
//~| NOTE statics require immutable values
2218
//~| ERROR cannot borrow
2319
static CONST_REF: &'static mut i32 = &mut C; //~ ERROR E0017
2420
//~| NOTE statics require immutable values
25-
//~| ERROR E0017
26-
//~| NOTE statics require immutable values
2721
fn main() {}

src/test/compile-fail/E0388.rs

-3
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,8 @@ static X: i32 = 1;
1212
const C: i32 = 2;
1313

1414
const CR: &'static mut i32 = &mut C; //~ ERROR E0017
15-
//~| ERROR E0017
1615
static STATIC_REF: &'static mut i32 = &mut X; //~ ERROR E0017
17-
//~| ERROR E0017
1816
//~| ERROR cannot borrow
1917
static CONST_REF: &'static mut i32 = &mut C; //~ ERROR E0017
20-
//~| ERROR E0017
2118

2219
fn main() {}

src/test/compile-fail/borrowck/borrowck-overloaded-call.rs

-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ fn f() {
6767
};
6868
let sp = &mut s;
6969
s(3); //~ ERROR cannot borrow `s` as immutable because it is also borrowed as mutable
70-
//~^ ERROR cannot borrow `s` as immutable because it is also borrowed as mutable
7170
}
7271

7372
fn g() {

src/test/compile-fail/borrowck/borrowck-unboxed-closures.rs

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
fn a<F:Fn(isize, isize) -> isize>(mut f: F) {
1212
let g = &mut f;
1313
f(1, 2); //~ ERROR cannot borrow `f` as immutable
14-
//~^ ERROR cannot borrow `f` as immutable
1514
}
1615

1716
fn b<F:FnMut(isize, isize) -> isize>(f: F) {

src/test/compile-fail/check-static-immutable-mut-slices.rs

-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,5 @@
1212

1313
static TEST: &'static mut [isize] = &mut [];
1414
//~^ ERROR references in statics may only refer to immutable values
15-
//~^^ ERROR references in statics may only refer to immutable values
1615

1716
pub fn main() { }

src/test/compile-fail/const-err.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,14 @@ fn black_box<T>(_: T) {
2424
const FOO: u8 = [5u8][1];
2525
//~^ ERROR constant evaluation error
2626
//~| index out of bounds: the len is 1 but the index is 1
27-
//~^^^ ERROR constant evaluation error
28-
//~| index out of bounds: the len is 1 but the index is 1
2927

3028
fn main() {
3129
let a = -std::i8::MIN;
3230
//~^ WARN this expression will panic at run-time
3331
//~| attempt to negate with overflow
3432
let b = 200u8 + 200u8 + 200u8;
3533
//~^ WARN this expression will panic at run-time
36-
//~| attempt to add with overflow
37-
//~^^^ WARN this expression will panic at run-time
34+
//~^^ WARN this expression will panic at run-time
3835
//~| attempt to add with overflow
3936
let c = 200u8 * 4;
4037
//~^ WARN this expression will panic at run-time

src/test/compile-fail/const-err2.rs

-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ fn main() {
2121
//~^ ERROR attempt to negate with overflow
2222
let b = 200u8 + 200u8 + 200u8;
2323
//~^ ERROR attempt to add with overflow
24-
//~| ERROR attempt to add with overflow
2524
let c = 200u8 * 4;
2625
//~^ ERROR attempt to multiply with overflow
2726
let d = 42u8 - (42u8 + 1);

src/test/compile-fail/cycle-trait-default-type-trait.rs

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
trait Foo<X = Box<Foo>> {
1515
//~^ ERROR unsupported cyclic reference
16-
//~| ERROR unsupported cyclic reference
1716
}
1817

1918
fn main() { }

src/test/compile-fail/derives-span-Clone-enum-struct-variant.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//

src/test/compile-fail/derives-span-Clone-enum.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//

src/test/compile-fail/derives-span-Clone-struct.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//

src/test/compile-fail/derives-span-Clone-tuple-struct.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//

src/test/compile-fail/derives-span-Debug-enum-struct-variant.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//

src/test/compile-fail/derives-span-Debug-enum.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//

src/test/compile-fail/derives-span-Debug-struct.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//

src/test/compile-fail/derives-span-Debug-tuple-struct.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//

src/test/compile-fail/derives-span-Default-struct.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -15,7 +15,7 @@ struct Error;
1515

1616
#[derive(Default)]
1717
struct Struct {
18-
x: Error //~ ERROR `Error: std::default::Default` is not satisfied
18+
x: Error //~ ERROR
1919
}
2020

2121
fn main() {}

src/test/compile-fail/derives-span-Default-tuple-struct.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//

src/test/compile-fail/derives-span-Eq-enum-struct-variant.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//

src/test/compile-fail/derives-span-Eq-enum.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//

src/test/compile-fail/derives-span-Eq-struct.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//

src/test/compile-fail/derives-span-Eq-tuple-struct.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//

src/test/compile-fail/derives-span-Hash-enum-struct-variant.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//

src/test/compile-fail/derives-span-Hash-enum.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//

src/test/compile-fail/derives-span-Hash-struct.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//

src/test/compile-fail/derives-span-Hash-tuple-struct.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//

src/test/compile-fail/derives-span-Ord-enum-struct-variant.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//

src/test/compile-fail/derives-span-Ord-enum.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//

src/test/compile-fail/derives-span-Ord-struct.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//

src/test/compile-fail/derives-span-Ord-tuple-struct.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//

src/test/compile-fail/derives-span-PartialEq-enum-struct-variant.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//

src/test/compile-fail/derives-span-PartialEq-enum.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//

0 commit comments

Comments
 (0)