From da9bbc424223dafccc16235f020c05b2b5d29f45 Mon Sep 17 00:00:00 2001 From: Amirhossein Akhlaghpour Date: Thu, 12 Nov 2026 13:11:53 +0330 Subject: [PATCH 01/11] fix ICE when confirming invalid dyn method receivers Signed-off-by: Amirhossein Akhlaghpour --- .../rustc_hir_typeck/src/method/confirm.rs | 51 +++++++++++-------- .../ui/self/invalid-self-dyn-receiver-cell.rs | 18 +++++++ .../invalid-self-dyn-receiver-cell.stderr | 12 +++++ 3 files changed, 61 insertions(+), 20 deletions(-) create mode 100644 tests/ui/self/invalid-self-dyn-receiver-cell.rs create mode 100644 tests/ui/self/invalid-self-dyn-receiver-cell.stderr diff --git a/compiler/rustc_hir_typeck/src/method/confirm.rs b/compiler/rustc_hir_typeck/src/method/confirm.rs index 86f3e4dd4f1e9..85ac4c6817bcf 100644 --- a/compiler/rustc_hir_typeck/src/method/confirm.rs +++ b/compiler/rustc_hir_typeck/src/method/confirm.rs @@ -354,6 +354,22 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> { ); upcast_trait_ref.args }) + .unwrap_or_else(|| { + // An invalid receiver can still lead to an ObjectPick even when we + // can't reach the trait object. if the method failed WF checking, + // recover instead of ICEing. + if pick.item.def_id.as_local().is_some_and(|def_id| { + self.tcx.ensure_result().check_well_formed(def_id).is_err() + }) { + ty::GenericArgs::extend_with_error(self.tcx, trait_def_id, &[]) + } else { + span_bug!( + self.span, + "self-type `{}` for ObjectPick never dereferenced to an object", + self_ty + ) + } + }) } probe::TraitPick { .. } => { @@ -375,7 +391,11 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> { } } - fn extract_existential_trait_ref(&mut self, self_ty: Ty<'tcx>, mut closure: F) -> R + fn extract_existential_trait_ref( + &mut self, + self_ty: Ty<'tcx>, + mut closure: F, + ) -> Option where F: FnMut(&mut ConfirmContext<'a, 'tcx>, Ty<'tcx>, ty::PolyExistentialTraitRef<'tcx>) -> R, { @@ -394,25 +414,16 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> { autoderef = autoderef.use_receiver_trait(); } - autoderef - .include_raw_pointers() - .find_map(|(ty, _)| match ty.kind() { - ty::Dynamic(data, ..) => Some(closure( - self, - ty, - data.principal().unwrap_or_else(|| { - span_bug!(self.span, "calling trait method on empty object?") - }), - )), - _ => None, - }) - .unwrap_or_else(|| { - span_bug!( - self.span, - "self-type `{}` for ObjectPick never dereferenced to an object", - self_ty - ) - }) + autoderef.include_raw_pointers().find_map(|(ty, _)| match ty.kind() { + ty::Dynamic(data, ..) => Some(closure( + self, + ty, + data.principal().unwrap_or_else(|| { + span_bug!(self.span, "calling trait method on empty object?") + }), + )), + _ => None, + }) } fn instantiate_method_args( diff --git a/tests/ui/self/invalid-self-dyn-receiver-cell.rs b/tests/ui/self/invalid-self-dyn-receiver-cell.rs new file mode 100644 index 0000000000000..6cf35bdd6d15f --- /dev/null +++ b/tests/ui/self/invalid-self-dyn-receiver-cell.rs @@ -0,0 +1,18 @@ +// Regression test for rust-lang/rust#165033. +// An invalid receiver must not trigger an ICE during method confirmation. + +use std::cell::Cell; +use std::ops::Deref; + +trait Foo: Deref> { + fn method(self: &Cell) {} + //~^ ERROR invalid `self` parameter type +} + +trait Bar {} + +fn test(x: &dyn Foo) { + x.method(); +} + +fn main() {} diff --git a/tests/ui/self/invalid-self-dyn-receiver-cell.stderr b/tests/ui/self/invalid-self-dyn-receiver-cell.stderr new file mode 100644 index 0000000000000..6b5f2a1836d20 --- /dev/null +++ b/tests/ui/self/invalid-self-dyn-receiver-cell.stderr @@ -0,0 +1,12 @@ +error[E0307]: invalid `self` parameter type: `&Cell<(dyn Bar + 'static)>` + --> $DIR/invalid-self-dyn-receiver-cell.rs:8:21 + | +LL | fn method(self: &Cell) {} + | ^^^^^^^^^^^^^^ + | + = note: type of `self` must be `Self` or a type that dereferences to it + = help: consider changing to `self`, `&self`, `&mut self`, `self: Box`, `self: Rc`, `self: Arc`, or `self: Pin

` (where P is one of the previous types except `Self`) + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0307`. From 118cd80f7cad01fb58f3defd169b8b6121bf1cd7 Mon Sep 17 00:00:00 2001 From: arvindkhoisnam Date: Wed, 18 Nov 2026 20:47:16 +0530 Subject: [PATCH 02/11] Add examples to Allocator methods --- library/core/src/alloc/mod.rs | 114 +++++++++++++++++++++++++++++++++- 1 file changed, 113 insertions(+), 1 deletion(-) diff --git a/library/core/src/alloc/mod.rs b/library/core/src/alloc/mod.rs index e30872c09c793..8e825594181ca 100644 --- a/library/core/src/alloc/mod.rs +++ b/library/core/src/alloc/mod.rs @@ -207,6 +207,10 @@ pub const unsafe trait Allocator { /// returned excess. Implementors are free to e.g. provide an alternate method to query /// available excess if doing so is expensive and should be left to the caller. /// + /// The returned block may be uninitialized, so it is unsound to read it + /// before it is written. Use [`allocate_zeroed`](Self::allocate_zeroed) if + /// zero-initialized memory is needed. + /// /// Note that the returned block of memory is considered [*currently allocated*] /// with this allocator (and equivalent allocators). /// Therefore, it is the responsibility of implementors of `Allocator` to make sure that @@ -228,6 +232,28 @@ pub const unsafe trait Allocator { /// call the [`handle_alloc_error`] function, rather than directly invoking `panic!` or similar. /// /// [`handle_alloc_error`]: ../../alloc/alloc/fn.handle_alloc_error.html + /// + /// # Examples + /// + /// ``` + /// use std::alloc::{Allocator, Layout, System}; + /// + /// let s = "Hello, world!"; + /// let layout = Layout::array::(s.len()).unwrap(); + // FIXME(slice_ptr_get): use `.as_mut_ptr()` once stable + /// let ptr = System.allocate(layout).expect("allocation failed").cast::(); + /// + /// // SAFETY: the block is at least `s.len()` bytes long and was just allocated, + /// // so it cannot overlap `s`. + /// unsafe { ptr.as_ptr().copy_from_nonoverlapping(s.as_ptr(), s.len()) }; + /// + /// // SAFETY: the first `s.len()` bytes were initialized by the copy above. + /// let bytes = unsafe { std::slice::from_raw_parts(ptr.as_ptr(), s.len()) }; + /// assert_eq!(bytes, s.as_bytes()); + /// + /// // SAFETY: `ptr` was allocated by `System` with `layout`. + /// unsafe { System.deallocate(ptr, layout) }; + /// ``` #[stable(feature = "allocator_api", since = "1.100.0")] fn allocate(&self, layout: Layout) -> Result, AllocError>; @@ -246,6 +272,24 @@ pub const unsafe trait Allocator { /// call the [`handle_alloc_error`] function, rather than directly invoking `panic!` or similar. /// /// [`handle_alloc_error`]: ../../alloc/alloc/fn.handle_alloc_error.html + /// + /// # Examples + /// + /// ``` + /// use std::alloc::{Allocator, Layout, System}; + /// + /// let layout = Layout::new::(); + /// let ptr = System.allocate_zeroed(layout).expect("allocation failed"); + /// + /// // N.B. the below would be unsound with `allocate` rather than `allocate_zeroed`. + /// // SAFETY: `allocate_zeroed` returns a valid, initialized block. + /// let bytes = unsafe { ptr.as_ref() }; + /// assert!(bytes.iter().all(|&b| b == 0)); + /// + /// // SAFETY: `ptr` was allocated by `System` with `layout`. + // FIXME(slice_ptr_get): use `.as_mut_ptr()` once stable + /// unsafe { System.deallocate(ptr.cast(), layout) }; + /// ``` #[stable(feature = "allocator_api", since = "1.100.0")] fn allocate_zeroed(&self, layout: Layout) -> Result, AllocError> { let ptr = self.allocate(layout)?; @@ -282,7 +326,9 @@ pub const unsafe trait Allocator { /// If this returns `Ok`, then the memory block referenced by `ptr` has been [*invalidated*]. /// The old `ptr` must not be used to access the memory, even if the allocation was grown in-place. /// The newly returned pointer is the only valid pointer for accessing this memory now. - /// All bytes past `old_layout.size()` should be assumed to be uninitialised. + /// All bytes past `old_layout.size()` should be assumed to be uninitialised, so it is + /// unsound to read them before they are written. Use [`grow_zeroed`](Self::grow_zeroed) + /// if the new bytes should be zero-initialized. /// /// If this method returns `Err`, then the memory block has not been *invalidated*, /// and the contents of the memory block are unaltered. @@ -312,6 +358,45 @@ pub const unsafe trait Allocator { /// call the [`handle_alloc_error`] function, rather than directly invoking `panic!` or similar. /// /// [`handle_alloc_error`]: ../../alloc/alloc/fn.handle_alloc_error.html + /// + /// # Examples + /// + /// ``` + /// use std::alloc::{Allocator, Layout, System}; + /// + /// let s1 = "Hello"; + /// let s2 = ", world!"; + /// + /// let old_layout = Layout::array::(s1.len()).unwrap(); + // FIXME(slice_ptr_get): use `.as_mut_ptr()` once stable + /// let ptr = System.allocate(old_layout).expect("allocation failed").cast::(); + /// + /// // SAFETY: the block is at least `s1.len()` bytes long and was just allocated, + /// // so it cannot overlap `s1`. + /// unsafe { ptr.as_ptr().copy_from_nonoverlapping(s1.as_ptr(), s1.len()) }; + /// + /// let new_layout = Layout::array::(s1.len() + s2.len()).unwrap(); + /// + /// // N.B. the original `ptr` is invalidated by this operation + /// // SAFETY: `ptr` is currently allocated by `System` with `old_layout`, + /// // and `new_layout` is at least as large as `old_layout`. + // FIXME(slice_ptr_get): use `.as_mut_ptr()` once stable + /// let ptr = unsafe { System.grow(ptr, old_layout, new_layout) } + /// .expect("grow failed").cast::(); + /// + /// // SAFETY: the block is at least `s1.len() + s2.len()` bytes long, so writing + /// // `s2.len()` bytes at offset `s1.len()` stays in bounds; it cannot overlap `s2`. + /// unsafe { + /// ptr.as_ptr().add(s1.len()).copy_from_nonoverlapping(s2.as_ptr(), s2.len()); + /// } + /// + /// // SAFETY: all bytes within `new_layout.size()` are now initialized. + /// let bytes = unsafe { std::slice::from_raw_parts(ptr.as_ptr(), new_layout.size()) }; + /// assert_eq!(bytes, b"Hello, world!"); + /// + /// // SAFETY: `ptr` is currently allocated by `System` with `new_layout`. + /// unsafe { System.deallocate(ptr, new_layout) }; + /// ``` #[stable(feature = "allocator_api", since = "1.100.0")] unsafe fn grow( &self, @@ -440,6 +525,33 @@ pub const unsafe trait Allocator { /// call the [`handle_alloc_error`] function, rather than directly invoking `panic!` or similar. /// /// [`handle_alloc_error`]: ../../alloc/alloc/fn.handle_alloc_error.html + /// + /// # Examples + /// + /// ``` + /// use std::alloc::{Allocator, Layout, System}; + /// + /// let old_layout = Layout::array::(4).unwrap(); + /// let ptr = System.allocate(old_layout).expect("allocation failed"); + /// + /// // SAFETY: the block holds at least 4 `u32`s and is aligned for `u32`. + /// unsafe { ptr.cast::<[u32; 4]>().write([7, 8, 9, 10]) }; + /// + /// let new_layout = Layout::array::(2).unwrap(); + /// + /// // N.B. the original `ptr` is invalidated by this operation + /// // SAFETY: `ptr` is currently allocated by `System` with `old_layout`, + /// // and `new_layout` is no larger than `old_layout`. + /// let ptr = unsafe { System.shrink(ptr.cast(), old_layout, new_layout) } + /// .expect("shrink failed"); + /// + /// // The contents that fit in the new layout are preserved. + /// // SAFETY: the first two `u32`s were written above and `shrink` kept them. + /// assert_eq!(unsafe { ptr.cast::<[u32; 2]>().read() }, [7, 8]); + /// + /// // SAFETY: `ptr` is currently allocated by `System` with `new_layout`. + /// unsafe { System.deallocate(ptr.cast(), new_layout) }; + /// ``` #[stable(feature = "allocator_api", since = "1.100.0")] unsafe fn shrink( &self, From 62368a08a860e9587c886727bbe25d0b99e92763 Mon Sep 17 00:00:00 2001 From: Amirhossein Akhlaghpour Date: Wed, 18 Nov 2026 20:28:48 +0330 Subject: [PATCH 03/11] use delayed bug recovery for invalid object receivers Signed-off-by: Amirhossein Akhlaghpour --- .../rustc_hir_typeck/src/method/confirm.rs | 103 +++++++++--------- 1 file changed, 53 insertions(+), 50 deletions(-) diff --git a/compiler/rustc_hir_typeck/src/method/confirm.rs b/compiler/rustc_hir_typeck/src/method/confirm.rs index 85ac4c6817bcf..c76854f76fe3b 100644 --- a/compiler/rustc_hir_typeck/src/method/confirm.rs +++ b/compiler/rustc_hir_typeck/src/method/confirm.rs @@ -333,43 +333,32 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> { return ty::GenericArgs::extend_with_error(self.tcx, trait_def_id, &[]); } - self.extract_existential_trait_ref(self_ty, |this, object_ty, principal| { - // The object data has no entry for the Self - // Type. For the purposes of this method call, we - // instantiate the object type itself. This - // wouldn't be a sound instantiation in all cases, - // since each instance of the object type is a - // different existential and hence could match - // distinct types (e.g., if `Self` appeared as an - // argument type), but those cases have already - // been ruled out when we deemed the trait to be - // "dyn-compatible". - let original_poly_trait_ref = principal.with_self_ty(this.tcx, object_ty); - let upcast_poly_trait_ref = this.upcast(original_poly_trait_ref, trait_def_id); - let upcast_trait_ref = - this.instantiate_binder_with_fresh_vars(upcast_poly_trait_ref); - debug!( - "original_poly_trait_ref={:?} upcast_trait_ref={:?} target_trait={:?}", - original_poly_trait_ref, upcast_trait_ref, trait_def_id - ); - upcast_trait_ref.args - }) - .unwrap_or_else(|| { - // An invalid receiver can still lead to an ObjectPick even when we - // can't reach the trait object. if the method failed WF checking, - // recover instead of ICEing. - if pick.item.def_id.as_local().is_some_and(|def_id| { - self.tcx.ensure_result().check_well_formed(def_id).is_err() - }) { - ty::GenericArgs::extend_with_error(self.tcx, trait_def_id, &[]) - } else { - span_bug!( - self.span, - "self-type `{}` for ObjectPick never dereferenced to an object", - self_ty - ) - } - }) + self.extract_existential_trait_ref( + self_ty, + trait_def_id, + |this, object_ty, principal| { + // The object data has no entry for the Self + // Type. For the purposes of this method call, we + // instantiate the object type itself. This + // wouldn't be a sound instantiation in all cases, + // since each instance of the object type is a + // different existential and hence could match + // distinct types (e.g., if `Self` appeared as an + // argument type), but those cases have already + // been ruled out when we deemed the trait to be + // "dyn-compatible". + let original_poly_trait_ref = principal.with_self_ty(this.tcx, object_ty); + let upcast_poly_trait_ref = + this.upcast(original_poly_trait_ref, trait_def_id); + let upcast_trait_ref = + this.instantiate_binder_with_fresh_vars(upcast_poly_trait_ref); + debug!( + "original_poly_trait_ref={:?} upcast_trait_ref={:?} target_trait={:?}", + original_poly_trait_ref, upcast_trait_ref, trait_def_id + ); + upcast_trait_ref.args + }, + ) } probe::TraitPick { .. } => { @@ -391,13 +380,18 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> { } } - fn extract_existential_trait_ref( + fn extract_existential_trait_ref( &mut self, self_ty: Ty<'tcx>, + trait_def_id: DefId, mut closure: F, - ) -> Option + ) -> GenericArgs<'tcx> where - F: FnMut(&mut ConfirmContext<'a, 'tcx>, Ty<'tcx>, ty::PolyExistentialTraitRef<'tcx>) -> R, + F: FnMut( + &mut ConfirmContext<'a, 'tcx>, + Ty<'tcx>, + ty::PolyExistentialTraitRef<'tcx>, + ) -> GenericArgs<'tcx>, { // If we specified that this is an object method, then the // self-type ought to be something that can be dereferenced to @@ -414,16 +408,25 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> { autoderef = autoderef.use_receiver_trait(); } - autoderef.include_raw_pointers().find_map(|(ty, _)| match ty.kind() { - ty::Dynamic(data, ..) => Some(closure( - self, - ty, - data.principal().unwrap_or_else(|| { - span_bug!(self.span, "calling trait method on empty object?") - }), - )), - _ => None, - }) + autoderef + .include_raw_pointers() + .find_map(|(ty, _)| match ty.kind() { + ty::Dynamic(data, ..) => Some(closure( + self, + ty, + data.principal().unwrap_or_else(|| { + span_bug!(self.span, "calling trait method on empty object?") + }), + )), + _ => None, + }) + .unwrap_or_else(|| { + self.dcx().span_delayed_bug( + self.span, + format!("self-type `{self_ty}` for ObjectPick never dereferenced to an object"), + ); + ty::GenericArgs::extend_with_error(self.tcx, trait_def_id, &[]) + }) } fn instantiate_method_args( From 6e767d1e209b85011f84a96b9b883038d688e383 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Fri, 13 Nov 2026 21:07:37 +0000 Subject: [PATCH 04/11] Point at trait is implemented but private ``` help: trait `crate::method::A` which provides `a` is implemented but not reachable --> $DIR/item-privacy.rs:7:5 | LL | trait A { | ^^^^^^^ ``` --- .../rustc_hir_typeck/src/method/suggest.rs | 107 +++++++++++------- ...ck-scoped-trait-import-issue-134146.stderr | 18 ++- tests/ui/traits/item-privacy.stderr | 18 ++- 3 files changed, 94 insertions(+), 49 deletions(-) diff --git a/compiler/rustc_hir_typeck/src/method/suggest.rs b/compiler/rustc_hir_typeck/src/method/suggest.rs index 20eb43ba718e6..6d2366562874a 100644 --- a/compiler/rustc_hir_typeck/src/method/suggest.rs +++ b/compiler/rustc_hir_typeck/src/method/suggest.rs @@ -400,7 +400,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ); self.suggest_use_candidates( candidates, - |accessible_sugg, inaccessible_sugg, span| { + |accessible_sugg, inaccessible_sugg, _, inaccessible, span| { let suggest_for_access = |err: &mut Diag<'_>, mut msg: String, sugg: Vec<_>| { msg += &format!( @@ -416,8 +416,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ); }; let suggest_for_privacy = - |err: &mut Diag<'_>, mut msg: String, suggs: Vec| { - if let [sugg] = suggs.as_slice() { + |err: &mut Diag<'_>, mut msg: String, suggs: Vec, inaccessible: Vec| { + if let [def_id] = inaccessible.as_slice() && let [sugg] = suggs.as_slice() { + err.span_help(self.tcx.def_span(*def_id), format!("\ + trait `{}` provides `{item_name}` is implemented but not reachable", + sugg.trim(), + )); + } else if let [sugg] = suggs.as_slice() { err.help(format!("\ trait `{}` provides `{item_name}` is implemented but not reachable", sugg.trim(), @@ -429,12 +434,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { }; if accessible_sugg.is_empty() { // `inaccessible_sugg` must not be empty - suggest_for_privacy(&mut err, help, inaccessible_sugg); + suggest_for_privacy(&mut err, help, inaccessible_sugg, inaccessible); } else if inaccessible_sugg.is_empty() { suggest_for_access(&mut err, help, accessible_sugg); } else { suggest_for_access(&mut err, help.clone(), accessible_sugg); - suggest_for_privacy(&mut err, help, inaccessible_sugg); + suggest_for_privacy(&mut err, help, inaccessible_sugg, inaccessible); } }, ); @@ -4002,7 +4007,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { fn suggest_use_candidates(&self, candidates: Vec, handle_candidates: F) where - F: FnOnce(Vec, Vec, Span), + F: FnOnce(Vec, Vec, Vec, Vec, Span), { let parent_map = self.tcx.visible_parent_map(()); @@ -4016,19 +4021,19 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { .all(|id| self.tcx.def_kind(id) == DefKind::Mod) }); - let sugg = |candidates: Vec<_>, visible| { + let sugg = |candidates: &[DefId], visible| { // Separate out candidates that must be imported with a glob, because they are named `_` // and cannot be referred with their identifier. let (candidates, globs): (Vec<_>, Vec<_>) = candidates.into_iter().partition(|trait_did| { if let Some(parent_did) = parent_map.get(trait_did) { // If the item is re-exported as `_`, we should suggest a glob-import instead. - if *parent_did != self.tcx.parent(*trait_did) + if *parent_did != self.tcx.parent(**trait_did) && self .tcx .module_children(*parent_did) .iter() - .filter(|child| child.res.opt_def_id() == Some(*trait_did)) + .filter(|child| child.res.opt_def_id() == Some(**trait_did)) .all(|child| child.ident.name == kw::Underscore) { return false; @@ -4064,12 +4069,18 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { sugg }; - let accessible_sugg = sugg(accessible_candidates, true); - let inaccessible_sugg = sugg(inaccessible_candidates, false); + let accessible_sugg = sugg(&accessible_candidates, true); + let inaccessible_sugg = sugg(&inaccessible_candidates, false); let (module, _) = self.tcx.hir_get_module(self.mod_id); let span = module.spans.inject_use_span; - handle_candidates(accessible_sugg, inaccessible_sugg, span); + handle_candidates( + accessible_sugg, + inaccessible_sugg, + accessible_candidates, + inaccessible_candidates, + span, + ); } fn suggest_valid_traits( @@ -4107,39 +4118,49 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } ); - self.suggest_use_candidates(candidates, |accessible_sugg, inaccessible_sugg, span| { - let suggest_for_access = |err: &mut Diag<'_>, mut msg: String, suggs: Vec<_>| { - msg += &format!( - "; perhaps you want to import {one_of}", - one_of = if suggs.len() == 1 { "it" } else { "one of them" }, - ); - err.span_suggestions(span, msg, suggs, Applicability::MaybeIncorrect); - }; - let suggest_for_privacy = |err: &mut Diag<'_>, suggs: Vec| { - let msg = format!( - "{this_trait_is} implemented but not reachable", - this_trait_is = if let [sugg] = suggs.as_slice() { - format!("trait `{}` which provides `{item_name}` is", sugg.trim()) - } else { - format!("the following traits which provide `{item_name}` are") - } - ); - if suggs.len() == 1 { - err.help(msg); + self.suggest_use_candidates( + candidates, + |accessible_sugg, inaccessible_sugg, _, inaccessible, span| { + let suggest_for_access = + |err: &mut Diag<'_>, mut msg: String, suggs: Vec<_>| { + msg += &format!( + "; perhaps you want to import {one_of}", + one_of = if suggs.len() == 1 { "it" } else { "one of them" }, + ); + err.span_suggestions(span, msg, suggs, Applicability::MaybeIncorrect); + }; + let suggest_for_privacy = + |err: &mut Diag<'_>, suggs: Vec, inaccessible: Vec| { + let msg = format!( + "{this_trait_is} implemented but not reachable", + this_trait_is = if let [sugg] = suggs.as_slice() { + format!( + "trait `{}` which provides `{item_name}` is", + sugg.trim() + ) + } else { + format!("the following traits which provide `{item_name}` are") + } + ); + if let [def_id] = inaccessible { + err.span_help(self.tcx.def_span(def_id), msg); + } else if suggs.len() == 1 { + err.help(msg); + } else { + err.help(format!("{msg}:\n{}", suggs.join("").trim_end())); + } + }; + if accessible_sugg.is_empty() { + // `inaccessible_sugg` must not be empty + suggest_for_privacy(err, inaccessible_sugg, inaccessible); + } else if inaccessible_sugg.is_empty() { + suggest_for_access(err, msg, accessible_sugg); } else { - err.help(format!("{msg}:\n{}", suggs.join("").trim_end())); + suggest_for_access(err, msg, accessible_sugg); + suggest_for_privacy(err, inaccessible_sugg, inaccessible); } - }; - if accessible_sugg.is_empty() { - // `inaccessible_sugg` must not be empty - suggest_for_privacy(err, inaccessible_sugg); - } else if inaccessible_sugg.is_empty() { - suggest_for_access(err, msg, accessible_sugg); - } else { - suggest_for_access(err, msg, accessible_sugg); - suggest_for_privacy(err, inaccessible_sugg); - } - }); + }, + ); if let Some(did) = edition_fix { err.note(format!( diff --git a/tests/ui/traits/block-scoped-trait-import-issue-134146.stderr b/tests/ui/traits/block-scoped-trait-import-issue-134146.stderr index 412acca28e9ce..48c0a5c1dfe9e 100644 --- a/tests/ui/traits/block-scoped-trait-import-issue-134146.stderr +++ b/tests/ui/traits/block-scoped-trait-import-issue-134146.stderr @@ -8,7 +8,11 @@ LL | ().hello(); | ^^^^^ method not found in `()` | = help: items from traits can only be used if the trait is in scope - = help: trait `crate::main::Hello` which provides `hello` is implemented but not reachable +help: trait `crate::main::Hello` which provides `hello` is implemented but not reachable + --> $DIR/block-scoped-trait-import-issue-134146.rs:8:9 + | +LL | trait Hello { + | ^^^^^^^^^^^ error[E0599]: no method named `nested` found for unit type `()` in the current scope --> $DIR/block-scoped-trait-import-issue-134146.rs:30:8 @@ -20,7 +24,11 @@ LL | ().nested(); | ^^^^^^ method not found in `()` | = help: items from traits can only be used if the trait is in scope - = help: trait `crate::nested_module::inner::Nested` which provides `nested` is implemented but not reachable +help: trait `crate::nested_module::inner::Nested` which provides `nested` is implemented but not reachable + --> $DIR/block-scoped-trait-import-issue-134146.rs:22:9 + | +LL | pub trait Nested { + | ^^^^^^^^^^^^^^^^ error[E0599]: no method named `in_const` found for unit type `()` in the current scope --> $DIR/block-scoped-trait-import-issue-134146.rs:42:8 @@ -32,7 +40,11 @@ LL | ().in_const(); | ^^^^^^^^ method not found in `()` | = help: items from traits can only be used if the trait is in scope - = help: trait `crate::_::InConst` which provides `in_const` is implemented but not reachable +help: trait `crate::_::InConst` which provides `in_const` is implemented but not reachable + --> $DIR/block-scoped-trait-import-issue-134146.rs:35:5 + | +LL | trait InConst { + | ^^^^^^^^^^^^^ error[E0599]: no method named `several` found for unit type `()` in the current scope --> $DIR/block-scoped-trait-import-issue-134146.rs:57:8 diff --git a/tests/ui/traits/item-privacy.stderr b/tests/ui/traits/item-privacy.stderr index 545f6f54a7939..baec52e4fccd1 100644 --- a/tests/ui/traits/item-privacy.stderr +++ b/tests/ui/traits/item-privacy.stderr @@ -8,7 +8,11 @@ LL | S.a(); | ^ | = help: items from traits can only be used if the trait is implemented and in scope - = help: trait `crate::method::A` which provides `a` is implemented but not reachable +help: trait `crate::method::A` which provides `a` is implemented but not reachable + --> $DIR/item-privacy.rs:7:5 + | +LL | trait A { + | ^^^^^^^ help: there is a method `b` with a similar name | LL - S.a(); @@ -57,7 +61,11 @@ LL | S::a(&S); | ^ associated function or constant not found in `S` | = help: items from traits can only be used if the trait is implemented and in scope - = help: trait `crate::method::A` which provides `a` is implemented but not reachable +help: trait `crate::method::A` which provides `a` is implemented but not reachable + --> $DIR/item-privacy.rs:7:5 + | +LL | trait A { + | ^^^^^^^ help: there is an associated constant `B` with a similar name --> $DIR/item-privacy.rs:30:9 | @@ -105,7 +113,11 @@ LL | S::A; | ^ associated function or constant not found in `S` | = help: items from traits can only be used if the trait is implemented and in scope - = help: trait `crate::assoc_const::A` which provides `A` is implemented but not reachable +help: trait `crate::assoc_const::A` which provides `A` is implemented but not reachable + --> $DIR/item-privacy.rs:25:5 + | +LL | trait A { + | ^^^^^^^ help: there is an associated constant `B` with a similar name | LL - S::A; From f764c8c33dff7cf17a5a676f165a1fb1d43eb4de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Fri, 13 Nov 2026 22:54:11 +0000 Subject: [PATCH 05/11] Point at method even when available through autoderef --- compiler/rustc_hir_typeck/src/method/probe.rs | 2 +- compiler/rustc_hir_typeck/src/method/suggest.rs | 6 +++--- tests/ui/coherence/coherence_inherent.stderr | 3 +++ tests/ui/coherence/coherence_inherent_cc.stderr | 5 +++++ tests/ui/impl-trait/no-method-suggested-traits.stderr | 8 ++++++++ .../ui/methods/rigid-alias-bound-is-not-inherent-2.stderr | 3 +++ tests/ui/suggestions/import-visible-path-39175.stderr | 4 ++++ .../nested-mod-trait-method-lookup-leak-10465.stderr | 3 +++ 8 files changed, 30 insertions(+), 4 deletions(-) diff --git a/compiler/rustc_hir_typeck/src/method/probe.rs b/compiler/rustc_hir_typeck/src/method/probe.rs index 4e05903660f02..a631466bd640c 100644 --- a/compiler/rustc_hir_typeck/src/method/probe.rs +++ b/compiler/rustc_hir_typeck/src/method/probe.rs @@ -1913,7 +1913,7 @@ impl<'tcx> Pick<'tcx> { // the code from `report_method_error()`. lint.help(format!( "call with fully qualified syntax `{}(...)` to keep using the current \ - method", + method", tcx.def_path_str(this.item.def_id), )); } diff --git a/compiler/rustc_hir_typeck/src/method/suggest.rs b/compiler/rustc_hir_typeck/src/method/suggest.rs index 6d2366562874a..ac6e583ba4faa 100644 --- a/compiler/rustc_hir_typeck/src/method/suggest.rs +++ b/compiler/rustc_hir_typeck/src/method/suggest.rs @@ -4231,8 +4231,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // We point at the method, but we just skip the rest of the check for arbitrary // self types and rely on the suggestion to `use` the trait from // `suggest_valid_traits`. - let did = Some(pick.item.container_id(self.tcx)); - if skippable.contains(&did) { + let did = pick.item.container_id(self.tcx); + if skippable.contains(&Some(did)) { continue; } trait_in_other_version_found = self @@ -4242,7 +4242,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { rcvr.hir_id, Some(*rcvr_ty), ); - if pick.autoderefs == 0 && !trait_in_other_version_found { + if !trait_in_other_version_found { err.span_label( pick.item.ident(self.tcx).span, format!("the method is available for `{rcvr_ty}` here"), diff --git a/tests/ui/coherence/coherence_inherent.stderr b/tests/ui/coherence/coherence_inherent.stderr index a4bf750fec8ad..8ed62716168c6 100644 --- a/tests/ui/coherence/coherence_inherent.stderr +++ b/tests/ui/coherence/coherence_inherent.stderr @@ -1,6 +1,9 @@ error[E0599]: no method named `the_fn` found for reference `&TheStruct` in the current scope --> $DIR/coherence_inherent.rs:32:11 | +LL | fn the_fn(&self); + | ------ the method is available for `&TheStruct` here +... LL | s.the_fn(); | ^^^^^^ method not found in `&TheStruct` | diff --git a/tests/ui/coherence/coherence_inherent_cc.stderr b/tests/ui/coherence/coherence_inherent_cc.stderr index 3b562ac19ab1e..fa33dc2bc3192 100644 --- a/tests/ui/coherence/coherence_inherent_cc.stderr +++ b/tests/ui/coherence/coherence_inherent_cc.stderr @@ -4,6 +4,11 @@ error[E0599]: no method named `the_fn` found for reference `&TheStruct` in the c LL | s.the_fn(); | ^^^^^^ method not found in `&TheStruct` | + ::: $DIR/auxiliary/coherence_inherent_cc_lib.rs:4:8 + | +LL | fn the_fn(&self); + | ------ the method is available for `&TheStruct` here + | = help: items from traits can only be used if the trait is in scope help: trait `TheTrait` which provides `the_fn` is implemented but not in scope; perhaps you want to import it | diff --git a/tests/ui/impl-trait/no-method-suggested-traits.stderr b/tests/ui/impl-trait/no-method-suggested-traits.stderr index 9115d814c404e..c7b1d99e42e2b 100644 --- a/tests/ui/impl-trait/no-method-suggested-traits.stderr +++ b/tests/ui/impl-trait/no-method-suggested-traits.stderr @@ -44,6 +44,9 @@ LL + use crate::foo::Bar; error[E0599]: no method named `method` found for struct `Rc<&mut Box<&char>>` in the current scope --> $DIR/no-method-suggested-traits.rs:35:43 | +LL | fn method(&self) {} + | ------ the method is available for `Rc<&mut Box<&char>>` here +... LL | std::rc::Rc::new(&mut Box::new(&'a')).method(); | ^^^^^^ method not found in `Rc<&mut Box<&char>>` | @@ -76,6 +79,11 @@ error[E0599]: no method named `method` found for struct `Rc<&mut Box<&i32>>` in LL | std::rc::Rc::new(&mut Box::new(&1i32)).method(); | ^^^^^^ method not found in `Rc<&mut Box<&i32>>` | + ::: $DIR/auxiliary/no_method_suggested_traits.rs:8:12 + | +LL | fn method(&self) {} + | ------ the method is available for `Rc<&mut Box<&i32>>` here + | = help: items from traits can only be used if the trait is in scope help: trait `PubPub` which provides `method` is implemented but not in scope; perhaps you want to import it | diff --git a/tests/ui/methods/rigid-alias-bound-is-not-inherent-2.stderr b/tests/ui/methods/rigid-alias-bound-is-not-inherent-2.stderr index 487ef3e0eadae..3920d56a6ee30 100644 --- a/tests/ui/methods/rigid-alias-bound-is-not-inherent-2.stderr +++ b/tests/ui/methods/rigid-alias-bound-is-not-inherent-2.stderr @@ -1,6 +1,9 @@ error[E0599]: no method named `method` found for type parameter `impl Deref` in the current scope --> $DIR/rigid-alias-bound-is-not-inherent-2.rs:14:7 | +LL | fn method(&self); + | ------ the method is available for `impl Deref` here +... LL | fn foo(x: impl Deref) { | --------------------------------- method `method` not found for this type parameter LL | x.method(); diff --git a/tests/ui/suggestions/import-visible-path-39175.stderr b/tests/ui/suggestions/import-visible-path-39175.stderr index a758a18f331d3..b18db9fc96012 100644 --- a/tests/ui/suggestions/import-visible-path-39175.stderr +++ b/tests/ui/suggestions/import-visible-path-39175.stderr @@ -4,6 +4,10 @@ error[E0599]: no method named `exec` found for mutable reference `&mut Command` LL | let _ = Command::new("echo").arg("hello").exec(); | ^^^^ method not found in `&mut Command` | + --> $SRC_DIR/std/src/os/unix/process.rs:LL:COL + | + = note: the method is available for `&mut Command` here + | = help: items from traits can only be used if the trait is in scope help: trait `CommandExt` which provides `exec` is implemented but not in scope; perhaps you want to import it | diff --git a/tests/ui/traits/nested-mod-trait-method-lookup-leak-10465.stderr b/tests/ui/traits/nested-mod-trait-method-lookup-leak-10465.stderr index c10f73bd7906c..cfa9357c063d8 100644 --- a/tests/ui/traits/nested-mod-trait-method-lookup-leak-10465.stderr +++ b/tests/ui/traits/nested-mod-trait-method-lookup-leak-10465.stderr @@ -1,6 +1,9 @@ error[E0599]: no method named `foo` found for reference `&B` in the current scope --> $DIR/nested-mod-trait-method-lookup-leak-10465.rs:20:15 | +LL | fn foo(&self); + | --- the method is available for `&B` here +... LL | b.foo(); | ^^^ method not found in `&B` | From 34409f443e4eb8fe137bfbc3bb71a87d1dce6d8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Fri, 13 Nov 2026 23:11:33 +0000 Subject: [PATCH 06/11] Use note instead of label when pointing at available method --- .../rustc_hir_typeck/src/method/suggest.rs | 19 ++++++++-- ...project-to-specializable-projection.stderr | 5 +-- tests/ui/coherence/coherence_inherent.stderr | 9 +++-- .../ui/coherence/coherence_inherent_cc.stderr | 7 ++-- tests/ui/hygiene/trait_items.stderr | 9 +++-- ...od_on_inherent_impl_ref-err.current.stderr | 9 +++-- ...ethod_on_inherent_impl_ref-err.next.stderr | 9 +++-- ...all_method_without_import.no_import.stderr | 4 +- .../no-method-suggested-traits.stderr | 32 ++++++++++------ tests/ui/imports/issue-114682-3.stderr | 9 +++-- tests/ui/imports/overlapping_pub_trait.stderr | 6 +-- ...uggested-without-extern-crate-56175.stderr | 14 ++++--- tests/ui/imports/unnamed_pub_trait.stderr | 6 +-- .../macros/missing-writer-issue-139830.stderr | 5 +-- ...on-trait-with-extra-generics-no-ice.stderr | 4 +- ...rigid-alias-bound-is-not-inherent-2.stderr | 9 +++-- .../similar-method-out-of-scope-trait.stderr | 37 +++++++++++++------ .../rust-2018/trait-import-suggestions.stderr | 18 ++++++--- .../ui/shadowed/shadowed-trait-methods.stderr | 8 ++-- .../double-reference-ty-in-self-ty.stderr | 9 +++-- .../import-trait-for-method-call.stderr | 4 +- .../import-visible-path-39175.stderr | 4 +- .../suggest-tryinto-edition-change.rs | 1 + .../suggest-tryinto-edition-change.stderr | 10 ++--- .../suggestions/use-placement-typeck.stderr | 9 +++-- ...ck-scoped-trait-import-issue-134146.stderr | 27 +++++++++----- tests/ui/traits/item-privacy.stderr | 9 +++-- ...-mod-trait-method-lookup-leak-10465.stderr | 9 +++-- tests/ui/typeck/issue-43189.stderr | 7 ++-- 29 files changed, 191 insertions(+), 117 deletions(-) diff --git a/compiler/rustc_hir_typeck/src/method/suggest.rs b/compiler/rustc_hir_typeck/src/method/suggest.rs index ac6e583ba4faa..c2fa937a14d27 100644 --- a/compiler/rustc_hir_typeck/src/method/suggest.rs +++ b/compiler/rustc_hir_typeck/src/method/suggest.rs @@ -4243,9 +4243,22 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { Some(*rcvr_ty), ); if !trait_in_other_version_found { - err.span_label( - pick.item.ident(self.tcx).span, - format!("the method is available for `{rcvr_ty}` here"), + let sp = pick.item.ident(self.tcx).span; + let mut span: MultiSpan = sp.into(); + span.push_span_context( + self.tcx + .def_span(pick.item.container_id(self.tcx)) + .shrink_to_lo(), + ); + let mut on_trait = String::new(); + + if self.tcx.def_kind(did) == DefKind::Trait { + let name = self.tcx.item_name(did); + on_trait = format!("on trait `{name}` "); + } + err.span_note( + span, + format!("the method is available {on_trait}for `{rcvr_ty}`"), ); } break; diff --git a/tests/ui/async-await/in-trait/dont-project-to-specializable-projection.stderr b/tests/ui/async-await/in-trait/dont-project-to-specializable-projection.stderr index 9a07c077518a5..4a27fed830c61 100644 --- a/tests/ui/async-await/in-trait/dont-project-to-specializable-projection.stderr +++ b/tests/ui/async-await/in-trait/dont-project-to-specializable-projection.stderr @@ -30,13 +30,12 @@ LL | match fut.as_mut().poll(ctx) { | | | this method is `std::pin::Pin::::as_mut` | - --> $SRC_DIR/core/src/future/future.rs:LL:COL - | - = note: the method is available for `Pin<&mut impl Future>` here note: this returns `Pin<&mut impl Future>` --> $SRC_DIR/core/src/pin.rs:LL:COL note: you might have meant to call `std::convert::AsMut::as_mut` instead --> $SRC_DIR/core/src/convert/mod.rs:LL:COL +note: the method is available on trait `Future` for `Pin<&mut impl Future>` + --> $SRC_DIR/core/src/future/future.rs:LL:COL = help: items from traits can only be used if the trait is in scope help: consider calling `std::convert::AsMut::as_mut` using the fully-qualified path | diff --git a/tests/ui/coherence/coherence_inherent.stderr b/tests/ui/coherence/coherence_inherent.stderr index 8ed62716168c6..77b60e19f4afb 100644 --- a/tests/ui/coherence/coherence_inherent.stderr +++ b/tests/ui/coherence/coherence_inherent.stderr @@ -1,12 +1,15 @@ error[E0599]: no method named `the_fn` found for reference `&TheStruct` in the current scope --> $DIR/coherence_inherent.rs:32:11 | -LL | fn the_fn(&self); - | ------ the method is available for `&TheStruct` here -... LL | s.the_fn(); | ^^^^^^ method not found in `&TheStruct` | +note: the method is available on trait `TheTrait` for `&TheStruct` + --> $DIR/coherence_inherent.rs:7:12 + | +LL | pub trait TheTrait { +LL | fn the_fn(&self); + | ^^^^^^ = help: items from traits can only be used if the trait is in scope help: trait `TheTrait` which provides `the_fn` is implemented but not in scope; perhaps you want to import it | diff --git a/tests/ui/coherence/coherence_inherent_cc.stderr b/tests/ui/coherence/coherence_inherent_cc.stderr index fa33dc2bc3192..1a1384bb22caf 100644 --- a/tests/ui/coherence/coherence_inherent_cc.stderr +++ b/tests/ui/coherence/coherence_inherent_cc.stderr @@ -4,11 +4,12 @@ error[E0599]: no method named `the_fn` found for reference `&TheStruct` in the c LL | s.the_fn(); | ^^^^^^ method not found in `&TheStruct` | - ::: $DIR/auxiliary/coherence_inherent_cc_lib.rs:4:8 +note: the method is available on trait `TheTrait` for `&TheStruct` + --> $DIR/auxiliary/coherence_inherent_cc_lib.rs:4:8 | +LL | pub trait TheTrait { LL | fn the_fn(&self); - | ------ the method is available for `&TheStruct` here - | + | ^^^^^^ = help: items from traits can only be used if the trait is in scope help: trait `TheTrait` which provides `the_fn` is implemented but not in scope; perhaps you want to import it | diff --git a/tests/ui/hygiene/trait_items.stderr b/tests/ui/hygiene/trait_items.stderr index 94d46961dbff8..3e1c33f9049c3 100644 --- a/tests/ui/hygiene/trait_items.stderr +++ b/tests/ui/hygiene/trait_items.stderr @@ -1,15 +1,18 @@ error[E0599]: no method named `f` found for unit type `()` in the current scope --> $DIR/trait_items.rs:18:24 | -LL | fn f(&self) {} - | - the method is available for `()` here -... LL | fn f() { ::baz::m!(); } | ----------- in this macro invocation ... LL | pub macro m() { ().f() } | ^ method not found in `()` | +note: the method is available on trait `T` for `()` + --> $DIR/trait_items.rs:6:12 + | +LL | pub trait T { +LL | fn f(&self) {} + | ^ = help: items from traits can only be used if the trait is in scope help: trait `T` which provides `f` is implemented but not in scope; perhaps you want to import it | diff --git a/tests/ui/impl-trait/call_method_on_inherent_impl_ref-err.current.stderr b/tests/ui/impl-trait/call_method_on_inherent_impl_ref-err.current.stderr index 6c3ed0efcd9f4..b9f904dbf67f2 100644 --- a/tests/ui/impl-trait/call_method_on_inherent_impl_ref-err.current.stderr +++ b/tests/ui/impl-trait/call_method_on_inherent_impl_ref-err.current.stderr @@ -1,12 +1,15 @@ error[E0599]: no method named `my_debug` found for opaque type `impl Debug` in the current scope --> $DIR/call_method_on_inherent_impl_ref-err.rs:19:11 | -LL | fn my_debug(&self); - | -------- the method is available for `&impl Debug` here -... LL | x.my_debug(); | ^^^^^^^^ method not found in `impl Debug` | +note: the method is available on trait `MyDebug` for `&impl Debug` + --> $DIR/call_method_on_inherent_impl_ref-err.rs:6:8 + | +LL | trait MyDebug { +LL | fn my_debug(&self); + | ^^^^^^^^ = help: items from traits can only be used if the trait is implemented and in scope note: `MyDebug` defines an item `my_debug`, perhaps you need to implement it --> $DIR/call_method_on_inherent_impl_ref-err.rs:5:1 diff --git a/tests/ui/impl-trait/call_method_on_inherent_impl_ref-err.next.stderr b/tests/ui/impl-trait/call_method_on_inherent_impl_ref-err.next.stderr index 94985e5e60b4e..9bbb6ed6e8a48 100644 --- a/tests/ui/impl-trait/call_method_on_inherent_impl_ref-err.next.stderr +++ b/tests/ui/impl-trait/call_method_on_inherent_impl_ref-err.next.stderr @@ -1,12 +1,15 @@ error[E0599]: no method named `my_debug` found for type `_` in the current scope --> $DIR/call_method_on_inherent_impl_ref-err.rs:19:11 | -LL | fn my_debug(&self); - | -------- the method is available for `&_` here -... LL | x.my_debug(); | ^^^^^^^^ method not found in `_` | +note: the method is available on trait `MyDebug` for `&_` + --> $DIR/call_method_on_inherent_impl_ref-err.rs:6:8 + | +LL | trait MyDebug { +LL | fn my_debug(&self); + | ^^^^^^^^ = help: items from traits can only be used if the trait is implemented and in scope note: `MyDebug` defines an item `my_debug`, perhaps you need to implement it --> $DIR/call_method_on_inherent_impl_ref-err.rs:5:1 diff --git a/tests/ui/impl-trait/call_method_without_import.no_import.stderr b/tests/ui/impl-trait/call_method_without_import.no_import.stderr index 2ca79aa7c10f9..e258bb69de2dd 100644 --- a/tests/ui/impl-trait/call_method_without_import.no_import.stderr +++ b/tests/ui/impl-trait/call_method_without_import.no_import.stderr @@ -4,10 +4,8 @@ error[E0599]: no method named `fmt` found for opaque type `impl Debug` in the cu LL | x.fmt(f); | ^^^ method not found in `impl Debug` | +note: the method is available on trait `Debug` for `impl Debug` --> $SRC_DIR/core/src/fmt/mod.rs:LL:COL - | - = note: the method is available for `impl Debug` here - | = help: items from traits can only be used if the trait is in scope help: trait `Debug` which provides `fmt` is implemented but not in scope; perhaps you want to import it | diff --git a/tests/ui/impl-trait/no-method-suggested-traits.stderr b/tests/ui/impl-trait/no-method-suggested-traits.stderr index c7b1d99e42e2b..765e834ef5697 100644 --- a/tests/ui/impl-trait/no-method-suggested-traits.stderr +++ b/tests/ui/impl-trait/no-method-suggested-traits.stderr @@ -29,12 +29,15 @@ LL + use crate::no_method_suggested_traits::foo::PubPub; error[E0599]: no method named `method` found for type `char` in the current scope --> $DIR/no-method-suggested-traits.rs:33:9 | -LL | fn method(&self) {} - | ------ the method is available for `char` here -... LL | 'a'.method(); | ^^^^^^ method not found in `char` | +note: the method is available on trait `Bar` for `char` + --> $DIR/no-method-suggested-traits.rs:12:12 + | +LL | pub trait Bar { +LL | fn method(&self) {} + | ^^^^^^ = help: items from traits can only be used if the trait is in scope help: trait `Bar` which provides `method` is implemented but not in scope; perhaps you want to import it | @@ -44,12 +47,15 @@ LL + use crate::foo::Bar; error[E0599]: no method named `method` found for struct `Rc<&mut Box<&char>>` in the current scope --> $DIR/no-method-suggested-traits.rs:35:43 | -LL | fn method(&self) {} - | ------ the method is available for `Rc<&mut Box<&char>>` here -... LL | std::rc::Rc::new(&mut Box::new(&'a')).method(); | ^^^^^^ method not found in `Rc<&mut Box<&char>>` | +note: the method is available on trait `Bar` for `Rc<&mut Box<&char>>` + --> $DIR/no-method-suggested-traits.rs:12:12 + | +LL | pub trait Bar { +LL | fn method(&self) {} + | ^^^^^^ = help: items from traits can only be used if the trait is in scope help: trait `Bar` which provides `method` is implemented but not in scope; perhaps you want to import it | @@ -62,11 +68,12 @@ error[E0599]: no method named `method` found for type `i32` in the current scope LL | 1i32.method(); | ^^^^^^ method not found in `i32` | - ::: $DIR/auxiliary/no_method_suggested_traits.rs:8:12 +note: the method is available on trait `PubPub` for `i32` + --> $DIR/auxiliary/no_method_suggested_traits.rs:8:12 | +LL | pub trait PubPub { LL | fn method(&self) {} - | ------ the method is available for `i32` here - | + | ^^^^^^ = help: items from traits can only be used if the trait is in scope help: trait `PubPub` which provides `method` is implemented but not in scope; perhaps you want to import it | @@ -79,11 +86,12 @@ error[E0599]: no method named `method` found for struct `Rc<&mut Box<&i32>>` in LL | std::rc::Rc::new(&mut Box::new(&1i32)).method(); | ^^^^^^ method not found in `Rc<&mut Box<&i32>>` | - ::: $DIR/auxiliary/no_method_suggested_traits.rs:8:12 +note: the method is available on trait `PubPub` for `Rc<&mut Box<&i32>>` + --> $DIR/auxiliary/no_method_suggested_traits.rs:8:12 | +LL | pub trait PubPub { LL | fn method(&self) {} - | ------ the method is available for `Rc<&mut Box<&i32>>` here - | + | ^^^^^^ = help: items from traits can only be used if the trait is in scope help: trait `PubPub` which provides `method` is implemented but not in scope; perhaps you want to import it | diff --git a/tests/ui/imports/issue-114682-3.stderr b/tests/ui/imports/issue-114682-3.stderr index 73267f35fe71c..0992b7d72d263 100644 --- a/tests/ui/imports/issue-114682-3.stderr +++ b/tests/ui/imports/issue-114682-3.stderr @@ -1,12 +1,15 @@ error[E0599]: no method named `ext` found for type `u8` in the current scope --> $DIR/issue-114682-3.rs:20:7 | -LL | fn ext(&self) {} - | --- the method is available for `u8` here -... LL | a.ext(); | ^^^ method not found in `u8` | +note: the method is available on trait `SettingsExt` for `u8` + --> $DIR/issue-114682-3.rs:10:12 + | +LL | pub trait SettingsExt { +LL | fn ext(&self) {} + | ^^^ = help: items from traits can only be used if the trait is in scope help: trait `SettingsExt` which provides `ext` is implemented but not in scope; perhaps you want to import it | diff --git a/tests/ui/imports/overlapping_pub_trait.stderr b/tests/ui/imports/overlapping_pub_trait.stderr index 19b47786ddd7d..4dfddaad1430a 100644 --- a/tests/ui/imports/overlapping_pub_trait.stderr +++ b/tests/ui/imports/overlapping_pub_trait.stderr @@ -4,11 +4,11 @@ error[E0599]: no method named `method` found for struct `S` in the current scope LL | S.method(); | ^^^^^^ method not found in `S` | - ::: $DIR/auxiliary/overlapping_pub_trait_source.rs:11:23 +note: the method is available on trait `Tr` for `S` + --> $DIR/auxiliary/overlapping_pub_trait_source.rs:11:23 | LL | pub trait Tr { fn method(&self); } - | ------ the method is available for `S` here - | + | ^^^^^^ = help: items from traits can only be used if the trait is in scope help: trait `Tr` which provides `method` is implemented but not in scope; perhaps you want to import it | diff --git a/tests/ui/imports/private-types-suggested-without-extern-crate-56175.stderr b/tests/ui/imports/private-types-suggested-without-extern-crate-56175.stderr index 2796eac4978ee..b585f629d39f2 100644 --- a/tests/ui/imports/private-types-suggested-without-extern-crate-56175.stderr +++ b/tests/ui/imports/private-types-suggested-without-extern-crate-56175.stderr @@ -4,11 +4,12 @@ error[E0599]: no method named `trait_method` found for struct `FooStruct` in the LL | reexported_trait::FooStruct.trait_method(); | ^^^^^^^^^^^^ | - ::: $DIR/auxiliary/reexported-trait-56175.rs:3:12 +note: the method is available on trait `Trait` for `FooStruct` + --> $DIR/auxiliary/reexported-trait-56175.rs:3:12 | +LL | pub trait Trait { LL | fn trait_method(&self) { - | ------------ the method is available for `FooStruct` here - | + | ^^^^^^^^^^^^ = help: items from traits can only be used if the trait is in scope help: trait `Trait` which provides `trait_method` is implemented but not in scope; perhaps you want to import it | @@ -25,11 +26,12 @@ error[E0599]: no method named `trait_method_b` found for struct `FooStruct` in t LL | reexported_trait::FooStruct.trait_method_b(); | ^^^^^^^^^^^^^^ | - ::: $DIR/auxiliary/reexported-trait-56175.rs:7:12 +note: the method is available on trait `TraitB` for `FooStruct` + --> $DIR/auxiliary/reexported-trait-56175.rs:7:12 | +LL | pub trait TraitB { LL | fn trait_method_b(&self) { - | -------------- the method is available for `FooStruct` here - | + | ^^^^^^^^^^^^^^ = help: items from traits can only be used if the trait is in scope help: trait `TraitB` which provides `trait_method_b` is implemented but not in scope; perhaps you want to import it | diff --git a/tests/ui/imports/unnamed_pub_trait.stderr b/tests/ui/imports/unnamed_pub_trait.stderr index 6db4399829ff3..3235f6c7defa4 100644 --- a/tests/ui/imports/unnamed_pub_trait.stderr +++ b/tests/ui/imports/unnamed_pub_trait.stderr @@ -4,11 +4,11 @@ error[E0599]: no method named `method` found for struct `S` in the current scope LL | S.method(); | ^^^^^^ method not found in `S` | - ::: $DIR/auxiliary/unnamed_pub_trait_source.rs:7:23 +note: the method is available on trait `Tr` for `S` + --> $DIR/auxiliary/unnamed_pub_trait_source.rs:7:23 | LL | pub trait Tr { fn method(&self); } - | ------ the method is available for `S` here - | + | ^^^^^^ = help: items from traits can only be used if the trait is in scope help: trait `Tr` which provides `method` is implemented but not in scope; perhaps you want to import it | diff --git a/tests/ui/macros/missing-writer-issue-139830.stderr b/tests/ui/macros/missing-writer-issue-139830.stderr index 3f5172eacab94..5c3a4c7ae290f 100644 --- a/tests/ui/macros/missing-writer-issue-139830.stderr +++ b/tests/ui/macros/missing-writer-issue-139830.stderr @@ -4,14 +4,13 @@ error[E0599]: cannot write into `String` LL | let _ = write!(buf, "foo"); | -------^^^-------- method not found in `String` | - --> $SRC_DIR/core/src/fmt/mod.rs:LL:COL - | - = note: the method is available for `String` here note: must implement `io::Write`, `fmt::Write`, or have a `write_fmt` method --> $DIR/missing-writer-issue-139830.rs:7:20 | LL | let _ = write!(buf, "foo"); | ^^^ +note: the method is available on trait `Write` for `String` + --> $SRC_DIR/core/src/fmt/mod.rs:LL:COL = help: items from traits can only be used if the trait is in scope help: trait `Write` which provides `write_fmt` is implemented but not in scope; perhaps you want to import it | diff --git a/tests/ui/methods/method-suggestion-trait-with-extra-generics-no-ice.stderr b/tests/ui/methods/method-suggestion-trait-with-extra-generics-no-ice.stderr index e4e595803b26f..58a5eeb8c5883 100644 --- a/tests/ui/methods/method-suggestion-trait-with-extra-generics-no-ice.stderr +++ b/tests/ui/methods/method-suggestion-trait-with-extra-generics-no-ice.stderr @@ -4,10 +4,8 @@ error[E0599]: no method named `borrow` found for struct `Box usi LL | foo.borrow(); | ^^^^^^ | +note: the method is available on trait `Borrow` for `Box usize>` --> $SRC_DIR/core/src/borrow.rs:LL:COL - | - = note: the method is available for `Box usize>` here - | = help: items from traits can only be used if the trait is in scope help: use parentheses to call this trait object | diff --git a/tests/ui/methods/rigid-alias-bound-is-not-inherent-2.stderr b/tests/ui/methods/rigid-alias-bound-is-not-inherent-2.stderr index 3920d56a6ee30..ede088a679381 100644 --- a/tests/ui/methods/rigid-alias-bound-is-not-inherent-2.stderr +++ b/tests/ui/methods/rigid-alias-bound-is-not-inherent-2.stderr @@ -1,14 +1,17 @@ error[E0599]: no method named `method` found for type parameter `impl Deref` in the current scope --> $DIR/rigid-alias-bound-is-not-inherent-2.rs:14:7 | -LL | fn method(&self); - | ------ the method is available for `impl Deref` here -... LL | fn foo(x: impl Deref) { | --------------------------------- method `method` not found for this type parameter LL | x.method(); | ^^^^^^ method not found in `impl Deref` | +note: the method is available on trait `Trait` for `impl Deref` + --> $DIR/rigid-alias-bound-is-not-inherent-2.rs:6:12 + | +LL | pub trait Trait { +LL | fn method(&self); + | ^^^^^^ = help: items from traits can only be used if the trait is in scope help: trait `Trait` which provides `method` is implemented but not in scope; perhaps you want to import it | diff --git a/tests/ui/methods/similar-method-out-of-scope-trait.stderr b/tests/ui/methods/similar-method-out-of-scope-trait.stderr index 02bad55825518..55ff3f39d78f5 100644 --- a/tests/ui/methods/similar-method-out-of-scope-trait.stderr +++ b/tests/ui/methods/similar-method-out-of-scope-trait.stderr @@ -28,12 +28,16 @@ error[E0599]: no method named `write_all` found for struct `Writer` in the curre LL | pub struct Writer; | ----------------- method `write_all` not found for this struct ... -LL | fn write_all(&self) {} - | --------- the method is available for `Writer` here -... LL | writer.write_all(); | ^^^^^^^^^ method not found in `Writer` | +note: the method is available on trait `Write` for `Writer` + --> $DIR/similar-method-out-of-scope-trait.rs:8:12 + | +LL | pub trait Write { +LL | fn write(&self) {} +LL | fn write_all(&self) {} + | ^^^^^^^^^ = help: items from traits can only be used if the trait is in scope help: trait `Write` which provides `write_all` is implemented but not in scope; perhaps you want to import it | @@ -75,12 +79,15 @@ error[E0599]: no method named `method` found for struct `ByValue` in the current LL | pub struct ByValue; | ------------------ method `method` not found for this struct ... -LL | fn method(&self) {} - | ------ the method is available for `ByValue` here -... LL | hidden::ByValue.method(); | ^^^^^^ | +note: the method is available on trait `Hidden` for `ByValue` + --> $DIR/similar-method-out-of-scope-trait.rs:51:12 + | +LL | pub trait Hidden { +LL | fn method(&self) {} + | ^^^^^^ = help: items from traits can only be used if the trait is in scope help: trait `Hidden` which provides `method` is implemented but not in scope; perhaps you want to import it | @@ -97,12 +104,15 @@ error[E0599]: no method named `method` found for struct `Ambiguous` in the curre LL | pub struct Ambiguous; | -------------------- method `method` not found for this struct ... -LL | fn method(&self) {} - | ------ the method is available for `Ambiguous` here -... LL | hidden::Ambiguous.method(); | ^^^^^^ | +note: the method is available on trait `HiddenRef` for `Ambiguous` + --> $DIR/similar-method-out-of-scope-trait.rs:63:12 + | +LL | pub trait HiddenRef { +LL | fn method(&self) {} + | ^^^^^^ = help: items from traits can only be used if the trait is in scope help: trait `HiddenRef` which provides `method` is implemented but not in scope; perhaps you want to import it | @@ -119,12 +129,15 @@ error[E0599]: no method named `method` found for struct `Inherent` in the curren LL | pub struct Inherent; | ------------------- method `method` not found for this struct ... -LL | fn method(&self) {} - | ------ the method is available for `Inherent` here -... LL | hidden::Inherent.method(); | ^^^^^^ | +note: the method is available on trait `Hidden` for `Inherent` + --> $DIR/similar-method-out-of-scope-trait.rs:51:12 + | +LL | pub trait Hidden { +LL | fn method(&self) {} + | ^^^^^^ = help: items from traits can only be used if the trait is in scope help: trait `Hidden` which provides `method` is implemented but not in scope; perhaps you want to import it | diff --git a/tests/ui/rust-2018/trait-import-suggestions.stderr b/tests/ui/rust-2018/trait-import-suggestions.stderr index 721ba0c50d783..6614a36050af1 100644 --- a/tests/ui/rust-2018/trait-import-suggestions.stderr +++ b/tests/ui/rust-2018/trait-import-suggestions.stderr @@ -1,12 +1,15 @@ error[E0599]: no method named `foobar` found for type `u32` in the current scope --> $DIR/trait-import-suggestions.rs:22:11 | -LL | fn foobar(&self) { } - | ------ the method is available for `u32` here -... LL | x.foobar(); | ^^^^^^ | +note: the method is available on trait `Foobar` for `u32` + --> $DIR/trait-import-suggestions.rs:8:16 + | +LL | pub(crate) trait Foobar { +LL | fn foobar(&self) { } + | ^^^^^^ = help: items from traits can only be used if the trait is in scope help: trait `Foobar` which provides `foobar` is implemented but not in scope; perhaps you want to import it | @@ -21,12 +24,15 @@ LL + x.bar(); error[E0599]: no method named `bar` found for type `u32` in the current scope --> $DIR/trait-import-suggestions.rs:28:7 | -LL | fn bar(&self) { } - | --- the method is available for `u32` here -... LL | x.bar(); | ^^^ | +note: the method is available on trait `Bar` for `u32` + --> $DIR/trait-import-suggestions.rs:15:12 + | +LL | pub(crate) trait Bar { +LL | fn bar(&self) { } + | ^^^ = help: items from traits can only be used if the trait is in scope help: trait `Bar` which provides `bar` is implemented but not in scope; perhaps you want to import it | diff --git a/tests/ui/shadowed/shadowed-trait-methods.stderr b/tests/ui/shadowed/shadowed-trait-methods.stderr index 6f42a7a975af7..0611b929bac4b 100644 --- a/tests/ui/shadowed/shadowed-trait-methods.stderr +++ b/tests/ui/shadowed/shadowed-trait-methods.stderr @@ -1,12 +1,14 @@ error[E0599]: no method named `f` found for unit type `()` in the current scope --> $DIR/shadowed-trait-methods.rs:14:8 | -LL | pub trait T { fn f(&self) {} } - | - the method is available for `()` here -... LL | ().f() | ^ method not found in `()` | +note: the method is available on trait `T` for `()` + --> $DIR/shadowed-trait-methods.rs:5:22 + | +LL | pub trait T { fn f(&self) {} } + | ^ = help: items from traits can only be used if the trait is in scope help: trait `T` which provides `f` is implemented but not in scope; perhaps you want to import it | diff --git a/tests/ui/suggestions/double-reference-ty-in-self-ty.stderr b/tests/ui/suggestions/double-reference-ty-in-self-ty.stderr index a718234241093..0f70693caebd5 100644 --- a/tests/ui/suggestions/double-reference-ty-in-self-ty.stderr +++ b/tests/ui/suggestions/double-reference-ty-in-self-ty.stderr @@ -4,12 +4,15 @@ error[E0599]: no method named `len` found for struct `A` in the current scope LL | struct A; | -------- method `len` not found for this struct ... -LL | fn len(self: &&A) {} - | --- the method is available for `&A` here -... LL | A.len(); | ^^^ method not found in `A` | +note: the method is available for `&A` + --> $DIR/double-reference-ty-in-self-ty.rs:6:8 + | +LL | impl A { +LL | fn len(self: &&A) {} + | ^^^ = help: items from traits can only be used if the trait is implemented and in scope = note: the following trait defines an item `len`, perhaps you need to implement it: candidate #1: `ExactSizeIterator` diff --git a/tests/ui/suggestions/import-trait-for-method-call.stderr b/tests/ui/suggestions/import-trait-for-method-call.stderr index 177ab76cd1f4f..346f03375ba67 100644 --- a/tests/ui/suggestions/import-trait-for-method-call.stderr +++ b/tests/ui/suggestions/import-trait-for-method-call.stderr @@ -4,10 +4,8 @@ error[E0599]: no method named `finish` found for struct `DefaultHasher` in the c LL | h.finish() | ^^^^^^ method not found in `DefaultHasher` | +note: the method is available on trait `Hasher` for `DefaultHasher` --> $SRC_DIR/core/src/hash/mod.rs:LL:COL - | - = note: the method is available for `DefaultHasher` here - | = help: items from traits can only be used if the trait is in scope help: trait `Hasher` which provides `finish` is implemented but not in scope; perhaps you want to import it | diff --git a/tests/ui/suggestions/import-visible-path-39175.stderr b/tests/ui/suggestions/import-visible-path-39175.stderr index b18db9fc96012..d9b5bd853df9e 100644 --- a/tests/ui/suggestions/import-visible-path-39175.stderr +++ b/tests/ui/suggestions/import-visible-path-39175.stderr @@ -4,10 +4,8 @@ error[E0599]: no method named `exec` found for mutable reference `&mut Command` LL | let _ = Command::new("echo").arg("hello").exec(); | ^^^^ method not found in `&mut Command` | +note: the method is available on trait `CommandExt` for `&mut Command` --> $SRC_DIR/std/src/os/unix/process.rs:LL:COL - | - = note: the method is available for `&mut Command` here - | = help: items from traits can only be used if the trait is in scope help: trait `CommandExt` which provides `exec` is implemented but not in scope; perhaps you want to import it | diff --git a/tests/ui/suggestions/suggest-tryinto-edition-change.rs b/tests/ui/suggestions/suggest-tryinto-edition-change.rs index 06675a8e530b8..7161d6fd96cd6 100644 --- a/tests/ui/suggestions/suggest-tryinto-edition-change.rs +++ b/tests/ui/suggestions/suggest-tryinto-edition-change.rs @@ -6,6 +6,7 @@ fn test() { let _i: i16 = 0_i32.try_into().unwrap(); //~^ ERROR no method named `try_into` found for type `i32` in the current scope //~| NOTE 'std::convert::TryInto' is included in the prelude starting in Edition 2021 + //~| NOTE the method is available on trait `TryInto` for `i32` let _i: i16 = TryFrom::try_from(0_i32).unwrap(); //~^ ERROR cannot find diff --git a/tests/ui/suggestions/suggest-tryinto-edition-change.stderr b/tests/ui/suggestions/suggest-tryinto-edition-change.stderr index b0d150f49c735..cb1e1cfdf8de0 100644 --- a/tests/ui/suggestions/suggest-tryinto-edition-change.stderr +++ b/tests/ui/suggestions/suggest-tryinto-edition-change.stderr @@ -1,5 +1,5 @@ error[E0433]: cannot find type `TryFrom` in this scope - --> $DIR/suggest-tryinto-edition-change.rs:10:19 + --> $DIR/suggest-tryinto-edition-change.rs:11:19 | LL | let _i: i16 = TryFrom::try_from(0_i32).unwrap(); | ^^^^^^^ use of undeclared type `TryFrom` @@ -11,7 +11,7 @@ LL + use std::convert::TryFrom; | error[E0433]: cannot find type `TryInto` in this scope - --> $DIR/suggest-tryinto-edition-change.rs:15:19 + --> $DIR/suggest-tryinto-edition-change.rs:16:19 | LL | let _i: i16 = TryInto::try_into(0_i32).unwrap(); | ^^^^^^^ use of undeclared type `TryInto` @@ -23,7 +23,7 @@ LL + use std::convert::TryInto; | error[E0433]: cannot find type `FromIterator` in this scope - --> $DIR/suggest-tryinto-edition-change.rs:20:22 + --> $DIR/suggest-tryinto-edition-change.rs:21:22 | LL | let _v: Vec<_> = FromIterator::from_iter(&[1]); | ^^^^^^^^^^^^ use of undeclared type `FromIterator` @@ -45,10 +45,8 @@ error[E0599]: no method named `try_into` found for type `i32` in the current sco LL | let _i: i16 = 0_i32.try_into().unwrap(); | ^^^^^^^^ | +note: the method is available on trait `TryInto` for `i32` --> $SRC_DIR/core/src/convert/mod.rs:LL:COL - | - = note: the method is available for `i32` here - | = help: items from traits can only be used if the trait is in scope = note: 'std::convert::TryInto' is included in the prelude starting in Edition 2021 help: trait `TryInto` which provides `try_into` is implemented but not in scope; perhaps you want to import it diff --git a/tests/ui/suggestions/use-placement-typeck.stderr b/tests/ui/suggestions/use-placement-typeck.stderr index 58d499a48582a..a3861ea68f751 100644 --- a/tests/ui/suggestions/use-placement-typeck.stderr +++ b/tests/ui/suggestions/use-placement-typeck.stderr @@ -4,12 +4,15 @@ error[E0599]: no method named `abc` found for struct `S` in the current scope LL | s.abc(); | ^^^ method not found in `S` ... -LL | fn abc(&self) {} - | --- the method is available for `S` here -LL | } LL | pub struct S; | ------------ method `abc` not found for this struct | +note: the method is available on trait `Foo` for `S` + --> $DIR/use-placement-typeck.rs:17:12 + | +LL | pub trait Foo { +LL | fn abc(&self) {} + | ^^^ = help: items from traits can only be used if the trait is in scope help: trait `Foo` which provides `abc` is implemented but not in scope; perhaps you want to import it | diff --git a/tests/ui/traits/block-scoped-trait-import-issue-134146.stderr b/tests/ui/traits/block-scoped-trait-import-issue-134146.stderr index 48c0a5c1dfe9e..816c9fab0e22e 100644 --- a/tests/ui/traits/block-scoped-trait-import-issue-134146.stderr +++ b/tests/ui/traits/block-scoped-trait-import-issue-134146.stderr @@ -1,12 +1,15 @@ error[E0599]: no method named `hello` found for unit type `()` in the current scope --> $DIR/block-scoped-trait-import-issue-134146.rs:16:8 | -LL | fn hello(&self) { - | ----- the method is available for `()` here -... LL | ().hello(); | ^^^^^ method not found in `()` | +note: the method is available on trait `Hello` for `()` + --> $DIR/block-scoped-trait-import-issue-134146.rs:9:16 + | +LL | trait Hello { +LL | fn hello(&self) { + | ^^^^^ = help: items from traits can only be used if the trait is in scope help: trait `crate::main::Hello` which provides `hello` is implemented but not reachable --> $DIR/block-scoped-trait-import-issue-134146.rs:8:9 @@ -17,12 +20,15 @@ LL | trait Hello { error[E0599]: no method named `nested` found for unit type `()` in the current scope --> $DIR/block-scoped-trait-import-issue-134146.rs:30:8 | -LL | fn nested(&self) {} - | ------ the method is available for `()` here -... LL | ().nested(); | ^^^^^^ method not found in `()` | +note: the method is available on trait `Nested` for `()` + --> $DIR/block-scoped-trait-import-issue-134146.rs:23:16 + | +LL | pub trait Nested { +LL | fn nested(&self) {} + | ^^^^^^ = help: items from traits can only be used if the trait is in scope help: trait `crate::nested_module::inner::Nested` which provides `nested` is implemented but not reachable --> $DIR/block-scoped-trait-import-issue-134146.rs:22:9 @@ -33,12 +39,15 @@ LL | pub trait Nested { error[E0599]: no method named `in_const` found for unit type `()` in the current scope --> $DIR/block-scoped-trait-import-issue-134146.rs:42:8 | -LL | fn in_const(&self) {} - | -------- the method is available for `()` here -... LL | ().in_const(); | ^^^^^^^^ method not found in `()` | +note: the method is available on trait `InConst` for `()` + --> $DIR/block-scoped-trait-import-issue-134146.rs:36:12 + | +LL | trait InConst { +LL | fn in_const(&self) {} + | ^^^^^^^^ = help: items from traits can only be used if the trait is in scope help: trait `crate::_::InConst` which provides `in_const` is implemented but not reachable --> $DIR/block-scoped-trait-import-issue-134146.rs:35:5 diff --git a/tests/ui/traits/item-privacy.stderr b/tests/ui/traits/item-privacy.stderr index baec52e4fccd1..224b4801472cb 100644 --- a/tests/ui/traits/item-privacy.stderr +++ b/tests/ui/traits/item-privacy.stderr @@ -25,12 +25,15 @@ error[E0599]: no method named `b` found for struct `S` in the current scope LL | struct S; | -------- method `b` not found for this struct ... -LL | fn b(&self) { } - | - the method is available for `S` here -... LL | S.b(); | ^ | +note: the method is available on trait `B` for `S` + --> $DIR/item-privacy.rs:12:12 + | +LL | pub trait B { +LL | fn b(&self) { } + | ^ = help: items from traits can only be used if the trait is in scope help: trait `B` which provides `b` is implemented but not in scope; perhaps you want to import it | diff --git a/tests/ui/traits/nested-mod-trait-method-lookup-leak-10465.stderr b/tests/ui/traits/nested-mod-trait-method-lookup-leak-10465.stderr index cfa9357c063d8..01805fc8fe5f4 100644 --- a/tests/ui/traits/nested-mod-trait-method-lookup-leak-10465.stderr +++ b/tests/ui/traits/nested-mod-trait-method-lookup-leak-10465.stderr @@ -1,12 +1,15 @@ error[E0599]: no method named `foo` found for reference `&B` in the current scope --> $DIR/nested-mod-trait-method-lookup-leak-10465.rs:20:15 | -LL | fn foo(&self); - | --- the method is available for `&B` here -... LL | b.foo(); | ^^^ method not found in `&B` | +note: the method is available on trait `A` for `&B` + --> $DIR/nested-mod-trait-method-lookup-leak-10465.rs:6:12 + | +LL | pub trait A { +LL | fn foo(&self); + | ^^^ = help: items from traits can only be used if the trait is in scope help: trait `A` which provides `foo` is implemented but not in scope; perhaps you want to import it | diff --git a/tests/ui/typeck/issue-43189.stderr b/tests/ui/typeck/issue-43189.stderr index b3f2d1e9aa661..5eff53bf9ee11 100644 --- a/tests/ui/typeck/issue-43189.stderr +++ b/tests/ui/typeck/issue-43189.stderr @@ -4,11 +4,12 @@ error[E0599]: no method named `a` found for unit type `()` in the current scope LL | ().a(); | ^ method not found in `()` | - ::: $DIR/auxiliary/xcrate-issue-43189-a.rs:5:8 +note: the method is available on trait `A` for `()` + --> $DIR/auxiliary/xcrate-issue-43189-a.rs:5:8 | +LL | pub trait A { LL | fn a(&self) {} - | - the method is available for `()` here - | + | ^ = help: items from traits can only be used if the trait is in scope help: trait `A` which provides `a` is implemented but not in scope; perhaps you want to import it | From eb545c5a4e347f3e6aaa89eafeedd5e2ccca0329 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Fri, 13 Nov 2026 23:19:17 +0000 Subject: [PATCH 07/11] Point at `impl` where method is available ``` error[E0599]: no method named `qwer` found for struct `S` in the current scope --> $DIR/use-placement-typeck.rs:13:7 | LL | s.qwer(); | ^^^^ method not found in `S` ... LL | pub struct S; | ------------ method `qwer` not found for this struct | note: the method is available on trait `Bar` for `S` --> $DIR/use-placement-typeck.rs:26:9 | LL | impl Bar for S { LL | fn qwer(&self) {} | ^^^^^^^^^^^^^^ the method is available here = help: items from traits can only be used if the trait is in scope help: trait `Bar` which provides `qwer` is implemented but not in scope; perhaps you want to import it | LL + use crate::m::Bar; | ``` --- .../rustc_hir_typeck/src/method/suggest.rs | 71 +++++++++++++++++-- ...project-to-specializable-projection.stderr | 2 + tests/ui/coherence/coherence_inherent.stderr | 4 +- .../ui/coherence/coherence_inherent_cc.stderr | 4 +- tests/ui/hygiene/trait_items.stderr | 7 +- ...od_on_inherent_impl_ref-err.current.stderr | 13 ++-- ...ethod_on_inherent_impl_ref-err.next.stderr | 13 ++-- ...all_method_without_import.no_import.stderr | 2 + .../no-method-suggested-traits.stderr | 22 +++--- tests/ui/imports/issue-114682-3.stderr | 7 +- tests/ui/imports/overlapping_pub_trait.stderr | 6 +- ...uggested-without-extern-crate-56175.stderr | 14 ++-- tests/ui/imports/unnamed_pub_trait.stderr | 6 +- .../macros/missing-writer-issue-139830.stderr | 5 ++ ...on-trait-with-extra-generics-no-ice.stderr | 2 + ...rigid-alias-bound-is-not-inherent-2.stderr | 4 +- .../similar-method-out-of-scope-trait.stderr | 28 +++++--- .../rust-2018/trait-import-suggestions.stderr | 14 ++-- .../ui/shadowed/shadowed-trait-methods.stderr | 6 +- .../double-reference-ty-in-self-ty.stderr | 4 +- .../import-trait-for-method-call.stderr | 4 +- .../import-visible-path-39175.stderr | 4 +- .../suggest-tryinto-edition-change.stderr | 2 + .../ui/suggestions/use-placement-typeck.fixed | 10 ++- tests/ui/suggestions/use-placement-typeck.rs | 9 ++- .../suggestions/use-placement-typeck.stderr | 30 +++++++- ...ck-scoped-trait-import-issue-134146.stderr | 21 ++++-- tests/ui/traits/item-privacy.stderr | 7 +- ...-mod-trait-method-lookup-leak-10465.stderr | 4 +- tests/ui/typeck/issue-43189.stderr | 7 +- 30 files changed, 253 insertions(+), 79 deletions(-) diff --git a/compiler/rustc_hir_typeck/src/method/suggest.rs b/compiler/rustc_hir_typeck/src/method/suggest.rs index c2fa937a14d27..fb0dd0c284ec8 100644 --- a/compiler/rustc_hir_typeck/src/method/suggest.rs +++ b/compiler/rustc_hir_typeck/src/method/suggest.rs @@ -24,6 +24,7 @@ use rustc_hir::def_id::DefId; use rustc_hir::intravisit::{self, Visitor}; use rustc_hir::{self as hir, ExprKind, HirId, Node, PathSegment, QPath, is_range_literal}; use rustc_infer::infer::{BoundRegionConversionTime, RegionVariableOrigin}; +use rustc_infer::traits::ImplSource; use rustc_middle::ty::fast_reject::{DeepRejectCtxt, TreatParams, simplify_type}; use rustc_middle::ty::print::{ PrintTraitRefExt as _, with_crate_prefix, with_forced_trimmed_paths, @@ -39,7 +40,8 @@ use rustc_trait_selection::error_reporting::traits::DefIdOrName; use rustc_trait_selection::infer::InferCtxtExt; use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt as _; use rustc_trait_selection::traits::{ - FulfillmentError, Obligation, ObligationCauseCode, supertraits, + FulfillmentError, Obligation, ObligationCause, ObligationCauseCode, SelectionContext, + supertraits, }; use tracing::{debug, info, instrument}; @@ -4245,17 +4247,74 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { if !trait_in_other_version_found { let sp = pick.item.ident(self.tcx).span; let mut span: MultiSpan = sp.into(); - span.push_span_context( - self.tcx - .def_span(pick.item.container_id(self.tcx)) - .shrink_to_lo(), - ); + let mut pointing_at_method = false; let mut on_trait = String::new(); if self.tcx.def_kind(did) == DefKind::Trait { let name = self.tcx.item_name(did); on_trait = format!("on trait `{name}` "); + let result = self.probe(|_| { + let trait_ref = ty::TraitRef::new( + self.tcx, + did, + ty::GenericArgs::for_item(self.tcx, did, |param, _| { + if param.index == 0 { + (*rcvr_ty).into() + } else { + self.var_for_def(rcvr.span, param) + } + }), + ); + let obligation = Obligation::new( + self.tcx, + ObligationCause::dummy(), + self.param_env, + trait_ref, + ); + SelectionContext::new(self).select(&obligation) + }); + if let Ok(Some(ImplSource::UserDefined(source))) = result { + let impl_sp = self.tcx.def_span(source.impl_def_id); + + if let Some(assoc) = self + .tcx + .associated_items(source.impl_def_id) + .filter_by_name_unhygienic(item_name.name) + .next() + { + pointing_at_method = true; + let assoc_sp = self.tcx.def_span(assoc.def_id); + span = assoc_sp.into(); + span.push_span_label( + assoc_sp, + "the method is available here", + ); + span.push_span_context(impl_sp); + } else { + span = impl_sp.into(); + span.push_span_label( + impl_sp, + "the trait is implemented here", + ); + } + } + } + + if !pointing_at_method { + span.push_span_context( + self.tcx + .def_span(pick.item.container_id(self.tcx)) + .shrink_to_lo(), + ); + span.push_span_label(sp, "the method is available here"); } + + // If the method is available through an auto-deref, then we will be + // pointing only at the trait and the method therein, not the `impl`, as + // it will not be found in the logic above. + + let rcvr_ty = + self.tcx.short_string(pick.self_ty.peel_refs(), err.long_ty_path()); err.span_note( span, format!("the method is available {on_trait}for `{rcvr_ty}`"), diff --git a/tests/ui/async-await/in-trait/dont-project-to-specializable-projection.stderr b/tests/ui/async-await/in-trait/dont-project-to-specializable-projection.stderr index 4a27fed830c61..cc6466880b67c 100644 --- a/tests/ui/async-await/in-trait/dont-project-to-specializable-projection.stderr +++ b/tests/ui/async-await/in-trait/dont-project-to-specializable-projection.stderr @@ -36,6 +36,8 @@ note: you might have meant to call `std::convert::AsMut::as_mut` instead --> $SRC_DIR/core/src/convert/mod.rs:LL:COL note: the method is available on trait `Future` for `Pin<&mut impl Future>` --> $SRC_DIR/core/src/future/future.rs:LL:COL + | + = note: the method is available here = help: items from traits can only be used if the trait is in scope help: consider calling `std::convert::AsMut::as_mut` using the fully-qualified path | diff --git a/tests/ui/coherence/coherence_inherent.stderr b/tests/ui/coherence/coherence_inherent.stderr index 77b60e19f4afb..e314fedda8648 100644 --- a/tests/ui/coherence/coherence_inherent.stderr +++ b/tests/ui/coherence/coherence_inherent.stderr @@ -4,12 +4,12 @@ error[E0599]: no method named `the_fn` found for reference `&TheStruct` in the c LL | s.the_fn(); | ^^^^^^ method not found in `&TheStruct` | -note: the method is available on trait `TheTrait` for `&TheStruct` +note: the method is available on trait `TheTrait` for `TheStruct` --> $DIR/coherence_inherent.rs:7:12 | LL | pub trait TheTrait { LL | fn the_fn(&self); - | ^^^^^^ + | ^^^^^^ the method is available here = help: items from traits can only be used if the trait is in scope help: trait `TheTrait` which provides `the_fn` is implemented but not in scope; perhaps you want to import it | diff --git a/tests/ui/coherence/coherence_inherent_cc.stderr b/tests/ui/coherence/coherence_inherent_cc.stderr index 1a1384bb22caf..353334a7ebe0f 100644 --- a/tests/ui/coherence/coherence_inherent_cc.stderr +++ b/tests/ui/coherence/coherence_inherent_cc.stderr @@ -4,12 +4,12 @@ error[E0599]: no method named `the_fn` found for reference `&TheStruct` in the c LL | s.the_fn(); | ^^^^^^ method not found in `&TheStruct` | -note: the method is available on trait `TheTrait` for `&TheStruct` +note: the method is available on trait `TheTrait` for `TheStruct` --> $DIR/auxiliary/coherence_inherent_cc_lib.rs:4:8 | LL | pub trait TheTrait { LL | fn the_fn(&self); - | ^^^^^^ + | ^^^^^^ the method is available here = help: items from traits can only be used if the trait is in scope help: trait `TheTrait` which provides `the_fn` is implemented but not in scope; perhaps you want to import it | diff --git a/tests/ui/hygiene/trait_items.stderr b/tests/ui/hygiene/trait_items.stderr index 3e1c33f9049c3..d8cb0bfaf2ba6 100644 --- a/tests/ui/hygiene/trait_items.stderr +++ b/tests/ui/hygiene/trait_items.stderr @@ -8,11 +8,14 @@ LL | pub macro m() { ().f() } | ^ method not found in `()` | note: the method is available on trait `T` for `()` - --> $DIR/trait_items.rs:6:12 + --> $DIR/trait_items.rs:8:5 | LL | pub trait T { LL | fn f(&self) {} - | ^ + | - the method is available here +LL | } +LL | impl T for () {} + | ^^^^^^^^^^^^^ the trait is implemented here = help: items from traits can only be used if the trait is in scope help: trait `T` which provides `f` is implemented but not in scope; perhaps you want to import it | diff --git a/tests/ui/impl-trait/call_method_on_inherent_impl_ref-err.current.stderr b/tests/ui/impl-trait/call_method_on_inherent_impl_ref-err.current.stderr index b9f904dbf67f2..465b01d6eea7f 100644 --- a/tests/ui/impl-trait/call_method_on_inherent_impl_ref-err.current.stderr +++ b/tests/ui/impl-trait/call_method_on_inherent_impl_ref-err.current.stderr @@ -4,12 +4,15 @@ error[E0599]: no method named `my_debug` found for opaque type `impl Debug` in t LL | x.my_debug(); | ^^^^^^^^ method not found in `impl Debug` | -note: the method is available on trait `MyDebug` for `&impl Debug` - --> $DIR/call_method_on_inherent_impl_ref-err.rs:6:8 +note: the method is available on trait `MyDebug` for `impl Debug` + --> $DIR/call_method_on_inherent_impl_ref-err.rs:13:5 | -LL | trait MyDebug { -LL | fn my_debug(&self); - | ^^^^^^^^ +LL | impl MyDebug for &T +LL | where +LL | T: std::fmt::Debug, +LL | { +LL | fn my_debug(&self) {} + | ^^^^^^^^^^^^^^^^^^ the method is available here = help: items from traits can only be used if the trait is implemented and in scope note: `MyDebug` defines an item `my_debug`, perhaps you need to implement it --> $DIR/call_method_on_inherent_impl_ref-err.rs:5:1 diff --git a/tests/ui/impl-trait/call_method_on_inherent_impl_ref-err.next.stderr b/tests/ui/impl-trait/call_method_on_inherent_impl_ref-err.next.stderr index 9bbb6ed6e8a48..62ac9594aea9d 100644 --- a/tests/ui/impl-trait/call_method_on_inherent_impl_ref-err.next.stderr +++ b/tests/ui/impl-trait/call_method_on_inherent_impl_ref-err.next.stderr @@ -4,12 +4,15 @@ error[E0599]: no method named `my_debug` found for type `_` in the current scope LL | x.my_debug(); | ^^^^^^^^ method not found in `_` | -note: the method is available on trait `MyDebug` for `&_` - --> $DIR/call_method_on_inherent_impl_ref-err.rs:6:8 +note: the method is available on trait `MyDebug` for `_` + --> $DIR/call_method_on_inherent_impl_ref-err.rs:13:5 | -LL | trait MyDebug { -LL | fn my_debug(&self); - | ^^^^^^^^ +LL | impl MyDebug for &T +LL | where +LL | T: std::fmt::Debug, +LL | { +LL | fn my_debug(&self) {} + | ^^^^^^^^^^^^^^^^^^ the method is available here = help: items from traits can only be used if the trait is implemented and in scope note: `MyDebug` defines an item `my_debug`, perhaps you need to implement it --> $DIR/call_method_on_inherent_impl_ref-err.rs:5:1 diff --git a/tests/ui/impl-trait/call_method_without_import.no_import.stderr b/tests/ui/impl-trait/call_method_without_import.no_import.stderr index e258bb69de2dd..184080a57338c 100644 --- a/tests/ui/impl-trait/call_method_without_import.no_import.stderr +++ b/tests/ui/impl-trait/call_method_without_import.no_import.stderr @@ -6,6 +6,8 @@ LL | x.fmt(f); | note: the method is available on trait `Debug` for `impl Debug` --> $SRC_DIR/core/src/fmt/mod.rs:LL:COL + | + = note: the method is available here = help: items from traits can only be used if the trait is in scope help: trait `Debug` which provides `fmt` is implemented but not in scope; perhaps you want to import it | diff --git a/tests/ui/impl-trait/no-method-suggested-traits.stderr b/tests/ui/impl-trait/no-method-suggested-traits.stderr index 765e834ef5697..a47f2dec4ec77 100644 --- a/tests/ui/impl-trait/no-method-suggested-traits.stderr +++ b/tests/ui/impl-trait/no-method-suggested-traits.stderr @@ -33,11 +33,14 @@ LL | 'a'.method(); | ^^^^^^ method not found in `char` | note: the method is available on trait `Bar` for `char` - --> $DIR/no-method-suggested-traits.rs:12:12 + --> $DIR/no-method-suggested-traits.rs:19:5 | LL | pub trait Bar { LL | fn method(&self) {} - | ^^^^^^ + | ------ the method is available here +... +LL | impl Bar for char {} + | ^^^^^^^^^^^^^^^^^ the trait is implemented here = help: items from traits can only be used if the trait is in scope help: trait `Bar` which provides `method` is implemented but not in scope; perhaps you want to import it | @@ -50,12 +53,12 @@ error[E0599]: no method named `method` found for struct `Rc<&mut Box<&char>>` in LL | std::rc::Rc::new(&mut Box::new(&'a')).method(); | ^^^^^^ method not found in `Rc<&mut Box<&char>>` | -note: the method is available on trait `Bar` for `Rc<&mut Box<&char>>` +note: the method is available on trait `Bar` for `char` --> $DIR/no-method-suggested-traits.rs:12:12 | LL | pub trait Bar { LL | fn method(&self) {} - | ^^^^^^ + | ^^^^^^ the method is available here = help: items from traits can only be used if the trait is in scope help: trait `Bar` which provides `method` is implemented but not in scope; perhaps you want to import it | @@ -69,11 +72,14 @@ LL | 1i32.method(); | ^^^^^^ method not found in `i32` | note: the method is available on trait `PubPub` for `i32` - --> $DIR/auxiliary/no_method_suggested_traits.rs:8:12 + --> $DIR/auxiliary/no_method_suggested_traits.rs:14:5 | LL | pub trait PubPub { LL | fn method(&self) {} - | ^^^^^^ + | ------ the method is available here +... +LL | impl PubPub for i32 {} + | ^^^^^^^^^^^^^^^^^^^ the trait is implemented here = help: items from traits can only be used if the trait is in scope help: trait `PubPub` which provides `method` is implemented but not in scope; perhaps you want to import it | @@ -86,12 +92,12 @@ error[E0599]: no method named `method` found for struct `Rc<&mut Box<&i32>>` in LL | std::rc::Rc::new(&mut Box::new(&1i32)).method(); | ^^^^^^ method not found in `Rc<&mut Box<&i32>>` | -note: the method is available on trait `PubPub` for `Rc<&mut Box<&i32>>` +note: the method is available on trait `PubPub` for `i32` --> $DIR/auxiliary/no_method_suggested_traits.rs:8:12 | LL | pub trait PubPub { LL | fn method(&self) {} - | ^^^^^^ + | ^^^^^^ the method is available here = help: items from traits can only be used if the trait is in scope help: trait `PubPub` which provides `method` is implemented but not in scope; perhaps you want to import it | diff --git a/tests/ui/imports/issue-114682-3.stderr b/tests/ui/imports/issue-114682-3.stderr index 0992b7d72d263..80e9e137d6ce7 100644 --- a/tests/ui/imports/issue-114682-3.stderr +++ b/tests/ui/imports/issue-114682-3.stderr @@ -5,11 +5,14 @@ LL | a.ext(); | ^^^ method not found in `u8` | note: the method is available on trait `SettingsExt` for `u8` - --> $DIR/issue-114682-3.rs:10:12 + --> $DIR/issue-114682-3.rs:13:5 | LL | pub trait SettingsExt { LL | fn ext(&self) {} - | ^^^ + | --- the method is available here +... +LL | impl SettingsExt for T {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^ the trait is implemented here = help: items from traits can only be used if the trait is in scope help: trait `SettingsExt` which provides `ext` is implemented but not in scope; perhaps you want to import it | diff --git a/tests/ui/imports/overlapping_pub_trait.stderr b/tests/ui/imports/overlapping_pub_trait.stderr index 4dfddaad1430a..2bbd9bd74de6c 100644 --- a/tests/ui/imports/overlapping_pub_trait.stderr +++ b/tests/ui/imports/overlapping_pub_trait.stderr @@ -5,10 +5,10 @@ LL | S.method(); | ^^^^^^ method not found in `S` | note: the method is available on trait `Tr` for `S` - --> $DIR/auxiliary/overlapping_pub_trait_source.rs:11:23 + --> $DIR/auxiliary/overlapping_pub_trait_source.rs:12:28 | -LL | pub trait Tr { fn method(&self); } - | ^^^^^^ +LL | impl Tr for crate::S { fn method(&self) {} } + | ^^^^^^^^^^^^^^^^ the method is available here = help: items from traits can only be used if the trait is in scope help: trait `Tr` which provides `method` is implemented but not in scope; perhaps you want to import it | diff --git a/tests/ui/imports/private-types-suggested-without-extern-crate-56175.stderr b/tests/ui/imports/private-types-suggested-without-extern-crate-56175.stderr index b585f629d39f2..ceb4d9f523232 100644 --- a/tests/ui/imports/private-types-suggested-without-extern-crate-56175.stderr +++ b/tests/ui/imports/private-types-suggested-without-extern-crate-56175.stderr @@ -5,11 +5,14 @@ LL | reexported_trait::FooStruct.trait_method(); | ^^^^^^^^^^^^ | note: the method is available on trait `Trait` for `FooStruct` - --> $DIR/auxiliary/reexported-trait-56175.rs:3:12 + --> $DIR/auxiliary/reexported-trait-56175.rs:14:1 | LL | pub trait Trait { LL | fn trait_method(&self) { - | ^^^^^^^^^^^^ + | ------------ the method is available here +... +LL | impl crate::private::Trait for FooStruct {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait is implemented here = help: items from traits can only be used if the trait is in scope help: trait `Trait` which provides `trait_method` is implemented but not in scope; perhaps you want to import it | @@ -27,11 +30,14 @@ LL | reexported_trait::FooStruct.trait_method_b(); | ^^^^^^^^^^^^^^ | note: the method is available on trait `TraitB` for `FooStruct` - --> $DIR/auxiliary/reexported-trait-56175.rs:7:12 + --> $DIR/auxiliary/reexported-trait-56175.rs:17:1 | LL | pub trait TraitB { LL | fn trait_method_b(&self) { - | ^^^^^^^^^^^^^^ + | -------------- the method is available here +... +LL | impl crate::private::TraitB for FooStruct {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait is implemented here = help: items from traits can only be used if the trait is in scope help: trait `TraitB` which provides `trait_method_b` is implemented but not in scope; perhaps you want to import it | diff --git a/tests/ui/imports/unnamed_pub_trait.stderr b/tests/ui/imports/unnamed_pub_trait.stderr index 3235f6c7defa4..a08b12122b45f 100644 --- a/tests/ui/imports/unnamed_pub_trait.stderr +++ b/tests/ui/imports/unnamed_pub_trait.stderr @@ -5,10 +5,10 @@ LL | S.method(); | ^^^^^^ method not found in `S` | note: the method is available on trait `Tr` for `S` - --> $DIR/auxiliary/unnamed_pub_trait_source.rs:7:23 + --> $DIR/auxiliary/unnamed_pub_trait_source.rs:8:28 | -LL | pub trait Tr { fn method(&self); } - | ^^^^^^ +LL | impl Tr for crate::S { fn method(&self) {} } + | ^^^^^^^^^^^^^^^^ the method is available here = help: items from traits can only be used if the trait is in scope help: trait `Tr` which provides `method` is implemented but not in scope; perhaps you want to import it | diff --git a/tests/ui/macros/missing-writer-issue-139830.stderr b/tests/ui/macros/missing-writer-issue-139830.stderr index 5c3a4c7ae290f..af76501907ad6 100644 --- a/tests/ui/macros/missing-writer-issue-139830.stderr +++ b/tests/ui/macros/missing-writer-issue-139830.stderr @@ -10,7 +10,12 @@ note: must implement `io::Write`, `fmt::Write`, or have a `write_fmt` method LL | let _ = write!(buf, "foo"); | ^^^ note: the method is available on trait `Write` for `String` + --> $SRC_DIR/alloc/src/string.rs:LL:COL + | + = note: the trait is implemented here --> $SRC_DIR/core/src/fmt/mod.rs:LL:COL + | + = note: the method is available here = help: items from traits can only be used if the trait is in scope help: trait `Write` which provides `write_fmt` is implemented but not in scope; perhaps you want to import it | diff --git a/tests/ui/methods/method-suggestion-trait-with-extra-generics-no-ice.stderr b/tests/ui/methods/method-suggestion-trait-with-extra-generics-no-ice.stderr index 58a5eeb8c5883..11cddc15ead45 100644 --- a/tests/ui/methods/method-suggestion-trait-with-extra-generics-no-ice.stderr +++ b/tests/ui/methods/method-suggestion-trait-with-extra-generics-no-ice.stderr @@ -6,6 +6,8 @@ LL | foo.borrow(); | note: the method is available on trait `Borrow` for `Box usize>` --> $SRC_DIR/core/src/borrow.rs:LL:COL + | + = note: the method is available here = help: items from traits can only be used if the trait is in scope help: use parentheses to call this trait object | diff --git a/tests/ui/methods/rigid-alias-bound-is-not-inherent-2.stderr b/tests/ui/methods/rigid-alias-bound-is-not-inherent-2.stderr index ede088a679381..9eb1fc7f5159c 100644 --- a/tests/ui/methods/rigid-alias-bound-is-not-inherent-2.stderr +++ b/tests/ui/methods/rigid-alias-bound-is-not-inherent-2.stderr @@ -6,12 +6,12 @@ LL | fn foo(x: impl Deref) { LL | x.method(); | ^^^^^^ method not found in `impl Deref` | -note: the method is available on trait `Trait` for `impl Deref` +note: the method is available on trait `Trait` for ` as Deref>::Target` --> $DIR/rigid-alias-bound-is-not-inherent-2.rs:6:12 | LL | pub trait Trait { LL | fn method(&self); - | ^^^^^^ + | ^^^^^^ the method is available here = help: items from traits can only be used if the trait is in scope help: trait `Trait` which provides `method` is implemented but not in scope; perhaps you want to import it | diff --git a/tests/ui/methods/similar-method-out-of-scope-trait.stderr b/tests/ui/methods/similar-method-out-of-scope-trait.stderr index 55ff3f39d78f5..caac1db637fe7 100644 --- a/tests/ui/methods/similar-method-out-of-scope-trait.stderr +++ b/tests/ui/methods/similar-method-out-of-scope-trait.stderr @@ -32,12 +32,15 @@ LL | writer.write_all(); | ^^^^^^^^^ method not found in `Writer` | note: the method is available on trait `Write` for `Writer` - --> $DIR/similar-method-out-of-scope-trait.rs:8:12 + --> $DIR/similar-method-out-of-scope-trait.rs:11:5 | LL | pub trait Write { LL | fn write(&self) {} LL | fn write_all(&self) {} - | ^^^^^^^^^ + | --------- the method is available here +... +LL | impl Write for Writer {} + | ^^^^^^^^^^^^^^^^^^^^^ the trait is implemented here = help: items from traits can only be used if the trait is in scope help: trait `Write` which provides `write_all` is implemented but not in scope; perhaps you want to import it | @@ -83,11 +86,14 @@ LL | hidden::ByValue.method(); | ^^^^^^ | note: the method is available on trait `Hidden` for `ByValue` - --> $DIR/similar-method-out-of-scope-trait.rs:51:12 + --> $DIR/similar-method-out-of-scope-trait.rs:59:5 | LL | pub trait Hidden { LL | fn method(&self) {} - | ^^^^^^ + | ------ the method is available here +... +LL | impl Hidden for ByValue {} + | ^^^^^^^^^^^^^^^^^^^^^^^ the trait is implemented here = help: items from traits can only be used if the trait is in scope help: trait `Hidden` which provides `method` is implemented but not in scope; perhaps you want to import it | @@ -108,11 +114,14 @@ LL | hidden::Ambiguous.method(); | ^^^^^^ | note: the method is available on trait `HiddenRef` for `Ambiguous` - --> $DIR/similar-method-out-of-scope-trait.rs:63:12 + --> $DIR/similar-method-out-of-scope-trait.rs:67:5 | LL | pub trait HiddenRef { LL | fn method(&self) {} - | ^^^^^^ + | ------ the method is available here +... +LL | impl HiddenRef for Ambiguous {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait is implemented here = help: items from traits can only be used if the trait is in scope help: trait `HiddenRef` which provides `method` is implemented but not in scope; perhaps you want to import it | @@ -133,11 +142,14 @@ LL | hidden::Inherent.method(); | ^^^^^^ | note: the method is available on trait `Hidden` for `Inherent` - --> $DIR/similar-method-out-of-scope-trait.rs:51:12 + --> $DIR/similar-method-out-of-scope-trait.rs:60:5 | LL | pub trait Hidden { LL | fn method(&self) {} - | ^^^^^^ + | ------ the method is available here +... +LL | impl Hidden for Inherent {} + | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait is implemented here = help: items from traits can only be used if the trait is in scope help: trait `Hidden` which provides `method` is implemented but not in scope; perhaps you want to import it | diff --git a/tests/ui/rust-2018/trait-import-suggestions.stderr b/tests/ui/rust-2018/trait-import-suggestions.stderr index 6614a36050af1..39141e68822b2 100644 --- a/tests/ui/rust-2018/trait-import-suggestions.stderr +++ b/tests/ui/rust-2018/trait-import-suggestions.stderr @@ -5,11 +5,14 @@ LL | x.foobar(); | ^^^^^^ | note: the method is available on trait `Foobar` for `u32` - --> $DIR/trait-import-suggestions.rs:8:16 + --> $DIR/trait-import-suggestions.rs:11:9 | LL | pub(crate) trait Foobar { LL | fn foobar(&self) { } - | ^^^^^^ + | ------ the method is available here +... +LL | impl Foobar for u32 { } + | ^^^^^^^^^^^^^^^^^^^ the trait is implemented here = help: items from traits can only be used if the trait is in scope help: trait `Foobar` which provides `foobar` is implemented but not in scope; perhaps you want to import it | @@ -28,11 +31,14 @@ LL | x.bar(); | ^^^ | note: the method is available on trait `Bar` for `u32` - --> $DIR/trait-import-suggestions.rs:15:12 + --> $DIR/trait-import-suggestions.rs:18:5 | LL | pub(crate) trait Bar { LL | fn bar(&self) { } - | ^^^ + | --- the method is available here +... +LL | impl Bar for u32 { } + | ^^^^^^^^^^^^^^^^ the trait is implemented here = help: items from traits can only be used if the trait is in scope help: trait `Bar` which provides `bar` is implemented but not in scope; perhaps you want to import it | diff --git a/tests/ui/shadowed/shadowed-trait-methods.stderr b/tests/ui/shadowed/shadowed-trait-methods.stderr index 0611b929bac4b..1beb96168ee98 100644 --- a/tests/ui/shadowed/shadowed-trait-methods.stderr +++ b/tests/ui/shadowed/shadowed-trait-methods.stderr @@ -5,10 +5,12 @@ LL | ().f() | ^ method not found in `()` | note: the method is available on trait `T` for `()` - --> $DIR/shadowed-trait-methods.rs:5:22 + --> $DIR/shadowed-trait-methods.rs:6:5 | LL | pub trait T { fn f(&self) {} } - | ^ + | - the method is available here +LL | impl T for () {} + | ^^^^^^^^^^^^^ the trait is implemented here = help: items from traits can only be used if the trait is in scope help: trait `T` which provides `f` is implemented but not in scope; perhaps you want to import it | diff --git a/tests/ui/suggestions/double-reference-ty-in-self-ty.stderr b/tests/ui/suggestions/double-reference-ty-in-self-ty.stderr index 0f70693caebd5..bea8d8ea19dfb 100644 --- a/tests/ui/suggestions/double-reference-ty-in-self-ty.stderr +++ b/tests/ui/suggestions/double-reference-ty-in-self-ty.stderr @@ -7,12 +7,12 @@ LL | struct A; LL | A.len(); | ^^^ method not found in `A` | -note: the method is available for `&A` +note: the method is available for `A` --> $DIR/double-reference-ty-in-self-ty.rs:6:8 | LL | impl A { LL | fn len(self: &&A) {} - | ^^^ + | ^^^ the method is available here = help: items from traits can only be used if the trait is implemented and in scope = note: the following trait defines an item `len`, perhaps you need to implement it: candidate #1: `ExactSizeIterator` diff --git a/tests/ui/suggestions/import-trait-for-method-call.stderr b/tests/ui/suggestions/import-trait-for-method-call.stderr index 346f03375ba67..60b7488083a87 100644 --- a/tests/ui/suggestions/import-trait-for-method-call.stderr +++ b/tests/ui/suggestions/import-trait-for-method-call.stderr @@ -5,7 +5,9 @@ LL | h.finish() | ^^^^^^ method not found in `DefaultHasher` | note: the method is available on trait `Hasher` for `DefaultHasher` - --> $SRC_DIR/core/src/hash/mod.rs:LL:COL + --> $SRC_DIR/std/src/hash/random.rs:LL:COL + | + = note: the method is available here = help: items from traits can only be used if the trait is in scope help: trait `Hasher` which provides `finish` is implemented but not in scope; perhaps you want to import it | diff --git a/tests/ui/suggestions/import-visible-path-39175.stderr b/tests/ui/suggestions/import-visible-path-39175.stderr index d9b5bd853df9e..7b5f635aa3166 100644 --- a/tests/ui/suggestions/import-visible-path-39175.stderr +++ b/tests/ui/suggestions/import-visible-path-39175.stderr @@ -4,8 +4,10 @@ error[E0599]: no method named `exec` found for mutable reference `&mut Command` LL | let _ = Command::new("echo").arg("hello").exec(); | ^^^^ method not found in `&mut Command` | -note: the method is available on trait `CommandExt` for `&mut Command` +note: the method is available on trait `CommandExt` for `Command` --> $SRC_DIR/std/src/os/unix/process.rs:LL:COL + | + = note: the method is available here = help: items from traits can only be used if the trait is in scope help: trait `CommandExt` which provides `exec` is implemented but not in scope; perhaps you want to import it | diff --git a/tests/ui/suggestions/suggest-tryinto-edition-change.stderr b/tests/ui/suggestions/suggest-tryinto-edition-change.stderr index cb1e1cfdf8de0..21a136b7689ac 100644 --- a/tests/ui/suggestions/suggest-tryinto-edition-change.stderr +++ b/tests/ui/suggestions/suggest-tryinto-edition-change.stderr @@ -47,6 +47,8 @@ LL | let _i: i16 = 0_i32.try_into().unwrap(); | note: the method is available on trait `TryInto` for `i32` --> $SRC_DIR/core/src/convert/mod.rs:LL:COL + | + = note: the method is available here = help: items from traits can only be used if the trait is in scope = note: 'std::convert::TryInto' is included in the prelude starting in Edition 2021 help: trait `TryInto` which provides `try_into` is implemented but not in scope; perhaps you want to import it diff --git a/tests/ui/suggestions/use-placement-typeck.fixed b/tests/ui/suggestions/use-placement-typeck.fixed index 2ab00b28099a7..dcc9f787984a1 100644 --- a/tests/ui/suggestions/use-placement-typeck.fixed +++ b/tests/ui/suggestions/use-placement-typeck.fixed @@ -8,15 +8,23 @@ #![allow(unused)] use crate::m::Foo; +use crate::m::Bar; fn main() { let s = m::S; s.abc(); //~ ERROR no method named `abc` + s.qwer(); //~ ERROR no method named `qwer` } mod m { pub trait Foo { fn abc(&self) {} } + pub trait Bar{ + fn qwer(&self) {} + } pub struct S; - impl Foo for S{} + impl Foo for S {} + impl Bar for S { + fn qwer(&self) {} + } } diff --git a/tests/ui/suggestions/use-placement-typeck.rs b/tests/ui/suggestions/use-placement-typeck.rs index 05e2abe7b4d96..5c64b9a640daa 100644 --- a/tests/ui/suggestions/use-placement-typeck.rs +++ b/tests/ui/suggestions/use-placement-typeck.rs @@ -10,12 +10,19 @@ fn main() { let s = m::S; s.abc(); //~ ERROR no method named `abc` + s.qwer(); //~ ERROR no method named `qwer` } mod m { pub trait Foo { fn abc(&self) {} } + pub trait Bar{ + fn qwer(&self) {} + } pub struct S; - impl Foo for S{} + impl Foo for S {} + impl Bar for S { + fn qwer(&self) {} + } } diff --git a/tests/ui/suggestions/use-placement-typeck.stderr b/tests/ui/suggestions/use-placement-typeck.stderr index a3861ea68f751..492f8bec76a52 100644 --- a/tests/ui/suggestions/use-placement-typeck.stderr +++ b/tests/ui/suggestions/use-placement-typeck.stderr @@ -8,17 +8,41 @@ LL | pub struct S; | ------------ method `abc` not found for this struct | note: the method is available on trait `Foo` for `S` - --> $DIR/use-placement-typeck.rs:17:12 + --> $DIR/use-placement-typeck.rs:24:5 | LL | pub trait Foo { LL | fn abc(&self) {} - | ^^^ + | --- the method is available here +... +LL | impl Foo for S {} + | ^^^^^^^^^^^^^^ the trait is implemented here = help: items from traits can only be used if the trait is in scope help: trait `Foo` which provides `abc` is implemented but not in scope; perhaps you want to import it | LL + use crate::m::Foo; | -error: aborting due to 1 previous error +error[E0599]: no method named `qwer` found for struct `S` in the current scope + --> $DIR/use-placement-typeck.rs:13:7 + | +LL | s.qwer(); + | ^^^^ method not found in `S` +... +LL | pub struct S; + | ------------ method `qwer` not found for this struct + | +note: the method is available on trait `Bar` for `S` + --> $DIR/use-placement-typeck.rs:26:9 + | +LL | impl Bar for S { +LL | fn qwer(&self) {} + | ^^^^^^^^^^^^^^ the method is available here + = help: items from traits can only be used if the trait is in scope +help: trait `Bar` which provides `qwer` is implemented but not in scope; perhaps you want to import it + | +LL + use crate::m::Bar; + | + +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0599`. diff --git a/tests/ui/traits/block-scoped-trait-import-issue-134146.stderr b/tests/ui/traits/block-scoped-trait-import-issue-134146.stderr index 816c9fab0e22e..5f5464443f746 100644 --- a/tests/ui/traits/block-scoped-trait-import-issue-134146.stderr +++ b/tests/ui/traits/block-scoped-trait-import-issue-134146.stderr @@ -5,11 +5,14 @@ LL | ().hello(); | ^^^^^ method not found in `()` | note: the method is available on trait `Hello` for `()` - --> $DIR/block-scoped-trait-import-issue-134146.rs:9:16 + --> $DIR/block-scoped-trait-import-issue-134146.rs:13:9 | LL | trait Hello { LL | fn hello(&self) { - | ^^^^^ + | ----- the method is available here +... +LL | impl Hello for T {} + | ^^^^^^^^^^^^^^^^^^^ the trait is implemented here = help: items from traits can only be used if the trait is in scope help: trait `crate::main::Hello` which provides `hello` is implemented but not reachable --> $DIR/block-scoped-trait-import-issue-134146.rs:8:9 @@ -24,11 +27,14 @@ LL | ().nested(); | ^^^^^^ method not found in `()` | note: the method is available on trait `Nested` for `()` - --> $DIR/block-scoped-trait-import-issue-134146.rs:23:16 + --> $DIR/block-scoped-trait-import-issue-134146.rs:25:9 | LL | pub trait Nested { LL | fn nested(&self) {} - | ^^^^^^ + | ------ the method is available here +LL | } +LL | impl Nested for () {} + | ^^^^^^^^^^^^^^^^^^ the trait is implemented here = help: items from traits can only be used if the trait is in scope help: trait `crate::nested_module::inner::Nested` which provides `nested` is implemented but not reachable --> $DIR/block-scoped-trait-import-issue-134146.rs:22:9 @@ -43,11 +49,14 @@ LL | ().in_const(); | ^^^^^^^^ method not found in `()` | note: the method is available on trait `InConst` for `()` - --> $DIR/block-scoped-trait-import-issue-134146.rs:36:12 + --> $DIR/block-scoped-trait-import-issue-134146.rs:38:5 | LL | trait InConst { LL | fn in_const(&self) {} - | ^^^^^^^^ + | -------- the method is available here +LL | } +LL | impl InConst for () {} + | ^^^^^^^^^^^^^^^^^^^ the trait is implemented here = help: items from traits can only be used if the trait is in scope help: trait `crate::_::InConst` which provides `in_const` is implemented but not reachable --> $DIR/block-scoped-trait-import-issue-134146.rs:35:5 diff --git a/tests/ui/traits/item-privacy.stderr b/tests/ui/traits/item-privacy.stderr index 224b4801472cb..32029fe68fbac 100644 --- a/tests/ui/traits/item-privacy.stderr +++ b/tests/ui/traits/item-privacy.stderr @@ -29,11 +29,14 @@ LL | S.b(); | ^ | note: the method is available on trait `B` for `S` - --> $DIR/item-privacy.rs:12:12 + --> $DIR/item-privacy.rs:20:5 | LL | pub trait B { LL | fn b(&self) { } - | ^ + | - the method is available here +... +LL | impl B for crate::S {} + | ^^^^^^^^^^^^^^^^^^^ the trait is implemented here = help: items from traits can only be used if the trait is in scope help: trait `B` which provides `b` is implemented but not in scope; perhaps you want to import it | diff --git a/tests/ui/traits/nested-mod-trait-method-lookup-leak-10465.stderr b/tests/ui/traits/nested-mod-trait-method-lookup-leak-10465.stderr index 01805fc8fe5f4..f2918ddac15ca 100644 --- a/tests/ui/traits/nested-mod-trait-method-lookup-leak-10465.stderr +++ b/tests/ui/traits/nested-mod-trait-method-lookup-leak-10465.stderr @@ -4,12 +4,12 @@ error[E0599]: no method named `foo` found for reference `&B` in the current scop LL | b.foo(); | ^^^ method not found in `&B` | -note: the method is available on trait `A` for `&B` +note: the method is available on trait `A` for `B` --> $DIR/nested-mod-trait-method-lookup-leak-10465.rs:6:12 | LL | pub trait A { LL | fn foo(&self); - | ^^^ + | ^^^ the method is available here = help: items from traits can only be used if the trait is in scope help: trait `A` which provides `foo` is implemented but not in scope; perhaps you want to import it | diff --git a/tests/ui/typeck/issue-43189.stderr b/tests/ui/typeck/issue-43189.stderr index 5eff53bf9ee11..ec44978fd117c 100644 --- a/tests/ui/typeck/issue-43189.stderr +++ b/tests/ui/typeck/issue-43189.stderr @@ -5,11 +5,14 @@ LL | ().a(); | ^ method not found in `()` | note: the method is available on trait `A` for `()` - --> $DIR/auxiliary/xcrate-issue-43189-a.rs:5:8 + --> $DIR/auxiliary/xcrate-issue-43189-a.rs:7:1 | LL | pub trait A { LL | fn a(&self) {} - | ^ + | - the method is available here +LL | } +LL | impl A for () {} + | ^^^^^^^^^^^^^ the trait is implemented here = help: items from traits can only be used if the trait is in scope help: trait `A` which provides `a` is implemented but not in scope; perhaps you want to import it | From 4d860564cc8f6fe5b29559ecaccbc9d96bbc77fc Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 18 Nov 2026 11:58:57 +0100 Subject: [PATCH 08/11] Remove `#[allow(missing_docs)]` where possible --- .../alloc/src/collections/binary_heap/mod.rs | 2 +- library/alloc/src/io/buffered/bufreader.rs | 1 - library/core/src/alloc/layout.rs | 1 + library/core/src/error.rs | 2 +- library/core/src/intrinsics/mod.rs | 6 +++++- library/core/src/lib.rs | 1 - library/core/src/panicking.rs | 17 ++++++++++------- library/std/src/net/tcp.rs | 8 ++++++-- library/std/src/num/f32.rs | 1 - library/std/src/num/f64.rs | 1 - library/std/src/num/mod.rs | 1 - library/std/src/sys/pal/unix/mod.rs | 2 +- 12 files changed, 25 insertions(+), 18 deletions(-) diff --git a/library/alloc/src/collections/binary_heap/mod.rs b/library/alloc/src/collections/binary_heap/mod.rs index 1d7e6ad89a469..2c69b40eb5394 100644 --- a/library/alloc/src/collections/binary_heap/mod.rs +++ b/library/alloc/src/collections/binary_heap/mod.rs @@ -140,7 +140,6 @@ //! } //! ``` -#![allow(missing_docs)] #![stable(feature = "rust1", since = "1.0.0")] use core::alloc::Allocator; @@ -1797,6 +1796,7 @@ unsafe impl AsVecIntoIter for IntoIter { } } +/// Iterator which retrieves elements in heap order. #[must_use = "iterators are lazy and do nothing unless consumed"] #[unstable(feature = "binary_heap_into_iter_sorted", issue = "59278")] #[derive(Clone, Debug)] diff --git a/library/alloc/src/io/buffered/bufreader.rs b/library/alloc/src/io/buffered/bufreader.rs index c911746c2a611..a6f264bf29646 100644 --- a/library/alloc/src/io/buffered/bufreader.rs +++ b/library/alloc/src/io/buffered/bufreader.rs @@ -299,7 +299,6 @@ impl BufReader { impl BufReader { #[doc(hidden)] #[unstable(feature = "core_io_internals", reason = "exposed only for libstd", issue = "none")] - #[allow(missing_docs)] pub fn initialized(&self) -> bool { self.buf.initialized() } diff --git a/library/core/src/alloc/layout.rs b/library/core/src/alloc/layout.rs index 31b20e5967270..2f4ce37e9e41d 100644 --- a/library/core/src/alloc/layout.rs +++ b/library/core/src/alloc/layout.rs @@ -600,6 +600,7 @@ impl Layout { note = "Name does not follow std convention, use LayoutError", suggestion = "LayoutError" )] +/// Old name of [`LayoutError`]. pub type LayoutErr = LayoutError; /// The `LayoutError` is returned when the parameters given diff --git a/library/core/src/error.rs b/library/core/src/error.rs index b6de3eb1b44e5..9504236cad2dc 100644 --- a/library/core/src/error.rs +++ b/library/core/src/error.rs @@ -143,7 +143,7 @@ pub trait Error: Debug + Display { since = "1.33.0", note = "replaced by Error::source, which can support downcasting" )] - #[allow(missing_docs)] + /// Replaced by [`Error::source`]. fn cause(&self) -> Option<&dyn Error> { self.source() } diff --git a/library/core/src/intrinsics/mod.rs b/library/core/src/intrinsics/mod.rs index 0a170fae1e186..5c20f4a93fb2e 100644 --- a/library/core/src/intrinsics/mod.rs +++ b/library/core/src/intrinsics/mod.rs @@ -103,15 +103,19 @@ use crate::sync::atomic::{ /// A type for atomic ordering parameters for intrinsics. This is a separate type from /// `atomic::Ordering` so that we can make it `ConstParamTy` and fix the values used here without a /// risk of leaking that to stable code. -#[allow(missing_docs)] #[derive(Debug, ConstParamTy, PartialEq, Eq)] pub enum AtomicOrdering { // These values must match the compiler's `AtomicOrdering` defined in // `rustc_middle/src/ty/consts/int.rs`! + /// [`Ordering::Relaxed`][`crate::sync::atomic::Ordering::Relaxed`] Relaxed = 0, + /// [`Ordering::Release`][`crate::sync::atomic::Ordering::Release`] Release = 1, + /// [`Ordering::Acquire`][`crate::sync::atomic::Ordering::Acquire`] Acquire = 2, + /// [`Ordering::AcqRel`][`crate::sync::atomic::Ordering::AcqRel`] AcqRel = 3, + /// [`Ordering::SeqCst`][`crate::sync::atomic::Ordering::SeqCst`] SeqCst = 4, } diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs index 15d0640bd0aaa..7f0f250a96486 100644 --- a/library/core/src/lib.rs +++ b/library/core/src/lib.rs @@ -343,7 +343,6 @@ pub mod future; pub mod task; /* Heap memory allocator trait */ -#[allow(missing_docs)] pub mod alloc; // note: does not need to be public diff --git a/library/core/src/panicking.rs b/library/core/src/panicking.rs index 8a5e0f035d775..767707458d6a9 100644 --- a/library/core/src/panicking.rs +++ b/library/core/src/panicking.rs @@ -21,7 +21,7 @@ //! necessary lang items for the compiler. All panics are funneled through this //! one function. The actual symbol is declared through the `#[panic_handler]` attribute. -#![allow(dead_code, missing_docs)] +#![allow(dead_code)] #![unstable( feature = "panic_internals", reason = "internal details of the implementation of the `panic!` and related macros", @@ -182,6 +182,7 @@ macro_rules! panic_const { // slightly different forms. It's not clear if there's a good way to deduplicate without adding // special cases to the compiler (e.g., a const generic function wouldn't have a single definition // shared across crates, which is exactly what we want here). +#[allow(missing_docs)] pub mod panic_const { use super::*; panic_const! { @@ -233,9 +234,10 @@ pub fn panic_nounwind_nobacktrace(expr: &'static str) -> ! { panic_nounwind_fmt(fmt::Arguments::from_str(expr), /* force_no_backtrace */ true); } +/// Needed by `non-fmt-panics` lint. #[inline] #[track_caller] -#[rustc_diagnostic_item = "unreachable_display"] // needed for `non-fmt-panics` lint +#[rustc_diagnostic_item = "unreachable_display"] pub fn unreachable_display(x: &T) -> ! { panic_fmt(format_args!("internal error: entered unreachable code: {}", *x)); } @@ -250,9 +252,10 @@ pub const fn panic_str_2015(expr: &str) -> ! { panic_display(&expr); } +/// Needed for const-evaluated panics. #[inline] #[track_caller] -#[lang = "panic_display"] // needed for const-evaluated panics +#[lang = "panic_display"] #[rustc_do_not_const_check] // hooked by const-eval #[rustc_const_stable_indirect] // must follow stable const rules since it is exposed to stable pub const fn panic_display(x: &T) -> ! { @@ -457,7 +460,7 @@ fn assert_failed_inner( } } -// panic!() without args expands to this, to generate slightly less code +/// `panic!()` without args expands to this, to generate slightly less code. #[cfg_attr(not(panic = "immediate-abort"), inline(never), cold)] #[cfg_attr(panic = "immediate-abort", inline)] #[track_caller] @@ -465,7 +468,7 @@ pub const fn panic_default_msg() -> ! { panic("explicit panic") } -// unreachable!() without args expands to this, to generate slightly less code +/// `unreachable!()` without args expands to this, to generate slightly less code. #[cfg_attr(not(panic = "immediate-abort"), inline(never), cold)] #[cfg_attr(panic = "immediate-abort", inline)] #[track_caller] @@ -473,7 +476,7 @@ pub const fn unreachable_default_msg() -> ! { panic("internal error: entered unreachable code") } -// unimplemented!() without args expands to this, to generate slightly less code +/// `unimplemented!()` without args expands to this, to generate slightly less code. #[cfg_attr(not(panic = "immediate-abort"), inline(never), cold)] #[cfg_attr(panic = "immediate-abort", inline)] #[track_caller] @@ -481,7 +484,7 @@ pub const fn unimplemented_default_msg() -> ! { panic("not implemented") } -// todo!() without args expands to this, to generate slightly less code +/// `todo!()` without args expands to this, to generate slightly less code. #[cfg_attr(not(panic = "immediate-abort"), inline(never), cold)] #[cfg_attr(panic = "immediate-abort", inline)] #[track_caller] diff --git a/library/std/src/net/tcp.rs b/library/std/src/net/tcp.rs index 7f3b00a315862..ae1bf03eb28b5 100644 --- a/library/std/src/net/tcp.rs +++ b/library/std/src/net/tcp.rs @@ -1110,16 +1110,20 @@ impl TcpListener { self.0.hop_limit_v6() } + /// Only allow v6 for this socket. + /// + /// ⚠️: This option can only be set before the socket is bound. #[stable(feature = "net2_mutators", since = "1.9.0")] #[deprecated(since = "1.16.0", note = "this option can only be set before the socket is bound")] - #[allow(missing_docs)] pub fn set_only_v6(&self, only_v6: bool) -> io::Result<()> { self.0.set_only_v6(only_v6) } + /// Checks if this socket only allow v6. + /// + /// ⚠️: This option can only be set before the socket is bound. #[stable(feature = "net2_mutators", since = "1.9.0")] #[deprecated(since = "1.16.0", note = "this option can only be set before the socket is bound")] - #[allow(missing_docs)] pub fn only_v6(&self) -> io::Result { self.0.only_v6() } diff --git a/library/std/src/num/f32.rs b/library/std/src/num/f32.rs index 67d72e8ecd638..738b6e1964cdd 100644 --- a/library/std/src/num/f32.rs +++ b/library/std/src/num/f32.rs @@ -10,7 +10,6 @@ //! defined directly on the `f32` type. #![stable(feature = "rust1", since = "1.0.0")] -#![allow(missing_docs)] #[stable(feature = "rust1", since = "1.0.0")] #[allow(deprecated, clippy::legacy_numeric_constants)] diff --git a/library/std/src/num/f64.rs b/library/std/src/num/f64.rs index dcab1615780b2..2b586321235c4 100644 --- a/library/std/src/num/f64.rs +++ b/library/std/src/num/f64.rs @@ -10,7 +10,6 @@ //! defined directly on the `f64` type. #![stable(feature = "rust1", since = "1.0.0")] -#![allow(missing_docs)] #[stable(feature = "rust1", since = "1.0.0")] #[allow(deprecated, clippy::legacy_numeric_constants)] diff --git a/library/std/src/num/mod.rs b/library/std/src/num/mod.rs index 2feaae34135fe..3d9e26569d40f 100644 --- a/library/std/src/num/mod.rs +++ b/library/std/src/num/mod.rs @@ -4,7 +4,6 @@ //! work. See the individual documentation for each piece for more information. #![stable(feature = "rust1", since = "1.0.0")] -#![allow(missing_docs)] #[unstable(feature = "complex_numbers", issue = "154023")] pub use core::num::Complex; diff --git a/library/std/src/sys/pal/unix/mod.rs b/library/std/src/sys/pal/unix/mod.rs index 4b0bbdaf073ca..9b6eec8e322b8 100644 --- a/library/std/src/sys/pal/unix/mod.rs +++ b/library/std/src/sys/pal/unix/mod.rs @@ -1,4 +1,4 @@ -#![allow(missing_docs, nonstandard_style)] +#![allow(nonstandard_style)] use crate::io; From fec604ad2745cab11dcc79da80313e7bfab2a0d5 Mon Sep 17 00:00:00 2001 From: Jonathan Brouwer Date: Wed, 18 Nov 2026 22:03:56 +0100 Subject: [PATCH 09/11] Fix `x86_64-gnu-parallel-frontend` link --- src/doc/rustc-dev-guide/src/SUMMARY.md | 2 +- ...gnu-parallel-frontend.md => x86_64-gnu-parallel-frontend.md} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename src/doc/rustc-dev-guide/src/tests/{optional-x86_64-gnu-parallel-frontend.md => x86_64-gnu-parallel-frontend.md} (100%) diff --git a/src/doc/rustc-dev-guide/src/SUMMARY.md b/src/doc/rustc-dev-guide/src/SUMMARY.md index 183f1df017dc4..5cf48689bbe7e 100644 --- a/src/doc/rustc-dev-guide/src/SUMMARY.md +++ b/src/doc/rustc-dev-guide/src/SUMMARY.md @@ -37,7 +37,7 @@ - [Performance testing](./tests/perf.md) - [Autodiff CI job](./tests/autodiff-ci-job.md) - [Pre-stabilization CI job for the next solver and polonius alpha](./tests/x86_64-gnu-next-trait-solver-polonius-ci-job.md) - - [Parallel frontend CI job](./tests/optional-x86_64-gnu-parallel-frontend.md) + - [Parallel frontend CI job](./tests/x86_64-gnu-parallel-frontend.md) - [Standard library semver breakage test](./tests/stdlib-semver-check.md) - [Misc info](./tests/misc.md) - [Debugging the compiler](./compiler-debugging.md) diff --git a/src/doc/rustc-dev-guide/src/tests/optional-x86_64-gnu-parallel-frontend.md b/src/doc/rustc-dev-guide/src/tests/x86_64-gnu-parallel-frontend.md similarity index 100% rename from src/doc/rustc-dev-guide/src/tests/optional-x86_64-gnu-parallel-frontend.md rename to src/doc/rustc-dev-guide/src/tests/x86_64-gnu-parallel-frontend.md From f0bc5bf5b2947d1889287e1d711c82c73eea1678 Mon Sep 17 00:00:00 2001 From: Jonathan Brouwer Date: Wed, 18 Nov 2026 22:05:12 +0100 Subject: [PATCH 10/11] Ignore `cycle-guaranteed-unsized-self-type-116914.rs` on parallel frontend --- .../cycle-guaranteed-unsized-self-type-116914.rs | 3 +++ .../cycle-guaranteed-unsized-self-type-116914.stderr | 10 +++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/tests/ui/traits/cycle-guaranteed-unsized-self-type-116914.rs b/tests/ui/traits/cycle-guaranteed-unsized-self-type-116914.rs index 43f76c7ed2021..40dda022aa21c 100644 --- a/tests/ui/traits/cycle-guaranteed-unsized-self-type-116914.rs +++ b/tests/ui/traits/cycle-guaranteed-unsized-self-type-116914.rs @@ -1,3 +1,6 @@ +//@ ignore-parallel-frontend triage +// Spuriously failed at https://github.com/rust-lang/rust/pull/166138#issuecomment-6991382914 + //! Regression test for . trait Filter { diff --git a/tests/ui/traits/cycle-guaranteed-unsized-self-type-116914.stderr b/tests/ui/traits/cycle-guaranteed-unsized-self-type-116914.stderr index 91cdd89a3babf..e55e8e7454578 100644 --- a/tests/ui/traits/cycle-guaranteed-unsized-self-type-116914.stderr +++ b/tests/ui/traits/cycle-guaranteed-unsized-self-type-116914.stderr @@ -1,14 +1,14 @@ -error[E0391]: cycle detected when computing whether `` has a guaranteed unsized self type - --> $DIR/cycle-guaranteed-unsized-self-type-116914.rs:7:1 +error[E0391]: cycle detected when computing whether `` has a guaranteed unsized self type + --> $DIR/cycle-guaranteed-unsized-self-type-116914.rs:10:1 | LL | / impl Filter for T LL | | where LL | | T: Fn(Self::ToMatch), | |_________________________^ | - = note: ...which requires computing normalized predicates of ``... - = note: ...which again requires computing whether `` has a guaranteed unsized self type, completing the cycle - = note: cycle used when checking that `` is well-formed + = note: ...which requires computing normalized predicates of ``... + = note: ...which again requires computing whether `` has a guaranteed unsized self type, completing the cycle + = note: cycle used when checking that `` is well-formed = note: for more information, see and error: aborting due to 1 previous error From ccc5e3b5738e7d8666a1dda91e8dec9e1c45cb8d Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 19 Nov 2026 15:10:35 +1100 Subject: [PATCH 11/11] Remove dead size assertion `WithCachedTypeInfo` is never used. --- compiler/rustc_middle/src/ty/region.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/compiler/rustc_middle/src/ty/region.rs b/compiler/rustc_middle/src/ty/region.rs index fbb40465cd5fd..6b4b91ec7e1ce 100644 --- a/compiler/rustc_middle/src/ty/region.rs +++ b/compiler/rustc_middle/src/ty/region.rs @@ -149,6 +149,5 @@ mod size_asserts { use super::*; // tidy-alphabetical-start static_assert_size!(RegionKind<'_>, 20); - static_assert_size!(ty::WithCachedTypeInfo>, 28); // tidy-alphabetical-end }