Skip to content

Commit fca5c64

Browse files
committed
Point at arguments or output when fn obligations come from them, or ident when they don't
1 parent 994e5e7 commit fca5c64

File tree

42 files changed

+261
-392
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+261
-392
lines changed

src/librustc_typeck/check/wfcheck.rs

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,17 @@ fn check_associated_item(
219219
ty::AssocKind::Method => {
220220
let sig = fcx.tcx.fn_sig(item.def_id);
221221
let sig = fcx.normalize_associated_types_in(span, &sig);
222-
check_fn_or_method(tcx, fcx, span, sig, item.def_id, &mut implied_bounds);
223-
let sig_if_method = sig_if_method.expect("bad signature for method");
224-
check_method_receiver(fcx, sig_if_method, &item, self_ty);
222+
let hir_sig = sig_if_method.expect("bad signature for method");
223+
check_fn_or_method(
224+
tcx,
225+
fcx,
226+
item.ident.span,
227+
sig,
228+
hir_sig,
229+
item.def_id,
230+
&mut implied_bounds,
231+
);
232+
check_method_receiver(fcx, hir_sig, &item, self_ty);
225233
}
226234
ty::AssocKind::Type => {
227235
if item.defaultness.has_value() {
@@ -364,7 +372,11 @@ fn check_item_fn(tcx: TyCtxt<'_>, item: &hir::Item<'_>) {
364372
let sig = fcx.tcx.fn_sig(def_id);
365373
let sig = fcx.normalize_associated_types_in(item.span, &sig);
366374
let mut implied_bounds = vec![];
367-
check_fn_or_method(tcx, fcx, item.span, sig, def_id, &mut implied_bounds);
375+
let hir_sig = match &item.kind {
376+
ItemKind::Fn(sig, ..) => sig,
377+
_ => bug!("expected `ItemKind::Fn`, found `{:?}`", item.kind),
378+
};
379+
check_fn_or_method(tcx, fcx, item.ident.span, sig, hir_sig, def_id, &mut implied_bounds);
368380
implied_bounds
369381
})
370382
}
@@ -609,18 +621,23 @@ fn check_fn_or_method<'fcx, 'tcx>(
609621
fcx: &FnCtxt<'fcx, 'tcx>,
610622
span: Span,
611623
sig: ty::PolyFnSig<'tcx>,
624+
hir_sig: &hir::FnSig<'_>,
612625
def_id: DefId,
613626
implied_bounds: &mut Vec<Ty<'tcx>>,
614627
) {
615628
let sig = fcx.normalize_associated_types_in(span, &sig);
616629
let sig = fcx.tcx.liberate_late_bound_regions(def_id, &sig);
617630

618-
for input_ty in sig.inputs() {
631+
for (input_ty, span) in sig.inputs().iter().zip(hir_sig.decl.inputs.iter().map(|t| t.span)) {
619632
fcx.register_wf_obligation(&input_ty, span, ObligationCauseCode::MiscObligation);
620633
}
621634
implied_bounds.extend(sig.inputs());
622635

623-
fcx.register_wf_obligation(sig.output(), span, ObligationCauseCode::ReturnType);
636+
fcx.register_wf_obligation(
637+
sig.output(),
638+
hir_sig.decl.output.span(),
639+
ObligationCauseCode::ReturnType,
640+
);
624641

625642
// FIXME(#25759) return types should not be implied bounds
626643
implied_bounds.push(sig.output());

src/test/ui/associated-type-bounds/bad-bounds-on-assoc-in-trait.stderr

Lines changed: 20 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -9,74 +9,47 @@ LL | impl Case1 for S1 {
99
error[E0277]: `<<T as Case1>::C as std::iter::Iterator>::Item` is not an iterator
1010
--> $DIR/bad-bounds-on-assoc-in-trait.rs:36:1
1111
|
12-
LL | fn assume_case1<T: Case1>() {
13-
| ^ - help: consider further restricting the associated type: `where <<T as Case1>::C as std::iter::Iterator>::Item: std::iter::Iterator`
14-
| _|
15-
| |
16-
LL | |
17-
LL | |
18-
LL | |
19-
... |
20-
LL | | assert_c::<_, _, _, T::C>();
21-
LL | | }
22-
| |_^ `<<T as Case1>::C as std::iter::Iterator>::Item` is not an iterator
12+
LL | fn assume_case1<T: Case1>() {
13+
| ^^^^^^^^^^^^ - help: consider further restricting the associated type: `where <<T as Case1>::C as std::iter::Iterator>::Item: std::iter::Iterator`
14+
| |
15+
| `<<T as Case1>::C as std::iter::Iterator>::Item` is not an iterator
2316
|
2417
= help: the trait `std::iter::Iterator` is not implemented for `<<T as Case1>::C as std::iter::Iterator>::Item`
2518

2619
error[E0277]: `<<T as Case1>::C as std::iter::Iterator>::Item` cannot be sent between threads safely
2720
--> $DIR/bad-bounds-on-assoc-in-trait.rs:36:1
2821
|
29-
LL | trait Case1 {
30-
| ----------- required by `Case1`
22+
LL | trait Case1 {
23+
| ----------- required by `Case1`
3124
...
32-
LL | fn assume_case1<T: Case1>() {
33-
| ^ - help: consider further restricting the associated type: `where <<T as Case1>::C as std::iter::Iterator>::Item: std::marker::Send`
34-
| _|
35-
| |
36-
LL | |
37-
LL | |
38-
LL | |
39-
... |
40-
LL | | assert_c::<_, _, _, T::C>();
41-
LL | | }
42-
| |_^ `<<T as Case1>::C as std::iter::Iterator>::Item` cannot be sent between threads safely
25+
LL | fn assume_case1<T: Case1>() {
26+
| ^^^^^^^^^^^^ - help: consider further restricting the associated type: `where <<T as Case1>::C as std::iter::Iterator>::Item: std::marker::Send`
27+
| |
28+
| `<<T as Case1>::C as std::iter::Iterator>::Item` cannot be sent between threads safely
4329
|
4430
= help: the trait `std::marker::Send` is not implemented for `<<T as Case1>::C as std::iter::Iterator>::Item`
4531

4632
error[E0277]: `<<T as Case1>::C as std::iter::Iterator>::Item` cannot be shared between threads safely
4733
--> $DIR/bad-bounds-on-assoc-in-trait.rs:36:1
4834
|
49-
LL | trait Case1 {
50-
| ----------- required by `Case1`
35+
LL | trait Case1 {
36+
| ----------- required by `Case1`
5137
...
52-
LL | fn assume_case1<T: Case1>() {
53-
| ^ - help: consider further restricting the associated type: `where <<T as Case1>::C as std::iter::Iterator>::Item: std::marker::Sync`
54-
| _|
55-
| |
56-
LL | |
57-
LL | |
58-
LL | |
59-
... |
60-
LL | | assert_c::<_, _, _, T::C>();
61-
LL | | }
62-
| |_^ `<<T as Case1>::C as std::iter::Iterator>::Item` cannot be shared between threads safely
38+
LL | fn assume_case1<T: Case1>() {
39+
| ^^^^^^^^^^^^ - help: consider further restricting the associated type: `where <<T as Case1>::C as std::iter::Iterator>::Item: std::marker::Sync`
40+
| |
41+
| `<<T as Case1>::C as std::iter::Iterator>::Item` cannot be shared between threads safely
6342
|
6443
= help: the trait `std::marker::Sync` is not implemented for `<<T as Case1>::C as std::iter::Iterator>::Item`
6544

6645
error[E0277]: `<_ as Lam<&'a u8>>::App` doesn't implement `std::fmt::Debug`
6746
--> $DIR/bad-bounds-on-assoc-in-trait.rs:36:1
6847
|
69-
LL | trait Case1 {
70-
| ----------- required by `Case1`
48+
LL | trait Case1 {
49+
| ----------- required by `Case1`
7150
...
72-
LL | / fn assume_case1<T: Case1>() {
73-
LL | |
74-
LL | |
75-
LL | |
76-
... |
77-
LL | | assert_c::<_, _, _, T::C>();
78-
LL | | }
79-
| |_^ `<_ as Lam<&'a u8>>::App` cannot be formatted using `{:?}` because it doesn't implement `std::fmt::Debug`
51+
LL | fn assume_case1<T: Case1>() {
52+
| ^^^^^^^^^^^^ `<_ as Lam<&'a u8>>::App` cannot be formatted using `{:?}` because it doesn't implement `std::fmt::Debug`
8053
|
8154
= help: the trait `for<'a> std::fmt::Debug` is not implemented for `<_ as Lam<&'a u8>>::App`
8255

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

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
error[E0277]: `F` cannot be sent between threads safely
2-
--> $DIR/closure-bounds-cant-promote-superkind-in-struct.rs:5:1
2+
--> $DIR/closure-bounds-cant-promote-superkind-in-struct.rs:5:22
33
|
4-
LL | struct X<F> where F: FnOnce() + 'static + Send {
5-
| ---------------------------------------------- required by `X`
4+
LL | struct X<F> where F: FnOnce() + 'static + Send {
5+
| ---------------------------------------------- required by `X`
66
...
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-
| |
11-
LL | |
12-
LL | | return X { field: blk };
13-
LL | | }
14-
| |_^ `F` cannot be sent between threads safely
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+
| `F` cannot be sent between threads safely
1511
|
1612
= help: the trait `std::marker::Send` is not implemented for `F`
1713

src/test/ui/error-codes/E0038.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
error[E0038]: the trait `Trait` cannot be made into an object
2-
--> $DIR/E0038.rs:5:1
2+
--> $DIR/E0038.rs:5:16
33
|
44
LL | fn foo(&self) -> Self;
55
| --- method `foo` references the `Self` type in its parameters or return type
66
...
77
LL | fn call_foo(x: Box<dyn Trait>) {
8-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Trait` cannot be made into an object
8+
| ^^^^^^^^^^^^^^ the trait `Trait` cannot be made into an object
99

1010
error: aborting due to previous error
1111

src/test/ui/feature-gates/feature-gate-object_safe_for_dispatch.stderr

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,37 @@
11
error[E0038]: the trait `NonObjectSafe1` cannot be made into an object
2-
--> $DIR/feature-gate-object_safe_for_dispatch.rs:18:1
2+
--> $DIR/feature-gate-object_safe_for_dispatch.rs:18:38
33
|
44
LL | fn takes_non_object_safe_ref<T>(obj: &dyn NonObjectSafe1) {
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `NonObjectSafe1` cannot be made into an object
5+
| ^^^^^^^^^^^^^^^^^^^ the trait `NonObjectSafe1` cannot be made into an object
66
|
77
= note: the trait cannot require that `Self : Sized`
88

99
error[E0038]: the trait `NonObjectSafe2` cannot be made into an object
10-
--> $DIR/feature-gate-object_safe_for_dispatch.rs:22:1
10+
--> $DIR/feature-gate-object_safe_for_dispatch.rs:22:36
1111
|
1212
LL | fn static_fn() {}
1313
| --------- associated function `static_fn` has no `self` parameter
1414
...
1515
LL | fn return_non_object_safe_ref() -> &'static dyn NonObjectSafe2 {
16-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `NonObjectSafe2` cannot be made into an object
16+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `NonObjectSafe2` cannot be made into an object
1717

1818
error[E0038]: the trait `NonObjectSafe3` cannot be made into an object
19-
--> $DIR/feature-gate-object_safe_for_dispatch.rs:27:1
19+
--> $DIR/feature-gate-object_safe_for_dispatch.rs:27:35
2020
|
2121
LL | fn foo<T>(&self);
2222
| --- method `foo` has generic type parameters
2323
...
2424
LL | fn takes_non_object_safe_box(obj: Box<dyn NonObjectSafe3>) {
25-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `NonObjectSafe3` cannot be made into an object
25+
| ^^^^^^^^^^^^^^^^^^^^^^^ the trait `NonObjectSafe3` cannot be made into an object
2626

2727
error[E0038]: the trait `NonObjectSafe4` cannot be made into an object
28-
--> $DIR/feature-gate-object_safe_for_dispatch.rs:31:1
28+
--> $DIR/feature-gate-object_safe_for_dispatch.rs:31:35
2929
|
3030
LL | fn foo(&self, &Self);
3131
| --- method `foo` references the `Self` type in its parameters or return type
3232
...
3333
LL | fn return_non_object_safe_rc() -> std::rc::Rc<dyn NonObjectSafe4> {
34-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `NonObjectSafe4` cannot be made into an object
34+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `NonObjectSafe4` cannot be made into an object
3535

3636
error[E0038]: the trait `NonObjectSafe1` cannot be made into an object
3737
--> $DIR/feature-gate-object_safe_for_dispatch.rs:38:6

src/test/ui/generic-associated-types/iterable.stderr

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,33 +25,27 @@ LL | type Item<'a> where T: 'a = <std::slice::Iter<'a, T> as Iterator>::Item
2525
= note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html
2626

2727
error[E0271]: type mismatch resolving `for<'a> <<std::vec::Vec<T> as Iterable>::Iter<'a> as std::iter::Iterator>::Item == <std::vec::Vec<T> as Iterable>::Item<'a>`
28-
--> $DIR/iterable.rs:19:5
28+
--> $DIR/iterable.rs:19:30
2929
|
30-
LL | trait Iterable {
31-
| -------------- required by `Iterable`
30+
LL | trait Iterable {
31+
| -------------- required by `Iterable`
3232
...
33-
LL | / fn iter<'a>(&'a self) -> Self::Iter<'a> {
34-
LL | |
35-
LL | | self.iter()
36-
LL | | }
37-
| |_____^ expected associated type, found reference
33+
LL | fn iter<'a>(&'a self) -> Self::Iter<'a> {
34+
| ^^^^^^^^^^^^^^ expected associated type, found reference
3835
|
3936
= note: expected associated type `<std::vec::Vec<T> as Iterable>::Item<'_>`
4037
found reference `&T`
4138
= note: consider constraining the associated type `<std::vec::Vec<T> as Iterable>::Item<'_>` to `&_` or calling a method that returns `<std::vec::Vec<T> as Iterable>::Item<'_>`
4239
= note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html
4340

4441
error[E0271]: type mismatch resolving `for<'a> <<[T] as Iterable>::Iter<'a> as std::iter::Iterator>::Item == <[T] as Iterable>::Item<'a>`
45-
--> $DIR/iterable.rs:31:5
42+
--> $DIR/iterable.rs:31:30
4643
|
47-
LL | trait Iterable {
48-
| -------------- required by `Iterable`
44+
LL | trait Iterable {
45+
| -------------- required by `Iterable`
4946
...
50-
LL | / fn iter<'a>(&'a self) -> Self::Iter<'a> {
51-
LL | |
52-
LL | | self.iter()
53-
LL | | }
54-
| |_____^ expected associated type, found reference
47+
LL | fn iter<'a>(&'a self) -> Self::Iter<'a> {
48+
| ^^^^^^^^^^^^^^ expected associated type, found reference
5549
|
5650
= note: expected associated type `<[T] as Iterable>::Item<'_>`
5751
found reference `&T`

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
error[E0277]: the size for values of type `dyn for<'r> std::ops::Fn(&'r isize) -> isize` cannot be known at compilation time
2-
--> $DIR/issue-18919.rs:3:1
2+
--> $DIR/issue-18919.rs:3:15
33
|
4-
LL | / fn ho_func(f: Option<FuncType>) {
5-
LL | |
6-
LL | | }
7-
| |_^ doesn't have a size known at compile-time
4+
LL | fn ho_func(f: Option<FuncType>) {
5+
| ^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
86
|
97
= help: the trait `std::marker::Sized` is not implemented for `dyn for<'r> std::ops::Fn(&'r isize) -> isize`
108
= note: to learn more, visit <https://doc.rust-lang.org/book/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait>

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
error[E0038]: the trait `Bar` cannot be made into an object
2-
--> $DIR/issue-18959.rs:11:1
2+
--> $DIR/issue-18959.rs:11:11
33
|
44
LL | pub trait Foo { fn foo<T>(&self, ext_thing: &T); }
55
| --- method `foo` has generic type parameters
66
...
77
LL | fn foo(b: &dyn Bar) {
8-
| ^^^^^^^^^^^^^^^^^^^ the trait `Bar` cannot be made into an object
8+
| ^^^^^^^^ the trait `Bar` cannot be made into an object
99

1010
error: aborting due to previous error
1111

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

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
error[E0277]: the size for values of type `Self` cannot be known at compilation time
2-
--> $DIR/issue-20005.rs:8:5
2+
--> $DIR/issue-20005.rs:8:8
33
|
4-
LL | trait From<Src> {
5-
| --------------- required by `From`
4+
LL | trait From<Src> {
5+
| --------------- required by `From`
66
...
7-
LL | / fn to<Dst>(
8-
LL | | self
9-
LL | | ) -> <Dst as From<Self>>::Result where Dst: From<Self> {
10-
| | - help: consider further restricting `Self`: `, Self: std::marker::Sized`
11-
LL | | From::from(self)
12-
LL | | }
13-
| |_____^ doesn't have a size known at compile-time
7+
LL | fn to<Dst>(
8+
| ^^ doesn't have a size known at compile-time
9+
LL | self
10+
LL | ) -> <Dst as From<Self>>::Result where Dst: From<Self> {
11+
| - help: consider further restricting `Self`: `, Self: std::marker::Sized`
1412
|
1513
= help: the trait `std::marker::Sized` is not implemented for `Self`
1614
= note: to learn more, visit <https://doc.rust-lang.org/book/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait>

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -151,16 +151,13 @@ LL | | }
151151
= note: required because of the requirements on the impl of `Foo` for `NoData<T>`
152152

153153
error[E0275]: overflow evaluating the requirement `NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<T>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>: Foo`
154-
--> $DIR/issue-20413.rs:10:3
154+
--> $DIR/issue-20413.rs:10:6
155155
|
156-
LL | trait Foo {
157-
| --------- required by `Foo`
156+
LL | trait Foo {
157+
| --------- required by `Foo`
158158
...
159-
LL | / fn answer(self) {
160-
LL | |
161-
LL | | let val: NoData<T> = NoData;
162-
LL | | }
163-
| |___^
159+
LL | fn answer(self) {
160+
| ^^^^^^
164161
|
165162
= help: consider adding a `#![recursion_limit="256"]` attribute to your crate
166163
= note: required because of the requirements on the impl of `Foo` for `NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<NoData<T>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>`

0 commit comments

Comments
 (0)