Skip to content

Commit f3744a1

Browse files
committed
Implement CRs
1 parent f922483 commit f3744a1

File tree

6 files changed

+46
-75
lines changed

6 files changed

+46
-75
lines changed

src/librustc_typeck/check/expr.rs

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1392,26 +1392,18 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
13921392
} else if !expr_t.is_primitive_ty() {
13931393
let mut err = self.no_such_field_err(field.span, field, expr_t);
13941394

1395-
match expr_t.kind {
1395+
match expr_t.peel_refs().kind {
13961396
ty::Array(_, len) => {
13971397
self.maybe_suggest_array_indexing(&mut err, expr, base, field, len);
13981398
}
13991399
ty::RawPtr(..) => {
14001400
self.suggest_first_deref_field(&mut err, expr, base, field);
14011401
}
1402-
_ => {}
1403-
}
1404-
1405-
let deref_t = match expr_t.kind {
1406-
ty::Ref(_, ref_t, _) => ref_t,
1407-
_ => &expr_t
1408-
};
1409-
match deref_t.kind {
14101402
ty::Adt(def, _) if !def.is_enum() => {
14111403
self.suggest_fields_on_recordish(&mut err, def, field);
14121404
}
14131405
ty::Param(param_ty) => {
1414-
self.explain_param(&mut err, param_ty);
1406+
self.point_at_param_definition(&mut err, param_ty);
14151407
}
14161408
_ => {}
14171409
}
@@ -1502,21 +1494,21 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
15021494
err.emit();
15031495
}
15041496

1505-
fn explain_param(
1506-
&self,
1507-
err: &mut DiagnosticBuilder<'_>,
1508-
param: ty::ParamTy,
1509-
) {
1497+
fn point_at_param_definition(&self, err: &mut DiagnosticBuilder<'_>, param: ty::ParamTy) {
15101498
let generics = self.tcx.generics_of(self.body_id.owner_def_id());
1511-
let param_def_id = generics.type_param(&param, self.tcx).def_id;
1499+
let generic_param = generics.type_param(&param, self.tcx);
1500+
if let ty::GenericParamDefKind::Type{synthetic: Some(..), ..} = generic_param.kind {
1501+
return;
1502+
}
1503+
let param_def_id = generic_param.def_id;
15121504
let param_hir_id = match self.tcx.hir().as_local_hir_id(param_def_id) {
15131505
Some(x) => x,
15141506
None => return,
15151507
};
15161508
let param_span = self.tcx.hir().span(param_hir_id);
15171509
let param_name = self.tcx.hir().ty_param_name(param_hir_id);
15181510

1519-
err.span_note(param_span, &format!("Type parameter '{}' was declared here", param_name));
1511+
err.span_label(param_span, &format!("type parameter '{}' declared here", param_name));
15201512
}
15211513

15221514
fn suggest_fields_on_recordish(

src/test/ui/derived-errors/issue-30580.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0609]: no field `c` on type `&Foo`
22
--> $DIR/issue-30580.rs:12:11
33
|
44
LL | b.c;
5-
| ^
5+
| ^ help: a field with a similar name exists: `a`
66

77
error: aborting due to previous error
88

src/test/ui/issues/issue-31011.stderr

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ error[E0609]: no field `trace` on type `&T`
44
LL | if $ctx.trace {
55
| ^^^^^
66
...
7+
LL | fn wrap<T>(context: &T) -> ()
8+
| - type parameter 'T' declared here
9+
LL | {
710
LL | log!(context, "entered wrapper");
811
| --------------------------------- in this macro invocation
912

src/test/ui/structs/struct-pat-derived-error.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0609]: no field `d` on type `&A`
22
--> $DIR/struct-pat-derived-error.rs:8:31
33
|
44
LL | let A { x, y } = self.d;
5-
| ^
5+
| ^ help: a field with a similar name exists: `b`
66

77
error[E0026]: struct `A` does not have fields named `x`, `y`
88
--> $DIR/struct-pat-derived-error.rs:8:17

src/test/ui/typeck/issue-52082.stderr renamed to src/test/ui/typeck/issue-52082-type-param-shadows-existing-type.stderr

Lines changed: 32 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,98 +1,74 @@
11
error[E0609]: no field `x` on type `&Point`
2-
--> $DIR/issue-52082.rs:31:11
2+
--> $DIR/issue-52082-type-param-shadows-existing-type.rs:31:11
33
|
4+
LL | fn equals_ref<Point>(a: &Point, b: &Point) -> bool
5+
| ----- type parameter 'Point' declared here
6+
LL | {
47
LL | a.x == b.x && a.y == b.y
58
| ^
6-
|
7-
note: Type parameter 'Point' was declared here
8-
--> $DIR/issue-52082.rs:29:19
9-
|
10-
LL | fn equals_ref<Point>(a: &Point, b: &Point) -> bool
11-
| ^^^^^
129

1310
error[E0609]: no field `x` on type `&Point`
14-
--> $DIR/issue-52082.rs:31:18
11+
--> $DIR/issue-52082-type-param-shadows-existing-type.rs:31:18
1512
|
13+
LL | fn equals_ref<Point>(a: &Point, b: &Point) -> bool
14+
| ----- type parameter 'Point' declared here
15+
LL | {
1616
LL | a.x == b.x && a.y == b.y
1717
| ^
18-
|
19-
note: Type parameter 'Point' was declared here
20-
--> $DIR/issue-52082.rs:29:19
21-
|
22-
LL | fn equals_ref<Point>(a: &Point, b: &Point) -> bool
23-
| ^^^^^
2418

2519
error[E0609]: no field `y` on type `&Point`
26-
--> $DIR/issue-52082.rs:31:25
20+
--> $DIR/issue-52082-type-param-shadows-existing-type.rs:31:25
2721
|
22+
LL | fn equals_ref<Point>(a: &Point, b: &Point) -> bool
23+
| ----- type parameter 'Point' declared here
24+
LL | {
2825
LL | a.x == b.x && a.y == b.y
2926
| ^
30-
|
31-
note: Type parameter 'Point' was declared here
32-
--> $DIR/issue-52082.rs:29:19
33-
|
34-
LL | fn equals_ref<Point>(a: &Point, b: &Point) -> bool
35-
| ^^^^^
3627

3728
error[E0609]: no field `y` on type `&Point`
38-
--> $DIR/issue-52082.rs:31:32
29+
--> $DIR/issue-52082-type-param-shadows-existing-type.rs:31:32
3930
|
31+
LL | fn equals_ref<Point>(a: &Point, b: &Point) -> bool
32+
| ----- type parameter 'Point' declared here
33+
LL | {
4034
LL | a.x == b.x && a.y == b.y
4135
| ^
42-
|
43-
note: Type parameter 'Point' was declared here
44-
--> $DIR/issue-52082.rs:29:19
45-
|
46-
LL | fn equals_ref<Point>(a: &Point, b: &Point) -> bool
47-
| ^^^^^
4836

4937
error[E0609]: no field `x` on type `Point`
50-
--> $DIR/issue-52082.rs:39:11
38+
--> $DIR/issue-52082-type-param-shadows-existing-type.rs:39:11
5139
|
40+
LL | fn equals_val<Point>(a: Point, b: Point) -> bool
41+
| ----- type parameter 'Point' declared here
42+
LL | {
5243
LL | a.x == b.x && a.y == b.y
5344
| ^
54-
|
55-
note: Type parameter 'Point' was declared here
56-
--> $DIR/issue-52082.rs:37:19
57-
|
58-
LL | fn equals_val<Point>(a: Point, b: Point) -> bool
59-
| ^^^^^
6045

6146
error[E0609]: no field `x` on type `Point`
62-
--> $DIR/issue-52082.rs:39:18
47+
--> $DIR/issue-52082-type-param-shadows-existing-type.rs:39:18
6348
|
49+
LL | fn equals_val<Point>(a: Point, b: Point) -> bool
50+
| ----- type parameter 'Point' declared here
51+
LL | {
6452
LL | a.x == b.x && a.y == b.y
6553
| ^
66-
|
67-
note: Type parameter 'Point' was declared here
68-
--> $DIR/issue-52082.rs:37:19
69-
|
70-
LL | fn equals_val<Point>(a: Point, b: Point) -> bool
71-
| ^^^^^
7254

7355
error[E0609]: no field `y` on type `Point`
74-
--> $DIR/issue-52082.rs:39:25
56+
--> $DIR/issue-52082-type-param-shadows-existing-type.rs:39:25
7557
|
58+
LL | fn equals_val<Point>(a: Point, b: Point) -> bool
59+
| ----- type parameter 'Point' declared here
60+
LL | {
7661
LL | a.x == b.x && a.y == b.y
7762
| ^
78-
|
79-
note: Type parameter 'Point' was declared here
80-
--> $DIR/issue-52082.rs:37:19
81-
|
82-
LL | fn equals_val<Point>(a: Point, b: Point) -> bool
83-
| ^^^^^
8463

8564
error[E0609]: no field `y` on type `Point`
86-
--> $DIR/issue-52082.rs:39:32
65+
--> $DIR/issue-52082-type-param-shadows-existing-type.rs:39:32
8766
|
67+
LL | fn equals_val<Point>(a: Point, b: Point) -> bool
68+
| ----- type parameter 'Point' declared here
69+
LL | {
8870
LL | a.x == b.x && a.y == b.y
8971
| ^
90-
|
91-
note: Type parameter 'Point' was declared here
92-
--> $DIR/issue-52082.rs:37:19
93-
|
94-
LL | fn equals_val<Point>(a: Point, b: Point) -> bool
95-
| ^^^^^
9672

9773
error: aborting due to 8 previous errors
9874

0 commit comments

Comments
 (0)