Skip to content
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

Normalize each signature input/output in typeck_with_fallback with its own span #134745

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
19 changes: 17 additions & 2 deletions compiler/rustc_hir_typeck/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,23 @@ fn typeck_with_fallback<'tcx>(
check_abi(tcx, span, fn_sig.abi());

// Compute the function signature from point of view of inside the fn.
let fn_sig = tcx.liberate_late_bound_regions(def_id.to_def_id(), fn_sig);
let fn_sig = fcx.normalize(body.value.span, fn_sig);
let mut fn_sig = tcx.liberate_late_bound_regions(def_id.to_def_id(), fn_sig);

// Normalize the input and output types one at a time, using a different
// `WellFormedLoc` for each. We cannot call `normalize_associated_types`
// on the entire `FnSig`, since this would use the same `WellFormedLoc`
// for each type, preventing the HIR wf check from generating
// a nice error message.
let arg_span =
|idx| decl.inputs.get(idx).map_or(decl.output.span(), |arg: &hir::Ty<'_>| arg.span);

fn_sig.inputs_and_output = tcx.mk_type_list_from_iter(
fn_sig
.inputs_and_output
.iter()
.enumerate()
.map(|(idx, ty)| fcx.normalize(arg_span(idx), ty)),
);

check_fn(&mut fcx, fn_sig, None, decl, def_id, body, tcx.features().unsized_fn_params());
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ LL | fn uhoh<U: Get>(&self, foo: U, bar: <Self as Get>::Value) where Self: S
| +++++++++++

error[E0277]: the trait bound `Self: Get` is not satisfied
--> $DIR/associated-types-for-unimpl-trait.rs:11:81
--> $DIR/associated-types-for-unimpl-trait.rs:11:41
|
LL | fn uhoh<U: Get>(&self, foo: U, bar: <Self as Get>::Value) where Self: Sized {}
| ^^ the trait `Get` is not implemented for `Self`
| ^^^^^^^^^^^^^^^^^^^^ the trait `Get` is not implemented for `Self`
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
help: consider further restricting `Self`
|
LL | fn uhoh<U: Get>(&self, foo: U, bar: <Self as Get>::Value) where Self: Sized, Self: Get {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ LL | fn uhoh<T: Get>(foo: <T as Get>::Value) {}
| +++++

error[E0277]: the trait bound `T: Get` is not satisfied
--> $DIR/associated-types-no-suitable-bound.rs:11:40
--> $DIR/associated-types-no-suitable-bound.rs:11:21
|
LL | fn uhoh<T>(foo: <T as Get>::Value) {}
| ^^ the trait `Get` is not implemented for `T`
| ^^^^^^^^^^^^^^^^^ the trait `Get` is not implemented for `T`
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
help: consider restricting type parameter `T` with trait `Get`
|
LL | fn uhoh<T: Get>(foo: <T as Get>::Value) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ LL | fn uhoh<U:Get>(&self, foo: U, bar: <Self as Get>::Value) where Self: Ge
| +++++++++++++++

error[E0277]: the trait bound `Self: Get` is not satisfied
--> $DIR/associated-types-no-suitable-supertrait-2.rs:17:62
--> $DIR/associated-types-no-suitable-supertrait-2.rs:17:40
|
LL | fn uhoh<U:Get>(&self, foo: U, bar: <Self as Get>::Value) {}
| ^^ the trait `Get` is not implemented for `Self`
| ^^^^^^^^^^^^^^^^^^^^ the trait `Get` is not implemented for `Self`
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
help: consider further restricting `Self`
|
LL | fn uhoh<U:Get>(&self, foo: U, bar: <Self as Get>::Value) where Self: Get {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,27 +34,29 @@ LL | fn uhoh<U:Get>(&self, foo: U, bar: <Self as Get>::Value) where Self: Ge
| +++++++++++++++

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

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

error: aborting due to 5 previous errors

Expand Down
5 changes: 3 additions & 2 deletions tests/ui/associated-types/issue-59324.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,17 @@ LL | pub trait ThriftService<Bug: NotFoo + Foo>:
| +++++

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

error[E0277]: the size for values of type `(dyn ThriftService<(), AssocType = _> + 'static)` cannot be known at compilation time
--> $DIR/issue-59324.rs:23:29
Expand Down
12 changes: 3 additions & 9 deletions tests/ui/auto-traits/issue-83857-ub.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,10 @@ LL | fn generic<T, U>(v: Foo<T, U>, f: fn(<Foo<T, U> as WithAssoc>::Output) -> i
| +++++++++++++++++++++

error[E0277]: `Foo<T, U>` cannot be sent between threads safely
--> $DIR/issue-83857-ub.rs:21:80
--> $DIR/issue-83857-ub.rs:21:35
|
LL | fn generic<T, U>(v: Foo<T, U>, f: fn(<Foo<T, U> as WithAssoc>::Output) -> i32) {
| ________________________________________________________________________________^
LL | |
LL | |
LL | | f(foo(v));
LL | |
LL | | }
| |_^ `Foo<T, U>` cannot be sent between threads safely
LL | fn generic<T, U>(v: Foo<T, U>, f: fn(<Foo<T, U> as WithAssoc>::Output) -> i32) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `Foo<T, U>` cannot be sent between threads safely
|
= help: the trait `Send` is not implemented for `Foo<T, U>`
note: required for `Foo<T, U>` to implement `WithAssoc`
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/error-codes/E0229.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ LL | fn baz<I: Foo>(x: &<I as Foo<A = Bar>>::A) {}
| +++++

error[E0277]: the trait bound `I: Foo` is not satisfied
--> $DIR/E0229.rs:13:39
--> $DIR/E0229.rs:13:14
|
LL | fn baz<I>(x: &<I as Foo<A = Bar>>::A) {}
| ^^ the trait `Foo` is not implemented for `I`
| ^^^^^^^^^^^^^^^^^^^^^^^ the trait `Foo` is not implemented for `I`
|
help: consider restricting type parameter `I` with trait `Foo`
|
Expand Down
1 change: 0 additions & 1 deletion tests/ui/impl-trait/issues/issue-87340.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ impl<T> X for () {
type I = impl Sized;
fn f() -> Self::I {}
//~^ ERROR type annotations needed
//~| ERROR type annotations needed
}

fn main() {}
8 changes: 1 addition & 7 deletions tests/ui/impl-trait/issues/issue-87340.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,13 @@ error[E0207]: the type parameter `T` is not constrained by the impl trait, self
LL | impl<T> X for () {
| ^ unconstrained type parameter

error[E0282]: type annotations needed
--> $DIR/issue-87340.rs:11:23
|
LL | fn f() -> Self::I {}
| ^^ cannot infer type for type parameter `T`

error[E0282]: type annotations needed
--> $DIR/issue-87340.rs:11:15
|
LL | fn f() -> Self::I {}
| ^^^^^^^ cannot infer type for type parameter `T`

error: aborting due to 3 previous errors
error: aborting due to 2 previous errors

Some errors have detailed explanations: E0207, E0282.
For more information about an error, try `rustc --explain E0207`.
10 changes: 4 additions & 6 deletions tests/ui/issues/issue-18611.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,17 @@ LL | trait HasState {
| ^^^^^^^^^^^^^^

error[E0277]: the trait bound `isize: HasState` is not satisfied
--> $DIR/issue-18611.rs:1:46
--> $DIR/issue-18611.rs:1:18
|
LL | fn add_state(op: <isize as HasState>::State) {
| ______________________________________________^
... |
LL | | }
| |_^ the trait `HasState` is not implemented for `isize`
LL | fn add_state(op: <isize as HasState>::State) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `HasState` is not implemented for `isize`
|
help: this trait has no implementations, consider adding one
--> $DIR/issue-18611.rs:6:1
|
LL | trait HasState {
| ^^^^^^^^^^^^^^
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error: aborting due to 2 previous errors

Expand Down
11 changes: 3 additions & 8 deletions tests/ui/issues/issue-35570.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,10 @@ LL | trait Trait2<'a> {
| ^^^^^^^^^^^^^^^^

error[E0277]: the trait bound `for<'a> (): Trait2<'a>` is not satisfied
--> $DIR/issue-35570.rs:8:66
--> $DIR/issue-35570.rs:8:16
|
LL | fn _ice(param: Box<dyn for <'a> Trait1<<() as Trait2<'a>>::Ty>>) {
| __________________________________________________________________^
LL | |
LL | |
LL | | let _e: (usize, usize) = unsafe{mem::transmute(param)};
LL | | }
| |_^ the trait `for<'a> Trait2<'a>` is not implemented for `()`
LL | fn _ice(param: Box<dyn for <'a> Trait1<<() as Trait2<'a>>::Ty>>) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `for<'a> Trait2<'a>` is not implemented for `()`
|
help: this trait has no implementations, consider adding one
--> $DIR/issue-35570.rs:4:1
Expand Down
5 changes: 3 additions & 2 deletions tests/ui/proc-macro/bad-projection.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,17 @@ LL | trait Project {
| ^^^^^^^^^^^^^

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

error: aborting due to 5 previous errors

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ trait Trait2<'a, 'b> {
// do not infer that.
fn callee<'x, 'y, T>(t: &'x dyn for<'z> Trait1< <T as Trait2<'y, 'z>>::Foo >)
//~^ ERROR the trait bound `for<'z> T: Trait2<'y, 'z>` is not satisfied
//~| ERROR the trait bound `for<'z> T: Trait2<'y, 'z>` is not satisfied
{
//~^ ERROR the trait bound `for<'z> T: Trait2<'y, 'z>` is not satisfied
}

fn main() { }
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@ LL | fn callee<'x, 'y, T: for<'z> Trait2<'y, 'z>>(t: &'x dyn for<'z> Trait1< <T
| ++++++++++++++++++++++++

error[E0277]: the trait bound `for<'z> T: Trait2<'y, 'z>` is not satisfied
--> $DIR/regions-implied-bounds-projection-gap-hr-1.rs:23:1
--> $DIR/regions-implied-bounds-projection-gap-hr-1.rs:21:25
|
LL | / {
LL | |
LL | | }
| |_^ the trait `for<'z> Trait2<'y, 'z>` is not implemented for `T`
LL | fn callee<'x, 'y, T>(t: &'x dyn for<'z> Trait1< <T as Trait2<'y, 'z>>::Foo >)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `for<'z> Trait2<'y, 'z>` is not implemented for `T`
|
help: consider restricting type parameter `T` with trait `Trait2`
|
Expand Down
9 changes: 3 additions & 6 deletions tests/ui/specialization/min_specialization/issue-79224.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,10 @@ LL | impl<B: ?Sized + std::clone::Clone> Display for Cow<'_, B> {
| +++++++++++++++++++

error[E0277]: the trait bound `B: Clone` is not satisfied
--> $DIR/issue-79224.rs:30:62
--> $DIR/issue-79224.rs:30:12
|
LL | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
| ______________________________________________________________^
... |
LL | | }
| |_____^ the trait `Clone` is not implemented for `B`
LL | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
| ^^^^^ the trait `Clone` is not implemented for `B`
|
= note: required for `B` to implement `ToOwned`
help: consider further restricting type parameter `B` with trait `Clone`
Expand Down
12 changes: 4 additions & 8 deletions tests/ui/type-alias-impl-trait/generic_underconstrained.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,17 @@ LL | fn underconstrain<T: Trait>(_: T) -> Underconstrained<T> {
| +++++++

error[E0277]: the trait bound `T: Trait` is not satisfied
--> $DIR/generic_underconstrained.rs:9:51
--> $DIR/generic_underconstrained.rs:9:31
|
LL | fn underconstrain<T>(_: T) -> Underconstrained<T> {
| ___________________________________________________^
LL | |
LL | |
LL | | unimplemented!()
LL | | }
| |_^ the trait `Trait` is not implemented for `T`
LL | fn underconstrain<T>(_: T) -> Underconstrained<T> {
| ^^^^^^^^^^^^^^^^^^^ the trait `Trait` is not implemented for `T`
|
note: required by a bound on the type alias `Underconstrained`
--> $DIR/generic_underconstrained.rs:6:26
|
LL | type Underconstrained<T: Trait> = impl Send;
| ^^^^^ required by this bound
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
help: consider restricting type parameter `T` with trait `Trait`
|
LL | fn underconstrain<T: Trait>(_: T) -> Underconstrained<T> {
Expand Down
24 changes: 8 additions & 16 deletions tests/ui/type-alias-impl-trait/generic_underconstrained2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -31,42 +31,34 @@ LL | fn underconstrained2<U, V: std::fmt::Debug>(_: U, _: V) -> Underconstrained
| +++++++++++++++++

error[E0277]: `U` doesn't implement `Debug`
--> $DIR/generic_underconstrained2.rs:8:53
--> $DIR/generic_underconstrained2.rs:8:33
|
LL | fn underconstrained<U>(_: U) -> Underconstrained<U> {
| _____________________________________________________^
LL | |
LL | |
LL | | 5u32
LL | | }
| |_^ `U` cannot be formatted using `{:?}` because it doesn't implement `Debug`
LL | fn underconstrained<U>(_: U) -> Underconstrained<U> {
| ^^^^^^^^^^^^^^^^^^^ `U` cannot be formatted using `{:?}` because it doesn't implement `Debug`
|
note: required by a bound on the type alias `Underconstrained`
--> $DIR/generic_underconstrained2.rs:5:26
|
LL | type Underconstrained<T: std::fmt::Debug> = impl Send;
| ^^^^^^^^^^^^^^^ required by this bound
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
help: consider restricting type parameter `U` with trait `Debug`
|
LL | fn underconstrained<U: std::fmt::Debug>(_: U) -> Underconstrained<U> {
| +++++++++++++++++

error[E0277]: `V` doesn't implement `Debug`
--> $DIR/generic_underconstrained2.rs:17:64
--> $DIR/generic_underconstrained2.rs:17:43
|
LL | fn underconstrained2<U, V>(_: U, _: V) -> Underconstrained2<V> {
| ________________________________________________________________^
LL | |
LL | |
LL | | 5u32
LL | | }
| |_^ `V` cannot be formatted using `{:?}` because it doesn't implement `Debug`
LL | fn underconstrained2<U, V>(_: U, _: V) -> Underconstrained2<V> {
| ^^^^^^^^^^^^^^^^^^^^ `V` cannot be formatted using `{:?}` because it doesn't implement `Debug`
|
note: required by a bound on the type alias `Underconstrained2`
--> $DIR/generic_underconstrained2.rs:14:27
|
LL | type Underconstrained2<T: std::fmt::Debug> = impl Send;
| ^^^^^^^^^^^^^^^ required by this bound
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
help: consider restricting type parameter `V` with trait `Debug`
|
LL | fn underconstrained2<U, V: std::fmt::Debug>(_: U, _: V) -> Underconstrained2<V> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ impl<T> X for () {
type I = impl Sized;
fn f() -> Self::I {}
//~^ ERROR type annotations needed
//~| ERROR type annotations needed
}

fn main() {}
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,13 @@ error[E0207]: the type parameter `T` is not constrained by the impl trait, self
LL | impl<T> X for () {
| ^ unconstrained type parameter

error[E0282]: type annotations needed
--> $DIR/impl-with-unconstrained-param.rs:14:23
|
LL | fn f() -> Self::I {}
| ^^ cannot infer type for type parameter `T`

error[E0282]: type annotations needed
--> $DIR/impl-with-unconstrained-param.rs:14:15
|
LL | fn f() -> Self::I {}
| ^^^^^^^ cannot infer type for type parameter `T`

error: aborting due to 3 previous errors
error: aborting due to 2 previous errors

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