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

Commit 3efa5b4

Browse files
committed
Emit additional arguments in future_prelude_collision lint
1 parent 17ab9c0 commit 3efa5b4

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

compiler/rustc_typeck/src/check/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -941,7 +941,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
941941
// no need to check for bot/err -- callee does that
942942
let rcvr_t = self.structurally_resolved_type(args[0].span, rcvr_t);
943943

944-
let method = match self.lookup_method(rcvr_t, segment, span, expr, rcvr) {
944+
let method = match self.lookup_method(rcvr_t, segment, span, expr, rcvr, args) {
945945
Ok(method) => {
946946
// We could add a "consider `foo::<params>`" suggestion here, but I wasn't able to
947947
// trigger this codepath causing `structuraly_resolved_type` to emit an error.

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,14 +174,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
174174
///
175175
/// # Arguments
176176
///
177-
/// Given a method call like `foo.bar::<T1,...Tn>(...)`:
177+
/// Given a method call like `foo.bar::<T1,...Tn>(a, b + 1, ...)`:
178178
///
179179
/// * `self`: the surrounding `FnCtxt` (!)
180180
/// * `self_ty`: the (unadjusted) type of the self expression (`foo`)
181181
/// * `segment`: the name and generic arguments of the method (`bar::<T1, ...Tn>`)
182182
/// * `span`: the span for the method call
183183
/// * `call_expr`: the complete method call: (`foo.bar::<T1,...Tn>(...)`)
184184
/// * `self_expr`: the self expression (`foo`)
185+
/// * `args`: the expressions of the arguments (`a, b + 1, ...`)
185186
#[instrument(level = "debug", skip(self, call_expr, self_expr))]
186187
pub fn lookup_method(
187188
&self,
@@ -190,6 +191,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
190191
span: Span,
191192
call_expr: &'tcx hir::Expr<'tcx>,
192193
self_expr: &'tcx hir::Expr<'tcx>,
194+
args: &'tcx [hir::Expr<'tcx>],
193195
) -> Result<MethodCallee<'tcx>, MethodError<'tcx>> {
194196
debug!(
195197
"lookup(method_name={}, self_ty={:?}, call_expr={:?}, self_expr={:?})",
@@ -199,7 +201,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
199201
let pick =
200202
self.lookup_probe(span, segment.ident, self_ty, call_expr, ProbeScope::TraitsInScope)?;
201203

202-
self.lint_dot_call_from_2018(self_ty, segment, span, call_expr, self_expr, &pick);
204+
self.lint_dot_call_from_2018(self_ty, segment, span, call_expr, self_expr, &pick, args);
203205

204206
for import_id in &pick.import_ids {
205207
debug!("used_trait_import: {:?}", import_id);

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2020
call_expr: &'tcx hir::Expr<'tcx>,
2121
self_expr: &'tcx hir::Expr<'tcx>,
2222
pick: &Pick<'tcx>,
23+
args: &'tcx [hir::Expr<'tcx>],
2324
) {
2425
debug!(
2526
"lookup(method_name={}, self_ty={:?}, call_expr={:?}, self_expr={:?})",
@@ -75,10 +76,24 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
7576
} else {
7677
format!("{}{}{}", autoref, derefs, self_expr)
7778
};
79+
let args = args
80+
.iter()
81+
.skip(1)
82+
.map(|arg| {
83+
format!(
84+
", {}",
85+
self.sess().source_map().span_to_snippet(arg.span).unwrap()
86+
)
87+
})
88+
.collect::<String>();
89+
7890
lint.span_suggestion(
7991
sp,
8092
"disambiguate the associated function",
81-
format!("{}::{}({})", trait_name, segment.ident.name, self_adjusted,),
93+
format!(
94+
"{}::{}({}{})",
95+
trait_name, segment.ident.name, self_adjusted, args
96+
),
8297
Applicability::MachineApplicable,
8398
);
8499
} else {

0 commit comments

Comments
 (0)