From aabb6043137f71c686a77bf4bda4eb37f1a9fe22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Sun, 26 Nov 2017 12:32:30 -0800 Subject: [PATCH 1/4] Move "auto trait leak" impl-trait cycle dependency test to ui --- .../impl-trait/auto-trait-leak.rs | 0 src/test/ui/impl-trait/auto-trait-leak.stderr | 70 +++++++++++++++++++ 2 files changed, 70 insertions(+) rename src/test/{compile-fail => ui}/impl-trait/auto-trait-leak.rs (100%) create mode 100644 src/test/ui/impl-trait/auto-trait-leak.stderr diff --git a/src/test/compile-fail/impl-trait/auto-trait-leak.rs b/src/test/ui/impl-trait/auto-trait-leak.rs similarity index 100% rename from src/test/compile-fail/impl-trait/auto-trait-leak.rs rename to src/test/ui/impl-trait/auto-trait-leak.rs diff --git a/src/test/ui/impl-trait/auto-trait-leak.stderr b/src/test/ui/impl-trait/auto-trait-leak.stderr new file mode 100644 index 0000000000000..90476eb2d0d7a --- /dev/null +++ b/src/test/ui/impl-trait/auto-trait-leak.stderr @@ -0,0 +1,70 @@ +error[E0277]: the trait bound `std::rc::Rc>: std::marker::Send` is not satisfied in `impl std::ops::Fn<(i32,)>` + --> $DIR/auto-trait-leak.rs:27:5 + | +27 | send(before()); + | ^^^^ `std::rc::Rc>` cannot be sent between threads safely + | + = help: within `impl std::ops::Fn<(i32,)>`, the trait `std::marker::Send` is not implemented for `std::rc::Rc>` + = note: required because it appears within the type `[closure@$DIR/auto-trait-leak.rs:21:5: 21:22 p:std::rc::Rc>]` + = note: required because it appears within the type `impl std::ops::Fn<(i32,)>` + = note: required by `send` + +error[E0277]: the trait bound `std::rc::Rc>: std::marker::Send` is not satisfied in `impl std::ops::Fn<(i32,)>` + --> $DIR/auto-trait-leak.rs:34:5 + | +34 | send(after()); + | ^^^^ `std::rc::Rc>` cannot be sent between threads safely + | + = help: within `impl std::ops::Fn<(i32,)>`, the trait `std::marker::Send` is not implemented for `std::rc::Rc>` + = note: required because it appears within the type `[closure@$DIR/auto-trait-leak.rs:46:5: 46:22 p:std::rc::Rc>]` + = note: required because it appears within the type `impl std::ops::Fn<(i32,)>` + = note: required by `send` + +error[E0391]: unsupported cyclic reference between types/traits detected + --> $DIR/auto-trait-leak.rs:52:1 + | +52 | / fn cycle1() -> impl Clone { +53 | | //~^ ERROR unsupported cyclic reference between types/traits detected +54 | | //~| cyclic reference +55 | | //~| NOTE the cycle begins when processing `cycle1`... +... | +60 | | Rc::new(Cell::new(5)) +61 | | } + | |_^ cyclic reference + | +note: the cycle begins when processing `cycle1`... + --> $DIR/auto-trait-leak.rs:52:1 + | +52 | / fn cycle1() -> impl Clone { +53 | | //~^ ERROR unsupported cyclic reference between types/traits detected +54 | | //~| cyclic reference +55 | | //~| NOTE the cycle begins when processing `cycle1`... +... | +60 | | Rc::new(Cell::new(5)) +61 | | } + | |_^ +note: ...which then requires processing `cycle2::{{impl-Trait}}`... + --> $DIR/auto-trait-leak.rs:63:16 + | +63 | fn cycle2() -> impl Clone { + | ^^^^^^^^^^ +note: ...which then requires processing `cycle2`... + --> $DIR/auto-trait-leak.rs:63:1 + | +63 | / fn cycle2() -> impl Clone { +64 | | //~^ NOTE ...which then requires processing `cycle2::{{impl-Trait}}`... +65 | | //~| NOTE ...which then requires processing `cycle2`... +66 | | send(cycle1().clone()); +67 | | +68 | | Rc::new(String::from("foo")) +69 | | } + | |_^ +note: ...which then requires processing `cycle1::{{impl-Trait}}`... + --> $DIR/auto-trait-leak.rs:52:16 + | +52 | fn cycle1() -> impl Clone { + | ^^^^^^^^^^ + = note: ...which then again requires processing `cycle1`, completing the cycle. + +error: aborting due to 3 previous errors + From 0b2d21e32b40dfc25f09db5a12864d060ac1070a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Sun, 26 Nov 2017 12:35:19 -0800 Subject: [PATCH 2/4] Make impl-trait ciclical reference error point to def_span --- src/librustc/ty/maps/plumbing.rs | 8 ++++---- src/test/ui/impl-trait/auto-trait-leak.stderr | 20 ++++--------------- 2 files changed, 8 insertions(+), 20 deletions(-) diff --git a/src/librustc/ty/maps/plumbing.rs b/src/librustc/ty/maps/plumbing.rs index 739537c7c3a71..3440282db2d66 100644 --- a/src/librustc/ty/maps/plumbing.rs +++ b/src/librustc/ty/maps/plumbing.rs @@ -86,12 +86,12 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { "unsupported cyclic reference between types/traits detected"); err.span_label(span, "cyclic reference"); - err.span_note(stack[0].0, &format!("the cycle begins when {}...", - stack[0].1.describe(self))); + err.span_note(self.sess.codemap().def_span(stack[0].0), + &format!("the cycle begins when {}...", stack[0].1.describe(self))); for &(span, ref query) in &stack[1..] { - err.span_note(span, &format!("...which then requires {}...", - query.describe(self))); + err.span_note(self.sess.codemap().def_span(span), + &format!("...which then requires {}...", query.describe(self))); } err.note(&format!("...which then again requires {}, completing the cycle.", diff --git a/src/test/ui/impl-trait/auto-trait-leak.stderr b/src/test/ui/impl-trait/auto-trait-leak.stderr index 90476eb2d0d7a..ac5c79be6a93e 100644 --- a/src/test/ui/impl-trait/auto-trait-leak.stderr +++ b/src/test/ui/impl-trait/auto-trait-leak.stderr @@ -35,14 +35,8 @@ error[E0391]: unsupported cyclic reference between types/traits detected note: the cycle begins when processing `cycle1`... --> $DIR/auto-trait-leak.rs:52:1 | -52 | / fn cycle1() -> impl Clone { -53 | | //~^ ERROR unsupported cyclic reference between types/traits detected -54 | | //~| cyclic reference -55 | | //~| NOTE the cycle begins when processing `cycle1`... -... | -60 | | Rc::new(Cell::new(5)) -61 | | } - | |_^ +52 | fn cycle1() -> impl Clone { + | ^^^^^^^^^^^^^^^^^^^^^^^^^ note: ...which then requires processing `cycle2::{{impl-Trait}}`... --> $DIR/auto-trait-leak.rs:63:16 | @@ -51,14 +45,8 @@ note: ...which then requires processing `cycle2::{{impl-Trait}}`... note: ...which then requires processing `cycle2`... --> $DIR/auto-trait-leak.rs:63:1 | -63 | / fn cycle2() -> impl Clone { -64 | | //~^ NOTE ...which then requires processing `cycle2::{{impl-Trait}}`... -65 | | //~| NOTE ...which then requires processing `cycle2`... -66 | | send(cycle1().clone()); -67 | | -68 | | Rc::new(String::from("foo")) -69 | | } - | |_^ +63 | fn cycle2() -> impl Clone { + | ^^^^^^^^^^^^^^^^^^^^^^^^^ note: ...which then requires processing `cycle1::{{impl-Trait}}`... --> $DIR/auto-trait-leak.rs:52:16 | From 8a93deca9a41e7c185b96ca55f132b18d7e22f3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Sun, 26 Nov 2017 12:37:13 -0800 Subject: [PATCH 3/4] Make main span in impl-trait ciclic reference point to def_span --- src/librustc/ty/maps/plumbing.rs | 1 + src/test/ui/impl-trait/auto-trait-leak.stderr | 10 ++-------- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/src/librustc/ty/maps/plumbing.rs b/src/librustc/ty/maps/plumbing.rs index 3440282db2d66..e292862faa05c 100644 --- a/src/librustc/ty/maps/plumbing.rs +++ b/src/librustc/ty/maps/plumbing.rs @@ -81,6 +81,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { // (And cycle errors around impls tend to occur during the // collect/coherence phases anyhow.) item_path::with_forced_impl_filename_line(|| { + let span = self.sess.codemap().def_span(span); let mut err = struct_span_err!(self.sess, span, E0391, "unsupported cyclic reference between types/traits detected"); diff --git a/src/test/ui/impl-trait/auto-trait-leak.stderr b/src/test/ui/impl-trait/auto-trait-leak.stderr index ac5c79be6a93e..1c03e9d852645 100644 --- a/src/test/ui/impl-trait/auto-trait-leak.stderr +++ b/src/test/ui/impl-trait/auto-trait-leak.stderr @@ -23,14 +23,8 @@ error[E0277]: the trait bound `std::rc::Rc>: std::marker::S error[E0391]: unsupported cyclic reference between types/traits detected --> $DIR/auto-trait-leak.rs:52:1 | -52 | / fn cycle1() -> impl Clone { -53 | | //~^ ERROR unsupported cyclic reference between types/traits detected -54 | | //~| cyclic reference -55 | | //~| NOTE the cycle begins when processing `cycle1`... -... | -60 | | Rc::new(Cell::new(5)) -61 | | } - | |_^ cyclic reference +52 | fn cycle1() -> impl Clone { + | ^^^^^^^^^^^^^^^^^^^^^^^^^ cyclic reference | note: the cycle begins when processing `cycle1`... --> $DIR/auto-trait-leak.rs:52:1 From 487daabb529b437e99342c0d49db2401376e1a71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Mon, 27 Nov 2017 06:01:16 -0800 Subject: [PATCH 4/4] Fix test --- src/test/ui/resolve/issue-23305.stderr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/ui/resolve/issue-23305.stderr b/src/test/ui/resolve/issue-23305.stderr index fda87de9b9c50..5bba9fc41e276 100644 --- a/src/test/ui/resolve/issue-23305.stderr +++ b/src/test/ui/resolve/issue-23305.stderr @@ -8,7 +8,7 @@ note: the cycle begins when processing ` $DIR/issue-23305.rs:15:1 | 15 | impl ToNbt {} - | ^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^ = note: ...which then again requires processing ``, completing the cycle. error: aborting due to previous error