Skip to content

Commit c8a16d3

Browse files
authored
Merge pull request #26041 from atrick/remove-ptrcast-diag
Remove the Swift-3-era pointer casting diagnostic.
2 parents d236a17 + d2a0ae2 commit c8a16d3

File tree

3 files changed

+6
-52
lines changed

3 files changed

+6
-52
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,9 +257,6 @@ ERROR(cannot_call_with_params, none,
257257
"cannot invoke %select{|initializer for type }2'%0' with an argument list"
258258
" of type '%1'", (StringRef, StringRef, bool))
259259

260-
NOTE(pointer_init_to_type,none,
261-
"Pointer conversion restricted: use '.assumingMemoryBound(to:)' or '.bindMemory(to:capacity:)' to view memory as a type.", ())
262-
263260
ERROR(cannot_call_non_function_value,none,
264261
"cannot call value of non-function type %0", (Type))
265262

lib/Sema/CSDiag.cpp

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -4059,44 +4059,6 @@ bool FailureDiagnosis::diagnoseArgumentGenericRequirements(
40594059
return result == RequirementCheckResult::Failure;
40604060
}
40614061

4062-
/// When initializing Unsafe[Mutable]Pointer<T> from Unsafe[Mutable]RawPointer,
4063-
/// issue a diagnostic that refers to the API for binding memory to a type.
4064-
static bool isCastToTypedPointer(ConstraintSystem &CS, const Expr *Fn,
4065-
const Expr *Arg) {
4066-
auto &Ctx = CS.DC->getASTContext();
4067-
auto *TypeExp = dyn_cast<TypeExpr>(Fn);
4068-
auto *ParenExp = dyn_cast<ParenExpr>(Arg);
4069-
if (!TypeExp || !ParenExp)
4070-
return false;
4071-
4072-
auto InitType = CS.getInstanceType(TypeExp);
4073-
auto ArgType = CS.getType(ParenExp->getSubExpr());
4074-
if (InitType.isNull() || ArgType.isNull())
4075-
return false;
4076-
4077-
// unwrap one level of Optional
4078-
if (auto ArgOptType = ArgType->getOptionalObjectType())
4079-
ArgType = ArgOptType;
4080-
4081-
auto *InitNom = InitType->getAnyNominal();
4082-
if (!InitNom)
4083-
return false;
4084-
4085-
if (InitNom != Ctx.getUnsafeMutablePointerDecl()
4086-
&& InitNom != Ctx.getUnsafePointerDecl()) {
4087-
return false;
4088-
}
4089-
auto *ArgNom = ArgType->getAnyNominal();
4090-
if (!ArgNom)
4091-
return false;
4092-
4093-
if (ArgNom != Ctx.getUnsafeMutableRawPointerDecl()
4094-
&& ArgNom != Ctx.getUnsafeRawPointerDecl()) {
4095-
return false;
4096-
}
4097-
return true;
4098-
}
4099-
41004062
static bool diagnoseClosureExplicitParameterMismatch(
41014063
ConstraintSystem &CS, SourceLoc loc,
41024064
ArrayRef<AnyFunctionType::Param> params,
@@ -4971,11 +4933,6 @@ bool FailureDiagnosis::visitApplyExpr(ApplyExpr *callExpr) {
49714933
overloadName, argString, isInitializer);
49724934
}
49734935

4974-
if (isCastToTypedPointer(CS, fnExpr, argExpr)) {
4975-
diagnose(fnExpr->getLoc(), diag::pointer_init_to_type)
4976-
.highlight(argExpr->getSourceRange());
4977-
}
4978-
49794936
// Did the user intend on invoking a different overload?
49804937
calleeInfo.suggestPotentialOverloads(fnExpr->getLoc());
49814938
return true;

test/stdlib/UnsafePointerDiagnostics.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ func unsafePointerConversionAvailability(
6161
_ = UnsafeMutablePointer<Int>(umpi)
6262
_ = UnsafeMutablePointer<Int>(oumpi)
6363

64-
_ = UnsafeMutablePointer<Void>(rp) // expected-warning 4 {{UnsafeMutablePointer<Void> has been replaced by UnsafeMutableRawPointer}} expected-error {{cannot invoke initializer for type 'UnsafeMutablePointer<Void>' with an argument list of type '(UnsafeRawPointer)'}} expected-note {{overloads for 'UnsafeMutablePointer<Void>' exist with these partially matching parameter lists: (RawPointer), (UnsafeMutablePointer<Pointee>), (UnsafeMutablePointer<Pointee>?)}} expected-note {{Pointer conversion restricted: use '.assumingMemoryBound(to:)' or '.bindMemory(to:capacity:)' to view memory as a type.}}
65-
_ = UnsafeMutablePointer<Void>(mrp) // expected-warning 4 {{UnsafeMutablePointer<Void> has been replaced by UnsafeMutableRawPointer}} expected-error {{cannot invoke initializer for type 'UnsafeMutablePointer<Void>' with an argument list of type '(UnsafeMutableRawPointer)'}} expected-note {{overloads for 'UnsafeMutablePointer<Void>' exist with these partially matching parameter lists: (RawPointer), (UnsafeMutablePointer<Pointee>), (UnsafeMutablePointer<Pointee>?)}} expected-note {{Pointer conversion restricted: use '.assumingMemoryBound(to:)' or '.bindMemory(to:capacity:)' to view memory as a type.}}
64+
_ = UnsafeMutablePointer<Void>(rp) // expected-warning 4 {{UnsafeMutablePointer<Void> has been replaced by UnsafeMutableRawPointer}} expected-error {{cannot invoke initializer for type 'UnsafeMutablePointer<Void>' with an argument list of type '(UnsafeRawPointer)'}} expected-note {{overloads for 'UnsafeMutablePointer<Void>' exist with these partially matching parameter lists: (RawPointer), (UnsafeMutablePointer<Pointee>), (UnsafeMutablePointer<Pointee>?)}}
65+
_ = UnsafeMutablePointer<Void>(mrp) // expected-warning 4 {{UnsafeMutablePointer<Void> has been replaced by UnsafeMutableRawPointer}} expected-error {{cannot invoke initializer for type 'UnsafeMutablePointer<Void>' with an argument list of type '(UnsafeMutableRawPointer)'}} expected-note {{overloads for 'UnsafeMutablePointer<Void>' exist with these partially matching parameter lists: (RawPointer), (UnsafeMutablePointer<Pointee>), (UnsafeMutablePointer<Pointee>?)}}
6666
_ = UnsafeMutablePointer<Void>(umpv) // expected-warning {{UnsafeMutablePointer<Void> has been replaced by UnsafeMutableRawPointer}}
6767
_ = UnsafeMutablePointer<Void>(umpi) // expected-warning {{UnsafeMutablePointer<Void> has been replaced by UnsafeMutableRawPointer}}
6868
_ = UnsafeMutablePointer<Void>(umps) // expected-warning {{UnsafeMutablePointer<Void> has been replaced by UnsafeMutableRawPointer}}
@@ -76,10 +76,10 @@ func unsafePointerConversionAvailability(
7676
_ = UnsafePointer<Void>(umps) // expected-warning {{UnsafePointer<Void> has been replaced by UnsafeRawPointer}}
7777
_ = UnsafePointer<Void>(ups) // expected-warning {{UnsafePointer<Void> has been replaced by UnsafeRawPointer}}
7878

79-
_ = UnsafeMutablePointer<Int>(rp) // expected-error {{cannot invoke initializer for type 'UnsafeMutablePointer<Int>' with an argument list of type '(UnsafeRawPointer)'}} expected-note {{overloads for 'UnsafeMutablePointer<Int>' exist with these partially matching parameter lists: (RawPointer), (UnsafeMutablePointer<Pointee>), (UnsafeMutablePointer<Pointee>?)}} expected-note {{Pointer conversion restricted: use '.assumingMemoryBound(to:)' or '.bindMemory(to:capacity:)' to view memory as a type.}}
80-
_ = UnsafeMutablePointer<Int>(mrp) // expected-error {{cannot invoke initializer for type 'UnsafeMutablePointer<Int>' with an argument list of type '(UnsafeMutableRawPointer)'}} expected-note {{Pointer conversion restricted: use '.assumingMemoryBound(to:)' or '.bindMemory(to:capacity:)' to view memory as a type.}} expected-note {{overloads for 'UnsafeMutablePointer<Int>' exist with these partially matching parameter lists: (RawPointer), (UnsafeMutablePointer<Pointee>), (UnsafeMutablePointer<Pointee>?)}}
81-
_ = UnsafeMutablePointer<Int>(orp) // expected-error {{cannot invoke initializer for type 'UnsafeMutablePointer<Int>' with an argument list of type '(UnsafeRawPointer?)'}} expected-note {{overloads for 'UnsafeMutablePointer<Int>' exist with these partially matching parameter lists: (RawPointer), (UnsafeMutablePointer<Pointee>), (UnsafeMutablePointer<Pointee>?)}} expected-note {{Pointer conversion restricted: use '.assumingMemoryBound(to:)' or '.bindMemory(to:capacity:)' to view memory as a type.}}
82-
_ = UnsafeMutablePointer<Int>(omrp) // expected-error {{cannot invoke initializer for type 'UnsafeMutablePointer<Int>' with an argument list of type '(UnsafeMutableRawPointer?)'}} expected-note {{overloads for 'UnsafeMutablePointer<Int>' exist with these partially matching parameter lists: (RawPointer), (UnsafeMutablePointer<Pointee>), (UnsafeMutablePointer<Pointee>?)}} expected-note {{Pointer conversion restricted: use '.assumingMemoryBound(to:)' or '.bindMemory(to:capacity:)' to view memory as a type.}}
79+
_ = UnsafeMutablePointer<Int>(rp) // expected-error {{cannot invoke initializer for type 'UnsafeMutablePointer<Int>' with an argument list of type '(UnsafeRawPointer)'}} expected-note {{overloads for 'UnsafeMutablePointer<Int>' exist with these partially matching parameter lists: (RawPointer), (UnsafeMutablePointer<Pointee>), (UnsafeMutablePointer<Pointee>?)}}
80+
_ = UnsafeMutablePointer<Int>(mrp) // expected-error {{cannot invoke initializer for type 'UnsafeMutablePointer<Int>' with an argument list of type '(UnsafeMutableRawPointer)'}} expected-note {{overloads for 'UnsafeMutablePointer<Int>' exist with these partially matching parameter lists: (RawPointer), (UnsafeMutablePointer<Pointee>), (UnsafeMutablePointer<Pointee>?)}}
81+
_ = UnsafeMutablePointer<Int>(orp) // expected-error {{cannot invoke initializer for type 'UnsafeMutablePointer<Int>' with an argument list of type '(UnsafeRawPointer?)'}} expected-note {{overloads for 'UnsafeMutablePointer<Int>' exist with these partially matching parameter lists: (RawPointer), (UnsafeMutablePointer<Pointee>), (UnsafeMutablePointer<Pointee>?)}}
82+
_ = UnsafeMutablePointer<Int>(omrp) // expected-error {{cannot invoke initializer for type 'UnsafeMutablePointer<Int>' with an argument list of type '(UnsafeMutableRawPointer?)'}} expected-note {{overloads for 'UnsafeMutablePointer<Int>' exist with these partially matching parameter lists: (RawPointer), (UnsafeMutablePointer<Pointee>), (UnsafeMutablePointer<Pointee>?)}}
8383

8484
_ = UnsafePointer<Int>(rp) // expected-error {{cannot convert value of type 'UnsafeRawPointer' to expected argument type 'RawPointer'}}
8585
_ = UnsafePointer<Int>(mrp) // expected-error {{cannot convert value of type 'UnsafeMutableRawPointer' to expected argument type 'RawPointer'}}

0 commit comments

Comments
 (0)