Skip to content

Commit 3324257

Browse files
committed
rustc: Start accepting *const T
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
1 parent 0973eb4 commit 3324257

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
@@ -3468,10 +3468,11 @@ There are four varieties of pointer in Rust:
34683468

34693469
* Raw pointers (`*`)
34703470
: Raw pointers are pointers without safety or liveness guarantees.
3471-
Raw pointers are written `*content`,
3472-
for example `*int` means a raw pointer to an integer.
3473-
Copying or dropping a raw pointer has no effect on the lifecycle of any other value.
3474-
Dereferencing a raw pointer or converting it to any other pointer type is an [`unsafe` operation](#unsafe-functions).
3471+
Raw pointers are written as `*const T` or `*mut T`,
3472+
for example `*const int` means a raw pointer to an integer.
3473+
Copying or dropping a raw pointer has no effect on the lifecycle of any
3474+
other value. Dereferencing a raw pointer or converting it to any other
3475+
pointer type is an [`unsafe` operation](#unsafe-functions).
34753476
Raw pointers are generally discouraged in Rust code;
34763477
they exist to support interoperability with foreign code,
34773478
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
@@ -1352,7 +1352,7 @@ impl<'a> Parser<'a> {
13521352
} else if self.token == token::BINOP(token::STAR) {
13531353
// STAR POINTER (bare pointer?)
13541354
self.bump();
1355-
TyPtr(self.parse_mt())
1355+
TyPtr(self.parse_ptr())
13561356
} else if self.token == token::LBRACKET {
13571357
// VECTOR
13581358
self.expect(&token::LBRACKET);
@@ -1429,6 +1429,19 @@ impl<'a> Parser<'a> {
14291429
return TyRptr(opt_lifetime, mt);
14301430
}
14311431

1432+
pub fn parse_ptr(&mut self) -> MutTy {
1433+
let mutbl = if self.eat_keyword(keywords::Mut) {
1434+
MutMutable
1435+
} else if self.eat_keyword(keywords::Const) {
1436+
MutImmutable
1437+
} else {
1438+
// NOTE: after a stage0 snap this should turn into a span_err.
1439+
MutImmutable
1440+
};
1441+
let t = self.parse_ty(true);
1442+
MutTy { ty: t, mutbl: mutbl }
1443+
}
1444+
14321445
pub fn is_named_argument(&mut self) -> bool {
14331446
let offset = match self.token {
14341447
token::BINOP(token::AND) => 1,

src/libsyntax/parse/token.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -486,11 +486,11 @@ declare_special_idents_and_keywords! {
486486
(40, Continue, "continue");
487487
(41, Proc, "proc");
488488
(42, Box, "box");
489+
(43, Const, "const");
489490

490491
'reserved:
491-
(43, Alignof, "alignof");
492-
(44, Be, "be");
493-
(45, Const, "const");
492+
(44, Alignof, "alignof");
493+
(45, Be, "be");
494494
(46, Offsetof, "offsetof");
495495
(47, Priv, "priv");
496496
(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)