From 1112274275be9216b42ef2f27b1e85c5e88d67c5 Mon Sep 17 00:00:00 2001 From: Connor Tsui Date: Thu, 28 Aug 2025 19:53:12 +0100 Subject: [PATCH 1/5] add `Bound::copied` Signed-off-by: Connor Tsui --- library/core/src/ops/range.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/library/core/src/ops/range.rs b/library/core/src/ops/range.rs index 95d1e2069ac94..c5a7744d73b39 100644 --- a/library/core/src/ops/range.rs +++ b/library/core/src/ops/range.rs @@ -736,6 +736,28 @@ impl Bound { } } +impl Bound<&T> { + /// Map a `Bound<&T>` to a `Bound` by copying the contents of the bound. + /// + /// # Examples + /// + /// ``` + /// use std::ops::Bound::*; + /// use std::ops::RangeBounds; + /// + /// assert_eq!((1..12).start_bound(), Included(&1)); + /// assert_eq!((1..12).start_bound().copied(), Included(1)); + /// ``` + #[unstable(feature = "bound_copied", issue = "145966")] + pub fn copied(self) -> Bound { + match self { + Bound::Unbounded => Bound::Unbounded, + Bound::Included(x) => Bound::Included(*x), + Bound::Excluded(x) => Bound::Excluded(*x), + } + } +} + impl Bound<&T> { /// Map a `Bound<&T>` to a `Bound` by cloning the contents of the bound. /// From 9c1255f0a46e7a8d22f17ad5705f0c8e2018bfe6 Mon Sep 17 00:00:00 2001 From: Connor Tsui <87130162+connortsui20@users.noreply.github.com> Date: Thu, 28 Aug 2025 20:38:07 +0100 Subject: [PATCH 2/5] add feature gate in doc test --- library/core/src/ops/range.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/library/core/src/ops/range.rs b/library/core/src/ops/range.rs index c5a7744d73b39..b1df5afa20224 100644 --- a/library/core/src/ops/range.rs +++ b/library/core/src/ops/range.rs @@ -742,6 +742,8 @@ impl Bound<&T> { /// # Examples /// /// ``` + /// #![feature(bound_copied)] + /// /// use std::ops::Bound::*; /// use std::ops::RangeBounds; /// From 114c0c2fefbc90d1cb71f6a0c4d150174e73ca75 Mon Sep 17 00:00:00 2001 From: Connor Tsui Date: Sat, 30 Aug 2025 11:15:41 +0100 Subject: [PATCH 3/5] Add `#[must_use] and update `cloned` documentation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Connor Tsui Co-authored-by: Jonas Böttiger --- library/core/src/ops/range.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/library/core/src/ops/range.rs b/library/core/src/ops/range.rs index b1df5afa20224..c0a27775694c3 100644 --- a/library/core/src/ops/range.rs +++ b/library/core/src/ops/range.rs @@ -751,6 +751,7 @@ impl Bound<&T> { /// assert_eq!((1..12).start_bound().copied(), Included(1)); /// ``` #[unstable(feature = "bound_copied", issue = "145966")] + #[must_use] pub fn copied(self) -> Bound { match self { Bound::Unbounded => Bound::Unbounded, @@ -769,8 +770,11 @@ impl Bound<&T> { /// use std::ops::Bound::*; /// use std::ops::RangeBounds; /// - /// assert_eq!((1..12).start_bound(), Included(&1)); - /// assert_eq!((1..12).start_bound().cloned(), Included(1)); + /// let a1 = String::from("a"); + /// let (a2, a3, a4) = (a1.clone(), a1.clone(), a1.clone()); + /// + /// assert_eq!(Included(&a1), (a2..).start_bound()); + /// assert_eq!(Included(a3), (a4..).start_bound().cloned()); /// ``` #[must_use = "`self` will be dropped if the result is not used"] #[stable(feature = "bound_cloned", since = "1.55.0")] From 263766bcc28a9441d0acfb1a335308e46cfd1917 Mon Sep 17 00:00:00 2001 From: yukang Date: Sun, 31 Aug 2025 10:53:33 +0800 Subject: [PATCH 4/5] suggest method name with maybe ty mismatch --- compiler/rustc_hir_typeck/src/method/mod.rs | 2 +- ...-suggest-await-on-method-return-mismatch.stderr | 5 +++++ tests/ui/privacy/private-field-ty-err.stderr | 5 +++++ ...st-method-name-with-maybe-ty-mismatch-146008.rs | 14 ++++++++++++++ ...ethod-name-with-maybe-ty-mismatch-146008.stderr | 14 ++++++++++++++ 5 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 tests/ui/typeck/suggest-method-name-with-maybe-ty-mismatch-146008.rs create mode 100644 tests/ui/typeck/suggest-method-name-with-maybe-ty-mismatch-146008.stderr diff --git a/compiler/rustc_hir_typeck/src/method/mod.rs b/compiler/rustc_hir_typeck/src/method/mod.rs index e37ea03167262..652644ad78cce 100644 --- a/compiler/rustc_hir_typeck/src/method/mod.rs +++ b/compiler/rustc_hir_typeck/src/method/mod.rs @@ -117,7 +117,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { Err(Ambiguity(..)) => true, Err(PrivateMatch(..)) => false, Err(IllegalSizedBound { .. }) => true, - Err(BadReturnType) => false, + Err(BadReturnType) => true, Err(ErrorReported(_)) => false, } } diff --git a/tests/ui/async-await/dont-suggest-await-on-method-return-mismatch.stderr b/tests/ui/async-await/dont-suggest-await-on-method-return-mismatch.stderr index 1faaf4ddce2f6..aa2343e48a6e5 100644 --- a/tests/ui/async-await/dont-suggest-await-on-method-return-mismatch.stderr +++ b/tests/ui/async-await/dont-suggest-await-on-method-return-mismatch.stderr @@ -3,6 +3,11 @@ error[E0599]: no method named `test` found for opaque type `impl Future` + | +help: consider `await`ing on the `Future` and calling the method on its `Output` + | +LL | let x: u32 = foo().await.test(); + | ++++++ error: aborting due to 1 previous error diff --git a/tests/ui/privacy/private-field-ty-err.stderr b/tests/ui/privacy/private-field-ty-err.stderr index 17d50f24a945f..0eecad14cfc33 100644 --- a/tests/ui/privacy/private-field-ty-err.stderr +++ b/tests/ui/privacy/private-field-ty-err.stderr @@ -3,6 +3,11 @@ error[E0616]: field `len` of struct `Foo` is private | LL | if x.len { | ^^^ private field + | +help: a method `len` also exists, call it with parentheses + | +LL | if x.len() { + | ++ error: aborting due to 1 previous error diff --git a/tests/ui/typeck/suggest-method-name-with-maybe-ty-mismatch-146008.rs b/tests/ui/typeck/suggest-method-name-with-maybe-ty-mismatch-146008.rs new file mode 100644 index 0000000000000..671f280e81430 --- /dev/null +++ b/tests/ui/typeck/suggest-method-name-with-maybe-ty-mismatch-146008.rs @@ -0,0 +1,14 @@ +struct LlamaModel; + +impl LlamaModel { + fn chat_template(&self) -> Result<&str, ()> { + todo!() + } +} + +fn template_from_str(_x: &str) {} + +fn main() { + let model = LlamaModel; + template_from_str(&model.chat_template); //~ ERROR attempted to take value of method `chat_template` on type `LlamaModel` +} diff --git a/tests/ui/typeck/suggest-method-name-with-maybe-ty-mismatch-146008.stderr b/tests/ui/typeck/suggest-method-name-with-maybe-ty-mismatch-146008.stderr new file mode 100644 index 0000000000000..7f5dd0617b1b6 --- /dev/null +++ b/tests/ui/typeck/suggest-method-name-with-maybe-ty-mismatch-146008.stderr @@ -0,0 +1,14 @@ +error[E0615]: attempted to take value of method `chat_template` on type `LlamaModel` + --> $DIR/suggest-method-name-with-maybe-ty-mismatch-146008.rs:13:30 + | +LL | template_from_str(&model.chat_template); + | ^^^^^^^^^^^^^ method, not a field + | +help: use parentheses to call the method + | +LL | template_from_str(&model.chat_template()); + | ++ + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0615`. From cfba491e674dcff8cc5edbf9ae3e3880518804fd Mon Sep 17 00:00:00 2001 From: LorrensP-2158466 Date: Sun, 31 Aug 2025 10:03:49 +0200 Subject: [PATCH 5/5] fix --- library/std/tests/floats/f32.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/std/tests/floats/f32.rs b/library/std/tests/floats/f32.rs index 38c906c1d8771..c61a8ec4d2096 100644 --- a/library/std/tests/floats/f32.rs +++ b/library/std/tests/floats/f32.rs @@ -79,8 +79,8 @@ fn test_log() { let nan: f32 = f32::NAN; let inf: f32 = f32::INFINITY; let neg_inf: f32 = f32::NEG_INFINITY; - assert_approx_eq!(10.0f32.log(10.0), 1.0); - assert_approx_eq!(2.3f32.log(3.5), 0.664858); + assert_approx_eq!(10.0f32.log(10.0), 1.0, APPROX_DELTA); + assert_approx_eq!(2.3f32.log(3.5), 0.664858, APPROX_DELTA); assert_approx_eq!(1.0f32.exp().log(1.0f32.exp()), 1.0, APPROX_DELTA); assert!(1.0f32.log(1.0).is_nan()); assert!(1.0f32.log(-13.9).is_nan());