This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +21
-9
lines changed
rustc_query_system/src/query Expand file tree Collapse file tree 3 files changed +21
-9
lines changed Original file line number Diff line number Diff line change @@ -178,6 +178,10 @@ impl Key for (DefId, Option<Ident>) {
178178 fn default_span ( & self , tcx : TyCtxt < ' _ > ) -> Span {
179179 tcx. def_span ( self . 0 )
180180 }
181+ #[ inline( always) ]
182+ fn key_as_def_id ( & self ) -> Option < DefId > {
183+ Some ( self . 0 )
184+ }
181185}
182186
183187impl Key for ( DefId , LocalDefId , Ident ) {
Original file line number Diff line number Diff line change @@ -600,16 +600,23 @@ pub(crate) fn report_cycle<'a>(
600600 ) ) ;
601601 }
602602
603- if !stack. is_empty ( )
604- && stack. iter ( ) . all ( |entry| {
605- entry. query . def_kind . map_or ( false , |def_kind| {
606- matches ! ( def_kind, SimpleDefKind :: TyAlias | SimpleDefKind :: TraitAlias )
607- } )
603+ if stack. iter ( ) . all ( |entry| {
604+ entry. query . def_kind . map_or ( false , |def_kind| {
605+ matches ! ( def_kind, SimpleDefKind :: TyAlias | SimpleDefKind :: TraitAlias )
608606 } )
609- {
610- err. note ( "type aliases cannot be recursive" ) ;
611- err. help ( "consider using a struct, enum, or union instead to break the cycle" ) ;
612- err. help ( "see <https://doc.rust-lang.org/reference/types.html#recursive-types> for more information" ) ;
607+ } ) {
608+ if stack. iter ( ) . all ( |entry| {
609+ entry
610+ . query
611+ . def_kind
612+ . map_or ( false , |def_kind| matches ! ( def_kind, SimpleDefKind :: TyAlias ) )
613+ } ) {
614+ err. note ( "type aliases cannot be recursive" ) ;
615+ err. help ( "consider using a struct, enum, or union instead to break the cycle" ) ;
616+ err. help ( "see <https://doc.rust-lang.org/reference/types.html#recursive-types> for more information" ) ;
617+ } else {
618+ err. note ( "trait aliases cannot be recursive" ) ;
619+ }
613620 }
614621
615622 if let Some ( ( span, query) ) = usage {
Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ note: ...which requires computing the super traits of `T3`...
3030LL | trait T3 = T1 + T3;
3131 | ^^
3232 = note: ...which again requires computing the super predicates of `T1`, completing the cycle
33+ = note: trait aliases cannot be recursive
3334note: cycle used when collecting item types in top-level module
3435 --> $DIR/infinite-trait-alias-recursion.rs:3:1
3536 |
You can’t perform that action at this time.
0 commit comments