diff --git a/include/swift/AST/DiagnosticsSema.def b/include/swift/AST/DiagnosticsSema.def index 2622f3a47fb3c..6e52d6c1b8ac8 100644 --- a/include/swift/AST/DiagnosticsSema.def +++ b/include/swift/AST/DiagnosticsSema.def @@ -398,22 +398,12 @@ NOTE(generic_parameter_inferred_from_result_context,none, ERROR(cannot_pass_type_to_non_ephemeral,none, "cannot pass %0 to parameter; argument %1 must be a pointer that " "outlives the call%select{| to %3}2", (Type, StringRef, bool, DeclName)) -WARNING(cannot_pass_type_to_non_ephemeral_warning,none, - "passing %0 to parameter, but argument %1 should be a pointer that " - "outlives the call%select{| to %3}2", (Type, StringRef, bool, DeclName)) ERROR(cannot_use_inout_non_ephemeral,none, "cannot use inout expression here; argument %0 must be a pointer that " "outlives the call%select{| to %2}1", (StringRef, bool, DeclName)) -WARNING(cannot_use_inout_non_ephemeral_warning,none, - "inout expression creates a temporary pointer, but argument %0 should " - "be a pointer that outlives the call%select{| to %2}1", - (StringRef, bool, DeclName)) ERROR(cannot_construct_dangling_pointer,none, "initialization of %0 results in a dangling %select{|buffer }1pointer", (Type, unsigned)) -WARNING(cannot_construct_dangling_pointer_warning,none, - "initialization of %0 results in a dangling %select{|buffer }1pointer", - (Type, unsigned)) NOTE(ephemeral_pointer_argument_conversion_note,none, "implicit argument conversion from %0 to %1 produces a pointer valid only " "for the duration of the call%select{| to %3}2", diff --git a/include/swift/AST/EducationalNotes.def b/include/swift/AST/EducationalNotes.def index bc57ec20410c0..78a331ad05afe 100644 --- a/include/swift/AST/EducationalNotes.def +++ b/include/swift/AST/EducationalNotes.def @@ -25,17 +25,9 @@ EDUCATIONAL_NOTES(could_not_use_member_on_existential, "existential-member-access-limitations.md") EDUCATIONAL_NOTES(cannot_pass_type_to_non_ephemeral, "temporary-pointers.md") -EDUCATIONAL_NOTES(cannot_pass_type_to_non_ephemeral_warning, - "temporary-pointers.md") EDUCATIONAL_NOTES(cannot_use_inout_non_ephemeral, "temporary-pointers.md") -EDUCATIONAL_NOTES(cannot_use_inout_non_ephemeral_warning, - "temporary-pointers.md") EDUCATIONAL_NOTES(cannot_construct_dangling_pointer, "temporary-pointers.md") -EDUCATIONAL_NOTES(cannot_construct_dangling_pointer_warning, - "temporary-pointers.md") - - EDUCATIONAL_NOTES(non_nominal_no_initializers, "nominal-types.md") EDUCATIONAL_NOTES(non_nominal_extension, "nominal-types.md") diff --git a/include/swift/Sema/CSFix.h b/include/swift/Sema/CSFix.h index b65ed6013a316..f776d83d062ba 100644 --- a/include/swift/Sema/CSFix.h +++ b/include/swift/Sema/CSFix.h @@ -650,9 +650,9 @@ class ContextualMismatch : public ConstraintFix { Type LHS, RHS; ContextualMismatch(ConstraintSystem &cs, Type lhs, Type rhs, - ConstraintLocator *locator) - : ConstraintFix(cs, FixKind::ContextualMismatch, locator), LHS(lhs), - RHS(rhs) {} + ConstraintLocator *locator, bool warning) + : ConstraintFix(cs, FixKind::ContextualMismatch, locator, warning), + LHS(lhs), RHS(rhs) {} protected: ContextualMismatch(ConstraintSystem &cs, FixKind kind, Type lhs, Type rhs, @@ -741,9 +741,9 @@ class MarkExplicitlyEscaping final : public ContextualMismatch { /// Mark function type as being part of a global actor. class MarkGlobalActorFunction final : public ContextualMismatch { MarkGlobalActorFunction(ConstraintSystem &cs, Type lhs, Type rhs, - ConstraintLocator *locator) + ConstraintLocator *locator, bool warning) : ContextualMismatch(cs, FixKind::MarkGlobalActorFunction, lhs, rhs, - locator) { + locator, warning) { } public: @@ -752,7 +752,8 @@ class MarkGlobalActorFunction final : public ContextualMismatch { bool diagnose(const Solution &solution, bool asNote = false) const override; static MarkGlobalActorFunction *create(ConstraintSystem &cs, Type lhs, - Type rhs, ConstraintLocator *locator); + Type rhs, ConstraintLocator *locator, + bool warning); static bool classof(ConstraintFix *fix) { return fix->getKind() == FixKind::MarkGlobalActorFunction; @@ -787,9 +788,10 @@ class ForceOptional final : public ContextualMismatch { /// function types, repair it by adding @Sendable attribute. class AddSendableAttribute final : public ContextualMismatch { AddSendableAttribute(ConstraintSystem &cs, FunctionType *fromType, - FunctionType *toType, ConstraintLocator *locator) + FunctionType *toType, ConstraintLocator *locator, + bool warning) : ContextualMismatch(cs, FixKind::AddSendableAttribute, fromType, toType, - locator) { + locator, warning) { assert(fromType->isSendable() != toType->isSendable()); } @@ -801,7 +803,8 @@ class AddSendableAttribute final : public ContextualMismatch { static AddSendableAttribute *create(ConstraintSystem &cs, FunctionType *fromType, FunctionType *toType, - ConstraintLocator *locator); + ConstraintLocator *locator, + bool warning); static bool classof(ConstraintFix *fix) { return fix->getKind() == FixKind::AddSendableAttribute; diff --git a/lib/Sema/CSDiagnostics.cpp b/lib/Sema/CSDiagnostics.cpp index 5190650f8a651..0b13a8408531a 100644 --- a/lib/Sema/CSDiagnostics.cpp +++ b/lib/Sema/CSDiagnostics.cpp @@ -102,7 +102,10 @@ template InFlightDiagnostic FailureDiagnostic::emitDiagnosticAt(ArgTypes &&... Args) const { auto &DE = getASTContext().Diags; - return DE.diagnose(std::forward(Args)...); + auto behavior = isWarning ? DiagnosticBehavior::Warning + : DiagnosticBehavior::Unspecified; + return std::move(DE.diagnose(std::forward(Args)...) + .limitBehavior(behavior)); } Expr *FailureDiagnostic::findParentExpr(const Expr *subExpr) const { @@ -6779,12 +6782,9 @@ bool NonEphemeralConversionFailure::diagnosePointerInit() const { return false; } - auto diagID = DowngradeToWarning - ? diag::cannot_construct_dangling_pointer_warning - : diag::cannot_construct_dangling_pointer; - auto anchor = getRawAnchor(); - emitDiagnosticAt(::getLoc(anchor), diagID, constructedTy, constructorKind) + emitDiagnosticAt(::getLoc(anchor), diag::cannot_construct_dangling_pointer, + constructedTy, constructorKind) .highlight(::getSourceRange(anchor)); emitSuggestionNotes(); @@ -6814,20 +6814,12 @@ bool NonEphemeralConversionFailure::diagnoseAsError() { auto *argExpr = getArgExpr(); if (isa(argExpr)) { - auto diagID = DowngradeToWarning - ? diag::cannot_use_inout_non_ephemeral_warning - : diag::cannot_use_inout_non_ephemeral; - - emitDiagnosticAt(argExpr->getLoc(), diagID, argDesc, getCallee(), - getCalleeFullName()) + emitDiagnosticAt(argExpr->getLoc(), diag::cannot_use_inout_non_ephemeral, + argDesc, getCallee(), getCalleeFullName()) .highlight(argExpr->getSourceRange()); } else { - auto diagID = DowngradeToWarning - ? diag::cannot_pass_type_to_non_ephemeral_warning - : diag::cannot_pass_type_to_non_ephemeral; - - emitDiagnosticAt(argExpr->getLoc(), diagID, getArgType(), argDesc, - getCallee(), getCalleeFullName()) + emitDiagnosticAt(argExpr->getLoc(), diag::cannot_pass_type_to_non_ephemeral, + getArgType(), argDesc, getCallee(), getCalleeFullName()) .highlight(argExpr->getSourceRange()); } emitSuggestionNotes(); diff --git a/lib/Sema/CSDiagnostics.h b/lib/Sema/CSDiagnostics.h index 9036eb024fd1c..3c7b1c5619b97 100644 --- a/lib/Sema/CSDiagnostics.h +++ b/lib/Sema/CSDiagnostics.h @@ -42,13 +42,17 @@ class FunctionArgApplyInfo; class FailureDiagnostic { const Solution &S; ConstraintLocator *Locator; + bool isWarning; public: - FailureDiagnostic(const Solution &solution, ConstraintLocator *locator) - : S(solution), Locator(locator) {} + FailureDiagnostic(const Solution &solution, ConstraintLocator *locator, + bool isWarning = false) + : S(solution), Locator(locator), isWarning(isWarning) {} - FailureDiagnostic(const Solution &solution, ASTNode anchor) - : FailureDiagnostic(solution, solution.getConstraintLocator(anchor)) {} + FailureDiagnostic(const Solution &solution, ASTNode anchor, + bool isWarning = false) + : FailureDiagnostic(solution, solution.getConstraintLocator(anchor), + isWarning) { } virtual ~FailureDiagnostic(); @@ -601,7 +605,7 @@ class ContextualFailure : public FailureDiagnostic { public: ContextualFailure(const Solution &solution, Type lhs, Type rhs, - ConstraintLocator *locator) + ConstraintLocator *locator, bool isWarning = false) : ContextualFailure( solution, locator->isForContextualType() @@ -609,12 +613,13 @@ class ContextualFailure : public FailureDiagnostic { .getPurpose() : solution.getConstraintSystem().getContextualTypePurpose( locator->getAnchor()), - lhs, rhs, locator) {} + lhs, rhs, locator, isWarning) {} ContextualFailure(const Solution &solution, ContextualTypePurpose purpose, - Type lhs, Type rhs, ConstraintLocator *locator) - : FailureDiagnostic(solution, locator), CTP(purpose), RawFromType(lhs), - RawToType(rhs) { + Type lhs, Type rhs, ConstraintLocator *locator, + bool isWarning = false) + : FailureDiagnostic(solution, locator, isWarning), CTP(purpose), + RawFromType(lhs), RawToType(rhs) { assert(lhs && "Expected a valid 'from' type"); assert(rhs && "Expected a valid 'to' type"); } @@ -753,8 +758,9 @@ class AttributedFuncToTypeConversionFailure final : public ContextualFailure { AttributedFuncToTypeConversionFailure(const Solution &solution, Type fromType, Type toType, ConstraintLocator *locator, - AttributeKind attributeKind) - : ContextualFailure(solution, fromType, toType, locator), + AttributeKind attributeKind, + bool isWarning = false) + : ContextualFailure(solution, fromType, toType, locator, isWarning), attributeKind(attributeKind) {} bool diagnoseAsError() override; @@ -777,8 +783,9 @@ class AttributedFuncToTypeConversionFailure final : public ContextualFailure { class DroppedGlobalActorFunctionAttr final : public ContextualFailure { public: DroppedGlobalActorFunctionAttr(const Solution &solution, Type fromType, - Type toType, ConstraintLocator *locator) - : ContextualFailure(solution, fromType, toType, locator) {} + Type toType, ConstraintLocator *locator, + bool isWarning) + : ContextualFailure(solution, fromType, toType, locator, isWarning) { } bool diagnoseAsError() override; }; @@ -1942,8 +1949,9 @@ class ArgumentMismatchFailure : public ContextualFailure { public: ArgumentMismatchFailure(const Solution &solution, Type argType, - Type paramType, ConstraintLocator *locator) - : ContextualFailure(solution, argType, paramType, locator), + Type paramType, ConstraintLocator *locator, + bool warning = false) + : ContextualFailure(solution, argType, paramType, locator, warning), Info(*getFunctionArgApplyInfo(getLocator())) {} bool diagnoseAsError() override; @@ -2112,16 +2120,15 @@ class InvalidUseOfTrailingClosure final : public ArgumentMismatchFailure { /// ``` class NonEphemeralConversionFailure final : public ArgumentMismatchFailure { ConversionRestrictionKind ConversionKind; - bool DowngradeToWarning; public: NonEphemeralConversionFailure(const Solution &solution, ConstraintLocator *locator, Type fromType, Type toType, ConversionRestrictionKind conversionKind, - bool downgradeToWarning) - : ArgumentMismatchFailure(solution, fromType, toType, locator), - ConversionKind(conversionKind), DowngradeToWarning(downgradeToWarning) { + bool warning) + : ArgumentMismatchFailure(solution, fromType, toType, locator, warning), + ConversionKind(conversionKind) { } bool diagnoseAsError() override; diff --git a/lib/Sema/CSFix.cpp b/lib/Sema/CSFix.cpp index a2a0e7675ad82..155bc2621020e 100644 --- a/lib/Sema/CSFix.cpp +++ b/lib/Sema/CSFix.cpp @@ -201,39 +201,41 @@ MarkExplicitlyEscaping::create(ConstraintSystem &cs, Type lhs, Type rhs, bool MarkGlobalActorFunction::diagnose(const Solution &solution, bool asNote) const { DroppedGlobalActorFunctionAttr failure( - solution, getFromType(), getToType(), getLocator()); + solution, getFromType(), getToType(), getLocator(), isWarning()); return failure.diagnose(asNote); } MarkGlobalActorFunction * MarkGlobalActorFunction::create(ConstraintSystem &cs, Type lhs, Type rhs, - ConstraintLocator *locator) { + ConstraintLocator *locator, bool warning) { if (locator->isLastElement()) locator = cs.getConstraintLocator( locator, LocatorPathElt::ArgumentAttribute::forGlobalActor()); - return new (cs.getAllocator()) MarkGlobalActorFunction(cs, lhs, rhs, locator); + return new (cs.getAllocator()) MarkGlobalActorFunction( + cs, lhs, rhs, locator, warning); } bool AddSendableAttribute::diagnose(const Solution &solution, bool asNote) const { AttributedFuncToTypeConversionFailure failure( solution, getFromType(), getToType(), getLocator(), - AttributedFuncToTypeConversionFailure::Concurrent); + AttributedFuncToTypeConversionFailure::Concurrent, isWarning()); return failure.diagnose(asNote); } AddSendableAttribute * AddSendableAttribute::create(ConstraintSystem &cs, - FunctionType *fromType, - FunctionType *toType, - ConstraintLocator *locator) { + FunctionType *fromType, + FunctionType *toType, + ConstraintLocator *locator, + bool warning) { if (locator->isLastElement()) locator = cs.getConstraintLocator( locator, LocatorPathElt::ArgumentAttribute::forConcurrent()); return new (cs.getAllocator()) AddSendableAttribute( - cs, fromType, toType, locator); + cs, fromType, toType, locator, warning); } bool RelabelArguments::diagnose(const Solution &solution, bool asNote) const { LabelingFailure failure(solution, getLocator(), getLabels()); @@ -369,7 +371,8 @@ bool ContextualMismatch::diagnoseForAmbiguity( ContextualMismatch *ContextualMismatch::create(ConstraintSystem &cs, Type lhs, Type rhs, ConstraintLocator *locator) { - return new (cs.getAllocator()) ContextualMismatch(cs, lhs, rhs, locator); + return new (cs.getAllocator()) ContextualMismatch( + cs, lhs, rhs, locator, /*warning=*/false); } bool AllowWrappedValueMismatch::diagnose(const Solution &solution, bool asError) const { diff --git a/lib/Sema/CSSimplify.cpp b/lib/Sema/CSSimplify.cpp index b22bee0497543..40f6f15d2bca5 100644 --- a/lib/Sema/CSSimplify.cpp +++ b/lib/Sema/CSSimplify.cpp @@ -16,6 +16,7 @@ //===----------------------------------------------------------------------===// #include "CSDiagnostics.h" +#include "TypeCheckConcurrency.h" #include "swift/AST/ASTPrinter.h" #include "swift/AST/Decl.h" #include "swift/AST/ExistentialLayout.h" @@ -2170,6 +2171,22 @@ ConstraintSystem::matchFunctionTypes(FunctionType *func1, FunctionType *func2, increaseScore(SK_SyncInAsync); } + /// Whether to downgrade to a concurrency warning. + auto isConcurrencyWarning = [&] { + if (contextUsesConcurrencyFeatures(DC) || + Context.LangOpts.isSwiftVersionAtLeast(6)) + return false; + + switch (kind) { + case ConstraintKind::Conversion: + case ConstraintKind::ArgumentConversion: + return true; + + default: + return false; + } + }; + // A @Sendable function can be a subtype of a non-@Sendable function. if (func1->isSendable() != func2->isSendable()) { // Cannot add '@Sendable'. @@ -2178,7 +2195,8 @@ ConstraintSystem::matchFunctionTypes(FunctionType *func1, FunctionType *func2, return getTypeMatchFailure(locator); auto *fix = AddSendableAttribute::create( - *this, func1, func2, getConstraintLocator(locator)); + *this, func1, func2, getConstraintLocator(locator), + isConcurrencyWarning()); if (recordFix(fix)) return getTypeMatchFailure(locator); } @@ -2212,7 +2230,8 @@ ConstraintSystem::matchFunctionTypes(FunctionType *func1, FunctionType *func2, return getTypeMatchFailure(locator); auto *fix = MarkGlobalActorFunction::create( - *this, func1, func2, getConstraintLocator(locator)); + *this, func1, func2, getConstraintLocator(locator), + isConcurrencyWarning()); if (recordFix(fix)) return getTypeMatchFailure(locator); diff --git a/test/Concurrency/actor_isolation.swift b/test/Concurrency/actor_isolation.swift index 5bb2d157b9020..e25e42f69814a 100644 --- a/test/Concurrency/actor_isolation.swift +++ b/test/Concurrency/actor_isolation.swift @@ -403,7 +403,7 @@ func testGlobalActorClosures() { return 17 } - acceptConcurrentClosure { @SomeGlobalActor in 5 } // expected-error{{converting function value of type '@SomeGlobalActor @Sendable () -> Int' to '@Sendable () -> Int' loses global actor 'SomeGlobalActor'}} + acceptConcurrentClosure { @SomeGlobalActor in 5 } // expected-warning{{converting function value of type '@SomeGlobalActor @Sendable () -> Int' to '@Sendable () -> Int' loses global actor 'SomeGlobalActor'}} } @available(SwiftStdlib 5.1, *) diff --git a/test/Concurrency/global_actor_function_types.swift b/test/Concurrency/global_actor_function_types.swift index a42cfad34a65e..12e765e2d4410 100644 --- a/test/Concurrency/global_actor_function_types.swift +++ b/test/Concurrency/global_actor_function_types.swift @@ -16,7 +16,7 @@ struct OtherGlobalActor { func testConversions(f: @escaping @SomeGlobalActor (Int) -> Void, g: @escaping (Int) -> Void) { let _: Int = f // expected-error{{cannot convert value of type '@SomeGlobalActor (Int) -> Void' to specified type 'Int'}} - let _: (Int) -> Void = f // expected-error{{converting function value of type '@SomeGlobalActor (Int) -> Void' to '(Int) -> Void' loses global actor 'SomeGlobalActor'}} + let _: (Int) -> Void = f // expected-warning{{converting function value of type '@SomeGlobalActor (Int) -> Void' to '(Int) -> Void' loses global actor 'SomeGlobalActor'}} let _: @SomeGlobalActor (Int) -> Void = g // okay // FIXME: this could be better. @@ -119,7 +119,7 @@ func testTypesNonConcurrencyContext() { // expected-note{{add '@SomeGlobalActor' let f1 = onSomeGlobalActor // expected-note{{calls to let 'f1' from outside of its actor context are implicitly asynchronous}} let f2 = onSomeGlobalActorUnsafe - let _: () -> Int = f1 // expected-error{{converting function value of type '@SomeGlobalActor () -> Int' to '() -> Int' loses global actor 'SomeGlobalActor'}} + let _: () -> Int = f1 // expected-warning{{converting function value of type '@SomeGlobalActor () -> Int' to '() -> Int' loses global actor 'SomeGlobalActor'}} let _: () -> Int = f2 _ = f1() // expected-error{{call to global actor 'SomeGlobalActor'-isolated let 'f1' in a synchronous nonisolated context}} diff --git a/test/Concurrency/sendable_checking.swift b/test/Concurrency/sendable_checking.swift index f8ffa94474520..ef746b65a7c69 100644 --- a/test/Concurrency/sendable_checking.swift +++ b/test/Concurrency/sendable_checking.swift @@ -24,19 +24,32 @@ extension NS3: Sendable { } @available(SwiftStdlib 5.1, *) func acceptCV(_: T) { } +func acceptSendableFn(_: @Sendable @escaping () -> Void) { } + @available(SwiftStdlib 5.1, *) -func testCV(ns1: NS1, ns1array: [NS1], ns2: NS2, ns3: NS3) { +func testCV( + ns1: NS1, ns1array: [NS1], ns2: NS2, ns3: NS3, fn: @escaping () -> Void + // expected-note@-1{{parameter 'fn' is implicitly non-sendable}} +) { acceptCV(ns1) acceptCV(ns1array) acceptCV(ns2) acceptCV(ns3) + acceptCV(fn) + acceptSendableFn(fn) // expected-warning{{passing non-sendable parameter 'fn' to function expecting a @Sendable closure}} } @available(SwiftStdlib 5.1, *) -func testCV(ns1: NS1, ns1array: [NS1], ns2: NS2, ns3: NS3) async { +func testCV( + ns1: NS1, ns1array: [NS1], ns2: NS2, ns3: NS3, fn: @escaping () -> Void + // expected-note@-1{{parameter 'fn' is implicitly non-sendable}} +) async { acceptCV(ns1) // expected-warning{{conformance of 'NS1' to 'Sendable' is unavailable}} acceptCV(ns1array) // expected-warning{{conformance of 'NS1' to 'Sendable' is unavailable}} acceptCV(ns2) // expected-warning{{type 'NS2' does not conform to the 'Sendable' protocol}} acceptCV(ns3) // expected-warning{{conformance of 'NS3' to 'Sendable' is only available in macOS 11.0 or newer}} // expected-note@-1{{add 'if #available' version check}} + acceptCV(fn) // expected-warning{{type '() -> Void' does not conform to the 'Sendable' protocol}} + // expected-note@-1{{a function type must be marked '@Sendable' to conform to 'Sendable'}} + acceptSendableFn(fn) // expected-error{{passing non-sendable parameter 'fn' to function expecting a @Sendable closure}} } diff --git a/test/IDE/newtype.swift b/test/IDE/newtype.swift index 876784ca6b1f2..08945a1cd44cb 100644 --- a/test/IDE/newtype.swift +++ b/test/IDE/newtype.swift @@ -238,19 +238,19 @@ func testFixit() { func testNonEphemeralInitParams(x: OpaquePointer) { var x = x - _ = TRefRef(&x) // expected-warning {{inout expression creates a temporary pointer, but argument #1 should be a pointer that outlives the call to 'init(_:)'}} + _ = TRefRef(&x) // expected-warning {{argument #1 must be a pointer that outlives the call to 'init(_:)'}} // expected-note@-1 {{implicit argument conversion from 'OpaquePointer' to 'UnsafeMutablePointer' produces a pointer valid only for the duration of the call}} // expected-note@-2 {{use 'withUnsafeMutablePointer' in order to explicitly convert argument to pointer valid for a defined scope}} - _ = TRefRef(rawValue: &x) // expected-warning {{inout expression creates a temporary pointer, but argument 'rawValue' should be a pointer that outlives the call to 'init(rawValue:)'}} + _ = TRefRef(rawValue: &x) // expected-warning {{argument 'rawValue' must be a pointer that outlives the call to 'init(rawValue:)'}} // expected-note@-1 {{implicit argument conversion from 'OpaquePointer' to 'UnsafeMutablePointer' produces a pointer valid only for the duration of the call}} // expected-note@-2 {{use 'withUnsafeMutablePointer' in order to explicitly convert argument to pointer valid for a defined scope}} - _ = ConstTRefRef(&x) // expected-warning {{inout expression creates a temporary pointer, but argument #1 should be a pointer that outlives the call to 'init(_:)'}} + _ = ConstTRefRef(&x) // expected-warning {{argument #1 must be a pointer that outlives the call to 'init(_:)'}} // expected-note@-1 {{implicit argument conversion from 'OpaquePointer' to 'UnsafePointer' produces a pointer valid only for the duration of the call}} // expected-note@-2 {{use 'withUnsafePointer' in order to explicitly convert argument to pointer valid for a defined scope}} - _ = ConstTRefRef(rawValue: &x) // expected-warning {{inout expression creates a temporary pointer, but argument 'rawValue' should be a pointer that outlives the call to 'init(rawValue:)'}} + _ = ConstTRefRef(rawValue: &x) // expected-warning {{argument 'rawValue' must be a pointer that outlives the call to 'init(rawValue:)'}} // expected-note@-1 {{implicit argument conversion from 'OpaquePointer' to 'UnsafePointer' produces a pointer valid only for the duration of the call}} // expected-note@-2 {{use 'withUnsafePointer' in order to explicitly convert argument to pointer valid for a defined scope}} } diff --git a/test/Sema/diag_non_ephemeral_warning.swift b/test/Sema/diag_non_ephemeral_warning.swift index 11c9a4cfe6583..09fcf2ff01dfa 100644 --- a/test/Sema/diag_non_ephemeral_warning.swift +++ b/test/Sema/diag_non_ephemeral_warning.swift @@ -23,45 +23,45 @@ var optionalArr: [Int8]? // We cannot use array-to-pointer and string-to-pointer conversions with // non-ephemeral parameters. -takesMutableRaw(&arr, 5) // expected-warning {{inout expression creates a temporary pointer, but argument #1 should be a pointer that outlives the call to 'takesMutableRaw'}} +takesMutableRaw(&arr, 5) // expected-warning {{cannot use inout expression here; argument #1 must be a pointer that outlives the call to 'takesMutableRaw'}} // expected-note@-1 {{implicit argument conversion from '[Int8]' to 'UnsafeMutableRawPointer' produces a pointer valid only for the duration of the call to 'takesMutableRaw'}} // expected-note@-2 {{use the 'withUnsafeMutableBytes' method on Array in order to explicitly convert argument to buffer pointer valid for a defined scope}} -takesConst(str, 5) // expected-warning {{passing 'String' to parameter, but argument #1 should be a pointer that outlives the call to 'takesConst'}} +takesConst(str, 5) // expected-warning {{cannot pass 'String' to parameter; argument #1 must be a pointer that outlives the call to 'takesConst'}} // expected-note@-1 {{implicit argument conversion from 'String' to 'UnsafePointer' produces a pointer valid only for the duration of the call to 'takesConst'}} // expected-note@-2 {{use the 'withCString' method on String in order to explicitly convert argument to pointer valid for a defined scope}} -takesConst(arr, 5) // expected-warning {{passing '[Int8]' to parameter, but argument #1 should be a pointer that outlives the call to 'takesConst'}} +takesConst(arr, 5) // expected-warning {{cannot pass '[Int8]' to parameter; argument #1 must be a pointer that outlives the call to 'takesConst'}} // expected-note@-1 {{implicit argument conversion from '[Int8]' to 'UnsafePointer' produces a pointer valid only for the duration of the call to 'takesConst'}} // expected-note@-2 {{use the 'withUnsafeBufferPointer' method on Array in order to explicitly convert argument to buffer pointer valid for a defined scope}} -takesRaw(&arr) // expected-warning {{inout expression creates a temporary pointer, but argument #1 should be a pointer that outlives the call to 'takesRaw'}} +takesRaw(&arr) // expected-warning {{cannot use inout expression here; argument #1 must be a pointer that outlives the call to 'takesRaw'}} // expected-note@-1 {{implicit argument conversion from '[Int8]' to 'UnsafeRawPointer' produces a pointer valid only for the duration of the call to 'takesRaw'}} // expected-note@-2 {{use the 'withUnsafeBytes' method on Array in order to explicitly convert argument to buffer pointer valid for a defined scope}} -takesMutable(&arr) // expected-warning {{inout expression creates a temporary pointer, but argument #1 should be a pointer that outlives the call to 'takesMutable'}} +takesMutable(&arr) // expected-warning {{cannot use inout expression here; argument #1 must be a pointer that outlives the call to 'takesMutable'}} // expected-note@-1 {{implicit argument conversion from '[Int8]' to 'UnsafeMutablePointer' produces a pointer valid only for the duration of the call to 'takesMutable'}} // expected-note@-2 {{use the 'withUnsafeMutableBufferPointer' method on Array in order to explicitly convert argument to buffer pointer valid for a defined scope}} -takesOptMutableRaw(&arr) // expected-warning {{inout expression creates a temporary pointer, but argument #1 should be a pointer that outlives the call to 'takesOptMutableRaw'}} +takesOptMutableRaw(&arr) // expected-warning {{cannot use inout expression here; argument #1 must be a pointer that outlives the call to 'takesOptMutableRaw'}} // expected-note@-1 {{implicit argument conversion from '[Int8]' to 'UnsafeMutableRawPointer?' produces a pointer valid only for the duration of the call to 'takesOptMutableRaw'}} // expected-note@-2 {{use the 'withUnsafeMutableBytes' method on Array in order to explicitly convert argument to buffer pointer valid for a defined scope}} // FIXME(SR-9100): This currently uses inout-to-pointer instead of array-to-pointer. takesOptMutableRaw(&optionalArr) -takesOptConst(arr) // expected-warning {{passing '[Int8]' to parameter, but argument #1 should be a pointer that outlives the call to 'takesOptConst'}} +takesOptConst(arr) // expected-warning {{cannot pass '[Int8]' to parameter; argument #1 must be a pointer that outlives the call to 'takesOptConst'}} // expected-note@-1 {{implicit argument conversion from '[Int8]' to 'UnsafePointer?' produces a pointer valid only for the duration of the call to 'takesOptConst'}} // expected-note@-2 {{use the 'withUnsafeBufferPointer' method on Array in order to explicitly convert argument to buffer pointer valid for a defined scope}} -takesOptConst(optionalArr) // expected-warning {{passing '[Int8]?' to parameter, but argument #1 should be a pointer that outlives the call to 'takesOptConst'}} +takesOptConst(optionalArr) // expected-warning {{cannot pass '[Int8]?' to parameter; argument #1 must be a pointer that outlives the call to 'takesOptConst'}} // expected-note@-1 {{implicit argument conversion from '[Int8]?' to 'UnsafePointer?' produces a pointer valid only for the duration of the call to 'takesOptConst'}} -takesOptConst(str) // expected-warning {{passing 'String' to parameter, but argument #1 should be a pointer that outlives the call to 'takesOptConst'}} +takesOptConst(str) // expected-warning {{cannot pass 'String' to parameter; argument #1 must be a pointer that outlives the call to 'takesOptConst'}} // expected-note@-1 {{implicit argument conversion from 'String' to 'UnsafePointer?' produces a pointer valid only for the duration of the call to 'takesOptConst'}} // expected-note@-2 {{use the 'withCString' method on String in order to explicitly convert argument to pointer valid for a defined scope}} -takesOptConst(optionalStr) // expected-warning {{passing 'String?' to parameter, but argument #1 should be a pointer that outlives the call to 'takesOptConst'}} +takesOptConst(optionalStr) // expected-warning {{cannot pass 'String?' to parameter; argument #1 must be a pointer that outlives the call to 'takesOptConst'}} // expected-note@-1 {{implicit argument conversion from 'String?' to 'UnsafePointer?' produces a pointer valid only for the duration of the call to 'takesOptConst'}} struct S { @@ -171,29 +171,29 @@ takesRaw(&topLevelOptOfResilientS!) // But we cannot do the same for: // - Class bases -takesMutableRaw(&topLevelC.storedProperty, 5) // expected-warning {{inout expression creates a temporary pointer, but argument #1 should be a pointer that outlives the call to 'takesMutableRaw'}} +takesMutableRaw(&topLevelC.storedProperty, 5) // expected-warning {{cannot use inout expression here; argument #1 must be a pointer that outlives the call to 'takesMutableRaw'}} // expected-note@-1 {{implicit argument conversion from 'Int8' to 'UnsafeMutableRawPointer' produces a pointer valid only for the duration of the call to 'takesMutableRaw'}} // expected-note@-2 {{use 'withUnsafeMutableBytes' in order to explicitly convert argument to buffer pointer valid for a defined scope}} -takesMutableRaw(&topLevelFinalC.storedProperty, 5) // expected-warning {{inout expression creates a temporary pointer, but argument #1 should be a pointer that outlives the call to 'takesMutableRaw'}} +takesMutableRaw(&topLevelFinalC.storedProperty, 5) // expected-warning {{cannot use inout expression here; argument #1 must be a pointer that outlives the call to 'takesMutableRaw'}} // expected-note@-1 {{implicit argument conversion from 'Int8' to 'UnsafeMutableRawPointer' produces a pointer valid only for the duration of the call to 'takesMutableRaw'}} // expected-note@-2 {{use 'withUnsafeMutableBytes' in order to explicitly convert argument to buffer pointer valid for a defined scope}} -takesMutableRaw(&topLevelFragileFinalC.storedProperty, 5) // expected-warning {{inout expression creates a temporary pointer, but argument #1 should be a pointer that outlives the call to 'takesMutableRaw'}} +takesMutableRaw(&topLevelFragileFinalC.storedProperty, 5) // expected-warning {{cannot use inout expression here; argument #1 must be a pointer that outlives the call to 'takesMutableRaw'}} // expected-note@-1 {{implicit argument conversion from 'Int8' to 'UnsafeMutableRawPointer' produces a pointer valid only for the duration of the call to 'takesMutableRaw'}} // expected-note@-2 {{use 'withUnsafeMutableBytes' in order to explicitly convert argument to buffer pointer valid for a defined scope}} -takesMutableRaw(&topLevelS.storedFinalC.storedProperty, 5) // expected-warning {{inout expression creates a temporary pointer, but argument #1 should be a pointer that outlives the call to 'takesMutableRaw'}} +takesMutableRaw(&topLevelS.storedFinalC.storedProperty, 5) // expected-warning {{cannot use inout expression here; argument #1 must be a pointer that outlives the call to 'takesMutableRaw'}} // expected-note@-1 {{implicit argument conversion from 'Int8' to 'UnsafeMutableRawPointer' produces a pointer valid only for the duration of the call to 'takesMutableRaw'}} // expected-note@-2 {{use 'withUnsafeMutableBytes' in order to explicitly convert argument to buffer pointer valid for a defined scope}} // - Resilient global or static variables -takesMutableRaw(&globalResilient, 5) // expected-warning {{inout expression creates a temporary pointer, but argument #1 should be a pointer that outlives the call to 'takesMutableRaw'}} +takesMutableRaw(&globalResilient, 5) // expected-warning {{cannot use inout expression here; argument #1 must be a pointer that outlives the call to 'takesMutableRaw'}} // expected-note@-1 {{implicit argument conversion from 'Int8' to 'UnsafeMutableRawPointer' produces a pointer valid only for the duration of the call to 'takesMutableRaw'}} // expected-note@-2 {{use 'withUnsafeMutableBytes' in order to explicitly convert argument to buffer pointer valid for a defined scope}} -takesMutableRaw(&ResilientStruct.staticStoredProperty, 5) // expected-warning {{inout expression creates a temporary pointer, but argument #1 should be a pointer that outlives the call to 'takesMutableRaw'}} +takesMutableRaw(&ResilientStruct.staticStoredProperty, 5) // expected-warning {{cannot use inout expression here; argument #1 must be a pointer that outlives the call to 'takesMutableRaw'}} // expected-note@-1 {{implicit argument conversion from 'Int8' to 'UnsafeMutableRawPointer' produces a pointer valid only for the duration of the call to 'takesMutableRaw'}} // expected-note@-2 {{use 'withUnsafeMutableBytes' in order to explicitly convert argument to buffer pointer valid for a defined scope}} @@ -202,86 +202,86 @@ takesMutableRaw(&type(of: topLevelResilientS).staticStoredProperty, 5) // - Resilient struct or class bases -takesMutableRaw(&topLevelResilientS.storedProperty, 5) // expected-warning {{inout expression creates a temporary pointer, but argument #1 should be a pointer that outlives the call to 'takesMutableRaw'}} +takesMutableRaw(&topLevelResilientS.storedProperty, 5) // expected-warning {{cannot use inout expression here; argument #1 must be a pointer that outlives the call to 'takesMutableRaw'}} // expected-note@-1 {{implicit argument conversion from 'Int8' to 'UnsafeMutableRawPointer' produces a pointer valid only for the duration of the call to 'takesMutableRaw'}} // expected-note@-2 {{use 'withUnsafeMutableBytes' in order to explicitly convert argument to buffer pointer valid for a defined scope}} -takesMutableRaw(&topLevelResilientFinalC.storedProperty, 5) // expected-warning {{inout expression creates a temporary pointer, but argument #1 should be a pointer that outlives the call to 'takesMutableRaw'}} +takesMutableRaw(&topLevelResilientFinalC.storedProperty, 5) // expected-warning {{cannot use inout expression here; argument #1 must be a pointer that outlives the call to 'takesMutableRaw'}} // expected-note@-1 {{implicit argument conversion from 'Int8' to 'UnsafeMutableRawPointer' produces a pointer valid only for the duration of the call to 'takesMutableRaw'}} // expected-note@-2 {{use 'withUnsafeMutableBytes' in order to explicitly convert argument to buffer pointer valid for a defined scope}} -takesMutableRaw(&topLevelOptOfResilientS!.storedProperty, 5) // expected-warning {{inout expression creates a temporary pointer, but argument #1 should be a pointer that outlives the call to 'takesMutableRaw'}} +takesMutableRaw(&topLevelOptOfResilientS!.storedProperty, 5) // expected-warning {{cannot use inout expression here; argument #1 must be a pointer that outlives the call to 'takesMutableRaw'}} // expected-note@-1 {{implicit argument conversion from 'Int8' to 'UnsafeMutableRawPointer' produces a pointer valid only for the duration of the call to 'takesMutableRaw'}} // expected-note@-2 {{use 'withUnsafeMutableBytes' in order to explicitly convert argument to buffer pointer valid for a defined scope}} // - Protocol bases -takesRaw(&topLevelP.property) // expected-warning {{inout expression creates a temporary pointer, but argument #1 should be a pointer that outlives the call to 'takesRaw'}} +takesRaw(&topLevelP.property) // expected-warning {{cannot use inout expression here; argument #1 must be a pointer that outlives the call to 'takesRaw'}} // expected-note@-1 {{implicit argument conversion from 'Int8' to 'UnsafeRawPointer' produces a pointer valid only for the duration of the call to 'takesRaw'}} // expected-note@-2 {{use 'withUnsafeBytes' in order to explicitly convert argument to buffer pointer valid for a defined scope}} // FIXME: This should also produce a warning. takesRaw(&type(of: topLevelP).staticProperty) -takesRaw(&topLevelP[]) // expected-warning {{inout expression creates a temporary pointer, but argument #1 should be a pointer that outlives the call to 'takesRaw'}} +takesRaw(&topLevelP[]) // expected-warning {{cannot use inout expression here; argument #1 must be a pointer that outlives the call to 'takesRaw'}} // expected-note@-1 {{implicit argument conversion from 'Int8' to 'UnsafeRawPointer' produces a pointer valid only for the duration of the call to 'takesRaw'}} // expected-note@-2 {{use 'withUnsafeBytes' in order to explicitly convert argument to buffer pointer valid for a defined scope}} // - Properties with observers -takesRaw(&topLevelWithObservers) // expected-warning {{inout expression creates a temporary pointer, but argument #1 should be a pointer that outlives the call to 'takesRaw'}} +takesRaw(&topLevelWithObservers) // expected-warning {{cannot use inout expression here; argument #1 must be a pointer that outlives the call to 'takesRaw'}} // expected-note@-1 {{implicit argument conversion from 'Int8' to 'UnsafeRawPointer' produces a pointer valid only for the duration of the call to 'takesRaw'}} // expected-note@-2 {{use 'withUnsafeBytes' in order to explicitly convert argument to buffer pointer valid for a defined scope}} -takesRaw(&topLevelS.storedPropertyWithObservers) // expected-warning {{inout expression creates a temporary pointer, but argument #1 should be a pointer that outlives the call to 'takesRaw'}} +takesRaw(&topLevelS.storedPropertyWithObservers) // expected-warning {{cannot use inout expression here; argument #1 must be a pointer that outlives the call to 'takesRaw'}} // expected-note@-1 {{implicit argument conversion from 'Int8' to 'UnsafeRawPointer' produces a pointer valid only for the duration of the call to 'takesRaw'}} // expected-note@-2 {{use 'withUnsafeBytes' in order to explicitly convert argument to buffer pointer valid for a defined scope}} -takesRaw(&topLevelOptOfS!.storedPropertyWithObservers) // expected-warning {{inout expression creates a temporary pointer, but argument #1 should be a pointer that outlives the call to 'takesRaw'}} +takesRaw(&topLevelOptOfS!.storedPropertyWithObservers) // expected-warning {{cannot use inout expression here; argument #1 must be a pointer that outlives the call to 'takesRaw'}} // expected-note@-1 {{implicit argument conversion from 'Int8' to 'UnsafeRawPointer' produces a pointer valid only for the duration of the call to 'takesRaw'}} // expected-note@-2 {{use 'withUnsafeBytes' in order to explicitly convert argument to buffer pointer valid for a defined scope}} -takesRaw(&topLevelC.storedPropertyWithObservers) // expected-warning {{inout expression creates a temporary pointer, but argument #1 should be a pointer that outlives the call to 'takesRaw'}} +takesRaw(&topLevelC.storedPropertyWithObservers) // expected-warning {{cannot use inout expression here; argument #1 must be a pointer that outlives the call to 'takesRaw'}} // expected-note@-1 {{implicit argument conversion from 'Int8' to 'UnsafeRawPointer' produces a pointer valid only for the duration of the call to 'takesRaw'}} // expected-note@-2 {{use 'withUnsafeBytes' in order to explicitly convert argument to buffer pointer valid for a defined scope}} -takesRaw(&topLevelFinalC.storedPropertyWithObservers) // expected-warning {{inout expression creates a temporary pointer, but argument #1 should be a pointer that outlives the call to 'takesRaw'}} +takesRaw(&topLevelFinalC.storedPropertyWithObservers) // expected-warning {{cannot use inout expression here; argument #1 must be a pointer that outlives the call to 'takesRaw'}} // expected-note@-1 {{implicit argument conversion from 'Int8' to 'UnsafeRawPointer' produces a pointer valid only for the duration of the call to 'takesRaw'}} // expected-note@-2 {{use 'withUnsafeBytes' in order to explicitly convert argument to buffer pointer valid for a defined scope}} -takesRaw(&topLevelTupleOfS.0.storedPropertyWithObservers) // expected-warning {{inout expression creates a temporary pointer, but argument #1 should be a pointer that outlives the call to 'takesRaw'}} +takesRaw(&topLevelTupleOfS.0.storedPropertyWithObservers) // expected-warning {{cannot use inout expression here; argument #1 must be a pointer that outlives the call to 'takesRaw'}} // expected-note@-1 {{implicit argument conversion from 'Int8' to 'UnsafeRawPointer' produces a pointer valid only for the duration of the call to 'takesRaw'}} // expected-note@-2 {{use 'withUnsafeBytes' in order to explicitly convert argument to buffer pointer valid for a defined scope}} // - Computed properties -takesRaw(&topLevelOptOfS!.computedProperty) // expected-warning {{inout expression creates a temporary pointer, but argument #1 should be a pointer that outlives the call to 'takesRaw'}} +takesRaw(&topLevelOptOfS!.computedProperty) // expected-warning {{cannot use inout expression here; argument #1 must be a pointer that outlives the call to 'takesRaw'}} // expected-note@-1 {{implicit argument conversion from 'Int8' to 'UnsafeRawPointer' produces a pointer valid only for the duration of the call to 'takesRaw'}} // expected-note@-2 {{use 'withUnsafeBytes' in order to explicitly convert argument to buffer pointer valid for a defined scope}} -takesRaw(&topLevelC.computedProperty) // expected-warning {{inout expression creates a temporary pointer, but argument #1 should be a pointer that outlives the call to 'takesRaw'}} +takesRaw(&topLevelC.computedProperty) // expected-warning {{cannot use inout expression here; argument #1 must be a pointer that outlives the call to 'takesRaw'}} // expected-note@-1 {{implicit argument conversion from 'Int8' to 'UnsafeRawPointer' produces a pointer valid only for the duration of the call to 'takesRaw'}} // expected-note@-2 {{use 'withUnsafeBytes' in order to explicitly convert argument to buffer pointer valid for a defined scope}} -takesRaw(&topLevelFinalC.computedProperty) // expected-warning {{inout expression creates a temporary pointer, but argument #1 should be a pointer that outlives the call to 'takesRaw'}} +takesRaw(&topLevelFinalC.computedProperty) // expected-warning {{cannot use inout expression here; argument #1 must be a pointer that outlives the call to 'takesRaw'}} // expected-note@-1 {{implicit argument conversion from 'Int8' to 'UnsafeRawPointer' produces a pointer valid only for the duration of the call to 'takesRaw'}} // expected-note@-2 {{use 'withUnsafeBytes' in order to explicitly convert argument to buffer pointer valid for a defined scope}} -takesRaw(&topLevelTupleOfS.0.computedProperty) // expected-warning {{inout expression creates a temporary pointer, but argument #1 should be a pointer that outlives the call to 'takesRaw'}} +takesRaw(&topLevelTupleOfS.0.computedProperty) // expected-warning {{cannot use inout expression here; argument #1 must be a pointer that outlives the call to 'takesRaw'}} // expected-note@-1 {{implicit argument conversion from 'Int8' to 'UnsafeRawPointer' produces a pointer valid only for the duration of the call to 'takesRaw'}} // expected-note@-2 {{use 'withUnsafeBytes' in order to explicitly convert argument to buffer pointer valid for a defined scope}} // - Subscripts -takesRaw(&topLevelS[]) // expected-warning {{inout expression creates a temporary pointer, but argument #1 should be a pointer that outlives the call to 'takesRaw'}} +takesRaw(&topLevelS[]) // expected-warning {{cannot use inout expression here; argument #1 must be a pointer that outlives the call to 'takesRaw'}} // expected-note@-1 {{implicit argument conversion from 'Int8' to 'UnsafeRawPointer' produces a pointer valid only for the duration of the call to 'takesRaw'}} // expected-note@-2 {{use 'withUnsafeBytes' in order to explicitly convert argument to buffer pointer valid for a defined scope}} -takesRaw(&topLevelC[]) // expected-warning {{inout expression creates a temporary pointer, but argument #1 should be a pointer that outlives the call to 'takesRaw'}} +takesRaw(&topLevelC[]) // expected-warning {{cannot use inout expression here; argument #1 must be a pointer that outlives the call to 'takesRaw'}} // expected-note@-1 {{implicit argument conversion from 'Int8' to 'UnsafeRawPointer' produces a pointer valid only for the duration of the call to 'takesRaw'}} // expected-note@-2 {{use 'withUnsafeBytes' in order to explicitly convert argument to buffer pointer valid for a defined scope}} -takesRaw(&topLevelFinalC[]) // expected-warning {{inout expression creates a temporary pointer, but argument #1 should be a pointer that outlives the call to 'takesRaw'}} +takesRaw(&topLevelFinalC[]) // expected-warning {{cannot use inout expression here; argument #1 must be a pointer that outlives the call to 'takesRaw'}} // expected-note@-1 {{implicit argument conversion from 'Int8' to 'UnsafeRawPointer' produces a pointer valid only for the duration of the call to 'takesRaw'}} // expected-note@-2 {{use 'withUnsafeBytes' in order to explicitly convert argument to buffer pointer valid for a defined scope}} @@ -290,15 +290,15 @@ takesRaw(&topLevelFinalC[]) // expected-warning {{inout expression creates a tem func testInoutToPointerOfLocal() { var local: Int8 = 0 - takesMutableRaw(&local, 5) // expected-warning {{inout expression creates a temporary pointer, but argument #1 should be a pointer that outlives the call to 'takesMutableRaw'}} + takesMutableRaw(&local, 5) // expected-warning {{cannot use inout expression here; argument #1 must be a pointer that outlives the call to 'takesMutableRaw'}} // expected-note@-1 {{implicit argument conversion from 'Int8' to 'UnsafeMutableRawPointer' produces a pointer valid only for the duration of the call to 'takesMutableRaw'}} // expected-note@-2 {{use 'withUnsafeMutableBytes' in order to explicitly convert argument to buffer pointer valid for a defined scope}} - takesRaw(&local) // expected-warning {{inout expression creates a temporary pointer, but argument #1 should be a pointer that outlives the call to 'takesRaw'}} + takesRaw(&local) // expected-warning {{cannot use inout expression here; argument #1 must be a pointer that outlives the call to 'takesRaw'}} // expected-note@-1 {{implicit argument conversion from 'Int8' to 'UnsafeRawPointer' produces a pointer valid only for the duration of the call to 'takesRaw'}} // expected-note@-2 {{use 'withUnsafeBytes' in order to explicitly convert argument to buffer pointer valid for a defined scope}} - takesMutable(&local) // expected-warning {{inout expression creates a temporary pointer, but argument #1 should be a pointer that outlives the call to 'takesMutable'}} + takesMutable(&local) // expected-warning {{cannot use inout expression here; argument #1 must be a pointer that outlives the call to 'takesMutable'}} // expected-note@-1 {{implicit argument conversion from 'Int8' to 'UnsafeMutablePointer' produces a pointer valid only for the duration of the call to 'takesMutable'}} // expected-note@-2 {{use 'withUnsafeMutablePointer' in order to explicitly convert argument to pointer valid for a defined scope}} } @@ -308,11 +308,11 @@ func testInoutToPointerOfLocal() { struct S1 { var property: Int8 = 0 mutating func foo() { - takesRaw(&property) // expected-warning {{inout expression creates a temporary pointer, but argument #1 should be a pointer that outlives the call to 'takesRaw'}} + takesRaw(&property) // expected-warning {{cannot use inout expression here; argument #1 must be a pointer that outlives the call to 'takesRaw'}} // expected-note@-1 {{implicit argument conversion from 'Int8' to 'UnsafeRawPointer' produces a pointer valid only for the duration of the call to 'takesRaw'}} // expected-note@-2 {{use 'withUnsafeBytes' in order to explicitly convert argument to buffer pointer valid for a defined scope}} - takesRaw(&self.property) // expected-warning {{inout expression creates a temporary pointer, but argument #1 should be a pointer that outlives the call to 'takesRaw'}} + takesRaw(&self.property) // expected-warning {{cannot use inout expression here; argument #1 must be a pointer that outlives the call to 'takesRaw'}} // expected-note@-1 {{implicit argument conversion from 'Int8' to 'UnsafeRawPointer' produces a pointer valid only for the duration of the call to 'takesRaw'}} // expected-note@-2 {{use 'withUnsafeBytes' in order to explicitly convert argument to buffer pointer valid for a defined scope}} } @@ -321,11 +321,11 @@ struct S1 { final class C1 { var property: Int8 = 0 func foo() { - takesRaw(&property) // expected-warning {{inout expression creates a temporary pointer, but argument #1 should be a pointer that outlives the call to 'takesRaw'}} + takesRaw(&property) // expected-warning {{cannot use inout expression here; argument #1 must be a pointer that outlives the call to 'takesRaw'}} // expected-note@-1 {{implicit argument conversion from 'Int8' to 'UnsafeRawPointer' produces a pointer valid only for the duration of the call to 'takesRaw'}} // expected-note@-2 {{use 'withUnsafeBytes' in order to explicitly convert argument to buffer pointer valid for a defined scope}} - takesRaw(&self.property) // expected-warning {{inout expression creates a temporary pointer, but argument #1 should be a pointer that outlives the call to 'takesRaw'}} + takesRaw(&self.property) // expected-warning {{cannot use inout expression here; argument #1 must be a pointer that outlives the call to 'takesRaw'}} // expected-note@-1 {{implicit argument conversion from 'Int8' to 'UnsafeRawPointer' produces a pointer valid only for the duration of the call to 'takesRaw'}} // expected-note@-2 {{use 'withUnsafeBytes' in order to explicitly convert argument to buffer pointer valid for a defined scope}} } @@ -333,22 +333,22 @@ final class C1 { // Check that @_nonEphemeral is preserved through type inference. let f1 = takesMutableRaw -f1(&arr, 5) // expected-warning {{inout expression creates a temporary pointer, but argument #1 should be a pointer that outlives the call to 'f1'}} +f1(&arr, 5) // expected-warning {{cannot use inout expression here; argument #1 must be a pointer that outlives the call to 'f1'}} // expected-note@-1 {{implicit argument conversion from '[Int8]' to 'UnsafeMutableRawPointer' produces a pointer valid only for the duration of the call to 'f1'}} // expected-note@-2 {{use the 'withUnsafeMutableBytes' method on Array in order to explicitly convert argument to buffer pointer valid for a defined scope}} let f2 = takesConst -f2(arr, 5) // expected-warning {{passing '[Int8]' to parameter, but argument #1 should be a pointer that outlives the call to 'f2'}} +f2(arr, 5) // expected-warning {{cannot pass '[Int8]' to parameter; argument #1 must be a pointer that outlives the call to 'f2'}} // expected-note@-1 {{implicit argument conversion from '[Int8]' to 'UnsafePointer' produces a pointer valid only for the duration of the call to 'f2'}} // expected-note@-2 {{use the 'withUnsafeBufferPointer' method on Array in order to explicitly convert argument to buffer pointer valid for a defined scope}} let f3 = takesRaw -f3(&arr) // expected-warning {{inout expression creates a temporary pointer, but argument #1 should be a pointer that outlives the call to 'f3'}} +f3(&arr) // expected-warning {{cannot use inout expression here; argument #1 must be a pointer that outlives the call to 'f3'}} // expected-note@-1 {{implicit argument conversion from '[Int8]' to 'UnsafeRawPointer' produces a pointer valid only for the duration of the call to 'f3'}} // expected-note@-2 {{use the 'withUnsafeBytes' method on Array in order to explicitly convert argument to buffer pointer valid for a defined scope}} let f4 = takesMutable -f4(&arr) // expected-warning {{inout expression creates a temporary pointer, but argument #1 should be a pointer that outlives the call to 'f4'}} +f4(&arr) // expected-warning {{cannot use inout expression here; argument #1 must be a pointer that outlives the call to 'f4'}} // expected-note@-1 {{implicit argument conversion from '[Int8]' to 'UnsafeMutablePointer' produces a pointer valid only for the duration of the call to 'f4'}} // expected-note@-2 {{use the 'withUnsafeMutableBufferPointer' method on Array in order to explicitly convert argument to buffer pointer valid for a defined scope}} @@ -368,33 +368,33 @@ struct S2 { func testNonEphemeralInMembers() { var local = 0 - let _: S2 = .takesConstStaticAndReturns([1, 2, 3]) // expected-warning {{passing '[Int]' to parameter, but argument #1 should be a pointer that outlives the call to 'takesConstStaticAndReturns'}} + let _: S2 = .takesConstStaticAndReturns([1, 2, 3]) // expected-warning {{cannot pass '[Int]' to parameter; argument #1 must be a pointer that outlives the call to 'takesConstStaticAndReturns'}} // expected-note@-1 {{implicit argument conversion from '[Int]' to 'UnsafePointer' produces a pointer valid only for the duration of the call to 'takesConstStaticAndReturns'}} // expected-note@-2 {{use the 'withUnsafeBufferPointer' method on Array in order to explicitly convert argument to buffer pointer valid for a defined scope}} - S2.takesMutableRawStatic(ptr: &local) // expected-warning {{inout expression creates a temporary pointer, but argument 'ptr' should be a pointer that outlives the call to 'takesMutableRawStatic(_:ptr:)'}} + S2.takesMutableRawStatic(ptr: &local) // expected-warning {{cannot use inout expression here; argument 'ptr' must be a pointer that outlives the call to 'takesMutableRawStatic(_:ptr:)'}} // expected-note@-1 {{implicit argument conversion from 'Int' to 'UnsafeMutableRawPointer' produces a pointer valid only for the duration of the call to 'takesMutableRawStatic(_:ptr:)'}} // expected-note@-2 {{use 'withUnsafeMutableBytes' in order to explicitly convert argument to buffer pointer valid for a defined scope}} - S2.takesMutableRawStatic("", ptr: &local) // expected-warning {{inout expression creates a temporary pointer, but argument 'ptr' should be a pointer that outlives the call to 'takesMutableRawStatic(_:ptr:)'}} + S2.takesMutableRawStatic("", ptr: &local) // expected-warning {{cannot use inout expression here; argument 'ptr' must be a pointer that outlives the call to 'takesMutableRawStatic(_:ptr:)'}} // expected-note@-1 {{implicit argument conversion from 'Int' to 'UnsafeMutableRawPointer' produces a pointer valid only for the duration of the call to 'takesMutableRawStatic(_:ptr:)'}} // expected-note@-2 {{use 'withUnsafeMutableBytes' in order to explicitly convert argument to buffer pointer valid for a defined scope}} var s2 = S2() s2.takesMutableRaw() - s2.takesMutableRaw(ptr: &local) // expected-warning {{inout expression creates a temporary pointer, but argument 'ptr' should be a pointer that outlives the call to 'takesMutableRaw(ptr:)'}} + s2.takesMutableRaw(ptr: &local) // expected-warning {{cannot use inout expression here; argument 'ptr' must be a pointer that outlives the call to 'takesMutableRaw(ptr:)'}} // expected-note@-1 {{implicit argument conversion from 'Int' to 'UnsafeMutableRawPointer' produces a pointer valid only for the duration of the call to 'takesMutableRaw(ptr:)'}} // expected-note@-2 {{use 'withUnsafeMutableBytes' in order to explicitly convert argument to buffer pointer valid for a defined scope}} - _ = s2[takesConstInt8: ""] // expected-warning {{passing 'String' to parameter, but argument 'takesConstInt8' should be a pointer that outlives the call to 'subscript(takesConstInt8:)'}} + _ = s2[takesConstInt8: ""] // expected-warning {{cannot pass 'String' to parameter; argument 'takesConstInt8' must be a pointer that outlives the call to 'subscript(takesConstInt8:)'}} // expected-note@-1 {{implicit argument conversion from 'String' to 'UnsafePointer' produces a pointer valid only for the duration of the call to 'subscript(takesConstInt8:)'}} // expected-note@-2 {{use the 'withCString' method on String in order to explicitly convert argument to pointer valid for a defined scope}} - s2[takesConstInt8: ""] += 1 // expected-warning {{passing 'String' to parameter, but argument 'takesConstInt8' should be a pointer that outlives the call to 'subscript(takesConstInt8:)'}} + s2[takesConstInt8: ""] += 1 // expected-warning {{cannot pass 'String' to parameter; argument 'takesConstInt8' must be a pointer that outlives the call to 'subscript(takesConstInt8:)'}} // expected-note@-1 {{implicit argument conversion from 'String' to 'UnsafePointer' produces a pointer valid only for the duration of the call to 'subscript(takesConstInt8:)'}} // expected-note@-2 {{use the 'withCString' method on String in order to explicitly convert argument to pointer valid for a defined scope}} - _ = \S2.[takesConstInt8: ""] // expected-warning {{passing 'String' to parameter, but argument 'takesConstInt8' should be a pointer that outlives the call to 'subscript(takesConstInt8:)'}} + _ = \S2.[takesConstInt8: ""] // expected-warning {{cannot pass 'String' to parameter; argument 'takesConstInt8' must be a pointer that outlives the call to 'subscript(takesConstInt8:)'}} // expected-note@-1 {{implicit argument conversion from 'String' to 'UnsafePointer' produces a pointer valid only for the duration of the call to 'subscript(takesConstInt8:)'}} // expected-note@-2 {{use the 'withCString' method on String in order to explicitly convert argument to pointer valid for a defined scope}} } @@ -427,7 +427,7 @@ func testNonEphemeralInOperators() { &value ^^^ 1 - &local ^^^ 1 // expected-warning {{inout expression creates a temporary pointer, but argument #1 should be a pointer that outlives the call to '^^^'}} + &local ^^^ 1 // expected-warning {{cannot use inout expression here; argument #1 must be a pointer that outlives the call to '^^^'}} // expected-note@-1 {{implicit argument conversion from 'Int' to 'UnsafeMutableRawPointer' produces a pointer valid only for the duration of the call to '^^^'}} // expected-note@-2 {{use 'withUnsafeMutableBytes' in order to explicitly convert argument to buffer pointer valid for a defined scope}} } @@ -445,23 +445,23 @@ enum E { func testNonEphemeralInMemberwiseInits() { var local = 0 - _ = S3(ptr1: &topLevelS, ptr2: &local) // expected-warning {{inout expression creates a temporary pointer, but argument 'ptr2' should be a pointer that outlives the call to 'init(ptr1:ptr2:)'}} + _ = S3(ptr1: &topLevelS, ptr2: &local) // expected-warning {{cannot use inout expression here; argument 'ptr2' must be a pointer that outlives the call to 'init(ptr1:ptr2:)'}} // expected-note@-1 {{implicit argument conversion from 'Int' to 'UnsafeMutableRawPointer?' produces a pointer valid only for the duration of the call to 'init(ptr1:ptr2:)'}} // expected-note@-2 {{use 'withUnsafeMutableBytes' in order to explicitly convert argument to buffer pointer valid for a defined scope}} - _ = S3.init(ptr1: &local, ptr2: &topLevelS) // expected-warning {{inout expression creates a temporary pointer, but argument 'ptr1' should be a pointer that outlives the call to 'init(ptr1:ptr2:)'}} + _ = S3.init(ptr1: &local, ptr2: &topLevelS) // expected-warning {{cannot use inout expression here; argument 'ptr1' must be a pointer that outlives the call to 'init(ptr1:ptr2:)'}} // expected-note@-1 {{implicit argument conversion from 'Int' to 'UnsafeMutableRawPointer' produces a pointer valid only for the duration of the call to 'init(ptr1:ptr2:)'}} // expected-note@-2 {{use 'withUnsafeMutableBytes' in order to explicitly convert argument to buffer pointer valid for a defined scope}} - _ = E.mutableRaw(&local) // expected-warning {{inout expression creates a temporary pointer, but argument #1 should be a pointer that outlives the call to 'mutableRaw'}} + _ = E.mutableRaw(&local) // expected-warning {{cannot use inout expression here; argument #1 must be a pointer that outlives the call to 'mutableRaw'}} // expected-note@-1 {{implicit argument conversion from 'Int' to 'UnsafeMutableRawPointer' produces a pointer valid only for the duration of the call to 'mutableRaw'}} // expected-note@-2 {{use 'withUnsafeMutableBytes' in order to explicitly convert argument to buffer pointer valid for a defined scope}} - _ = E.const([1, 2, 3]) // expected-warning {{passing '[Int8]' to parameter, but argument #1 should be a pointer that outlives the call to 'const'}} + _ = E.const([1, 2, 3]) // expected-warning {{cannot pass '[Int8]' to parameter; argument #1 must be a pointer that outlives the call to 'const'}} // expected-note@-1 {{implicit argument conversion from '[Int8]' to 'UnsafePointer' produces a pointer valid only for the duration of the call to 'const'}} // expected-note@-2 {{use the 'withUnsafeBufferPointer' method on Array in order to explicitly convert argument to buffer pointer valid for a defined scope}} - _ = E.const("hello") // expected-warning {{passing 'String' to parameter, but argument #1 should be a pointer that outlives the call to 'const'}} + _ = E.const("hello") // expected-warning {{cannot pass 'String' to parameter; argument #1 must be a pointer that outlives the call to 'const'}} // expected-note@-1 {{implicit argument conversion from 'String' to 'UnsafePointer' produces a pointer valid only for the duration of the call to 'const'}} // expected-note@-2 {{use the 'withCString' method on String in order to explicitly convert argument to pointer valid for a defined scope}} } diff --git a/test/attr/attr_concurrent.swift b/test/attr/attr_concurrent.swift index b3c0d3c378e7e..b04880619193c 100644 --- a/test/attr/attr_concurrent.swift +++ b/test/attr/attr_concurrent.swift @@ -29,7 +29,7 @@ func passingConcurrentOrNot( f(ncfn) acceptsConcurrent(cfn) // okay - acceptsConcurrent(ncfn) // expected-error{{passing non-sendable parameter 'ncfn' to function expecting a @Sendable closure}} + acceptsConcurrent(ncfn) // expected-warning{{passing non-sendable parameter 'ncfn' to function expecting a @Sendable closure}} acceptsNonConcurrent(cfn) // okay acceptsNonConcurrent(ncfn) // okay @@ -50,7 +50,7 @@ func closures() { }) let closure1 = { $0 + 1 } // inferred to be non-sendable - acceptsConcurrent(closure1) // expected-error{{converting non-sendable function value to '@Sendable (Int) -> Int' may introduce data races}} + acceptsConcurrent(closure1) // expected-warning{{converting non-sendable function value to '@Sendable (Int) -> Int' may introduce data races}} } // Mutation of captured locals from within @Sendable functions. diff --git a/test/stdlib/UnsafePointerDiagnostics_warning.swift b/test/stdlib/UnsafePointerDiagnostics_warning.swift index aa876119cbd45..52b3bfeee92f8 100644 --- a/test/stdlib/UnsafePointerDiagnostics_warning.swift +++ b/test/stdlib/UnsafePointerDiagnostics_warning.swift @@ -13,7 +13,7 @@ func unsafePointerInitEphemeralConversions() { // expected-note@-1 {{implicit argument conversion from 'Int' to 'UnsafePointer' produces a pointer valid only for the duration of the call to 'init(_:)'}} // expected-note@-2 {{use 'withUnsafePointer' in order to explicitly convert argument to pointer valid for a defined scope}} - _ = UnsafePointer(&foo + 1) // expected-warning {{inout expression creates a temporary pointer, but argument #1 should be a pointer that outlives the call to '+'}} + _ = UnsafePointer(&foo + 1) // expected-warning {{argument #1 must be a pointer that outlives the call to '+'}} // expected-note@-1 {{implicit argument conversion from 'Int' to 'UnsafePointer' produces a pointer valid only for the duration of the call to '+'}} // expected-note@-2 {{use 'withUnsafePointer' in order to explicitly convert argument to pointer valid for a defined scope}} @@ -57,7 +57,7 @@ func unsafePointerInitEphemeralConversions() { // expected-note@-1 {{implicit argument conversion from '[Int]' to 'UnsafeMutablePointer' produces a pointer valid only for the duration of the call to 'init(_:)'}} // expected-note@-2 {{use the 'withUnsafeMutableBufferPointer' method on Array in order to explicitly convert argument to buffer pointer valid for a defined scope}} - _ = UnsafeMutablePointer(&arr + 2) // expected-warning {{inout expression creates a temporary pointer, but argument #1 should be a pointer that outlives the call to '+'}} + _ = UnsafeMutablePointer(&arr + 2) // expected-warning {{argument #1 must be a pointer that outlives the call to '+'}} // expected-note@-1 {{implicit argument conversion from '[Int]' to 'UnsafeMutablePointer' produces a pointer valid only for the duration of the call to '+'}} // expected-note@-2 {{use the 'withUnsafeMutableBufferPointer' method on Array in order to explicitly convert argument to buffer pointer valid for a defined scope}}