|
14 | 14 | //
|
15 | 15 | //===----------------------------------------------------------------------===//
|
16 | 16 |
|
17 |
| -#include "swift/Parse/Parser.h" |
18 |
| -#include "swift/Parse/CodeCompletionCallbacks.h" |
19 |
| -#include "swift/Parse/ParsedSyntaxRecorder.h" |
20 |
| -#include "swift/Parse/ParseSILSupport.h" |
21 |
| -#include "swift/Parse/SyntaxParsingContext.h" |
22 |
| -#include "swift/Syntax/SyntaxKind.h" |
23 |
| -#include "swift/Subsystems.h" |
24 |
| -#include "swift/Strings.h" |
25 | 17 | #include "swift/AST/ASTWalker.h"
|
26 | 18 | #include "swift/AST/Attr.h"
|
27 |
| -#include "swift/AST/GenericParamList.h" |
28 |
| -#include "swift/AST/LazyResolver.h" |
29 | 19 | #include "swift/AST/DebuggerClient.h"
|
| 20 | +#include "swift/AST/Decl.h" |
30 | 21 | #include "swift/AST/DiagnosticsParse.h"
|
| 22 | +#include "swift/AST/GenericParamList.h" |
31 | 23 | #include "swift/AST/Initializer.h"
|
| 24 | +#include "swift/AST/LazyResolver.h" |
32 | 25 | #include "swift/AST/Module.h"
|
33 | 26 | #include "swift/AST/ParameterList.h"
|
34 | 27 | #include "swift/AST/ParseRequests.h"
|
35 | 28 | #include "swift/AST/SourceFile.h"
|
36 | 29 | #include "swift/Basic/Defer.h"
|
37 | 30 | #include "swift/Basic/Statistic.h"
|
38 | 31 | #include "swift/Basic/StringExtras.h"
|
| 32 | +#include "swift/Parse/CodeCompletionCallbacks.h" |
| 33 | +#include "swift/Parse/ParseSILSupport.h" |
| 34 | +#include "swift/Parse/ParsedSyntaxRecorder.h" |
| 35 | +#include "swift/Parse/Parser.h" |
| 36 | +#include "swift/Parse/SyntaxParsingContext.h" |
| 37 | +#include "swift/Strings.h" |
| 38 | +#include "swift/Subsystems.h" |
| 39 | +#include "swift/Syntax/SyntaxKind.h" |
| 40 | +#include "llvm/ADT/PointerUnion.h" |
| 41 | +#include "llvm/ADT/StringSwitch.h" |
| 42 | +#include "llvm/ADT/Twine.h" |
39 | 43 | #include "llvm/Support/Compiler.h"
|
40 | 44 | #include "llvm/Support/MemoryBuffer.h"
|
41 | 45 | #include "llvm/Support/Path.h"
|
42 | 46 | #include "llvm/Support/SaveAndRestore.h"
|
43 |
| -#include "llvm/ADT/PointerUnion.h" |
44 |
| -#include "llvm/ADT/StringSwitch.h" |
45 |
| -#include "llvm/ADT/Twine.h" |
46 | 47 | #include <algorithm>
|
47 | 48 |
|
48 | 49 | using namespace swift;
|
@@ -5111,9 +5112,7 @@ static Parser::ParseDeclOptions getMemberParseDeclOptions(
|
5111 | 5112 | Parser::PD_InProtocol);
|
5112 | 5113 |
|
5113 | 5114 | case DeclKind::Class:
|
5114 |
| - return ParseDeclOptions( |
5115 |
| - Parser::PD_HasContainerType | Parser::PD_AllowDestructor | |
5116 |
| - Parser::PD_InClass); |
| 5115 | + return ParseDeclOptions(Parser::PD_HasContainerType | Parser::PD_InClass); |
5117 | 5116 |
|
5118 | 5117 | case DeclKind::Struct:
|
5119 | 5118 | return ParseDeclOptions(Parser::PD_HasContainerType | Parser::PD_InStruct);
|
@@ -8748,8 +8747,13 @@ parseDeclDeinit(ParseDeclOptions Flags, DeclAttributes &Attributes) {
|
8748 | 8747 |
|
8749 | 8748 | DD->getAttrs() = Attributes;
|
8750 | 8749 |
|
8751 |
| - // Reject 'destructor' functions outside of classes |
8752 |
| - if (!(Flags & PD_AllowDestructor)) { |
| 8750 | + // Reject 'destructor' functions outside of structs, enums, and classes. |
| 8751 | + // |
| 8752 | + // Later in the type checker, we validate that structs/enums only do this if |
| 8753 | + // they are move only. |
| 8754 | + auto *nom = dyn_cast<NominalTypeDecl>(CurDeclContext); |
| 8755 | + if (!nom || |
| 8756 | + (!isa<StructDecl>(nom) && !isa<EnumDecl>(nom) && !isa<ClassDecl>(nom))) { |
8753 | 8757 | diagnose(DestructorLoc, diag::destructor_decl_outside_class);
|
8754 | 8758 |
|
8755 | 8759 | // Tell the type checker not to touch this destructor.
|
|
0 commit comments