Skip to content

Commit 8dd10e6

Browse files
authored
Rollup merge of #46282 - estebank:impl-trait-cicle-span, r=arielb1
Shorten output of E0391 Use the shorter `def_span` on the impl-Trait cyclic reference errors.
2 parents 81ba352 + 487daab commit 8dd10e6

File tree

4 files changed

+58
-5
lines changed

4 files changed

+58
-5
lines changed

src/librustc/ty/maps/plumbing.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -81,17 +81,18 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
8181
// (And cycle errors around impls tend to occur during the
8282
// collect/coherence phases anyhow.)
8383
item_path::with_forced_impl_filename_line(|| {
84+
let span = self.sess.codemap().def_span(span);
8485
let mut err =
8586
struct_span_err!(self.sess, span, E0391,
8687
"unsupported cyclic reference between types/traits detected");
8788
err.span_label(span, "cyclic reference");
8889

89-
err.span_note(stack[0].0, &format!("the cycle begins when {}...",
90-
stack[0].1.describe(self)));
90+
err.span_note(self.sess.codemap().def_span(stack[0].0),
91+
&format!("the cycle begins when {}...", stack[0].1.describe(self)));
9192

9293
for &(span, ref query) in &stack[1..] {
93-
err.span_note(span, &format!("...which then requires {}...",
94-
query.describe(self)));
94+
err.span_note(self.sess.codemap().def_span(span),
95+
&format!("...which then requires {}...", query.describe(self)));
9596
}
9697

9798
err.note(&format!("...which then again requires {}, completing the cycle.",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
error[E0277]: the trait bound `std::rc::Rc<std::cell::Cell<i32>>: std::marker::Send` is not satisfied in `impl std::ops::Fn<(i32,)>`
2+
--> $DIR/auto-trait-leak.rs:27:5
3+
|
4+
27 | send(before());
5+
| ^^^^ `std::rc::Rc<std::cell::Cell<i32>>` cannot be sent between threads safely
6+
|
7+
= help: within `impl std::ops::Fn<(i32,)>`, the trait `std::marker::Send` is not implemented for `std::rc::Rc<std::cell::Cell<i32>>`
8+
= note: required because it appears within the type `[closure@$DIR/auto-trait-leak.rs:21:5: 21:22 p:std::rc::Rc<std::cell::Cell<i32>>]`
9+
= note: required because it appears within the type `impl std::ops::Fn<(i32,)>`
10+
= note: required by `send`
11+
12+
error[E0277]: the trait bound `std::rc::Rc<std::cell::Cell<i32>>: std::marker::Send` is not satisfied in `impl std::ops::Fn<(i32,)>`
13+
--> $DIR/auto-trait-leak.rs:34:5
14+
|
15+
34 | send(after());
16+
| ^^^^ `std::rc::Rc<std::cell::Cell<i32>>` cannot be sent between threads safely
17+
|
18+
= help: within `impl std::ops::Fn<(i32,)>`, the trait `std::marker::Send` is not implemented for `std::rc::Rc<std::cell::Cell<i32>>`
19+
= note: required because it appears within the type `[closure@$DIR/auto-trait-leak.rs:46:5: 46:22 p:std::rc::Rc<std::cell::Cell<i32>>]`
20+
= note: required because it appears within the type `impl std::ops::Fn<(i32,)>`
21+
= note: required by `send`
22+
23+
error[E0391]: unsupported cyclic reference between types/traits detected
24+
--> $DIR/auto-trait-leak.rs:52:1
25+
|
26+
52 | fn cycle1() -> impl Clone {
27+
| ^^^^^^^^^^^^^^^^^^^^^^^^^ cyclic reference
28+
|
29+
note: the cycle begins when processing `cycle1`...
30+
--> $DIR/auto-trait-leak.rs:52:1
31+
|
32+
52 | fn cycle1() -> impl Clone {
33+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
34+
note: ...which then requires processing `cycle2::{{impl-Trait}}`...
35+
--> $DIR/auto-trait-leak.rs:63:16
36+
|
37+
63 | fn cycle2() -> impl Clone {
38+
| ^^^^^^^^^^
39+
note: ...which then requires processing `cycle2`...
40+
--> $DIR/auto-trait-leak.rs:63:1
41+
|
42+
63 | fn cycle2() -> impl Clone {
43+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
44+
note: ...which then requires processing `cycle1::{{impl-Trait}}`...
45+
--> $DIR/auto-trait-leak.rs:52:16
46+
|
47+
52 | fn cycle1() -> impl Clone {
48+
| ^^^^^^^^^^
49+
= note: ...which then again requires processing `cycle1`, completing the cycle.
50+
51+
error: aborting due to 3 previous errors
52+

src/test/ui/resolve/issue-23305.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ note: the cycle begins when processing `<impl at $DIR/issue-23305.rs:15:1: 15:20
88
--> $DIR/issue-23305.rs:15:1
99
|
1010
15 | impl ToNbt<Self> {}
11-
| ^^^^^^^^^^^^^^^^^^^
11+
| ^^^^^^^^^^^^^^^^
1212
= note: ...which then again requires processing `<impl at $DIR/issue-23305.rs:15:1: 15:20>`, completing the cycle.
1313

1414
error: aborting due to previous error

0 commit comments

Comments
 (0)