diff --git a/include/clang/Basic/DiagnosticParseKinds.td b/include/clang/Basic/DiagnosticParseKinds.td
index ff76e95..283bc1b 100644
--- a/include/clang/Basic/DiagnosticParseKinds.td
+++ b/include/clang/Basic/DiagnosticParseKinds.td
@@ -422,6 +422,9 @@ def warn_semicolon_before_method_body : Warning<
   InGroup<DiagGroup<"semicolon-before-method-body">>, DefaultIgnore;
 def note_extra_comma_message_arg : Note<
   "comma separating Objective-C messaging arguments">;
+def err_import_in_impl : Error<
+  "%select{|treating directive as a module import; }0module import not allowed "
+  "within @implementation">;
 
 def err_expected_field_designator : Error<
   "expected a field designator, such as '.field = 4'">;
diff --git a/lib/Parse/ParseObjc.cpp b/lib/Parse/ParseObjc.cpp
index c8460c0..55097fa 100644
--- a/lib/Parse/ParseObjc.cpp
+++ b/lib/Parse/ParseObjc.cpp
@@ -1582,7 +1582,11 @@ Parser::ParseObjCAtImplementationDeclaration(SourceLocation AtLoc) {
 
   {
     ObjCImplParsingDataRAII ObjCImplParsing(*this, ObjCImpDecl);
-    while (!ObjCImplParsing.isFinished() && !isEofOrEom()) {
+    while (!ObjCImplParsing.isFinished()) {
+      // Allow annot_module_include, as it will emit a diagnostic in
+      // ParseExternalDeclaration similarly to explicit @import.
+      if (isEofOrEom() && !Tok.is(tok::annot_module_include))
+        break;
       ParsedAttributesWithRange attrs(AttrFactory);
       MaybeParseCXX11Attributes(attrs);
       MaybeParseMicrosoftAttributes(attrs);
diff --git a/lib/Parse/Parser.cpp b/lib/Parse/Parser.cpp
index efa6a1b..16a1081 100644
--- a/lib/Parse/Parser.cpp
+++ b/lib/Parse/Parser.cpp
@@ -602,13 +602,6 @@ bool Parser::ParseTopLevelDecl(DeclGroupPtrTy &Result) {
     HandlePragmaUnused();
     return false;
 
-  case tok::annot_module_include:
-    Actions.ActOnModuleInclude(Tok.getLocation(),
-                               reinterpret_cast<Module *>(
-                                   Tok.getAnnotationValue()));
-    ConsumeToken();
-    return false;
-
   case tok::annot_module_begin:
   case tok::annot_module_end:
     // FIXME: Update visibility based on the submodule we're in.
@@ -739,6 +732,18 @@ Parser::ParseExternalDeclaration(ParsedAttributesWithRange &attrs,
   }
   case tok::at:
     return ParseObjCAtDirectives();
+
+  case tok::annot_module_include:
+    if (CurParsedObjCImpl) {
+      Diag(Tok.getLocation(), diag::err_import_in_impl) << /*Implicit*/1;
+      Diag(CurParsedObjCImpl->Dcl->getLocStart(),
+           diag::note_objc_container_start) << /*Implementation*/4;
+    } else
+      Actions.ActOnModuleInclude(Tok.getLocation(),
+        reinterpret_cast<Module *>(Tok.getAnnotationValue()));
+
+    ConsumeToken();
+    return DeclGroupPtrTy();
   case tok::minus:
   case tok::plus:
     if (!getLangOpts().ObjC1) {
@@ -2013,6 +2018,14 @@ Parser::DeclGroupPtrTy Parser::ParseModuleImport(SourceLocation AtLoc) {
     return DeclGroupPtrTy();
   }
 
+  if (CurParsedObjCImpl) {
+    Diag(AtLoc, diag::err_import_in_impl) << /*Explicit*/0;
+    Diag(CurParsedObjCImpl->Dcl->getLocStart(),
+         diag::note_objc_container_start) << /*Implementation*/4;
+    ExpectAndConsumeSemi(diag::err_module_expected_semi);
+    return DeclGroupPtrTy();
+  }
+
   DeclResult Import = Actions.ActOnModuleImport(AtLoc, ImportLoc, Path);
   ExpectAndConsumeSemi(diag::err_module_expected_semi);
   if (Import.isInvalid())
diff --git a/test/Modules/import-in-impl.m b/test/Modules/import-in-impl.m
new file mode 100644
index 0000000..b16a2dc
--- /dev/null
+++ b/test/Modules/import-in-impl.m
@@ -0,0 +1,10 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -F %S/Inputs -I %S/Inputs -Wno-objc-root-class -verify %s
+
+@interface I
+@end
+
+@implementation I // expected-note 2 {{implementation started here}}
+@import Module; // expected-error{{module import not allowed within @implementation}}
+#include "Module/Module.h" // expected-error{{treating directive as a module import; module import not allowed within @implementation}}
+@end
