Skip to content

Commit

Permalink
in unit tests, use note to dump multiple program clauses
Browse files Browse the repository at this point in the history
(rather than issuing multiple errors)

Also, reorder so that the annotations are considered "used" when the
lint runs.
  • Loading branch information
nikomatsakis committed Apr 23, 2018
1 parent 94639ca commit 7173fd7
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 110 deletions.
8 changes: 4 additions & 4 deletions src/librustc_driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1155,6 +1155,10 @@ where
}
});

time(sess, "dumping chalk-like clauses", || {
rustc_traits::lowering::dump_program_clauses(tcx);
});

time(sess, "MIR effect checking", || {
for def_id in tcx.body_owners() {
mir::transform::check_unsafety::check_unsafety(tcx, def_id)
Expand All @@ -1178,10 +1182,6 @@ where

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

time(sess, "dumping chalk-like clauses", || {
rustc_traits::lowering::dump_program_clauses(tcx)
});

return Ok(f(tcx, analysis, rx, tcx.sess.compile_status()));
},
)
Expand Down
25 changes: 19 additions & 6 deletions src/librustc_traits/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,19 +319,32 @@ impl<'a, 'tcx> ClauseDumper<'a, 'tcx> {
fn process_attrs(&mut self, node_id: ast::NodeId, attrs: &[ast::Attribute]) {
let def_id = self.tcx.hir.local_def_id(node_id);
for attr in attrs {
let mut clauses = None;

if attr.check_name("rustc_dump_program_clauses") {
let clauses = self.tcx.program_clauses_for(def_id);
for clause in *clauses {
clauses = Some(self.tcx.program_clauses_for(def_id));
}

if attr.check_name("rustc_dump_env_program_clauses") {
let param_env = self.tcx.param_env(def_id);
clauses = Some(self.tcx.program_clauses_for_env(param_env));
}

if let Some(clauses) = clauses {
let mut err = self.tcx
.sess
.struct_span_err(attr.span, "program clause dump");

for clause in clauses.iter() {
// Skip the top-level binder for a less verbose output
let program_clause = match clause {
Clause::Implies(program_clause) => program_clause,
Clause::ForAll(program_clause) => program_clause.skip_binder(),
};
self.tcx
.sess
.struct_span_err(attr.span, &format!("{}", program_clause))
.emit();
err.note(&format!("{}", program_clause));
}

err.emit();
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/chalkify/lower_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@

trait Foo { }

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

trait Bar {
type Assoc;
}

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

Expand Down
12 changes: 8 additions & 4 deletions src/test/ui/chalkify/lower_impl.stderr
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
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).
error: program clause dump
--> $DIR/lower_impl.rs:15:1
|
LL | #[rustc_dump_program_clauses] //~ ERROR Implemented(T: Foo) :-
LL | #[rustc_dump_program_clauses] //~ ERROR program clause dump
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= 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).

error: Normalize(<T as Bar>::Assoc == std::vec::Vec<T>) :- Implemented(T: Bar).
error: program clause dump
--> $DIR/lower_impl.rs:23:5
|
LL | #[rustc_dump_program_clauses] //~ ERROR Normalize(<T as Bar>::Assoc == std::vec::Vec<T>) :-
LL | #[rustc_dump_program_clauses] //~ ERROR program clause dump
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: Normalize(<T as Bar>::Assoc == std::vec::Vec<T>) :- Implemented(T: Bar).

error: aborting due to 2 previous errors

5 changes: 1 addition & 4 deletions src/test/ui/chalkify/lower_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@

#![feature(rustc_attrs)]

#[rustc_dump_program_clauses] //~ ERROR Implemented(Self: Foo<S, T, U>) :-
//~| ERROR FromEnv
//~| ERROR FromEnv
//~| ERROR FromEnv
#[rustc_dump_program_clauses] //~ ERROR program clause dump
trait Foo<S, T, U> {
fn s(S) -> S;
fn t(T) -> T;
Expand Down
27 changes: 7 additions & 20 deletions src/test/ui/chalkify/lower_trait.stderr
Original file line number Diff line number Diff line change
@@ -1,26 +1,13 @@
error: Implemented(Self: Foo<S, T, U>) :- FromEnv(Self: Foo<S, T, U>).
error: program clause dump
--> $DIR/lower_trait.rs:13:1
|
LL | #[rustc_dump_program_clauses] //~ ERROR Implemented(Self: Foo<S, T, U>) :-
LL | #[rustc_dump_program_clauses] //~ ERROR program clause dump
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: FromEnv(S: std::marker::Sized) :- FromEnv(Self: Foo<S, T, U>).
--> $DIR/lower_trait.rs:13:1
|
LL | #[rustc_dump_program_clauses] //~ ERROR Implemented(Self: Foo<S, T, U>) :-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: FromEnv(T: std::marker::Sized) :- FromEnv(Self: Foo<S, T, U>).
--> $DIR/lower_trait.rs:13:1
|
LL | #[rustc_dump_program_clauses] //~ ERROR Implemented(Self: Foo<S, T, U>) :-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: FromEnv(U: std::marker::Sized) :- FromEnv(Self: Foo<S, T, U>).
--> $DIR/lower_trait.rs:13:1
|
LL | #[rustc_dump_program_clauses] //~ ERROR Implemented(Self: Foo<S, T, U>) :-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: Implemented(Self: Foo<S, T, U>) :- FromEnv(Self: Foo<S, T, U>).
= note: FromEnv(S: std::marker::Sized) :- FromEnv(Self: Foo<S, T, U>).
= note: FromEnv(T: std::marker::Sized) :- FromEnv(Self: Foo<S, T, U>).
= note: FromEnv(U: std::marker::Sized) :- FromEnv(Self: Foo<S, T, U>).

error: aborting due to 4 previous errors
error: aborting due to previous error

5 changes: 1 addition & 4 deletions src/test/ui/chalkify/lower_trait_higher_rank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@

#![feature(rustc_attrs)]

#[rustc_dump_program_clauses] //~ ERROR Implemented(Self: Foo<F>) :-
//~| ERROR FromEnv
//~| ERROR FromEnv
//~| ERROR FromEnv
#[rustc_dump_program_clauses] //~ ERROR program clause dump
trait Foo<F> where for<'a> F: Fn(&'a (u8, u16)) -> &'a u8
{
fn s(F) -> F;
Expand Down
27 changes: 7 additions & 20 deletions src/test/ui/chalkify/lower_trait_higher_rank.stderr
Original file line number Diff line number Diff line change
@@ -1,26 +1,13 @@
error: Implemented(Self: Foo<F>) :- FromEnv(Self: Foo<F>).
error: program clause dump
--> $DIR/lower_trait_higher_rank.rs:13:1
|
LL | #[rustc_dump_program_clauses] //~ ERROR Implemented(Self: Foo<F>) :-
LL | #[rustc_dump_program_clauses] //~ ERROR program clause dump
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: FromEnv(F: std::marker::Sized) :- FromEnv(Self: Foo<F>).
--> $DIR/lower_trait_higher_rank.rs:13:1
|
LL | #[rustc_dump_program_clauses] //~ ERROR Implemented(Self: Foo<F>) :-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: FromEnv(F: std::ops::Fn<(&'a (u8, u16),)>) :- FromEnv(Self: Foo<F>).
--> $DIR/lower_trait_higher_rank.rs:13:1
|
LL | #[rustc_dump_program_clauses] //~ ERROR Implemented(Self: Foo<F>) :-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: FromEnv(<F as std::ops::FnOnce<(&'a (u8, u16),)>>::Output == &'a u8) :- FromEnv(Self: Foo<F>).
--> $DIR/lower_trait_higher_rank.rs:13:1
|
LL | #[rustc_dump_program_clauses] //~ ERROR Implemented(Self: Foo<F>) :-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: Implemented(Self: Foo<F>) :- FromEnv(Self: Foo<F>).
= note: FromEnv(F: std::marker::Sized) :- FromEnv(Self: Foo<F>).
= note: FromEnv(F: std::ops::Fn<(&'a (u8, u16),)>) :- FromEnv(Self: Foo<F>).
= note: FromEnv(<F as std::ops::FnOnce<(&'a (u8, u16),)>>::Output == &'a u8) :- FromEnv(Self: Foo<F>).

error: aborting due to 4 previous errors
error: aborting due to previous error

8 changes: 1 addition & 7 deletions src/test/ui/chalkify/lower_trait_where_clause.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,7 @@
use std::fmt::{Debug, Display};
use std::borrow::Borrow;

#[rustc_dump_program_clauses] //~ ERROR Implemented(Self: Foo<'a, 'b, S, T, U>) :-
//~| ERROR FromEnv
//~| ERROR FromEnv
//~| ERROR FromEnv
//~| ERROR FromEnv
//~| ERROR RegionOutlives
//~| ERROR TypeOutlives
#[rustc_dump_program_clauses] //~ ERROR program clause dump
trait Foo<'a, 'b, S, T, U> where S: Debug, T: Borrow<U>, U: ?Sized, 'a: 'b, U: 'b {
fn s(S) -> S;
fn t(T) -> T;
Expand Down
50 changes: 11 additions & 39 deletions src/test/ui/chalkify/lower_trait_where_clause.stderr
Original file line number Diff line number Diff line change
@@ -1,44 +1,16 @@
error: Implemented(Self: Foo<'a, 'b, S, T, U>) :- FromEnv(Self: Foo<'a, 'b, S, T, U>).
error: program clause dump
--> $DIR/lower_trait_where_clause.rs:16:1
|
LL | #[rustc_dump_program_clauses] //~ ERROR Implemented(Self: Foo<'a, 'b, S, T, U>) :-
LL | #[rustc_dump_program_clauses] //~ ERROR program clause dump
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: FromEnv(S: std::marker::Sized) :- FromEnv(Self: Foo<'a, 'b, S, T, U>).
--> $DIR/lower_trait_where_clause.rs:16:1
|
LL | #[rustc_dump_program_clauses] //~ ERROR Implemented(Self: Foo<'a, 'b, S, T, U>) :-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: FromEnv(T: std::marker::Sized) :- FromEnv(Self: Foo<'a, 'b, S, T, U>).
--> $DIR/lower_trait_where_clause.rs:16:1
|
LL | #[rustc_dump_program_clauses] //~ ERROR Implemented(Self: Foo<'a, 'b, S, T, U>) :-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: FromEnv(S: std::fmt::Debug) :- FromEnv(Self: Foo<'a, 'b, S, T, U>).
--> $DIR/lower_trait_where_clause.rs:16:1
|
LL | #[rustc_dump_program_clauses] //~ ERROR Implemented(Self: Foo<'a, 'b, S, T, U>) :-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: FromEnv(T: std::borrow::Borrow<U>) :- FromEnv(Self: Foo<'a, 'b, S, T, U>).
--> $DIR/lower_trait_where_clause.rs:16:1
|
LL | #[rustc_dump_program_clauses] //~ ERROR Implemented(Self: Foo<'a, 'b, S, T, U>) :-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: RegionOutlives('a : 'b) :- FromEnv(Self: Foo<'a, 'b, S, T, U>).
--> $DIR/lower_trait_where_clause.rs:16:1
|
LL | #[rustc_dump_program_clauses] //~ ERROR Implemented(Self: Foo<'a, 'b, S, T, U>) :-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: TypeOutlives(U : 'b) :- FromEnv(Self: Foo<'a, 'b, S, T, U>).
--> $DIR/lower_trait_where_clause.rs:16:1
|
LL | #[rustc_dump_program_clauses] //~ ERROR Implemented(Self: Foo<'a, 'b, S, T, U>) :-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 7 previous errors
= note: Implemented(Self: Foo<'a, 'b, S, T, U>) :- FromEnv(Self: Foo<'a, 'b, S, T, U>).
= note: FromEnv(S: std::marker::Sized) :- FromEnv(Self: Foo<'a, 'b, S, T, U>).
= note: FromEnv(T: std::marker::Sized) :- FromEnv(Self: Foo<'a, 'b, S, T, U>).
= note: FromEnv(S: std::fmt::Debug) :- FromEnv(Self: Foo<'a, 'b, S, T, U>).
= note: FromEnv(T: std::borrow::Borrow<U>) :- FromEnv(Self: Foo<'a, 'b, S, T, U>).
= note: RegionOutlives('a : 'b) :- FromEnv(Self: Foo<'a, 'b, S, T, U>).
= note: TypeOutlives(U : 'b) :- FromEnv(Self: Foo<'a, 'b, S, T, U>).

error: aborting due to previous error

0 comments on commit 7173fd7

Please sign in to comment.