From b18a8c3036c962d3a09bd04d0537ad86c046b3f7 Mon Sep 17 00:00:00 2001 From: Remo Senekowitsch Date: Tue, 19 May 2026 17:29:16 +0200 Subject: [PATCH] strings4: remove From-based conversion To understand From-based conversion, an understanding of traits is required, which we teach in a later chapter. The From trait specifically is taught in one of the conversion exercises. So, we can safely remove it here without users missing out on learning something important. A specific source of confusion for users was a warning that the conversion is useless, which appeared when using the `string_slice` function for the expression with `.into()`. closes #2190 --- exercises/09_strings/strings4.rs | 2 -- solutions/09_strings/strings4.rs | 9 --------- 2 files changed, 11 deletions(-) diff --git a/exercises/09_strings/strings4.rs b/exercises/09_strings/strings4.rs index 473072636d..43976a6403 100644 --- a/exercises/09_strings/strings4.rs +++ b/exercises/09_strings/strings4.rs @@ -21,8 +21,6 @@ fn main() { placeholder("rust is fun!".to_owned()); - placeholder("nice weather".into()); - placeholder(format!("Interpolation {}", "Station")); // WARNING: This is byte indexing, not character indexing. diff --git a/solutions/09_strings/strings4.rs b/solutions/09_strings/strings4.rs index 087b0386d4..ab976d274c 100644 --- a/solutions/09_strings/strings4.rs +++ b/solutions/09_strings/strings4.rs @@ -15,15 +15,6 @@ fn main() { string("rust is fun!".to_owned()); - // Here, both answers work. - // `.into()` converts a type into an expected type. - // If it is called where `String` is expected, it will convert `&str` to `String`. - string("nice weather".into()); - // But if it is called where `&str` is expected, then `&str` is kept as `&str` since no conversion is needed. - // If you remove the `#[allow(…)]` line, then Clippy will tell you to remove `.into()` below since it is a useless conversion. - #[allow(clippy::useless_conversion)] - string_slice("nice weather".into()); - string(format!("Interpolation {}", "Station")); // WARNING: This is byte indexing, not character indexing.