Ensure that we don't try to access fields on a non-struct pattern type in diagnostic
Fix #135209.
This commit is contained in:
parent
ad211ced81
commit
5f04f98c9a
3 changed files with 38 additions and 1 deletions
|
@ -1130,7 +1130,9 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
|
||||||
let None = following_seg else { return };
|
let None = following_seg else { return };
|
||||||
for rib in self.ribs[ValueNS].iter().rev() {
|
for rib in self.ribs[ValueNS].iter().rev() {
|
||||||
for (def_id, spans) in &rib.patterns_with_skipped_bindings {
|
for (def_id, spans) in &rib.patterns_with_skipped_bindings {
|
||||||
if let Some(fields) = self.r.field_idents(*def_id) {
|
if let DefKind::Struct = self.r.tcx.def_kind(*def_id)
|
||||||
|
&& let Some(fields) = self.r.field_idents(*def_id)
|
||||||
|
{
|
||||||
for field in fields {
|
for field in fields {
|
||||||
if field.name == segment.ident.name {
|
if field.name == segment.ident.name {
|
||||||
if spans.iter().all(|(_, had_error)| had_error.is_err()) {
|
if spans.iter().all(|(_, had_error)| had_error.is_err()) {
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
// Regression test for #135209.
|
||||||
|
// We ensure that we don't try to access fields on a non-struct pattern type.
|
||||||
|
fn main() {
|
||||||
|
if let Iterator::Item { .. } = 1 { //~ ERROR E0223
|
||||||
|
x //~ ERROR E0425
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
error[E0425]: cannot find value `x` in this scope
|
||||||
|
--> $DIR/struct-pattern-on-non-struct-resolve-error.rs:5:9
|
||||||
|
|
|
||||||
|
LL | x
|
||||||
|
| ^ not found in this scope
|
||||||
|
|
||||||
|
error[E0223]: ambiguous associated type
|
||||||
|
--> $DIR/struct-pattern-on-non-struct-resolve-error.rs:4:12
|
||||||
|
|
|
||||||
|
LL | if let Iterator::Item { .. } = 1 {
|
||||||
|
| ^^^^^^^^^^^^^^
|
||||||
|
|
|
||||||
|
help: use fully-qualified syntax
|
||||||
|
|
|
||||||
|
LL | if let <Ancestors<'_> as Iterator>::Item { .. } = 1 {
|
||||||
|
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
LL | if let <Args as Iterator>::Item { .. } = 1 {
|
||||||
|
| ~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
LL | if let <ArgsOs as Iterator>::Item { .. } = 1 {
|
||||||
|
| ~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
LL | if let <CharIndices<'_> as Iterator>::Item { .. } = 1 {
|
||||||
|
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
and 71 other candidates
|
||||||
|
|
||||||
|
error: aborting due to 2 previous errors
|
||||||
|
|
||||||
|
Some errors have detailed explanations: E0223, E0425.
|
||||||
|
For more information about an error, try `rustc --explain E0223`.
|
Loading…
Add table
Add a link
Reference in a new issue