55use std:: ops:: ControlFlow ;
66
77use base_db:: CrateId ;
8- use chalk_ir:: { cast:: Cast , Mutability , TyKind , UniverseIndex , WhereClause } ;
8+ use chalk_ir:: { cast:: Cast , UniverseIndex , WithKind } ;
99use hir_def:: {
1010 data:: { adt:: StructFlags , ImplData } ,
1111 nameres:: DefMap ,
@@ -16,7 +16,6 @@ use hir_expand::name::Name;
1616use intern:: sym;
1717use rustc_hash:: { FxHashMap , FxHashSet } ;
1818use smallvec:: { smallvec, SmallVec } ;
19- use span:: Edition ;
2019use stdx:: never;
2120use triomphe:: Arc ;
2221
@@ -25,12 +24,14 @@ use crate::{
2524 db:: HirDatabase ,
2625 error_lifetime, from_chalk_trait_id, from_foreign_def_id,
2726 infer:: { unify:: InferenceTable , Adjust , Adjustment , OverloadedDeref , PointerCast } ,
27+ lang_items:: is_box,
2828 primitive:: { FloatTy , IntTy , UintTy } ,
2929 to_chalk_trait_id,
3030 utils:: all_super_traits,
31- AdtId , Canonical , CanonicalVarKinds , DebruijnIndex , DynTyExt , ForeignDefId , Goal , Guidance ,
32- InEnvironment , Interner , Scalar , Solution , Substitution , TraitEnvironment , TraitRef ,
33- TraitRefExt , Ty , TyBuilder , TyExt ,
31+ AdtId , Canonical , CanonicalVarKinds , DebruijnIndex , DynTyExt , ForeignDefId , GenericArgData ,
32+ Goal , Guidance , InEnvironment , Interner , Mutability , Scalar , Solution , Substitution ,
33+ TraitEnvironment , TraitRef , TraitRefExt , Ty , TyBuilder , TyExt , TyKind , VariableKind ,
34+ WhereClause ,
3435} ;
3536
3637/// This is used as a key for indexing impls.
@@ -1146,17 +1147,30 @@ fn iterate_trait_method_candidates(
11461147 ' traits: for & t in traits_in_scope {
11471148 let data = db. trait_data ( t) ;
11481149
1149- // Traits annotated with `#[rustc_skip_array_during_method_dispatch ]` are skipped during
1150+ // Traits annotated with `#[rustc_skip_during_method_dispatch ]` are skipped during
11501151 // method resolution, if the receiver is an array, and we're compiling for editions before
11511152 // 2021.
11521153 // This is to make `[a].into_iter()` not break code with the new `IntoIterator` impl for
11531154 // arrays.
11541155 if data. skip_array_during_method_dispatch
1155- && matches ! ( self_ty. kind( Interner ) , chalk_ir :: TyKind :: Array ( ..) )
1156+ && matches ! ( self_ty. kind( Interner ) , TyKind :: Array ( ..) )
11561157 {
11571158 // FIXME: this should really be using the edition of the method name's span, in case it
11581159 // comes from a macro
1159- if db. crate_graph ( ) [ krate] . edition < Edition :: Edition2021 {
1160+ if !db. crate_graph ( ) [ krate] . edition . at_least_2021 ( ) {
1161+ continue ;
1162+ }
1163+ }
1164+ if data. skip_boxed_slice_during_method_dispatch
1165+ && matches ! (
1166+ self_ty. kind( Interner ) , TyKind :: Adt ( AdtId ( def) , subst)
1167+ if is_box( table. db, * def)
1168+ && matches!( subst. at( Interner , 0 ) . assert_ty_ref( Interner ) . kind( Interner ) , TyKind :: Slice ( ..) )
1169+ )
1170+ {
1171+ // FIXME: this should really be using the edition of the method name's span, in case it
1172+ // comes from a macro
1173+ if !db. crate_graph ( ) [ krate] . edition . at_least_2024 ( ) {
11601174 continue ;
11611175 }
11621176 }
@@ -1619,15 +1633,11 @@ fn generic_implements_goal(
16191633 let kinds =
16201634 binders. iter ( ) . cloned ( ) . chain ( trait_ref. substitution . iter ( Interner ) . skip ( 1 ) . map ( |it| {
16211635 let vk = match it. data ( Interner ) {
1622- chalk_ir:: GenericArgData :: Ty ( _) => {
1623- chalk_ir:: VariableKind :: Ty ( chalk_ir:: TyVariableKind :: General )
1624- }
1625- chalk_ir:: GenericArgData :: Lifetime ( _) => chalk_ir:: VariableKind :: Lifetime ,
1626- chalk_ir:: GenericArgData :: Const ( c) => {
1627- chalk_ir:: VariableKind :: Const ( c. data ( Interner ) . ty . clone ( ) )
1628- }
1636+ GenericArgData :: Ty ( _) => VariableKind :: Ty ( chalk_ir:: TyVariableKind :: General ) ,
1637+ GenericArgData :: Lifetime ( _) => VariableKind :: Lifetime ,
1638+ GenericArgData :: Const ( c) => VariableKind :: Const ( c. data ( Interner ) . ty . clone ( ) ) ,
16291639 } ;
1630- chalk_ir :: WithKind :: new ( vk, UniverseIndex :: ROOT )
1640+ WithKind :: new ( vk, UniverseIndex :: ROOT )
16311641 } ) ) ;
16321642 let binders = CanonicalVarKinds :: from_iter ( Interner , kinds) ;
16331643
0 commit comments