parser: support [unsafe] instead of [unsafe_fn] (#6066)

pull/6093/head
Nick Treleaven 2020-08-08 15:24:05 +01:00 committed by GitHub
parent 2a4ef2acbd
commit 6cc8815931
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 15 additions and 5 deletions

View File

@ -16,7 +16,7 @@ fn test_ptr_infix() {
struct S1 {}
[unsafe_fn]
[unsafe]
fn (s S1) f(){}
fn test_funcs() {

View File

@ -16,7 +16,7 @@ fn test_ptr_infix() {
struct S1 {}
[unsafe_fn]
[unsafe]
fn (s S1) f(){}
fn test_funcs() {

View File

@ -132,7 +132,7 @@ fn (mut p Parser) fn_decl() ast.FnDecl {
p.top_level_statement_start()
start_pos := p.tok.position()
is_deprecated := p.attrs.contains('deprecated')
mut is_unsafe := p.attrs.contains('unsafe_fn')
mut is_unsafe := p.attrs.contains('unsafe')
is_pub := p.tok.kind == .key_pub
if is_pub {
p.next()

View File

@ -725,6 +725,12 @@ fn (mut p Parser) attributes() {
}
fn (mut p Parser) parse_attr() table.Attr {
if p.tok.kind == .key_unsafe {
p.next()
return table.Attr{
name: 'unsafe'
}
}
mut is_ctdefine := false
if p.tok.kind == .key_if {
p.next()
@ -737,6 +743,10 @@ fn (mut p Parser) parse_attr() table.Attr {
p.next()
} else {
mut name = p.check_name()
if name == 'unsafe_fn' {
// p.error_with_pos('please use `[unsafe]` instead', p.tok.position())
name = 'unsafe'
}
if p.tok.kind == .colon {
name += ':'
p.next()

View File

@ -3,7 +3,7 @@
// that can be found in the LICENSE file.
module table
// e.g. `[unsafe_fn]`
// e.g. `[unsafe]`
pub struct Attr {
pub:
name string

View File

@ -33,7 +33,7 @@ fn test_ptr_infix() {
struct S1 {
}
[unsafe_fn]
[unsafe]
fn (s S1) f() {
}