Skip to content

Commit 12cd452

Browse files
Rollup merge of #46801 - estebank:impl-extra-req-def-span, r=arielb1
Point at def span in "impl has stricter requirements" diagnostic
2 parents 6cc58b3 + c08dab8 commit 12cd452

8 files changed

+23
-32
lines changed

src/librustc/traits/error_reporting.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -484,19 +484,16 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
484484
-> DiagnosticBuilder<'tcx>
485485
{
486486
let msg = "impl has stricter requirements than trait";
487-
let mut err = struct_span_err!(self.tcx.sess,
488-
error_span,
489-
E0276,
490-
"{}", msg);
487+
let sp = self.tcx.sess.codemap().def_span(error_span);
488+
489+
let mut err = struct_span_err!(self.tcx.sess, sp, E0276, "{}", msg);
491490

492491
if let Some(trait_item_span) = self.tcx.hir.span_if_local(trait_item_def_id) {
493492
let span = self.tcx.sess.codemap().def_span(trait_item_span);
494493
err.span_label(span, format!("definition of `{}` from trait", item_name));
495494
}
496495

497-
err.span_label(
498-
error_span,
499-
format!("impl has extra requirement {}", requirement));
496+
err.span_label(sp, format!("impl has extra requirement {}", requirement));
500497

501498
err
502499
}

src/test/ui/compare-method/proj-outlives-region.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ error[E0276]: impl has stricter requirements than trait
55
| --------------------- definition of `foo` from trait
66
...
77
19 | fn foo() where U: 'a { } //~ ERROR E0276
8-
| ^^^^^^^^^^^^^^^^^^^^^^^^ impl has extra requirement `U: 'a`
8+
| ^^^^^^^^^^^^^^^^^^^^ impl has extra requirement `U: 'a`
99

1010
error: aborting due to previous error
1111

Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
error[E0276]: impl has stricter requirements than trait
22
--> $DIR/region-extra-2.rs:19:5
33
|
4-
15 | fn renew<'b: 'a>(self) -> &'b mut [T];
5-
| -------------------------------------- definition of `renew` from trait
4+
15 | fn renew<'b: 'a>(self) -> &'b mut [T];
5+
| -------------------------------------- definition of `renew` from trait
66
...
7-
19 | / fn renew<'b: 'a>(self) -> &'b mut [T] where 'a: 'b {
8-
20 | | //~^ ERROR E0276
9-
21 | | &mut self[..]
10-
22 | | }
11-
| |_____^ impl has extra requirement `'a: 'b`
7+
19 | fn renew<'b: 'a>(self) -> &'b mut [T] where 'a: 'b {
8+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl has extra requirement `'a: 'b`
129

1310
error: aborting due to previous error
1411

src/test/ui/compare-method/region-extra.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ error[E0276]: impl has stricter requirements than trait
55
| --------- definition of `foo` from trait
66
...
77
19 | fn foo() where 'a: 'b { } //~ ERROR impl has stricter
8-
| ^^^^^^^^^^^^^^^^^^^^^^^^^ impl has extra requirement `'a: 'b`
8+
| ^^^^^^^^^^^^^^^^^^^^^ impl has extra requirement `'a: 'b`
99

1010
error: aborting due to previous error
1111

src/test/ui/compare-method/region-unrelated.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ error[E0276]: impl has stricter requirements than trait
55
| --------------------- definition of `foo` from trait
66
...
77
19 | fn foo() where V: 'a { }
8-
| ^^^^^^^^^^^^^^^^^^^^^^^^ impl has extra requirement `V: 'a`
8+
| ^^^^^^^^^^^^^^^^^^^^ impl has extra requirement `V: 'a`
99

1010
error: aborting due to previous error
1111

src/test/ui/compare-method/trait-bound-on-type-parameter.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ error[E0276]: impl has stricter requirements than trait
55
| ---------------------------- definition of `b` from trait
66
...
77
25 | fn b<F: Sync, G>(&self, _x: F) -> F { panic!() } //~ ERROR E0276
8-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl has extra requirement `F: std::marker::Sync`
8+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl has extra requirement `F: std::marker::Sync`
99

1010
error: aborting due to previous error
1111

src/test/ui/compare-method/traits-misc-mismatch-1.stderr

+7-7
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ error[E0276]: impl has stricter requirements than trait
55
| -------------------------------- definition of `test_error1_fn` from trait
66
...
77
36 | fn test_error1_fn<T: Ord>(&self) {}
8-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl has extra requirement `T: std::cmp::Ord`
8+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl has extra requirement `T: std::cmp::Ord`
99

1010
error[E0276]: impl has stricter requirements than trait
1111
--> $DIR/traits-misc-mismatch-1.rs:40:5
@@ -14,7 +14,7 @@ error[E0276]: impl has stricter requirements than trait
1414
| -------------------------------------- definition of `test_error2_fn` from trait
1515
...
1616
40 | fn test_error2_fn<T: Eq + B>(&self) {}
17-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl has extra requirement `T: B`
17+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl has extra requirement `T: B`
1818

1919
error[E0276]: impl has stricter requirements than trait
2020
--> $DIR/traits-misc-mismatch-1.rs:44:5
@@ -23,7 +23,7 @@ error[E0276]: impl has stricter requirements than trait
2323
| -------------------------------------- definition of `test_error3_fn` from trait
2424
...
2525
44 | fn test_error3_fn<T: B + Eq>(&self) {}
26-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl has extra requirement `T: B`
26+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl has extra requirement `T: B`
2727

2828
error[E0276]: impl has stricter requirements than trait
2929
--> $DIR/traits-misc-mismatch-1.rs:54:5
@@ -32,7 +32,7 @@ error[E0276]: impl has stricter requirements than trait
3232
| ------------------------------- definition of `test_error5_fn` from trait
3333
...
3434
54 | fn test_error5_fn<T: B>(&self) {}
35-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl has extra requirement `T: B`
35+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl has extra requirement `T: B`
3636

3737
error[E0276]: impl has stricter requirements than trait
3838
--> $DIR/traits-misc-mismatch-1.rs:60:5
@@ -41,7 +41,7 @@ error[E0276]: impl has stricter requirements than trait
4141
| ------------------------------- definition of `test_error7_fn` from trait
4242
...
4343
60 | fn test_error7_fn<T: A + Eq>(&self) {}
44-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl has extra requirement `T: std::cmp::Eq`
44+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl has extra requirement `T: std::cmp::Eq`
4545

4646
error[E0276]: impl has stricter requirements than trait
4747
--> $DIR/traits-misc-mismatch-1.rs:63:5
@@ -50,7 +50,7 @@ error[E0276]: impl has stricter requirements than trait
5050
| ------------------------------- definition of `test_error8_fn` from trait
5151
...
5252
63 | fn test_error8_fn<T: C>(&self) {}
53-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl has extra requirement `T: C`
53+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl has extra requirement `T: C`
5454

5555
error[E0276]: impl has stricter requirements than trait
5656
--> $DIR/traits-misc-mismatch-1.rs:76:5
@@ -59,7 +59,7 @@ error[E0276]: impl has stricter requirements than trait
5959
| ---------------------------------- definition of `method` from trait
6060
...
6161
76 | fn method<G: Getter<usize>>(&self) {}
62-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl has extra requirement `G: Getter<usize>`
62+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl has extra requirement `G: Getter<usize>`
6363

6464
error: aborting due to 7 previous errors
6565

Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
error[E0276]: impl has stricter requirements than trait
22
--> $DIR/traits-misc-mismatch-2.rs:23:5
33
|
4-
19 | fn zip<B, U: Iterator<U>>(self, other: U) -> ZipIterator<Self, U>;
5-
| ------------------------------------------------------------------ definition of `zip` from trait
4+
19 | fn zip<B, U: Iterator<U>>(self, other: U) -> ZipIterator<Self, U>;
5+
| ------------------------------------------------------------------ definition of `zip` from trait
66
...
7-
23 | / fn zip<B, U: Iterator<B>>(self, other: U) -> ZipIterator<T, U> {
8-
24 | | //~^ ERROR E0276
9-
25 | | ZipIterator{a: self, b: other}
10-
26 | | }
11-
| |_____^ impl has extra requirement `U: Iterator<B>`
7+
23 | fn zip<B, U: Iterator<B>>(self, other: U) -> ZipIterator<T, U> {
8+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl has extra requirement `U: Iterator<B>`
129

1310
error: aborting due to previous error
1411

0 commit comments

Comments
 (0)