From 955064b6aaa5c24e980328f9d9fbe731cc29636c Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Tue, 1 Jun 2021 21:33:14 +0200 Subject: Implement `#[rustc_skip_array_during_method_dispatch]` --- crates/hir_ty/src/tests/method_resolution.rs | 49 ++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'crates/hir_ty/src/tests') diff --git a/crates/hir_ty/src/tests/method_resolution.rs b/crates/hir_ty/src/tests/method_resolution.rs index 058eb9129..f26b2c8a7 100644 --- a/crates/hir_ty/src/tests/method_resolution.rs +++ b/crates/hir_ty/src/tests/method_resolution.rs @@ -1349,3 +1349,52 @@ fn f() { "#, ); } + +#[test] +fn skip_array_during_method_dispatch() { + check_types( + r#" +//- /main2018.rs crate:main2018 deps:core +use core::IntoIterator; + +fn f() { + let v = [4].into_iter(); + v; + //^ &i32 + + let a = [0, 1].into_iter(); + a; + //^ &i32 +} + +//- /main2021.rs crate:main2021 deps:core edition:2021 +use core::IntoIterator; + +fn f() { + let v = [4].into_iter(); + v; + //^ i32 + + let a = [0, 1].into_iter(); + a; + //^ &i32 +} + +//- /core.rs crate:core +#[rustc_skip_array_during_method_dispatch] +pub trait IntoIterator { + type Out; + fn into_iter(self) -> Self::Out; +} + +impl IntoIterator for [T; 1] { + type Out = T; + fn into_iter(self) -> Self::Out {} +} +impl<'a, T> IntoIterator for &'a [T] { + type Out = &'a T; + fn into_iter(self) -> Self::Out {} +} + "#, + ); +} -- cgit v1.2.3