From 8f64141e7540aa32aff098e67348a302b38cea11 Mon Sep 17 00:00:00 2001 From: 0v0 Date: Fri, 5 Jul 2024 04:56:43 +0800 Subject: [PATCH] simplify nested reference checking (#16656) --- compiler/src/dmd/canthrow.d | 6 ++---- compiler/src/dmd/cppmangle.d | 3 +-- compiler/src/dmd/delegatize.d | 9 +++------ compiler/src/dmd/func.d | 3 +-- druntime/src/rt/config.d | 3 +-- druntime/src/rt/trace.d | 3 +-- 6 files changed, 9 insertions(+), 18 deletions(-) diff --git a/compiler/src/dmd/canthrow.d b/compiler/src/dmd/canthrow.d index 31155f188dca..c96a65b8d40f 100644 --- a/compiler/src/dmd/canthrow.d +++ b/compiler/src/dmd/canthrow.d @@ -111,11 +111,9 @@ CT canThrow(Expression e, FuncDeclaration func, ErrorSink eSink) if (ce.f && ce.arguments.length > 0) { Type tb = (*ce.arguments)[0].type.toBasetype(); - auto tbNext = tb.nextOf(); - if (tbNext) + if (auto tbNext = tb.nextOf()) { - auto ts = tbNext.baseElemOf().isTypeStruct(); - if (ts) + if (auto ts = tbNext.baseElemOf().isTypeStruct()) { auto sd = ts.sym; const id = ce.f.ident; diff --git a/compiler/src/dmd/cppmangle.d b/compiler/src/dmd/cppmangle.d index 0609778e4c77..79be1e5454cd 100644 --- a/compiler/src/dmd/cppmangle.d +++ b/compiler/src/dmd/cppmangle.d @@ -725,8 +725,7 @@ private final class CppMangleVisitor : Visitor */ static Dsymbol getInstance(Dsymbol s) { - Dsymbol p = s.toParent(); - if (p) + if (Dsymbol p = s.toParent()) { if (TemplateInstance ti = p.isTemplateInstance()) return ti; diff --git a/compiler/src/dmd/delegatize.d b/compiler/src/dmd/delegatize.d index 62800d3fdb77..95064b0d16dc 100644 --- a/compiler/src/dmd/delegatize.d +++ b/compiler/src/dmd/delegatize.d @@ -215,15 +215,13 @@ bool lambdaCheckForNestedRef(Expression e, Scope* sc) override void visit(SymOffExp e) { - VarDeclaration v = e.var.isVarDeclaration(); - if (v) + if (VarDeclaration v = e.var.isVarDeclaration()) result = v.checkNestedReference(sc, Loc.initial); } override void visit(VarExp e) { - VarDeclaration v = e.var.isVarDeclaration(); - if (v) + if (VarDeclaration v = e.var.isVarDeclaration()) result = v.checkNestedReference(sc, Loc.initial); } @@ -235,8 +233,7 @@ bool lambdaCheckForNestedRef(Expression e, Scope* sc) override void visit(DeclarationExp e) { - VarDeclaration v = e.declaration.isVarDeclaration(); - if (v) + if (VarDeclaration v = e.declaration.isVarDeclaration()) { result = v.checkNestedReference(sc, Loc.initial); if (result) diff --git a/compiler/src/dmd/func.d b/compiler/src/dmd/func.d index 54ff82670aeb..4f2b08cc8cb1 100644 --- a/compiler/src/dmd/func.d +++ b/compiler/src/dmd/func.d @@ -1262,8 +1262,7 @@ extern (C++) class FuncDeclaration : Declaration { if (type) { - TypeFunction fdtype = type.isTypeFunction(); - if (fdtype) // Could also be TypeError + if (TypeFunction fdtype = type.isTypeFunction()) // Could also be TypeError return fdtype.parameterList; } diff --git a/druntime/src/rt/config.d b/druntime/src/rt/config.d index a6605f4d6037..912b8fe36ad1 100644 --- a/druntime/src/rt/config.d +++ b/druntime/src/rt/config.d @@ -129,8 +129,7 @@ string rt_envvarsOption(string opt, scope rt_configCallBack dg) @nogc nothrow var[4 + i] = cast(char) toupper(c); var[4 + opt.length] = 0; - auto p = getenv(var.ptr); - if (p) + if (auto p = getenv(var.ptr)) { string s = dg(cast(string) p[0 .. strlen(p)]); if (s != null) diff --git a/druntime/src/rt/trace.d b/druntime/src/rt/trace.d index 4cbf071f14e4..8afd7b899a6e 100644 --- a/druntime/src/rt/trace.d +++ b/druntime/src/rt/trace.d @@ -679,8 +679,7 @@ extern(C) void _c_trace_pro(size_t idlen, char* idptr) extern(C) void _c_trace_epi() { //printf("_c_trace_epi()\n"); - auto tos = trace_tos; - if (tos) + if (auto tos = trace_tos) { timer_t endtime; QueryPerformanceCounter(&endtime);