Skip to content

Commit 5c90dd7

Browse files
committed
Use a proper future-compatibility lint
1 parent 085f046 commit 5c90dd7

File tree

4 files changed

+44
-7
lines changed

4 files changed

+44
-7
lines changed

src/librustc/lint/builtin.rs

+8
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,
@@ -272,6 +279,7 @@ impl LintPass for HardwiredLints {
272279
SUPER_OR_SELF_IN_GLOBAL_PATH,
273280
HR_LIFETIME_IN_ASSOC_TYPE,
274281
LIFETIME_UNDERSCORE,
282+
RESOLVE_TRAIT_ON_DEFAULTED_UNIT,
275283
SAFE_EXTERN_STATICS,
276284
PATTERNS_IN_FNS_WITHOUT_BODY,
277285
EXTRA_REQUIREMENT_IN_IMPL,

src/librustc/traits/select.rs

+6-7
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> {
@@ -455,13 +456,11 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
455456
}
456457

457458
if raise_warning {
458-
let sess = tcx.sess;
459-
let span = obligation.cause.span;
460-
let mut warn = sess.struct_span_warn(span, "code relies on type inference rules \
461-
which are likely to change");
462-
warn.span_label(span, &"the type of this expression may change from () \
463-
to ! in a future version of Rust");
464-
warn.emit();
459+
tcx.sess.add_lint(lint::builtin::RESOLVE_TRAIT_ON_DEFAULTED_UNIT,
460+
obligation.cause.body_id,
461+
obligation.cause.span,
462+
format!("code relies on type inference rules which are likely \
463+
to change"));
465464
}
466465
}
467466
Ok(ret)

src/librustc_lint/lib.rs

+4
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,10 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
220220
id: LintId::of(LIFETIME_UNDERSCORE),
221221
reference: "issue #36892 <https://github.com/rust-lang/rust/issues/36892>",
222222
},
223+
FutureIncompatibleInfo {
224+
id: LintId::of(RESOLVE_TRAIT_ON_DEFAULTED_UNIT),
225+
reference: "issue #39216 <https://github.com/rust-lang/rust/issues/39216>",
226+
},
223227
FutureIncompatibleInfo {
224228
id: LintId::of(SAFE_EXTERN_STATICS),
225229
reference: "issue #36247 <https://github.com/rust-lang/rust/issues/35112>",
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)