[前][次][番号順一覧][スレッド一覧]

ruby-changes:59331

From: Nobuyoshi <ko1@a...>
Date: Thu, 19 Dec 2019 10:32:34 +0900 (JST)
Subject: [ruby-changes:59331] c6c67254fb (master): Added rb_warn_deprecated

https://git.ruby-lang.org/ruby.git/commit/?id=c6c67254fb

From c6c67254fb17b3196a7b0d3fda4650f6b20a467d Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Tue, 17 Dec 2019 17:17:07 +0900
Subject: Added rb_warn_deprecated


diff --git a/enumerator.c b/enumerator.c
index e85c911..73bca61 100644
--- a/enumerator.c
+++ b/enumerator.c
@@ -466,7 +466,7 @@ enumerator_initialize(int argc, VALUE *argv, VALUE obj) https://github.com/ruby/ruby/blob/trunk/enumerator.c#L466
     }
     else {
 	rb_check_arity(argc, 1, UNLIMITED_ARGUMENTS);
-	rb_warn("Enumerator.new without a block is deprecated; use Object#to_enum");
+	rb_warn_deprecated("Enumerator.new without a block", "Object#to_enum");
 	recv = *argv++;
 	if (--argc) {
 	    meth = *argv++;
diff --git a/error.c b/error.c
index 4cb17df..e5dc0c3 100644
--- a/error.c
+++ b/error.c
@@ -325,6 +325,22 @@ rb_enc_warning(rb_encoding *enc, const char *fmt, ...) https://github.com/ruby/ruby/blob/trunk/error.c#L325
 }
 #endif
 
+void
+rb_warn_deprecated(const char *fmt, const char *suggest, ...)
+{
+    if (NIL_P(ruby_verbose)) return;
+    if (!rb_warning_category_enabled_p(RB_WARN_CATEGORY_DEPRECATED)) return;
+    va_list args;
+    va_start(args, suggest);
+    VALUE mesg = warning_string(0, fmt, args);
+    va_end(args);
+    rb_str_set_len(mesg, RSTRING_LEN(mesg) - 1);
+    rb_str_cat_cstr(mesg, " is deprecated");
+    if (suggest) rb_str_catf(mesg, "; use %s instead", suggest);
+    rb_str_cat_cstr(mesg, "\n");
+    rb_write_warning_str(mesg);
+}
+
 static inline int
 end_with_asciichar(VALUE str, int c)
 {
diff --git a/hash.c b/hash.c
index 27d1d03..79f69f6 100644
--- a/hash.c
+++ b/hash.c
@@ -2245,7 +2245,7 @@ rb_hash_key(VALUE hash, VALUE value) https://github.com/ruby/ruby/blob/trunk/hash.c#L2245
 static VALUE
 rb_hash_index(VALUE hash, VALUE value)
 {
-    rb_warn("Hash#index is deprecated; use Hash#key");
+    rb_warn_deprecated("Hash#index", "Hash#key");
     return rb_hash_key(hash, value);
 }
 
@@ -5861,7 +5861,7 @@ env_key(VALUE dmy, VALUE value) https://github.com/ruby/ruby/blob/trunk/hash.c#L5861
 static VALUE
 env_index(VALUE dmy, VALUE value)
 {
-    rb_warn("ENV.index is deprecated; use ENV.key");
+    rb_warn_deprecated("ENV.index", "ENV.key");
     return env_key(dmy, value);
 }
 
diff --git a/internal.h b/internal.h
index fc2ff0e..2812b63 100644
--- a/internal.h
+++ b/internal.h
@@ -1547,6 +1547,7 @@ void rb_report_bug_valist(VALUE file, int line, const char *fmt, va_list args); https://github.com/ruby/ruby/blob/trunk/internal.h#L1547
 NORETURN(void rb_async_bug_errno(const char *,int));
 const char *rb_builtin_type_name(int t);
 const char *rb_builtin_class_name(VALUE x);
+PRINTF_ARGS(void rb_warn_deprecated(const char *fmt, const char *suggest, ...), 1, 3);
 #ifdef RUBY_ENCODING_H
 VALUE rb_syntax_error_append(VALUE, VALUE, int, int, rb_encoding*, const char*, va_list);
 PRINTF_ARGS(void rb_enc_warn(rb_encoding *enc, const char *fmt, ...), 2, 3);
diff --git a/io.c b/io.c
index eaaccbb..caef68c 100644
--- a/io.c
+++ b/io.c
@@ -3810,7 +3810,7 @@ rb_io_each_line(int argc, VALUE *argv, VALUE io) https://github.com/ruby/ruby/blob/trunk/io.c#L3810
 static VALUE
 rb_io_lines(int argc, VALUE *argv, VALUE io)
 {
-    rb_warn("IO#lines is deprecated; use #each_line instead");
+    rb_warn_deprecated("IO#lines", "#each_line");
     if (!rb_block_given_p())
 	return rb_enumeratorize(io, ID2SYM(rb_intern("each_line")), argc, argv);
     return rb_io_each_line(argc, argv, io);
@@ -3861,7 +3861,7 @@ rb_io_each_byte(VALUE io) https://github.com/ruby/ruby/blob/trunk/io.c#L3861
 static VALUE
 rb_io_bytes(VALUE io)
 {
-    rb_warn("IO#bytes is deprecated; use #each_byte instead");
+    rb_warn_deprecated("IO#bytes", "#each_byte");
     if (!rb_block_given_p())
 	return rb_enumeratorize(io, ID2SYM(rb_intern("each_byte")), 0, 0);
     return rb_io_each_byte(io);
@@ -4015,7 +4015,7 @@ rb_io_each_char(VALUE io) https://github.com/ruby/ruby/blob/trunk/io.c#L4015
 static VALUE
 rb_io_chars(VALUE io)
 {
-    rb_warn("IO#chars is deprecated; use #each_char instead");
+    rb_warn_deprecated("IO#chars", "#each_char");
     if (!rb_block_given_p())
 	return rb_enumeratorize(io, ID2SYM(rb_intern("each_char")), 0, 0);
     return rb_io_each_char(io);
@@ -4143,7 +4143,7 @@ rb_io_each_codepoint(VALUE io) https://github.com/ruby/ruby/blob/trunk/io.c#L4143
 static VALUE
 rb_io_codepoints(VALUE io)
 {
-    rb_warn("IO#codepoints is deprecated; use #each_codepoint instead");
+    rb_warn_deprecated("IO#codepoints", "#each_codepoint");
     if (!rb_block_given_p())
 	return rb_enumeratorize(io, ID2SYM(rb_intern("each_codepoint")), 0, 0);
     return rb_io_each_codepoint(io);
@@ -12479,7 +12479,7 @@ argf_each_line(int argc, VALUE *argv, VALUE argf) https://github.com/ruby/ruby/blob/trunk/io.c#L12479
 static VALUE
 argf_lines(int argc, VALUE *argv, VALUE argf)
 {
-    rb_warn("ARGF#lines is deprecated; use #each_line instead");
+    rb_warn_deprecated("ARGF#lines", "#each_line");
     if (!rb_block_given_p())
 	return rb_enumeratorize(argf, ID2SYM(rb_intern("each_line")), argc, argv);
     return argf_each_line(argc, argv, argf);
@@ -12526,7 +12526,7 @@ argf_each_byte(VALUE argf) https://github.com/ruby/ruby/blob/trunk/io.c#L12526
 static VALUE
 argf_bytes(VALUE argf)
 {
-    rb_warn("ARGF#bytes is deprecated; use #each_byte instead");
+    rb_warn_deprecated("ARGF#bytes", "#each_byte");
     if (!rb_block_given_p())
 	return rb_enumeratorize(argf, ID2SYM(rb_intern("each_byte")), 0, 0);
     return argf_each_byte(argf);
@@ -12565,7 +12565,7 @@ argf_each_char(VALUE argf) https://github.com/ruby/ruby/blob/trunk/io.c#L12565
 static VALUE
 argf_chars(VALUE argf)
 {
-    rb_warn("ARGF#chars is deprecated; use #each_char instead");
+    rb_warn_deprecated("ARGF#chars", "#each_char");
     if (!rb_block_given_p())
 	return rb_enumeratorize(argf, ID2SYM(rb_intern("each_char")), 0, 0);
     return argf_each_char(argf);
@@ -12604,7 +12604,7 @@ argf_each_codepoint(VALUE argf) https://github.com/ruby/ruby/blob/trunk/io.c#L12604
 static VALUE
 argf_codepoints(VALUE argf)
 {
-    rb_warn("ARGF#codepoints is deprecated; use #each_codepoint instead");
+    rb_warn_deprecated("ARGF#codepoints", "#each_codepoint");
     if (!rb_block_given_p())
 	return rb_enumeratorize(argf, ID2SYM(rb_intern("each_codepoint")), 0, 0);
     return argf_each_codepoint(argf);
diff --git a/proc.c b/proc.c
index b1b6735..54b044f 100644
--- a/proc.c
+++ b/proc.c
@@ -758,8 +758,8 @@ proc_new(VALUE klass, int8_t is_lambda, int8_t kernel) https://github.com/ruby/ruby/blob/trunk/proc.c#L758
             }
             else {
                 const char *name = kernel ? "Kernel#proc" : "Proc.new";
-                rb_warn("Capturing the given block using %s is deprecated; "
-                        "use `&block` instead", name);
+                rb_warn_deprecated("Capturing the given block using %s",
+                                   "`&block`", name);
 	    }
 	}
 #else
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]