Skip to content

Commit 7173fd7

Browse files
committed
in unit tests, use note to dump multiple program clauses
(rather than issuing multiple errors) Also, reorder so that the annotations are considered "used" when the lint runs.
1 parent 94639ca commit 7173fd7

File tree

10 files changed

+61
-110
lines changed

10 files changed

+61
-110
lines changed

src/librustc_driver/driver.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,6 +1155,10 @@ where
11551155
}
11561156
});
11571157

1158+
time(sess, "dumping chalk-like clauses", || {
1159+
rustc_traits::lowering::dump_program_clauses(tcx);
1160+
});
1161+
11581162
time(sess, "MIR effect checking", || {
11591163
for def_id in tcx.body_owners() {
11601164
mir::transform::check_unsafety::check_unsafety(tcx, def_id)
@@ -1178,10 +1182,6 @@ where
11781182

11791183
time(sess, "lint checking", || lint::check_crate(tcx));
11801184

1181-
time(sess, "dumping chalk-like clauses", || {
1182-
rustc_traits::lowering::dump_program_clauses(tcx)
1183-
});
1184-
11851185
return Ok(f(tcx, analysis, rx, tcx.sess.compile_status()));
11861186
},
11871187
)

src/librustc_traits/lowering.rs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -319,19 +319,32 @@ impl<'a, 'tcx> ClauseDumper<'a, 'tcx> {
319319
fn process_attrs(&mut self, node_id: ast::NodeId, attrs: &[ast::Attribute]) {
320320
let def_id = self.tcx.hir.local_def_id(node_id);
321321
for attr in attrs {
322+
let mut clauses = None;
323+
322324
if attr.check_name("rustc_dump_program_clauses") {
323-
let clauses = self.tcx.program_clauses_for(def_id);
324-
for clause in *clauses {
325+
clauses = Some(self.tcx.program_clauses_for(def_id));
326+
}
327+
328+
if attr.check_name("rustc_dump_env_program_clauses") {
329+
let param_env = self.tcx.param_env(def_id);
330+
clauses = Some(self.tcx.program_clauses_for_env(param_env));
331+
}
332+
333+
if let Some(clauses) = clauses {
334+
let mut err = self.tcx
335+
.sess
336+
.struct_span_err(attr.span, "program clause dump");
337+
338+
for clause in clauses.iter() {
325339
// Skip the top-level binder for a less verbose output
326340
let program_clause = match clause {
327341
Clause::Implies(program_clause) => program_clause,
328342
Clause::ForAll(program_clause) => program_clause.skip_binder(),
329343
};
330-
self.tcx
331-
.sess
332-
.struct_span_err(attr.span, &format!("{}", program_clause))
333-
.emit();
344+
err.note(&format!("{}", program_clause));
334345
}
346+
347+
err.emit();
335348
}
336349
}
337350
}

src/test/ui/chalkify/lower_impl.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@
1212

1313
trait Foo { }
1414

15-
#[rustc_dump_program_clauses] //~ ERROR Implemented(T: Foo) :-
15+
#[rustc_dump_program_clauses] //~ ERROR program clause dump
1616
impl<T: 'static> Foo for T where T: Iterator<Item = i32> { }
1717

1818
trait Bar {
1919
type Assoc;
2020
}
2121

2222
impl<T> Bar for T where T: Iterator<Item = i32> {
23-
#[rustc_dump_program_clauses] //~ ERROR Normalize(<T as Bar>::Assoc == std::vec::Vec<T>) :-
23+
#[rustc_dump_program_clauses] //~ ERROR program clause dump
2424
type Assoc = Vec<T>;
2525
}
2626

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1-
error: Implemented(T: Foo) :- ProjectionEq(<T as std::iter::Iterator>::Item == i32), TypeOutlives(T : 'static), Implemented(T: std::iter::Iterator), Implemented(T: std::marker::Sized).
1+
error: program clause dump
22
--> $DIR/lower_impl.rs:15:1
33
|
4-
LL | #[rustc_dump_program_clauses] //~ ERROR Implemented(T: Foo) :-
4+
LL | #[rustc_dump_program_clauses] //~ ERROR program clause dump
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: Implemented(T: Foo) :- ProjectionEq(<T as std::iter::Iterator>::Item == i32), TypeOutlives(T : 'static), Implemented(T: std::iter::Iterator), Implemented(T: std::marker::Sized).
68

7-
error: Normalize(<T as Bar>::Assoc == std::vec::Vec<T>) :- Implemented(T: Bar).
9+
error: program clause dump
810
--> $DIR/lower_impl.rs:23:5
911
|
10-
LL | #[rustc_dump_program_clauses] //~ ERROR Normalize(<T as Bar>::Assoc == std::vec::Vec<T>) :-
12+
LL | #[rustc_dump_program_clauses] //~ ERROR program clause dump
1113
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14+
|
15+
= note: Normalize(<T as Bar>::Assoc == std::vec::Vec<T>) :- Implemented(T: Bar).
1216

1317
error: aborting due to 2 previous errors
1418

src/test/ui/chalkify/lower_trait.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@
1010

1111
#![feature(rustc_attrs)]
1212

13-
#[rustc_dump_program_clauses] //~ ERROR Implemented(Self: Foo<S, T, U>) :-
14-
//~| ERROR FromEnv
15-
//~| ERROR FromEnv
16-
//~| ERROR FromEnv
13+
#[rustc_dump_program_clauses] //~ ERROR program clause dump
1714
trait Foo<S, T, U> {
1815
fn s(S) -> S;
1916
fn t(T) -> T;
Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,13 @@
1-
error: Implemented(Self: Foo<S, T, U>) :- FromEnv(Self: Foo<S, T, U>).
1+
error: program clause dump
22
--> $DIR/lower_trait.rs:13:1
33
|
4-
LL | #[rustc_dump_program_clauses] //~ ERROR Implemented(Self: Foo<S, T, U>) :-
4+
LL | #[rustc_dump_program_clauses] //~ ERROR program clause dump
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6-
7-
error: FromEnv(S: std::marker::Sized) :- FromEnv(Self: Foo<S, T, U>).
8-
--> $DIR/lower_trait.rs:13:1
9-
|
10-
LL | #[rustc_dump_program_clauses] //~ ERROR Implemented(Self: Foo<S, T, U>) :-
11-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12-
13-
error: FromEnv(T: std::marker::Sized) :- FromEnv(Self: Foo<S, T, U>).
14-
--> $DIR/lower_trait.rs:13:1
156
|
16-
LL | #[rustc_dump_program_clauses] //~ ERROR Implemented(Self: Foo<S, T, U>) :-
17-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18-
19-
error: FromEnv(U: std::marker::Sized) :- FromEnv(Self: Foo<S, T, U>).
20-
--> $DIR/lower_trait.rs:13:1
21-
|
22-
LL | #[rustc_dump_program_clauses] //~ ERROR Implemented(Self: Foo<S, T, U>) :-
23-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7+
= note: Implemented(Self: Foo<S, T, U>) :- FromEnv(Self: Foo<S, T, U>).
8+
= note: FromEnv(S: std::marker::Sized) :- FromEnv(Self: Foo<S, T, U>).
9+
= note: FromEnv(T: std::marker::Sized) :- FromEnv(Self: Foo<S, T, U>).
10+
= note: FromEnv(U: std::marker::Sized) :- FromEnv(Self: Foo<S, T, U>).
2411

25-
error: aborting due to 4 previous errors
12+
error: aborting due to previous error
2613

src/test/ui/chalkify/lower_trait_higher_rank.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@
1010

1111
#![feature(rustc_attrs)]
1212

13-
#[rustc_dump_program_clauses] //~ ERROR Implemented(Self: Foo<F>) :-
14-
//~| ERROR FromEnv
15-
//~| ERROR FromEnv
16-
//~| ERROR FromEnv
13+
#[rustc_dump_program_clauses] //~ ERROR program clause dump
1714
trait Foo<F> where for<'a> F: Fn(&'a (u8, u16)) -> &'a u8
1815
{
1916
fn s(F) -> F;
Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,13 @@
1-
error: Implemented(Self: Foo<F>) :- FromEnv(Self: Foo<F>).
1+
error: program clause dump
22
--> $DIR/lower_trait_higher_rank.rs:13:1
33
|
4-
LL | #[rustc_dump_program_clauses] //~ ERROR Implemented(Self: Foo<F>) :-
4+
LL | #[rustc_dump_program_clauses] //~ ERROR program clause dump
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6-
7-
error: FromEnv(F: std::marker::Sized) :- FromEnv(Self: Foo<F>).
8-
--> $DIR/lower_trait_higher_rank.rs:13:1
9-
|
10-
LL | #[rustc_dump_program_clauses] //~ ERROR Implemented(Self: Foo<F>) :-
11-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12-
13-
error: FromEnv(F: std::ops::Fn<(&'a (u8, u16),)>) :- FromEnv(Self: Foo<F>).
14-
--> $DIR/lower_trait_higher_rank.rs:13:1
156
|
16-
LL | #[rustc_dump_program_clauses] //~ ERROR Implemented(Self: Foo<F>) :-
17-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18-
19-
error: FromEnv(<F as std::ops::FnOnce<(&'a (u8, u16),)>>::Output == &'a u8) :- FromEnv(Self: Foo<F>).
20-
--> $DIR/lower_trait_higher_rank.rs:13:1
21-
|
22-
LL | #[rustc_dump_program_clauses] //~ ERROR Implemented(Self: Foo<F>) :-
23-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7+
= note: Implemented(Self: Foo<F>) :- FromEnv(Self: Foo<F>).
8+
= note: FromEnv(F: std::marker::Sized) :- FromEnv(Self: Foo<F>).
9+
= note: FromEnv(F: std::ops::Fn<(&'a (u8, u16),)>) :- FromEnv(Self: Foo<F>).
10+
= note: FromEnv(<F as std::ops::FnOnce<(&'a (u8, u16),)>>::Output == &'a u8) :- FromEnv(Self: Foo<F>).
2411

25-
error: aborting due to 4 previous errors
12+
error: aborting due to previous error
2613

src/test/ui/chalkify/lower_trait_where_clause.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,7 @@
1313
use std::fmt::{Debug, Display};
1414
use std::borrow::Borrow;
1515

16-
#[rustc_dump_program_clauses] //~ ERROR Implemented(Self: Foo<'a, 'b, S, T, U>) :-
17-
//~| ERROR FromEnv
18-
//~| ERROR FromEnv
19-
//~| ERROR FromEnv
20-
//~| ERROR FromEnv
21-
//~| ERROR RegionOutlives
22-
//~| ERROR TypeOutlives
16+
#[rustc_dump_program_clauses] //~ ERROR program clause dump
2317
trait Foo<'a, 'b, S, T, U> where S: Debug, T: Borrow<U>, U: ?Sized, 'a: 'b, U: 'b {
2418
fn s(S) -> S;
2519
fn t(T) -> T;
Lines changed: 11 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,16 @@
1-
error: Implemented(Self: Foo<'a, 'b, S, T, U>) :- FromEnv(Self: Foo<'a, 'b, S, T, U>).
1+
error: program clause dump
22
--> $DIR/lower_trait_where_clause.rs:16:1
33
|
4-
LL | #[rustc_dump_program_clauses] //~ ERROR Implemented(Self: Foo<'a, 'b, S, T, U>) :-
4+
LL | #[rustc_dump_program_clauses] //~ ERROR program clause dump
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6-
7-
error: FromEnv(S: std::marker::Sized) :- FromEnv(Self: Foo<'a, 'b, S, T, U>).
8-
--> $DIR/lower_trait_where_clause.rs:16:1
9-
|
10-
LL | #[rustc_dump_program_clauses] //~ ERROR Implemented(Self: Foo<'a, 'b, S, T, U>) :-
11-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12-
13-
error: FromEnv(T: std::marker::Sized) :- FromEnv(Self: Foo<'a, 'b, S, T, U>).
14-
--> $DIR/lower_trait_where_clause.rs:16:1
15-
|
16-
LL | #[rustc_dump_program_clauses] //~ ERROR Implemented(Self: Foo<'a, 'b, S, T, U>) :-
17-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18-
19-
error: FromEnv(S: std::fmt::Debug) :- FromEnv(Self: Foo<'a, 'b, S, T, U>).
20-
--> $DIR/lower_trait_where_clause.rs:16:1
21-
|
22-
LL | #[rustc_dump_program_clauses] //~ ERROR Implemented(Self: Foo<'a, 'b, S, T, U>) :-
23-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24-
25-
error: FromEnv(T: std::borrow::Borrow<U>) :- FromEnv(Self: Foo<'a, 'b, S, T, U>).
26-
--> $DIR/lower_trait_where_clause.rs:16:1
27-
|
28-
LL | #[rustc_dump_program_clauses] //~ ERROR Implemented(Self: Foo<'a, 'b, S, T, U>) :-
29-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
30-
31-
error: RegionOutlives('a : 'b) :- FromEnv(Self: Foo<'a, 'b, S, T, U>).
32-
--> $DIR/lower_trait_where_clause.rs:16:1
336
|
34-
LL | #[rustc_dump_program_clauses] //~ ERROR Implemented(Self: Foo<'a, 'b, S, T, U>) :-
35-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
36-
37-
error: TypeOutlives(U : 'b) :- FromEnv(Self: Foo<'a, 'b, S, T, U>).
38-
--> $DIR/lower_trait_where_clause.rs:16:1
39-
|
40-
LL | #[rustc_dump_program_clauses] //~ ERROR Implemented(Self: Foo<'a, 'b, S, T, U>) :-
41-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
42-
43-
error: aborting due to 7 previous errors
7+
= note: Implemented(Self: Foo<'a, 'b, S, T, U>) :- FromEnv(Self: Foo<'a, 'b, S, T, U>).
8+
= note: FromEnv(S: std::marker::Sized) :- FromEnv(Self: Foo<'a, 'b, S, T, U>).
9+
= note: FromEnv(T: std::marker::Sized) :- FromEnv(Self: Foo<'a, 'b, S, T, U>).
10+
= note: FromEnv(S: std::fmt::Debug) :- FromEnv(Self: Foo<'a, 'b, S, T, U>).
11+
= note: FromEnv(T: std::borrow::Borrow<U>) :- FromEnv(Self: Foo<'a, 'b, S, T, U>).
12+
= note: RegionOutlives('a : 'b) :- FromEnv(Self: Foo<'a, 'b, S, T, U>).
13+
= note: TypeOutlives(U : 'b) :- FromEnv(Self: Foo<'a, 'b, S, T, U>).
14+
15+
error: aborting due to previous error
4416

0 commit comments

Comments
 (0)