提交 33242578 编写于 作者: A Alex Crichton

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
上级 0973eb44
...@@ -3468,10 +3468,11 @@ There are four varieties of pointer in Rust: ...@@ -3468,10 +3468,11 @@ There are four varieties of pointer in Rust:
* Raw pointers (`*`) * Raw pointers (`*`)
: Raw pointers are pointers without safety or liveness guarantees. : Raw pointers are pointers without safety or liveness guarantees.
Raw pointers are written `*content`, Raw pointers are written as `*const T` or `*mut T`,
for example `*int` means a raw pointer to an integer. for example `*const int` means a raw pointer to an integer.
Copying or dropping a raw pointer has no effect on the lifecycle of any other value. Copying or dropping a raw pointer has no effect on the lifecycle of any
Dereferencing a raw pointer or converting it to any other pointer type is an [`unsafe` operation](#unsafe-functions). other value. Dereferencing a raw pointer or converting it to any other
pointer type is an [`unsafe` operation](#unsafe-functions).
Raw pointers are generally discouraged in Rust code; Raw pointers are generally discouraged in Rust code;
they exist to support interoperability with foreign code, they exist to support interoperability with foreign code,
and writing performance-critical or low-level functions. and writing performance-critical or low-level functions.
......
...@@ -30,8 +30,7 @@ syn keyword rustKeyword unsafe virtual while ...@@ -30,8 +30,7 @@ syn keyword rustKeyword unsafe virtual while
syn keyword rustKeyword use nextgroup=rustModPath skipwhite skipempty syn keyword rustKeyword use nextgroup=rustModPath skipwhite skipempty
" FIXME: Scoped impl's name is also fallen in this category " FIXME: Scoped impl's name is also fallen in this category
syn keyword rustKeyword mod trait struct enum type nextgroup=rustIdentifier skipwhite skipempty syn keyword rustKeyword mod trait struct enum type nextgroup=rustIdentifier skipwhite skipempty
syn keyword rustStorage mut ref static syn keyword rustStorage mut ref static const
syn keyword rustObsoleteStorage const
syn keyword rustInvalidBareKeyword crate syn keyword rustInvalidBareKeyword crate
......
...@@ -1352,7 +1352,7 @@ pub fn parse_ty(&mut self, plus_allowed: bool) -> P<Ty> { ...@@ -1352,7 +1352,7 @@ pub fn parse_ty(&mut self, plus_allowed: bool) -> P<Ty> {
} else if self.token == token::BINOP(token::STAR) { } else if self.token == token::BINOP(token::STAR) {
// STAR POINTER (bare pointer?) // STAR POINTER (bare pointer?)
self.bump(); self.bump();
TyPtr(self.parse_mt()) TyPtr(self.parse_ptr())
} else if self.token == token::LBRACKET { } else if self.token == token::LBRACKET {
// VECTOR // VECTOR
self.expect(&token::LBRACKET); self.expect(&token::LBRACKET);
...@@ -1429,6 +1429,19 @@ pub fn parse_borrowed_pointee(&mut self) -> Ty_ { ...@@ -1429,6 +1429,19 @@ pub fn parse_borrowed_pointee(&mut self) -> Ty_ {
return TyRptr(opt_lifetime, mt); return TyRptr(opt_lifetime, mt);
} }
pub fn parse_ptr(&mut self) -> MutTy {
let mutbl = if self.eat_keyword(keywords::Mut) {
MutMutable
} else if self.eat_keyword(keywords::Const) {
MutImmutable
} else {
// NOTE: after a stage0 snap this should turn into a span_err.
MutImmutable
};
let t = self.parse_ty(true);
MutTy { ty: t, mutbl: mutbl }
}
pub fn is_named_argument(&mut self) -> bool { pub fn is_named_argument(&mut self) -> bool {
let offset = match self.token { let offset = match self.token {
token::BINOP(token::AND) => 1, token::BINOP(token::AND) => 1,
......
...@@ -486,11 +486,11 @@ pub mod keywords { ...@@ -486,11 +486,11 @@ pub mod keywords {
(40, Continue, "continue"); (40, Continue, "continue");
(41, Proc, "proc"); (41, Proc, "proc");
(42, Box, "box"); (42, Box, "box");
(43, Const, "const");
'reserved: 'reserved:
(43, Alignof, "alignof"); (44, Alignof, "alignof");
(44, Be, "be"); (45, Be, "be");
(45, Const, "const");
(46, Offsetof, "offsetof"); (46, Offsetof, "offsetof");
(47, Priv, "priv"); (47, Priv, "priv");
(48, Pure, "pure"); (48, Pure, "pure");
......
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn main() {
let _a: *const int = 3 as *const int;
let _a: *mut int = 3 as *mut int;
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册