Allow non-ephemeral diag to refer to argument labels

Use getArgDescription to improve the diagnostic
for invalid temporary pointer conversions.
This commit is contained in:
Hamish Knight
2019-11-04 11:03:14 -08:00
parent 912a7acc1e
commit 96e5f2a145
6 changed files with 48 additions and 30 deletions

View File

@@ -5680,13 +5680,16 @@ bool NonEphemeralConversionFailure::diagnoseAsError() {
return true;
// Otherwise, emit a more general diagnostic.
SmallString<8> scratch;
auto argDesc = getArgDescription(scratch);
auto *argExpr = getArgExpr();
if (isa<InOutExpr>(argExpr)) {
auto diagID = DowngradeToWarning
? diag::cannot_use_inout_non_ephemeral_warning
: diag::cannot_use_inout_non_ephemeral;
emitDiagnostic(argExpr->getLoc(), diagID, getArgPosition(), getCallee(),
emitDiagnostic(argExpr->getLoc(), diagID, argDesc, getCallee(),
getCalleeFullName())
.highlight(argExpr->getSourceRange());
} else {
@@ -5694,7 +5697,7 @@ bool NonEphemeralConversionFailure::diagnoseAsError() {
? diag::cannot_pass_type_to_non_ephemeral_warning
: diag::cannot_pass_type_to_non_ephemeral;
emitDiagnostic(argExpr->getLoc(), diagID, getArgType(), getArgPosition(),
emitDiagnostic(argExpr->getLoc(), diagID, getArgType(), argDesc,
getCallee(), getCalleeFullName())
.highlight(argExpr->getSourceRange());
}