Skip to content

Commit

Permalink
Use a proper future-compatibility lint
Browse files Browse the repository at this point in the history
  • Loading branch information
canndrew committed Feb 3, 2017
1 parent 085f046 commit 5c90dd7
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 7 deletions.
8 changes: 8 additions & 0 deletions src/librustc/lint/builtin.rs
Expand Up @@ -192,6 +192,13 @@ declare_lint! {
"lifetimes or labels named `'_` were erroneously allowed"
}

declare_lint! {
pub RESOLVE_TRAIT_ON_DEFAULTED_UNIT,
Warn,
"attempt to resolve a trait on an expression whose type cannot be inferred but which \
currently defaults to ()"
}

declare_lint! {
pub SAFE_EXTERN_STATICS,
Warn,
Expand Down Expand Up @@ -272,6 +279,7 @@ impl LintPass for HardwiredLints {
SUPER_OR_SELF_IN_GLOBAL_PATH,
HR_LIFETIME_IN_ASSOC_TYPE,
LIFETIME_UNDERSCORE,
RESOLVE_TRAIT_ON_DEFAULTED_UNIT,
SAFE_EXTERN_STATICS,
PATTERNS_IN_FNS_WITHOUT_BODY,
EXTRA_REQUIREMENT_IN_IMPL,
Expand Down
13 changes: 6 additions & 7 deletions src/librustc/traits/select.rs
Expand Up @@ -52,6 +52,7 @@ use std::mem;
use std::rc::Rc;
use syntax::abi::Abi;
use hir;
use lint;
use util::nodemap::FxHashMap;

struct InferredObligationsSnapshotVecDelegate<'tcx> {
Expand Down Expand Up @@ -455,13 +456,11 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
}

if raise_warning {
let sess = tcx.sess;
let span = obligation.cause.span;
let mut warn = sess.struct_span_warn(span, "code relies on type inference rules \
which are likely to change");
warn.span_label(span, &"the type of this expression may change from () \
to ! in a future version of Rust");
warn.emit();
tcx.sess.add_lint(lint::builtin::RESOLVE_TRAIT_ON_DEFAULTED_UNIT,
obligation.cause.body_id,
obligation.cause.span,
format!("code relies on type inference rules which are likely \
to change"));
}
}
Ok(ret)
Expand Down
4 changes: 4 additions & 0 deletions src/librustc_lint/lib.rs
Expand Up @@ -220,6 +220,10 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
id: LintId::of(LIFETIME_UNDERSCORE),
reference: "issue #36892 <https://github.com/rust-lang/rust/issues/36892>",
},
FutureIncompatibleInfo {
id: LintId::of(RESOLVE_TRAIT_ON_DEFAULTED_UNIT),
reference: "issue #39216 <https://github.com/rust-lang/rust/issues/39216>",
},
FutureIncompatibleInfo {
id: LintId::of(SAFE_EXTERN_STATICS),
reference: "issue #36247 <https://github.com/rust-lang/rust/issues/35112>",
Expand Down
26 changes: 26 additions & 0 deletions src/test/compile-fail/defaulted-unit-warning.rs
@@ -0,0 +1,26 @@
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![deny(resolve_trait_on_defaulted_unit)]

trait Deserialize {
fn deserialize() -> Result<Self, String>
}

fn doit() -> Result<(), String> {
let _ = Deserialize::deserialize()?;
//~^ ERROR attempt to resolve a trait
Ok(())
}

fn main() {
doit();
}

0 comments on commit 5c90dd7

Please sign in to comment.