Closed
Description
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,)>`