diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 5df4f3af1323..484fbe43d5da 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -3217,15 +3217,15 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { .join(", "); struct_span_err!(tcx.sess, span, E0063, - "missing field{} {}{} in initializer of `{}`", - if remaining_fields.len() == 1 {""} else {"s"}, - remaining_fields_names, - truncated_fields_error, - adt_ty) - .span_label(span, format!("missing {}{}", - remaining_fields_names, - truncated_fields_error)) - .emit(); + "missing field{} {}{} in initializer of `{}`", + if remaining_fields.len() == 1 { "" } else { "s" }, + remaining_fields_names, + truncated_fields_error, + adt_ty) + .span_label(span, format!("missing {}{}", + remaining_fields_names, + truncated_fields_error)) + .emit(); } } @@ -3458,10 +3458,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { oprnd_t = self.make_overloaded_lvalue_return_type(method).ty; self.write_method_call(expr.id, method); } else { - self.type_error_message(expr.span, |actual| { - format!("type `{}` cannot be \ - dereferenced", actual) - }, oprnd_t); + type_error_struct!(tcx.sess, expr.span, oprnd_t, E0614, + "type `{}` cannot be dereferenced", + oprnd_t).emit(); oprnd_t = tcx.types.err; } } diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index 308cc3b32cab..f34151b60be0 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -4286,6 +4286,27 @@ println!("x: {} y: {}", s.x, s.y); ``` "##, +E0614: r##" +Attempted to dereference a variable which cannot be dereferenced. + +Erroneous code example: + +```compile_fail,E0614 +let y = 0u32; +*y; // error: type `u32` cannot be dereferenced +``` + +Only types implementing `std::ops::Deref` can be dereferenced (such as `&T`). +Example: + +``` +let y = 0u32; +let x = &y; +// So here, `x` is a `&u32`, so we can dereference it: +*x; // ok! +``` +"##, + E0617: r##" Attempted to pass an invalid type of variable into a variadic function. diff --git a/src/test/compile-fail/E0614.rs b/src/test/compile-fail/E0614.rs new file mode 100644 index 000000000000..909f0eb82855 --- /dev/null +++ b/src/test/compile-fail/E0614.rs @@ -0,0 +1,14 @@ +// Copyright 2017 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn main() { + let y = 0u32; + *y; //~ ERROR E0614 +}