Refactor into ban_nonexisting_field method
This commit is contained in:
parent
f3744a1b3d
commit
9ad99c30cb
@ -1390,33 +1390,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
} else if self.method_exists(field, expr_t, expr.hir_id, true) {
|
||||
self.ban_take_value_of_method(expr, expr_t, field);
|
||||
} else if !expr_t.is_primitive_ty() {
|
||||
let mut err = self.no_such_field_err(field.span, field, expr_t);
|
||||
|
||||
match expr_t.peel_refs().kind {
|
||||
ty::Array(_, len) => {
|
||||
self.maybe_suggest_array_indexing(&mut err, expr, base, field, len);
|
||||
}
|
||||
ty::RawPtr(..) => {
|
||||
self.suggest_first_deref_field(&mut err, expr, base, field);
|
||||
}
|
||||
ty::Adt(def, _) if !def.is_enum() => {
|
||||
self.suggest_fields_on_recordish(&mut err, def, field);
|
||||
}
|
||||
ty::Param(param_ty) => {
|
||||
self.point_at_param_definition(&mut err, param_ty);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
if field.name == kw::Await {
|
||||
// We know by construction that `<expr>.await` is either on Rust 2015
|
||||
// or results in `ExprKind::Await`. Suggest switching the edition to 2018.
|
||||
err.note("to `.await` a `Future`, switch to Rust 2018");
|
||||
err.help("set `edition = \"2018\"` in `Cargo.toml`");
|
||||
err.note("for more on editions, read https://doc.rust-lang.org/edition-guide");
|
||||
}
|
||||
|
||||
err.emit();
|
||||
self.ban_nonexisting_field(field, base, expr, expr_t);
|
||||
} else {
|
||||
type_error_struct!(
|
||||
self.tcx().sess,
|
||||
@ -1432,6 +1406,42 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
self.tcx().types.err
|
||||
}
|
||||
|
||||
fn ban_nonexisting_field(
|
||||
&self,
|
||||
field: ast::Ident,
|
||||
base: &'tcx hir::Expr,
|
||||
expr: &'tcx hir::Expr,
|
||||
expr_t: Ty<'tcx>,
|
||||
) {
|
||||
let mut err = self.no_such_field_err(field.span, field, expr_t);
|
||||
|
||||
match expr_t.peel_refs().kind {
|
||||
ty::Array(_, len) => {
|
||||
self.maybe_suggest_array_indexing(&mut err, expr, base, field, len);
|
||||
}
|
||||
ty::RawPtr(..) => {
|
||||
self.suggest_first_deref_field(&mut err, expr, base, field);
|
||||
}
|
||||
ty::Adt(def, _) if !def.is_enum() => {
|
||||
self.suggest_fields_on_recordish(&mut err, def, field);
|
||||
}
|
||||
ty::Param(param_ty) => {
|
||||
self.point_at_param_definition(&mut err, param_ty);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
if field.name == kw::Await {
|
||||
// We know by construction that `<expr>.await` is either on Rust 2015
|
||||
// or results in `ExprKind::Await`. Suggest switching the edition to 2018.
|
||||
err.note("to `.await` a `Future`, switch to Rust 2018");
|
||||
err.help("set `edition = \"2018\"` in `Cargo.toml`");
|
||||
err.note("for more on editions, read https://doc.rust-lang.org/edition-guide");
|
||||
}
|
||||
|
||||
err.emit();
|
||||
}
|
||||
|
||||
fn ban_private_field_access(
|
||||
&self,
|
||||
expr: &hir::Expr,
|
||||
|
Loading…
x
Reference in New Issue
Block a user