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

Print missing semicolon warning for type-inferred ints #29396

Closed
wants to merge 2 commits into from

Conversation

dylanmckay
Copy link
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
Collaborator

r? @nikomatsakis

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

@dylanmckay
Copy link
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.

// inform the user of a semicolon in this case.
(&ty::TyInt(ast::TyI32),&ty::TyInt(..)) => true,
(&ty::TyInt(ast::TyI32),&ty::TyUint(..)) => true,
(a,b) => (a == b),
Copy link
Member

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
Contributor Author

@sanxiyn fixed.

@alexcrichton
Copy link
Member

@bors: r+ b2f72c3

Thanks!

// to be evaluated as i32 values. We still want to
// inform the user of a semicolon in this case.
(&ty::TyInt(ast::TyI32), &ty::TyInt(..)) => true,
(&ty::TyInt(ast::TyI32), &ty::TyUint(..)) => true,
Copy link
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
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
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
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
Copy link
Member

sanxiyn commented Oct 28, 2015

@bors r-

@dylanmckay dylanmckay closed this Oct 28, 2015
@dylanmckay
Copy link
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