pw_span: Remove std::span polyfill

Removes the deprecated std::span polyfill, which was only available in
GN and disabled by default.

In a future change, span_common.inc will be merged into pw_span/span.h.

Bug: b/235237667
Change-Id: I0652a295e76c90877d6fbbafa2eae35dcecfacf6
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/108732
Pigweed-Auto-Submit: Wyatt Hepler <hepler@google.com>
Commit-Queue: Auto-Submit <auto-submit@pigweed.google.com.iam.gserviceaccount.com>
Reviewed-by: Armando Montanez <amontanez@google.com>
diff --git a/pw_build/defaults.gni b/pw_build/defaults.gni
index 06b0062..50f52db 100644
--- a/pw_build/defaults.gni
+++ b/pw_build/defaults.gni
@@ -14,8 +14,6 @@
 
 import("//build_overrides/pigweed.gni")
 
-import("$dir_pw_span/polyfill.gni")
-
 declare_args() {
   # Default configs and dependencies targets provided by the toolchain. These
   # are applied to all of the pw_* target types. They are set from a toolchain's
@@ -55,10 +53,6 @@
     "$dir_pw_build:relative_paths",
   ]
 
-  # TODO(b/235237667): Remove this once all uses explicitly depend on polyfills.
-  if (pw_span_ENABLE_STD_SPAN_POLYFILL) {
-    public_deps += [ "$dir_pw_span:polyfill" ]
-  }
   if (pw_build_DEFAULT_VISIBILITY != "*") {
     visibility = pw_build_DEFAULT_VISIBILITY
   }
diff --git a/pw_span/BUILD.bazel b/pw_span/BUILD.bazel
index acf798f..61efc4a 100644
--- a/pw_span/BUILD.bazel
+++ b/pw_span/BUILD.bazel
@@ -30,45 +30,9 @@
     deps = ["//pw_polyfill"],
 )
 
-pw_cc_library(
-    name = "polyfill",
-    srcs = [
-        "public/pw_span/internal/span_common.inc",
-        "public/pw_span/internal/span_polyfill.h",
-    ],
-    hdrs = ["internal_only_include_path_do_not_use/span"],
-    includes = [
-        "internal_only_include_path_do_not_use",
-        "public",
-    ],
-    # Disallow use of the <span> polyfill.
-    visibility = ["//visibility:private"],
-    deps = [
-        "//pw_polyfill",
-        "//pw_polyfill:standard_library",
-    ],
-)
-
-pw_cc_test(
-    name = "polyfill_test",
-    srcs = ["span_test.cc"],
-    defines = [
-        "PW_SPAN_TEST_INCLUDE=<span>",
-        "PW_SPAN_TEST_NAMESPACE=std",
-    ],
-    deps = [
-        ":polyfill",
-        "//pw_unit_test",
-    ],
-)
-
 pw_cc_test(
     name = "pw_span_test",
     srcs = ["span_test.cc"],
-    defines = [
-        'PW_SPAN_TEST_INCLUDE=\\"pw_span/span.h\\"',
-        "PW_SPAN_TEST_NAMESPACE=pw",
-    ],
     deps = [
         ":pw_span",
         "//pw_unit_test",
@@ -78,8 +42,5 @@
 pw_cc_test(
     name = "compatibility_test",
     srcs = ["compatibility_test.cc"],
-    deps = [
-        ":polyfill",
-        ":pw_span",
-    ],
+    deps = [":pw_span"],
 )
diff --git a/pw_span/BUILD.gn b/pw_span/BUILD.gn
index 2b5911d..3fe2c06 100644
--- a/pw_span/BUILD.gn
+++ b/pw_span/BUILD.gn
@@ -16,7 +16,6 @@
 
 import("$dir_pw_build/target_types.gni")
 import("$dir_pw_docgen/docs.gni")
-import("$dir_pw_span/polyfill.gni")
 import("$dir_pw_toolchain/traits.gni")
 import("$dir_pw_unit_test/test.gni")
 
@@ -25,37 +24,12 @@
   visibility = [ ":*" ]
 }
 
-config("polyfill_config") {
-  include_dirs = [ "internal_only_include_path_do_not_use" ]
-
-  if (pw_span_ENABLE_STD_SPAN_POLYFILL) {
-    defines = [ "_PW_SPAN_POLYFILL_ENABLED" ]
-  }
-
-  cflags = [ "-Wno-gnu-include-next" ]
-  visibility = [ ":*" ]
-}
-
 # Provides "pw_span/span.h" and pw::span.
 pw_source_set("pw_span") {
   public = [ "public/pw_span/span.h" ]
   public_deps = [ ":common" ]
 }
 
-# Provides <span> and std::span.
-pw_source_set("polyfill") {
-  public_configs = [ ":polyfill_config" ]
-  public_deps = [ ":common" ]
-  public = [ "internal_only_include_path_do_not_use/span" ]
-  sources = [ "public/pw_span/internal/span_polyfill.h" ]
-
-  if (pw_span_ENABLE_STD_SPAN_POLYFILL) {
-    remove_public_deps = [ "*" ]
-  } else {
-    visibility = [ ":*" ]
-  }
-}
-
 pw_source_set("common") {
   public_configs = [ ":public_config" ]
   public_deps = [ dir_pw_polyfill ]
@@ -71,44 +45,25 @@
 
   sources = [ "public/pw_span/internal/span_common.inc" ]
   visibility = [ ":*" ]
-
-  if (pw_span_ENABLE_STD_SPAN_POLYFILL) {
-    remove_public_deps = [ "*" ]
-  }
 }
 
 pw_test_group("tests") {
   tests = [
-    ":polyfill_test",
     ":pw_span_test",
     ":compatibility_test",
   ]
 }
 
-pw_test("polyfill_test") {
-  deps = [ ":polyfill" ]
-  remove_configs = [ "$dir_pw_build:extra_strict_warnings" ]
-  sources = [ "span_test.cc" ]
-  defines = [
-    "PW_SPAN_TEST_INCLUDE=<span>",
-    "PW_SPAN_TEST_NAMESPACE=std",
-  ]
-}
-
 pw_test("pw_span_test") {
   deps = [ ":pw_span" ]
   remove_configs = [ "$dir_pw_build:extra_strict_warnings" ]
   sources = [ "span_test.cc" ]
-  defines = [
-    "PW_SPAN_TEST_INCLUDE=\"pw_span/span.h\"",
-    "PW_SPAN_TEST_NAMESPACE=pw",
-  ]
 }
 
 pw_test("compatibility_test") {
   deps = [
-    ":polyfill",
     ":pw_span",
+    dir_pw_polyfill,
   ]
   sources = [ "compatibility_test.cc" ]
 }
diff --git a/pw_span/compatibility_test.cc b/pw_span/compatibility_test.cc
index 3c410f4..3f17ad0 100644
--- a/pw_span/compatibility_test.cc
+++ b/pw_span/compatibility_test.cc
@@ -12,6 +12,10 @@
 // License for the specific language governing permissions and limitations under
 // the License.
 
+#include "pw_polyfill/standard.h"
+
+#if PW_CXX_STANDARD_IS_SUPPORTED(20)
+
 #include <span>
 
 #include "gtest/gtest.h"
@@ -69,3 +73,5 @@
 }
 
 }  // namespace
+
+#endif  // PW_CXX_STANDARD_IS_SUPPORTED(20)
diff --git a/pw_span/docs.rst b/pw_span/docs.rst
index c2402a1..2a7dc98 100644
--- a/pw_span/docs.rst
+++ b/pw_span/docs.rst
@@ -11,16 +11,6 @@
 If C++20's ``std::span`` is available, :cpp:class:`pw::span` is simply an alias
 of it.
 
-.. note::
-
- ``pw_span:polyfill`` provides ``<span>`` and a ``std::span`` class. However,
- this ``std::span`` polyfill is DEPRECATED; do NOT use it for new code. Use
- :cpp:class:`pw::span` instead, or ``std::span`` if you are building with C++20.
-
- To use the ``std::span`` polyfill, set the GN arg
- ``pw_span_ENABLE_STD_SPAN_POLYFILL`` to true. This makes ``std::span``
- available and makes :cpp:class:`pw::span` an alias of it.
-
 --------------
 Using pw::span
 --------------
diff --git a/pw_span/internal_only_include_path_do_not_use/span b/pw_span/internal_only_include_path_do_not_use/span
deleted file mode 100644
index ef9216b..0000000
--- a/pw_span/internal_only_include_path_do_not_use/span
+++ /dev/null
@@ -1,28 +0,0 @@
-// Copyright 2020 The Pigweed Authors
-//
-// Licensed under the Apache License, Version 2.0 (the "License"); you may not
-// use this file except in compliance with the License. You may obtain a copy of
-// the License at
-//
-//     https://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-// License for the specific language governing permissions and limitations under
-// the License.
-#pragma once
-
-#if __has_include(<version>)
-#include <version>
-#endif  // __has_include(<version>)
-
-// We are using <span> only if we were able to fetch __cpp_lib_span from
-// <version> and it is at least 202002. In all other cases we are using
-// custom span implementation.
-#if defined(__cpp_lib_span) && __cpp_lib_span >= 202002L
-#include_next <span>
-#else
-#undef __cpp_lib_span
-#include "pw_span/internal/span_polyfill.h"
-#endif  // defined(__cpp_lib_span) && __cpp_lib_span >= 202002L
diff --git a/pw_span/polyfill.gni b/pw_span/polyfill.gni
deleted file mode 100644
index 49d49f1..0000000
--- a/pw_span/polyfill.gni
+++ /dev/null
@@ -1,20 +0,0 @@
-# Copyright 2022 The Pigweed Authors
-#
-# Licensed under the Apache License, Version 2.0 (the "License"); you may not
-# use this file except in compliance with the License. You may obtain a copy of
-# the License at
-#
-#     https://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-# License for the specific language governing permissions and limitations under
-# the License.
-
-declare_args() {
-  # Whether to provide <span> and std::span in the build. This feature is
-  # DEPRECATED and should not be used. Instead, use "pw_span/span.h" and
-  # pw::span in C++17, or std::span in C++20 or newer.
-  pw_span_ENABLE_STD_SPAN_POLYFILL = false
-}
diff --git a/pw_span/span_test.cc b/pw_span/span_test.cc
index 11353b8..ba14551 100644
--- a/pw_span/span_test.cc
+++ b/pw_span/span_test.cc
@@ -23,18 +23,11 @@
 
 // NOLINTBEGIN(modernize-unary-static-assert)
 
-#ifndef PW_SPAN_TEST_INCLUDE
-#error "The PW_SPAN_TEST_INCLUDE macro must be defined to compile this test."
-#endif  // PW_SPAN_TEST_INCLUDE
-
-#ifndef PW_SPAN_TEST_NAMESPACE
-#error "The PW_SPAN_TEST_NAMESPACE macro must be defined to compile this test."
-#endif  // PW_SPAN_TEST_NAMESPACE
+#include "pw_span/span.h"
 
 #include <algorithm>
 #include <cstdint>
 #include <memory>
-#include PW_SPAN_TEST_INCLUDE
 #include <string>
 #include <type_traits>
 #include <vector>
@@ -49,8 +42,7 @@
 using ::testing::Pointwise;
 #endif  // 0
 
-namespace PW_SPAN_TEST_NAMESPACE {
-
+namespace pw {
 namespace {
 
 // constexpr implementation of std::equal's 4 argument overload.
@@ -1657,4 +1649,4 @@
 
 // NOLINTEND(modernize-unary-static-assert)
 
-}  // namespace PW_SPAN_TEST_NAMESPACE
+}  // namespace pw