Skip to content

Moving away from deprecated i/u suffixes in libcore #21511

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

Merged
merged 1 commit into from
Jan 25, 2015
Merged

Moving away from deprecated i/u suffixes in libcore #21511

merged 1 commit into from
Jan 25, 2015

Conversation

alfiedotwtf
Copy link
Contributor

No description provided.

@rust-highfive
Copy link
Contributor

r? @huonw

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

@alfiedotwtf
Copy link
Contributor Author

If everyone is happy with this change, I'll move forward with the rest. Otherwise, let me know what needs to be done and I'll give it a go.

Note: I was thinking of updating [u]int => [u]isize, but that should be a separate change.

@eddyb
Copy link
Member

eddyb commented Jan 22, 2015

I started looking through these and realized commenting on each one would be pointless.
Most uses of integral suffixes outside of code examples in documentation seem to be unnecessary.
Do we have any style guidelines related to the use of suffixes in general? cc @aturon

@alfiedotwtf
Copy link
Contributor Author

@eddyb I've tried looking for style on this but didn't find anything. The word on IRC today was to drop the suffix when it can be inferred, which I've done.

Are you sure you want to drop most suffixes? e.g.

let mut n = 0i;  // original: int
let mut n = 0is; // mine: isize
let mut n = 0;   // dropped: i32

I deliberately didn't want to change the datatypes like above, only move away from the deprecated suffixes.

@eddyb
Copy link
Member

eddyb commented Jan 22, 2015

@Alfie the type only changes if it's unconstrained anywhere, which seems a bit suspicious. Do you have examples of this? I'll look through the diff again, I guess.

@@ -846,7 +846,7 @@ macro_rules! tuple {
fn fmt(&self, f: &mut Formatter) -> Result {
try!(write!(f, "("));
let ($(ref $name,)*) = *self;
let mut n = 0i;
let mut n = 0is;
Copy link
Member

Choose a reason for hiding this comment

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

First usage that needs annotation. Even then, this is used for 3 states, which would be only 2 if we were to special-case one-element tuples. Feels saner that way IMO.
We can do it without adding another case to the macro, too, and while removing the peel helper macro.
Something like $first, $($name),*.

@eddyb
Copy link
Member

eddyb commented Jan 22, 2015

None of the 3 cases I found would actually cause a subtle change in semantics (the last one would error if 1 would default to a differently-sized type).
They are all in macros, and even then, the suffixes can be removed while cleaning up the way the macro works.
I ignored examples in doc comments because they are highly artificial, though some of them may work with less suffixes.

@alfiedotwtf
Copy link
Contributor Author

@eddyb Ok, no problem. I've updated the patch:

- Suffixes have been dropped in code
- Suffixes updated from deprecated i/u in documentation

I'd like for the examples to be updated because it's going to be confusing in the future once i/u are no longer valid syntax.

@alfiedotwtf alfiedotwtf changed the title moving from i/u to is/us suffixes in libcore Moving away from deprecated i/u suffixes in libcore Jan 23, 2015
'E' | 'e' if radix == 10 => 10u as $T,
'P' | 'p' if radix == 16 => 2u as $T,
'E' | 'e' if radix == 10 => 10.0 as $T,
'P' | 'p' if radix == 16 => 2.0 as $T,
Copy link
Member

Choose a reason for hiding this comment

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

You don't need as $T at all, the type is either f32 or f64.

@alfiedotwtf
Copy link
Contributor Author

@eddyb Thanks for that. I wasn't too sure about that one.

@huonw
Copy link
Member

huonw commented Jan 23, 2015

I think much of the documentation can have the suffixes dropped too: in most cases it doesn't matter if it's a i32 or isize or whatever, and the cases where it does matter it should infer (I would guess).

@alfiedotwtf
Copy link
Contributor Author

@huonw No problem. Fixed.

@@ -150,13 +150,13 @@ default_impl! { (), () }
default_impl! { bool, false }
default_impl! { char, '\x00' }

default_impl! { uint, 0u }
default_impl! { uint, 0us }
Copy link
Member

Choose a reason for hiding this comment

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

All of these suffixed integers should be able to be just 0.

@alfiedotwtf
Copy link
Contributor Author

@eddyb Thanks for the clarification. I wasn't too sure about that one. Fixed.

@eddyb
Copy link
Member

eddyb commented Jan 23, 2015

Right now the only us/is suffixes added in the entire diff are in the transmute calls in the slice iterators - which could be replaced later with something pointer-based (e.g. &mut *(1 as *mut _)).
I am honestly surprised this is possible on such a scale. Great work, @Alfie!

@alfiedotwtf
Copy link
Contributor Author

@eddyb Thanks for that. I wasn't sure what to replace it with, but that looks reasonable. Fixed.

@huonw
Copy link
Member

huonw commented Jan 24, 2015

@bors: r+ 4

Looks great!

@bors
Copy link
Collaborator

bors commented Jan 24, 2015

🙀 You have the wrong number! Please try again with 45b6d40.

@huonw
Copy link
Member

huonw commented Jan 24, 2015

@bors: r+ 45b6d40

(Drat, a single letter is too short. 😝 )

@bors
Copy link
Collaborator

bors commented Jan 24, 2015

⌛ Testing commit 45b6d40 with merge b64d9fe...

@bors
Copy link
Collaborator

bors commented Jan 24, 2015

💔 Test failed - auto-mac-32-opt

@alfiedotwtf
Copy link
Contributor Author

Was that auto-mac-32-opt failure legit?

@@ -1138,7 +1138,7 @@ pub trait AdditiveIterator<A> {
/// ```
/// use std::iter::AdditiveIterator;
///
/// let a = [1i, 2, 3, 4, 5];
/// let a = [1, 2, 3, 4, 5];
Copy link
Member

Choose a reason for hiding this comment

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

I think this needs a suffix (e.g. 1i32).

@huonw
Copy link
Member

huonw commented Jan 24, 2015

@Alfie yeah, I think so.

@alfiedotwtf
Copy link
Contributor Author

@huonw Thanks. Ok, will fix.

Can you just clear something up for me please. These are all in comments and not code, but it still failed?

Also, you said to make the following to an i32:

  • /// let a = [1i, 2, 3, 4, 5];
  • /// let a = [1, 2, 3, 4, 5];

I thought that if an integer doesn't have a suffix, it's typed as an i32 as a default? If so, why should this need an i32 suffix?

@huonw
Copy link
Member

huonw commented Jan 24, 2015

The rustdoc supports running code examples in doc-comments as tests and we run these tests on all crates to keep the docs up to date.

I'm not sure what's happening with those examples, but inference can be a little sensitive/less-than-perfect when there's closures around, at the moment.

@alfiedotwtf
Copy link
Contributor Author

@huonw Thanks for the explanation.

@huonw
Copy link
Member

huonw commented Jan 25, 2015

@bors: r+ 42958d3

@@ -258,7 +258,29 @@ impl CharExt for char {
#[inline]
#[unstable = "pending decision about Iterator/Writer/Reader"]
fn encode_utf8(self, dst: &mut [u8]) -> Option<uint> {
encode_utf8_raw(self as u32, dst)
// Marked #[inline] to allow llvm optimizing it away
Copy link
Member

Choose a reason for hiding this comment

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

Hm, why was this changed?

@alfiedotwtf
Copy link
Contributor Author

I got a conflict while rebasing onto master. I was sure I resolved it correctly. Fixing now :(

@alfiedotwtf
Copy link
Contributor Author

Apologies. I resolved the conflict that the wrong way. Fixed.

@huonw
Copy link
Member

huonw commented Jan 25, 2015

@bors: r+ f67e747

It's not problem at all, rebases are tricky like that sometimes.

@bors
Copy link
Collaborator

bors commented Jan 25, 2015

⌛ Testing commit f67e747 with merge 70b13a7...

bors added a commit that referenced this pull request Jan 25, 2015
@bors bors merged commit f67e747 into rust-lang:master Jan 25, 2015
@alfiedotwtf alfiedotwtf deleted the suffix-cleanup branch February 3, 2015 11:38
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.

5 participants