-
Notifications
You must be signed in to change notification settings - Fork 13k
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
librustc (RFC #34): Implement the new Index
and IndexMut
traits.
#15394
Conversation
let ref_ty = ty::ty_fn_ret(monomorphize_type(bcx, method_ty)); | ||
Datum::new(val, ref_ty, LvalueExpr) | ||
} | ||
None => { |
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.
Note for reviewers: This None
branch is the same as the code that was removed below.
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.
Would it be at all reasonable for this slice indexing to go via Index
and IndexMut
(i.e. just be implemented in the libraries)?
|
@@ -563,12 +562,6 @@ pub fn from_fn(len: uint, f: |index: uint| -> bool) -> Bitv { | |||
bitv | |||
} | |||
|
|||
impl ops::Index<uint,bool> for Bitv { |
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.
This can actually work:
static T: bool = true;
static F: bool = false;
impl ops::Index<uint, bool> for Bitv {
fn index<'a>(&'a self, i: &uint) -> &'a bool {
if self.get(*i) { &T } else { &F }
}
}
It's a little weird, but it does allow the bitv[n]
syntax.
LGTM, modulo the questions inline. |
FYI, code that used the old index trait most likely can't use the new ones. |
|
||
let vt = tvec::vec_types(bcx, ty::sequence_element_type(bcx.tcx(), base_datum.ty)); | ||
base::maybe_name_value(bcx.ccx(), vt.llunit_size, "unit_sz"); | ||
// Translate index expression and cast to a suitable LLVM integer. |
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 this comment doesn't apply to this arm?
re-r? @nick29581 Fixed the borrow check and added a test. |
… traits. This will break code that used the old `Index` trait. Change this code to use the new `Index` traits. For reference, here are their signatures: pub trait Index<Index,Result> { fn index<'a>(&'a self, index: &Index) -> &'a Result; } pub trait IndexMut<Index,Result> { fn index_mut<'a>(&'a mut self, index: &Index) -> &'a mut Result; } Closes rust-lang#6515. [breaking-change]
Updated and addressed @huonw's comments. re-r? @nick29581 |
This will break code that used the old `Index` trait. Change this code to use the new `Index` traits. For reference, here are their signatures: pub trait Index<Index,Result> { fn index<'a>(&'a self, index: &Index) -> &'a Result; } pub trait IndexMut<Index,Result> { fn index_mut<'a>(&'a mut self, index: &Index) -> &'a mut Result; } Closes #6515. [breaking-change] r? @nick29581
This will break code that used the old
Index
trait. Change this codeto use the new
Index
traits. For reference, here are their signatures:Closes #6515.
[breaking-change]
r? @nick29581