Skip to content

Commit a6fc844

Browse files
committed
Auto merge of #46914 - mikeyhew:raw_pointer_self, r=arielb1
Convert warning about `*const _` to a future-compat lint #46664 was merged before I could convert the soft warning about method lookup on `*const _` into a future-compatibility lint. This PR makes that change. fixes #46837 tracking issue for the future-compatibility lint: #46906 r? @arielb1
2 parents ae65dcc + 60e6629 commit a6fc844

File tree

9 files changed

+38
-21
lines changed

9 files changed

+38
-21
lines changed

src/libcore/ptr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1829,7 +1829,7 @@ impl<T: ?Sized> *mut T {
18291829
///
18301830
/// # #[allow(dead_code)]
18311831
/// unsafe fn from_buf_raw<T: Copy>(ptr: *const T, elts: usize) -> Vec<T> {
1832-
/// let mut dst = Vec::with_capacity(elts);
1832+
/// let mut dst: Vec<T> = Vec::with_capacity(elts);
18331833
/// dst.set_len(elts);
18341834
/// dst.as_mut_ptr().copy_from(ptr, elts);
18351835
/// dst
@@ -1868,7 +1868,7 @@ impl<T: ?Sized> *mut T {
18681868
///
18691869
/// # #[allow(dead_code)]
18701870
/// unsafe fn from_buf_raw<T: Copy>(ptr: *const T, elts: usize) -> Vec<T> {
1871-
/// let mut dst = Vec::with_capacity(elts);
1871+
/// let mut dst: Vec<T> = Vec::with_capacity(elts);
18721872
/// dst.set_len(elts);
18731873
/// dst.as_mut_ptr().copy_from_nonoverlapping(ptr, elts);
18741874
/// dst

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_data_structures/array_vec.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ impl<A: Array> ArrayVec<A> {
138138
// Use the borrow in the IterMut to indicate borrowing behavior of the
139139
// whole Drain iterator (like &mut T).
140140
let range_slice = {
141-
let arr = &mut self.values as &mut [ManuallyDrop<_>];
141+
let arr = &mut self.values as &mut [ManuallyDrop<<A as Array>::Element>];
142142
slice::from_raw_parts_mut(arr.as_mut_ptr().offset(start as isize),
143143
end - start)
144144
};
@@ -255,12 +255,13 @@ impl<'a, A: Array> Drop for Drain<'a, A> {
255255

256256
if self.tail_len > 0 {
257257
unsafe {
258-
let source_array_vec = self.array_vec.as_mut();
258+
let source_array_vec: &mut ArrayVec<A> = self.array_vec.as_mut();
259259
// memmove back untouched tail, update to new length
260260
let start = source_array_vec.len();
261261
let tail = self.tail_start;
262262
{
263-
let arr = &mut source_array_vec.values as &mut [ManuallyDrop<_>];
263+
let arr =
264+
&mut source_array_vec.values as &mut [ManuallyDrop<<A as Array>::Element>];
264265
let src = arr.as_ptr().offset(tail as isize);
265266
let dst = arr.as_mut_ptr().offset(start as isize);
266267
ptr::copy(src, dst, self.tail_len);

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);

src/libstd/sys/unix/os.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ pub fn getenv(k: &OsStr) -> io::Result<Option<OsString>> {
453453
let k = CString::new(k.as_bytes())?;
454454
unsafe {
455455
ENV_LOCK.lock();
456-
let s = libc::getenv(k.as_ptr()) as *const _;
456+
let s = libc::getenv(k.as_ptr()) as *const libc::c_char;
457457
let ret = if s.is_null() {
458458
None
459459
} else {

src/libstd/sys/windows/fs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,7 @@ fn symlink_junction_inner(target: &Path, junction: &Path) -> io::Result<()> {
770770
let mut data = [0u8; c::MAXIMUM_REPARSE_DATA_BUFFER_SIZE];
771771
let db = data.as_mut_ptr()
772772
as *mut c::REPARSE_MOUNTPOINT_DATA_BUFFER;
773-
let buf = &mut (*db).ReparseTarget as *mut _;
773+
let buf = &mut (*db).ReparseTarget as *mut c::WCHAR;
774774
let mut i = 0;
775775
// FIXME: this conversion is very hacky
776776
let v = br"\??\";

src/libstd/sys_common/gnu/libbacktrace.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ pub fn resolve_symname<F>(frame: Frame,
7373
"failed to allocate libbacktrace state")
7474
)
7575
}
76-
let mut data = ptr::null();
76+
let mut data: *const libc::c_char = ptr::null();
7777
let data_addr = &mut data as *mut *const libc::c_char;
7878
let ret = unsafe {
7979
backtrace_syminfo(state,
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)