@@ -11,14 +11,14 @@ use rustc_middle::ty::subst::{InternalSubsts, Subst, SubstsRef};
11
11
use rustc_middle:: ty:: { self , AssocItemContainer , AssocKind , TyCtxt , TypeFoldable } ;
12
12
13
13
use rustc_hir:: def_id:: DefId ;
14
- use rustc_hir:: Unsafety ;
15
14
16
15
use rustc_span:: symbol:: sym;
17
16
18
17
use std:: fmt;
19
18
use std:: sync:: Arc ;
20
19
21
20
use crate :: chalk:: lowering:: { self , LowerInto } ;
21
+ use rustc_ast:: ast;
22
22
23
23
pub struct RustIrDatabase < ' tcx > {
24
24
pub ( crate ) interner : RustInterner < ' tcx > ,
@@ -247,12 +247,7 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
247
247
} ;
248
248
Arc :: new ( chalk_solve:: rust_ir:: FnDefDatum {
249
249
id : fn_def_id,
250
- abi : sig. abi ( ) ,
251
- safety : match sig. unsafety ( ) {
252
- Unsafety :: Normal => chalk_ir:: Safety :: Safe ,
253
- Unsafety :: Unsafe => chalk_ir:: Safety :: Unsafe ,
254
- } ,
255
- variadic : sig. c_variadic ( ) ,
250
+ sig : sig. lower_into ( & self . interner ) ,
256
251
binders : chalk_ir:: Binders :: new ( binders, bound) ,
257
252
} )
258
253
}
@@ -327,21 +322,75 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
327
322
fn impl_provided_for (
328
323
& self ,
329
324
auto_trait_id : chalk_ir:: TraitId < RustInterner < ' tcx > > ,
330
- adt_id : chalk_ir:: AdtId < RustInterner < ' tcx > > ,
325
+ app_ty : & chalk_ir:: ApplicationTy < RustInterner < ' tcx > > ,
331
326
) -> bool {
327
+ use chalk_ir:: Scalar :: * ;
328
+ use chalk_ir:: TypeName :: * ;
329
+
332
330
let trait_def_id = auto_trait_id. 0 ;
333
- let adt_def = adt_id. 0 ;
334
331
let all_impls = self . interner . tcx . all_impls ( trait_def_id) ;
335
332
for impl_def_id in all_impls {
336
333
let trait_ref = self . interner . tcx . impl_trait_ref ( impl_def_id) . unwrap ( ) ;
337
334
let self_ty = trait_ref. self_ty ( ) ;
338
- match * self_ty. kind ( ) {
339
- ty:: Adt ( impl_adt_def, _) => {
340
- if impl_adt_def == adt_def {
341
- return true ;
335
+ let provides = match ( self_ty. kind ( ) , app_ty. name ) {
336
+ ( & ty:: Adt ( impl_adt_def, ..) , Adt ( id) ) => impl_adt_def. did == id. 0 . did ,
337
+ ( _, AssociatedType ( _ty_id) ) => {
338
+ // FIXME(chalk): See https://github.com/rust-lang/rust/pull/77152#discussion_r494484774
339
+ false
340
+ }
341
+ ( ty:: Bool , Scalar ( Bool ) ) => true ,
342
+ ( ty:: Char , Scalar ( Char ) ) => true ,
343
+ ( ty:: Int ( ty1) , Scalar ( Int ( ty2) ) ) => match ( ty1, ty2) {
344
+ ( ast:: IntTy :: Isize , chalk_ir:: IntTy :: Isize )
345
+ | ( ast:: IntTy :: I8 , chalk_ir:: IntTy :: I8 )
346
+ | ( ast:: IntTy :: I16 , chalk_ir:: IntTy :: I16 )
347
+ | ( ast:: IntTy :: I32 , chalk_ir:: IntTy :: I32 )
348
+ | ( ast:: IntTy :: I64 , chalk_ir:: IntTy :: I64 )
349
+ | ( ast:: IntTy :: I128 , chalk_ir:: IntTy :: I128 ) => true ,
350
+ _ => false ,
351
+ } ,
352
+ ( ty:: Uint ( ty1) , Scalar ( Uint ( ty2) ) ) => match ( ty1, ty2) {
353
+ ( ast:: UintTy :: Usize , chalk_ir:: UintTy :: Usize )
354
+ | ( ast:: UintTy :: U8 , chalk_ir:: UintTy :: U8 )
355
+ | ( ast:: UintTy :: U16 , chalk_ir:: UintTy :: U16 )
356
+ | ( ast:: UintTy :: U32 , chalk_ir:: UintTy :: U32 )
357
+ | ( ast:: UintTy :: U64 , chalk_ir:: UintTy :: U64 )
358
+ | ( ast:: UintTy :: U128 , chalk_ir:: UintTy :: U128 ) => true ,
359
+ _ => false ,
360
+ } ,
361
+ ( ty:: Float ( ty1) , Scalar ( Float ( ty2) ) ) => match ( ty1, ty2) {
362
+ ( ast:: FloatTy :: F32 , chalk_ir:: FloatTy :: F32 )
363
+ | ( ast:: FloatTy :: F64 , chalk_ir:: FloatTy :: F64 ) => true ,
364
+ _ => false ,
365
+ } ,
366
+ ( & ty:: Tuple ( ..) , Tuple ( ..) ) => true ,
367
+ ( & ty:: Array ( ..) , Array ) => true ,
368
+ ( & ty:: Slice ( ..) , Slice ) => true ,
369
+ ( & ty:: RawPtr ( type_and_mut) , Raw ( mutability) ) => {
370
+ match ( type_and_mut. mutbl , mutability) {
371
+ ( ast:: Mutability :: Mut , chalk_ir:: Mutability :: Mut ) => true ,
372
+ ( ast:: Mutability :: Mut , chalk_ir:: Mutability :: Not ) => false ,
373
+ ( ast:: Mutability :: Not , chalk_ir:: Mutability :: Mut ) => false ,
374
+ ( ast:: Mutability :: Not , chalk_ir:: Mutability :: Not ) => true ,
342
375
}
343
376
}
344
- _ => { }
377
+ ( & ty:: Ref ( .., mutability1) , Ref ( mutability2) ) => match ( mutability1, mutability2) {
378
+ ( ast:: Mutability :: Mut , chalk_ir:: Mutability :: Mut ) => true ,
379
+ ( ast:: Mutability :: Mut , chalk_ir:: Mutability :: Not ) => false ,
380
+ ( ast:: Mutability :: Not , chalk_ir:: Mutability :: Mut ) => false ,
381
+ ( ast:: Mutability :: Not , chalk_ir:: Mutability :: Not ) => true ,
382
+ } ,
383
+ ( & ty:: Opaque ( def_id, ..) , OpaqueType ( opaque_ty_id) ) => def_id == opaque_ty_id. 0 ,
384
+ ( & ty:: FnDef ( def_id, ..) , FnDef ( fn_def_id) ) => def_id == fn_def_id. 0 ,
385
+ ( & ty:: Str , Str ) => true ,
386
+ ( & ty:: Never , Never ) => true ,
387
+ ( & ty:: Closure ( def_id, ..) , Closure ( closure_id) ) => def_id == closure_id. 0 ,
388
+ ( & ty:: Foreign ( def_id) , Foreign ( foreign_def_id) ) => def_id == foreign_def_id. 0 ,
389
+ ( & ty:: Error ( ..) , Error ) => false ,
390
+ _ => false ,
391
+ } ;
392
+ if provides {
393
+ return true ;
345
394
}
346
395
}
347
396
false
@@ -416,15 +465,18 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
416
465
well_known_trait : chalk_solve:: rust_ir:: WellKnownTrait ,
417
466
) -> Option < chalk_ir:: TraitId < RustInterner < ' tcx > > > {
418
467
use chalk_solve:: rust_ir:: WellKnownTrait :: * ;
468
+ let lang_items = self . interner . tcx . lang_items ( ) ;
419
469
let def_id = match well_known_trait {
420
- Sized => self . interner . tcx . lang_items ( ) . sized_trait ( ) ,
421
- Copy => self . interner . tcx . lang_items ( ) . copy_trait ( ) ,
422
- Clone => self . interner . tcx . lang_items ( ) . clone_trait ( ) ,
423
- Drop => self . interner . tcx . lang_items ( ) . drop_trait ( ) ,
424
- Fn => self . interner . tcx . lang_items ( ) . fn_trait ( ) ,
425
- FnMut => self . interner . tcx . lang_items ( ) . fn_mut_trait ( ) ,
426
- FnOnce => self . interner . tcx . lang_items ( ) . fn_once_trait ( ) ,
427
- Unsize => self . interner . tcx . lang_items ( ) . unsize_trait ( ) ,
470
+ Sized => lang_items. sized_trait ( ) ,
471
+ Copy => lang_items. copy_trait ( ) ,
472
+ Clone => lang_items. clone_trait ( ) ,
473
+ Drop => lang_items. drop_trait ( ) ,
474
+ Fn => lang_items. fn_trait ( ) ,
475
+ FnMut => lang_items. fn_mut_trait ( ) ,
476
+ FnOnce => lang_items. fn_once_trait ( ) ,
477
+ Unsize => lang_items. unsize_trait ( ) ,
478
+ Unpin => lang_items. unpin_trait ( ) ,
479
+ CoerceUnsized => lang_items. coerce_unsized_trait ( ) ,
428
480
} ;
429
481
def_id. map ( chalk_ir:: TraitId )
430
482
}
0 commit comments