File tree Expand file tree Collapse file tree 3 files changed +39
-2
lines changed Expand file tree Collapse file tree 3 files changed +39
-2
lines changed Original file line number Diff line number Diff line change @@ -550,14 +550,18 @@ pub(crate) fn trait_datum_query(
550
550
debug ! ( "trait_datum {:?}" , trait_id) ;
551
551
let trait_ = from_chalk_trait_id ( trait_id) ;
552
552
let trait_data = db. trait_data ( trait_) ;
553
+
554
+ let coinductive =
555
+ trait_data. is_auto || db. attrs ( trait_. into ( ) ) . by_key ( "rustc_coinductive" ) . exists ( ) ;
556
+
553
557
debug ! ( "trait {:?} = {:?}" , trait_id, trait_data. name) ;
554
558
let generic_params = generics ( db. upcast ( ) , trait_. into ( ) ) ;
555
559
let bound_vars = generic_params. bound_vars_subst ( db, DebruijnIndex :: INNERMOST ) ;
556
560
let flags = rust_ir:: TraitFlags {
557
561
auto : trait_data. is_auto ,
558
562
upstream : trait_. lookup ( db. upcast ( ) ) . container . krate ( ) != krate,
559
563
non_enumerable : true ,
560
- coinductive : false , // only relevant for Chalk testing
564
+ coinductive,
561
565
// FIXME: set these flags correctly
562
566
marker : false ,
563
567
fundamental : false ,
@@ -637,7 +641,7 @@ pub(crate) fn struct_datum_query(
637
641
fundamental : false ,
638
642
phantom_data : false ,
639
643
} ;
640
- // FIXME provide enum variants properly (for auto traits)
644
+ // FIXME provide enum variants properly (for auto traits and `Sized` )
641
645
let variant = rust_ir:: AdtVariantDatum {
642
646
fields : Vec :: new ( ) , // FIXME add fields (only relevant for auto traits),
643
647
} ;
Original file line number Diff line number Diff line change @@ -4410,3 +4410,35 @@ fn test(v: S<i32>) {
4410
4410
"# ,
4411
4411
) ;
4412
4412
}
4413
+
4414
+ #[ test]
4415
+ fn rustc_coinductive ( ) {
4416
+ // Taken from rust-lang/rust#108033 with modification.
4417
+ check_types (
4418
+ r#"
4419
+ #[rustc_coinductive]
4420
+ trait Trait { type Assoc; }
4421
+
4422
+ impl<T, U> Trait for (T, U)
4423
+ where
4424
+ (U, T): Trait,
4425
+ (): ConstrainToU32<T>,
4426
+ {
4427
+ type Assoc = i32;
4428
+ }
4429
+
4430
+ trait ConstrainToU32<T> {}
4431
+ impl ConstrainToU32<u32> for () {}
4432
+
4433
+ fn impls_trait<T, U, R>() -> R
4434
+ where
4435
+ (T, U): Trait<Assoc = R>,
4436
+ { loop {} }
4437
+
4438
+ fn main() {
4439
+ let _ = impls_trait::<_, _, _>();
4440
+ //^ i32
4441
+ }
4442
+ "# ,
4443
+ ) ;
4444
+ }
Original file line number Diff line number Diff line change @@ -62,6 +62,7 @@ pub mod marker {
62
62
#[ lang = "sized" ]
63
63
#[ fundamental]
64
64
#[ rustc_specialization_trait]
65
+ #[ rustc_coinductive]
65
66
pub trait Sized { }
66
67
// endregion:sized
67
68
You can’t perform that action at this time.
0 commit comments