Skip to content

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

Closed
@vandenheuvel

Description

@vandenheuvel
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,)>`

Activity

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[/+] on Jul 16, 2020
vandenheuvel

vandenheuvel commented on Jul 20, 2020

@vandenheuvel
ContributorAuthor

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

added
I-prioritizeIssue: Indicates that prioritization has been requested for this issue.
on Jul 20, 2020
JohnTitor

JohnTitor commented on Jul 20, 2020

@JohnTitor
Member

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

added
E-needs-bisectionCall for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc
on Jul 20, 2020
LeSeulArtichaut

LeSeulArtichaut commented on Jul 20, 2020

@LeSeulArtichaut
Contributor

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

rustbot

rustbot commented on Jul 20, 2020

@rustbot
Collaborator

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

kanru

kanru commented on Jul 20, 2020

@kanru
Contributor

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

LeSeulArtichaut commented on Jul 21, 2020

@LeSeulArtichaut
Contributor

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

kanru commented on Jul 21, 2020

@kanru
Contributor

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`.

24 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.P-highHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @kanru@spastorino@nikomatsakis@pnkfelix@jonas-schievink

      Issue actions

        Type mismatch in function arguments E0631, E0271 are falsely recognized as E0308 mismatched types · Issue #74400 · rust-lang/rust