Skip to content

Issue 4920 autoref index operator #5558

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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/libcore/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,5 @@ pub trait Shr<RHS,Result> {

#[lang="index"]
pub trait Index<Index,Result> {
fn index(&self, index: Index) -> Result;
fn index(&self, index: &Index) -> Result;
}
1 change: 0 additions & 1 deletion src/librustc/metadata/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,6 @@ fn get_self_ty(item: ebml::Doc) -> ast::self_ty_ {
let self_ty_kind = string[0];
match self_ty_kind as char {
's' => { return ast::sty_static; }
'r' => { return ast::sty_by_ref; }
'v' => { return ast::sty_value; }
'@' => { return ast::sty_box(get_mutability(string[1])); }
'~' => { return ast::sty_uniq(get_mutability(string[1])); }
Expand Down
3 changes: 0 additions & 3 deletions src/librustc/metadata/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,9 +410,6 @@ fn encode_self_type(ebml_w: writer::Encoder, self_type: ast::self_ty_) {
sty_static => {
ebml_w.writer.write(&[ 's' as u8 ]);
}
sty_by_ref => {
ebml_w.writer.write(&[ 'r' as u8 ]);
}
sty_value => {
ebml_w.writer.write(&[ 'v' as u8 ]);
}
Expand Down
10 changes: 5 additions & 5 deletions src/librustc/middle/astencode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ fn simplify_ast(ii: ast::inlined_item) -> ast::inlined_item {
}

fn decode_ast(par_doc: ebml::Doc) -> ast::inlined_item {
let chi_doc = par_doc[c::tag_tree as uint];
let chi_doc = par_doc.get(c::tag_tree as uint);
let d = &reader::Decoder(chi_doc);
Decodable::decode(d)
}
Expand Down Expand Up @@ -1089,9 +1089,9 @@ impl ebml_decoder_decoder_helpers for reader::Decoder {
fn decode_side_tables(xcx: @ExtendedDecodeContext,
ast_doc: ebml::Doc) {
let dcx = xcx.dcx;
let tbl_doc = ast_doc[c::tag_table as uint];
let tbl_doc = ast_doc.get(c::tag_table as uint);
for reader::docs(tbl_doc) |tag, entry_doc| {
let id0 = entry_doc[c::tag_table_id as uint].as_int();
let id0 = entry_doc.get(c::tag_table_id as uint).as_int();
let id = xcx.tr_id(id0);

debug!(">> Side table document with tag 0x%x \
Expand All @@ -1103,7 +1103,7 @@ fn decode_side_tables(xcx: @ExtendedDecodeContext,
} else if tag == (c::tag_table_moves_map as uint) {
dcx.maps.moves_map.insert(id);
} else {
let val_doc = entry_doc[c::tag_table_val as uint];
let val_doc = entry_doc.get(c::tag_table_val as uint);
let val_dsr = &reader::Decoder(val_doc);
if tag == (c::tag_table_def as uint) {
let def = decode_def(xcx, val_doc);
Expand Down Expand Up @@ -1172,7 +1172,7 @@ fn encode_item_ast(ebml_w: writer::Encoder, item: @ast::item) {

#[cfg(test)]
fn decode_item_ast(par_doc: ebml::Doc) -> @ast::item {
let chi_doc = par_doc[c::tag_tree as uint];
let chi_doc = par_doc.get(c::tag_tree as uint);
let d = &reader::Decoder(chi_doc);
@Decodable::decode(d)
}
Expand Down
15 changes: 0 additions & 15 deletions src/librustc/middle/borrowck/gather_loans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,21 +180,6 @@ fn req_loans_in_expr(ex: @ast::expr,
}
}

match self.bccx.method_map.find(&ex.id) {
Some(ref method_map_entry) => {
match (*method_map_entry).explicit_self {
ast::sty_by_ref => {
let rcvr_cmt = self.bccx.cat_expr(rcvr);
self.guarantee_valid(rcvr_cmt, m_imm, scope_r);
}
_ => {} // Nothing to do.
}
}
None => {
self.tcx().sess.span_bug(ex.span, ~"no method map entry");
}
}

visit::visit_expr(ex, self, vt);
}

Expand Down
5 changes: 0 additions & 5 deletions src/librustc/middle/liveness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,11 +467,6 @@ fn visit_fn(fk: &visit::fn_kind,
match *fk {
fk_method(_, _, method) => {
match method.self_ty.node {
sty_by_ref => {
fn_maps.add_variable(Arg(method.self_id,
special_idents::self_,
by_ref));
}
sty_value | sty_region(*) | sty_box(_) | sty_uniq(_) => {
fn_maps.add_variable(Arg(method.self_id,
special_idents::self_,
Expand Down
43 changes: 9 additions & 34 deletions src/librustc/middle/moves.rs
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ pub impl VisitContext {

expr_unary(deref, base) => { // *base
if !self.use_overloaded_operator(
expr, DontDerefArgs, base, [], visitor)
expr, base, [], visitor)
{
// Moving out of *base moves out of base.
self.use_expr(base, comp_mode, visitor);
Expand All @@ -450,7 +450,7 @@ pub impl VisitContext {

expr_index(lhs, rhs) => { // lhs[rhs]
if !self.use_overloaded_operator(
expr, DontDerefArgs, lhs, [rhs], visitor)
expr, lhs, [rhs], visitor)
{
self.use_expr(lhs, comp_mode, visitor);
self.consume_expr(rhs, visitor);
Expand Down Expand Up @@ -579,15 +579,15 @@ pub impl VisitContext {

expr_unary(_, lhs) => {
if !self.use_overloaded_operator(
expr, DontDerefArgs, lhs, [], visitor)
expr, lhs, [], visitor)
{
self.consume_expr(lhs, visitor);
}
}

expr_binary(_, lhs, rhs) => {
if !self.use_overloaded_operator(
expr, DoDerefArgs, lhs, [rhs], visitor)
expr, lhs, [rhs], visitor)
{
self.consume_expr(lhs, visitor);
self.consume_expr(rhs, visitor);
Expand Down Expand Up @@ -659,7 +659,6 @@ pub impl VisitContext {

fn use_overloaded_operator(&self,
expr: @expr,
deref_args: DerefArgs,
receiver_expr: @expr,
arg_exprs: &[@expr],
visitor: vt<VisitContext>) -> bool
Expand All @@ -670,21 +669,10 @@ pub impl VisitContext {

self.use_receiver(expr.id, expr.span, receiver_expr, visitor);

// The deref_args stuff should eventually be converted into
// adjustments. Moreover, it should eventually be applied
// consistently to all overloaded operators. But that's not
// how it is today.
match deref_args {
DoDerefArgs => {
// we are always passing in a borrowed pointer,
// so it's always read mode:
for arg_exprs.each |arg_expr| {
self.use_expr(*arg_expr, Read, visitor);
}
}
DontDerefArgs => {
self.use_fn_args(expr.callee_id, arg_exprs, visitor);
}
// for overloaded operatrs, we are always passing in a
// borrowed pointer, so it's always read mode:
for arg_exprs.each |arg_expr| {
self.use_expr(*arg_expr, Read, visitor);
}

return true;
Expand Down Expand Up @@ -737,20 +725,7 @@ pub impl VisitContext {
receiver_expr: @expr,
visitor: vt<VisitContext>)
{
let callee_mode = match self.method_map.find(&expr_id) {
Some(ref method_map_entry) => {
match method_map_entry.explicit_self {
sty_by_ref => by_ref,
_ => by_copy
}
}
None => {
self.tcx.sess.span_bug(
span,
~"no method map entry");
}
};
self.use_fn_arg(callee_mode, receiver_expr, visitor);
self.use_fn_arg(by_copy, receiver_expr, visitor);
}

fn use_fn_args(&self,
Expand Down
3 changes: 1 addition & 2 deletions src/librustc/middle/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ use syntax::ast::{named_field, ne, neg, node_id, pat, pat_enum, pat_ident};
use syntax::ast::{path, pat_box, pat_lit, pat_range, pat_struct};
use syntax::ast::{pat_tup, pat_uniq, pat_wild, prim_ty, private, provided};
use syntax::ast::{public, required, rem, self_ty_, shl, shr, stmt_decl};
use syntax::ast::{struct_dtor, struct_field, struct_variant_kind, sty_by_ref};
use syntax::ast::{struct_dtor, struct_field, struct_variant_kind};
use syntax::ast::{sty_static, subtract, trait_ref, tuple_variant_kind, Ty};
use syntax::ast::{ty_bool, ty_char, ty_f, ty_f32, ty_f64, ty_float, ty_i};
use syntax::ast::{ty_i16, ty_i32, ty_i64, ty_i8, ty_int, TyParam, ty_path};
Expand Down Expand Up @@ -3792,7 +3792,6 @@ pub impl Resolver {
// we only have self ty if it is a non static method
let self_binding = match method.self_ty.node {
sty_static => { NoSelfBinding }
sty_by_ref => { HasSelfBinding(method.self_id, true) }
_ => { HasSelfBinding(method.self_id, false) }
};

Expand Down
16 changes: 6 additions & 10 deletions src/librustc/middle/trans/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -766,18 +766,15 @@ fn trans_rvalue_dps_unadjusted(bcx: block, expr: @ast::expr,
}
ast::expr_binary(_, lhs, rhs) => {
// if not overloaded, would be RvalueDatumExpr
return trans_overloaded_op(bcx, expr, lhs, ~[rhs], dest,
DoAutorefArg);
return trans_overloaded_op(bcx, expr, lhs, ~[rhs], dest);
}
ast::expr_unary(_, subexpr) => {
// if not overloaded, would be RvalueDatumExpr
return trans_overloaded_op(bcx, expr, subexpr, ~[], dest,
DontAutorefArg);
return trans_overloaded_op(bcx, expr, subexpr, ~[], dest);
}
ast::expr_index(base, idx) => {
// if not overloaded, would be RvalueDatumExpr
return trans_overloaded_op(bcx, expr, base, ~[idx], dest,
DontAutorefArg);
return trans_overloaded_op(bcx, expr, base, ~[idx], dest);
}
ast::expr_cast(val, _) => {
match ty::get(node_id_type(bcx, expr.id)).sty {
Expand Down Expand Up @@ -1644,16 +1641,15 @@ fn trans_overloaded_op(bcx: block,
expr: @ast::expr,
rcvr: @ast::expr,
+args: ~[@ast::expr],
dest: Dest,
+autoref_arg: AutorefArg) -> block
dest: Dest) -> block
{
let origin = *bcx.ccx().maps.method_map.get(&expr.id);
let fty = node_id_type(bcx, expr.callee_id);
return callee::trans_call_inner(
bcx, expr.info(), fty,
expr_ty(bcx, expr),
|bcx| meth::trans_method_callee(bcx, expr.callee_id, rcvr, origin),
callee::ArgExprs(args), dest, autoref_arg);
callee::ArgExprs(args), dest, DoAutorefArg);
}

fn int_cast(bcx: block, lldsttype: TypeRef, llsrctype: TypeRef,
Expand Down Expand Up @@ -1806,7 +1802,7 @@ fn trans_assign_op(bcx: block,
// FIXME(#2528) evaluates the receiver twice!!
let scratch = scratch_datum(bcx, dst_datum.ty, false);
let bcx = trans_overloaded_op(bcx, expr, dst, ~[src],
SaveIn(scratch.val), DoAutorefArg);
SaveIn(scratch.val));
return scratch.move_to_datum(bcx, DROP_EXISTING, dst_datum);
}

Expand Down
17 changes: 1 addition & 16 deletions src/librustc/middle/trans/meth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ pub fn trans_trait_callee(bcx: block,

let llpair = match explicit_self {
ast::sty_region(*) => Load(bcx, llpair),
ast::sty_static | ast::sty_by_ref | ast::sty_value |
ast::sty_static | ast::sty_value |
ast::sty_box(_) | ast::sty_uniq(_) => llpair
};

Expand Down Expand Up @@ -645,21 +645,6 @@ pub fn trans_trait_callee_from_llval(bcx: block,
ast::sty_static => {
bcx.tcx().sess.bug(~"shouldn't see static method here");
}
ast::sty_by_ref => {
// We need to pass a pointer to a pointer to the payload.
match store {
ty::BoxTraitStore |
ty::BareTraitStore |
ty::UniqTraitStore => {
llself = GEPi(bcx, llbox, [0u, abi::box_field_body]);
}
ty::RegionTraitStore(_) => {
llself = llbox;
}
}

self_mode = ast::by_ref;
}
ast::sty_value => {
bcx.tcx().sess.bug(~"methods with by-value self should not be \
called on objects");
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/middle/typeck/check/method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ use core::hashmap::linear::LinearSet;
use core::result;
use core::uint;
use core::vec;
use syntax::ast::{def_id, sty_by_ref, sty_value, sty_region, sty_box};
use syntax::ast::{def_id, sty_value, sty_region, sty_box};
use syntax::ast::{sty_uniq, sty_static, node_id, by_copy, by_ref};
use syntax::ast::{m_const, m_mutbl, m_imm};
use syntax::ast;
Expand Down Expand Up @@ -527,7 +527,7 @@ pub impl<'self> LookupContext<'self> {
ast::sty_region(_) => {
return; // inapplicable
}
ast::sty_by_ref | ast::sty_region(_) => vstore_slice(r)
ast::sty_region(_) => vstore_slice(r)
ast::sty_box(_) => vstore_box, // XXX NDM mutability
ast::sty_uniq(_) => vstore_uniq
}
Expand Down Expand Up @@ -741,7 +741,7 @@ pub impl<'self> LookupContext<'self> {
// shouldn't really have to be.
let rcvr_substs = {
match self_decl {
sty_static | sty_value | sty_by_ref |
sty_static | sty_value |
sty_box(_) | sty_uniq(_) => {
self_substs
}
Expand Down Expand Up @@ -1327,7 +1327,7 @@ pub fn transform_self_type_for_method(tcx: ty::ctxt,
tcx.sess.bug(~"calling transform_self_type_for_method on \
static method");
}
sty_by_ref | sty_value => {
sty_value => {
impl_ty
}
sty_region(_, mutability) => {
Expand Down
43 changes: 3 additions & 40 deletions src/librustc/middle/typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1064,44 +1064,7 @@ pub fn impl_self_ty(vcx: &VtableContext,
-> ty_param_substs_and_ty {
let tcx = vcx.tcx();

let (n_tps, region_param, raw_ty) = if did.crate == ast::local_crate {
let region_param = tcx.region_paramd_items.find(&did.node).
map_consume(|x| *x);
match tcx.items.find(&did.node) {
Some(&ast_map::node_item(@ast::item {
node: ast::item_impl(ref ts, _, st, _),
_
}, _)) => {
let region_parameterization =
RegionParameterization::from_variance_and_generics(
region_param,
ts);
(ts.ty_params.len(),
region_param,
vcx.ccx.to_ty(&rscope::type_rscope(region_parameterization), st))
}
Some(&ast_map::node_item(@ast::item {
node: ast::item_struct(_, ref ts),
id: class_id,
_
},_)) => {
/* If the impl is a class, the self ty is just the class ty
(doing a no-op subst for the ty params; in the next step,
we substitute in fresh vars for them)
*/
(ts.ty_params.len(),
region_param,
ty::mk_struct(tcx, local_def(class_id),
substs {
self_r: rscope::bound_self_region(region_param),
self_ty: None,
tps: ty::ty_params_to_tys(tcx, ts)
}))
}
_ => { tcx.sess.bug(~"impl_self_ty: unbound item or item that \
doesn't have a self_ty"); }
}
} else {
let (n_tps, region_param, raw_ty) = {
let ity = ty::lookup_item_type(tcx, did);
(vec::len(*ity.bounds), ity.region_param, ity.ty)
};
Expand Down Expand Up @@ -1586,7 +1549,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
lookup_op_method(
fcx, ex, rhs_expr, rhs_t,
fcx.tcx().sess.ident_of(mname), ~[],
DontDerefArgs, DontAutoderefReceiver,
DoDerefArgs, DontAutoderefReceiver,
|| {
fcx.type_error_message(ex.span, |actual| {
fmt!("cannot apply unary operator `%s` to type `%s`",
Expand Down Expand Up @@ -2794,7 +2757,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
expr.span, raw_base_t);
let ret_ty = lookup_op_method(fcx, expr, base, resolved,
tcx.sess.ident_of(~"index"),
~[idx], DontDerefArgs, AutoderefReceiver,
~[idx], DoDerefArgs, AutoderefReceiver,
|| {
fcx.type_error_message(expr.span, |actual|
fmt!("cannot index a value \
Expand Down
Loading