-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Use slicing syntax instead of methods and add a feature gate #17620
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
Conversation
Does it really make sense to deprecate methods if the replacement is feature gated? |
@@ -3407,9 +3407,9 @@ may be specified with `..`. For example: | |||
# let x = 2i; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Three lines above, ..
needs to be changed to ...
as well (i.e., ‘A range of values may be specified with ...
.’)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh whoops, that change shouldn't even be part of this branch.
Can you do collections::btree as well? |
@sfackler yes, I think so. They are feature gated because the syntax might change, not because they might go away. Slicing syntax is definitely the preferred use. |
I agree with @sfackler: I would prefer not to deprecate until slice syntax is "officially" supported, rather than encourage people to opt in to a feature gate. The reasons to have this behind a feature gate are (1) working through bugs and (2) the fact that at least the That said, it seems fine to land the internal use of this syntax for now. I'm willing to review this PR. |
@@ -3813,7 +3813,7 @@ type signature of `print`, and the cast expression in `main`. | |||
Within the body of an item that has type parameter declarations, the names of | |||
its type parameters are types: | |||
|
|||
``` | |||
```ignore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you undo the deprecation, please remove the ignore
here. (And in general, better to add a silent #[allow(deprecated)]
but otherwise keep the test.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For some reason I couldn't add attributes to this code snippet - I tried to allow slicing syntax but there was no way I could get it to work.
Hm, so I just noticed that the new impl<'a> Slice<&'a Idx, T> for U { ... } to allow references with arbitrary lifetimes. But for |
We may want to resolve the by val/by ref issue before moving forward here. |
Nevermind -- this only affects usage of the methods directly, not the syntax. We should still consider what's desired, but we can move forward with this PR. |
fn split_at(&self, mid: uint) -> (&'a [T], &'a [T]) { | ||
(self.slice(0, mid), self.slice(mid, self.len())) | ||
((*self)[..mid], (*self)[mid..]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a shame the (*self)
is needed here. Is that fundamental?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is a choice - when looking up the trait method we don't autoderef the receiver (self has type &&[T]
here) - that is just a flag we pass in to the trait matching algorithm though, so it should be easy to change. However, I was following what index does, I assume we should be consistent with that, one way or the other.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And I don't know why index is implemented that way. Perhaps @pcwalton does?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that we should be consistent, but I'm not sure that the current design of things like Index
is where we want it to be. I know that @nikomatsakis has been thinking about this, especially as it related to method dispatch issues elsewhere.
Ok, I've finished reviewing -- looks great overall, this is a nice readability win! I'm curious to hear more about the |
88260ff
to
b1b27db
Compare
Deprecates slicing methods from ImmutableSlice/MutableSlice in favour of slicing syntax or the methods in Slice/SliceMut. Closes rust-lang#17273.
[breaking-change] If you are using slicing syntax you will need to add #![feature(slicing_syntax)] to your crate.
This PR reverts #17620, which caused a significant regression for slices. As discussed with @alexcrichton, all of the public-facing changes of the earlier PR need to be rolled back, and it's not clear that we should move the libraries over to this new notation yet anyway (especially given its feature-gated status). Closes #17710
This PR reverts #17620, which caused a significant regression for slices. As discussed with @alexcrichton, all of the public-facing changes of the earlier PR need to be rolled back, and it's not clear that we should move the libraries over to this new notation yet anyway (especially given its feature-gated status). Closes #17710
Edition aware parser Fixes rust-lang/rust-analyzer#16324 by allowing us to properly thread through the edition to the parser
Edition aware parser Fixes rust-lang/rust-analyzer#16324 by allowing us to properly thread through the edition to the parser
cc @aturon
r? anyone?