Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 327697a

Browse files
jam1garnernikomatsakis
authored andcommitted
Fix autoderef and autoref for future_prelude_collision lint
1 parent c41a157 commit 327697a

File tree

1 file changed

+13
-1
lines changed
  • compiler/rustc_typeck/src/check/method

1 file changed

+13
-1
lines changed

compiler/rustc_typeck/src/check/method/mod.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ pub use self::CandidateSource::*;
1111
pub use self::MethodError::*;
1212

1313
use crate::check::FnCtxt;
14+
use rustc_ast::ast::Mutability;
1415
use rustc_data_structures::sync::Lrc;
1516
use rustc_errors::{Applicability, DiagnosticBuilder};
1617
use rustc_hir as hir;
@@ -222,12 +223,23 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
222223
if let Ok(self_expr) =
223224
self.sess().source_map().span_to_snippet(self_expr.span)
224225
{
226+
let derefs = "*".repeat(pick.autoderefs);
227+
let self_adjusted = match pick.autoref_or_ptr_adjustment {
228+
Some(probe::AutorefOrPtrAdjustment::Autoref {
229+
mutbl: Mutability::Mut, ..
230+
}) => format!("&mut {}{}", derefs, self_expr),
231+
Some(probe::AutorefOrPtrAdjustment::Autoref {
232+
mutbl: Mutability::Not, ..
233+
}) => format!("&{}{}", derefs, self_expr),
234+
Some(probe::AutorefOrPtrAdjustment::ToConstPtr) | None
235+
=> format!("{}{}", derefs, self_expr),
236+
};
225237
lint.span_suggestion(
226238
sp,
227239
"disambiguate the associated function",
228240
format!(
229241
"{}::{}({})",
230-
trait_name, segment.ident.name, self_expr,
242+
trait_name, segment.ident.name, self_adjusted,
231243
),
232244
Applicability::MachineApplicable,
233245
);

0 commit comments

Comments
 (0)