Skip to content

Commit 8d288d0

Browse files
committed
report const excess time limt as lint
1 parent 9ac3725 commit 8d288d0

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

src/librustc/lint/builtin.rs

+6
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ declare_lint! {
3131
"constant evaluation detected erroneous expression"
3232
}
3333

34+
declare_lint! {
35+
pub CONST_TIME_LIMIT,
36+
Warn,
37+
"constant evaluating a complex constant, this might take some time"
38+
}
39+
3440
declare_lint! {
3541
pub UNUSED_IMPORTS,
3642
Warn,

src/librustc_mir/interpret/step.rs

+23-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
//! The main entry point is the `step` method.
44
55
use rustc::mir;
6+
use rustc::lint;
67

78
use rustc::mir::interpret::EvalResult;
89
use super::{EvalContext, Machine};
@@ -11,8 +12,28 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
1112
pub fn inc_step_counter_and_check_limit(&mut self, n: usize) {
1213
self.terminators_remaining = self.terminators_remaining.saturating_sub(n);
1314
if self.terminators_remaining == 0 {
14-
// FIXME(#49980): make this warning a lint
15-
self.tcx.sess.span_warn(self.frame().span, "Constant evaluating a complex constant, this might take some time");
15+
let msg = "constant evaluating a complex constant, this might take some time";
16+
let lint = ::rustc::lint::builtin::CONST_TIME_LIMIT;
17+
let node_id = self
18+
.stack()
19+
.iter()
20+
.rev()
21+
.filter_map(|frame| frame.lint_root)
22+
.next()
23+
.or(lint_root)
24+
.expect("some part of a failing const eval must be local");
25+
let err = self.tcx.struct_span_lint_node(
26+
lint,
27+
node_id,
28+
self.frame().span,
29+
msg,
30+
);
31+
if self.lint_level_at_node(lint, node_id).0 == lint::Level::Deny ||
32+
self.lint_level_at_node(lint, node_id).0 == lint::Level::Forbid {
33+
err.report_as_err(self.tcx, msg, node_id);
34+
} else {
35+
err.report_as_lint(self.tcx, msg);
36+
}
1637
self.terminators_remaining = 1_000_000;
1738
}
1839
}

0 commit comments

Comments
 (0)