1
Fork 0

Auto merge of #29274 - thepowersgang:issues-29107-const-unsafe-fn-order, r=nikomatsakis

This PR switches the implemented ordering from `unsafe const fn` (as was in the original RFC) to `const unsafe fn` (which is what the lang team decided on)
This commit is contained in:
bors 2015-10-26 21:23:32 +00:00
commit 04475b92f9
6 changed files with 21 additions and 16 deletions

View file

@ -55,7 +55,7 @@ macro_rules! nonzero_new {
/// Creates an instance of NonZero with the provided value. /// Creates an instance of NonZero with the provided value.
/// You must indeed ensure that the value is actually "non-zero". /// You must indeed ensure that the value is actually "non-zero".
#[inline(always)] #[inline(always)]
pub unsafe const fn new(inner: T) -> NonZero<T> { pub const unsafe fn new(inner: T) -> NonZero<T> {
NonZero(inner) NonZero(inner)
} }
) )

View file

@ -511,7 +511,7 @@ macro_rules! unique_new {
macro_rules! unique_new { macro_rules! unique_new {
() => ( () => (
/// Creates a new `Unique`. /// Creates a new `Unique`.
pub unsafe const fn new(ptr: *mut T) -> Unique<T> { pub const unsafe fn new(ptr: *mut T) -> Unique<T> {
Unique { pointer: NonZero::new(ptr), _marker: PhantomData } Unique { pointer: NonZero::new(ptr), _marker: PhantomData }
} }
) )

View file

@ -4380,7 +4380,8 @@ impl<'a> Parser<'a> {
/// true if we are looking at `const ID`, false for things like `const fn` etc /// true if we are looking at `const ID`, false for things like `const fn` etc
pub fn is_const_item(&mut self) -> bool { pub fn is_const_item(&mut self) -> bool {
self.token.is_keyword(keywords::Const) && self.token.is_keyword(keywords::Const) &&
!self.look_ahead(1, |t| t.is_keyword(keywords::Fn)) !self.look_ahead(1, |t| t.is_keyword(keywords::Fn)) &&
!self.look_ahead(1, |t| t.is_keyword(keywords::Unsafe))
} }
/// parses all the "front matter" for a `fn` declaration, up to /// parses all the "front matter" for a `fn` declaration, up to
@ -4388,11 +4389,12 @@ impl<'a> Parser<'a> {
/// ///
/// - `const fn` /// - `const fn`
/// - `unsafe fn` /// - `unsafe fn`
/// - `const unsafe fn`
/// - `extern fn` /// - `extern fn`
/// - etc /// - etc
pub fn parse_fn_front_matter(&mut self) -> PResult<(ast::Constness, ast::Unsafety, abi::Abi)> { pub fn parse_fn_front_matter(&mut self) -> PResult<(ast::Constness, ast::Unsafety, abi::Abi)> {
let unsafety = try!(self.parse_unsafety());
let is_const_fn = try!(self.eat_keyword(keywords::Const)); let is_const_fn = try!(self.eat_keyword(keywords::Const));
let unsafety = try!(self.parse_unsafety());
let (constness, unsafety, abi) = if is_const_fn { let (constness, unsafety, abi) = if is_const_fn {
(Constness::Const, unsafety, abi::Rust) (Constness::Const, unsafety, abi::Rust)
} else { } else {
@ -5300,11 +5302,18 @@ impl<'a> Parser<'a> {
return Ok(Some(item)); return Ok(Some(item));
} }
if try!(self.eat_keyword(keywords::Const) ){ if try!(self.eat_keyword(keywords::Const) ){
if self.check_keyword(keywords::Fn) { if self.check_keyword(keywords::Fn)
|| (self.check_keyword(keywords::Unsafe)
&& self.look_ahead(1, |t| t.is_keyword(keywords::Fn))) {
// CONST FUNCTION ITEM // CONST FUNCTION ITEM
let unsafety = if try!(self.eat_keyword(keywords::Unsafe) ){
Unsafety::Unsafe
} else {
Unsafety::Normal
};
try!(self.bump()); try!(self.bump());
let (ident, item_, extra_attrs) = let (ident, item_, extra_attrs) =
try!(self.parse_item_fn(Unsafety::Normal, Constness::Const, abi::Rust)); try!(self.parse_item_fn(unsafety, Constness::Const, abi::Rust));
let last_span = self.last_span; let last_span = self.last_span;
let item = self.mk_item(lo, let item = self.mk_item(lo,
last_span.hi, last_span.hi,
@ -5387,14 +5396,9 @@ impl<'a> Parser<'a> {
} else { } else {
abi::Rust abi::Rust
}; };
let constness = if abi == abi::Rust && try!(self.eat_keyword(keywords::Const) ){
Constness::Const
} else {
Constness::NotConst
};
try!(self.expect_keyword(keywords::Fn)); try!(self.expect_keyword(keywords::Fn));
let (ident, item_, extra_attrs) = let (ident, item_, extra_attrs) =
try!(self.parse_item_fn(Unsafety::Unsafe, constness, abi)); try!(self.parse_item_fn(Unsafety::Unsafe, Constness::NotConst, abi));
let last_span = self.last_span; let last_span = self.last_span;
let item = self.mk_item(lo, let item = self.mk_item(lo,
last_span.hi, last_span.hi,

View file

@ -3058,13 +3058,14 @@ impl<'a> State<'a> {
abi: abi::Abi, abi: abi::Abi,
vis: ast::Visibility) -> io::Result<()> { vis: ast::Visibility) -> io::Result<()> {
try!(word(&mut self.s, &visibility_qualified(vis, ""))); try!(word(&mut self.s, &visibility_qualified(vis, "")));
try!(self.print_unsafety(unsafety));
match constness { match constness {
ast::Constness::NotConst => {} ast::Constness::NotConst => {}
ast::Constness::Const => try!(self.word_nbsp("const")) ast::Constness::Const => try!(self.word_nbsp("const"))
} }
try!(self.print_unsafety(unsafety));
if abi != abi::Rust { if abi != abi::Rust {
try!(self.word_nbsp("extern")); try!(self.word_nbsp("extern"));
try!(self.word_nbsp(&abi.to_string())); try!(self.word_nbsp(&abi.to_string()));

View file

@ -12,7 +12,7 @@
#![feature(const_fn)] #![feature(const_fn)]
unsafe const fn dummy(v: u32) -> u32 { const unsafe fn dummy(v: u32) -> u32 {
!v !v
} }

View file

@ -12,13 +12,13 @@
#![feature(const_fn)] #![feature(const_fn)]
unsafe const fn dummy(v: u32) -> u32 { const unsafe fn dummy(v: u32) -> u32 {
!v !v
} }
struct Type; struct Type;
impl Type { impl Type {
unsafe const fn new() -> Type { const unsafe fn new() -> Type {
Type Type
} }
} }