Skip to content

Commit 96d0b35

Browse files
committed
[cxx-interop] Fixit: std.x -> CxxStdlib.x.
1 parent 30482c3 commit 96d0b35

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,8 @@ ERROR(expect_compile_time_const,none,
764764

765765
ERROR(sema_no_import,Fatal,
766766
"no such module '%0'", (StringRef))
767+
NOTE(did_you_mean_cxxstdlib,none,
768+
"did you mean 'CxxStdlib'?'", ())
767769
ERROR(sema_no_import_target,Fatal,
768770
"could not find module '%0' for target '%1'; "
769771
"found: %2, at: %3", (StringRef, StringRef, StringRef, StringRef))

lib/Sema/ImportResolution.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,15 @@ UnboundImport::getTopLevelModule(ModuleDecl *M, SourceFile &SF) {
420420
// MARK: Implicit imports
421421
//===----------------------------------------------------------------------===//
422422

423+
static void tryStdlibFixit(ASTContext &ctx,
424+
StringRef moduleName,
425+
SourceLoc loc) {
426+
if (moduleName.startswith("std")) {
427+
ctx.Diags.diagnose(loc, diag::did_you_mean_cxxstdlib)
428+
.fixItReplaceChars(loc, loc.getAdvancedLoc(3), "CxxStdlib");
429+
}
430+
}
431+
423432
static void diagnoseNoSuchModule(ModuleDecl *importingModule,
424433
SourceLoc importLoc,
425434
ImportPath::Module modulePath,
@@ -438,6 +447,7 @@ static void diagnoseNoSuchModule(ModuleDecl *importingModule,
438447
if (nonfatalInREPL && ctx.LangOpts.DebuggerSupport)
439448
diagKind = diag::sema_no_import_repl;
440449
ctx.Diags.diagnose(importLoc, diagKind, modulePathStr);
450+
tryStdlibFixit(ctx, modulePathStr, importLoc);
441451
}
442452

443453
if (ctx.SearchPathOpts.getSDKPath().empty() &&

0 commit comments

Comments
 (0)