Skip to content

Commit 5c35047

Browse files
committed
librustc: Remove &const and *const from the language.
They are still present as part of the borrow check.
1 parent 58d6eb5 commit 5c35047

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+306
-457
lines changed

src/libextra/flate.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ pub mod rustrt {
2525

2626
#[link_name = "rustrt"]
2727
extern {
28-
pub fn tdefl_compress_mem_to_heap(psrc_buf: *const c_void,
28+
pub fn tdefl_compress_mem_to_heap(psrc_buf: *c_void,
2929
src_buf_len: size_t,
3030
pout_len: *mut size_t,
3131
flags: c_int)
3232
-> *c_void;
3333

34-
pub fn tinfl_decompress_mem_to_heap(psrc_buf: *const c_void,
34+
pub fn tinfl_decompress_mem_to_heap(psrc_buf: *c_void,
3535
src_buf_len: size_t,
3636
pout_len: *mut size_t,
3737
flags: c_int)

src/librustc/metadata/decoder.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -804,12 +804,9 @@ pub fn get_enum_variants(intr: @ident_interner, cdata: cmd, id: ast::NodeId,
804804
fn get_explicit_self(item: ebml::Doc) -> ast::explicit_self_ {
805805
fn get_mutability(ch: u8) -> ast::mutability {
806806
match ch as char {
807-
'i' => { ast::m_imm }
808-
'm' => { ast::m_mutbl }
809-
'c' => { ast::m_const }
810-
_ => {
811-
fail!("unknown mutability character: `%c`", ch as char)
812-
}
807+
'i' => ast::m_imm,
808+
'm' => ast::m_mutbl,
809+
_ => fail!("unknown mutability character: `%c`", ch as char),
813810
}
814811
}
815812

src/librustc/metadata/encoder.rs

+2-9
Original file line numberDiff line numberDiff line change
@@ -635,15 +635,8 @@ fn encode_explicit_self(ebml_w: &mut writer::Encoder, explicit_self: ast::explic
635635
fn encode_mutability(ebml_w: &writer::Encoder,
636636
m: ast::mutability) {
637637
match m {
638-
m_imm => {
639-
ebml_w.writer.write(&[ 'i' as u8 ]);
640-
}
641-
m_mutbl => {
642-
ebml_w.writer.write(&[ 'm' as u8 ]);
643-
}
644-
m_const => {
645-
ebml_w.writer.write(&[ 'c' as u8 ]);
646-
}
638+
m_imm => ebml_w.writer.write(&[ 'i' as u8 ]),
639+
m_mutbl => ebml_w.writer.write(&[ 'm' as u8 ]),
647640
}
648641
}
649642
}

src/librustc/metadata/tydecode.rs

-1
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,6 @@ fn parse_ty(st: &mut PState, conv: conv_did) -> ty::t {
417417
fn parse_mutability(st: &mut PState) -> ast::mutability {
418418
match peek(st) {
419419
'm' => { next(st); ast::m_mutbl }
420-
'?' => { next(st); ast::m_const }
421420
_ => { ast::m_imm }
422421
}
423422
}

src/librustc/metadata/tyencode.rs

-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ fn enc_mutability(w: @io::Writer, mt: ast::mutability) {
9999
match mt {
100100
m_imm => (),
101101
m_mutbl => w.write_char('m'),
102-
m_const => w.write_char('?')
103102
}
104103
}
105104

src/librustc/middle/borrowck/check_loans.rs

+10-8
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use mc = middle::mem_categorization;
2323
use middle::borrowck::*;
2424
use middle::moves;
2525
use middle::ty;
26-
use syntax::ast::{m_mutbl, m_imm, m_const};
26+
use syntax::ast::m_mutbl;
2727
use syntax::ast;
2828
use syntax::ast_util;
2929
use syntax::codemap::span;
@@ -220,9 +220,9 @@ impl<'self> CheckLoanCtxt<'self> {
220220

221221
// Restrictions that would cause the new loan to be illegal:
222222
let illegal_if = match loan2.mutbl {
223-
m_mutbl => RESTR_ALIAS | RESTR_FREEZE | RESTR_CLAIM,
224-
m_imm => RESTR_ALIAS | RESTR_FREEZE,
225-
m_const => RESTR_ALIAS,
223+
MutableMutability => RESTR_ALIAS | RESTR_FREEZE | RESTR_CLAIM,
224+
ImmutableMutability => RESTR_ALIAS | RESTR_FREEZE,
225+
ConstMutability => RESTR_ALIAS,
226226
};
227227
debug!("illegal_if=%?", illegal_if);
228228

@@ -231,7 +231,7 @@ impl<'self> CheckLoanCtxt<'self> {
231231
if restr.loan_path != loan2.loan_path { loop; }
232232

233233
match (new_loan.mutbl, old_loan.mutbl) {
234-
(m_mutbl, m_mutbl) => {
234+
(MutableMutability, MutableMutability) => {
235235
self.bccx.span_err(
236236
new_loan.span,
237237
fmt!("cannot borrow `%s` as mutable \
@@ -582,16 +582,18 @@ impl<'self> CheckLoanCtxt<'self> {
582582
// Otherwise stop iterating
583583
LpExtend(_, mc::McDeclared, _) |
584584
LpExtend(_, mc::McImmutable, _) |
585-
LpExtend(_, mc::McReadOnly, _) |
586585
LpVar(_) => {
587586
return true;
588587
}
589588
}
590589

591590
// Check for a non-const loan of `loan_path`
592591
let cont = do this.each_in_scope_loan(expr.id) |loan| {
593-
if loan.loan_path == loan_path && loan.mutbl != m_const {
594-
this.report_illegal_mutation(expr, full_loan_path, loan);
592+
if loan.loan_path == loan_path &&
593+
loan.mutbl != ConstMutability {
594+
this.report_illegal_mutation(expr,
595+
full_loan_path,
596+
loan);
595597
false
596598
} else {
597599
true

src/librustc/middle/borrowck/gather_loans/lifetime.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use middle::borrowck::*;
1616
use mc = middle::mem_categorization;
1717
use middle::ty;
18-
use syntax::ast::{m_const, m_imm, m_mutbl};
18+
use syntax::ast::{m_imm, m_mutbl};
1919
use syntax::ast;
2020
use syntax::codemap::span;
2121
use util::ppaux::{note_and_explain_region};
@@ -26,7 +26,7 @@ pub fn guarantee_lifetime(bccx: @BorrowckCtxt,
2626
span: span,
2727
cmt: mc::cmt,
2828
loan_region: ty::Region,
29-
loan_mutbl: ast::mutability) {
29+
loan_mutbl: LoanMutability) {
3030
debug!("guarantee_lifetime(cmt=%s, loan_region=%s)",
3131
cmt.repr(bccx.tcx), loan_region.repr(bccx.tcx));
3232
let ctxt = GuaranteeLifetimeContext {bccx: bccx,
@@ -54,7 +54,7 @@ struct GuaranteeLifetimeContext {
5454

5555
span: span,
5656
loan_region: ty::Region,
57-
loan_mutbl: ast::mutability,
57+
loan_mutbl: LoanMutability,
5858
cmt_original: mc::cmt
5959
}
6060

@@ -235,11 +235,11 @@ impl GuaranteeLifetimeContext {
235235
// we need to dynamically mark it to prevent incompatible
236236
// borrows from happening later.
237237
let opt_dyna = match ptr_mutbl {
238-
m_imm | m_const => None,
238+
m_imm => None,
239239
m_mutbl => {
240240
match self.loan_mutbl {
241-
m_mutbl => Some(DynaMut),
242-
m_imm | m_const => Some(DynaImm)
241+
MutableMutability => Some(DynaMut),
242+
ImmutableMutability | ConstMutability => Some(DynaImm)
243243
}
244244
}
245245
};

src/librustc/middle/borrowck/gather_loans/mod.rs

+48-34
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ use middle::ty;
2626
use util::common::indenter;
2727
use util::ppaux::{Repr};
2828

29-
use syntax::ast::{m_const, m_imm, m_mutbl};
3029
use syntax::ast;
3130
use syntax::ast_util::id_range;
3231
use syntax::codemap::span;
@@ -237,7 +236,11 @@ fn gather_loans_in_expr(v: &mut GatherLoanVisitor,
237236
// make sure that the thing we are pointing out stays valid
238237
// for the lifetime `scope_r` of the resulting ptr:
239238
let scope_r = ty_region(tcx, ex.span, ty::expr_ty(tcx, ex));
240-
this.guarantee_valid(ex.id, ex.span, base_cmt, mutbl, scope_r);
239+
this.guarantee_valid(ex.id,
240+
ex.span,
241+
base_cmt,
242+
LoanMutability::from_ast_mutability(mutbl),
243+
scope_r);
241244
visit::walk_expr(v, ex, this);
242245
}
243246

@@ -278,7 +281,11 @@ fn gather_loans_in_expr(v: &mut GatherLoanVisitor,
278281
// adjustments).
279282
let scope_r = ty::re_scope(ex.id);
280283
let arg_cmt = this.bccx.cat_expr(arg);
281-
this.guarantee_valid(arg.id, arg.span, arg_cmt, m_imm, scope_r);
284+
this.guarantee_valid(arg.id,
285+
arg.span,
286+
arg_cmt,
287+
ImmutableMutability,
288+
scope_r);
282289
visit::walk_expr(v, ex, this);
283290
}
284291

@@ -357,26 +364,30 @@ impl GatherLoanCtxt {
357364

358365
match *autoref {
359366
ty::AutoPtr(r, m) => {
367+
let loan_mutability =
368+
LoanMutability::from_ast_mutability(m);
360369
self.guarantee_valid(expr.id,
361370
expr.span,
362371
cmt,
363-
m,
372+
loan_mutability,
364373
r)
365374
}
366375
ty::AutoBorrowVec(r, m) | ty::AutoBorrowVecRef(r, m) => {
367376
let cmt_index = mcx.cat_index(expr, cmt, autoderefs+1);
377+
let loan_mutability =
378+
LoanMutability::from_ast_mutability(m);
368379
self.guarantee_valid(expr.id,
369380
expr.span,
370381
cmt_index,
371-
m,
382+
loan_mutability,
372383
r)
373384
}
374385
ty::AutoBorrowFn(r) => {
375386
let cmt_deref = mcx.cat_deref_fn_or_obj(expr, cmt, 0);
376387
self.guarantee_valid(expr.id,
377388
expr.span,
378389
cmt_deref,
379-
m_imm,
390+
ImmutableMutability,
380391
r)
381392
}
382393
ty::AutoBorrowObj(r, m) => {
@@ -402,7 +413,7 @@ impl GatherLoanCtxt {
402413
borrow_id: ast::NodeId,
403414
borrow_span: span,
404415
cmt: mc::cmt,
405-
req_mutbl: ast::mutability,
416+
req_mutbl: LoanMutability,
406417
loan_region: ty::Region) {
407418
debug!("guarantee_valid(borrow_id=%?, cmt=%s, \
408419
req_mutbl=%?, loan_region=%?)",
@@ -473,7 +484,7 @@ impl GatherLoanCtxt {
473484
let kill_scope = self.compute_kill_scope(loan_scope, loan_path);
474485
debug!("kill_scope = %?", kill_scope);
475486

476-
if req_mutbl == m_mutbl {
487+
if req_mutbl == MutableMutability {
477488
self.mark_loan_path_as_mutated(loan_path);
478489
}
479490

@@ -516,7 +527,7 @@ impl GatherLoanCtxt {
516527
// index: all_loans.len(),
517528
// loan_path: loan_path,
518529
// cmt: cmt,
519-
// mutbl: m_const,
530+
// mutbl: ConstMutability,
520531
// gen_scope: borrow_id,
521532
// kill_scope: kill_scope,
522533
// span: borrow_span,
@@ -527,29 +538,20 @@ impl GatherLoanCtxt {
527538
fn check_mutability(bccx: @BorrowckCtxt,
528539
borrow_span: span,
529540
cmt: mc::cmt,
530-
req_mutbl: ast::mutability) {
541+
req_mutbl: LoanMutability) {
531542
//! Implements the M-* rules in doc.rs.
532543
533544
match req_mutbl {
534-
m_const => {
545+
ConstMutability => {
535546
// Data of any mutability can be lent as const.
536547
}
537548

538-
m_imm => {
539-
match cmt.mutbl {
540-
mc::McImmutable | mc::McDeclared | mc::McInherited => {
541-
// both imm and mut data can be lent as imm;
542-
// for mutable data, this is a freeze
543-
}
544-
mc::McReadOnly => {
545-
bccx.report(BckError {span: borrow_span,
546-
cmt: cmt,
547-
code: err_mutbl(req_mutbl)});
548-
}
549-
}
549+
ImmutableMutability => {
550+
// both imm and mut data can be lent as imm;
551+
// for mutable data, this is a freeze
550552
}
551553

552-
m_mutbl => {
554+
MutableMutability => {
553555
// Only mutable data can be lent as mutable.
554556
if !cmt.mutbl.is_mutable() {
555557
bccx.report(BckError {span: borrow_span,
@@ -561,12 +563,14 @@ impl GatherLoanCtxt {
561563
}
562564
}
563565

564-
pub fn restriction_set(&self, req_mutbl: ast::mutability)
566+
pub fn restriction_set(&self, req_mutbl: LoanMutability)
565567
-> RestrictionSet {
566568
match req_mutbl {
567-
m_const => RESTR_EMPTY,
568-
m_imm => RESTR_EMPTY | RESTR_MUTATE | RESTR_CLAIM,
569-
m_mutbl => RESTR_EMPTY | RESTR_MUTATE | RESTR_CLAIM | RESTR_FREEZE
569+
ConstMutability => RESTR_EMPTY,
570+
ImmutableMutability => RESTR_EMPTY | RESTR_MUTATE | RESTR_CLAIM,
571+
MutableMutability => {
572+
RESTR_EMPTY | RESTR_MUTATE | RESTR_CLAIM | RESTR_FREEZE
573+
}
570574
}
571575
}
572576

@@ -582,8 +586,8 @@ impl GatherLoanCtxt {
582586
self.mark_loan_path_as_mutated(base);
583587
}
584588
LpExtend(_, mc::McDeclared, _) |
585-
LpExtend(_, mc::McImmutable, _) |
586-
LpExtend(_, mc::McReadOnly, _) => {
589+
LpExtend(_, mc::McImmutable, _) => {
590+
// Nothing to do.
587591
}
588592
}
589593
}
@@ -701,8 +705,13 @@ impl GatherLoanCtxt {
701705
}
702706
}
703707
};
704-
self.guarantee_valid(pat.id, pat.span,
705-
cmt_discr, mutbl, scope_r);
708+
let loan_mutability =
709+
LoanMutability::from_ast_mutability(mutbl);
710+
self.guarantee_valid(pat.id,
711+
pat.span,
712+
cmt_discr,
713+
loan_mutability,
714+
scope_r);
706715
}
707716
ast::bind_infer => {
708717
// No borrows here, but there may be moves
@@ -725,6 +734,8 @@ impl GatherLoanCtxt {
725734
self.vec_slice_info(slice_pat, slice_ty);
726735
let mcx = self.bccx.mc_ctxt();
727736
let cmt_index = mcx.cat_index(slice_pat, cmt, 0);
737+
let slice_loan_mutability =
738+
LoanMutability::from_ast_mutability(slice_mutbl);
728739

729740
// Note: We declare here that the borrow occurs upon
730741
// entering the `[...]` pattern. This implies that
@@ -743,8 +754,11 @@ impl GatherLoanCtxt {
743754
// trans do the right thing, and it would only work
744755
// for `~` vectors. It seems simpler to just require
745756
// that people call `vec.pop()` or `vec.unshift()`.
746-
self.guarantee_valid(pat.id, pat.span,
747-
cmt_index, slice_mutbl, slice_r);
757+
self.guarantee_valid(pat.id,
758+
pat.span,
759+
cmt_index,
760+
slice_loan_mutability,
761+
slice_r);
748762
}
749763

750764
_ => {}

src/librustc/middle/borrowck/gather_loans/restrictions.rs

+1-8
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use std::vec;
1515
use middle::borrowck::*;
1616
use mc = middle::mem_categorization;
1717
use middle::ty;
18-
use syntax::ast::{m_const, m_imm, m_mutbl};
18+
use syntax::ast::{m_imm, m_mutbl};
1919
use syntax::codemap::span;
2020

2121
pub enum RestrictionResult {
@@ -121,13 +121,6 @@ impl RestrictionsContext {
121121
Safe
122122
}
123123

124-
mc::cat_deref(_, _, mc::region_ptr(m_const, _)) |
125-
mc::cat_deref(_, _, mc::gc_ptr(m_const)) => {
126-
// R-Deref-Freeze-Borrowed
127-
self.check_no_mutability_control(cmt, restrictions);
128-
Safe
129-
}
130-
131124
mc::cat_deref(cmt_base, _, pk @ mc::gc_ptr(m_mutbl)) => {
132125
// R-Deref-Managed-Borrowed
133126
//

0 commit comments

Comments
 (0)