Skip to content

Commit 8cd23e5

Browse files
authored
Merge pull request #1642 from ahoppen/ahoppen/shorthand-let
Migrate SwiftSyntax to shorthand `let` notation
2 parents fcc4880 + f20e124 commit 8cd23e5

34 files changed

+50
-50
lines changed

CodeGeneration/Sources/SyntaxSupport/TokenSpec.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public class TokenSpec {
4848
self.name = name
4949
self.kind = kind
5050
self.nameForDiagnostics = nameForDiagnostics
51-
if let unprefixedKind = unprefixedKind {
51+
if let unprefixedKind {
5252
self.unprefixedKind = unprefixedKind
5353
} else {
5454
self.unprefixedKind = kind

CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntax/RawSyntaxValidationFile.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ let rawSyntaxValidationFile = try! SourceFileSyntax(leadingTrivia: copyrightHead
157157
DeclSyntax(
158158
#"""
159159
func assertNoError(_ nodeKind: SyntaxKind, _ index: Int, _ error: ValidationError?) {
160-
if let error = error {
160+
if let error {
161161
let (file, line) = error.fileAndLine
162162
assertionFailure("""
163163
Error validating child at index \(index) of \(nodeKind):

CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntax/SyntaxRewriterFile.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ let syntaxRewriterFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
316316
}
317317
}
318318
319-
if let newLayout = newLayout {
319+
if let newLayout {
320320
// A child node was rewritten. Build the updated node.
321321
322322
// Sanity check, ensure the new children are the same length.

Sources/SwiftBasicFormat/BasicFormat.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ open class BasicFormat: SyntaxRewriter {
5555
// MARK: - Updating indentation level
5656

5757
public func increaseIndentationLevel(to userDefinedIndentation: Trivia? = nil) {
58-
if let userDefinedIndentation = userDefinedIndentation {
58+
if let userDefinedIndentation {
5959
indentationStack.append((indentation: userDefinedIndentation, isUserDefined: true))
6060
} else {
6161
indentationStack.append((indentation: currentIndentationLevel + indentationWidth, isUserDefined: false))

Sources/SwiftDiagnostics/DiagnosticsFormatter.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ public struct DiagnosticsFormatter {
221221
var annotatedSource = ""
222222

223223
// If there was a filename, add it first.
224-
if let fileName = fileName {
224+
if let fileName {
225225
let header = colorizeBufferOutline("===")
226226
let firstLine =
227227
1

Sources/SwiftOperators/OperatorTable+Folding.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,8 +413,8 @@ extension OperatorTable {
413413
// - missing precedence groups,
414414
// - have unordered precedence groups, or
415415
// - have the same precedence group with no associativity.
416-
if let op1Precedence = op1Precedence,
417-
let op2Precedence = op2Precedence
416+
if let op1Precedence,
417+
let op2Precedence
418418
{
419419
try errorHandler(
420420
.incomparableOperators(

Sources/SwiftParser/Expressions.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ extension Parser {
173173
elements.append(lastElement)
174174
elements.append(operatorExpr)
175175

176-
if let rhsExpr = rhsExpr {
176+
if let rhsExpr {
177177
// Operator parsing returned the RHS.
178178
lastElement = rhsExpr
179179
} else if forDirective && self.currentToken.isAtStartOfLine {
@@ -1491,7 +1491,7 @@ extension Parser {
14911491
let (unexpectedBeforeSlash, openSlash) = self.expect(.regexSlash)
14921492

14931493
// If we had opening pounds, there should be no trivia for the slash.
1494-
if let openPounds = openPounds {
1494+
if let openPounds {
14951495
precondition(openPounds.trailingTriviaByteLength == 0 && openSlash.leadingTriviaByteLength == 0)
14961496
}
14971497

Sources/SwiftParser/Lexer/Cursor.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ extension Lexer.Cursor {
172172
mutating func perform(stateTransition: Lexer.StateTransition, stateAllocator: BumpPtrAllocator) {
173173
switch stateTransition {
174174
case .push(newState: let newState):
175-
if let topState = topState {
175+
if let topState {
176176
if let stateStack = stateStack {
177177
let newStateStack = stateAllocator.allocate(State.self, count: stateStack.count + 1)
178178
let (_, existingStateStackEndIndex) = newStateStack.initialize(from: stateStack)
@@ -190,7 +190,7 @@ extension Lexer.Cursor {
190190
case .replace(newState: let newState):
191191
topState = newState
192192
case .pop:
193-
if let stateStack = stateStack {
193+
if let stateStack {
194194
topState = stateStack.last!
195195
if stateStack.count == 1 {
196196
self.stateStack = nil
@@ -760,7 +760,7 @@ extension Lexer.Cursor {
760760
// Test for single-line string literals that resemble multiline delimiter.
761761
var sameLineCloseCheck = self
762762
_ = sameLineCloseCheck.advance()
763-
if let openingRawStringDelimiters = openingRawStringDelimiters, openingRawStringDelimiters != 0 {
763+
if let openingRawStringDelimiters, openingRawStringDelimiters != 0 {
764764
// Scan if the current line contains `"` followed by `openingRawStringDelimiters` `#` characters
765765
while sameLineCloseCheck.is(notAt: "\r", "\n") {
766766
if sameLineCloseCheck.advance(matching: #"""#) {

Sources/SwiftParser/Lexer/RegexLiteralLexer.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ fileprivate struct RegexLiteralLexer {
174174

175175
// If we have a multi-line literal, make sure the closing delimiter
176176
// appears alone on a newline.
177-
if let lastNewlineEnd = lastNewlineEnd {
177+
if let lastNewlineEnd {
178178
var delimScan = lastNewlineEnd
179179
while delimScan.pointer < slashBegin.pointer {
180180
if !delimScan.advance(matching: " ", "\t") {
@@ -809,7 +809,7 @@ extension Lexer.Cursor {
809809

810810
// Compute the new transition.
811811
let transition: Lexer.StateTransition?
812-
if let existingPtr = existingPtr {
812+
if let existingPtr {
813813
transition = lexemes.isEmpty ? .pop : .replace(newState: .inRegexLiteral(index: index, lexemes: existingPtr))
814814
} else {
815815
transition = lexemes.isEmpty ? nil : .pushRegexLexemes(index: index, lexemes: lexemes.base)

Sources/SwiftParser/Names.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ extension Parser {
185185
} else {
186186
generics = nil
187187
}
188-
if let keepGoing = keepGoing {
188+
if let keepGoing {
189189
result = RawTypeSyntax(
190190
RawMemberTypeIdentifierSyntax(
191191
baseType: result!,

Sources/SwiftParser/Parser.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public struct Parser {
148148
self.maximumNestingLevel = maximumNestingLevel ?? Self.defaultMaximumNestingLevel
149149

150150
var sourceBuffer: UnsafeBufferPointer<UInt8>
151-
if let arena = arena {
151+
if let arena {
152152
self.arena = arena
153153
sourceBuffer = input
154154
precondition(arena.contains(text: SyntaxText(baseAddress: input.baseAddress, count: input.count)))

Sources/SwiftParser/Patterns.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ extension Parser {
164164
let colon = self.consume(if: .colon)
165165
var lookahead = self.lookahead()
166166
var type: RawTypeAnnotationSyntax?
167-
if let colon = colon {
167+
if let colon {
168168
let result = self.parseResultType()
169169
type = RawTypeAnnotationSyntax(
170170
colon: colon,

Sources/SwiftParser/Recovery.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ extension Parser.Lookahead {
9292
default:
9393
matchedSpec = nil
9494
}
95-
if let matchedSpec = matchedSpec {
95+
if let matchedSpec {
9696
return RecoveryConsumptionHandle(
9797
unexpectedTokens: self.tokensConsumed - initialTokensConsumed,
9898
tokenConsumptionHandle: TokenConsumptionHandle(spec: matchedSpec)

Sources/SwiftParser/StringLiterals.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ fileprivate class StringLiteralExpressionIndentationChecker {
7272
var hasRewrittenChild = false
7373
var rewrittenChildren: [RawSyntax?] = []
7474
for child in layoutView.children {
75-
if let child = child, let rewrittenChild = visit(node: child) {
75+
if let child, let rewrittenChild = visit(node: child) {
7676
hasRewrittenChild = true
7777
rewrittenChildren.append(rewrittenChild)
7878
} else {
@@ -360,7 +360,7 @@ extension Parser {
360360
// -------------------------------------------------------------------------
361361
// Parse indentation of the closing quote
362362

363-
if let lastSegment = lastSegment,
363+
if let lastSegment,
364364
let parsedTrivia = parseIndentationTrivia(text: lastSegment.content.tokenText)
365365
{
366366
indentationTrivia = parsedTrivia

Sources/SwiftParser/SyntaxUtils.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ extension Array: UnexpectedNodesCombinable where Element: UnexpectedNodesCombina
5656

5757
extension Optional: UnexpectedNodesCombinable where Wrapped: UnexpectedNodesCombinable {
5858
var elements: [RawSyntax] {
59-
if let self = self {
59+
if let self {
6060
return self.elements
6161
} else {
6262
return []

Sources/SwiftParser/Types.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ extension Parser {
156156

157157
var base = self.parseSimpleType()
158158
guard self.atContextualPunctuator("&") else {
159-
if let someOrAny = someOrAny {
159+
if let someOrAny {
160160
return RawTypeSyntax(
161161
RawConstrainedSugarTypeSyntax(
162162
someOrAnySpecifier: someOrAny,
@@ -201,7 +201,7 @@ extension Parser {
201201
)
202202
}
203203

204-
if let someOrAny = someOrAny {
204+
if let someOrAny {
205205
return RawTypeSyntax(
206206
RawConstrainedSugarTypeSyntax(
207207
someOrAnySpecifier: someOrAny,
@@ -545,7 +545,7 @@ extension Parser {
545545

546546
// In the case that the input is "(foo bar)" we have to decide whether we parse it as "(foo: bar)" or "(foo, bar)".
547547
// As most people write identifiers lowercase and types capitalized, we decide on the first character of the first token
548-
if let first = first,
548+
if let first,
549549
second == nil,
550550
colon?.isMissing == true,
551551
first.tokenText.isStartingWithUppercase

Sources/SwiftParserDiagnostics/DiagnosticExtensions.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,10 @@ extension FixIt.MultiNodeChange {
141141
var presentNode = MissingNodesBasicFormatter(viewMode: .fixedUp).visit(Syntax(node))
142142
presentNode = PresentMaker().rewrite(presentNode)
143143

144-
if let leadingTrivia = leadingTrivia {
144+
if let leadingTrivia {
145145
presentNode = presentNode.with(\.leadingTrivia, leadingTrivia)
146146
}
147-
if let trailingTrivia = trailingTrivia {
147+
if let trailingTrivia {
148148
presentNode = presentNode.with(\.trailingTrivia, trailingTrivia)
149149
}
150150

Sources/SwiftParserDiagnostics/MissingNodesError.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ public struct MissingNodesError: ParserError {
249249
} else {
250250
missingExpr = nil
251251
}
252-
if let missingExpr = missingExpr,
252+
if let missingExpr,
253253
let exprList = missingExpr.parent?.as(ExprListSyntax.self),
254254
exprList.parent?.is(SequenceExprSyntax.self) ?? false,
255255
let previousSiblingIndex = exprList.index(missingExpr.index, offsetBy: -1, limitedBy: exprList.startIndex)
@@ -296,7 +296,7 @@ public struct MissingNodesError: ParserError {
296296
public var message: String {
297297
let (anchor, description) = nodesDescriptionAndCommonParent(missingNodes, format: true)
298298
var message = "expected \(description)"
299-
if let afterClause = afterClause {
299+
if let afterClause {
300300
message += " \(afterClause)"
301301
} else if let parentContextClause = parentContextClause(anchor: anchor?.parent ?? findCommonAncestor(missingNodes)) {
302302
message += " \(parentContextClause)"
@@ -389,7 +389,7 @@ extension ParseDiagnosticsGenerator {
389389
}
390390

391391
let position: AbsolutePosition
392-
if let overridePosition = overridePosition {
392+
if let overridePosition {
393393
position = overridePosition
394394
} else if node.shouldBeInsertedAfterNextTokenTrivia, let nextToken = node.nextToken(viewMode: .sourceAccurate) {
395395
position = nextToken.positionAfterSkippingLeadingTrivia

Sources/SwiftParserDiagnostics/ParseDiagnosticsGenerator.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1129,7 +1129,7 @@ public class ParseDiagnosticsGenerator: SyntaxAnyVisitor {
11291129
} else {
11301130
message = nil
11311131
}
1132-
if let message = message {
1132+
if let message {
11331133
let fixIts: [FixIt]
11341134
if node.identifier.presence == .present {
11351135
fixIts = [FixIt(message: RemoveNodesFixIt(unexpected), changes: .makeMissing(unexpected))]

Sources/SwiftRefactor/OpaqueParameterToGeneric.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public struct OpaqueParameterToGeneric: RefactoringProvider {
133133
}
134134

135135
var newGenericParams: [GenericParameterSyntax] = []
136-
if let genericParams = genericParams {
136+
if let genericParams {
137137
newGenericParams.append(contentsOf: genericParams.genericParameterList)
138138
}
139139

@@ -152,7 +152,7 @@ public struct OpaqueParameterToGeneric: RefactoringProvider {
152152

153153
let newGenericParamSyntax = GenericParameterListSyntax(newGenericParams)
154154
let newGenericParamClause: GenericParameterClauseSyntax
155-
if let genericParams = genericParams {
155+
if let genericParams {
156156
newGenericParamClause = genericParams.with(
157157
\.genericParameterList,
158158
newGenericParamSyntax

Sources/SwiftSyntax/IncrementalParseTransition.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ public struct IncrementalParseLookup {
238238
}
239239
let prevPosition = AbsolutePosition(utf8Offset: prevOffset)
240240
let node = cursorLookup(prevPosition: prevPosition, kind: kind)
241-
if let delegate = reusedDelegate, let node = node {
241+
if let delegate = reusedDelegate, let node {
242242
delegate.parserReusedNode(
243243
range: ByteSourceRange(offset: newOffset, length: node.byteSize),
244244
previousNode: node

Sources/SwiftSyntax/Raw/RawSyntax.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ internal struct RawSyntaxData {
7676
}
7777
}
7878
set {
79-
if let newValue = newValue {
79+
if let newValue {
8080
self.tokenDiagnosticKind = newValue.kind
8181
self.tokenDiagnosticByteOffset = newValue.byteOffset
8282
} else {
@@ -130,7 +130,7 @@ internal struct RawSyntaxData {
130130
}
131131
}
132132
set {
133-
if let newValue = newValue {
133+
if let newValue {
134134
self.tokenDiagnosticKind = newValue.kind
135135
self.tokenDiagnosticByteOffset = newValue.byteOffset
136136
} else {

Sources/SwiftSyntax/Syntax.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ public extension SyntaxProtocol {
619619
mark: SyntaxProtocol? = nil,
620620
indentString: String
621621
) {
622-
if let mark = mark, self.id == mark.id {
622+
if let mark, self.id == mark.id {
623623
target.write("*** ")
624624
}
625625

@@ -639,7 +639,7 @@ public extension SyntaxProtocol {
639639

640640
let allChildren = children(viewMode: .all)
641641

642-
if let converter = converter {
642+
if let converter {
643643
let range = sourceRange(converter: converter)
644644
target.write(" [\(range.start)...\(range.end)]")
645645
}
@@ -648,7 +648,7 @@ public extension SyntaxProtocol {
648648
target.write(" MISSING")
649649
}
650650

651-
if let mark = mark, self.id == mark.id {
651+
if let mark, self.id == mark.id {
652652
target.write(" ***")
653653
}
654654

Sources/SwiftSyntax/SyntaxChildren.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ struct NonNilRawSyntaxChildren: BidirectionalCollection {
302302
guard let (node, info) = self.iterator.next() else {
303303
return nil
304304
}
305-
if let node = node, viewMode.shouldTraverse(node: node) {
305+
if let node, viewMode.shouldTraverse(node: node) {
306306
return AbsoluteRawSyntax(raw: node, info: info)
307307
}
308308
}

Sources/SwiftSyntax/SyntaxData.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ struct SyntaxData {
295295
func replacingSelf(_ newRaw: RawSyntax, arena: SyntaxArena) -> SyntaxData {
296296
// If we have a parent already, then ask our current parent to copy itself
297297
// recursively up to the root.
298-
if let parent = parent {
298+
if let parent {
299299
let parentData = parent.replacingChild(at: indexInParent, with: newRaw, arena: arena)
300300
let newParent = Syntax(parentData)
301301
return SyntaxData(absoluteRaw.replacingSelf(newRaw, newRootId: parentData.nodeId.rootId), parent: newParent)

Sources/SwiftSyntax/Trivia.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ extension Trivia: CustomStringConvertible {
133133

134134
extension Trivia: CustomDebugStringConvertible {
135135
public var debugDescription: String {
136-
if count == 1, let first = first {
136+
if count == 1, let first {
137137
return first.debugDescription
138138
}
139139
return "[" + map(\.debugDescription).joined(separator: ", ") + "]"

Sources/SwiftSyntax/generated/SyntaxRewriter.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7049,7 +7049,7 @@ open class SyntaxRewriter {
70497049
}
70507050
}
70517051

7052-
if let newLayout = newLayout {
7052+
if let newLayout {
70537053
// A child node was rewritten. Build the updated node.
70547054

70557055
// Sanity check, ensure the new children are the same length.

Sources/SwiftSyntax/generated/raw/RawSyntaxValidation.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ func validateLayout(layout: RawSyntaxBuffer, as kind: SyntaxKind) {
179179
)
180180
}
181181
func assertNoError(_ nodeKind: SyntaxKind, _ index: Int, _ error: ValidationError?) {
182-
if let error = error {
182+
if let error {
183183
let (file, line) = error.fileAndLine
184184
assertionFailure("""
185185
Error validating child at index \(index) of \(nodeKind):

Sources/SwiftSyntaxBuilder/Syntax+StringInterpolation.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ extension SyntaxStringInterpolation: StringInterpolationProtocol {
6868
) {
6969
let startIndex = sourceText.count
7070
let indentedNode: Node
71-
if let lastIndentation = lastIndentation {
71+
if let lastIndentation {
7272
indentedNode = Indenter.indent(node, indentation: lastIndentation)
7373
} else {
7474
indentedNode = node

Sources/SwiftSyntaxMacros/FunctionParameterUtils.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ extension FunctionParameterSyntax {
1111
/// respectively.
1212
var parameterName: TokenSyntax? {
1313
// If there were two names, the second is the parameter name.
14-
if let secondName = secondName {
14+
if let secondName {
1515
if secondName.text == "_" {
1616
return nil
1717
}

0 commit comments

Comments
 (0)