From 76bd555913eb9d363bf76136e1767f08f2c06bdb Mon Sep 17 00:00:00 2001 From: yukang Date: Sun, 5 Oct 2025 12:03:17 +0800 Subject: [PATCH 1/5] Avoid suggesting constrain the associated type to a trait --- .../rustc_resolve/src/late/diagnostics.rs | 37 +++++++++++-------- .../assoc-type-maybe-trait-147356.rs | 16 ++++++++ .../assoc-type-maybe-trait-147356.stderr | 21 +++++++++++ 3 files changed, 58 insertions(+), 16 deletions(-) create mode 100644 tests/ui/traits/associated_type_bound/assoc-type-maybe-trait-147356.rs create mode 100644 tests/ui/traits/associated_type_bound/assoc-type-maybe-trait-147356.stderr diff --git a/compiler/rustc_resolve/src/late/diagnostics.rs b/compiler/rustc_resolve/src/late/diagnostics.rs index da58c923695dd..08976ce4feea5 100644 --- a/compiler/rustc_resolve/src/late/diagnostics.rs +++ b/compiler/rustc_resolve/src/late/diagnostics.rs @@ -1572,26 +1572,31 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> { [ast::PathSegment { args: None, .. }], [ast::GenericBound::Trait(poly_trait_ref)], ) = (&type_param_path.segments[..], &bounds[..]) + && let [ast::PathSegment { ident, args: None, id }] = + &poly_trait_ref.trait_ref.path.segments[..] && poly_trait_ref.modifiers == ast::TraitBoundModifiers::NONE { - if let [ast::PathSegment { ident, args: None, .. }] = - &poly_trait_ref.trait_ref.path.segments[..] - { - if ident.span == span { - let Some(new_where_bound_predicate) = - mk_where_bound_predicate(path, poly_trait_ref, ty) - else { - return false; - }; - err.span_suggestion_verbose( - *where_span, - format!("constrain the associated type to `{ident}`"), - where_bound_predicate_to_string(&new_where_bound_predicate), - Applicability::MaybeIncorrect, - ); + if ident.span == span { + let Some(partial_res) = self.r.partial_res_map.get(&id) else { + return false; + }; + if !matches!(partial_res.full_res(), Some(hir::def::Res::Def(..))) { + return false; } - return true; + + let Some(new_where_bound_predicate) = + mk_where_bound_predicate(path, poly_trait_ref, ty) + else { + return false; + }; + err.span_suggestion_verbose( + *where_span, + format!("constrain the associated type to `{ident}`"), + where_bound_predicate_to_string(&new_where_bound_predicate), + Applicability::MaybeIncorrect, + ); } + return true; } } false diff --git a/tests/ui/traits/associated_type_bound/assoc-type-maybe-trait-147356.rs b/tests/ui/traits/associated_type_bound/assoc-type-maybe-trait-147356.rs new file mode 100644 index 0000000000000..8d8eab308ba23 --- /dev/null +++ b/tests/ui/traits/associated_type_bound/assoc-type-maybe-trait-147356.rs @@ -0,0 +1,16 @@ +use std::str::FromStr; +fn foo() -> T +where + ::Err: Debug, //~ ERROR expected trait +{ + "".parse().unwrap() +} + +fn bar() -> T +where + ::Err: some_unknown_name, //~ ERROR cannot find trait `some_unknown_name` in this scope +{ + "".parse().unwrap() +} + +fn main() {} diff --git a/tests/ui/traits/associated_type_bound/assoc-type-maybe-trait-147356.stderr b/tests/ui/traits/associated_type_bound/assoc-type-maybe-trait-147356.stderr new file mode 100644 index 0000000000000..b7fc85af82407 --- /dev/null +++ b/tests/ui/traits/associated_type_bound/assoc-type-maybe-trait-147356.stderr @@ -0,0 +1,21 @@ +error[E0404]: expected trait, found derive macro `Debug` + --> $DIR/assoc-type-maybe-trait-147356.rs:4:26 + | +LL | ::Err: Debug, + | ^^^^^ not a trait + | +help: consider importing this trait instead + | +LL + use std::fmt::Debug; + | + +error[E0405]: cannot find trait `some_unknown_name` in this scope + --> $DIR/assoc-type-maybe-trait-147356.rs:11:26 + | +LL | ::Err: some_unknown_name, + | ^^^^^^^^^^^^^^^^^ not found in this scope + +error: aborting due to 2 previous errors + +Some errors have detailed explanations: E0404, E0405. +For more information about an error, try `rustc --explain E0404`. From be22161390e4daea57df5d09aaf9f1e4186d7165 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Thu, 27 Nov 2025 18:58:41 +0100 Subject: [PATCH 2/5] float::minimum/maximum: say which exact IEEE operation this corresponds to --- library/core/src/num/f128.rs | 12 ++++++------ library/core/src/num/f16.rs | 12 ++++++------ library/core/src/num/f32.rs | 12 ++++++------ library/core/src/num/f64.rs | 12 ++++++------ 4 files changed, 24 insertions(+), 24 deletions(-) diff --git a/library/core/src/num/f128.rs b/library/core/src/num/f128.rs index 0d20142e718f8..bfe3a501f4537 100644 --- a/library/core/src/num/f128.rs +++ b/library/core/src/num/f128.rs @@ -695,8 +695,8 @@ impl f128 { /// Returns the maximum of the two numbers, ignoring NaN. /// /// If one of the arguments is NaN, then the other argument is returned. - /// This follows the IEEE 754-2008 semantics for maxNum, except for handling of signaling NaNs; - /// this function handles all NaNs the same way and avoids maxNum's problems with associativity. + /// This follows the IEEE 754-2008 semantics for `maxNum`, except for handling of signaling NaNs; + /// this function handles all NaNs the same way and avoids `maxNum`'s problems with associativity. /// This also matches the behavior of libm’s fmax. In particular, if the inputs compare equal /// (such as for the case of `+0.0` and `-0.0`), either input may be returned non-deterministically. /// @@ -723,8 +723,8 @@ impl f128 { /// Returns the minimum of the two numbers, ignoring NaN. /// /// If one of the arguments is NaN, then the other argument is returned. - /// This follows the IEEE 754-2008 semantics for minNum, except for handling of signaling NaNs; - /// this function handles all NaNs the same way and avoids minNum's problems with associativity. + /// This follows the IEEE 754-2008 semantics for `minNum`, except for handling of signaling NaNs; + /// this function handles all NaNs the same way and avoids `minNum`'s problems with associativity. /// This also matches the behavior of libm’s fmin. In particular, if the inputs compare equal /// (such as for the case of `+0.0` and `-0.0`), either input may be returned non-deterministically. /// @@ -769,7 +769,7 @@ impl f128 { /// /// If one of the arguments is NaN, then NaN is returned. Otherwise this returns the greater /// of the two numbers. For this operation, -0.0 is considered to be less than +0.0. - /// Note that this follows the semantics specified in IEEE 754-2019. + /// Note that this follows the IEEE 754-2019 semantics for `maximum`. /// /// Also note that "propagation" of NaNs here doesn't necessarily mean that the bitpattern of a NaN /// operand is conserved; see the [specification of NaN bit patterns](f32#nan-bit-patterns) for more info. @@ -802,7 +802,7 @@ impl f128 { /// /// If one of the arguments is NaN, then NaN is returned. Otherwise this returns the lesser /// of the two numbers. For this operation, -0.0 is considered to be less than +0.0. - /// Note that this follows the semantics specified in IEEE 754-2019. + /// Note that this follows the IEEE 754-2019 semantics for `minimum`. /// /// Also note that "propagation" of NaNs here doesn't necessarily mean that the bitpattern of a NaN /// operand is conserved; see the [specification of NaN bit patterns](f32#nan-bit-patterns) for more info. diff --git a/library/core/src/num/f16.rs b/library/core/src/num/f16.rs index 2b31426fb3539..d3a12e94c800c 100644 --- a/library/core/src/num/f16.rs +++ b/library/core/src/num/f16.rs @@ -688,8 +688,8 @@ impl f16 { /// Returns the maximum of the two numbers, ignoring NaN. /// /// If one of the arguments is NaN, then the other argument is returned. - /// This follows the IEEE 754-2008 semantics for maxNum, except for handling of signaling NaNs; - /// this function handles all NaNs the same way and avoids maxNum's problems with associativity. + /// This follows the IEEE 754-2008 semantics for `maxNum`, except for handling of signaling NaNs; + /// this function handles all NaNs the same way and avoids `maxNum`'s problems with associativity. /// This also matches the behavior of libm’s fmax. In particular, if the inputs compare equal /// (such as for the case of `+0.0` and `-0.0`), either input may be returned non-deterministically. /// @@ -715,8 +715,8 @@ impl f16 { /// Returns the minimum of the two numbers, ignoring NaN. /// /// If one of the arguments is NaN, then the other argument is returned. - /// This follows the IEEE 754-2008 semantics for minNum, except for handling of signaling NaNs; - /// this function handles all NaNs the same way and avoids minNum's problems with associativity. + /// This follows the IEEE 754-2008 semantics for `minNum`, except for handling of signaling NaNs; + /// this function handles all NaNs the same way and avoids `minNum`'s problems with associativity. /// This also matches the behavior of libm’s fmin. In particular, if the inputs compare equal /// (such as for the case of `+0.0` and `-0.0`), either input may be returned non-deterministically. /// @@ -759,7 +759,7 @@ impl f16 { /// /// If one of the arguments is NaN, then NaN is returned. Otherwise this returns the greater /// of the two numbers. For this operation, -0.0 is considered to be less than +0.0. - /// Note that this follows the semantics specified in IEEE 754-2019. + /// Note that this follows the IEEE 754-2019 semantics for `maximum`. /// /// Also note that "propagation" of NaNs here doesn't necessarily mean that the bitpattern of a NaN /// operand is conserved; see the [specification of NaN bit patterns](f32#nan-bit-patterns) for more info. @@ -791,7 +791,7 @@ impl f16 { /// /// If one of the arguments is NaN, then NaN is returned. Otherwise this returns the lesser /// of the two numbers. For this operation, -0.0 is considered to be less than +0.0. - /// Note that this follows the semantics specified in IEEE 754-2019. + /// Note that this follows the IEEE 754-2019 semantics for `minimum`. /// /// Also note that "propagation" of NaNs here doesn't necessarily mean that the bitpattern of a NaN /// operand is conserved; see the [specification of NaN bit patterns](f32#nan-bit-patterns) for more info. diff --git a/library/core/src/num/f32.rs b/library/core/src/num/f32.rs index c0ff1d5b47c81..7e6a757e5e297 100644 --- a/library/core/src/num/f32.rs +++ b/library/core/src/num/f32.rs @@ -898,8 +898,8 @@ impl f32 { /// Returns the maximum of the two numbers, ignoring NaN. /// /// If one of the arguments is NaN, then the other argument is returned. - /// This follows the IEEE 754-2008 semantics for maxNum, except for handling of signaling NaNs; - /// this function handles all NaNs the same way and avoids maxNum's problems with associativity. + /// This follows the IEEE 754-2008 semantics for `maxNum`, except for handling of signaling NaNs; + /// this function handles all NaNs the same way and avoids `maxNum`'s problems with associativity. /// This also matches the behavior of libm’s fmax. In particular, if the inputs compare equal /// (such as for the case of `+0.0` and `-0.0`), either input may be returned non-deterministically. /// @@ -921,8 +921,8 @@ impl f32 { /// Returns the minimum of the two numbers, ignoring NaN. /// /// If one of the arguments is NaN, then the other argument is returned. - /// This follows the IEEE 754-2008 semantics for minNum, except for handling of signaling NaNs; - /// this function handles all NaNs the same way and avoids minNum's problems with associativity. + /// This follows the IEEE 754-2008 semantics for `minNum`, except for handling of signaling NaNs; + /// this function handles all NaNs the same way and avoids `minNum`'s problems with associativity. /// This also matches the behavior of libm’s fmin. In particular, if the inputs compare equal /// (such as for the case of `+0.0` and `-0.0`), either input may be returned non-deterministically. /// @@ -957,7 +957,7 @@ impl f32 { /// /// If one of the arguments is NaN, then NaN is returned. Otherwise this returns the greater /// of the two numbers. For this operation, -0.0 is considered to be less than +0.0. - /// Note that this follows the semantics specified in IEEE 754-2019. + /// Note that this follows the IEEE 754-2019 semantics for `maximum`. /// /// Also note that "propagation" of NaNs here doesn't necessarily mean that the bitpattern of a NaN /// operand is conserved; see the [specification of NaN bit patterns](f32#nan-bit-patterns) for more info. @@ -984,7 +984,7 @@ impl f32 { /// /// If one of the arguments is NaN, then NaN is returned. Otherwise this returns the lesser /// of the two numbers. For this operation, -0.0 is considered to be less than +0.0. - /// Note that this follows the semantics specified in IEEE 754-2019. + /// Note that this follows the IEEE 754-2019 semantics for `minimum`. /// /// Also note that "propagation" of NaNs here doesn't necessarily mean that the bitpattern of a NaN /// operand is conserved; see the [specification of NaN bit patterns](f32#nan-bit-patterns) for more info. diff --git a/library/core/src/num/f64.rs b/library/core/src/num/f64.rs index 8ad52268206e8..854bdcf39d09e 100644 --- a/library/core/src/num/f64.rs +++ b/library/core/src/num/f64.rs @@ -916,8 +916,8 @@ impl f64 { /// Returns the maximum of the two numbers, ignoring NaN. /// /// If one of the arguments is NaN, then the other argument is returned. - /// This follows the IEEE 754-2008 semantics for maxNum, except for handling of signaling NaNs; - /// this function handles all NaNs the same way and avoids maxNum's problems with associativity. + /// This follows the IEEE 754-2008 semantics for `maxNum`, except for handling of signaling NaNs; + /// this function handles all NaNs the same way and avoids `maxNum`'s problems with associativity. /// This also matches the behavior of libm’s fmax. In particular, if the inputs compare equal /// (such as for the case of `+0.0` and `-0.0`), either input may be returned non-deterministically. /// @@ -939,8 +939,8 @@ impl f64 { /// Returns the minimum of the two numbers, ignoring NaN. /// /// If one of the arguments is NaN, then the other argument is returned. - /// This follows the IEEE 754-2008 semantics for minNum, except for handling of signaling NaNs; - /// this function handles all NaNs the same way and avoids minNum's problems with associativity. + /// This follows the IEEE 754-2008 semantics for `minNum`, except for handling of signaling NaNs; + /// this function handles all NaNs the same way and avoids `minNum`'s problems with associativity. /// This also matches the behavior of libm’s fmin. In particular, if the inputs compare equal /// (such as for the case of `+0.0` and `-0.0`), either input may be returned non-deterministically. /// @@ -975,7 +975,7 @@ impl f64 { /// /// If one of the arguments is NaN, then NaN is returned. Otherwise this returns the greater /// of the two numbers. For this operation, -0.0 is considered to be less than +0.0. - /// Note that this follows the semantics specified in IEEE 754-2019. + /// Note that this follows the IEEE 754-2019 semantics for `maximum`. /// /// Also note that "propagation" of NaNs here doesn't necessarily mean that the bitpattern of a NaN /// operand is conserved; see the [specification of NaN bit patterns](f32#nan-bit-patterns) for more info. @@ -1002,7 +1002,7 @@ impl f64 { /// /// If one of the arguments is NaN, then NaN is returned. Otherwise this returns the lesser /// of the two numbers. For this operation, -0.0 is considered to be less than +0.0. - /// Note that this follows the semantics specified in IEEE 754-2019. + /// Note that this follows the IEEE 754-2019 semantics for `minimum`. /// /// Also note that "propagation" of NaNs here doesn't necessarily mean that the bitpattern of a NaN /// operand is conserved; see the [specification of NaN bit patterns](f32#nan-bit-patterns) for more info. From f15e99b2f08bc238b5cc6694ef31c29c22a75029 Mon Sep 17 00:00:00 2001 From: Yotam Ofek Date: Thu, 27 Nov 2025 20:05:58 +0200 Subject: [PATCH 3/5] Remove outdated comment --- library/std/src/lib.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index 8df87124245bc..e7b9550780a0b 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -265,8 +265,6 @@ // // Language features: // tidy-alphabetical-start - -// stabilization was reverted after it hit beta #![feature(alloc_error_handler)] #![feature(allocator_internals)] #![feature(allow_internal_unsafe)] @@ -421,7 +419,7 @@ #![default_lib_allocator] // The Rust prelude -// The compiler expects the prelude definition to be defined before it's use statement. +// The compiler expects the prelude definition to be defined before its use statement. pub mod prelude; // Explicitly import the prelude. The compiler uses this same unstable attribute From c6b0f7888b93b29836a4645dc583cb52c875d04a Mon Sep 17 00:00:00 2001 From: Shoyu Vanilla Date: Fri, 28 Nov 2025 23:58:50 +0900 Subject: [PATCH 4/5] Add a regression test for issue 129865 --- .../normalize/normalize-const-in-async-body.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 tests/ui/traits/next-solver/normalize/normalize-const-in-async-body.rs diff --git a/tests/ui/traits/next-solver/normalize/normalize-const-in-async-body.rs b/tests/ui/traits/next-solver/normalize/normalize-const-in-async-body.rs new file mode 100644 index 0000000000000..2b9454db3fac7 --- /dev/null +++ b/tests/ui/traits/next-solver/normalize/normalize-const-in-async-body.rs @@ -0,0 +1,14 @@ +//@ compile-flags: -Znext-solver +//@ check-pass +//@ edition:2021 + +pub async fn cleanse_old_array_async(_: &[u8; BUCKET_LEN]) {} + +pub const BUCKET_LEN: usize = 0; + +pub fn cleanse_old_array_async2() -> impl std::future::Future { + let x: [u8; 0 + 0] = []; + async move { let _ = x; } +} + +fn main() {} From d2564a990e066ba0d4b2ddaf9ba0baa7b36f6c0d Mon Sep 17 00:00:00 2001 From: rustbot <47979223+rustbot@users.noreply.github.com> Date: Fri, 28 Nov 2025 19:47:24 +0100 Subject: [PATCH 5/5] Update books --- src/doc/book | 2 +- src/doc/reference | 2 +- src/doc/rust-by-example | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/doc/book b/src/doc/book index f78ab89d7545a..8c0eacd5c4acb 160000 --- a/src/doc/book +++ b/src/doc/book @@ -1 +1 @@ -Subproject commit f78ab89d7545ac17780e6a367055cc089f4cd2ec +Subproject commit 8c0eacd5c4acbb650497454f3a58c9e8083202a4 diff --git a/src/doc/reference b/src/doc/reference index f9f1d2a4149f0..f2ac173df9906 160000 --- a/src/doc/reference +++ b/src/doc/reference @@ -1 +1 @@ -Subproject commit f9f1d2a4149f02582aec2f8fcdfa5b596193b4e2 +Subproject commit f2ac173df9906de5c03b0ee50653321ef1c4ebe8 diff --git a/src/doc/rust-by-example b/src/doc/rust-by-example index f944161716230..111cfae2f9c3a 160000 --- a/src/doc/rust-by-example +++ b/src/doc/rust-by-example @@ -1 +1 @@ -Subproject commit f944161716230641605b5e3733e1c81f10047fd4 +Subproject commit 111cfae2f9c3a43f7b0ff8fa68c51cc8f930637c