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

Matching on a function causes "found structure or enum pattern" #12863

Closed
huonw opened this issue Mar 13, 2014 · 1 comment · Fixed by #18324
Closed

Matching on a function causes "found structure or enum pattern" #12863

huonw opened this issue Mar 13, 2014 · 1 comment · Fixed by #18324
Labels
A-diagnostics Area: Messages for errors, warnings, and lints E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added.

Comments

@huonw
Copy link
Member

huonw commented Mar 13, 2014

mod foo { pub fn bar() {} }
fn main() {
    match () {
        foo::bar => {}
    }
}
function-match.rs:4:9: 4:17 error: mismatched types: expected `()` but found an enum or structure pattern
function-match.rs:4         foo::bar => {}
                            ^~~~~~~~

This should be complaining about mismatched types.

(The module is necessary to force the compiler search/use the function; with just bar => {} it takes bar to be a variable binding.)

@flaper87
Copy link
Contributor

I agree, it should probably mention the exact type it found.

@ghost ghost added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Oct 25, 2014
fasterthanlime pushed a commit to fasterthanlime/rust that referenced this issue Jul 26, 2022
…ing-assignment, r=Veykril

Fix missing fields check on destructuring assignment

Fixes rust-lang#12838

When checking if the record literal in question is an assignee expression or not, the new fn `is_assignee_record_literal` iterates over its ancestors until it is sure. This isn't super efficient, as we don't cache anything and does the iteration for every record literal during missing fields check. Alternatively, we may want to have a field like `assignee` on `hir_def::Expr::{RecordLit, Array, Tuple, Call}` to tell if it's an assignee expression, which would be O(1) when checking later but have some memory overhead for the field.
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 E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants