Skip to content

Commit

Permalink
Fold E0613 into E0609
Browse files Browse the repository at this point in the history
  • Loading branch information
boreeas committed Jul 7, 2017
1 parent c0ec385 commit c215d08
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 81 deletions.
18 changes: 11 additions & 7 deletions src/librustc_typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ use util::nodemap::{DefIdMap, FxHashMap, NodeMap};
use std::cell::{Cell, RefCell, Ref, RefMut};
use std::collections::hash_map::Entry;
use std::cmp;
use std::fmt::Display;
use std::mem::replace;
use std::ops::{self, Deref};
use syntax::abi::Abi;
Expand Down Expand Up @@ -2945,9 +2946,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
self.tcx().types.err
} else {
if !expr_t.is_primitive_ty() {
let mut err = type_error_struct!(self.tcx().sess, field.span, expr_t, E0609,
"no field `{}` on type `{}`",
field.node, expr_t);
let mut err = self.no_such_field_err(field.span, &field.node, expr_t);

match expr_t.sty {
ty::TyAdt(def, _) if !def.is_enum() => {
if let Some(suggested_field_name) =
Expand Down Expand Up @@ -3064,15 +3064,19 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
"attempted out-of-bounds tuple index `{}` on type `{}`",
idx.node, expr_t).emit();
} else {
type_error_struct!(self.tcx().sess, expr.span, expr_t, E0613,
"attempted to access tuple index `{}` on type `{}`, but the type \
was not a tuple or tuple struct",
idx.node, expr_t).emit();
self.no_such_field_err(expr.span, idx.node, expr_t).emit();
}

self.tcx().types.err
}

fn no_such_field_err<T: Display>(&self, span: Span, field: T, expr_t: &ty::TyS)
-> DiagnosticBuilder {
type_error_struct!(self.tcx().sess, span, expr_t, E0609,
"no field `{}` on type `{}`",
field, expr_t)
}

fn report_unknown_field(&self,
ty: Ty<'tcx>,
variant: &'tcx ty::VariantDef,
Expand Down
55 changes: 1 addition & 54 deletions src/librustc_typeck/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4443,60 +4443,6 @@ println!("{}", y.0); // ok!
```
"##,

E0613: r##"
Attempted tuple index on a type which isn't a tuple nor a tuple-struct.
Erroneous code example:
```compile_fail,E0613
struct Foo;
let y = Foo;
println!("{}", y.1); // error: attempted to access tuple index `1` on type
// `Foo`, but the type was not a tuple or tuple
// struct
```
Only tuple and tuple-struct types can be indexed this way. Example:
```
// Let's create a tuple first:
let x: (u32, u32, u32, u32) = (0, 1, 1, 2);
// You can index its fields this way:
println!("({}, {}, {}, {})", x.0, x.1, x.2, x.3);
// Now let's declare a tuple-struct:
struct TupleStruct(u32, u32, u32, u32);
// Let's instantiate it:
let x = TupleStruct(0, 1, 1, 2);
// And just like the tuple:
println!("({}, {}, {}, {})", x.0, x.1, x.2, x.3);
```
If you want to index into an array, use `[]` instead:
```
let x = &[0, 1, 1, 2];
println!("[{}, {}, {}, {}]", x[0], x[1], x[2], x[3]);
```
If you want to access a field of a struct, check the field's name wasn't
misspelled:
```
struct SomeStruct {
x: u32,
y: i32,
}
let s = SomeStruct {
x: 0,
y: -1,
};
println!("x: {} y: {}", s.x, s.y);
```
"##,

E0614: r##"
Attempted to dereference a variable which cannot be dereferenced.
Expand Down Expand Up @@ -4817,4 +4763,5 @@ register_diagnostics! {
E0568, // auto-traits can not have predicates,
E0588, // packed struct cannot transitively contain a `[repr(align)]` struct
E0592, // duplicate definitions with name `{}`
// E0613, // Removed (merged with E0609)
}
4 changes: 4 additions & 0 deletions src/test/compile-fail/E0609.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@
struct Foo {
x: u32,
}
struct Bar;

fn main() {
let x = Foo { x: 0 };
let _ = x.foo; //~ ERROR E0609

let y = Bar;
y.1; //~ ERROR E0609
}
16 changes: 0 additions & 16 deletions src/test/compile-fail/E0613.rs

This file was deleted.

4 changes: 2 additions & 2 deletions src/test/compile-fail/tuple-index-not-tuple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ struct Empty;
fn main() {
let origin = Point { x: 0, y: 0 };
origin.0;
//~^ ERROR attempted to access tuple index `0` on type `Point`, but the type was not
//~^ ERROR no field `0` on type `Point`
Empty.0;
//~^ ERROR attempted to access tuple index `0` on type `Empty`, but the type was not
//~^ ERROR no field `0` on type `Empty`
}
4 changes: 2 additions & 2 deletions src/test/ui/macros/macro-backtrace-invalid-internals.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ error[E0610]: `{integer}` is a primitive type and therefore doesn't have fields
51 | fake_field_stmt!();
| ------------------- in this macro invocation

error[E0613]: attempted to access tuple index `0` on type `{integer}`, but the type was not a tuple or tuple struct
error[E0609]: no field `0` on type `{integer}`
--> $DIR/macro-backtrace-invalid-internals.rs:27:11
|
27 | (1).0
Expand All @@ -43,7 +43,7 @@ error[E0610]: `{integer}` is a primitive type and therefore doesn't have fields
55 | let _ = fake_field_expr!();
| ------------------ in this macro invocation

error[E0613]: attempted to access tuple index `0` on type `{integer}`, but the type was not a tuple or tuple struct
error[E0609]: no field `0` on type `{integer}`
--> $DIR/macro-backtrace-invalid-internals.rs:45:11
|
45 | (1).0
Expand Down

0 comments on commit c215d08

Please sign in to comment.