Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide-assists/src/handlers/replace_arith_with_checked.rs')
-rw-r--r--crates/ide-assists/src/handlers/replace_arith_with_checked.rs33
1 files changed, 33 insertions, 0 deletions
diff --git a/crates/ide-assists/src/handlers/replace_arith_with_checked.rs b/crates/ide-assists/src/handlers/replace_arith_with_checked.rs
new file mode 100644
index 0000000000..419b6febf1
--- /dev/null
+++ b/crates/ide-assists/src/handlers/replace_arith_with_checked.rs
@@ -0,0 +1,33 @@
+use crate::assist_context::{AssistContext, Assists};
+use crate::utils::{replace_arith, ArithKind};
+
+pub(crate) fn replace_arith_with_checked(
+ acc: &mut Assists,
+ ctx: &AssistContext<'_>,
+) -> Option<()> {
+ replace_arith(acc, ctx, ArithKind::Checked)
+}
+
+#[cfg(test)]
+mod tests {
+ use crate::tests::check_assist;
+
+ use super::*;
+
+ #[test]
+ fn replace_arith_with_saturating_add() {
+ check_assist(
+ replace_arith_with_checked,
+ r#"
+fn main() {
+ let x = 1 $0+ 2;
+}
+"#,
+ r#"
+fn main() {
+ let x = 1.checked_add(2);
+}
+"#,
+ )
+ }
+}