diff --git a/lib/rubygems.rb b/lib/rubygems.rb index 610ef6c83f75..cd3ea9241536 100644 --- a/lib/rubygems.rb +++ b/lib/rubygems.rb @@ -119,6 +119,10 @@ module Gem # to avoid deprecation warnings in Ruby 2.7. UNTAINT = RUBY_VERSION < '2.7' ? :untaint.to_sym : proc{} + # When https://bugs.ruby-lang.org/issues/17259 is available, there is no need to override Kernel#warn + KERNEL_WARN_IGNORES_INTERNAL_ENTRIES = RUBY_ENGINE == "truffleruby" || + (RUBY_ENGINE == "ruby" && RUBY_VERSION >= '3.0') + ## # An Array of Regexps that match windows Ruby platforms. diff --git a/lib/rubygems/core_ext/kernel_require.rb b/lib/rubygems/core_ext/kernel_require.rb index edf046651e7a..4b867c55e951 100644 --- a/lib/rubygems/core_ext/kernel_require.rb +++ b/lib/rubygems/core_ext/kernel_require.rb @@ -17,6 +17,8 @@ module Kernel private :gem_original_require end + file = Gem::KERNEL_WARN_IGNORES_INTERNAL_ENTRIES ? "" : __FILE__ + module_eval <<'RUBY', file, __LINE__ + 1 ## # When RubyGems is required, Kernel#require is replaced with our own which # is capable of loading gems on demand. @@ -166,6 +168,7 @@ def require(path) end end end +RUBY private :require diff --git a/lib/rubygems/core_ext/kernel_warn.rb b/lib/rubygems/core_ext/kernel_warn.rb index b468813ce722..3373cfdd3b29 100644 --- a/lib/rubygems/core_ext/kernel_warn.rb +++ b/lib/rubygems/core_ext/kernel_warn.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true # `uplevel` keyword argument of Kernel#warn is available since ruby 2.5. -if RUBY_VERSION >= "2.5" +if RUBY_VERSION >= "2.5" && !Gem::KERNEL_WARN_IGNORES_INTERNAL_ENTRIES module Kernel rubygems_path = "#{__dir__}/" # Frames to be skipped start with this path. diff --git a/test/rubygems/test_require.rb b/test/rubygems/test_require.rb index d65b6c9527de..8c7d06edc3c1 100644 --- a/test/rubygems/test_require.rb +++ b/test/rubygems/test_require.rb @@ -709,7 +709,7 @@ def deprecated RUBY _, err = capture_subprocess_io do - system(*ruby_with_rubygems_in_load_path, "-w", "--enable=gems", "-C", dir, "-I", dir, "main.rb") + system(*ruby_with_rubygems_in_load_path, "-w", "--disable=gems", "-C", dir, "-I", dir, "main.rb") end assert_match(/main\.rb:2: warning: This is a deprecated method$/, err) _, err = capture_subprocess_io do