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

Type mismatch in function arguments E0631, E0271 are falsely recognized as E0308 mismatched types #74400

Closed
vandenheuvel opened this issue Jul 16, 2020 · 12 comments · Fixed by #88541
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. P-high High priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@vandenheuvel
Copy link
Contributor

Regression from 1.45.0-beta.4 (2020-07-13 e99e6422a2f799fc86a3) to 1.46.0-nightly (2020-07-15 7e11379f3b4c376fbb9a).

The following code yields an incorrect error:

use std::convert::identity;

pub fn is_sorted_and_has_duplicates_by<T, S: PartialEq + PartialOrd>(
    data: &[T],
    key: impl Fn(&T) -> S,
) -> Option<&T> {
    unimplemented!()
}

pub fn is_sorted_and_has_duplicates<T: PartialEq + PartialOrd>(data: &[T]) -> Option<&T> {
    is_sorted_and_has_duplicates_by(data, identity)
}

On beta, this gives:

error[E0631]: type mismatch in function arguments
  --> src/lib.rs:11:43
   |
3  | pub fn is_sorted_and_has_duplicates_by<T, S: PartialEq + PartialOrd>(
   |        ------------------------------- required by a bound in this
4  |     data: &[T],
5  |     key: impl Fn(&T) -> S,
   |               ----------- required by this bound in `is_sorted_and_has_duplicates_by`
...
11 |     is_sorted_and_has_duplicates_by(data, identity)
   |                                           ^^^^^^^^
   |                                           |
   |                                           expected signature of `for<'r> fn(&'r T) -> _`
   |                                           found signature of `fn(_) -> _`

error[E0271]: type mismatch resolving `for<'r> <fn(_) -> _ {std::convert::identity::<_>} as std::ops::FnOnce<(&'r T,)>>::Output == _`
  --> src/lib.rs:11:5
   |
3  | pub fn is_sorted_and_has_duplicates_by<T, S: PartialEq + PartialOrd>(
   |        ------------------------------- required by a bound in this
4  |     data: &[T],
5  |     key: impl Fn(&T) -> S,
   |                         - required by this bound in `is_sorted_and_has_duplicates_by`
...
11 |     is_sorted_and_has_duplicates_by(data, identity)
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected bound lifetime parameter, found concrete lifetime

On nightly, this:

error[E0308]: mismatched types
  --> src/lib.rs:11:5
   |
11 |     is_sorted_and_has_duplicates_by(data, identity)
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ one type is more general than the other
   |
   = note: expected type `std::ops::FnOnce<(&T,)>`
              found type `std::ops::FnOnce<(&T,)>`
@vandenheuvel vandenheuvel changed the title Type mismatch in function arguments E0631, E0271 are false recognized as E0308 mismatched types Type mismatch in function arguments E0631, E0271 are falsely recognized as E0308 mismatched types Jul 16, 2020
@vandenheuvel
Copy link
Contributor Author

@jonas-schievink would you be so kind to label this issue? It's sliding down the list while being hard to search.

@jonas-schievink jonas-schievink added A-diagnostics Area: Messages for errors, warnings, and lints regression-from-stable-to-beta Performance or correctness regression from stable to beta. labels Jul 20, 2020
@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Jul 20, 2020
@jonas-schievink jonas-schievink added regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. and removed regression-from-stable-to-beta Performance or correctness regression from stable to beta. labels Jul 20, 2020
@JohnTitor
Copy link
Member

JohnTitor commented Jul 20, 2020

Regression occurred between nightly-2020-06-23 and nightly-2020-06-24, I suspect #73643 is related (it's #72493?).

@LeSeulArtichaut LeSeulArtichaut added the E-needs-bisection Call for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc label Jul 20, 2020
@LeSeulArtichaut
Copy link
Contributor

It would be great to find the culprit PR.
@rustbot ping cleanup

@rustbot
Copy link
Collaborator

rustbot commented Jul 20, 2020

Hey Cleanup Crew ICE-breakers! This bug has been identified as a good
"Cleanup ICE-breaking candidate". In case it's useful, here are some
instructions for tackling these sorts of bugs. Maybe take a look?
Thanks! <3

cc @AminArria @camelid @chrissimpkins @contrun @DutchGhost @elshize @ethanboxx @h-michael @HallerPatrick @hdhoang @hellow554 @imtsuki @kanru @KarlK90 @LeSeulArtichaut @MAdrianMattocks @matheus-consoli @mental32 @nmccarty @Noah-Kennedy @pard68 @PeytonT @pierreN @Redblueflame @RobbieClarken @RobertoSnap @robjtede @SarthakSingh31 @senden9 @shekohex @sinato @spastorino @turboladen @woshilapin @yerke

@rustbot rustbot added the ICEBreaker-Cleanup-Crew Helping to "clean up" bugs with minimal examples and bisections label Jul 20, 2020
@kanru
Copy link
Contributor

kanru commented Jul 20, 2020

searched nightlies: from nightly-2020-06-23 to nightly-2020-06-24
regressed nightly: nightly-2020-06-24
searched commits: from 6bb3dbf to ff5b446
regressed commit: 1557fb0

bisected with cargo-bisect-rustc v0.5.1

Host triple: x86_64-unknown-linux-gnu
Reproduce with:

cargo bisect-rustc --start=2020-06-23 --end=2020-06-24 --prompt -- check 

If we rule out document changes then we have

#72271
#72493
#73398
#73496
#73515

@LeSeulArtichaut
Copy link
Contributor

LeSeulArtichaut commented Jul 21, 2020

Regression occurred between nightly-2020-06-23 and nightly-2020-06-24, I suspect #73643 is related (it's #72493?).

Bisection seems to confirm this, cc @nikomatsakis

@kanru
Copy link
Contributor

kanru commented Jul 21, 2020

With a little more git bisect it seems 6873a76 is the first bad commit

And I guess the change to the test case also shows that

diff --git a/src/test/ui/type-alias-impl-trait/issue-57611-trait-alias.stderr b/src/test/ui/type-alias-impl-trait/issue-57611-trait-alias.stderr
index 3cb8abcdcfd..cd637056c94 100644
--- a/src/test/ui/type-alias-impl-trait/issue-57611-trait-alias.stderr
+++ b/src/test/ui/type-alias-impl-trait/issue-57611-trait-alias.stderr
@@ -1,11 +1,12 @@
-error[E0271]: type mismatch resolving `for<'r> <[closure@$DIR/issue-57611-trait-alias.rs:21:9: 21:14] as std::ops::FnOnce<(&'r X,)>>::Output == &'r X`
+error[E0308]: mismatched types
   --> $DIR/issue-57611-trait-alias.rs:17:16
    |
 LL |     type Bar = impl Baz<Self, Self>;
-   |                ^^^^^^^^^^^^^^^^^^^^ expected bound lifetime parameter, found concrete lifetime
+   |                ^^^^^^^^^^^^^^^^^^^^ one type is more general than the other
    |
-   = note: the return type of a function must have a statically known size
+   = note: expected type `std::ops::FnOnce<(&X,)>`
+              found type `std::ops::FnOnce<(&X,)>`
 
 error: aborting due to previous error
 
-For more information about this error, try `rustc --explain E0271`.
+For more information about this error, try `rustc --explain E0308`.

@JohnTitor JohnTitor added C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed E-needs-bisection Call for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc ICEBreaker-Cleanup-Crew Helping to "clean up" bugs with minimal examples and bisections labels Jul 21, 2020
@spastorino
Copy link
Member

Assigning P-high as discussed as part of the Prioritization Working Group procedure and removing I-prioritize.

@spastorino spastorino added P-high High priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Jul 22, 2020
@nikomatsakis
Copy link
Contributor

Well, I can certainly imagine how this could come about as a result of the leak-check moving, since the same error can now be detected at a different point during type-checking.

What's happening in that confusing error, I imagine, is that we are now winding up with a "universe error" that comes out from region checking. The identity function was inferred to take an argument identity::<&'a T> for some 'a...

Well, in short, I imagine that the solution here is to improve the error reporting for the new point where the error occurs, but it'll take a bit more digging to give good mentoring instructions into how to go about doing that.

@spastorino
Copy link
Member

This is now a stable regression.

@spastorino spastorino added regression-from-stable-to-stable Performance or correctness regression from one stable version to another. and removed regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. labels Sep 3, 2020
@pnkfelix
Copy link
Member

pnkfelix commented Sep 3, 2020

Discussed in T-compiler meeting. Seems related to (or potential duplicate of) #75791 ?

@vandenheuvel
Copy link
Contributor Author

On today's nightly, the error is now:

error: implementation of `FnOnce` is not general enough
  --> src/lib.rs:11:5
   |
11 |     is_sorted_and_has_duplicates_by(data, identity)
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ implementation of `FnOnce` is not general enough
   |
   = note: `fn(&'2 T) -> &'2 T {identity::<&'2 T>}` must implement `FnOnce<(&'1 T,)>`, for any lifetime `'1`...
   = note: ...but it actually implements `FnOnce<(&'2 T,)>`, for some specific lifetime `'2`

That seems correct, and with the extra lifetime, the snippet compiles:

use std::convert::identity;

pub fn is_sorted_and_has_duplicates_by<'a, T, S: PartialEq + PartialOrd>(
    data: &'a [T],
    key: impl Fn(&'a T) -> S,
) -> Option<&T> {
    unimplemented!()
}

pub fn is_sorted_and_has_duplicates<T: PartialEq + PartialOrd>(data: &[T]) -> Option<&T> {
    is_sorted_and_has_duplicates_by(data, identity)
}

vandenheuvel added a commit to vandenheuvel/rust that referenced this issue Sep 5, 2021
bors added a commit to rust-lang-ci/rust that referenced this issue Sep 8, 2021
Rollup of 9 pull requests

Successful merges:

 - rust-lang#86263 (Rustdoc: Report Layout of enum variants)
 - rust-lang#88541 (Add regression test for rust-lang#74400)
 - rust-lang#88553 (Improve diagnostics for unary plus operators (rust-lang#88276))
 - rust-lang#88594 (More symbolic doc aliases)
 - rust-lang#88648 (Correct “copies” to “moves” in `<Option<T> as From<T>>::from` doc, and other copyediting)
 - rust-lang#88691 (Add a regression test for rust-lang#88649)
 - rust-lang#88694 (Drop 1.56 stabilizations from 1.55 release notes)
 - rust-lang#88712 (Fix docs for `uX::checked_next_multiple_of`)
 - rust-lang#88726 (Fix typo in `const_generics` replaced with `adt_const_params` note)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors closed this as completed in 4fb0084 Sep 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. P-high High priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants