Skip to content

Commit 996af2c

Browse files
committed
Disable deprecation warning by the default [Feature #16345]
And `-w` option turns it on.
1 parent 83ff0f7 commit 996af2c

19 files changed

Lines changed: 98 additions & 154 deletions

error.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,9 @@ rb_syntax_error_append(VALUE exc, VALUE file, int line, int column,
142142
return exc;
143143
}
144144

145-
static unsigned int warning_disabled_categories;
145+
static unsigned int warning_disabled_categories = (
146+
1U << RB_WARN_CATEGORY_DEPRECATED |
147+
0);
146148

147149
static unsigned int
148150
rb_warning_category_mask(VALUE category)

internal/error.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ typedef enum {
4444
RB_WARN_CATEGORY_NONE,
4545
RB_WARN_CATEGORY_DEPRECATED,
4646
RB_WARN_CATEGORY_EXPERIMENTAL,
47+
RB_WARN_CATEGORY_ALL_BITS = 0x6, /* no RB_WARN_CATEGORY_NONE bit */
4748
} rb_warning_category_t;
4849

4950
extern long rb_backtrace_length_limit;

ruby.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1109,6 +1109,7 @@ proc_options(long argc, char **argv, ruby_cmdline_options_t *opt, int envopt)
11091109
warning = 1;
11101110
ruby_verbose = Qtrue;
11111111
}
1112+
FEATURE_SET(opt->warn, RB_WARN_CATEGORY_ALL_BITS);
11121113
s++;
11131114
goto reswitch;
11141115

@@ -1155,6 +1156,17 @@ proc_options(long argc, char **argv, ruby_cmdline_options_t *opt, int envopt)
11551156
}
11561157
}
11571158
warning = 1;
1159+
switch (v) {
1160+
case 0:
1161+
FEATURE_SET_TO(opt->warn, RB_WARN_CATEGORY_ALL_BITS, 0);
1162+
break;
1163+
case 1:
1164+
FEATURE_SET_TO(opt->warn, 1U << RB_WARN_CATEGORY_DEPRECATED, 0);
1165+
break;
1166+
default:
1167+
FEATURE_SET(opt->warn, RB_WARN_CATEGORY_ALL_BITS);
1168+
break;
1169+
}
11581170
}
11591171
goto reswitch;
11601172

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
require_relative '../../spec_helper'
22

3-
describe "Data" do
4-
it "is a subclass of Object" do
5-
suppress_warning do
6-
Data.superclass.should == Object
3+
ruby_version_is ""..."3.0" do
4+
describe "Data" do
5+
it "is a subclass of Object" do
6+
suppress_warning do
7+
Data.superclass.should == Object
8+
end
79
end
8-
end
910

10-
it "is deprecated" do
11-
-> { Data }.should complain(/constant ::Data is deprecated/)
11+
it "is deprecated" do
12+
-> { Data }.should complain(/constant ::Data is deprecated/)
13+
end
1214
end
1315
end

spec/ruby/core/env/index_spec.rb

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
require_relative '../../spec_helper'
22
require_relative 'shared/key'
33

4-
describe "ENV.index" do
5-
it_behaves_like :env_key, :index
4+
ruby_version_is ""..."3.0" do
5+
describe "ENV.index" do
6+
it_behaves_like :env_key, :index
67

7-
it "warns about deprecation" do
8-
-> do
9-
ENV.index("foo")
10-
end.should complain(/warning: ENV.index is deprecated; use ENV.key/)
8+
it "warns about deprecation" do
9+
-> do
10+
ENV.index("foo")
11+
end.should complain(/warning: ENV.index is deprecated; use ENV.key/)
12+
end
1113
end
1214
end
Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
11
require_relative '../../spec_helper'
22

3-
describe "Fixnum" do
4-
it "is unified into Integer" do
5-
suppress_warning do
6-
Fixnum.should equal(Integer)
3+
ruby_version_is ""..."3.0" do
4+
describe "Fixnum" do
5+
it "is unified into Integer" do
6+
suppress_warning do
7+
Fixnum.should equal(Integer)
8+
end
79
end
8-
end
910

10-
it "is deprecated" do
11-
-> { Fixnum }.should complain(/constant ::Fixnum is deprecated/)
11+
it "is deprecated" do
12+
-> { Fixnum }.should complain(/constant ::Fixnum is deprecated/)
13+
end
1214
end
13-
end
1415

15-
describe "Bignum" do
16-
it "is unified into Integer" do
17-
suppress_warning do
18-
Bignum.should equal(Integer)
16+
describe "Bignum" do
17+
it "is unified into Integer" do
18+
suppress_warning do
19+
Bignum.should equal(Integer)
20+
end
1921
end
20-
end
2122

22-
it "is deprecated" do
23-
-> { Bignum }.should complain(/constant ::Bignum is deprecated/)
23+
it "is deprecated" do
24+
-> { Bignum }.should complain(/constant ::Bignum is deprecated/)
25+
end
2426
end
2527
end

spec/ruby/core/kernel/match_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
end
1515
end
1616

17-
ruby_version_is "2.6" do
17+
ruby_version_is "2.6"..."3.0" do
1818
it "is deprecated" do
1919
-> do
2020
Object.new =~ /regexp/

spec/ruby/core/module/deprecate_constant_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@
1010
@module.private_constant :PRIVATE
1111
@module.deprecate_constant :PRIVATE
1212
@pattern = /deprecated/
13+
if Warning.respond_to?(:[])
14+
@deprecated = Warning[:deprecated]
15+
Warning[:deprecated] = true
16+
end
17+
end
18+
19+
after :each do
20+
if Warning.respond_to?(:[])
21+
Warning[:deprecated] = @deprecated
22+
end
1323
end
1424

1525
describe "when accessing the deprecated module" do

spec/ruby/language/predefined_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,7 @@ def foo
654654
-> { $, = Object.new }.should raise_error(TypeError)
655655
end
656656

657-
ruby_version_is "2.7" do
657+
ruby_version_is "2.7"..."3.0" do
658658
it "warns if assigned non-nil" do
659659
-> { $, = "_" }.should complain(/warning: `\$,' is deprecated/)
660660
end
@@ -693,7 +693,7 @@ def foo
693693
$; = nil
694694
end
695695

696-
ruby_version_is "2.7" do
696+
ruby_version_is "2.7"..."3.0" do
697697
it "warns if assigned non-nil" do
698698
-> { $; = "_" }.should complain(/warning: `\$;' is deprecated/)
699699
end

spec/ruby/library/net/http/HTTPServerException_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
end
1414
end
1515

16-
ruby_version_is "2.6" do
16+
ruby_version_is "2.6"..."3.0" do
1717
describe "Net::HTTPServerException" do
1818
it "is a subclass of Net::ProtoServerError and is warned as deprecated" do
1919
-> { Net::HTTPServerException.should < Net::ProtoServerError }.should complain(/warning: constant Net::HTTPServerException is deprecated/)

0 commit comments

Comments
 (0)