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

Type check failure in match for tuple. #4968

Closed
youknowone opened this issue Feb 15, 2013 · 2 comments
Closed

Type check failure in match for tuple. #4968

youknowone opened this issue Feb 15, 2013 · 2 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-typesystem Area: The type system

Comments

@youknowone
Copy link
Contributor

youknowone commented Feb 15, 2013

Case 1: Unexpected path error

Input code

const A: (int,int) = (3,4);
fn main() { match 42 { A => () } }

expected: type error on line r { }, because type of 0 is not tuple but r is.

result: compile error

log:

rust: task failed at 'Unsupported constant expr', <core-macros>:15
error: internal compiler error: unexpected failure
note: the compiler hit an unexpected failure path. this is a bug
note: try running with RUST_LOG=rustc=1,::rt::backtrace to get further details and report the results to github.com/mozilla/rust/issues
rust: task failed at 'explicit failure', <core-macros>:15
rust: domain main @0x7fd30b80c810 root task failed

Case 2: Unexpected silence and strange behavior
Input:

fn main() {
    let a_tuple = (1, 2);
    match 0 {
        a_tuple => {
            io::println("A");
        }
    }
}

Expected: type error on line r { }, because type of 0 is not tuple but r is.

Result: Unexpected warnings, silence complie and unexpected behavior.

Warnings:

min2.rs:2:8: 2:17 warning: unused variable: `a_tuple`
min2.rs:2     let a_tuple = (1, 2);
                  ^~~~~~~~~
min2.rs:4:8: 4:18 warning: unused variable: `a_tuple`
min2.rs:4         a_tuple => {
                  ^~~~~~~~~~

It should not be 'unused variable'

Output with execution:

$ ./min2
A

0 looks matched to (1,2)

Even more, trying next:

fn main() {
    let a_tuple = (1, 2);
    match 0 {
        a_tuple => {
            io::println("A");
        }
        _ => {
            io::println("B");
        }
    }
}

Unreachable _ error is raised.

min2.rs:7:8: 7:9 error: unreachable pattern
min2.rs:7         _ => {
                  ^
error: aborting due to previous error
rust: task failed at 'explicit failure', <core-macros>:15
rust: task failed at 'explicit failure', <core-macros>:15
rust: domain main @0x7f981b80c810 root task failed
@Kimundi
Copy link
Member

Kimundi commented Feb 16, 2013

Don't understand the first one, but I've run in the second case myself, see #4612.
The error messages are completely correct, just misleading.

fn main() {
    let a_tuple = (1, 2);     // Introduces new local variable 'a_tuple'
    match 0 {
        a_tuple => {          // Matches every possible value and binds them to a new local variable 'a_tuple'
            io::println("A"); // That variable never gets used here, hence the warning
        }
        _ => {                // Because the above arm matches everything, this arm can never be reached
            io::println("B");
        }
    }
}

@youknowone
Copy link
Contributor Author

youknowone commented Feb 18, 2013

@Kimundi Thank you. I get it now. I am not familiar with rust yet.

youknowone added a commit to youknowone/rust that referenced this issue Feb 18, 2013
bors added a commit that referenced this issue Feb 19, 2013
bors added a commit to rust-lang-ci/rust that referenced this issue May 2, 2020
Fix ICE on `unsound_collection_transmute`

Fixes rust-lang#4968

Check if `Ty`s are normalizable. It might show hidden false negative, I'm not sure.
Also, the regression tests are placed on two dirs, so move them to `/crashes`. I think it will be easier to find the right place.

changelog: Fix ICE on `unsound_collection_transmute`
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 A-typesystem Area: The type system
Projects
None yet
Development

No branches or pull requests

2 participants