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

Underscore variables #27

Closed
mcfilib opened this issue Oct 30, 2017 · 3 comments
Closed

Underscore variables #27

mcfilib opened this issue Oct 30, 2017 · 3 comments

Comments

@mcfilib
Copy link

mcfilib commented Oct 30, 2017

When I set up my mock but I only use an underscore as the variable (see example below), the mock doesn't get created. Why does this happen when I use let _ but not let _m? Is the call being optimised away by the compiler? Is it worth adding a note in the documentation?

  let _ = mock("GET", "/recordings?device_id=0000")
    .with_status(201)
    .with_header("content-type", "text/plain")
    .with_body(json_body) // some json string
    .create();

Versions

rustc 1.22.0-nightly (d7e73e4b1 2017-10-04)
mockito-0.9.0
@lipanski
Copy link
Owner

good point. I've clarified this in 1205b59

I'm actually not sure why Rust treats the _ this way, but it's definitly a consistent behaviour. I've found this RFC but I'm still not exactly sure what the story behind this is.

@ozkriff
Copy link

ozkriff commented Sep 14, 2018

I'm actually not sure why Rust treats the _ this way

Saying "variable named _" is incorrect, as _ isn't a variable (binding), it's just a part of a pattern matching syntax, like mut, ref, | etc.

@lipanski
Copy link
Owner

@ozkriff good point. I tried to be more correct in 55d36f3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants