Skip to content

Commit dc293c9

Browse files
Normalize each signature input/output in typeck_with_fallback with its own span
1 parent 409998c commit dc293c9

20 files changed

+71
-93
lines changed

compiler/rustc_hir_typeck/src/lib.rs

+17-2
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,23 @@ fn typeck_with_fallback<'tcx>(
159159
check_abi(tcx, span, fn_sig.abi());
160160

161161
// Compute the function signature from point of view of inside the fn.
162-
let fn_sig = tcx.liberate_late_bound_regions(def_id.to_def_id(), fn_sig);
163-
let fn_sig = fcx.normalize(body.value.span, fn_sig);
162+
let mut fn_sig = tcx.liberate_late_bound_regions(def_id.to_def_id(), fn_sig);
163+
164+
// Normalize the input and output types one at a time, using a different
165+
// `WellFormedLoc` for each. We cannot call `normalize_associated_types`
166+
// on the entire `FnSig`, since this would use the same `WellFormedLoc`
167+
// for each type, preventing the HIR wf check from generating
168+
// a nice error message.
169+
let arg_span =
170+
|idx| decl.inputs.get(idx).map_or(decl.output.span(), |arg: &hir::Ty<'_>| arg.span);
171+
172+
fn_sig.inputs_and_output = tcx.mk_type_list_from_iter(
173+
fn_sig
174+
.inputs_and_output
175+
.iter()
176+
.enumerate()
177+
.map(|(idx, ty)| fcx.normalize(arg_span(idx), ty)),
178+
);
164179

165180
check_fn(&mut fcx, fn_sig, None, decl, def_id, body, tcx.features().unsized_fn_params());
166181
} else {

tests/ui/associated-types/associated-types-for-unimpl-trait.stderr

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ LL | fn uhoh<U: Get>(&self, foo: U, bar: <Self as Get>::Value) where Self: S
1010
| +++++++++++
1111

1212
error[E0277]: the trait bound `Self: Get` is not satisfied
13-
--> $DIR/associated-types-for-unimpl-trait.rs:11:81
13+
--> $DIR/associated-types-for-unimpl-trait.rs:11:41
1414
|
1515
LL | fn uhoh<U: Get>(&self, foo: U, bar: <Self as Get>::Value) where Self: Sized {}
16-
| ^^ the trait `Get` is not implemented for `Self`
16+
| ^^^^^^^^^^^^^^^^^^^^ the trait `Get` is not implemented for `Self`
1717
|
18+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
1819
help: consider further restricting `Self`
1920
|
2021
LL | fn uhoh<U: Get>(&self, foo: U, bar: <Self as Get>::Value) where Self: Sized, Self: Get {}

tests/ui/associated-types/associated-types-no-suitable-bound.stderr

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ LL | fn uhoh<T: Get>(foo: <T as Get>::Value) {}
1010
| +++++
1111

1212
error[E0277]: the trait bound `T: Get` is not satisfied
13-
--> $DIR/associated-types-no-suitable-bound.rs:11:40
13+
--> $DIR/associated-types-no-suitable-bound.rs:11:21
1414
|
1515
LL | fn uhoh<T>(foo: <T as Get>::Value) {}
16-
| ^^ the trait `Get` is not implemented for `T`
16+
| ^^^^^^^^^^^^^^^^^ the trait `Get` is not implemented for `T`
1717
|
18+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
1819
help: consider restricting type parameter `T` with trait `Get`
1920
|
2021
LL | fn uhoh<T: Get>(foo: <T as Get>::Value) {}

tests/ui/associated-types/associated-types-no-suitable-supertrait-2.stderr

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ LL | fn uhoh<U:Get>(&self, foo: U, bar: <Self as Get>::Value) where Self: Ge
1010
| +++++++++++++++
1111

1212
error[E0277]: the trait bound `Self: Get` is not satisfied
13-
--> $DIR/associated-types-no-suitable-supertrait-2.rs:17:62
13+
--> $DIR/associated-types-no-suitable-supertrait-2.rs:17:40
1414
|
1515
LL | fn uhoh<U:Get>(&self, foo: U, bar: <Self as Get>::Value) {}
16-
| ^^ the trait `Get` is not implemented for `Self`
16+
| ^^^^^^^^^^^^^^^^^^^^ the trait `Get` is not implemented for `Self`
1717
|
18+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
1819
help: consider further restricting `Self`
1920
|
2021
LL | fn uhoh<U:Get>(&self, foo: U, bar: <Self as Get>::Value) where Self: Get {}

tests/ui/associated-types/associated-types-no-suitable-supertrait.stderr

+6-4
Original file line numberDiff line numberDiff line change
@@ -34,27 +34,29 @@ LL | fn uhoh<U:Get>(&self, foo: U, bar: <Self as Get>::Value) where Self: Ge
3434
| +++++++++++++++
3535

3636
error[E0277]: the trait bound `Self: Get` is not satisfied
37-
--> $DIR/associated-types-no-suitable-supertrait.rs:17:62
37+
--> $DIR/associated-types-no-suitable-supertrait.rs:17:40
3838
|
3939
LL | fn uhoh<U:Get>(&self, foo: U, bar: <Self as Get>::Value) {}
40-
| ^^ the trait `Get` is not implemented for `Self`
40+
| ^^^^^^^^^^^^^^^^^^^^ the trait `Get` is not implemented for `Self`
4141
|
42+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
4243
help: consider further restricting `Self`
4344
|
4445
LL | fn uhoh<U:Get>(&self, foo: U, bar: <Self as Get>::Value) where Self: Get {}
4546
| +++++++++++++++
4647

4748
error[E0277]: the trait bound `(T, U): Get` is not satisfied
48-
--> $DIR/associated-types-no-suitable-supertrait.rs:23:64
49+
--> $DIR/associated-types-no-suitable-supertrait.rs:23:40
4950
|
5051
LL | fn uhoh<U:Get>(&self, foo: U, bar: <(T, U) as Get>::Value) {}
51-
| ^^ the trait `Get` is not implemented for `(T, U)`
52+
| ^^^^^^^^^^^^^^^^^^^^^^ the trait `Get` is not implemented for `(T, U)`
5253
|
5354
help: this trait has no implementations, consider adding one
5455
--> $DIR/associated-types-no-suitable-supertrait.rs:12:1
5556
|
5657
LL | trait Get {
5758
| ^^^^^^^^^
59+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
5860

5961
error: aborting due to 5 previous errors
6062

tests/ui/associated-types/issue-59324.stderr

+3-2
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,17 @@ LL | pub trait ThriftService<Bug: NotFoo + Foo>:
6565
| +++++
6666

6767
error[E0277]: the trait bound `(): Foo` is not satisfied
68-
--> $DIR/issue-59324.rs:23:52
68+
--> $DIR/issue-59324.rs:23:29
6969
|
7070
LL | fn with_factory<H>(factory: dyn ThriftService<()>) {}
71-
| ^^ the trait `Foo` is not implemented for `()`
71+
| ^^^^^^^^^^^^^^^^^^^^^ the trait `Foo` is not implemented for `()`
7272
|
7373
help: this trait has no implementations, consider adding one
7474
--> $DIR/issue-59324.rs:3:1
7575
|
7676
LL | pub trait Foo: NotFoo {
7777
| ^^^^^^^^^^^^^^^^^^^^^
78+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
7879

7980
error[E0277]: the size for values of type `(dyn ThriftService<(), AssocType = _> + 'static)` cannot be known at compilation time
8081
--> $DIR/issue-59324.rs:23:29

tests/ui/auto-traits/issue-83857-ub.stderr

+3-9
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,10 @@ LL | fn generic<T, U>(v: Foo<T, U>, f: fn(<Foo<T, U> as WithAssoc>::Output) -> i
1818
| +++++++++++++++++++++
1919

2020
error[E0277]: `Foo<T, U>` cannot be sent between threads safely
21-
--> $DIR/issue-83857-ub.rs:21:80
21+
--> $DIR/issue-83857-ub.rs:21:35
2222
|
23-
LL | fn generic<T, U>(v: Foo<T, U>, f: fn(<Foo<T, U> as WithAssoc>::Output) -> i32) {
24-
| ________________________________________________________________________________^
25-
LL | |
26-
LL | |
27-
LL | | f(foo(v));
28-
LL | |
29-
LL | | }
30-
| |_^ `Foo<T, U>` cannot be sent between threads safely
23+
LL | fn generic<T, U>(v: Foo<T, U>, f: fn(<Foo<T, U> as WithAssoc>::Output) -> i32) {
24+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `Foo<T, U>` cannot be sent between threads safely
3125
|
3226
= help: the trait `Send` is not implemented for `Foo<T, U>`
3327
note: required for `Foo<T, U>` to implement `WithAssoc`

tests/ui/error-codes/E0229.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ LL | fn baz<I: Foo>(x: &<I as Foo<A = Bar>>::A) {}
4848
| +++++
4949

5050
error[E0277]: the trait bound `I: Foo` is not satisfied
51-
--> $DIR/E0229.rs:13:39
51+
--> $DIR/E0229.rs:13:14
5252
|
5353
LL | fn baz<I>(x: &<I as Foo<A = Bar>>::A) {}
54-
| ^^ the trait `Foo` is not implemented for `I`
54+
| ^^^^^^^^^^^^^^^^^^^^^^^ the trait `Foo` is not implemented for `I`
5555
|
5656
help: consider restricting type parameter `I` with trait `Foo`
5757
|

tests/ui/impl-trait/issues/issue-87340.rs

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ impl<T> X for () {
1010
type I = impl Sized;
1111
fn f() -> Self::I {}
1212
//~^ ERROR type annotations needed
13-
//~| ERROR type annotations needed
1413
}
1514

1615
fn main() {}

tests/ui/impl-trait/issues/issue-87340.stderr

+1-7
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,13 @@ error[E0207]: the type parameter `T` is not constrained by the impl trait, self
44
LL | impl<T> X for () {
55
| ^ unconstrained type parameter
66

7-
error[E0282]: type annotations needed
8-
--> $DIR/issue-87340.rs:11:23
9-
|
10-
LL | fn f() -> Self::I {}
11-
| ^^ cannot infer type for type parameter `T`
12-
137
error[E0282]: type annotations needed
148
--> $DIR/issue-87340.rs:11:15
159
|
1610
LL | fn f() -> Self::I {}
1711
| ^^^^^^^ cannot infer type for type parameter `T`
1812

19-
error: aborting due to 3 previous errors
13+
error: aborting due to 2 previous errors
2014

2115
Some errors have detailed explanations: E0207, E0282.
2216
For more information about an error, try `rustc --explain E0207`.

tests/ui/issues/issue-18611.stderr

+4-6
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,17 @@ LL | trait HasState {
1111
| ^^^^^^^^^^^^^^
1212

1313
error[E0277]: the trait bound `isize: HasState` is not satisfied
14-
--> $DIR/issue-18611.rs:1:46
14+
--> $DIR/issue-18611.rs:1:18
1515
|
16-
LL | fn add_state(op: <isize as HasState>::State) {
17-
| ______________________________________________^
18-
... |
19-
LL | | }
20-
| |_^ the trait `HasState` is not implemented for `isize`
16+
LL | fn add_state(op: <isize as HasState>::State) {
17+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `HasState` is not implemented for `isize`
2118
|
2219
help: this trait has no implementations, consider adding one
2320
--> $DIR/issue-18611.rs:6:1
2421
|
2522
LL | trait HasState {
2623
| ^^^^^^^^^^^^^^
24+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
2725

2826
error: aborting due to 2 previous errors
2927

tests/ui/issues/issue-35570.stderr

+3-8
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,10 @@ LL | trait Trait2<'a> {
1111
| ^^^^^^^^^^^^^^^^
1212

1313
error[E0277]: the trait bound `for<'a> (): Trait2<'a>` is not satisfied
14-
--> $DIR/issue-35570.rs:8:66
14+
--> $DIR/issue-35570.rs:8:16
1515
|
16-
LL | fn _ice(param: Box<dyn for <'a> Trait1<<() as Trait2<'a>>::Ty>>) {
17-
| __________________________________________________________________^
18-
LL | |
19-
LL | |
20-
LL | | let _e: (usize, usize) = unsafe{mem::transmute(param)};
21-
LL | | }
22-
| |_^ the trait `for<'a> Trait2<'a>` is not implemented for `()`
16+
LL | fn _ice(param: Box<dyn for <'a> Trait1<<() as Trait2<'a>>::Ty>>) {
17+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `for<'a> Trait2<'a>` is not implemented for `()`
2318
|
2419
help: this trait has no implementations, consider adding one
2520
--> $DIR/issue-35570.rs:4:1

tests/ui/proc-macro/bad-projection.stderr

+3-2
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,17 @@ LL | trait Project {
4848
| ^^^^^^^^^^^^^
4949

5050
error[E0277]: the trait bound `(): Project` is not satisfied
51-
--> $DIR/bad-projection.rs:14:40
51+
--> $DIR/bad-projection.rs:14:17
5252
|
5353
LL | pub fn uwu() -> <() as Project>::Assoc {}
54-
| ^^ the trait `Project` is not implemented for `()`
54+
| ^^^^^^^^^^^^^^^^^^^^^^ the trait `Project` is not implemented for `()`
5555
|
5656
help: this trait has no implementations, consider adding one
5757
--> $DIR/bad-projection.rs:9:1
5858
|
5959
LL | trait Project {
6060
| ^^^^^^^^^^^^^
61+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
6162

6263
error: aborting due to 5 previous errors
6364

tests/ui/regions/regions-implied-bounds-projection-gap-hr-1.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ trait Trait2<'a, 'b> {
2020
// do not infer that.
2121
fn callee<'x, 'y, T>(t: &'x dyn for<'z> Trait1< <T as Trait2<'y, 'z>>::Foo >)
2222
//~^ ERROR the trait bound `for<'z> T: Trait2<'y, 'z>` is not satisfied
23+
//~| ERROR the trait bound `for<'z> T: Trait2<'y, 'z>` is not satisfied
2324
{
24-
//~^ ERROR the trait bound `for<'z> T: Trait2<'y, 'z>` is not satisfied
2525
}
2626

2727
fn main() { }

tests/ui/regions/regions-implied-bounds-projection-gap-hr-1.stderr

+3-5
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,10 @@ LL | fn callee<'x, 'y, T: for<'z> Trait2<'y, 'z>>(t: &'x dyn for<'z> Trait1< <T
1010
| ++++++++++++++++++++++++
1111

1212
error[E0277]: the trait bound `for<'z> T: Trait2<'y, 'z>` is not satisfied
13-
--> $DIR/regions-implied-bounds-projection-gap-hr-1.rs:23:1
13+
--> $DIR/regions-implied-bounds-projection-gap-hr-1.rs:21:25
1414
|
15-
LL | / {
16-
LL | |
17-
LL | | }
18-
| |_^ the trait `for<'z> Trait2<'y, 'z>` is not implemented for `T`
15+
LL | fn callee<'x, 'y, T>(t: &'x dyn for<'z> Trait1< <T as Trait2<'y, 'z>>::Foo >)
16+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `for<'z> Trait2<'y, 'z>` is not implemented for `T`
1917
|
2018
help: consider restricting type parameter `T` with trait `Trait2`
2119
|

tests/ui/specialization/min_specialization/issue-79224.stderr

+3-6
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,10 @@ LL | impl<B: ?Sized + std::clone::Clone> Display for Cow<'_, B> {
3535
| +++++++++++++++++++
3636

3737
error[E0277]: the trait bound `B: Clone` is not satisfied
38-
--> $DIR/issue-79224.rs:30:62
38+
--> $DIR/issue-79224.rs:30:12
3939
|
40-
LL | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
41-
| ______________________________________________________________^
42-
... |
43-
LL | | }
44-
| |_____^ the trait `Clone` is not implemented for `B`
40+
LL | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
41+
| ^^^^^ the trait `Clone` is not implemented for `B`
4542
|
4643
= note: required for `B` to implement `ToOwned`
4744
help: consider further restricting type parameter `B` with trait `Clone`

tests/ui/type-alias-impl-trait/generic_underconstrained.stderr

+4-8
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,17 @@ LL | fn underconstrain<T: Trait>(_: T) -> Underconstrained<T> {
1515
| +++++++
1616

1717
error[E0277]: the trait bound `T: Trait` is not satisfied
18-
--> $DIR/generic_underconstrained.rs:9:51
18+
--> $DIR/generic_underconstrained.rs:9:31
1919
|
20-
LL | fn underconstrain<T>(_: T) -> Underconstrained<T> {
21-
| ___________________________________________________^
22-
LL | |
23-
LL | |
24-
LL | | unimplemented!()
25-
LL | | }
26-
| |_^ the trait `Trait` is not implemented for `T`
20+
LL | fn underconstrain<T>(_: T) -> Underconstrained<T> {
21+
| ^^^^^^^^^^^^^^^^^^^ the trait `Trait` is not implemented for `T`
2722
|
2823
note: required by a bound on the type alias `Underconstrained`
2924
--> $DIR/generic_underconstrained.rs:6:26
3025
|
3126
LL | type Underconstrained<T: Trait> = impl Send;
3227
| ^^^^^ required by this bound
28+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
3329
help: consider restricting type parameter `T` with trait `Trait`
3430
|
3531
LL | fn underconstrain<T: Trait>(_: T) -> Underconstrained<T> {

tests/ui/type-alias-impl-trait/generic_underconstrained2.stderr

+8-16
Original file line numberDiff line numberDiff line change
@@ -31,42 +31,34 @@ LL | fn underconstrained2<U, V: std::fmt::Debug>(_: U, _: V) -> Underconstrained
3131
| +++++++++++++++++
3232

3333
error[E0277]: `U` doesn't implement `Debug`
34-
--> $DIR/generic_underconstrained2.rs:8:53
34+
--> $DIR/generic_underconstrained2.rs:8:33
3535
|
36-
LL | fn underconstrained<U>(_: U) -> Underconstrained<U> {
37-
| _____________________________________________________^
38-
LL | |
39-
LL | |
40-
LL | | 5u32
41-
LL | | }
42-
| |_^ `U` cannot be formatted using `{:?}` because it doesn't implement `Debug`
36+
LL | fn underconstrained<U>(_: U) -> Underconstrained<U> {
37+
| ^^^^^^^^^^^^^^^^^^^ `U` cannot be formatted using `{:?}` because it doesn't implement `Debug`
4338
|
4439
note: required by a bound on the type alias `Underconstrained`
4540
--> $DIR/generic_underconstrained2.rs:5:26
4641
|
4742
LL | type Underconstrained<T: std::fmt::Debug> = impl Send;
4843
| ^^^^^^^^^^^^^^^ required by this bound
44+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
4945
help: consider restricting type parameter `U` with trait `Debug`
5046
|
5147
LL | fn underconstrained<U: std::fmt::Debug>(_: U) -> Underconstrained<U> {
5248
| +++++++++++++++++
5349

5450
error[E0277]: `V` doesn't implement `Debug`
55-
--> $DIR/generic_underconstrained2.rs:17:64
51+
--> $DIR/generic_underconstrained2.rs:17:43
5652
|
57-
LL | fn underconstrained2<U, V>(_: U, _: V) -> Underconstrained2<V> {
58-
| ________________________________________________________________^
59-
LL | |
60-
LL | |
61-
LL | | 5u32
62-
LL | | }
63-
| |_^ `V` cannot be formatted using `{:?}` because it doesn't implement `Debug`
53+
LL | fn underconstrained2<U, V>(_: U, _: V) -> Underconstrained2<V> {
54+
| ^^^^^^^^^^^^^^^^^^^^ `V` cannot be formatted using `{:?}` because it doesn't implement `Debug`
6455
|
6556
note: required by a bound on the type alias `Underconstrained2`
6657
--> $DIR/generic_underconstrained2.rs:14:27
6758
|
6859
LL | type Underconstrained2<T: std::fmt::Debug> = impl Send;
6960
| ^^^^^^^^^^^^^^^ required by this bound
61+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
7062
help: consider restricting type parameter `V` with trait `Debug`
7163
|
7264
LL | fn underconstrained2<U, V: std::fmt::Debug>(_: U, _: V) -> Underconstrained2<V> {

tests/ui/type-alias-impl-trait/impl-with-unconstrained-param.rs

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ impl<T> X for () {
1313
type I = impl Sized;
1414
fn f() -> Self::I {}
1515
//~^ ERROR type annotations needed
16-
//~| ERROR type annotations needed
1716
}
1817

1918
fn main() {}

tests/ui/type-alias-impl-trait/impl-with-unconstrained-param.stderr

+1-7
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,13 @@ error[E0207]: the type parameter `T` is not constrained by the impl trait, self
44
LL | impl<T> X for () {
55
| ^ unconstrained type parameter
66

7-
error[E0282]: type annotations needed
8-
--> $DIR/impl-with-unconstrained-param.rs:14:23
9-
|
10-
LL | fn f() -> Self::I {}
11-
| ^^ cannot infer type for type parameter `T`
12-
137
error[E0282]: type annotations needed
148
--> $DIR/impl-with-unconstrained-param.rs:14:15
159
|
1610
LL | fn f() -> Self::I {}
1711
| ^^^^^^^ cannot infer type for type parameter `T`
1812

19-
error: aborting due to 3 previous errors
13+
error: aborting due to 2 previous errors
2014

2115
Some errors have detailed explanations: E0207, E0282.
2216
For more information about an error, try `rustc --explain E0207`.

0 commit comments

Comments
 (0)