Skip to content

Commit 4c1ee75

Browse files
committed
librustc: Remove &const and *const from the language.
They are still present as part of the borrow check.
1 parent d8b299d commit 4c1ee75

Some content is hidden

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

51 files changed

+315
-472
lines changed

src/libextra/flate.rs

Lines changed: 2 additions & 2 deletions
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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -792,12 +792,9 @@ pub fn get_enum_variants(intr: @ident_interner, cdata: cmd, id: ast::NodeId,
792792
fn get_explicit_self(item: ebml::Doc) -> ast::explicit_self_ {
793793
fn get_mutability(ch: u8) -> ast::mutability {
794794
match ch as char {
795-
'i' => { ast::m_imm }
796-
'm' => { ast::m_mutbl }
797-
'c' => { ast::m_const }
798-
_ => {
799-
fail!("unknown mutability character: `%c`", ch as char)
800-
}
795+
'i' => ast::m_imm,
796+
'm' => ast::m_mutbl,
797+
_ => fail!("unknown mutability character: `%c`", ch as char),
801798
}
802799
}
803800

src/librustc/metadata/encoder.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -643,15 +643,8 @@ fn encode_explicit_self(ebml_w: &mut writer::Encoder, explicit_self: ast::explic
643643
fn encode_mutability(ebml_w: &writer::Encoder,
644644
m: ast::mutability) {
645645
match m {
646-
m_imm => {
647-
ebml_w.writer.write(&[ 'i' as u8 ]);
648-
}
649-
m_mutbl => {
650-
ebml_w.writer.write(&[ 'm' as u8 ]);
651-
}
652-
m_const => {
653-
ebml_w.writer.write(&[ 'c' as u8 ]);
654-
}
646+
m_imm => ebml_w.writer.write(&[ 'i' as u8 ]),
647+
m_mutbl => ebml_w.writer.write(&[ 'm' as u8 ]),
655648
}
656649
}
657650
}

src/librustc/metadata/tydecode.rs

Lines changed: 0 additions & 1 deletion
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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ fn enc_mutability(w: @io::Writer, mt: ast::mutability) {
100100
match mt {
101101
m_imm => (),
102102
m_mutbl => w.write_char('m'),
103-
m_const => w.write_char('?')
104103
}
105104
}
106105

src/librustc/middle/borrowck/check_loans.rs

Lines changed: 10 additions & 8 deletions
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;
@@ -205,9 +205,9 @@ impl<'self> CheckLoanCtxt<'self> {
205205

206206
// Restrictions that would cause the new loan to be illegal:
207207
let illegal_if = match loan2.mutbl {
208-
m_mutbl => RESTR_ALIAS | RESTR_FREEZE | RESTR_CLAIM,
209-
m_imm => RESTR_ALIAS | RESTR_FREEZE,
210-
m_const => RESTR_ALIAS,
208+
MutableMutability => RESTR_ALIAS | RESTR_FREEZE | RESTR_CLAIM,
209+
ImmutableMutability => RESTR_ALIAS | RESTR_FREEZE,
210+
ConstMutability => RESTR_ALIAS,
211211
};
212212
debug!("illegal_if=%?", illegal_if);
213213

@@ -216,7 +216,7 @@ impl<'self> CheckLoanCtxt<'self> {
216216
if restr.loan_path != loan2.loan_path { loop; }
217217

218218
match (new_loan.mutbl, old_loan.mutbl) {
219-
(m_mutbl, m_mutbl) => {
219+
(MutableMutability, MutableMutability) => {
220220
self.bccx.span_err(
221221
new_loan.span,
222222
fmt!("cannot borrow `%s` as mutable \
@@ -522,16 +522,18 @@ impl<'self> CheckLoanCtxt<'self> {
522522
// Otherwise stop iterating
523523
LpExtend(_, mc::McDeclared, _) |
524524
LpExtend(_, mc::McImmutable, _) |
525-
LpExtend(_, mc::McReadOnly, _) |
526525
LpVar(_) => {
527526
return true;
528527
}
529528
}
530529

531530
// Check for a non-const loan of `loan_path`
532531
let cont = do this.each_in_scope_loan(expr.id) |loan| {
533-
if loan.loan_path == loan_path && loan.mutbl != m_const {
534-
this.report_illegal_mutation(expr, full_loan_path, loan);
532+
if loan.loan_path == loan_path &&
533+
loan.mutbl != ConstMutability {
534+
this.report_illegal_mutation(expr,
535+
full_loan_path,
536+
loan);
535537
false
536538
} else {
537539
true

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

Lines changed: 6 additions & 6 deletions
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

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

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

Lines changed: 48 additions & 34 deletions
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;
@@ -217,7 +216,11 @@ fn gather_loans_in_expr(ex: @ast::expr,
217216
// make sure that the thing we are pointing out stays valid
218217
// for the lifetime `scope_r` of the resulting ptr:
219218
let scope_r = ty_region(tcx, ex.span, ty::expr_ty(tcx, ex));
220-
this.guarantee_valid(ex.id, ex.span, base_cmt, mutbl, scope_r);
219+
this.guarantee_valid(ex.id,
220+
ex.span,
221+
base_cmt,
222+
LoanMutability::from_ast_mutability(mutbl),
223+
scope_r);
221224
oldvisit::visit_expr(ex, (this, vt));
222225
}
223226

@@ -258,7 +261,11 @@ fn gather_loans_in_expr(ex: @ast::expr,
258261
// adjustments).
259262
let scope_r = ty::re_scope(ex.id);
260263
let arg_cmt = this.bccx.cat_expr(arg);
261-
this.guarantee_valid(arg.id, arg.span, arg_cmt, m_imm, scope_r);
264+
this.guarantee_valid(arg.id,
265+
arg.span,
266+
arg_cmt,
267+
ImmutableMutability,
268+
scope_r);
262269
oldvisit::visit_expr(ex, (this, vt));
263270
}
264271

@@ -337,26 +344,30 @@ impl GatherLoanCtxt {
337344

338345
match *autoref {
339346
ty::AutoPtr(r, m) => {
347+
let loan_mutability =
348+
LoanMutability::from_ast_mutability(m);
340349
self.guarantee_valid(expr.id,
341350
expr.span,
342351
cmt,
343-
m,
352+
loan_mutability,
344353
r)
345354
}
346355
ty::AutoBorrowVec(r, m) | ty::AutoBorrowVecRef(r, m) => {
347356
let cmt_index = mcx.cat_index(expr, cmt, autoderefs+1);
357+
let loan_mutability =
358+
LoanMutability::from_ast_mutability(m);
348359
self.guarantee_valid(expr.id,
349360
expr.span,
350361
cmt_index,
351-
m,
362+
loan_mutability,
352363
r)
353364
}
354365
ty::AutoBorrowFn(r) => {
355366
let cmt_deref = mcx.cat_deref_fn(expr, cmt, 0);
356367
self.guarantee_valid(expr.id,
357368
expr.span,
358369
cmt_deref,
359-
m_imm,
370+
ImmutableMutability,
360371
r)
361372
}
362373
ty::AutoUnsafe(_) => {}
@@ -374,7 +385,7 @@ impl GatherLoanCtxt {
374385
borrow_id: ast::NodeId,
375386
borrow_span: span,
376387
cmt: mc::cmt,
377-
req_mutbl: ast::mutability,
388+
req_mutbl: LoanMutability,
378389
loan_region: ty::Region) {
379390
debug!("guarantee_valid(borrow_id=%?, cmt=%s, \
380391
req_mutbl=%?, loan_region=%?)",
@@ -445,7 +456,7 @@ impl GatherLoanCtxt {
445456
let kill_scope = self.compute_kill_scope(loan_scope, loan_path);
446457
debug!("kill_scope = %?", kill_scope);
447458

448-
if req_mutbl == m_mutbl {
459+
if req_mutbl == MutableMutability {
449460
self.mark_loan_path_as_mutated(loan_path);
450461
}
451462

@@ -488,7 +499,7 @@ impl GatherLoanCtxt {
488499
// index: all_loans.len(),
489500
// loan_path: loan_path,
490501
// cmt: cmt,
491-
// mutbl: m_const,
502+
// mutbl: ConstMutability,
492503
// gen_scope: borrow_id,
493504
// kill_scope: kill_scope,
494505
// span: borrow_span,
@@ -499,29 +510,20 @@ impl GatherLoanCtxt {
499510
fn check_mutability(bccx: @BorrowckCtxt,
500511
borrow_span: span,
501512
cmt: mc::cmt,
502-
req_mutbl: ast::mutability) {
513+
req_mutbl: LoanMutability) {
503514
//! Implements the M-* rules in doc.rs.
504515
505516
match req_mutbl {
506-
m_const => {
517+
ConstMutability => {
507518
// Data of any mutability can be lent as const.
508519
}
509520

510-
m_imm => {
511-
match cmt.mutbl {
512-
mc::McImmutable | mc::McDeclared | mc::McInherited => {
513-
// both imm and mut data can be lent as imm;
514-
// for mutable data, this is a freeze
515-
}
516-
mc::McReadOnly => {
517-
bccx.report(BckError {span: borrow_span,
518-
cmt: cmt,
519-
code: err_mutbl(req_mutbl)});
520-
}
521-
}
521+
ImmutableMutability => {
522+
// both imm and mut data can be lent as imm;
523+
// for mutable data, this is a freeze
522524
}
523525

524-
m_mutbl => {
526+
MutableMutability => {
525527
// Only mutable data can be lent as mutable.
526528
if !cmt.mutbl.is_mutable() {
527529
bccx.report(BckError {span: borrow_span,
@@ -533,12 +535,14 @@ impl GatherLoanCtxt {
533535
}
534536
}
535537

536-
pub fn restriction_set(&self, req_mutbl: ast::mutability)
538+
pub fn restriction_set(&self, req_mutbl: LoanMutability)
537539
-> RestrictionSet {
538540
match req_mutbl {
539-
m_const => RESTR_EMPTY,
540-
m_imm => RESTR_EMPTY | RESTR_MUTATE | RESTR_CLAIM,
541-
m_mutbl => RESTR_EMPTY | RESTR_MUTATE | RESTR_CLAIM | RESTR_FREEZE
541+
ConstMutability => RESTR_EMPTY,
542+
ImmutableMutability => RESTR_EMPTY | RESTR_MUTATE | RESTR_CLAIM,
543+
MutableMutability => {
544+
RESTR_EMPTY | RESTR_MUTATE | RESTR_CLAIM | RESTR_FREEZE
545+
}
542546
}
543547
}
544548

@@ -554,8 +558,8 @@ impl GatherLoanCtxt {
554558
self.mark_loan_path_as_mutated(base);
555559
}
556560
LpExtend(_, mc::McDeclared, _) |
557-
LpExtend(_, mc::McImmutable, _) |
558-
LpExtend(_, mc::McReadOnly, _) => {
561+
LpExtend(_, mc::McImmutable, _) => {
562+
// Nothing to do.
559563
}
560564
}
561565
}
@@ -673,8 +677,13 @@ impl GatherLoanCtxt {
673677
}
674678
}
675679
};
676-
self.guarantee_valid(pat.id, pat.span,
677-
cmt_discr, mutbl, scope_r);
680+
let loan_mutability =
681+
LoanMutability::from_ast_mutability(mutbl);
682+
self.guarantee_valid(pat.id,
683+
pat.span,
684+
cmt_discr,
685+
loan_mutability,
686+
scope_r);
678687
}
679688
ast::bind_infer => {
680689
// No borrows here, but there may be moves
@@ -697,6 +706,8 @@ impl GatherLoanCtxt {
697706
self.vec_slice_info(slice_pat, slice_ty);
698707
let mcx = self.bccx.mc_ctxt();
699708
let cmt_index = mcx.cat_index(slice_pat, cmt, 0);
709+
let slice_loan_mutability =
710+
LoanMutability::from_ast_mutability(slice_mutbl);
700711

701712
// Note: We declare here that the borrow occurs upon
702713
// entering the `[...]` pattern. This implies that
@@ -715,8 +726,11 @@ impl GatherLoanCtxt {
715726
// trans do the right thing, and it would only work
716727
// for `~` vectors. It seems simpler to just require
717728
// that people call `vec.pop()` or `vec.unshift()`.
718-
self.guarantee_valid(pat.id, pat.span,
719-
cmt_index, slice_mutbl, slice_r);
729+
self.guarantee_valid(pat.id,
730+
pat.span,
731+
cmt_index,
732+
slice_loan_mutability,
733+
slice_r);
720734
}
721735

722736
_ => {}

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

Lines changed: 1 addition & 8 deletions
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 {
@@ -122,13 +122,6 @@ impl RestrictionsContext {
122122
Safe
123123
}
124124

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

0 commit comments

Comments
 (0)