Use a proper future-compatibility lint
This commit is contained in:
parent
085f046c28
commit
5c90dd7978
@ -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,
|
||||
@ -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,
|
||||
|
@ -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> {
|
||||
@ -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)
|
||||
|
@ -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>",
|
||||
|
26
src/test/compile-fail/defaulted-unit-warning.rs
Normal file
26
src/test/compile-fail/defaulted-unit-warning.rs
Normal file
@ -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();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user