Skip to content

Commit

Permalink
Convert warning about *const _ to a future-compat lint
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeyhew committed Dec 22, 2017
1 parent b7b52cc commit 0783db9
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 13 deletions.
9 changes: 8 additions & 1 deletion src/librustc/lint/builtin.rs
Expand Up @@ -240,6 +240,12 @@ declare_lint! {
"detects single use lifetimes"
}

declare_lint! {
pub TYVAR_BEHIND_RAW_POINTER,
Warn,
"raw pointer to an inference variable"
}

/// Does nothing as a lint pass, but registers some `Lint`s
/// which are used by other parts of the compiler.
#[derive(Copy, Clone)]
Expand Down Expand Up @@ -284,7 +290,8 @@ impl LintPass for HardwiredLints {
UNUSED_UNSAFE,
UNUSED_MUT,
COERCE_NEVER,
SINGLE_USE_LIFETIME
SINGLE_USE_LIFETIME,
TYVAR_BEHIND_RAW_POINTER
)
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/librustc_lint/lib.rs
Expand Up @@ -255,6 +255,10 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
id: LintId::of(COERCE_NEVER),
reference: "issue #46325 <https://github.com/rust-lang/rust/issues/46325>",
},
FutureIncompatibleInfo {
id: LintId::of(TYVAR_BEHIND_RAW_POINTER),
reference: "issue #46906 <https://github.com/rust-lang/rust/issues/46906>",
},
]);

// Register renamed and removed lints
Expand Down
23 changes: 13 additions & 10 deletions src/librustc_typeck/check/method/probe.rs
Expand Up @@ -27,6 +27,7 @@ use syntax::ast;
use syntax::util::lev_distance::{lev_distance, find_best_match_for_name};
use syntax_pos::Span;
use rustc::hir;
use rustc::lint;
use std::mem;
use std::ops::Deref;
use std::rc::Rc;
Expand Down Expand Up @@ -249,7 +250,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
// think cause spurious errors. Really though this part should
// take place in the `self.probe` below.
let steps = if mode == Mode::MethodCall {
match self.create_steps(span, self_ty, is_suggestion) {
match self.create_steps(span, scope_expr_id, self_ty, is_suggestion) {
Some(steps) => steps,
None => {
return Err(MethodError::NoMatch(NoMatchData::new(Vec::new(),
Expand Down Expand Up @@ -291,6 +292,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {

fn create_steps(&self,
span: Span,
scope_expr_id: ast::NodeId,
self_ty: Ty<'tcx>,
is_suggestion: IsSuggestion)
-> Option<Vec<CandidateStep<'tcx>>> {
Expand Down Expand Up @@ -318,18 +320,19 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
match final_ty.sty {
ty::TyInfer(ty::TyVar(_)) => {
// Ended in an inference variable. If we are doing
// a real method lookup, this is a hard error (it's an
// ambiguity and we can't make progress).
// a real method lookup, this is a hard error because it's
// possible that there will be multiple applicable methods.
if !is_suggestion.0 {
if reached_raw_pointer
&& !self.tcx.sess.features.borrow().arbitrary_self_types {
// only produce a warning in this case, because inference variables used to
// be allowed here in some cases for raw pointers
struct_span_warn!(self.tcx.sess, span, E0619,
"the type of this value must be known in this context")
.note("this will be made into a hard error in a future version of \
the compiler")
.emit();
// this case used to be allowed by the compiler,
// so we do a future-compat lint here
// (see https://github.com/rust-lang/rust/issues/46906)
self.tcx.lint_node(
lint::builtin::TYVAR_BEHIND_RAW_POINTER,
scope_expr_id,
span,
&format!("the type of this value must be known in this context"));
} else {
let t = self.structurally_resolved_type(span, final_ty);
assert_eq!(t, self.tcx.types.err);
Expand Down
6 changes: 4 additions & 2 deletions src/test/ui/inference-variable-behind-raw-pointer.stderr
@@ -1,8 +1,10 @@
warning[E0619]: the type of this value must be known in this context
warning: the type of this value must be known in this context
--> $DIR/inference-variable-behind-raw-pointer.rs:18:13
|
18 | if data.is_null() {}
| ^^^^^^^
|
= note: this will be made into a hard error in a future version of the compiler
= note: #[warn(tyvar_behind_raw_pointer)] on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #46906 <https://github.com/rust-lang/rust/issues/46906>

0 comments on commit 0783db9

Please sign in to comment.