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

Encourage fixed-size integer #16446

Closed
l0kod opened this issue Aug 12, 2014 · 20 comments
Closed

Encourage fixed-size integer #16446

l0kod opened this issue Aug 12, 2014 · 20 comments

Comments

@l0kod
Copy link
Contributor

l0kod commented Aug 12, 2014

The #6023 force to use a type suffix for integers. As discussed in rust-lang/rfcs#115 and #9940, the int and uint should only be used for memory-related values (e.g. length).

The documentations mostly use i suffix examples. It should encourage the use of fixed-size integer (e.g. u32) for common uses.

A more strict rule could be to remove the u and i from allowed suffixes, but to rely on full explicit typing (e.g. : int) when really needed.
This could be annoying for range-like functions but it's not that burdensome to use the explicit generic typing (e.g. range::<uint>(0, 5)).

@huonw
Copy link
Member

huonw commented Aug 12, 2014

cc #11831

@steveklabnik
Copy link
Member

The documentations

Can you be more specific? I also feel like #15526 is related, this may just be a superset of that issue.

@l0kod
Copy link
Contributor Author

l0kod commented Aug 12, 2014

The documentations (i.e. tutorial, guide…) part is definitely #15526.

The strict rule about removing i and/or u can be discussed here.

@thestinger
Copy link
Contributor

I don't think the suffixes should be removed. Fixed-size integers are a better choice for anything not being used for sizes / indexing, but I have a feeling that the most common case is tied to container lengths. I didn't like the fallback because it was prone to causing mistakes, but I don't think we should go out of the way to make things more painful.

@vks
Copy link
Contributor

vks commented Aug 15, 2014

Currently the documentation teaches new users to use int and uint in a lot of places where it is not related to any container size. Especially int is very rarely related to container sizes (which are never negative).

@l0kod
Copy link
Contributor Author

l0kod commented Aug 18, 2014

cc rust-lang/rfcs#161

@l0kod
Copy link
Contributor Author

l0kod commented Aug 25, 2014

cc #16736

@l0kod
Copy link
Contributor Author

l0kod commented Sep 1, 2014

cc rust-lang/rust-guidelines#24

@l0kod
Copy link
Contributor Author

l0kod commented Sep 1, 2014

cc #14758

@l0kod
Copy link
Contributor Author

l0kod commented Sep 1, 2014

@thestinger, could you please change the label for "metabug" (if appropriate)?

@l0kod
Copy link
Contributor Author

l0kod commented Sep 3, 2014

cc rust-lang/rfcs#212

@l0kod
Copy link
Contributor Author

l0kod commented Nov 15, 2014

cc rust-lang/rfcs#464

@l0kod
Copy link
Contributor Author

l0kod commented Jan 3, 2015

@l0kod
Copy link
Contributor Author

l0kod commented Jan 3, 2015

cc rust-lang/rfcs#544

@l0kod
Copy link
Contributor Author

l0kod commented Jan 3, 2015

@l0kod
Copy link
Contributor Author

l0kod commented Jan 3, 2015

Integer overflow bug:

@huonw
Copy link
Member

huonw commented Jan 3, 2015

@l0kod #17795 doesn't seem to be caused by the names/sizes/conventions of integers in Rust. At some point in the past libc::c_uint was precisely correct (LLVM used unsigned int) but then LLVM was changed to use unsigned long long without us realising, causing the FFI declaration to become incorrect.

@steveklabnik
Copy link
Member

We've gone through and made a lot of changes related to this, and so I'm gonna give it a close. If we find anything else, it should also be fixed.

bors added a commit to rust-lang-ci/rust that referenced this issue Feb 18, 2024
Implement `literal_from_str` for proc macro server

Closes rust-lang#16233

Todos and unanswered questions:

- [x] Is this the correct approach? Can both the legacy and `rust_analyzer_span` servers depend on the `syntax` crate?
- [ ] How should we handle suffixes for string literals? It doesn't seem like `rust-analyzer` preservers suffix information after parsing.
- [x] Why are the `expect` tests failing? Specifically `test_fn_like_macro_clone_literals`
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

5 participants