suggest tuple struct syntax
This commit is contained in:
parent
b01a257da1
commit
f7ecf1c548
@ -1215,38 +1215,49 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
}
|
||||
},
|
||||
ty);
|
||||
// prevent all specified fields from being suggested
|
||||
let skip_fields = skip_fields.iter().map(|ref x| x.ident.as_str());
|
||||
if let Some(field_name) = Self::suggest_field_name(variant,
|
||||
&field.ident.as_str(),
|
||||
skip_fields.collect()) {
|
||||
err.span_suggestion(
|
||||
field.ident.span,
|
||||
"a field with a similar name exists",
|
||||
field_name.to_string(),
|
||||
Applicability::MaybeIncorrect,
|
||||
);
|
||||
} else {
|
||||
match ty.sty {
|
||||
ty::Adt(adt, ..) => {
|
||||
if adt.is_enum() {
|
||||
err.span_label(field.ident.span,
|
||||
format!("`{}::{}` does not have this field",
|
||||
ty, variant.ident));
|
||||
} else {
|
||||
err.span_label(field.ident.span,
|
||||
format!("`{}` does not have this field", ty));
|
||||
}
|
||||
let available_field_names = self.available_field_names(variant);
|
||||
if !available_field_names.is_empty() {
|
||||
err.note(&format!("available fields are: {}",
|
||||
self.name_series_display(available_field_names)));
|
||||
}
|
||||
}
|
||||
_ => bug!("non-ADT passed to report_unknown_field")
|
||||
match variant.ctor_kind {
|
||||
CtorKind::Fn => {
|
||||
err.span_label(field.ident.span, "field does not exist");
|
||||
err.span_label(
|
||||
field.ident.span,
|
||||
format!("`{adt}` is a tuple {kind_name}, use the appropriate syntax: `{adt}(/* fields */)`", adt=ty, kind_name=kind_name)
|
||||
);
|
||||
}
|
||||
};
|
||||
err.emit();
|
||||
_ => {
|
||||
// prevent all specified fields from being suggested
|
||||
let skip_fields = skip_fields.iter().map(|ref x| x.ident.as_str());
|
||||
if let Some(field_name) = Self::suggest_field_name(variant,
|
||||
&field.ident.as_str(),
|
||||
skip_fields.collect()) {
|
||||
err.span_suggestion(
|
||||
field.ident.span,
|
||||
"a field with a similar name exists",
|
||||
field_name.to_string(),
|
||||
Applicability::MaybeIncorrect,
|
||||
);
|
||||
} else {
|
||||
match ty.sty {
|
||||
ty::Adt(adt, ..) => {
|
||||
if adt.is_enum() {
|
||||
err.span_label(field.ident.span,
|
||||
format!("`{}::{}` does not have this field",
|
||||
ty, variant.ident));
|
||||
} else {
|
||||
err.span_label(field.ident.span,
|
||||
format!("`{}` does not have this field", ty));
|
||||
}
|
||||
let available_field_names = self.available_field_names(variant);
|
||||
if !available_field_names.is_empty() {
|
||||
err.note(&format!("available fields are: {}",
|
||||
self.name_series_display(available_field_names)));
|
||||
}
|
||||
}
|
||||
_ => bug!("non-ADT passed to report_unknown_field")
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
err.emit();
|
||||
}
|
||||
|
||||
// Return an hint about the closest match in field names
|
||||
|
@ -2,7 +2,10 @@ error[E0560]: struct `NonCopyable` has no field named `p`
|
||||
--> $DIR/issue-4736.rs:4:26
|
||||
|
|
||||
LL | let z = NonCopyable{ p: () };
|
||||
| ^ help: a field with a similar name exists: `0`
|
||||
| ^
|
||||
| |
|
||||
| field does not exist
|
||||
| `NonCopyable` is a tuple struct, use the appropriate syntax: `NonCopyable(/* fields */)`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
@ -2,9 +2,10 @@ error[E0560]: struct `S` has no field named `0b1`
|
||||
--> $DIR/numeric-fields.rs:4:15
|
||||
|
|
||||
LL | let s = S{0b1: 10, 0: 11};
|
||||
| ^^^ `S` does not have this field
|
||||
|
|
||||
= note: available fields are: `0`, `1`
|
||||
| ^^^
|
||||
| |
|
||||
| field does not exist
|
||||
| `S` is a tuple struct, use the appropriate syntax: `S(/* fields */)`
|
||||
|
||||
error[E0026]: struct `S` does not have a field named `0x1`
|
||||
--> $DIR/numeric-fields.rs:7:17
|
||||
|
Loading…
x
Reference in New Issue
Block a user