From e66db09a6c1361f5db480f1edc2bbee9c13c0516 Mon Sep 17 00:00:00 2001 From: Sergio Benitez Date: Mon, 10 Apr 2023 12:47:09 -0700 Subject: [PATCH] Emit warning when 'String' is used as a parameter. The warning is only emitted when Rocket is compiled in debug. --- core/lib/src/request/from_param.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/core/lib/src/request/from_param.rs b/core/lib/src/request/from_param.rs index 3eca0084..994ce6ab 100644 --- a/core/lib/src/request/from_param.rs +++ b/core/lib/src/request/from_param.rs @@ -195,9 +195,15 @@ impl<'a> FromParam<'a> for &'a str { impl<'a> FromParam<'a> for String { type Error = std::convert::Infallible; + #[track_caller] #[inline(always)] fn from_param(param: &'a str) -> Result { - // TODO: Tell the user they're being inefficient? + #[cfg(debug_assertions)] { + let loc = std::panic::Location::caller(); + warn_!("Note: Using `String` as a parameter type is inefficient. Use `&str` instead."); + info_!("`String` is used a parameter guard in {}:{}.", loc.file(), loc.line()); + } + Ok(param.to_string()) } }