Skip to content

Commit c0f5502

Browse files
committed
Leverage error-to-warnings downgrades for non-ephemeral conversion diagnostics
There were slight wording changes between the warning and error diagnostics, but they don't seem to justify the duplication here.
1 parent 365f0af commit c0f5502

File tree

7 files changed

+76
-105
lines changed

7 files changed

+76
-105
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -398,22 +398,12 @@ NOTE(generic_parameter_inferred_from_result_context,none,
398398
ERROR(cannot_pass_type_to_non_ephemeral,none,
399399
"cannot pass %0 to parameter; argument %1 must be a pointer that "
400400
"outlives the call%select{| to %3}2", (Type, StringRef, bool, DeclName))
401-
WARNING(cannot_pass_type_to_non_ephemeral_warning,none,
402-
"passing %0 to parameter, but argument %1 should be a pointer that "
403-
"outlives the call%select{| to %3}2", (Type, StringRef, bool, DeclName))
404401
ERROR(cannot_use_inout_non_ephemeral,none,
405402
"cannot use inout expression here; argument %0 must be a pointer that "
406403
"outlives the call%select{| to %2}1", (StringRef, bool, DeclName))
407-
WARNING(cannot_use_inout_non_ephemeral_warning,none,
408-
"inout expression creates a temporary pointer, but argument %0 should "
409-
"be a pointer that outlives the call%select{| to %2}1",
410-
(StringRef, bool, DeclName))
411404
ERROR(cannot_construct_dangling_pointer,none,
412405
"initialization of %0 results in a dangling %select{|buffer }1pointer",
413406
(Type, unsigned))
414-
WARNING(cannot_construct_dangling_pointer_warning,none,
415-
"initialization of %0 results in a dangling %select{|buffer }1pointer",
416-
(Type, unsigned))
417407
NOTE(ephemeral_pointer_argument_conversion_note,none,
418408
"implicit argument conversion from %0 to %1 produces a pointer valid only "
419409
"for the duration of the call%select{| to %3}2",

include/swift/AST/EducationalNotes.def

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,9 @@ EDUCATIONAL_NOTES(could_not_use_member_on_existential,
2525
"existential-member-access-limitations.md")
2626

2727
EDUCATIONAL_NOTES(cannot_pass_type_to_non_ephemeral, "temporary-pointers.md")
28-
EDUCATIONAL_NOTES(cannot_pass_type_to_non_ephemeral_warning,
29-
"temporary-pointers.md")
3028
EDUCATIONAL_NOTES(cannot_use_inout_non_ephemeral,
3129
"temporary-pointers.md")
32-
EDUCATIONAL_NOTES(cannot_use_inout_non_ephemeral_warning,
33-
"temporary-pointers.md")
3430
EDUCATIONAL_NOTES(cannot_construct_dangling_pointer, "temporary-pointers.md")
35-
EDUCATIONAL_NOTES(cannot_construct_dangling_pointer_warning,
36-
"temporary-pointers.md")
37-
38-
3931

4032
EDUCATIONAL_NOTES(non_nominal_no_initializers, "nominal-types.md")
4133
EDUCATIONAL_NOTES(non_nominal_extension, "nominal-types.md")

lib/Sema/CSDiagnostics.cpp

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6782,12 +6782,9 @@ bool NonEphemeralConversionFailure::diagnosePointerInit() const {
67826782
return false;
67836783
}
67846784

6785-
auto diagID = DowngradeToWarning
6786-
? diag::cannot_construct_dangling_pointer_warning
6787-
: diag::cannot_construct_dangling_pointer;
6788-
67896785
auto anchor = getRawAnchor();
6790-
emitDiagnosticAt(::getLoc(anchor), diagID, constructedTy, constructorKind)
6786+
emitDiagnosticAt(::getLoc(anchor), diag::cannot_construct_dangling_pointer,
6787+
constructedTy, constructorKind)
67916788
.highlight(::getSourceRange(anchor));
67926789

67936790
emitSuggestionNotes();
@@ -6817,20 +6814,12 @@ bool NonEphemeralConversionFailure::diagnoseAsError() {
68176814

68186815
auto *argExpr = getArgExpr();
68196816
if (isa<InOutExpr>(argExpr)) {
6820-
auto diagID = DowngradeToWarning
6821-
? diag::cannot_use_inout_non_ephemeral_warning
6822-
: diag::cannot_use_inout_non_ephemeral;
6823-
6824-
emitDiagnosticAt(argExpr->getLoc(), diagID, argDesc, getCallee(),
6825-
getCalleeFullName())
6817+
emitDiagnosticAt(argExpr->getLoc(), diag::cannot_use_inout_non_ephemeral,
6818+
argDesc, getCallee(), getCalleeFullName())
68266819
.highlight(argExpr->getSourceRange());
68276820
} else {
6828-
auto diagID = DowngradeToWarning
6829-
? diag::cannot_pass_type_to_non_ephemeral_warning
6830-
: diag::cannot_pass_type_to_non_ephemeral;
6831-
6832-
emitDiagnosticAt(argExpr->getLoc(), diagID, getArgType(), argDesc,
6833-
getCallee(), getCalleeFullName())
6821+
emitDiagnosticAt(argExpr->getLoc(), diag::cannot_pass_type_to_non_ephemeral,
6822+
getArgType(), argDesc, getCallee(), getCalleeFullName())
68346823
.highlight(argExpr->getSourceRange());
68356824
}
68366825
emitSuggestionNotes();

lib/Sema/CSDiagnostics.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1949,8 +1949,9 @@ class ArgumentMismatchFailure : public ContextualFailure {
19491949

19501950
public:
19511951
ArgumentMismatchFailure(const Solution &solution, Type argType,
1952-
Type paramType, ConstraintLocator *locator)
1953-
: ContextualFailure(solution, argType, paramType, locator),
1952+
Type paramType, ConstraintLocator *locator,
1953+
bool warning = false)
1954+
: ContextualFailure(solution, argType, paramType, locator, warning),
19541955
Info(*getFunctionArgApplyInfo(getLocator())) {}
19551956

19561957
bool diagnoseAsError() override;
@@ -2119,16 +2120,15 @@ class InvalidUseOfTrailingClosure final : public ArgumentMismatchFailure {
21192120
/// ```
21202121
class NonEphemeralConversionFailure final : public ArgumentMismatchFailure {
21212122
ConversionRestrictionKind ConversionKind;
2122-
bool DowngradeToWarning;
21232123

21242124
public:
21252125
NonEphemeralConversionFailure(const Solution &solution,
21262126
ConstraintLocator *locator, Type fromType,
21272127
Type toType,
21282128
ConversionRestrictionKind conversionKind,
2129-
bool downgradeToWarning)
2130-
: ArgumentMismatchFailure(solution, fromType, toType, locator),
2131-
ConversionKind(conversionKind), DowngradeToWarning(downgradeToWarning) {
2129+
bool warning)
2130+
: ArgumentMismatchFailure(solution, fromType, toType, locator, warning),
2131+
ConversionKind(conversionKind) {
21322132
}
21332133

21342134
bool diagnoseAsError() override;

test/IDE/newtype.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -238,19 +238,19 @@ func testFixit() {
238238
func testNonEphemeralInitParams(x: OpaquePointer) {
239239
var x = x
240240

241-
_ = TRefRef(&x) // expected-warning {{inout expression creates a temporary pointer, but argument #1 should be a pointer that outlives the call to 'init(_:)'}}
241+
_ = TRefRef(&x) // expected-warning {{argument #1 must be a pointer that outlives the call to 'init(_:)'}}
242242
// expected-note@-1 {{implicit argument conversion from 'OpaquePointer' to 'UnsafeMutablePointer<OpaquePointer>' produces a pointer valid only for the duration of the call}}
243243
// expected-note@-2 {{use 'withUnsafeMutablePointer' in order to explicitly convert argument to pointer valid for a defined scope}}
244244

245-
_ = 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:)'}}
245+
_ = TRefRef(rawValue: &x) // expected-warning {{argument 'rawValue' must be a pointer that outlives the call to 'init(rawValue:)'}}
246246
// expected-note@-1 {{implicit argument conversion from 'OpaquePointer' to 'UnsafeMutablePointer<OpaquePointer>' produces a pointer valid only for the duration of the call}}
247247
// expected-note@-2 {{use 'withUnsafeMutablePointer' in order to explicitly convert argument to pointer valid for a defined scope}}
248248

249-
_ = ConstTRefRef(&x) // expected-warning {{inout expression creates a temporary pointer, but argument #1 should be a pointer that outlives the call to 'init(_:)'}}
249+
_ = ConstTRefRef(&x) // expected-warning {{argument #1 must be a pointer that outlives the call to 'init(_:)'}}
250250
// expected-note@-1 {{implicit argument conversion from 'OpaquePointer' to 'UnsafePointer<OpaquePointer>' produces a pointer valid only for the duration of the call}}
251251
// expected-note@-2 {{use 'withUnsafePointer' in order to explicitly convert argument to pointer valid for a defined scope}}
252252

253-
_ = 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:)'}}
253+
_ = ConstTRefRef(rawValue: &x) // expected-warning {{argument 'rawValue' must be a pointer that outlives the call to 'init(rawValue:)'}}
254254
// expected-note@-1 {{implicit argument conversion from 'OpaquePointer' to 'UnsafePointer<OpaquePointer>' produces a pointer valid only for the duration of the call}}
255255
// expected-note@-2 {{use 'withUnsafePointer' in order to explicitly convert argument to pointer valid for a defined scope}}
256256
}

0 commit comments

Comments
 (0)