Skip to content

N as T should interpret N as i32 if N is a literal #22004

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

Closed
mahkoh opened this issue Feb 6, 2015 · 4 comments
Closed

N as T should interpret N as i32 if N is a literal #22004

mahkoh opened this issue Feb 6, 2015 · 4 comments
Labels
A-type-system Area: Type system

Comments

@mahkoh
Copy link
Contributor

mahkoh commented Feb 6, 2015

If N is a literal then it's impossible for the compiler to infer a type for N because it will be cast to another type right away. Therefore it has to use the fallback which is i32. At the moment it infers T as the type of N.

@kmcallister kmcallister added the A-type-system Area: Type system label Feb 6, 2015
@Kimundi
Copy link
Member

Kimundi commented Feb 11, 2015

I agree that it does not make much sense, but this is intentional behavior and thus this issue should probably go in the RFC repo.

@huonw
Copy link
Member

huonw commented Feb 11, 2015

Does this cause problems in practice? Is it even observable other than via compiler lints about out-of-range literals?

@Kimundi
Copy link
Member

Kimundi commented Feb 11, 2015

I don't think it causes problems directly, but the mere fact that it is yet another weird special case is reason enough to not support it, imo.

Especially because there is a more idiomatic way already: Type suffixed integer literals. Why have a special way to write 100u8 as 100 as u8 that is inconsistent with how the as operator works everywhere else? Plus, 100: u8 will probably become possible as well in the future, which would have the same meaning as the current special case.

@mahkoh mahkoh closed this as completed Apr 9, 2015
@pnkfelix
Copy link
Member

pnkfelix commented Apr 9, 2015

Note that there are definitely problem associated with this oddity in the const-evaluator, see for example #23833

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-type-system Area: Type system
Projects
None yet
Development

No branches or pull requests

5 participants