Registry Mirror
Skip to content

Conversation

@dylanmckay

Copy link
Copy Markdown
Contributor

We only printed the extra semicolon warning if the type of the last
statement was the same as the return type of the function.

If a semicolon was appended, then the code

fn foo() -> u16 {
    1234;
}

Would not print the extra semicolon warning, because without knowing
that 1234 is the return value, the inference engine would take 1234 to
be an i32.

This adds extra logic to recognize this case.

Fixes issue #29307.

We only printed the extra semicolon warning if the type of the last
statement was the same as the return type of the function.

If a semicolon was appended, then the code

fn foo() -> u16 {
    1234;
}

Would not print the extra semicolon warning because without knowing
that 1234 is the return value, the inference engine would take 1234 to
be an i32.

This adds extra logic to recognize this case.
@rust-highfive

Copy link
Copy Markdown
Contributor

r? @nikomatsakis

(rust_highfive has picked a reviewer for you, use r? to override)

@dylanmckay

Copy link
Copy Markdown
Contributor Author

I have not ran the added test to see if it works - I'm not sure if "error-pattern:" will work for help messages. Let's see what travis thinks. It works.

Comment thread src/librustc/middle/liveness.rs Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Insert spaces after commas.

@dylanmckay

Copy link
Copy Markdown
Contributor Author

@sanxiyn fixed.

@alexcrichton

Copy link
Copy Markdown
Member

@bors: r+ b2f72c3

Thanks!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won’t… this make case like

fn foo() -> u16 {
    1234i32;
}

also print the note, even though i32 type is clearly intended?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't think about that. At the point in time liveliness is run, we don't have any other means of checking for a type-inferred int. Is this false positive worth it?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, this makes a compiler suggestion invalid in some cases, which is worse than suggesting nothing IMO. An idea that has been floating in my head is to try and try to reinfer the last expression with expected return value to see how it goes. Not sure if possible at this stage, though.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors: r-

@sanxiyn

sanxiyn commented Oct 28, 2015

Copy link
Copy Markdown
Contributor

@bors r-

@dylanmckay dylanmckay closed this Oct 28, 2015
@dylanmckay

Copy link
Copy Markdown
Contributor Author

It's not worth the false-positive for such a niche diagnostic.

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

Successfully merging this pull request may close these issues.

6 participants