зеркало из https://github.com/github/ruby.git
Made the warning for deprecated constants follow the category flag
This commit is contained in:
Родитель
76035e5bb6
Коммит
9bf9de3d9d
22
error.c
22
error.c
|
@ -129,32 +129,38 @@ rb_syntax_error_append(VALUE exc, VALUE file, int line, int column,
|
|||
}
|
||||
|
||||
static unsigned int warning_disabled_categories;
|
||||
#define RB_WARN_CATEGORY_DEPRECATED 1
|
||||
|
||||
static unsigned int
|
||||
rb_warning_category_mask(VALUE category)
|
||||
{
|
||||
unsigned int mask = 0;
|
||||
return 1U << rb_warning_category_from_name(category);
|
||||
}
|
||||
|
||||
rb_warning_category_t
|
||||
rb_warning_category_from_name(VALUE category)
|
||||
{
|
||||
rb_warning_category_t cat = RB_WARN_CATEGORY_NONE;
|
||||
Check_Type(category, T_SYMBOL);
|
||||
if (category == ID2SYM(rb_intern("deprecated"))) {
|
||||
mask = RB_WARN_CATEGORY_DEPRECATED;
|
||||
cat = RB_WARN_CATEGORY_DEPRECATED;
|
||||
}
|
||||
else {
|
||||
rb_raise(rb_eArgError, "unknown category: %"PRIsVALUE, category);
|
||||
}
|
||||
return mask;
|
||||
return cat;
|
||||
}
|
||||
|
||||
static int
|
||||
rb_warning_category_enabled_p(VALUE category)
|
||||
MJIT_FUNC_EXPORTED bool
|
||||
rb_warning_category_enabled_p(rb_warning_category_t category)
|
||||
{
|
||||
return !(warning_disabled_categories & rb_warning_category_mask(category));
|
||||
return !(warning_disabled_categories & (1U << category));
|
||||
}
|
||||
|
||||
static VALUE
|
||||
rb_warning_s_aref(VALUE mod, VALUE category)
|
||||
{
|
||||
if (rb_warning_category_enabled_p(category))
|
||||
rb_warning_category_t cat = rb_warning_category_from_name(category);
|
||||
if (rb_warning_category_enabled_p(cat))
|
||||
return Qtrue;
|
||||
return Qfalse;
|
||||
}
|
||||
|
|
|
@ -1554,6 +1554,13 @@ PRINTF_ARGS(void rb_sys_enc_warning(rb_encoding *enc, const char *fmt, ...), 2,
|
|||
PRINTF_ARGS(void rb_syserr_enc_warning(int err, rb_encoding *enc, const char *fmt, ...), 3, 4);
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
RB_WARN_CATEGORY_NONE,
|
||||
RB_WARN_CATEGORY_DEPRECATED,
|
||||
} rb_warning_category_t;
|
||||
rb_warning_category_t rb_warning_category_from_name(VALUE category);
|
||||
bool rb_warning_category_enabled_p(rb_warning_category_t category);
|
||||
|
||||
#define rb_raise_cstr(etype, mesg) \
|
||||
rb_exc_raise(rb_exc_new_str(etype, rb_str_new_cstr(mesg)))
|
||||
#define rb_raise_static(etype, mesg) \
|
||||
|
|
|
@ -28,10 +28,13 @@ class TestModule < Test::Unit::TestCase
|
|||
def setup
|
||||
@verbose = $VERBOSE
|
||||
$VERBOSE = nil
|
||||
@deprecated = Warning[:deprecated]
|
||||
Warning[:deprecated] = true
|
||||
end
|
||||
|
||||
def teardown
|
||||
$VERBOSE = @verbose
|
||||
Warning[:deprecated] = @deprecated
|
||||
end
|
||||
|
||||
def test_LT_0
|
||||
|
@ -1580,6 +1583,8 @@ class TestModule < Test::Unit::TestCase
|
|||
assert_warn(/#{c}::FOO is deprecated/) {Class.new(c)::FOO}
|
||||
bug12382 = '[ruby-core:75505] [Bug #12382]'
|
||||
assert_warn(/deprecated/, bug12382) {c.class_eval "FOO"}
|
||||
Warning[:deprecated] = false
|
||||
assert_warn('') {c::FOO}
|
||||
end
|
||||
|
||||
NIL = nil
|
||||
|
|
|
@ -2302,7 +2302,8 @@ rb_autoload_at_p(VALUE mod, ID id, int recur)
|
|||
MJIT_FUNC_EXPORTED void
|
||||
rb_const_warn_if_deprecated(const rb_const_entry_t *ce, VALUE klass, ID id)
|
||||
{
|
||||
if (RB_CONST_DEPRECATED_P(ce)) {
|
||||
if (RB_CONST_DEPRECATED_P(ce) &&
|
||||
rb_warning_category_enabled_p(RB_WARN_CATEGORY_DEPRECATED)) {
|
||||
if (klass == rb_cObject) {
|
||||
rb_warn("constant ::%"PRIsVALUE" is deprecated", QUOTE_ID(id));
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче