Skip to content

Commit a80db25

Browse files
Add E0614
1 parent e8cbb53 commit a80db25

File tree

3 files changed

+47
-13
lines changed

3 files changed

+47
-13
lines changed

src/librustc_typeck/check/mod.rs

+12-13
Original file line numberDiff line numberDiff line change
@@ -3217,15 +3217,15 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
32173217
.join(", ");
32183218

32193219
struct_span_err!(tcx.sess, span, E0063,
3220-
"missing field{} {}{} in initializer of `{}`",
3221-
if remaining_fields.len() == 1 {""} else {"s"},
3222-
remaining_fields_names,
3223-
truncated_fields_error,
3224-
adt_ty)
3225-
.span_label(span, format!("missing {}{}",
3226-
remaining_fields_names,
3227-
truncated_fields_error))
3228-
.emit();
3220+
"missing field{} {}{} in initializer of `{}`",
3221+
if remaining_fields.len() == 1 { "" } else { "s" },
3222+
remaining_fields_names,
3223+
truncated_fields_error,
3224+
adt_ty)
3225+
.span_label(span, format!("missing {}{}",
3226+
remaining_fields_names,
3227+
truncated_fields_error))
3228+
.emit();
32293229
}
32303230
}
32313231

@@ -3458,10 +3458,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
34583458
oprnd_t = self.make_overloaded_lvalue_return_type(method).ty;
34593459
self.write_method_call(expr.id, method);
34603460
} else {
3461-
self.type_error_message(expr.span, |actual| {
3462-
format!("type `{}` cannot be \
3463-
dereferenced", actual)
3464-
}, oprnd_t);
3461+
type_error_struct!(tcx.sess, expr.span, oprnd_t, E0614,
3462+
"type `{}` cannot be dereferenced",
3463+
oprnd_t).emit();
34653464
oprnd_t = tcx.types.err;
34663465
}
34673466
}

src/librustc_typeck/diagnostics.rs

+21
Original file line numberDiff line numberDiff line change
@@ -4286,6 +4286,27 @@ println!("x: {} y: {}", s.x, s.y);
42864286
```
42874287
"##,
42884288

4289+
E0614: r##"
4290+
Attempted to dereference a variable which cannot be dereferenced.
4291+
4292+
Erroneous code example:
4293+
4294+
```compile_fail,E0614
4295+
let y = 0u32;
4296+
*y; // error: type `u32` cannot be dereferenced
4297+
```
4298+
4299+
Only types implementing `std::ops::Deref` can be dereferenced (such as `&T`).
4300+
Example:
4301+
4302+
```
4303+
let y = 0u32;
4304+
let x = &y;
4305+
// So here, `x` is a `&u32`, so we can dereference it:
4306+
*x; // ok!
4307+
```
4308+
"##,
4309+
42894310
E0617: r##"
42904311
Attempted to pass an invalid type of variable into a variadic function.
42914312

src/test/compile-fail/E0614.rs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn main() {
12+
let y = 0u32;
13+
*y; //~ ERROR E0614
14+
}

0 commit comments

Comments
 (0)