Skip to content

Commit e70f951

Browse files
committed
Use a proper future-compatibility lint
1 parent 4a1f8e9 commit e70f951

File tree

4 files changed

+44
-7
lines changed

4 files changed

+44
-7
lines changed

src/librustc/lint/builtin.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,13 @@ declare_lint! {
192192
"lifetimes or labels named `'_` were erroneously allowed"
193193
}
194194

195+
declare_lint! {
196+
pub RESOLVE_TRAIT_ON_DEFAULTED_UNIT,
197+
Warn,
198+
"attempt to resolve a trait on an expression whose type cannot be inferred but which \
199+
currently defaults to ()"
200+
}
201+
195202
declare_lint! {
196203
pub SAFE_EXTERN_STATICS,
197204
Warn,
@@ -266,6 +273,7 @@ impl LintPass for HardwiredLints {
266273
SUPER_OR_SELF_IN_GLOBAL_PATH,
267274
HR_LIFETIME_IN_ASSOC_TYPE,
268275
LIFETIME_UNDERSCORE,
276+
RESOLVE_TRAIT_ON_DEFAULTED_UNIT,
269277
SAFE_EXTERN_STATICS,
270278
PATTERNS_IN_FNS_WITHOUT_BODY,
271279
EXTRA_REQUIREMENT_IN_IMPL,

src/librustc/traits/select.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ use std::mem;
5252
use std::rc::Rc;
5353
use syntax::abi::Abi;
5454
use hir;
55+
use lint;
5556
use util::nodemap::FxHashMap;
5657

5758
struct InferredObligationsSnapshotVecDelegate<'tcx> {
@@ -459,13 +460,11 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
459460
}
460461

461462
if raise_warning {
462-
let sess = tcx.sess;
463-
let span = obligation.cause.span;
464-
let mut warn = sess.struct_span_warn(span, "code relies on type inference rules \
465-
which are likely to change");
466-
warn.span_label(span, &"the type of this expression may change from () \
467-
to ! in a future version of Rust");
468-
warn.emit();
463+
tcx.sess.add_lint(lint::builtin::RESOLVE_TRAIT_ON_DEFAULTED_UNIT,
464+
obligation.cause.body_id,
465+
obligation.cause.span,
466+
format!("code relies on type inference rules which are likely \
467+
to change"));
469468
}
470469
}
471470
Ok(ret)

src/librustc_lint/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,10 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
221221
id: LintId::of(LIFETIME_UNDERSCORE),
222222
reference: "issue #36892 <https://github.com/rust-lang/rust/issues/36892>",
223223
},
224+
FutureIncompatibleInfo {
225+
id: LintId::of(RESOLVE_TRAIT_ON_DEFAULTED_UNIT),
226+
reference: "issue #39216 <https://github.com/rust-lang/rust/issues/39216>",
227+
},
224228
FutureIncompatibleInfo {
225229
id: LintId::of(SAFE_EXTERN_STATICS),
226230
reference: "issue #36247 <https://github.com/rust-lang/rust/issues/35112>",
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![deny(resolve_trait_on_defaulted_unit)]
12+
13+
trait Deserialize {
14+
fn deserialize() -> Result<Self, String>
15+
}
16+
17+
fn doit() -> Result<(), String> {
18+
let _ = Deserialize::deserialize()?;
19+
//~^ ERROR attempt to resolve a trait
20+
Ok(())
21+
}
22+
23+
fn main() {
24+
doit();
25+
}
26+

0 commit comments

Comments
 (0)