Skip to content

Commit 7689213

Browse files
committed
auto merge of #14952 : alexcrichton/rust/const-unsafe-pointers, r=brson
This does not yet change the compiler and libraries from `*T` to `*const T` as it will require a snapshot to do so. cc #7362 --- Note that the corresponding RFC, rust-lang/rfcs#68, has not yet been accepted. It was [discussed at the last meeting](https://github.com/rust-lang/rust/wiki/Meeting-weekly-2014-06-10#rfc-pr-68-unsafe-pointers-rename-t-to-const-t) and decided to be accepted, however. I figured I'd get started on the preliminary work for the RFC that will be required regardless.
2 parents 10b12bc + 3324257 commit 7689213

File tree

5 files changed

+38
-11
lines changed

5 files changed

+38
-11
lines changed

src/doc/rust.md

+6-5
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ block_comment_body : [block_comment | character] * ;
160160
line_comment : "//" non_eol * ;
161161
~~~~
162162

163-
Comments in Rust code follow the general C++ style of line and block-comment forms.
163+
Comments in Rust code follow the general C++ style of line and block-comment forms.
164164
Nested block comments are supported.
165165

166166
Line comments beginning with exactly _three_ slashes (`///`), and block
@@ -3563,10 +3563,11 @@ There are four varieties of pointer in Rust:
35633563

35643564
* Raw pointers (`*`)
35653565
: Raw pointers are pointers without safety or liveness guarantees.
3566-
Raw pointers are written `*content`,
3567-
for example `*int` means a raw pointer to an integer.
3568-
Copying or dropping a raw pointer has no effect on the lifecycle of any other value.
3569-
Dereferencing a raw pointer or converting it to any other pointer type is an [`unsafe` operation](#unsafe-functions).
3566+
Raw pointers are written as `*const T` or `*mut T`,
3567+
for example `*const int` means a raw pointer to an integer.
3568+
Copying or dropping a raw pointer has no effect on the lifecycle of any
3569+
other value. Dereferencing a raw pointer or converting it to any other
3570+
pointer type is an [`unsafe` operation](#unsafe-functions).
35703571
Raw pointers are generally discouraged in Rust code;
35713572
they exist to support interoperability with foreign code,
35723573
and writing performance-critical or low-level functions.

src/etc/vim/syntax/rust.vim

+1-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ syn keyword rustKeyword unsafe virtual while
3030
syn keyword rustKeyword use nextgroup=rustModPath skipwhite skipempty
3131
" FIXME: Scoped impl's name is also fallen in this category
3232
syn keyword rustKeyword mod trait struct enum type nextgroup=rustIdentifier skipwhite skipempty
33-
syn keyword rustStorage mut ref static
34-
syn keyword rustObsoleteStorage const
33+
syn keyword rustStorage mut ref static const
3534

3635
syn keyword rustInvalidBareKeyword crate
3736

src/libsyntax/parse/parser.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -1365,7 +1365,7 @@ impl<'a> Parser<'a> {
13651365
} else if self.token == token::BINOP(token::STAR) {
13661366
// STAR POINTER (bare pointer?)
13671367
self.bump();
1368-
TyPtr(self.parse_mt())
1368+
TyPtr(self.parse_ptr())
13691369
} else if self.token == token::LBRACKET {
13701370
// VECTOR
13711371
self.expect(&token::LBRACKET);
@@ -1442,6 +1442,19 @@ impl<'a> Parser<'a> {
14421442
return TyRptr(opt_lifetime, mt);
14431443
}
14441444

1445+
pub fn parse_ptr(&mut self) -> MutTy {
1446+
let mutbl = if self.eat_keyword(keywords::Mut) {
1447+
MutMutable
1448+
} else if self.eat_keyword(keywords::Const) {
1449+
MutImmutable
1450+
} else {
1451+
// NOTE: after a stage0 snap this should turn into a span_err.
1452+
MutImmutable
1453+
};
1454+
let t = self.parse_ty(true);
1455+
MutTy { ty: t, mutbl: mutbl }
1456+
}
1457+
14451458
pub fn is_named_argument(&mut self) -> bool {
14461459
let offset = match self.token {
14471460
token::BINOP(token::AND) => 1,

src/libsyntax/parse/token.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -512,11 +512,11 @@ declare_special_idents_and_keywords! {
512512
(40, Continue, "continue");
513513
(41, Proc, "proc");
514514
(42, Box, "box");
515+
(43, Const, "const");
515516

516517
'reserved:
517-
(43, Alignof, "alignof");
518-
(44, Be, "be");
519-
(45, Const, "const");
518+
(44, Alignof, "alignof");
519+
(45, Be, "be");
520520
(46, Offsetof, "offsetof");
521521
(47, Priv, "priv");
522522
(48, Pure, "pure");
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn main() {
12+
let _a: *const int = 3 as *const int;
13+
let _a: *mut int = 3 as *mut int;
14+
}

0 commit comments

Comments
 (0)