Fix usage with std::generator
Fixes #4053

Tested on (docker image) Ubuntu 24.04 with gcc 14
{"label": "fmtlib:master", "ref": "master", "sha": "ccea338070c795fd966a4dc08b19268b6fbad5ef"}
```cpp
#include <fmt/ranges.h>
#include <sstream>
#include <generator>

std::generator<std::string&> istream_gen() {
  auto words = std::istringstream{"today is yesterday's tomorrow"};
  std::string word;
  while (words >> word)
    co_yield word;
}

int main() {
  fmt::print("{}\n", istream_gen());
}
```

https://godbolt.org/z/s7sGrGvzd
trunk doesn't work with `std::generator`
diff --git a/include/fmt/ranges.h b/include/fmt/ranges.h
index f387903cf634..0d3dfbd8d378 100644
--- a/include/fmt/ranges.h
+++ b/include/fmt/ranges.h
@@ -490,7 +490,7 @@ struct range_formatter<
     auto out = ctx.out();
     auto it = detail::range_begin(range);
     auto end = detail::range_end(range);
-    if (is_debug) return write_debug_string(out, it, end);
+    if (is_debug) return write_debug_string(out, std::move(it), end);
 
     out = detail::copy<Char>(opening_bracket_, out);
     int i = 0;

diff --git a/test/ranges-test.cc b/test/ranges-test.cc
index ab94209fa436..1a5b5a706321 100644
--- a/test/ranges-test.cc
+++ b/test/ranges-test.cc
@@ -752,17 +752,17 @@ TEST(ranges_test, std_istream_iterator_join) {
   EXPECT_EQ("1, 2, 3, 4, 5", fmt::format("{}", fmt::join(first, last, ", ")));
 }
 
-TEST(ranges_test, movable_only_istream_iter_join) {
-  // Mirrors C++20 std::ranges::basic_istream_view::iterator.
-  struct noncopyable_istream_iterator : std::istream_iterator<int> {
-    explicit noncopyable_istream_iterator(std::istringstream& iss)
-        : std::istream_iterator<int>{iss} {}
-    noncopyable_istream_iterator(const noncopyable_istream_iterator&) = delete;
-    noncopyable_istream_iterator(noncopyable_istream_iterator&&) = default;
-  };
-  static_assert(
-      !std::is_copy_constructible<noncopyable_istream_iterator>::value, "");
+// Mirrors C++20 std::ranges::basic_istream_view::iterator.
+struct noncopyable_istream_iterator : std::istream_iterator<int> {
+  using base = std::istream_iterator<int>;
+  explicit noncopyable_istream_iterator(std::istringstream& iss) : base{iss} {}
+  noncopyable_istream_iterator(const noncopyable_istream_iterator&) = delete;
+  noncopyable_istream_iterator(noncopyable_istream_iterator&&) = default;
+};
+static_assert(!std::is_copy_constructible<noncopyable_istream_iterator>::value,
+              "");
 
+TEST(ranges_test, movable_only_istream_iter_join) {
   auto&& iss = std::istringstream("1 2 3 4 5");
   auto first = noncopyable_istream_iterator(iss);
   auto last = std::istream_iterator<int>();
@@ -770,6 +770,18 @@ TEST(ranges_test, movable_only_istream_iter_join) {
             fmt::format("{}", fmt::join(std::move(first), last, ", ")));
 }
 
+struct movable_iter_range {
+  std::istringstream iss{"1 2 3 4 5"};
+  noncopyable_istream_iterator begin() {
+    return noncopyable_istream_iterator{iss};
+  }
+  std::istream_iterator<int> end() { return {}; }
+};
+
+TEST(ranges_test, movable_only_istream_iter_join2) {
+  EXPECT_EQ("[1, 2, 3, 4, 5]", fmt::format("{}", movable_iter_range{}));
+}
+
 struct not_range {
   void begin() const {}
   void end() const {}

{"compile-test": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "ostream-test": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "ranges-test": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "std-test": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "scan-test": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "color-test": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "chrono-test": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "format-test": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "gtest-extra-test": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "args-test": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "compile-fp-test": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "unicode-test": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "assert-test": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "posix-mock-test": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "base-test": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "printf-test": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "enforce-checks-test": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "format-impl-test": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "os-test": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "xchar-test": {"run": "PASS", "test": "NONE", "fix": "PASS"}}
{"compile-test": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "ostream-test": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "ranges-test": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "std-test": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "scan-test": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "color-test": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "chrono-test": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "format-test": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "gtest-extra-test": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "args-test": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "compile-fp-test": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "unicode-test": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "assert-test": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "posix-mock-test": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "base-test": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "printf-test": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "enforce-checks-test": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "format-impl-test": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "os-test": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "xchar-test": {"run": "PASS", "test": "NONE", "fix": "PASS"}}
{"passed_count": 20, "failed_count": 0, "skipped_count": 0, "passed_tests": ["compile-test", "chrono-test", "gtest-extra-test", "compile-fp-test", "unicode-test", "assert-test", "base-test", "enforce-checks-test", "format-impl-test", "os-test", "xchar-test", "ostream-test", "ranges-test", "std-test", "scan-test", "color-test", "format-test", "args-test", "posix-mock-test", "printf-test"], "failed_tests": [], "skipped_tests": []}
{"passed_count": 0, "failed_count": 0, "skipped_count": 0, "passed_tests": [], "failed_tests": [], "skipped_tests": []}
{"passed_count": 20, "failed_count": 0, "skipped_count": 0, "passed_tests": ["compile-test", "chrono-test", "gtest-extra-test", "compile-fp-test", "unicode-test", "assert-test", "base-test", "enforce-checks-test", "format-impl-test", "os-test", "xchar-test", "ostream-test", "ranges-test", "std-test", "scan-test", "color-test", "format-test", "args-test", "posix-mock-test", "printf-test"], "failed_tests": [], "skipped_tests": []}