From 09a63c15714487178767a02fecd8ccaa8e35d047 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sun, 25 Sep 2016 19:10:06 +0200 Subject: [PATCH 1/3] Add E0513 error explanation --- src/librustc_typeck/diagnostics.rs | 40 +++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index e5c901f223ffb..0d6b43b59c6ad 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -3766,6 +3766,45 @@ extern "platform-intrinsic" { ``` "##, +E0513: r##" +The type of the variable couldn't be found out. + +Erroneous code example: + +```compile_fail,E0513 +use std::mem; + +unsafe { + let size = mem::size_of::(); + mem::transmute_copy::(&8_8); + // error: no type for local variable +} +``` + +To fix this error, please use a constant size instead of `size`. To make +this error more obvious, you could run: + +```compile_fail,E0080 +use std::mem; + +unsafe { + mem::transmute_copy::()]>(&8_8); + // error: constant evaluation error +} +``` + +So now, you can fix your code by setting the size directly: + +``` +use std::mem; + +unsafe { + mem::transmute_copy::(&8_8); + // `u32` is 4 bytes so we replace the `mem::size_of` call with its size +} +``` +"##, + E0516: r##" The `typeof` keyword is currently reserved but unimplemented. Erroneous code example: @@ -4064,7 +4103,6 @@ register_diagnostics! { E0399, // trait items need to be implemented because the associated // type `{}` was overridden E0436, // functional record update requires a struct - E0513, // no type for local variable .. E0521, // redundant default implementations of trait E0533, // `{}` does not name a unit variant, unit struct or a constant E0562, // `impl Trait` not allowed outside of function From 1e4e81c3200473842fa088f7549ff8f2419e321e Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sun, 25 Sep 2016 19:18:53 +0200 Subject: [PATCH 2/3] Add compile-fail test for E0513 --- src/test/compile-fail/E0513.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/test/compile-fail/E0513.rs diff --git a/src/test/compile-fail/E0513.rs b/src/test/compile-fail/E0513.rs new file mode 100644 index 0000000000000..726e23265241d --- /dev/null +++ b/src/test/compile-fail/E0513.rs @@ -0,0 +1,19 @@ +// Copyright 2016 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. + +use std::mem; + +fn main() { + unsafe { + let size = mem::size_of::(); + mem::transmute_copy::(&8_8); //~ ERROR E0513 + //~| NOTE no type for variable + } +} From 96a0f06b2f4a62f825b91dbf630a4b8bd8f81749 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sun, 25 Sep 2016 19:37:54 +0200 Subject: [PATCH 3/3] Update E0513 to new error format --- src/librustc_typeck/check/mod.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index e406807b51c31..c432d471803d0 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -1526,9 +1526,11 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { match self.locals.borrow().get(&nid) { Some(&t) => t, None => { - span_err!(self.tcx.sess, span, E0513, - "no type for local variable {}", - nid); + struct_span_err!(self.tcx.sess, span, E0513, + "no type for local variable {}", + self.tcx.map.node_to_string(nid)) + .span_label(span, &"no type for variable") + .emit(); self.tcx.types.err } }