Skip to content

Commit 4d9566c

Browse files
committed
[Diagnostics] NFC: Remove obsolete logic related to raw representable
1 parent 0e6dcab commit 4d9566c

File tree

2 files changed

+0
-83
lines changed

2 files changed

+0
-83
lines changed

lib/Sema/CSDiagnostics.cpp

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -166,12 +166,6 @@ bool FailureDiagnostic::conformsToKnownProtocol(
166166
return constraints::conformsToKnownProtocol(cs, type, protocol);
167167
}
168168

169-
Type FailureDiagnostic::isRawRepresentable(Type type,
170-
KnownProtocolKind protocol) const {
171-
auto &cs = getConstraintSystem();
172-
return constraints::isRawRepresentable(cs, type, protocol);
173-
}
174-
175169
Type RequirementFailure::getOwnerType() const {
176170
auto anchor = getRawAnchor();
177171

@@ -2297,12 +2291,6 @@ void ContextualFailure::tryFixIts(InFlightDiagnostic &diagnostic) const {
22972291
if (trySequenceSubsequenceFixIts(diagnostic))
22982292
return;
22992293

2300-
if (tryRawRepresentableFixIts(
2301-
diagnostic, KnownProtocolKind::ExpressibleByIntegerLiteral) ||
2302-
tryRawRepresentableFixIts(diagnostic,
2303-
KnownProtocolKind::ExpressibleByStringLiteral))
2304-
return;
2305-
23062294
if (tryIntegerCastFixIts(diagnostic))
23072295
return;
23082296

@@ -2532,59 +2520,6 @@ bool ContextualFailure::diagnoseYieldByReferenceMismatch() const {
25322520
return true;
25332521
}
25342522

2535-
bool ContextualFailure::tryRawRepresentableFixIts(
2536-
InFlightDiagnostic &diagnostic,
2537-
KnownProtocolKind rawRepresentableProtocol) const {
2538-
auto anchor = getAnchor();
2539-
auto fromType = getFromType();
2540-
auto toType = getToType();
2541-
2542-
// The following fixes apply for optional destination types as well.
2543-
bool toTypeIsOptional = !toType->getOptionalObjectType().isNull();
2544-
toType = toType->lookThroughAllOptionalTypes();
2545-
2546-
Type fromTypeUnwrapped = fromType->getOptionalObjectType();
2547-
bool fromTypeIsOptional = !fromTypeUnwrapped.isNull();
2548-
if (fromTypeIsOptional)
2549-
fromType = fromTypeUnwrapped;
2550-
2551-
auto fixIt = [&](StringRef convWrapBefore, StringRef convWrapAfter,
2552-
const Expr *expr) {
2553-
SourceRange exprRange = expr->getSourceRange();
2554-
if (fromTypeIsOptional && toTypeIsOptional) {
2555-
// Use optional's map function to convert conditionally, like so:
2556-
// expr.map{ T(rawValue: $0) }
2557-
bool needsParens = !expr->canAppendPostfixExpression();
2558-
std::string mapCodeFix;
2559-
if (needsParens) {
2560-
diagnostic.fixItInsert(exprRange.Start, "(");
2561-
mapCodeFix += ")";
2562-
}
2563-
mapCodeFix += ".map { ";
2564-
mapCodeFix += convWrapBefore;
2565-
mapCodeFix += "$0";
2566-
mapCodeFix += convWrapAfter;
2567-
mapCodeFix += " }";
2568-
diagnostic.fixItInsertAfter(exprRange.End, mapCodeFix);
2569-
} else if (!fromTypeIsOptional) {
2570-
diagnostic.fixItInsert(exprRange.Start, convWrapBefore);
2571-
diagnostic.fixItInsertAfter(exprRange.End, convWrapAfter);
2572-
}
2573-
};
2574-
2575-
if (auto rawTy = isRawRepresentable(fromType, rawRepresentableProtocol)) {
2576-
if (conformsToKnownProtocol(toType, rawRepresentableProtocol)) {
2577-
std::string convWrapBefore;
2578-
std::string convWrapAfter = ".rawValue";
2579-
if (auto *E = getAsExpr(anchor))
2580-
fixIt(convWrapBefore, convWrapAfter, E);
2581-
return true;
2582-
}
2583-
}
2584-
2585-
return false;
2586-
}
2587-
25882523
bool ContextualFailure::tryIntegerCastFixIts(
25892524
InFlightDiagnostic &diagnostic) const {
25902525
auto fromType = getFromType();

lib/Sema/CSDiagnostics.h

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,6 @@ class FailureDiagnostic {
219219
}
220220

221221
bool conformsToKnownProtocol(Type type, KnownProtocolKind protocol) const;
222-
Type isRawRepresentable(Type type, KnownProtocolKind protocol) const;
223222
};
224223

225224
/// Base class for all of the diagnostics related to generic requirement
@@ -621,23 +620,6 @@ class ContextualFailure : public FailureDiagnostic {
621620
/// Attempt to attach any relevant fix-its to already produced diagnostic.
622621
void tryFixIts(InFlightDiagnostic &diagnostic) const;
623622

624-
/// Attempts to add fix-its for these two mistakes:
625-
///
626-
/// - Passing an integer where a type conforming to RawRepresentable is
627-
/// expected, by wrapping the expression in a call to the contextual
628-
/// type's initializer
629-
///
630-
/// - Passing a type conforming to RawRepresentable where an integer is
631-
/// expected, by wrapping the expression in a call to the rawValue
632-
/// accessor
633-
///
634-
/// - Return true on the fixit is added, false otherwise.
635-
///
636-
/// This helps migration with SDK changes.
637-
bool
638-
tryRawRepresentableFixIts(InFlightDiagnostic &diagnostic,
639-
KnownProtocolKind rawRepresentablePrococol) const;
640-
641623
/// Attempts to add fix-its for these two mistakes:
642624
///
643625
/// - Passing an integer with the right type but which is getting wrapped with

0 commit comments

Comments
 (0)