@@ -1227,34 +1227,8 @@ static bool isDiscardableType(Type type) {
12271227}
12281228
12291229static void diagnoseIgnoredLiteral (ASTContext &Ctx, LiteralExpr *LE) {
1230- const auto getLiteralDescription = [](LiteralExpr *LE) -> StringRef {
1231- switch (LE->getKind ()) {
1232- case ExprKind::IntegerLiteral: return " integer" ;
1233- case ExprKind::FloatLiteral: return " floating-point" ;
1234- case ExprKind::BooleanLiteral: return " boolean" ;
1235- case ExprKind::StringLiteral: return " string" ;
1236- case ExprKind::InterpolatedStringLiteral: return " string" ;
1237- case ExprKind::RegexLiteral: return " regular expression" ;
1238- case ExprKind::MagicIdentifierLiteral:
1239- return MagicIdentifierLiteralExpr::getKindString (
1240- cast<MagicIdentifierLiteralExpr>(LE)->getKind ());
1241- case ExprKind::NilLiteral: return " nil" ;
1242- case ExprKind::ObjectLiteral: return " object" ;
1243-
1244- // Define an unreachable case for all non-literal expressions.
1245- // This way, if a new literal is added in the future, the compiler
1246- // will warn that a case is missing from this switch.
1247- #define LITERAL_EXPR (Id, Parent )
1248- #define EXPR (Id, Parent ) case ExprKind::Id:
1249- #include " swift/AST/ExprNodes.def"
1250- llvm_unreachable (" Not a literal expression" );
1251- }
1252-
1253- llvm_unreachable (" Unhandled ExprKind in switch." );
1254- };
1255-
12561230 Ctx.Diags .diagnose (LE->getLoc (), diag::expression_unused_literal,
1257- getLiteralDescription (LE ))
1231+ LE-> getLiteralKindDescription ( ))
12581232 .highlight (LE->getSourceRange ());
12591233}
12601234
0 commit comments