Skip to content

Commit 1339e24

Browse files
committed

File tree

5 files changed

+23
-8
lines changed

5 files changed

+23
-8
lines changed

swift-mode-font-lock.el

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ Return nil otherwise."
535535

536536
(defconst swift-mode:expression-keywords
537537
'("as" "catch" "dynamicType" "is" "rethrows" "super" "self" "Self" "throws"
538-
"throw" "try" "async" "await" "consume" "copy")
538+
"throw" "try" "async" "await" "consume" "copy" "discard")
539539
"Keywords used in expressions and types.
540540
541541
Excludes true, false, and keywords begin with a number sign.")

swift-mode-indent.el

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1649,7 +1649,7 @@ It is a Generic parameter list if:
16491649
"as" "as?" "as!"
16501650
"is"
16511651
"await"
1652-
"consume" "copy"
1652+
"consume" "copy" "discard"
16531653
"in"
16541654
"init" "deinit" "get" "set" "willSet" "didSet" "subscript"
16551655
"for" "case" "default" "while" "let" "var" "repeat" "if" "else"

swift-mode-lexer.el

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ END is the point after the token."
9999

100100
;; Token types is one of the following symbols:
101101
;;
102-
;; - prefix-operator (including try, try?, try!, await, consume, and copy)
102+
;; - prefix-operator (including try, try?, try!, await, consume, copy, and
103+
;; discard)
103104
;; - postfix-operator
104105
;; - binary-operator (including as, as?, as!, is, =, ., and ->)
105106
;; - attribute (e.g. @objc, @abc(def))
@@ -988,7 +989,8 @@ Other properties are the same as the TOKEN."
988989
(type
989990
(cond
990991
(is-declaration 'identifier)
991-
((member text '("try" "try?" "try!" "await" "consume" "copy"))
992+
((member text '("try" "try?" "try!" "await" "consume" "copy"
993+
"discard"))
992994
'prefix-operator)
993995
((equal text ".") 'binary-operator)
994996
((and has-preceding-space has-following-space) 'binary-operator)
@@ -1147,7 +1149,7 @@ This function does not return `implicit-;' or `type-:'."
11471149
pos-after-comment
11481150
(point))))
11491151

1150-
;; Operator (other than as, try, is, await, consume, or copy)
1152+
;; Operator (other than as, try, is, await, consume, copy, or discard)
11511153
;;
11521154
;; Operators starts with a dot can contains dots. Other operators cannot
11531155
;; contain dots.
@@ -1246,7 +1248,7 @@ This function does not return `implicit-;' or `type-:'."
12461248
text
12471249
(- (point) (length text))
12481250
(point)))
1249-
((member text '("await" "consume" "copy"))
1251+
((member text '("await" "consume" "copy" "discard"))
12501252
(swift-mode:token 'prefix-operator
12511253
text
12521254
(- (point) (length text))
@@ -1419,7 +1421,7 @@ This function does not return `implicit-;' or `type-:'."
14191421
(point)
14201422
pos-before-comment)))
14211423

1422-
;; Operator (other than as, try, is, await, consume, or copy)
1424+
;; Operator (other than as, try, is, await, consume, copy, or discard)
14231425
;;
14241426
;; Operators which starts with a dot can contain other dots. Other
14251427
;; operators cannot contain dots.
@@ -1501,7 +1503,7 @@ This function does not return `implicit-;' or `type-:'."
15011503
text
15021504
(point)
15031505
(+ (point) (length text))))
1504-
((member text '("try" "await" "consume" "copy"))
1506+
((member text '("try" "await" "consume" "copy" "discard"))
15051507
(swift-mode:token 'prefix-operator
15061508
text
15071509
(point)

test/swift-files/indent/expressions.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -843,3 +843,13 @@ func foo() {
843843
copy
844844
x
845845
}
846+
847+
848+
// discard self
849+
// https://github.com/apple/swift-evolution/blob/main/proposals/0390-noncopyable-structs-and-enums.md
850+
851+
func foo() {
852+
// discard operator cannot be followed by a line break.
853+
discard
854+
self
855+
}

test/swift-files/indent/identifiers.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,9 @@ func foo() {
227227
foo(
228228
copy: 1
229229
)
230+
foo(
231+
discard: 1
232+
)
230233

231234
// Keywords reserved in particular contexts
232235
foo(

0 commit comments

Comments
 (0)