Skip to content

Commit c215d08

Browse files
author
boreeas
committed
Fold E0613 into E0609
Resolves #42945
1 parent c0ec385 commit c215d08

File tree

6 files changed

+20
-81
lines changed

6 files changed

+20
-81
lines changed

src/librustc_typeck/check/mod.rs

+11-7
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ use util::nodemap::{DefIdMap, FxHashMap, NodeMap};
111111
use std::cell::{Cell, RefCell, Ref, RefMut};
112112
use std::collections::hash_map::Entry;
113113
use std::cmp;
114+
use std::fmt::Display;
114115
use std::mem::replace;
115116
use std::ops::{self, Deref};
116117
use syntax::abi::Abi;
@@ -2945,9 +2946,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
29452946
self.tcx().types.err
29462947
} else {
29472948
if !expr_t.is_primitive_ty() {
2948-
let mut err = type_error_struct!(self.tcx().sess, field.span, expr_t, E0609,
2949-
"no field `{}` on type `{}`",
2950-
field.node, expr_t);
2949+
let mut err = self.no_such_field_err(field.span, &field.node, expr_t);
2950+
29512951
match expr_t.sty {
29522952
ty::TyAdt(def, _) if !def.is_enum() => {
29532953
if let Some(suggested_field_name) =
@@ -3064,15 +3064,19 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
30643064
"attempted out-of-bounds tuple index `{}` on type `{}`",
30653065
idx.node, expr_t).emit();
30663066
} else {
3067-
type_error_struct!(self.tcx().sess, expr.span, expr_t, E0613,
3068-
"attempted to access tuple index `{}` on type `{}`, but the type \
3069-
was not a tuple or tuple struct",
3070-
idx.node, expr_t).emit();
3067+
self.no_such_field_err(expr.span, idx.node, expr_t).emit();
30713068
}
30723069

30733070
self.tcx().types.err
30743071
}
30753072

3073+
fn no_such_field_err<T: Display>(&self, span: Span, field: T, expr_t: &ty::TyS)
3074+
-> DiagnosticBuilder {
3075+
type_error_struct!(self.tcx().sess, span, expr_t, E0609,
3076+
"no field `{}` on type `{}`",
3077+
field, expr_t)
3078+
}
3079+
30763080
fn report_unknown_field(&self,
30773081
ty: Ty<'tcx>,
30783082
variant: &'tcx ty::VariantDef,

src/librustc_typeck/diagnostics.rs

+1-54
Original file line numberDiff line numberDiff line change
@@ -4443,60 +4443,6 @@ println!("{}", y.0); // ok!
44434443
```
44444444
"##,
44454445

4446-
E0613: r##"
4447-
Attempted tuple index on a type which isn't a tuple nor a tuple-struct.
4448-
4449-
Erroneous code example:
4450-
4451-
```compile_fail,E0613
4452-
struct Foo;
4453-
4454-
let y = Foo;
4455-
println!("{}", y.1); // error: attempted to access tuple index `1` on type
4456-
// `Foo`, but the type was not a tuple or tuple
4457-
// struct
4458-
```
4459-
4460-
Only tuple and tuple-struct types can be indexed this way. Example:
4461-
4462-
```
4463-
// Let's create a tuple first:
4464-
let x: (u32, u32, u32, u32) = (0, 1, 1, 2);
4465-
// You can index its fields this way:
4466-
println!("({}, {}, {}, {})", x.0, x.1, x.2, x.3);
4467-
4468-
// Now let's declare a tuple-struct:
4469-
struct TupleStruct(u32, u32, u32, u32);
4470-
// Let's instantiate it:
4471-
let x = TupleStruct(0, 1, 1, 2);
4472-
// And just like the tuple:
4473-
println!("({}, {}, {}, {})", x.0, x.1, x.2, x.3);
4474-
```
4475-
4476-
If you want to index into an array, use `[]` instead:
4477-
4478-
```
4479-
let x = &[0, 1, 1, 2];
4480-
println!("[{}, {}, {}, {}]", x[0], x[1], x[2], x[3]);
4481-
```
4482-
4483-
If you want to access a field of a struct, check the field's name wasn't
4484-
misspelled:
4485-
4486-
```
4487-
struct SomeStruct {
4488-
x: u32,
4489-
y: i32,
4490-
}
4491-
4492-
let s = SomeStruct {
4493-
x: 0,
4494-
y: -1,
4495-
};
4496-
println!("x: {} y: {}", s.x, s.y);
4497-
```
4498-
"##,
4499-
45004446
E0614: r##"
45014447
Attempted to dereference a variable which cannot be dereferenced.
45024448
@@ -4817,4 +4763,5 @@ register_diagnostics! {
48174763
E0568, // auto-traits can not have predicates,
48184764
E0588, // packed struct cannot transitively contain a `[repr(align)]` struct
48194765
E0592, // duplicate definitions with name `{}`
4766+
// E0613, // Removed (merged with E0609)
48204767
}

src/test/compile-fail/E0609.rs

+4
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,12 @@
1111
struct Foo {
1212
x: u32,
1313
}
14+
struct Bar;
1415

1516
fn main() {
1617
let x = Foo { x: 0 };
1718
let _ = x.foo; //~ ERROR E0609
19+
20+
let y = Bar;
21+
y.1; //~ ERROR E0609
1822
}

src/test/compile-fail/E0613.rs

-16
This file was deleted.

src/test/compile-fail/tuple-index-not-tuple.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ struct Empty;
1414
fn main() {
1515
let origin = Point { x: 0, y: 0 };
1616
origin.0;
17-
//~^ ERROR attempted to access tuple index `0` on type `Point`, but the type was not
17+
//~^ ERROR no field `0` on type `Point`
1818
Empty.0;
19-
//~^ ERROR attempted to access tuple index `0` on type `Empty`, but the type was not
19+
//~^ ERROR no field `0` on type `Empty`
2020
}

src/test/ui/macros/macro-backtrace-invalid-internals.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ error[E0610]: `{integer}` is a primitive type and therefore doesn't have fields
1616
51 | fake_field_stmt!();
1717
| ------------------- in this macro invocation
1818

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

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

0 commit comments

Comments
 (0)