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