-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
275 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/test/ui/suggestions/non-existent-field-present-in-subfield-recursion-limit.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// In rustc_typeck::check::expr::no_such_field_err we recursively | ||
// look in subfields for the field. This recursive search is limited | ||
// in depth for compile-time reasons and to avoid infinite recursion | ||
// in case of cycles. This file tests that the limit in the recursion | ||
// depth is enforced. | ||
|
||
struct Foo { | ||
first: Bar, | ||
second: u32, | ||
third: u32, | ||
} | ||
|
||
struct Bar { | ||
bar: C, | ||
} | ||
|
||
struct C { | ||
c: D, | ||
} | ||
|
||
struct D { | ||
test: E, | ||
} | ||
|
||
struct E { | ||
e: F, | ||
} | ||
|
||
struct F { | ||
f: u32, | ||
} | ||
|
||
fn main() { | ||
let f = F { f: 6 }; | ||
let e = E { e: f }; | ||
let d = D { test: e }; | ||
let c = C { c: d }; | ||
let bar = Bar { bar: c }; | ||
let fooer = Foo { first: bar, second: 4, third: 5 }; | ||
|
||
let test = fooer.f; | ||
//~^ ERROR no field | ||
} |
11 changes: 11 additions & 0 deletions
11
src/test/ui/suggestions/non-existent-field-present-in-subfield-recursion-limit.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
error[E0609]: no field `f` on type `Foo` | ||
--> $DIR/non-existent-field-present-in-subfield-recursion-limit.rs:41:22 | ||
| | ||
LL | let test = fooer.f; | ||
| ^ unknown field | ||
| | ||
= note: available fields are: `first`, `second`, `third` | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0609`. |
42 changes: 42 additions & 0 deletions
42
src/test/ui/suggestions/non-existent-field-present-in-subfield.fixed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// run-rustfix | ||
|
||
struct Foo { | ||
first: Bar, | ||
_second: u32, | ||
_third: u32, | ||
} | ||
|
||
struct Bar { | ||
bar: C, | ||
} | ||
|
||
struct C { | ||
c: D, | ||
} | ||
|
||
struct D { | ||
test: E, | ||
} | ||
|
||
struct E { | ||
_e: F, | ||
} | ||
|
||
struct F { | ||
_f: u32, | ||
} | ||
|
||
fn main() { | ||
let f = F { _f: 6 }; | ||
let e = E { _e: f }; | ||
let d = D { test: e }; | ||
let c = C { c: d }; | ||
let bar = Bar { bar: c }; | ||
let fooer = Foo { first: bar, _second: 4, _third: 5 }; | ||
|
||
let _test = &fooer.first.bar.c; | ||
//~^ ERROR no field | ||
|
||
let _test2 = fooer.first.bar.c.test; | ||
//~^ ERROR no field | ||
} |
42 changes: 42 additions & 0 deletions
42
src/test/ui/suggestions/non-existent-field-present-in-subfield.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// run-rustfix | ||
|
||
struct Foo { | ||
first: Bar, | ||
_second: u32, | ||
_third: u32, | ||
} | ||
|
||
struct Bar { | ||
bar: C, | ||
} | ||
|
||
struct C { | ||
c: D, | ||
} | ||
|
||
struct D { | ||
test: E, | ||
} | ||
|
||
struct E { | ||
_e: F, | ||
} | ||
|
||
struct F { | ||
_f: u32, | ||
} | ||
|
||
fn main() { | ||
let f = F { _f: 6 }; | ||
let e = E { _e: f }; | ||
let d = D { test: e }; | ||
let c = C { c: d }; | ||
let bar = Bar { bar: c }; | ||
let fooer = Foo { first: bar, _second: 4, _third: 5 }; | ||
|
||
let _test = &fooer.c; | ||
//~^ ERROR no field | ||
|
||
let _test2 = fooer.test; | ||
//~^ ERROR no field | ||
} |
27 changes: 27 additions & 0 deletions
27
src/test/ui/suggestions/non-existent-field-present-in-subfield.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
error[E0609]: no field `c` on type `Foo` | ||
--> $DIR/non-existent-field-present-in-subfield.rs:37:24 | ||
| | ||
LL | let _test = &fooer.c; | ||
| ^ unknown field | ||
| | ||
= note: available fields are: `first`, `_second`, `_third` | ||
help: one of the expressions' fields has a field of the same name | ||
| | ||
LL | let _test = &fooer.first.bar.c; | ||
| ^^^^^^^^^^ | ||
|
||
error[E0609]: no field `test` on type `Foo` | ||
--> $DIR/non-existent-field-present-in-subfield.rs:40:24 | ||
| | ||
LL | let _test2 = fooer.test; | ||
| ^^^^ unknown field | ||
| | ||
= note: available fields are: `first`, `_second`, `_third` | ||
help: one of the expressions' fields has a field of the same name | ||
| | ||
LL | let _test2 = fooer.first.bar.c.test; | ||
| ^^^^^^^^^^^^ | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0609`. |