@@ -142,29 +142,24 @@ def self.warning?(name, specs: nil)
142142 # are costly (see [Bug #20641]), so we first do a much cheaper check
143143 # to exclude the vast majority of candidates.
144144 if feature . include? ( "/" )
145- # If requiring $LIBDIR/mutex_m.rb, we check SINCE_FAST_PATH["mutex_m"]
146- # We'll fail to warn requires for files that are not the entry point
147- # of the gem, e.g. require "logger/formatter.rb" won't warn.
148- # But that's acceptable because this warning is best effort,
149- # and in the overwhelming majority of cases logger.rb will end
150- # up required.
151- return unless SINCE_FAST_PATH [ File . basename ( feature , ".*" ) ]
145+ # bootsnap expands `require "csv"` to `require "#{LIBDIR}/csv.rb"`,
146+ # and `require "syslog"` to `require "#{ARCHDIR}/syslog.so"`.
147+ name = feature . delete_prefix ( ARCHDIR ) . delete_prefix ( LIBDIR ) . sub ( LIBEXT , "" )
148+ segments = name . split ( "/" )
149+ name = segments . first
150+ if !SINCE [ name ]
151+ name = segments [ 0 ..1 ] . join ( "-" )
152+ return unless SINCE [ name ]
153+ end
152154 else
153- return unless SINCE_FAST_PATH [ feature ]
155+ name = feature . sub ( LIBEXT , "" )
156+ return unless SINCE_FAST_PATH [ name ]
154157 end
155158
156- # bootsnap expands `require "csv"` to `require "#{LIBDIR}/csv.rb"`,
157- # and `require "syslog"` to `require "#{ARCHDIR}/syslog.so"`.
158- name = feature . delete_prefix ( ARCHDIR )
159- name . delete_prefix! ( LIBDIR )
160- name . tr! ( "/" , "-" )
161- name . sub! ( LIBEXT , "" )
162159 return if specs . include? ( name )
163160 _t , path = $:. resolve_feature_path ( feature )
164161 if gem = find_gem ( path )
165162 return if specs . include? ( gem )
166- caller = caller_locations ( 3 , 3 ) &.find { |c | c &.absolute_path }
167- return if find_gem ( caller &.absolute_path )
168163 elsif SINCE [ name ] && !path
169164 gem = true
170165 else
@@ -177,8 +172,6 @@ def self.warning?(name, specs: nil)
177172 gem = name
178173 "#{ feature } was loaded from the standard library, but"
179174 elsif gem
180- return if WARNED [ gem ]
181- WARNED [ gem ] = true
182175 "#{ feature } is found in #{ gem } , which"
183176 else
184177 return
0 commit comments