Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix future_prelude_collision false positive #86657

Merged
merged 1 commit into from
Jun 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions compiler/rustc_typeck/src/check/method/prelude2021.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
{
return;
}

// if it's an inherent `self` method (not `&self` or `&mut self`), it will take
// precedence over the `TryInto` impl, and thus won't break in 2021 edition
if pick.autoderefs == 0 && pick.autoref_or_ptr_adjustment.is_none() {
return;
}

// Inherent impls only require not relying on autoref and autoderef in order to
// ensure that the trait implementation won't be used
self.tcx.struct_span_lint_hir(
Expand Down
16 changes: 16 additions & 0 deletions src/test/ui/rust-2021/future-prelude-collision-unneeded.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// edition:2018
// check-pass
#![allow(unused)]
#![deny(future_prelude_collision)]

struct S;

impl S {
fn try_into(self) -> S { S }
}

// See https://github.com/rust-lang/rust/issues/86633
fn main() {
let s = S;
let s2 = s.try_into();
}