Skip to content

Commit 5028581

Browse files
authored
Rollup merge of #86657 - jam1garner:future_prelude_false_positive, r=nikomatsakis
Fix `future_prelude_collision` false positive Fixes #86633 The lint for checking if method resolution of methods named `try_into` will fail in 2021 edition previously would fire on all inherent methods, however for inherent methods that consume `self`, this takes priority over `TryInto::try_into` due to being inherent, while trait method and methods that take `&self` or `&mut self` don't take priority, and thus aren't affected by this false positive. This fix is rather simple: simply checking if the inherent method doesn't auto-deref or auto-ref (and thus takes `self`) and if so, prevents the lint from firing.
2 parents c9ac096 + bf0da44 commit 5028581

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

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

+7
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
5757
{
5858
return;
5959
}
60+
61+
// if it's an inherent `self` method (not `&self` or `&mut self`), it will take
62+
// precedence over the `TryInto` impl, and thus won't break in 2021 edition
63+
if pick.autoderefs == 0 && pick.autoref_or_ptr_adjustment.is_none() {
64+
return;
65+
}
66+
6067
// Inherent impls only require not relying on autoref and autoderef in order to
6168
// ensure that the trait implementation won't be used
6269
self.tcx.struct_span_lint_hir(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// edition:2018
2+
// check-pass
3+
#![allow(unused)]
4+
#![deny(future_prelude_collision)]
5+
6+
struct S;
7+
8+
impl S {
9+
fn try_into(self) -> S { S }
10+
}
11+
12+
// See https://github.com/rust-lang/rust/issues/86633
13+
fn main() {
14+
let s = S;
15+
let s2 = s.try_into();
16+
}

0 commit comments

Comments
 (0)