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 of static variable name with some function's parameter name gives error. #23716

Closed
demelev opened this issue Mar 25, 2015 · 2 comments
Closed
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-type-system Area: Type system

Comments

@demelev
Copy link

demelev commented Mar 25, 2015

Rustc version: rustc 1.0.0-nightly (b0aad7d 2015-03-22) (built 2015-03-23)

static text : i32 = 1i32;

fn read_block(text: &str) {
}

fn main() {
}
src\main.rs:79:15: 79:19 error: static variables cannot be referenced in a patte
rn, use a `const` instead
src\main.rs:79 fn read_block(text: &str) {
                             ^~~~
error: aborting due to previous error
@steveklabnik
Copy link
Member

Hmm, I am not sure if this is a bug or not. I can see it both ways.

@steveklabnik steveklabnik added A-type-system Area: Type system A-diagnostics Area: Messages for errors, warnings, and lints labels Mar 26, 2015
@demelev
Copy link
Author

demelev commented Mar 26, 2015

As I understand, this error is related to the situation like this

static text : &str = "rust";

fn main() {
    match "rust compiler" {
        text => ... , // rather to use const text: &str = "rust"; 
        ....
    }
}
static text: &str = "rust";

fn foo( text: i32 ) {
     print!("{}", text); // usage of the function parameter
     print!("{}", ::text); // usage of the static variable
}

birkenfeld added a commit to birkenfeld/rust that referenced this issue May 2, 2016
The implementation mirrors the one for "constant defined here" annotation
used for constant patterns in the irrefutable-pattern case.

Fixes: rust-lang#23716
Manishearth added a commit to Manishearth/rust that referenced this issue May 3, 2016
resolve: print location of static for "static in pattern" error

The implementation mirrors the one for "constant defined here" annotation used for constant patterns in the irrefutable-pattern case.

Fixes: rust-lang#23716
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-type-system Area: Type system
Projects
None yet
Development

No branches or pull requests

2 participants