Skip to content

Commit 0783db9

Browse files
committed
Convert warning about *const _ to a future-compat lint
1 parent b7b52cc commit 0783db9

File tree

4 files changed

+29
-13
lines changed

4 files changed

+29
-13
lines changed

src/librustc/lint/builtin.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,12 @@ declare_lint! {
240240
"detects single use lifetimes"
241241
}
242242

243+
declare_lint! {
244+
pub TYVAR_BEHIND_RAW_POINTER,
245+
Warn,
246+
"raw pointer to an inference variable"
247+
}
248+
243249
/// Does nothing as a lint pass, but registers some `Lint`s
244250
/// which are used by other parts of the compiler.
245251
#[derive(Copy, Clone)]
@@ -284,7 +290,8 @@ impl LintPass for HardwiredLints {
284290
UNUSED_UNSAFE,
285291
UNUSED_MUT,
286292
COERCE_NEVER,
287-
SINGLE_USE_LIFETIME
293+
SINGLE_USE_LIFETIME,
294+
TYVAR_BEHIND_RAW_POINTER
288295
)
289296
}
290297
}

src/librustc_lint/lib.rs

+4
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,10 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
255255
id: LintId::of(COERCE_NEVER),
256256
reference: "issue #46325 <https://github.com/rust-lang/rust/issues/46325>",
257257
},
258+
FutureIncompatibleInfo {
259+
id: LintId::of(TYVAR_BEHIND_RAW_POINTER),
260+
reference: "issue #46906 <https://github.com/rust-lang/rust/issues/46906>",
261+
},
258262
]);
259263

260264
// Register renamed and removed lints

src/librustc_typeck/check/method/probe.rs

+13-10
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ use syntax::ast;
2727
use syntax::util::lev_distance::{lev_distance, find_best_match_for_name};
2828
use syntax_pos::Span;
2929
use rustc::hir;
30+
use rustc::lint;
3031
use std::mem;
3132
use std::ops::Deref;
3233
use std::rc::Rc;
@@ -249,7 +250,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
249250
// think cause spurious errors. Really though this part should
250251
// take place in the `self.probe` below.
251252
let steps = if mode == Mode::MethodCall {
252-
match self.create_steps(span, self_ty, is_suggestion) {
253+
match self.create_steps(span, scope_expr_id, self_ty, is_suggestion) {
253254
Some(steps) => steps,
254255
None => {
255256
return Err(MethodError::NoMatch(NoMatchData::new(Vec::new(),
@@ -291,6 +292,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
291292

292293
fn create_steps(&self,
293294
span: Span,
295+
scope_expr_id: ast::NodeId,
294296
self_ty: Ty<'tcx>,
295297
is_suggestion: IsSuggestion)
296298
-> Option<Vec<CandidateStep<'tcx>>> {
@@ -318,18 +320,19 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
318320
match final_ty.sty {
319321
ty::TyInfer(ty::TyVar(_)) => {
320322
// Ended in an inference variable. If we are doing
321-
// a real method lookup, this is a hard error (it's an
322-
// ambiguity and we can't make progress).
323+
// a real method lookup, this is a hard error because it's
324+
// possible that there will be multiple applicable methods.
323325
if !is_suggestion.0 {
324326
if reached_raw_pointer
325327
&& !self.tcx.sess.features.borrow().arbitrary_self_types {
326-
// only produce a warning in this case, because inference variables used to
327-
// be allowed here in some cases for raw pointers
328-
struct_span_warn!(self.tcx.sess, span, E0619,
329-
"the type of this value must be known in this context")
330-
.note("this will be made into a hard error in a future version of \
331-
the compiler")
332-
.emit();
328+
// this case used to be allowed by the compiler,
329+
// so we do a future-compat lint here
330+
// (see https://github.com/rust-lang/rust/issues/46906)
331+
self.tcx.lint_node(
332+
lint::builtin::TYVAR_BEHIND_RAW_POINTER,
333+
scope_expr_id,
334+
span,
335+
&format!("the type of this value must be known in this context"));
333336
} else {
334337
let t = self.structurally_resolved_type(span, final_ty);
335338
assert_eq!(t, self.tcx.types.err);
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
warning[E0619]: the type of this value must be known in this context
1+
warning: the type of this value must be known in this context
22
--> $DIR/inference-variable-behind-raw-pointer.rs:18:13
33
|
44
18 | if data.is_null() {}
55
| ^^^^^^^
66
|
7-
= note: this will be made into a hard error in a future version of the compiler
7+
= note: #[warn(tyvar_behind_raw_pointer)] on by default
8+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
9+
= note: for more information, see issue #46906 <https://github.com/rust-lang/rust/issues/46906>
810

0 commit comments

Comments
 (0)