Skip to content

Commit 2cba36b

Browse files
committed
Diagnostic language tweaks
1 parent 46a659f commit 2cba36b

File tree

8 files changed

+45
-44
lines changed

8 files changed

+45
-44
lines changed

Diff for: crates/hir-analysis/src/ty/diagnostics.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -943,7 +943,7 @@ impl<'db> BodyDiag<'db> {
943943
Self::DuplicatedBinding { name, .. } => {
944944
format!("duplicate binding `{}` in pattern", name.data(db))
945945
}
946-
Self::DuplicatedRestPat(_) => "duplicate `..` found".to_string(),
946+
Self::DuplicatedRestPat(_) => "duplicate `..` in pattern".to_string(),
947947
Self::InvalidPathDomainInPat { .. } => "invalid item is given here".to_string(),
948948
Self::UnitVariantExpected { .. } => "expected unit variant".to_string(),
949949
Self::TupleVariantExpected { .. } => "expected tuple variant".to_string(),
@@ -952,7 +952,7 @@ impl<'db> BodyDiag<'db> {
952952
Self::DuplicatedRecordFieldBind { .. } => "duplicated record field binding".to_string(),
953953
Self::RecordFieldNotFound { .. } => "specified field not found".to_string(),
954954
Self::ExplicitLabelExpectedInRecord { .. } => "explicit label is required".to_string(),
955-
Self::MissingRecordFields { .. } => "all fields are not given".to_string(),
955+
Self::MissingRecordFields { .. } => "missing fields in record pattern".to_string(),
956956
Self::UndefinedVariable(..) => "undefined variable".to_string(),
957957
Self::ReturnedTypeMismatch { .. } => "returned type mismatch".to_string(),
958958
Self::TypeMustBeKnown(..) => "type must be known here".to_string(),
@@ -978,14 +978,14 @@ impl<'db> BodyDiag<'db> {
978978
format!("`{}` needs to be implemented for {ty}", trait_name.data(db))
979979
}
980980

981-
Self::NotCallable(..) => "not callable type is given in call expression".to_string(),
981+
Self::NotCallable(_, ty) => format!("expected function, found `{ty}`"),
982982

983983
Self::CallGenericArgNumMismatch { .. } => {
984984
"given generic argument number mismatch".to_string()
985985
}
986986

987-
Self::CallArgNumMismatch { .. } => "given argument number mismatch".to_string(),
988-
Self::CallArgLabelMismatch { .. } => "given argument label mismatch".to_string(),
987+
Self::CallArgNumMismatch { .. } => "argument number mismatch".to_string(),
988+
Self::CallArgLabelMismatch { .. } => "argument label mismatch".to_string(),
989989

990990
Self::AmbiguousInherentMethodCall { .. } => "ambiguous method call".to_string(),
991991

@@ -1164,7 +1164,7 @@ impl<'db> BodyDiag<'db> {
11641164
vec![
11651165
SubDiagnostic::new(
11661166
LabelStyle::Primary,
1167-
format!("duplicated field binding `{}`", name),
1167+
format!("duplicate field binding `{}`", name),
11681168
primary.resolve(db),
11691169
),
11701170
SubDiagnostic::new(
@@ -1314,7 +1314,7 @@ impl<'db> BodyDiag<'db> {
13141314
vec![
13151315
SubDiagnostic::new(
13161316
LabelStyle::Primary,
1317-
format!("`{}` cant be applied to `{}`", op, ty),
1317+
format!("`{}` can't be applied to `{}`", op, ty),
13181318
span.resolve(db),
13191319
),
13201320
SubDiagnostic::new(
@@ -1381,7 +1381,7 @@ impl<'db> BodyDiag<'db> {
13811381
Self::NotCallable(primary, ty) => {
13821382
vec![SubDiagnostic::new(
13831383
LabelStyle::Primary,
1384-
format!("`{ty}` is not callable"),
1384+
format!("call expression requires function; `{ty}` is not callable"),
13851385
primary.resolve(db),
13861386
)]
13871387
}

Diff for: crates/uitest/fixtures/ty_check/aug_assign.snap

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
---
22
source: crates/uitest/tests/ty_check.rs
33
expression: diags
4-
input_file: crates/uitest/fixtures/ty_check/aug_assign.fe
4+
input_file: fixtures/ty_check/aug_assign.fe
55
---
66
error[8-0016]: `std::ops::SubAssign` trait is not implemented
77
┌─ aug_assign.fe:6:5
88
99
6f -= f
1010
^^^^^^
1111
│ │
12-
`-=` cant be applied to `Foo`
12+
`-=` can't be applied to `Foo`
1313
Try implementing `std::ops::SubAssign` for `Foo`
1414

1515
error[8-0018]: left-hand side of assignment is immutable
@@ -20,5 +20,3 @@ error[8-0018]: left-hand side of assignment is immutable
2020
6f -= f
2121
7f.x *= 1
2222
^^^ immutable assignment
23-
24-

Diff for: crates/uitest/fixtures/ty_check/binary.snap

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
---
22
source: crates/uitest/tests/ty_check.rs
33
expression: diags
4-
input_file: crates/uitest/fixtures/ty_check/binary.fe
4+
input_file: fixtures/ty_check/binary.fe
55
---
66
error[8-0016]: `std::ops::Add` trait is not implemented
77
┌─ binary.fe:4:5
88
99
4f + f
1010
^^^^^
1111
│ │
12-
`+` cant be applied to `Foo`
12+
`+` can't be applied to `Foo`
1313
Try implementing `std::ops::Add` for `Foo`
1414

1515
error[8-0016]: `std::ops::And` trait is not implemented
@@ -18,7 +18,7 @@ error[8-0016]: `std::ops::And` trait is not implemented
1818
6 │ (f && f) || f
1919
^^^^^^
2020
│ │
21-
`&&` cant be applied to `Foo`
21+
`&&` can't be applied to `Foo`
2222
Try implementing `std::ops::And` for `Foo`
2323

2424
error[8-0016]: `std::ops::Eq` trait is not implemented
@@ -27,7 +27,7 @@ error[8-0016]: `std::ops::Eq` trait is not implemented
2727
7f == f
2828
^^^^^^
2929
│ │
30-
`==` cant be applied to `Foo`
30+
`==` can't be applied to `Foo`
3131
Try implementing `std::ops::Eq` for `Foo`
3232

3333
error[8-0016]: `std::ops::Ord` trait is not implemented
@@ -36,7 +36,5 @@ error[8-0016]: `std::ops::Ord` trait is not implemented
3636
8f < f
3737
^^^^^
3838
│ │
39-
`<` cant be applied to `Foo`
39+
`<` can't be applied to `Foo`
4040
Try implementing `std::ops::Ord` for `Foo`
41-
42-

Diff for: crates/uitest/fixtures/ty_check/call.fe

+6-1
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,9 @@ pub fn make_tuple<T, U>(_ t: T, _ u: U) -> (T, U) {
1515

1616
pub fn use_make_tuple() -> (i32, u32) {
1717
make_tuple<i32, u32>(false, 1)
18-
}
18+
}
19+
20+
fn f() {
21+
let x: u32 = 1
22+
x(100)
23+
}

Diff for: crates/uitest/fixtures/ty_check/call.snap

+12-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
source: crates/uitest/tests/ty_check.rs
33
expression: diags
4-
input_file: crates/uitest/fixtures/ty_check/call.fe
4+
input_file: fixtures/ty_check/call.fe
55
---
66
error[8-0000]: type mismatch
77
┌─ call.fe:9:12
@@ -15,7 +15,13 @@ error[8-0000]: type mismatch
1515
17make_tuple<i32, u32>(false, 1)
1616
│ ^^^^^ expected `i32`, but `bool` is given
1717

18-
error[8-0024]: given argument label mismatch
18+
error[8-0021]: expected function, found `u32`
19+
┌─ call.fe:22:5
20+
21+
22 │ x(100)
22+
│ ^ call expression requires function; `u32` is not callable
23+
24+
error[8-0024]: argument label mismatch
1925
┌─ call.fe:6:9
2026
2127
1pub fn add(x: i32, y: i32) -> i32 {
@@ -24,7 +30,7 @@ error[8-0024]: given argument label mismatch
2430
6 │ add(1, 2)
2531
│ ^ expected `x` label
2632

27-
error[8-0024]: given argument label mismatch
33+
error[8-0024]: argument label mismatch
2834
┌─ call.fe:6:12
2935
3036
1 │ pub fn add(x: i32, y: i32) -> i32 {
@@ -33,7 +39,7 @@ error[8-0024]: given argument label mismatch
3339
6 │ add(1, 2)
3440
│ ^ expected `y` label
3541

36-
error[8-0024]: given argument label mismatch
42+
error[8-0024]: argument label mismatch
3743
┌─ call.fe:7:9
3844
3945
1 │ pub fn add(x: i32, y: i32) -> i32 {
@@ -42,7 +48,7 @@ error[8-0024]: given argument label mismatch
4248
7 │ add(y: 1, x: 2)
4349
│ ^ expected `x` label, but `y` given
4450

45-
error[8-0024]: given argument label mismatch
51+
error[8-0024]: argument label mismatch
4652
┌─ call.fe:7:15
4753
4854
1 │ pub fn add(x: i32, y: i32) -> i32 {
@@ -51,13 +57,11 @@ error[8-0024]: given argument label mismatch
5157
7 │ add(y: 1, x: 2)
5258
│ ^ expected `y` label, but `x` given
5359

54-
error[8-0024]: given argument label mismatch
60+
error[8-0024]: argument label mismatch
5561
┌─ call.fe:8:15
5662
5763
1 │ pub fn add(x: i32, y: i32) -> i32 {
5864
--- function defined here
5965
·
6066
8 │ add(x: 1, z: 2)
6167
│ ^ expected `y` label, but `z` given
62-
63-

Diff for: crates/uitest/fixtures/ty_check/index.snap

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
source: crates/uitest/tests/ty_check.rs
33
expression: diags
4-
input_file: crates/uitest/fixtures/ty_check/index.fe
4+
input_file: fixtures/ty_check/index.fe
55
---
66
error[8-0000]: type mismatch
77
┌─ index.fe:4:7
@@ -15,7 +15,5 @@ error[8-0016]: `std::ops::Index` trait is not implemented
1515
6f[1]
1616
│ ^^^^
1717
│ │
18-
│ `[]` cant be applied to `Foo`
18+
│ `[]` can't be applied to `Foo`
1919
Try implementing `std::ops::Index` for `Foo`
20-
21-

Diff for: crates/uitest/fixtures/ty_check/pat/record.snap

+6-6
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ source: crates/uitest/tests/ty_check.rs
33
expression: diags
44
input_file: fixtures/ty_check/pat/record.fe
55
---
6-
error[8-0002]: duplicate `..` found
6+
error[8-0002]: duplicate `..` in pattern
77
┌─ record.fe:13:24
88
99
13let Foo {x, .., y, ..}
1010
^^ `..` can be used only once
1111

12-
error[8-0002]: duplicate `..` found
12+
error[8-0002]: duplicate `..` in pattern
1313
┌─ record.fe:19:33
1414
1515
19let Bar::Variant {x, .., y, ..}
@@ -19,15 +19,15 @@ error[8-0008]: duplicated record field binding
1919
┌─ record.fe:12:17
2020
2121
12let Foo {x, x}
22-
- ^ duplicated field binding `x`
22+
- ^ duplicate field binding `x`
2323
│ │
2424
first use of `x`
2525

2626
error[8-0008]: duplicated record field binding
2727
┌─ record.fe:18:26
2828
2929
18let Bar::Variant {x, x}
30-
- ^ duplicated field binding `x`
30+
- ^ duplicate field binding `x`
3131
│ │
3232
first use of `x`
3333

@@ -61,7 +61,7 @@ error[8-0010]: explicit label is required
6161
explicit label is required
6262
Consider using `Bar::Variant { x, y }` instead
6363

64-
error[8-0011]: all fields are not given
64+
error[8-0011]: missing fields in record pattern
6565
┌─ record.fe:16:13
6666
6767
16let Foo {x}
@@ -70,7 +70,7 @@ error[8-0011]: all fields are not given
7070
missing `y`
7171
Consider using `Foo { x, y }` instead
7272

73-
error[8-0011]: all fields are not given
73+
error[8-0011]: missing fields in record pattern
7474
┌─ record.fe:22:22
7575
7676
22let Bar::Variant {}

Diff for: crates/uitest/fixtures/ty_check/unary.snap

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
---
22
source: crates/uitest/tests/ty_check.rs
33
expression: diags
4-
input_file: crates/uitest/fixtures/ty_check/unary.fe
4+
input_file: fixtures/ty_check/unary.fe
55
---
66
error[8-0016]: `std::ops::UnaryPlus` trait is not implemented
77
┌─ unary.fe:5:5
88
99
5+f
1010
^^
1111
│ │
12-
`+` cant be applied to `Foo`
12+
`+` can't be applied to `Foo`
1313
Try implementing `std::ops::UnaryPlus` for `Foo`
1414

1515
error[8-0016]: `std::ops::Neg` trait is not implemented
@@ -18,7 +18,7 @@ error[8-0016]: `std::ops::Neg` trait is not implemented
1818
6-f
1919
^^
2020
│ │
21-
`-` cant be applied to `Foo`
21+
`-` can't be applied to `Foo`
2222
Try implementing `std::ops::Neg` for `Foo`
2323

2424
error[8-0016]: `std::ops::Not` trait is not implemented
@@ -27,7 +27,5 @@ error[8-0016]: `std::ops::Not` trait is not implemented
2727
7!f
2828
^^
2929
│ │
30-
`!` cant be applied to `Foo`
30+
`!` can't be applied to `Foo`
3131
Try implementing `std::ops::Not` for `Foo`
32-
33-

0 commit comments

Comments
 (0)