Skip to content

[diags][cxx-interop] Update diagnostic for 'begin' to suggest using a for-loop instead. #65617

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/swift/AST/DiagnosticsClangImporter.def
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ NOTE(mark_safe_to_import, none, "annotate method '%0' with 'SWIFT_RETURNS_INDEPE
NOTE(at_to_subscript, none, "do you want to replace it with a call "
"to the subscript operator?",
())
NOTE(get_swift_iterator, none, "do you want to make a Swift iterator instead?",
NOTE(use_collection_apis, none, "do you want to use a for-loop instead?",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe for-in loop is better? That's how that construct is referred to in the documentation.

())
NOTE(replace_with_nil, none, "do you want to compare against 'nil' instead?",
())
Expand Down
2 changes: 1 addition & 1 deletion lib/Sema/CSDiagnostics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3877,7 +3877,7 @@ void MissingMemberFailure::diagnoseUnsafeCxxMethod(SourceLoc loc,
if (conformsToRACollection(baseType)) {
ctx.Diags.diagnose(loc, diag::iterator_method_unavailable,
name.getBaseIdentifier().str());
ctx.Diags.diagnose(loc, diag::get_swift_iterator)
ctx.Diags.diagnose(loc, diag::use_collection_apis)
.fixItReplaceChars(
loc, loc.getAdvancedLoc(name.getBaseIdentifier().str().size()),
"makeIterator");
Expand Down
2 changes: 1 addition & 1 deletion test/Interop/Cxx/class/fixits-for-std-vector.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import CxxStdlib

public func test(v: V) {
// CHECK: note: C++ method 'begin' that returns an iterator is unavailable
// CHECK: note: do you want to make a Swift iterator instead?
// CHECK: note: do you want to use a for-loop instead?
// CHECK: ^~~~~
// CHECK: makeIterator
_ = v.begin()
Expand Down