Skip to content

Commit 96d282c

Browse files
authored
Rollup merge of rust-lang#139654 - nnethercote:AssocKind-descr, r=compiler-errors
Improve `AssocItem::descr`. The commit adds "associated" to the description of associated types and associated consts, to match the description of associated functions. This increases error message precision and consistency with `AssocKind::fmt`. The commit also notes an imperfection in `AssocKind::fmt`; fixing this imperfection is possible but beyond the scope of this PR. r? `@estebank`
2 parents 25d282e + 7e8184f commit 96d282c

21 files changed

+53
-51
lines changed

compiler/rustc_middle/src/ty/assoc.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,10 @@ impl AssocItem {
9898

9999
pub fn descr(&self) -> &'static str {
100100
match self.kind {
101-
ty::AssocKind::Const => "const",
101+
ty::AssocKind::Const => "associated const",
102102
ty::AssocKind::Fn if self.fn_has_self_parameter => "method",
103103
ty::AssocKind::Fn => "associated function",
104-
ty::AssocKind::Type => "type",
104+
ty::AssocKind::Type => "associated type",
105105
}
106106
}
107107

@@ -155,6 +155,8 @@ impl AssocKind {
155155
impl std::fmt::Display for AssocKind {
156156
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
157157
match self {
158+
// FIXME: fails to distinguish between "associated function" and
159+
// "method" because `has_self` isn't known here.
158160
AssocKind::Fn => write!(f, "method"),
159161
AssocKind::Const => write!(f, "associated const"),
160162
AssocKind::Type => write!(f, "associated type"),

tests/ui/consts/static-default-lifetime/elided-lifetime.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ impl Bar for Foo<'_> {
1616
const STATIC: &str = "";
1717
//~^ ERROR `&` without an explicit lifetime name cannot be used here
1818
//~| WARN this was previously accepted by the compiler but is being phased out
19-
//~| ERROR lifetime parameters or bounds on const `STATIC` do not match the trait declaration
19+
//~| ERROR lifetime parameters or bounds on associated const `STATIC` do not match the trait declaration
2020
}
2121

2222
fn main() {}

tests/ui/consts/static-default-lifetime/elided-lifetime.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ help: use the `'static` lifetime
3939
LL | const STATIC: &'static str = "";
4040
| +++++++
4141

42-
error[E0195]: lifetime parameters or bounds on const `STATIC` do not match the trait declaration
42+
error[E0195]: lifetime parameters or bounds on associated const `STATIC` do not match the trait declaration
4343
--> $DIR/elided-lifetime.rs:16:17
4444
|
4545
LL | const STATIC: &str;
46-
| - lifetimes in impl do not match this const in trait
46+
| - lifetimes in impl do not match this associated const in trait
4747
...
4848
LL | const STATIC: &str = "";
49-
| ^ lifetimes do not match const in trait
49+
| ^ lifetimes do not match associated const in trait
5050

5151
error: aborting due to 3 previous errors
5252

tests/ui/consts/static-default-lifetime/static-trait-impl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ impl Bar<'_> for A {
99
const STATIC: &str = "";
1010
//~^ ERROR `&` without an explicit lifetime name cannot be used here
1111
//~| WARN this was previously accepted by the compiler but is being phased out
12-
//~| ERROR lifetime parameters or bounds on const `STATIC` do not match the trait declaration
12+
//~| ERROR lifetime parameters or bounds on associated const `STATIC` do not match the trait declaration
1313
}
1414

1515
struct B;

tests/ui/consts/static-default-lifetime/static-trait-impl.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ help: use the `'static` lifetime
2121
LL | const STATIC: &'static str = "";
2222
| +++++++
2323

24-
error[E0195]: lifetime parameters or bounds on const `STATIC` do not match the trait declaration
24+
error[E0195]: lifetime parameters or bounds on associated const `STATIC` do not match the trait declaration
2525
--> $DIR/static-trait-impl.rs:9:17
2626
|
2727
LL | const STATIC: &'a str;
28-
| - lifetimes in impl do not match this const in trait
28+
| - lifetimes in impl do not match this associated const in trait
2929
...
3030
LL | const STATIC: &str = "";
31-
| ^ lifetimes do not match const in trait
31+
| ^ lifetimes do not match associated const in trait
3232

3333
error: aborting due to 2 previous errors
3434

tests/ui/generic-associated-types/const_params_have_right_type.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0053]: type `Foo` has an incompatible generic parameter for trait `Trait`
1+
error[E0053]: associated type `Foo` has an incompatible generic parameter for trait `Trait`
22
--> $DIR/const_params_have_right_type.rs:6:14
33
|
44
LL | trait Trait {

tests/ui/generic-associated-types/issue-102114.current.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0049]: type `B` has 1 type parameter but its trait declaration has 0 type parameters
1+
error[E0049]: associated type `B` has 1 type parameter but its trait declaration has 0 type parameters
22
--> $DIR/issue-102114.rs:15:12
33
|
44
LL | type B<'b>;

tests/ui/generic-associated-types/issue-102114.next.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0049]: type `B` has 1 type parameter but its trait declaration has 0 type parameters
1+
error[E0049]: associated type `B` has 1 type parameter but its trait declaration has 0 type parameters
22
--> $DIR/issue-102114.rs:15:12
33
|
44
LL | type B<'b>;

tests/ui/generic-associated-types/parameter_number_and_kind_impl.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ struct Fooy;
1212

1313
impl Foo for Fooy {
1414
type A = u32;
15-
//~^ ERROR lifetime parameters or bounds on type `A` do not match the trait declaration
15+
//~^ ERROR lifetime parameters or bounds on associated type `A` do not match the trait declaration
1616
type B<'a, T> = Vec<T>;
1717
//~^ ERROR type `B` has 1 type parameter but its trait declaration has 0 type parameters
1818
type C<'a> = u32;
19-
//~^ ERROR lifetime parameters or bounds on type `C` do not match the trait declaration
19+
//~^ ERROR lifetime parameters or bounds on associated type `C` do not match the trait declaration
2020
}
2121

2222
struct Fooer;
@@ -25,7 +25,7 @@ impl Foo for Fooer {
2525
type A<T> = u32;
2626
//~^ ERROR type `A` has 1 type parameter but its trait declaration has 0 type parameters
2727
type B<'a> = u32;
28-
//~^ ERROR lifetime parameters or bounds on type `B` do not match the trait declaration
28+
//~^ ERROR lifetime parameters or bounds on associated type `B` do not match the trait declaration
2929
type C<T> = T;
3030
//~^ ERROR type `C` has 1 type parameter but its trait declaration has 0 type parameters
3131
}

tests/ui/generic-associated-types/parameter_number_and_kind_impl.stderr

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
error[E0195]: lifetime parameters or bounds on type `A` do not match the trait declaration
1+
error[E0195]: lifetime parameters or bounds on associated type `A` do not match the trait declaration
22
--> $DIR/parameter_number_and_kind_impl.rs:14:11
33
|
44
LL | type A<'a>;
5-
| ---- lifetimes in impl do not match this type in trait
5+
| ---- lifetimes in impl do not match this associated type in trait
66
...
77
LL | type A = u32;
8-
| ^ lifetimes do not match type in trait
8+
| ^ lifetimes do not match associated type in trait
99

10-
error[E0049]: type `B` has 1 type parameter but its trait declaration has 0 type parameters
10+
error[E0049]: associated type `B` has 1 type parameter but its trait declaration has 0 type parameters
1111
--> $DIR/parameter_number_and_kind_impl.rs:16:12
1212
|
1313
LL | type B<'a, 'b>;
@@ -20,16 +20,16 @@ LL | type B<'a, T> = Vec<T>;
2020
| |
2121
| found 1 type parameter
2222

23-
error[E0195]: lifetime parameters or bounds on type `C` do not match the trait declaration
23+
error[E0195]: lifetime parameters or bounds on associated type `C` do not match the trait declaration
2424
--> $DIR/parameter_number_and_kind_impl.rs:18:11
2525
|
2626
LL | type C;
27-
| - lifetimes in impl do not match this type in trait
27+
| - lifetimes in impl do not match this associated type in trait
2828
...
2929
LL | type C<'a> = u32;
30-
| ^^^^ lifetimes do not match type in trait
30+
| ^^^^ lifetimes do not match associated type in trait
3131

32-
error[E0049]: type `A` has 1 type parameter but its trait declaration has 0 type parameters
32+
error[E0049]: associated type `A` has 1 type parameter but its trait declaration has 0 type parameters
3333
--> $DIR/parameter_number_and_kind_impl.rs:25:12
3434
|
3535
LL | type A<'a>;
@@ -38,16 +38,16 @@ LL | type A<'a>;
3838
LL | type A<T> = u32;
3939
| ^ found 1 type parameter
4040

41-
error[E0195]: lifetime parameters or bounds on type `B` do not match the trait declaration
41+
error[E0195]: lifetime parameters or bounds on associated type `B` do not match the trait declaration
4242
--> $DIR/parameter_number_and_kind_impl.rs:27:11
4343
|
4444
LL | type B<'a, 'b>;
45-
| -------- lifetimes in impl do not match this type in trait
45+
| -------- lifetimes in impl do not match this associated type in trait
4646
...
4747
LL | type B<'a> = u32;
48-
| ^^^^ lifetimes do not match type in trait
48+
| ^^^^ lifetimes do not match associated type in trait
4949

50-
error[E0049]: type `C` has 1 type parameter but its trait declaration has 0 type parameters
50+
error[E0049]: associated type `C` has 1 type parameter but its trait declaration has 0 type parameters
5151
--> $DIR/parameter_number_and_kind_impl.rs:29:12
5252
|
5353
LL | type C;

0 commit comments

Comments
 (0)