parser: support [unsafe] instead of [unsafe_fn] (#6066)
parent
2a4ef2acbd
commit
6cc8815931
|
@ -16,7 +16,7 @@ fn test_ptr_infix() {
|
|||
|
||||
struct S1 {}
|
||||
|
||||
[unsafe_fn]
|
||||
[unsafe]
|
||||
fn (s S1) f(){}
|
||||
|
||||
fn test_funcs() {
|
||||
|
|
|
@ -16,7 +16,7 @@ fn test_ptr_infix() {
|
|||
|
||||
struct S1 {}
|
||||
|
||||
[unsafe_fn]
|
||||
[unsafe]
|
||||
fn (s S1) f(){}
|
||||
|
||||
fn test_funcs() {
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -33,7 +33,7 @@ fn test_ptr_infix() {
|
|||
struct S1 {
|
||||
}
|
||||
|
||||
[unsafe_fn]
|
||||
[unsafe]
|
||||
fn (s S1) f() {
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue