Skip to content

Commit a9ff018

Browse files
committed
Improve implicit todo warning wording
Closes #5979
1 parent ea9c598 commit a9ff018

5 files changed

Lines changed: 49 additions & 27 deletions

compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__use___just_use_in_fn_body.snap

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ warning: Incomplete use expression
2020
3use <- wibble()
2121
^^^^^^^^^^^^^^^ This code is incomplete
2222

23-
This code will crash if it is run. Be sure to finish it before
24-
running your program.
2523
A use expression must always be followed by at least one expression.
24+
25+
A todo expression has been use in place of the missing code, so
26+
this code will crash if it is run. Be sure to finish it before
27+
running your program.

compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__use___no_callback_body.snap

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ warning: Incomplete use expression
1717
4use <- thingy()
1818
^^^^^^^^^^^^^^^ This code is incomplete
1919

20-
This code will crash if it is run. Be sure to finish it before
21-
running your program.
2220
A use expression must always be followed by at least one expression.
21+
22+
A todo expression has been use in place of the missing code, so
23+
this code will crash if it is run. Be sure to finish it before
24+
running your program.

compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__warnings__empty_func_warning_test.snap

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,8 @@ warning: Unimplemented function
1414
2 │ pub fn wibble() { }
1515
^^^^^^^^^^^^^^^ This code is incomplete
1616

17-
This code will crash if it is run. Be sure to finish it before
17+
A function must always have an implementation.
18+
19+
A todo expression has been use in place of the missing body,
20+
so this code will crash if it is run. Be sure to finish it before
1821
running your program.

compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__warnings__incomplete_code_block_raises_warning.snap

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ warning: Incomplete block
1616
3 │ {}
1717
^^ This code is incomplete
1818

19-
This code will crash if it is run. Be sure to finish it before
20-
running your program.
2119
A block must always contain at least one expression.
20+
21+
A todo expression has been use in place of the missing code,
22+
so this code will crash if it is run. Be sure to finish it before
23+
running your program.

compiler-core/src/warning.rs

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -440,28 +440,41 @@ comment so it is not attached to any definition.",
440440
type_,
441441
names,
442442
} => {
443-
let mut text = String::new();
444-
text.push_str(
445-
"\
443+
let (title, text) = match kind {
444+
TodoKind::Keyword => {
445+
let text = "\
446446
This code will crash if it is run. Be sure to finish it before
447-
running your program.",
448-
);
449-
let title = match kind {
450-
TodoKind::Keyword => "Todo found",
447+
running your program.";
448+
449+
("Todo found", text)
450+
}
451+
451452
TodoKind::EmptyBlock => {
452-
text.push_str(
453-
"
454-
A block must always contain at least one expression.",
455-
);
456-
"Incomplete block"
453+
let text = "\
454+
A block must always contain at least one expression.
455+
456+
A todo expression has been use in place of the missing code,
457+
so this code will crash if it is run. Be sure to finish it before
458+
running your program.";
459+
("Incomplete block", text)
460+
}
461+
TodoKind::EmptyFunction { .. } => {
462+
let text = "\
463+
A function must always have an implementation.
464+
465+
A todo expression has been use in place of the missing body,
466+
so this code will crash if it is run. Be sure to finish it before
467+
running your program.";
468+
("Unimplemented function", text)
457469
}
458-
TodoKind::EmptyFunction { .. } => "Unimplemented function",
459470
TodoKind::IncompleteUse => {
460-
text.push_str(
461-
"
462-
A use expression must always be followed by at least one expression.",
463-
);
464-
"Incomplete use expression"
471+
let text = "\
472+
A use expression must always be followed by at least one expression.
473+
474+
A todo expression has been use in place of the missing code, so
475+
this code will crash if it is run. Be sure to finish it before
476+
running your program.";
477+
("Incomplete use expression", text)
465478
}
466479
}
467480
.into();
@@ -476,8 +489,8 @@ A use expression must always be followed by at least one expression.",
476489
};
477490

478491
Diagnostic {
479-
title,
480-
text,
492+
title: title.into(),
493+
text: text.into(),
481494
level: diagnostic::Level::Warning,
482495
location: Some(Location {
483496
path: path.to_path_buf(),

0 commit comments

Comments
 (0)