Skip to content

Commit 5b7ffd9

Browse files
committed
Handle more cases
1 parent 190589f commit 5b7ffd9

35 files changed

+134
-91
lines changed

src/librustc/traits/error_reporting.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -969,7 +969,16 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
969969
trait_ref: &ty::PolyTraitRef<'_>,
970970
body_id: hir::HirId,
971971
) {
972-
let node = self.tcx.hir().find(self.tcx.hir().get_parent_item(body_id));
972+
let node = self.tcx.hir()
973+
.find(self.tcx.hir().get_parent_item(body_id))
974+
.or_else(|| self.tcx.hir().find(body_id));
975+
debug!(
976+
"suggest_restricting_param_bound node={:?} - trait_ref={:?} ty={:?} ({:?})",
977+
node,
978+
trait_ref,
979+
trait_ref.self_ty(),
980+
trait_ref.self_ty().kind,
981+
);
973982
if let ty::Param(param_ty) = &trait_ref.self_ty().kind {
974983
let restrict_msg = "consider further restricting this bound";
975984
let param_name = param_ty.name.as_str();

src/test/ui/builtin-superkinds/builtin-superkinds-double-superkind.stderr

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,22 @@ error[E0277]: `T` cannot be sent between threads safely
22
--> $DIR/builtin-superkinds-double-superkind.rs:6:24
33
|
44
LL | impl <T: Sync+'static> Foo for (T,) { }
5-
| ^^^ `T` cannot be sent between threads safely
5+
| -- ^^^ `T` cannot be sent between threads safely
6+
| |
7+
| help: consider further restricting this bound: `T: std::marker::Send +`
68
|
79
= help: within `(T,)`, the trait `std::marker::Send` is not implemented for `T`
8-
= help: consider adding a `where T: std::marker::Send` bound
910
= note: required because it appears within the type `(T,)`
1011

1112
error[E0277]: `T` cannot be shared between threads safely
1213
--> $DIR/builtin-superkinds-double-superkind.rs:9:16
1314
|
1415
LL | impl <T: Send> Foo for (T,T) { }
15-
| ^^^ `T` cannot be shared between threads safely
16+
| -- ^^^ `T` cannot be shared between threads safely
17+
| |
18+
| help: consider further restricting this bound: `T: std::marker::Sync +`
1619
|
1720
= help: within `(T, T)`, the trait `std::marker::Sync` is not implemented for `T`
18-
= help: consider adding a `where T: std::marker::Sync` bound
1921
= note: required because it appears within the type `(T, T)`
2022

2123
error: aborting due to 2 previous errors

src/test/ui/builtin-superkinds/builtin-superkinds-in-metadata.stderr

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ error[E0277]: `T` cannot be sent between threads safely
22
--> $DIR/builtin-superkinds-in-metadata.rs:13:23
33
|
44
LL | impl <T:Sync+'static> RequiresRequiresShareAndSend for X<T> { }
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `T` cannot be sent between threads safely
5+
| -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `T` cannot be sent between threads safely
6+
| |
7+
| help: consider further restricting this bound: `T: std::marker::Send +`
68
|
79
= help: within `X<T>`, the trait `std::marker::Send` is not implemented for `T`
8-
= help: consider adding a `where T: std::marker::Send` bound
910
= note: required because it appears within the type `X<T>`
1011

1112
error: aborting due to previous error

src/test/ui/builtin-superkinds/builtin-superkinds-typaram-not-send.stderr

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ error[E0277]: `T` cannot be sent between threads safely
22
--> $DIR/builtin-superkinds-typaram-not-send.rs:5:24
33
|
44
LL | impl <T: Sync+'static> Foo for T { }
5-
| ^^^ `T` cannot be sent between threads safely
5+
| -- ^^^ `T` cannot be sent between threads safely
6+
| |
7+
| help: consider further restricting this bound: `T: std::marker::Send +`
68
|
79
= help: the trait `std::marker::Send` is not implemented for `T`
8-
= help: consider adding a `where T: std::marker::Send` bound
910

1011
error: aborting due to previous error
1112

src/test/ui/closures/closure-bounds-cant-promote-superkind-in-struct.stderr

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@ error[E0277]: `F` cannot be sent between threads safely
44
LL | struct X<F> where F: FnOnce() + 'static + Send {
55
| ---------------------------------------------- required by `X`
66
...
7-
LL | / fn foo<F>(blk: F) -> X<F> where F: FnOnce() + 'static {
7+
LL | fn foo<F>(blk: F) -> X<F> where F: FnOnce() + 'static {
8+
| ^ - help: consider further restricting type parameter `F`: `, F: std::marker::Send`
9+
| _|
10+
| |
811
LL | |
912
LL | | return X { field: blk };
1013
LL | | }
1114
| |_^ `F` cannot be sent between threads safely
1215
|
1316
= help: the trait `std::marker::Send` is not implemented for `F`
14-
= help: consider adding a `where F: std::marker::Send` bound
1517

1618
error: aborting due to previous error
1719

src/test/ui/issues/issue-21837.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ LL | pub struct Foo<T: Bound>(T);
55
| ---------------------------- required by `Foo`
66
...
77
LL | impl<T> Trait2 for Foo<T> {}
8-
| ^^^^^^ the trait `Bound` is not implemented for `T`
9-
|
10-
= help: consider adding a `where T: Bound` bound
8+
| - ^^^^^^ the trait `Bound` is not implemented for `T`
9+
| |
10+
| help: consider restricting this bound: `T: Bound`
1111

1212
error: aborting due to previous error
1313

src/test/ui/issues/issue-27060-2.stderr

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
error[E0277]: the size for values of type `T` cannot be known at compilation time
22
--> $DIR/issue-27060-2.rs:3:5
33
|
4+
LL | pub struct Bad<T: ?Sized> {
5+
| -- help: consider further restricting this bound: `T: std::marker::Sized +`
46
LL | data: T,
57
| ^^^^^^^ doesn't have a size known at compile-time
68
|
79
= help: the trait `std::marker::Sized` is not implemented for `T`
810
= note: to learn more, visit <https://doc.rust-lang.org/book/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait>
9-
= help: consider adding a `where T: std::marker::Sized` bound
1011
= note: the last field of a packed struct may only have a dynamically sized type if it does not need drop to be run
1112

1213
error: aborting due to previous error

src/test/ui/issues/issue-43784-associated-type.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ error[E0277]: the trait bound `T: std::marker::Copy` is not satisfied
22
--> $DIR/issue-43784-associated-type.rs:13:9
33
|
44
LL | impl<T> Complete for T {
5-
| ^^^^^^^^ the trait `std::marker::Copy` is not implemented for `T`
6-
|
7-
= help: consider adding a `where T: std::marker::Copy` bound
5+
| - ^^^^^^^^ the trait `std::marker::Copy` is not implemented for `T`
6+
| |
7+
| help: consider restricting this bound: `T: std::marker::Copy`
88

99
error: aborting due to previous error
1010

src/test/ui/issues/issue-43784-supertrait.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ error[E0277]: the trait bound `T: std::marker::Copy` is not satisfied
22
--> $DIR/issue-43784-supertrait.rs:8:9
33
|
44
LL | impl<T> Complete for T {}
5-
| ^^^^^^^^ the trait `std::marker::Copy` is not implemented for `T`
6-
|
7-
= help: consider adding a `where T: std::marker::Copy` bound
5+
| - ^^^^^^^^ the trait `std::marker::Copy` is not implemented for `T`
6+
| |
7+
| help: consider restricting this bound: `T: std::marker::Copy`
88

99
error: aborting due to previous error
1010

src/test/ui/specialization/defaultimpl/specialization-wfcheck.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ error[E0277]: the trait bound `U: std::cmp::Eq` is not satisfied
22
--> $DIR/specialization-wfcheck.rs:7:17
33
|
44
LL | default impl<U> Foo<'static, U> for () {}
5-
| ^^^^^^^^^^^^^^^ the trait `std::cmp::Eq` is not implemented for `U`
6-
|
7-
= help: consider adding a `where U: std::cmp::Eq` bound
5+
| - ^^^^^^^^^^^^^^^ the trait `std::cmp::Eq` is not implemented for `U`
6+
| |
7+
| help: consider restricting this bound: `U: std::cmp::Eq`
88

99
error: aborting due to previous error
1010

0 commit comments

Comments
 (0)