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

Mismatched closure arguments are no longer expanded in rustc 1.64 and later #100690

Closed
passy opened this issue Aug 17, 2022 · 5 comments · Fixed by #100691
Closed

Mismatched closure arguments are no longer expanded in rustc 1.64 and later #100690

passy opened this issue Aug 17, 2022 · 5 comments · Fixed by #100691
Labels
A-diagnostics Area: Messages for errors, warnings, and lints P-medium Medium priority regression-from-stable-to-beta Performance or correctness regression from stable to beta. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@passy
Copy link

passy commented Aug 17, 2022

Sorry, this is not necessarily the smallest possible example. Please let me know if this is unhelpful and I'll come up with something more concise.

Given the following code: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=8a1f669598035e38e7e141eb799d6738

use std::io;

fn real_dispatch<T, F>(f: F) -> Result<(), io::Error>
where
    F: FnOnce(&mut UIView<T>) -> Result<(), io::Error> + Send + 'static,
{
    todo!()
}

#[derive(Debug)]
struct UIView<'a, T: 'a> {
    _phantom: std::marker::PhantomData<&'a mut T>,
}

trait Handle<'a, T: 'a, V, R> {
    fn dispatch<F>(&self, f: F) -> Result<(), io::Error>
    where
        F: FnOnce(&mut V) -> R + Send + 'static;
}

#[derive(Debug, Clone)]
struct TUIHandle<T> {
    _phantom: std::marker::PhantomData<T>,
}

impl<'a, T: 'a> Handle<'a, T, UIView<'a, T>, Result<(), io::Error>> for TUIHandle<T> {
    fn dispatch<F>(&self, f: F) -> Result<(), io::Error>
    where
        F: FnOnce(&mut UIView<'a, T>) -> Result<(), io::Error> + Send + 'static,
    {
        real_dispatch(f)
    }
}

The output in current stable (1.63.0) is:

(Please note the "expected closure with ... found closure with ..." hint.)

error[E0277]: expected a `FnOnce<(&mut UIView<'_, T>,)>` closure, found `F`
  --> src/lib.rs:31:23
   |
31 |         real_dispatch(f)
   |         ------------- ^ expected an `FnOnce<(&mut UIView<'_, T>,)>` closure, found `F`
   |         |
   |         required by a bound introduced by this call
   |
   = note: expected a closure with arguments `(&mut UIView<'a, T>,)`
              found a closure with arguments `(&mut UIView<'_, T>,)`
note: required by a bound in `real_dispatch`
  --> src/lib.rs:5:8
   |
3  | fn real_dispatch<T, F>(f: F) -> Result<(), io::Error>
   |    ------------- required by a bound in this
4  | where
5  |     F: FnOnce(&mut UIView<T>) -> Result<(), io::Error> + Send + 'static,
   |        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `real_dispatch`

For more information about this error, try `rustc --explain E0277`.
error: could not compile `playground` due to previous error

From 1.64 onwards, the expected/found hint is omitted:

error[E0277]: expected a `FnOnce<(&mut UIView<'_, T>,)>` closure, found `F`
  --> src/lib.rs:31:23
   |
31 |         real_dispatch(f)
   |         ------------- ^ expected an `FnOnce<(&mut UIView<'_, T>,)>` closure, found `F`
   |         |
   |         required by a bound introduced by this call
   |
note: required by a bound in `real_dispatch`
  --> src/lib.rs:5:8
   |
3  | fn real_dispatch<T, F>(f: F) -> Result<(), io::Error>
   |    ------------- required by a bound in this
4  | where
5  |     F: FnOnce(&mut UIView<T>) -> Result<(), io::Error> + Send + 'static,
   |        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `real_dispatch`

For more information about this error, try `rustc --explain E0277`.
error: could not compile `playground` due to previous error

To me the 1.63 behaviour is preferable to that from 1.64+ as it can often be non-obvious where the differences lie.

@passy passy added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 17, 2022
@estebank estebank added the regression-from-stable-to-beta Performance or correctness regression from stable to beta. label Aug 17, 2022
@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Aug 17, 2022
@compiler-errors compiler-errors added the E-needs-bisection Call for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc label Aug 17, 2022
@Noratrieb
Copy link
Member

searched nightlies: from nightly-2022-06-01 to nightly-2022-08-11
regressed nightly: nightly-2022-07-23
searched commit range: 62b272d...848090d
regressed commit: e7a9c11

bisected with cargo-bisect-rustc v0.6.4

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

cargo bisect-rustc --prompt

@Noratrieb
Copy link
Member

Looks like it was caused by #99539, which is pretty big diagnostics PR in that rollup. cc @compiler-errors

@compiler-errors
Copy link
Member

Of course I caused it.

@steffahn
Copy link
Member

@rustbot label -E-needs-bisection

@rustbot rustbot removed the E-needs-bisection Call for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc label Aug 17, 2022
@apiraino
Copy link
Contributor

WG-prioritization assigning priority (Zulip discussion).

@rustbot label -I-prioritize +P-medium

@rustbot rustbot added P-medium Medium priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Aug 18, 2022
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue Aug 20, 2022
…tebank

Make `same_type_modulo_infer` a proper `TypeRelation`

Specifically, this fixes rust-lang#100690 because we no longer consider a `ReLateBound` and a `ReVar` to be equal. `ReVar` can only be equal to free regions or static.
@bors bors closed this as completed in 51769af Aug 20, 2022
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 P-medium Medium priority regression-from-stable-to-beta Performance or correctness regression from stable to beta. 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.

7 participants