Skip to content

Commit

Permalink
Implement CRs
Browse files Browse the repository at this point in the history
  • Loading branch information
Baranowski committed Sep 28, 2019
1 parent f922483 commit f3744a1
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 75 deletions.
26 changes: 9 additions & 17 deletions src/librustc_typeck/check/expr.rs
Expand Up @@ -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);
}
_ => {}
}
Expand Down Expand Up @@ -1502,21 +1494,21 @@ 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(&param, self.tcx).def_id;
let generic_param = generics.type_param(&param, 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,
};
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(
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/derived-errors/issue-30580.stderr
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions src/test/ui/issues/issue-31011.stderr
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/structs/struct-pat-derived-error.stderr
Expand Up @@ -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
Expand Down
File renamed without changes.
@@ -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
--> $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
| ^
|
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: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
--> $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
| ^
|
note: Type parameter 'Point' was declared here
--> $DIR/issue-52082.rs:37:19
|
LL | fn equals_val<Point>(a: Point, b: Point) -> bool
| ^^^^^

error: aborting due to 8 previous errors

Expand Down

0 comments on commit f3744a1

Please sign in to comment.