Skip to content

E0593 regression when mismatched argument count leads to other errors in Beta/Nightly #47244

Closed

Description

@Rantanen

Playground

use std::collections::HashMap;
fn main() {
    
    let m = HashMap::new();
    m.insert( "foo", "bar" );
    
    m.iter().map( |_, b| { // Stable ONLY:
                           // > [E0593]: closure is expected to take a single tuple as argument

        b.to_string()      // Stable + Beta + Nightly:
                           // > [E0619]: the type of this value must be known in this context
    });
}

Commenting out the b.to_string() will yield the [E0593] error in all toolchains.

The [E0619] alone makes for a very confusing error message, as the user's assumption is that the type of b is correct.

Activity

  1. added
    C-enhancementCategory: An issue proposing an enhancement or a PR with one.
    A-diagnosticsArea: Messages for errors, warnings, and lints
    A-closuresArea: Closures (`|…| { … }`)
    on Jan 24, 2018
  2. nikomatsakis commented on Feb 1, 2018

    @nikomatsakis
    Contributor

    cc @estebank -- was this fixed by #47747 ? Any idea what the problem is here?

  3. nikomatsakis commented on Feb 1, 2018

    @nikomatsakis
    Contributor

    triage: P-high

  4. estebank commented on Feb 1, 2018

    @estebank
    Contributor

    I don't think the presentation changes that that PR (and the one it's supplementing) introduced. It looks to me that it doesn't actually get to check E0593. I'll dig deeper.

  5. nikomatsakis commented on Feb 1, 2018

    @nikomatsakis
    Contributor

    @estebank great, if you don't have time, lemme know

  6. estebank commented on Feb 5, 2018

    @estebank
    Contributor

    @nikomatsakis I didn't have time to look into this and will unlikely have time to perform a bisect during the week. I can confirm that this was introduced earlier than #47747.

  7. nikomatsakis commented on Feb 5, 2018

    @nikomatsakis
    Contributor

    cc @rust-lang/compiler -- can somebody pick this up to try and get to the bottom of it?

  8. kennytm commented on Feb 5, 2018

    @kennytm
    Member

    Bisection result is #45879.

    Details

    Test script:

    #!/bin/sh
    $RUSTC_RELATIVE -V
    ! ( $RUSTC_RELATIVE 1.rs 2>&1 | grep E0593 )

    1.rs is the source in the bug report.

    Output:

    $ RUST_LOG=rust_sysroot=info target/release/bisect --preserve --test test.sh --start 33374fa9d09e2a790979b31e61100dfed4b44139 --end b65f0bedd2f22d9661ecb7092f07746dc2ccfb0d
    INFO:rust_sysroot: Getting commits from the git checkout in 33374fa9d09e2a790979b31e61100dfed4b44139...b65f0bedd2f22d9661ecb7092f07746dc2ccfb0d
    INFO:rust_sysroot: Received 272 commits
    Searching in 272 commits; about 9 steps
    rustc 1.24.0-nightly (830599b19 2017-12-11)
    rustc 1.24.0-nightly (315fbf751 2017-12-01)
    rustc 1.23.0-nightly (2f84fb5cc 2017-11-26)
    rustc 1.23.0-nightly (0916bbc00 2017-11-23)
    rustc 1.23.0-nightly (96e9cee77 2017-11-22)
    rustc 1.23.0-nightly (ebda7662d 2017-11-21)
    error[E0593]: closure is expected to take a single tuple as argument, but it takes 2 distinct arguments
    rustc 1.23.0-nightly (63739ab7b 2017-11-21)
    error[E0593]: closure is expected to take a single tuple as argument, but it takes 2 distinct arguments
    rustc 1.23.0-nightly (d6d09e0b4 2017-11-21)
    searched commits 33374fa9d09e2a790979b31e61100dfed4b44139 through b65f0bedd2f22d9661ecb7092f07746dc2ccfb0d
    regression in 7; Some(Commit { sha: "d6d09e0b4dac93ae07dae6206bf95e7cea0124a2", date: 2017-11-21T22:52:19Z, summary: "Auto merge of #45879 - nikomatsakis:nll-kill-cyclic-closures, r=arielb1" })
    
  9. nikomatsakis commented on Feb 6, 2018

    @nikomatsakis
    Contributor

    D'oh, that's my pr :)

  10. nikomatsakis commented on Feb 8, 2018

    @nikomatsakis
    Contributor

    I wonder if this really broke in 053383d...? at least, when I trace what's happening, that seems to be where it goes wrong. But I guess the bisection doesn't lie.

  11. nikomatsakis commented on Feb 8, 2018

    @nikomatsakis
    Contributor

    Anyway I think the problem roughly is here:

    } else if expected_sig.inputs_and_output.len() != decl.inputs.len() + 1 {
    // we could probably handle this case more gracefully
    return self.sig_of_closure_no_expectation(expr_def_id, decl, body);
    }

    This corresponds to the case where (a) we figured out from context that the fn needs N parameters but (b) it is declared with M parameters. As you can see from the comment, "we could probably handle this case more gracefully". What we do now is to ignore the expectations and just give those parameters "unknown types".

    I'm not sure yet the best way to fix this -- we could certainly report a useful error here, we have a lot of the information we want. But then I think we might get duplicate errors. We could perhaps report an error and then give the parameters the type of TyErr ("something went wrong!"), which would suppress duplicates and so forth.

    Hmm, that's probably best.

  12. Rantanen commented on Feb 8, 2018

    @Rantanen
    ContributorAuthor

    We could perhaps report an error and then give the parameters the type of TyErr ("something went wrong!"), which would suppress duplicates and so forth.

    As a user, the "Type must be known at compile time" error just ends up being confusing as that makes me search for ways to annotate the type, which is just wasted effort - so reporting the first error and skipping the second error might actually be better than reporting both issues.

  13. estebank commented on Feb 9, 2018

    @estebank
    Contributor

    @nikomatsakis for what is worth, I don't think we're taking advantage of TyErr nearly enough to silence errors down the line and I'm very much in favor of doing so in this case. As @Rantanen points out, the first error is much more useful than the later one, and this seems to be a common theme across different cases that result in multiple cascading errors.

  14. nikomatsakis commented on Feb 9, 2018

    @nikomatsakis
    Contributor

    I have a fix.

  15. nikomatsakis commented on Feb 9, 2018

    @nikomatsakis
    Contributor

    Something weird happened with git but once I get that straightened out, will open a PR.

  16. added a commit that references this issue on Feb 16, 2018
    fefd00d
  17. added 2 commits that reference this issue on Feb 19, 2018
    e91f1c0
  18. added
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Feb 22, 2018
  19. added a commit that references this issue on Feb 23, 2018
    1e67c13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-closuresArea: Closures (`|…| { … }`)A-diagnosticsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.P-highHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-betaPerformance or correctness regression from stable to beta.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions