Skip to content

Commit

Permalink
Diagnostic language tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
sbillig committed Jan 23, 2025
1 parent 46a659f commit 2cba36b
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 44 deletions.
16 changes: 8 additions & 8 deletions crates/hir-analysis/src/ty/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -943,7 +943,7 @@ impl<'db> BodyDiag<'db> {
Self::DuplicatedBinding { name, .. } => {
format!("duplicate binding `{}` in pattern", name.data(db))
}
Self::DuplicatedRestPat(_) => "duplicate `..` found".to_string(),
Self::DuplicatedRestPat(_) => "duplicate `..` in pattern".to_string(),
Self::InvalidPathDomainInPat { .. } => "invalid item is given here".to_string(),
Self::UnitVariantExpected { .. } => "expected unit variant".to_string(),
Self::TupleVariantExpected { .. } => "expected tuple variant".to_string(),
Expand All @@ -952,7 +952,7 @@ impl<'db> BodyDiag<'db> {
Self::DuplicatedRecordFieldBind { .. } => "duplicated record field binding".to_string(),
Self::RecordFieldNotFound { .. } => "specified field not found".to_string(),
Self::ExplicitLabelExpectedInRecord { .. } => "explicit label is required".to_string(),
Self::MissingRecordFields { .. } => "all fields are not given".to_string(),
Self::MissingRecordFields { .. } => "missing fields in record pattern".to_string(),
Self::UndefinedVariable(..) => "undefined variable".to_string(),
Self::ReturnedTypeMismatch { .. } => "returned type mismatch".to_string(),
Self::TypeMustBeKnown(..) => "type must be known here".to_string(),
Expand All @@ -978,14 +978,14 @@ impl<'db> BodyDiag<'db> {
format!("`{}` needs to be implemented for {ty}", trait_name.data(db))
}

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

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

Self::CallArgNumMismatch { .. } => "given argument number mismatch".to_string(),
Self::CallArgLabelMismatch { .. } => "given argument label mismatch".to_string(),
Self::CallArgNumMismatch { .. } => "argument number mismatch".to_string(),
Self::CallArgLabelMismatch { .. } => "argument label mismatch".to_string(),

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

Expand Down Expand Up @@ -1164,7 +1164,7 @@ impl<'db> BodyDiag<'db> {
vec![
SubDiagnostic::new(
LabelStyle::Primary,
format!("duplicated field binding `{}`", name),
format!("duplicate field binding `{}`", name),
primary.resolve(db),
),
SubDiagnostic::new(
Expand Down Expand Up @@ -1314,7 +1314,7 @@ impl<'db> BodyDiag<'db> {
vec![
SubDiagnostic::new(
LabelStyle::Primary,
format!("`{}` cant be applied to `{}`", op, ty),
format!("`{}` can't be applied to `{}`", op, ty),
span.resolve(db),
),
SubDiagnostic::new(
Expand Down Expand Up @@ -1381,7 +1381,7 @@ impl<'db> BodyDiag<'db> {
Self::NotCallable(primary, ty) => {
vec![SubDiagnostic::new(
LabelStyle::Primary,
format!("`{ty}` is not callable"),
format!("call expression requires function; `{ty}` is not callable"),
primary.resolve(db),
)]
}
Expand Down
6 changes: 2 additions & 4 deletions crates/uitest/fixtures/ty_check/aug_assign.snap
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
---
source: crates/uitest/tests/ty_check.rs
expression: diags
input_file: crates/uitest/fixtures/ty_check/aug_assign.fe
input_file: fixtures/ty_check/aug_assign.fe
---
error[8-0016]: `std::ops::SubAssign` trait is not implemented
┌─ aug_assign.fe:6:5
6f -= f
^^^^^^
│ │
`-=` cant be applied to `Foo`
`-=` can't be applied to `Foo`
Try implementing `std::ops::SubAssign` for `Foo`

error[8-0018]: left-hand side of assignment is immutable
Expand All @@ -20,5 +20,3 @@ error[8-0018]: left-hand side of assignment is immutable
6f -= f
7f.x *= 1
^^^ immutable assignment


12 changes: 5 additions & 7 deletions crates/uitest/fixtures/ty_check/binary.snap
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
---
source: crates/uitest/tests/ty_check.rs
expression: diags
input_file: crates/uitest/fixtures/ty_check/binary.fe
input_file: fixtures/ty_check/binary.fe
---
error[8-0016]: `std::ops::Add` trait is not implemented
┌─ binary.fe:4:5
4f + f
^^^^^
│ │
`+` cant be applied to `Foo`
`+` can't be applied to `Foo`
Try implementing `std::ops::Add` for `Foo`

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

error[8-0016]: `std::ops::Eq` trait is not implemented
Expand All @@ -27,7 +27,7 @@ error[8-0016]: `std::ops::Eq` trait is not implemented
7f == f
^^^^^^
│ │
`==` cant be applied to `Foo`
`==` can't be applied to `Foo`
Try implementing `std::ops::Eq` for `Foo`

error[8-0016]: `std::ops::Ord` trait is not implemented
Expand All @@ -36,7 +36,5 @@ error[8-0016]: `std::ops::Ord` trait is not implemented
8f < f
^^^^^
│ │
`<` cant be applied to `Foo`
`<` can't be applied to `Foo`
Try implementing `std::ops::Ord` for `Foo`


7 changes: 6 additions & 1 deletion crates/uitest/fixtures/ty_check/call.fe
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,9 @@ pub fn make_tuple<T, U>(_ t: T, _ u: U) -> (T, U) {

pub fn use_make_tuple() -> (i32, u32) {
make_tuple<i32, u32>(false, 1)
}
}

fn f() {
let x: u32 = 1
x(100)
}
20 changes: 12 additions & 8 deletions crates/uitest/fixtures/ty_check/call.snap
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
source: crates/uitest/tests/ty_check.rs
expression: diags
input_file: crates/uitest/fixtures/ty_check/call.fe
input_file: fixtures/ty_check/call.fe
---
error[8-0000]: type mismatch
┌─ call.fe:9:12
Expand All @@ -15,7 +15,13 @@ error[8-0000]: type mismatch
17make_tuple<i32, u32>(false, 1)
│ ^^^^^ expected `i32`, but `bool` is given

error[8-0024]: given argument label mismatch
error[8-0021]: expected function, found `u32`
┌─ call.fe:22:5
22 │ x(100)
│ ^ call expression requires function; `u32` is not callable

error[8-0024]: argument label mismatch
┌─ call.fe:6:9
1pub fn add(x: i32, y: i32) -> i32 {
Expand All @@ -24,7 +30,7 @@ error[8-0024]: given argument label mismatch
6 │ add(1, 2)
│ ^ expected `x` label

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

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

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

error[8-0024]: given argument label mismatch
error[8-0024]: argument label mismatch
┌─ call.fe:8:15
1 │ pub fn add(x: i32, y: i32) -> i32 {
--- function defined here
·
8 │ add(x: 1, z: 2)
│ ^ expected `y` label, but `z` given


6 changes: 2 additions & 4 deletions crates/uitest/fixtures/ty_check/index.snap
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
source: crates/uitest/tests/ty_check.rs
expression: diags
input_file: crates/uitest/fixtures/ty_check/index.fe
input_file: fixtures/ty_check/index.fe
---
error[8-0000]: type mismatch
┌─ index.fe:4:7
Expand All @@ -15,7 +15,5 @@ error[8-0016]: `std::ops::Index` trait is not implemented
6f[1]
│ ^^^^
│ │
│ `[]` cant be applied to `Foo`
│ `[]` can't be applied to `Foo`
Try implementing `std::ops::Index` for `Foo`


12 changes: 6 additions & 6 deletions crates/uitest/fixtures/ty_check/pat/record.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ source: crates/uitest/tests/ty_check.rs
expression: diags
input_file: fixtures/ty_check/pat/record.fe
---
error[8-0002]: duplicate `..` found
error[8-0002]: duplicate `..` in pattern
┌─ record.fe:13:24
13let Foo {x, .., y, ..}
^^ `..` can be used only once

error[8-0002]: duplicate `..` found
error[8-0002]: duplicate `..` in pattern
┌─ record.fe:19:33
19let Bar::Variant {x, .., y, ..}
Expand All @@ -19,15 +19,15 @@ error[8-0008]: duplicated record field binding
┌─ record.fe:12:17
12let Foo {x, x}
- ^ duplicated field binding `x`
- ^ duplicate field binding `x`
│ │
first use of `x`

error[8-0008]: duplicated record field binding
┌─ record.fe:18:26
18let Bar::Variant {x, x}
- ^ duplicated field binding `x`
- ^ duplicate field binding `x`
│ │
first use of `x`

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

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

error[8-0011]: all fields are not given
error[8-0011]: missing fields in record pattern
┌─ record.fe:22:22
22let Bar::Variant {}
Expand Down
10 changes: 4 additions & 6 deletions crates/uitest/fixtures/ty_check/unary.snap
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
---
source: crates/uitest/tests/ty_check.rs
expression: diags
input_file: crates/uitest/fixtures/ty_check/unary.fe
input_file: fixtures/ty_check/unary.fe
---
error[8-0016]: `std::ops::UnaryPlus` trait is not implemented
┌─ unary.fe:5:5
5+f
^^
│ │
`+` cant be applied to `Foo`
`+` can't be applied to `Foo`
Try implementing `std::ops::UnaryPlus` for `Foo`

error[8-0016]: `std::ops::Neg` trait is not implemented
Expand All @@ -18,7 +18,7 @@ error[8-0016]: `std::ops::Neg` trait is not implemented
6-f
^^
│ │
`-` cant be applied to `Foo`
`-` can't be applied to `Foo`
Try implementing `std::ops::Neg` for `Foo`

error[8-0016]: `std::ops::Not` trait is not implemented
Expand All @@ -27,7 +27,5 @@ error[8-0016]: `std::ops::Not` trait is not implemented
7!f
^^
│ │
`!` cant be applied to `Foo`
`!` can't be applied to `Foo`
Try implementing `std::ops::Not` for `Foo`


0 comments on commit 2cba36b

Please sign in to comment.