Skip to content

Point at def span in "impl has stricter requirements" diagnostic #46801

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions src/librustc/traits/error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -484,19 +484,16 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
-> DiagnosticBuilder<'tcx>
{
let msg = "impl has stricter requirements than trait";
let mut err = struct_span_err!(self.tcx.sess,
error_span,
E0276,
"{}", msg);
let sp = self.tcx.sess.codemap().def_span(error_span);

let mut err = struct_span_err!(self.tcx.sess, sp, E0276, "{}", msg);

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

err.span_label(
error_span,
format!("impl has extra requirement {}", requirement));
err.span_label(sp, format!("impl has extra requirement {}", requirement));

err
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/compare-method/proj-outlives-region.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ error[E0276]: impl has stricter requirements than trait
| --------------------- definition of `foo` from trait
...
19 | fn foo() where U: 'a { } //~ ERROR E0276
| ^^^^^^^^^^^^^^^^^^^^^^^^ impl has extra requirement `U: 'a`
| ^^^^^^^^^^^^^^^^^^^^ impl has extra requirement `U: 'a`

error: aborting due to previous error

11 changes: 4 additions & 7 deletions src/test/ui/compare-method/region-extra-2.stderr
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
error[E0276]: impl has stricter requirements than trait
--> $DIR/region-extra-2.rs:19:5
|
15 | fn renew<'b: 'a>(self) -> &'b mut [T];
| -------------------------------------- definition of `renew` from trait
15 | fn renew<'b: 'a>(self) -> &'b mut [T];
| -------------------------------------- definition of `renew` from trait
...
19 | / fn renew<'b: 'a>(self) -> &'b mut [T] where 'a: 'b {
20 | | //~^ ERROR E0276
21 | | &mut self[..]
22 | | }
| |_____^ impl has extra requirement `'a: 'b`
19 | fn renew<'b: 'a>(self) -> &'b mut [T] where 'a: 'b {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl has extra requirement `'a: 'b`

error: aborting due to previous error

2 changes: 1 addition & 1 deletion src/test/ui/compare-method/region-extra.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ error[E0276]: impl has stricter requirements than trait
| --------- definition of `foo` from trait
...
19 | fn foo() where 'a: 'b { } //~ ERROR impl has stricter
| ^^^^^^^^^^^^^^^^^^^^^^^^^ impl has extra requirement `'a: 'b`
| ^^^^^^^^^^^^^^^^^^^^^ impl has extra requirement `'a: 'b`

error: aborting due to previous error

2 changes: 1 addition & 1 deletion src/test/ui/compare-method/region-unrelated.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ error[E0276]: impl has stricter requirements than trait
| --------------------- definition of `foo` from trait
...
19 | fn foo() where V: 'a { }
| ^^^^^^^^^^^^^^^^^^^^^^^^ impl has extra requirement `V: 'a`
| ^^^^^^^^^^^^^^^^^^^^ impl has extra requirement `V: 'a`

error: aborting due to previous error

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

error: aborting due to previous error

14 changes: 7 additions & 7 deletions src/test/ui/compare-method/traits-misc-mismatch-1.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ error[E0276]: impl has stricter requirements than trait
| -------------------------------- definition of `test_error1_fn` from trait
...
36 | fn test_error1_fn<T: Ord>(&self) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl has extra requirement `T: std::cmp::Ord`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl has extra requirement `T: std::cmp::Ord`

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

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

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

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

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

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

error: aborting due to 7 previous errors

11 changes: 4 additions & 7 deletions src/test/ui/compare-method/traits-misc-mismatch-2.stderr
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
error[E0276]: impl has stricter requirements than trait
--> $DIR/traits-misc-mismatch-2.rs:23:5
|
19 | fn zip<B, U: Iterator<U>>(self, other: U) -> ZipIterator<Self, U>;
| ------------------------------------------------------------------ definition of `zip` from trait
19 | fn zip<B, U: Iterator<U>>(self, other: U) -> ZipIterator<Self, U>;
| ------------------------------------------------------------------ definition of `zip` from trait
...
23 | / fn zip<B, U: Iterator<B>>(self, other: U) -> ZipIterator<T, U> {
24 | | //~^ ERROR E0276
25 | | ZipIterator{a: self, b: other}
26 | | }
| |_____^ impl has extra requirement `U: Iterator<B>`
23 | fn zip<B, U: Iterator<B>>(self, other: U) -> ZipIterator<T, U> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl has extra requirement `U: Iterator<B>`

error: aborting due to previous error