Implement CRs
This commit is contained in:
parent
f922483112
commit
f3744a1b3d
6 changed files with 48 additions and 77 deletions
|
@ -1392,26 +1392,18 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
} else if !expr_t.is_primitive_ty() {
|
||||
let mut err = self.no_such_field_err(field.span, field, expr_t);
|
||||
|
||||
match expr_t.kind {
|
||||
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);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
let deref_t = match expr_t.kind {
|
||||
ty::Ref(_, ref_t, _) => ref_t,
|
||||
_ => &expr_t
|
||||
};
|
||||
match deref_t.kind {
|
||||
ty::Adt(def, _) if !def.is_enum() => {
|
||||
self.suggest_fields_on_recordish(&mut err, def, field);
|
||||
}
|
||||
ty::Param(param_ty) => {
|
||||
self.explain_param(&mut err, param_ty);
|
||||
self.point_at_param_definition(&mut err, param_ty);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
@ -1502,13 +1494,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
err.emit();
|
||||
}
|
||||
|
||||
fn explain_param(
|
||||
&self,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
param: ty::ParamTy,
|
||||
) {
|
||||
fn point_at_param_definition(&self, err: &mut DiagnosticBuilder<'_>, param: ty::ParamTy) {
|
||||
let generics = self.tcx.generics_of(self.body_id.owner_def_id());
|
||||
let param_def_id = generics.type_param(¶m, self.tcx).def_id;
|
||||
let generic_param = generics.type_param(¶m, self.tcx);
|
||||
if let ty::GenericParamDefKind::Type{synthetic: Some(..), ..} = generic_param.kind {
|
||||
return;
|
||||
}
|
||||
let param_def_id = generic_param.def_id;
|
||||
let param_hir_id = match self.tcx.hir().as_local_hir_id(param_def_id) {
|
||||
Some(x) => x,
|
||||
None => return,
|
||||
|
@ -1516,7 +1508,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
let param_span = self.tcx.hir().span(param_hir_id);
|
||||
let param_name = self.tcx.hir().ty_param_name(param_hir_id);
|
||||
|
||||
err.span_note(param_span, &format!("Type parameter '{}' was declared here", param_name));
|
||||
err.span_label(param_span, &format!("type parameter '{}' declared here", param_name));
|
||||
}
|
||||
|
||||
fn suggest_fields_on_recordish(
|
||||
|
|
|
@ -2,7 +2,7 @@ error[E0609]: no field `c` on type `&Foo`
|
|||
--> $DIR/issue-30580.rs:12:11
|
||||
|
|
||||
LL | b.c;
|
||||
| ^
|
||||
| ^ help: a field with a similar name exists: `a`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
@ -4,6 +4,9 @@ error[E0609]: no field `trace` on type `&T`
|
|||
LL | if $ctx.trace {
|
||||
| ^^^^^
|
||||
...
|
||||
LL | fn wrap<T>(context: &T) -> ()
|
||||
| - type parameter 'T' declared here
|
||||
LL | {
|
||||
LL | log!(context, "entered wrapper");
|
||||
| --------------------------------- in this macro invocation
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ error[E0609]: no field `d` on type `&A`
|
|||
--> $DIR/struct-pat-derived-error.rs:8:31
|
||||
|
|
||||
LL | let A { x, y } = self.d;
|
||||
| ^
|
||||
| ^ help: a field with a similar name exists: `b`
|
||||
|
||||
error[E0026]: struct `A` does not have fields named `x`, `y`
|
||||
--> $DIR/struct-pat-derived-error.rs:8:17
|
||||
|
|
|
@ -1,98 +1,74 @@
|
|||
error[E0609]: no field `x` on type `&Point`
|
||||
--> $DIR/issue-52082.rs:31:11
|
||||
--> $DIR/issue-52082-type-param-shadows-existing-type.rs:31:11
|
||||
|
|
||||
LL | fn equals_ref<Point>(a: &Point, b: &Point) -> bool
|
||||
| ----- type parameter 'Point' declared here
|
||||
LL | {
|
||||
LL | a.x == b.x && a.y == b.y
|
||||
| ^
|
||||
|
|
||||
note: Type parameter 'Point' was declared here
|
||||
--> $DIR/issue-52082.rs:29:19
|
||||
|
|
||||
LL | fn equals_ref<Point>(a: &Point, b: &Point) -> bool
|
||||
| ^^^^^
|
||||
|
||||
error[E0609]: no field `x` on type `&Point`
|
||||
--> $DIR/issue-52082.rs:31:18
|
||||
--> $DIR/issue-52082-type-param-shadows-existing-type.rs:31:18
|
||||
|
|
||||
LL | fn equals_ref<Point>(a: &Point, b: &Point) -> bool
|
||||
| ----- type parameter 'Point' declared here
|
||||
LL | {
|
||||
LL | a.x == b.x && a.y == b.y
|
||||
| ^
|
||||
|
|
||||
note: Type parameter 'Point' was declared here
|
||||
--> $DIR/issue-52082.rs:29:19
|
||||
|
|
||||
LL | fn equals_ref<Point>(a: &Point, b: &Point) -> bool
|
||||
| ^^^^^
|
||||
|
||||
error[E0609]: no field `y` on type `&Point`
|
||||
--> $DIR/issue-52082.rs:31:25
|
||||
--> $DIR/issue-52082-type-param-shadows-existing-type.rs:31:25
|
||||
|
|
||||
LL | fn equals_ref<Point>(a: &Point, b: &Point) -> bool
|
||||
| ----- type parameter 'Point' declared here
|
||||
LL | {
|
||||
LL | a.x == b.x && a.y == b.y
|
||||
| ^
|
||||
|
|
||||
note: Type parameter 'Point' was declared here
|
||||
--> $DIR/issue-52082.rs:29:19
|
||||
|
|
||||
LL | fn equals_ref<Point>(a: &Point, b: &Point) -> bool
|
||||
| ^^^^^
|
||||
|
||||
error[E0609]: no field `y` on type `&Point`
|
||||
--> $DIR/issue-52082.rs:31:32
|
||||
|
|
||||
LL | a.x == b.x && a.y == b.y
|
||||
| ^
|
||||
|
|
||||
note: Type parameter 'Point' was declared here
|
||||
--> $DIR/issue-52082.rs:29:19
|
||||
--> $DIR/issue-52082-type-param-shadows-existing-type.rs:31:32
|
||||
|
|
||||
LL | fn equals_ref<Point>(a: &Point, b: &Point) -> bool
|
||||
| ^^^^^
|
||||
| ----- type parameter 'Point' declared here
|
||||
LL | {
|
||||
LL | a.x == b.x && a.y == b.y
|
||||
| ^
|
||||
|
||||
error[E0609]: no field `x` on type `Point`
|
||||
--> $DIR/issue-52082.rs:39:11
|
||||
--> $DIR/issue-52082-type-param-shadows-existing-type.rs:39:11
|
||||
|
|
||||
LL | fn equals_val<Point>(a: Point, b: Point) -> bool
|
||||
| ----- type parameter 'Point' declared here
|
||||
LL | {
|
||||
LL | a.x == b.x && a.y == b.y
|
||||
| ^
|
||||
|
|
||||
note: Type parameter 'Point' was declared here
|
||||
--> $DIR/issue-52082.rs:37:19
|
||||
|
|
||||
LL | fn equals_val<Point>(a: Point, b: Point) -> bool
|
||||
| ^^^^^
|
||||
|
||||
error[E0609]: no field `x` on type `Point`
|
||||
--> $DIR/issue-52082.rs:39:18
|
||||
--> $DIR/issue-52082-type-param-shadows-existing-type.rs:39:18
|
||||
|
|
||||
LL | fn equals_val<Point>(a: Point, b: Point) -> bool
|
||||
| ----- type parameter 'Point' declared here
|
||||
LL | {
|
||||
LL | a.x == b.x && a.y == b.y
|
||||
| ^
|
||||
|
|
||||
note: Type parameter 'Point' was declared here
|
||||
--> $DIR/issue-52082.rs:37:19
|
||||
|
|
||||
LL | fn equals_val<Point>(a: Point, b: Point) -> bool
|
||||
| ^^^^^
|
||||
|
||||
error[E0609]: no field `y` on type `Point`
|
||||
--> $DIR/issue-52082.rs:39:25
|
||||
--> $DIR/issue-52082-type-param-shadows-existing-type.rs:39:25
|
||||
|
|
||||
LL | fn equals_val<Point>(a: Point, b: Point) -> bool
|
||||
| ----- type parameter 'Point' declared here
|
||||
LL | {
|
||||
LL | a.x == b.x && a.y == b.y
|
||||
| ^
|
||||
|
|
||||
note: Type parameter 'Point' was declared here
|
||||
--> $DIR/issue-52082.rs:37:19
|
||||
|
|
||||
LL | fn equals_val<Point>(a: Point, b: Point) -> bool
|
||||
| ^^^^^
|
||||
|
||||
error[E0609]: no field `y` on type `Point`
|
||||
--> $DIR/issue-52082.rs:39:32
|
||||
|
|
||||
LL | a.x == b.x && a.y == b.y
|
||||
| ^
|
||||
|
|
||||
note: Type parameter 'Point' was declared here
|
||||
--> $DIR/issue-52082.rs:37:19
|
||||
--> $DIR/issue-52082-type-param-shadows-existing-type.rs:39:32
|
||||
|
|
||||
LL | fn equals_val<Point>(a: Point, b: Point) -> bool
|
||||
| ^^^^^
|
||||
| ----- type parameter 'Point' declared here
|
||||
LL | {
|
||||
LL | a.x == b.x && a.y == b.y
|
||||
| ^
|
||||
|
||||
error: aborting due to 8 previous errors
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue