Add E0612
This commit is contained in:
parent
302f99693f
commit
a42f8160ed
5 changed files with 68 additions and 24 deletions
|
@ -3053,26 +3053,20 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
let struct_path = self.tcx().item_path_str(did);
|
let struct_path = self.tcx().item_path_str(did);
|
||||||
struct_span_err!(self.tcx().sess, expr.span, E0611,
|
struct_span_err!(self.tcx().sess, expr.span, E0611,
|
||||||
"field `{}` of tuple-struct `{}` is private",
|
"field `{}` of tuple-struct `{}` is private",
|
||||||
idx.node, struct_path);
|
idx.node, struct_path).emit();
|
||||||
return field_ty;
|
return field_ty;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.type_error_message(
|
if tuple_like {
|
||||||
expr.span,
|
type_error_struct!(self.tcx().sess, expr.span, expr_t, E0612,
|
||||||
|actual| {
|
"attempted out-of-bounds tuple index `{}` on type `{}`",
|
||||||
if tuple_like {
|
idx.node, expr_t).emit();
|
||||||
format!("attempted out-of-bounds tuple index `{}` on \
|
} else {
|
||||||
type `{}`",
|
type_error_struct!(self.tcx().sess, expr.span, expr_t, E0613,
|
||||||
idx.node,
|
"attempted tuple index `{}` on type `{}`, but the type was not a \
|
||||||
actual)
|
tuple or tuple struct",
|
||||||
} else {
|
idx.node, expr_t).emit();
|
||||||
format!("attempted tuple index `{}` on type `{}`, but the \
|
}
|
||||||
type was not a tuple or tuple struct",
|
|
||||||
idx.node,
|
|
||||||
actual)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
expr_t);
|
|
||||||
|
|
||||||
self.tcx().types.err
|
self.tcx().types.err
|
||||||
}
|
}
|
||||||
|
@ -3173,10 +3167,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
field_type_hint = tcx.types.err;
|
field_type_hint = tcx.types.err;
|
||||||
if let Some(_) = variant.find_field_named(field.name.node) {
|
if let Some(_) = variant.find_field_named(field.name.node) {
|
||||||
let mut err = struct_span_err!(self.tcx.sess,
|
let mut err = struct_span_err!(self.tcx.sess,
|
||||||
field.name.span,
|
field.name.span,
|
||||||
E0062,
|
E0062,
|
||||||
"field `{}` specified more than once",
|
"field `{}` specified more than once",
|
||||||
field.name.node);
|
field.name.node);
|
||||||
|
|
||||||
err.span_label(field.name.span, "used more than once");
|
err.span_label(field.name.span, "used more than once");
|
||||||
|
|
||||||
|
|
|
@ -4208,6 +4208,40 @@ println!("{}", y.get()); // So we can get the value through the function.
|
||||||
```
|
```
|
||||||
"##,
|
"##,
|
||||||
|
|
||||||
|
E0612: r##"
|
||||||
|
Attempted out-of-bounds tuple index.
|
||||||
|
|
||||||
|
Erroneous code example:
|
||||||
|
|
||||||
|
```compile_fail,E0612
|
||||||
|
struct Foo(u32);
|
||||||
|
|
||||||
|
let y = Foo(0);
|
||||||
|
println!("{}", y.1); // error: attempted out-of-bounds tuple index `1`
|
||||||
|
// on type `Foo`
|
||||||
|
```
|
||||||
|
|
||||||
|
If a tuple/tuple-struct type has n fields, you can only try to access these n
|
||||||
|
fields from 0 to (n - 1). So in this case, you can only index `0`. Example:
|
||||||
|
|
||||||
|
```
|
||||||
|
struct Foo(u32);
|
||||||
|
|
||||||
|
let y = Foo(0);
|
||||||
|
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
|
||||||
|
|
||||||
|
```
|
||||||
|
"##,
|
||||||
|
|
||||||
E0617: r##"
|
E0617: r##"
|
||||||
Attempted to pass an invalid type of variable into a variadic function.
|
Attempted to pass an invalid type of variable into a variadic function.
|
||||||
|
|
||||||
|
|
16
src/test/compile-fail/E0612.rs
Normal file
16
src/test/compile-fail/E0612.rs
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
// 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 <LICENSE-APACHE or
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||||
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||||
|
// option. This file may not be copied, modified, or distributed
|
||||||
|
// except according to those terms.
|
||||||
|
|
||||||
|
struct Foo(u32);
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let y = Foo(0);
|
||||||
|
y.1; //~ ERROR E0612
|
||||||
|
}
|
|
@ -42,7 +42,7 @@ fn test(a: A, b: inner::A, c: inner::B, d: xc::A, e: xc::B, z: inner::Z) {
|
||||||
e.b; //~ ERROR: field `b` of struct `xc::B` is private
|
e.b; //~ ERROR: field `b` of struct `xc::B` is private
|
||||||
|
|
||||||
z.0;
|
z.0;
|
||||||
z.1; //~ ERROR: field `1` of struct `inner::Z` is private
|
z.1; //~ ERROR: field `1` of tuple-struct `inner::Z` is private
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
|
|
@ -16,7 +16,7 @@ error[E0610]: `{integer}` is a primitive type and therefore doesn't have fields
|
||||||
51 | fake_field_stmt!();
|
51 | fake_field_stmt!();
|
||||||
| ------------------- in this macro invocation
|
| ------------------- in this macro invocation
|
||||||
|
|
||||||
error: attempted tuple index `0` on type `{integer}`, but the type was not a tuple or tuple struct
|
error[E0613]: attempted tuple index `0` on type `{integer}`, but the type was not a tuple or tuple struct
|
||||||
--> $DIR/macro-backtrace-invalid-internals.rs:27:11
|
--> $DIR/macro-backtrace-invalid-internals.rs:27:11
|
||||||
|
|
|
|
||||||
27 | (1).0
|
27 | (1).0
|
||||||
|
@ -43,7 +43,7 @@ error[E0610]: `{integer}` is a primitive type and therefore doesn't have fields
|
||||||
55 | let _ = fake_field_expr!();
|
55 | let _ = fake_field_expr!();
|
||||||
| ------------------ in this macro invocation
|
| ------------------ in this macro invocation
|
||||||
|
|
||||||
error: attempted tuple index `0` on type `{integer}`, but the type was not a tuple or tuple struct
|
error[E0613]: attempted tuple index `0` on type `{integer}`, but the type was not a tuple or tuple struct
|
||||||
--> $DIR/macro-backtrace-invalid-internals.rs:45:11
|
--> $DIR/macro-backtrace-invalid-internals.rs:45:11
|
||||||
|
|
|
|
||||||
45 | (1).0
|
45 | (1).0
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue