From b5cc51fe4aea574e08c842fa4c37e21e18859df5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Sat, 10 Feb 2024 17:34:18 +0100 Subject: [PATCH] Fix a few scope related deprecation warnings. --- http/vibe/http/common.d | 2 +- http/vibe/http/server.d | 2 +- stream/vibe/stream/multicast.d | 12 ++++++------ utils/vibe/utils/string.d | 2 +- web/vibe/web/common.d | 6 ++++-- 5 files changed, 13 insertions(+), 11 deletions(-) diff --git a/http/vibe/http/common.d b/http/vibe/http/common.d index 037a15b3d0..77a47d8419 100644 --- a/http/vibe/http/common.d +++ b/http/vibe/http/common.d @@ -300,7 +300,7 @@ class HTTPResponse { InetHeaderMap headers; /// All cookies that shall be set on the client for this request - @property ref DictionaryList!Cookie cookies() { return m_cookies; } + @property scope ref DictionaryList!Cookie cookies() return { return m_cookies; } } scope: diff --git a/http/vibe/http/server.d b/http/vibe/http/server.d index f911904111..e0453bd52b 100644 --- a/http/vibe/http/server.d +++ b/http/vibe/http/server.d @@ -1762,7 +1762,7 @@ scope: logTrace("---------------------"); // write cookies - foreach (n, cookie; this.cookies.byKeyValue) { + foreach (n, cookie; () @trusted { return this.cookies.byKeyValue; } ()) { dst.put("Set-Cookie: "); cookie.writeString(() @trusted { return &dst; } (), n); dst.put("\r\n"); diff --git a/stream/vibe/stream/multicast.d b/stream/vibe/stream/multicast.d index 45a012c567..02692ed1fb 100644 --- a/stream/vibe/stream/multicast.d +++ b/stream/vibe/stream/multicast.d @@ -75,10 +75,10 @@ struct MulticastStream(OutputStreams...) { if (m_tasks.length > 0) { Exception ex; foreach (i, T; OutputStreams[1 .. $]) - m_tasks[i] = runTask({ - try m_outputs[i+1].flush(); + m_tasks[i] = runTask((MulticastStream _this) { + try _this.m_outputs[i+1].flush(); catch (Exception e) ex = e; - }); + }, () @trusted { return this; } ()); m_outputs[0].flush(); foreach (t; m_tasks) t.join(); if (ex) throw ex; @@ -95,10 +95,10 @@ struct MulticastStream(OutputStreams...) { if (m_tasks.length > 0) { Exception ex; foreach (i, T; OutputStreams[1 .. $]) - m_tasks[i] = runTask({ - try m_outputs[i+1].write(bytes, mode); + m_tasks[i] = runTask((MulticastStream _this) { + try _this.m_outputs[i+1].write(bytes, mode); catch (Exception e) ex = e; - }); + }, () @trusted { return this; } ()); auto ret = m_outputs[0].write(bytes, mode); foreach (t; m_tasks) t.join(); if (ex) throw ex; diff --git a/utils/vibe/utils/string.d b/utils/vibe/utils/string.d index 482673bd74..e75ce34b49 100644 --- a/utils/vibe/utils/string.d +++ b/utils/vibe/utils/string.d @@ -161,7 +161,7 @@ sizediff_t matchBracket(const(char)[] str, bool nested = true) } /// Same as std.string.format, just using an allocator. -string formatAlloc(ARGS...)(IAllocator alloc, string fmt, ARGS args) +string formatAlloc(ARGS...)(scope IAllocator alloc, string fmt, ARGS args) { auto app = AllocAppender!string(alloc); formattedWrite(() @trusted { return &app; } (), fmt, args); diff --git a/web/vibe/web/common.d b/web/vibe/web/common.d index b7f4ae10d5..2eb7f48063 100644 --- a/web/vibe/web/common.d +++ b/web/vibe/web/common.d @@ -559,10 +559,12 @@ package void defaultSerialize (alias P, T, RT) (ref RT output_range, const scope static struct R { typeof(output_range) underlying; void put(char ch) { underlying.put(ch); } - void put(const(char)[] ch) { underlying.put(cast(const(ubyte)[])ch); } + void put(scope const(char)[] ch) { underlying.put(cast(const(ubyte)[])ch); } } auto dst = R(output_range); - value.serializeWithPolicy!(JsonStringSerializer!R, P) (dst); + // NOTE: serializeWithPolicy does not take value as scope due to issues + // deeply buried in the standard library + () @trusted { return value; } ().serializeWithPolicy!(JsonStringSerializer!R, P) (dst); } package T defaultDeserialize (alias P, T, R) (R input_range)