diff --git a/NEWS.md b/NEWS.md index 9712152da6a7b9..8ac808c2e7b6a4 100644 --- a/NEWS.md +++ b/NEWS.md @@ -11,6 +11,11 @@ Note that each entry is kept to a minimum, see links for details. Note: We're only listing outstanding class updates. +* Set + + * A deprecated behavior, `Set#to_set`, `Range#to_set`, and + `Enumerable#to_set` accepting arguments, was removed. [[Feature #21390]] + ## Stdlib updates We only list stdlib changes that are notable feature changes. @@ -61,3 +66,4 @@ A lot of work has gone into making Ractors more stable, performant, and usable. ## JIT +[Feature #21390]: https://bugs.ruby-lang.org/issues/21390 diff --git a/benchmark/set.yml b/benchmark/set.yml index 43217036e25ba5..061509cb1f72a9 100644 --- a/benchmark/set.yml +++ b/benchmark/set.yml @@ -259,7 +259,3 @@ benchmark: to_set_10: s1.to_set to_set_100: s2.to_set to_set_1000: s3.to_set - to_set_arg_0: s0.to_set set_subclass - to_set_arg_10: s1.to_set set_subclass - to_set_arg_100: s2.to_set set_subclass - to_set_arg_1000: s3.to_set set_subclass diff --git a/include/ruby/internal/core/rtypeddata.h b/include/ruby/internal/core/rtypeddata.h index 7d7df6c01a2d3b..55b7d2b47dc27f 100644 --- a/include/ruby/internal/core/rtypeddata.h +++ b/include/ruby/internal/core/rtypeddata.h @@ -476,7 +476,7 @@ RBIMPL_SYMBOL_EXPORT_END() */ #define TypedData_Make_Struct0(result, klass, type, size, data_type, sval) \ VALUE result = rb_data_typed_object_zalloc(klass, size, data_type); \ - (sval) = (type *)RTYPEDDATA_GET_DATA(result); \ + (sval) = RBIMPL_CAST((type *)RTYPEDDATA_GET_DATA(result)); \ RBIMPL_CAST(/*suppress unused variable warnings*/(void)(sval)) /** @@ -594,7 +594,7 @@ RBIMPL_ATTR_ARTIFICIAL() * @return Data type struct that corresponds to `obj`. * @pre `obj` must be an instance of ::RTypedData. */ -static inline const struct rb_data_type_struct * +static inline const rb_data_type_t * RTYPEDDATA_TYPE(VALUE obj) { #if RUBY_DEBUG @@ -604,7 +604,8 @@ RTYPEDDATA_TYPE(VALUE obj) } #endif - return (const struct rb_data_type_struct *)(RTYPEDDATA(obj)->type & TYPED_DATA_PTR_MASK); + VALUE type = RTYPEDDATA(obj)->type & TYPED_DATA_PTR_MASK; + return RBIMPL_CAST((const rb_data_type_t *)type); } RBIMPL_ATTR_ARTIFICIAL() diff --git a/lib/set/subclass_compatible.rb b/lib/set/subclass_compatible.rb index ab0aedc0e5bafd..f43c34f6a2bd35 100644 --- a/lib/set/subclass_compatible.rb +++ b/lib/set/subclass_compatible.rb @@ -69,15 +69,9 @@ def replace(enum) end end - def to_set(*args, &block) - klass = if args.empty? - Set - else - warn "passing arguments to Enumerable#to_set is deprecated", uplevel: 1 - args.shift - end - return self if instance_of?(Set) && klass == Set && block.nil? && args.empty? - klass.new(self, *args, &block) + def to_set(&block) + return self if instance_of?(Set) && block.nil? + Set.new(self, &block) end def flatten_merge(set, seen = {}) # :nodoc: diff --git a/prelude.rb b/prelude.rb index 36da381804e6a7..7b5a7668982a93 100644 --- a/prelude.rb +++ b/prelude.rb @@ -30,14 +30,7 @@ def pp(*objs) module Enumerable # Makes a set from the enumerable object with given arguments. - # Passing arguments to this method is deprecated. - def to_set(*args, &block) - klass = if args.empty? - Set - else - warn "passing arguments to Enumerable#to_set is deprecated", uplevel: 1 - args.shift - end - klass.new(self, *args, &block) + def to_set(&block) + Set.new(self, &block) end end diff --git a/range.c b/range.c index 82c252e3ef50cd..7aa917bc067b68 100644 --- a/range.c +++ b/range.c @@ -1033,12 +1033,12 @@ range_to_a(VALUE range) * */ static VALUE -range_to_set(int argc, VALUE *argv, VALUE range) +range_to_set(VALUE range) { if (NIL_P(RANGE_END(range))) { rb_raise(rb_eRangeError, "cannot convert endless range to a set"); } - return rb_call_super(argc, argv); + return rb_call_super(0, NULL); } static VALUE @@ -2868,7 +2868,7 @@ Init_Range(void) rb_define_method(rb_cRange, "minmax", range_minmax, 0); rb_define_method(rb_cRange, "size", range_size, 0); rb_define_method(rb_cRange, "to_a", range_to_a, 0); - rb_define_method(rb_cRange, "to_set", range_to_set, -1); + rb_define_method(rb_cRange, "to_set", range_to_set, 0); rb_define_method(rb_cRange, "entries", range_to_a, 0); rb_define_method(rb_cRange, "to_s", range_to_s, 0); rb_define_method(rb_cRange, "inspect", range_inspect, 0); diff --git a/set.c b/set.c index d7704e9cf38a4f..4d8178ffc080de 100644 --- a/set.c +++ b/set.c @@ -648,36 +648,22 @@ set_i_to_a(VALUE set) /* * call-seq: - * to_set(klass = Set, *args, &block) -> self or new_set + * to_set(&block) -> self or new_set * - * Without arguments, returns +self+ (for duck-typing in methods that - * accept "set, or set-convertible" arguments). + * Without a block, if +self+ is an instance of +Set+, returns +self+. + * Otherwise, calls Set.new(self, &block). * * A form with arguments is _deprecated_. It converts the set to another * with klass.new(self, *args, &block). */ static VALUE -set_i_to_set(int argc, VALUE *argv, VALUE set) +set_i_to_set(VALUE set) { - VALUE klass; - - if (argc == 0) { - klass = rb_cSet; - argv = &set; - argc = 1; - } - else { - rb_warn_deprecated("passing arguments to Set#to_set", NULL); - klass = argv[0]; - argv[0] = set; - } - - if (klass == rb_cSet && rb_obj_is_instance_of(set, rb_cSet) && - argc == 1 && !rb_block_given_p()) { + if (rb_obj_is_instance_of(set, rb_cSet) && !rb_block_given_p()) { return set; } - return rb_funcall_passing_block(klass, id_new, argc, argv); + return rb_funcall_passing_block(rb_cSet, id_new, 0, NULL); } /* @@ -2292,7 +2278,7 @@ Init_Set(void) rb_define_method(rb_cSet, "superset?", set_i_superset, 1); rb_define_alias(rb_cSet, ">=", "superset?"); rb_define_method(rb_cSet, "to_a", set_i_to_a, 0); - rb_define_method(rb_cSet, "to_set", set_i_to_set, -1); + rb_define_method(rb_cSet, "to_set", set_i_to_set, 0); /* :nodoc: */ VALUE compat = rb_define_class_under(rb_cSet, "compatible", rb_cObject); diff --git a/spec/ruby/core/enumerable/to_set_spec.rb b/spec/ruby/core/enumerable/to_set_spec.rb index e1fcd3a20d0273..91499aeb5b180c 100644 --- a/spec/ruby/core/enumerable/to_set_spec.rb +++ b/spec/ruby/core/enumerable/to_set_spec.rb @@ -11,7 +11,7 @@ [1, 2, 3].to_set { |x| x * x }.should == Set[1, 4, 9] end - ruby_version_is "4.0" do + ruby_version_is "4.0"..."4.1" do it "instantiates an object of provided as the first argument set class" do set = nil proc{set = [1, 2, 3].to_set(EnumerableSpecs::SetSubclass)}.should complain(/Enumerable#to_set/)