diff options
| author | bors <bors@rust-lang.org> | 2017-12-25 04:55:57 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2017-12-25 04:55:57 +0000 |
| commit | a6fc84440f3353b1090dc52d7859136880db89ec (patch) | |
| tree | ae9034dfdbd3fa7ad9b228758573a9d5b1f2b584 | |
| parent | ae65dcc30f421fd91b9e2d67cf77c86bfb20ee3a (diff) | |
| parent | 60e66290451644e81323daa7cf03c337a6569c83 (diff) | |
| download | rust-a6fc84440f3353b1090dc52d7859136880db89ec.tar.gz rust-a6fc84440f3353b1090dc52d7859136880db89ec.zip | |
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
| -rw-r--r-- | src/libcore/ptr.rs | 4 | ||||
| -rw-r--r-- | src/librustc/lint/builtin.rs | 9 | ||||
| -rw-r--r-- | src/librustc_data_structures/array_vec.rs | 7 | ||||
| -rw-r--r-- | src/librustc_lint/lib.rs | 4 | ||||
| -rw-r--r-- | src/librustc_typeck/check/method/probe.rs | 23 | ||||
| -rw-r--r-- | src/libstd/sys/unix/os.rs | 2 | ||||
| -rw-r--r-- | src/libstd/sys/windows/fs.rs | 2 | ||||
| -rw-r--r-- | src/libstd/sys_common/gnu/libbacktrace.rs | 2 | ||||
| -rw-r--r-- | src/test/ui/inference-variable-behind-raw-pointer.stderr | 6 |
9 files changed, 38 insertions, 21 deletions
diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs index 85bdeae442b..7f7246df8f2 100644 --- a/src/libcore/ptr.rs +++ b/src/libcore/ptr.rs @@ -1829,7 +1829,7 @@ impl<T: ?Sized> *mut T { /// /// # #[allow(dead_code)] /// unsafe fn from_buf_raw<T: Copy>(ptr: *const T, elts: usize) -> Vec<T> { - /// let mut dst = Vec::with_capacity(elts); + /// let mut dst: Vec<T> = Vec::with_capacity(elts); /// dst.set_len(elts); /// dst.as_mut_ptr().copy_from(ptr, elts); /// dst @@ -1868,7 +1868,7 @@ impl<T: ?Sized> *mut T { /// /// # #[allow(dead_code)] /// unsafe fn from_buf_raw<T: Copy>(ptr: *const T, elts: usize) -> Vec<T> { - /// let mut dst = Vec::with_capacity(elts); + /// let mut dst: Vec<T> = Vec::with_capacity(elts); /// dst.set_len(elts); /// dst.as_mut_ptr().copy_from_nonoverlapping(ptr, elts); /// dst diff --git a/src/librustc/lint/builtin.rs b/src/librustc/lint/builtin.rs index de0bd9d0295..7410386c6f4 100644 --- a/src/librustc/lint/builtin.rs +++ b/src/librustc/lint/builtin.rs @@ -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)] @@ -284,7 +290,8 @@ impl LintPass for HardwiredLints { UNUSED_UNSAFE, UNUSED_MUT, COERCE_NEVER, - SINGLE_USE_LIFETIME + SINGLE_USE_LIFETIME, + TYVAR_BEHIND_RAW_POINTER ) } } diff --git a/src/librustc_data_structures/array_vec.rs b/src/librustc_data_structures/array_vec.rs index 1b39e029604..57fc78ef531 100644 --- a/src/librustc_data_structures/array_vec.rs +++ b/src/librustc_data_structures/array_vec.rs @@ -138,7 +138,7 @@ impl<A: Array> ArrayVec<A> { // Use the borrow in the IterMut to indicate borrowing behavior of the // whole Drain iterator (like &mut T). let range_slice = { - let arr = &mut self.values as &mut [ManuallyDrop<_>]; + let arr = &mut self.values as &mut [ManuallyDrop<<A as Array>::Element>]; slice::from_raw_parts_mut(arr.as_mut_ptr().offset(start as isize), end - start) }; @@ -255,12 +255,13 @@ impl<'a, A: Array> Drop for Drain<'a, A> { if self.tail_len > 0 { unsafe { - let source_array_vec = self.array_vec.as_mut(); + let source_array_vec: &mut ArrayVec<A> = self.array_vec.as_mut(); // memmove back untouched tail, update to new length let start = source_array_vec.len(); let tail = self.tail_start; { - let arr = &mut source_array_vec.values as &mut [ManuallyDrop<_>]; + let arr = + &mut source_array_vec.values as &mut [ManuallyDrop<<A as Array>::Element>]; let src = arr.as_ptr().offset(tail as isize); let dst = arr.as_mut_ptr().offset(start as isize); ptr::copy(src, dst, self.tail_len); diff --git a/src/librustc_lint/lib.rs b/src/librustc_lint/lib.rs index 8b41dd62742..3d7f05afefc 100644 --- a/src/librustc_lint/lib.rs +++ b/src/librustc_lint/lib.rs @@ -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 diff --git a/src/librustc_typeck/check/method/probe.rs b/src/librustc_typeck/check/method/probe.rs index fe30ffb3cfc..53bb0e577a4 100644 --- a/src/librustc_typeck/check/method/probe.rs +++ b/src/librustc_typeck/check/method/probe.rs @@ -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; @@ -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(), @@ -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>>> { @@ -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); diff --git a/src/libstd/sys/unix/os.rs b/src/libstd/sys/unix/os.rs index 4f33a2b12fe..a46e855b4a6 100644 --- a/src/libstd/sys/unix/os.rs +++ b/src/libstd/sys/unix/os.rs @@ -453,7 +453,7 @@ pub fn getenv(k: &OsStr) -> io::Result<Option<OsString>> { let k = CString::new(k.as_bytes())?; unsafe { ENV_LOCK.lock(); - let s = libc::getenv(k.as_ptr()) as *const _; + let s = libc::getenv(k.as_ptr()) as *const libc::c_char; let ret = if s.is_null() { None } else { diff --git a/src/libstd/sys/windows/fs.rs b/src/libstd/sys/windows/fs.rs index ae9535139d9..165e1b0609b 100644 --- a/src/libstd/sys/windows/fs.rs +++ b/src/libstd/sys/windows/fs.rs @@ -770,7 +770,7 @@ fn symlink_junction_inner(target: &Path, junction: &Path) -> io::Result<()> { let mut data = [0u8; c::MAXIMUM_REPARSE_DATA_BUFFER_SIZE]; let db = data.as_mut_ptr() as *mut c::REPARSE_MOUNTPOINT_DATA_BUFFER; - let buf = &mut (*db).ReparseTarget as *mut _; + let buf = &mut (*db).ReparseTarget as *mut c::WCHAR; let mut i = 0; // FIXME: this conversion is very hacky let v = br"\??\"; diff --git a/src/libstd/sys_common/gnu/libbacktrace.rs b/src/libstd/sys_common/gnu/libbacktrace.rs index 75c6bd5d2a2..6ad3af6aee1 100644 --- a/src/libstd/sys_common/gnu/libbacktrace.rs +++ b/src/libstd/sys_common/gnu/libbacktrace.rs @@ -73,7 +73,7 @@ pub fn resolve_symname<F>(frame: Frame, "failed to allocate libbacktrace state") ) } - let mut data = ptr::null(); + let mut data: *const libc::c_char = ptr::null(); let data_addr = &mut data as *mut *const libc::c_char; let ret = unsafe { backtrace_syminfo(state, diff --git a/src/test/ui/inference-variable-behind-raw-pointer.stderr b/src/test/ui/inference-variable-behind-raw-pointer.stderr index a8874c9bf5a..d0ee55c092b 100644 --- a/src/test/ui/inference-variable-behind-raw-pointer.stderr +++ b/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> |
