Skip to content

Commit 0ca8e49

Browse files
committed
Convert negate_unsigned feature gate to a warning
1 parent 2250215 commit 0ca8e49

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

src/librustc_lint/builtin.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ use syntax::{abi, ast};
5353
use syntax::ast_util::{self, is_shift_binop, local_def};
5454
use syntax::attr::{self, AttrMetaMethods};
5555
use syntax::codemap::{self, Span};
56-
use syntax::feature_gate::{KNOWN_ATTRIBUTES, AttributeType, emit_feature_err};
56+
use syntax::feature_gate::{KNOWN_ATTRIBUTES, AttributeType};
5757
use syntax::parse::token;
5858
use syntax::ast::{TyIs, TyUs, TyI8, TyU8, TyI16, TyU16, TyI32, TyU32, TyI64, TyU64};
5959
use syntax::ptr::P;
@@ -382,11 +382,13 @@ impl LintPass for TypeLimits {
382382

383383
fn check_unsigned_negation_feature(cx: &Context, span: Span) {
384384
if !cx.sess().features.borrow().negate_unsigned {
385-
emit_feature_err(
386-
&cx.sess().parse_sess.span_diagnostic,
387-
"negate_unsigned",
388-
span,
389-
"unary negation of unsigned integers may be removed in the future");
385+
// FIXME(#27141): change this to syntax::feature_gate::emit_feature_err…
386+
cx.sess().span_warn(span,
387+
"unary negation of unsigned integers will be feature gated in the future");
388+
// …and remove following two expressions.
389+
if option_env!("CFG_DISABLE_UNSTABLE_FEATURES").is_some() { return; }
390+
cx.sess().fileline_help(span, "add #![feature(negate_unsigned)] to the \
391+
crate attributes to enable the gate in advance");
390392
}
391393
}
392394
}

src/test/compile-fail/feature-gate-negate-unsigned.rs src/test/run-pass/feature-gate-negate-unsigned.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,21 @@ impl std::ops::Neg for S {
1818
}
1919

2020
const _MAX: usize = -1;
21-
//~^ ERROR unary negation of unsigned integers may be removed in the future
21+
//~^ WARN unary negation of unsigned integers will be feature gated in the future
2222

2323
fn main() {
2424
let a = -1;
25-
//~^ ERROR unary negation of unsigned integers may be removed in the future
25+
//~^ WARN unary negation of unsigned integers will be feature gated in the future
2626
let _b : u8 = a; // for infering variable a to u8.
2727

2828
-a;
29-
//~^ ERROR unary negation of unsigned integers may be removed in the future
29+
//~^ WARN unary negation of unsigned integers will be feature gated in the future
3030

3131
let _d = -1u8;
32-
//~^ ERROR unary negation of unsigned integers may be removed in the future
32+
//~^ WARN unary negation of unsigned integers will be feature gated in the future
3333

3434
for _ in -10..10u8 {}
35-
//~^ ERROR unary negation of unsigned integers may be removed in the future
35+
//~^ WARN unary negation of unsigned integers will be feature gated in the future
3636

3737
-S; // should not trigger the gate; issue 26840
3838
}

0 commit comments

Comments
 (0)