From 6337594e3cab59e6c006f3f39db424c8c75c3fa1 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sun, 6 Dec 2020 22:18:01 +0100 Subject: [PATCH 01/16] Iterate on variances_of. --- compiler/rustc_metadata/src/rmeta/encoder.rs | 58 +++++++++++++------- 1 file changed, 39 insertions(+), 19 deletions(-) diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index 06f53bb9282eb..e3bb4cf5da0c6 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -836,6 +836,41 @@ fn should_encode_mir(tcx: TyCtxt<'_>, def_id: LocalDefId) -> (bool, bool) { } } +fn should_encode_variances(def_kind: DefKind) -> bool { + match def_kind { + DefKind::Struct + | DefKind::Union + | DefKind::Enum + | DefKind::Variant + | DefKind::Fn + | DefKind::Ctor(..) + | DefKind::AssocFn => true, + DefKind::Mod + | DefKind::Field + | DefKind::AssocTy + | DefKind::AssocConst + | DefKind::TyParam + | DefKind::ConstParam + | DefKind::Static + | DefKind::Const + | DefKind::ForeignMod + | DefKind::TyAlias + | DefKind::OpaqueTy + | DefKind::Impl + | DefKind::Trait + | DefKind::TraitAlias + | DefKind::Macro(..) + | DefKind::ForeignTy + | DefKind::Use + | DefKind::LifetimeParam + | DefKind::AnonConst + | DefKind::GlobalAsm + | DefKind::Closure + | DefKind::Generator + | DefKind::ExternCrate => false, + } +} + impl EncodeContext<'a, 'tcx> { fn encode_def_ids(&mut self) { if self.is_proc_macro { @@ -864,6 +899,10 @@ impl EncodeContext<'a, 'tcx> { self.encode_const_stability(def_id); self.encode_deprecation(def_id); } + if should_encode_variances(def_kind) { + let v = self.tcx.variances_of(def_id); + record!(self.tables.variances[def_id] <- v); + } } let inherent_impls = tcx.crate_inherent_impls(LOCAL_CRATE); for (def_id, implementations) in inherent_impls.inherent_impls.iter() { @@ -878,11 +917,6 @@ impl EncodeContext<'a, 'tcx> { } } - fn encode_variances_of(&mut self, def_id: DefId) { - debug!("EncodeContext::encode_variances_of({:?})", def_id); - record!(self.tables.variances[def_id] <- self.tcx.variances_of(def_id)); - } - fn encode_item_type(&mut self, def_id: DefId) { debug!("EncodeContext::encode_item_type({:?})", def_id); record!(self.tables.ty[def_id] <- self.tcx.type_of(def_id)); @@ -913,8 +947,6 @@ impl EncodeContext<'a, 'tcx> { if let Some(ctor_def_id) = variant.ctor_def_id { record!(self.tables.fn_sig[def_id] <- tcx.fn_sig(ctor_def_id)); } - // FIXME(eddyb) is this ever used? - self.encode_variances_of(def_id); } self.encode_generics(def_id); self.encode_explicit_predicates(def_id); @@ -939,7 +971,6 @@ impl EncodeContext<'a, 'tcx> { self.encode_item_type(def_id); if variant.ctor_kind == CtorKind::Fn { record!(self.tables.fn_sig[def_id] <- tcx.fn_sig(def_id)); - self.encode_variances_of(def_id); } self.encode_generics(def_id); self.encode_explicit_predicates(def_id); @@ -1023,7 +1054,6 @@ impl EncodeContext<'a, 'tcx> { self.encode_item_type(def_id); if variant.ctor_kind == CtorKind::Fn { record!(self.tables.fn_sig[def_id] <- tcx.fn_sig(def_id)); - self.encode_variances_of(def_id); } self.encode_generics(def_id); self.encode_explicit_predicates(def_id); @@ -1128,7 +1158,6 @@ impl EncodeContext<'a, 'tcx> { } if trait_item.kind == ty::AssocKind::Fn { record!(self.tables.fn_sig[def_id] <- tcx.fn_sig(def_id)); - self.encode_variances_of(def_id); } self.encode_generics(def_id); self.encode_explicit_predicates(def_id); @@ -1189,7 +1218,6 @@ impl EncodeContext<'a, 'tcx> { self.encode_item_type(def_id); if impl_item.kind == ty::AssocKind::Fn { record!(self.tables.fn_sig[def_id] <- tcx.fn_sig(def_id)); - self.encode_variances_of(def_id); } self.encode_generics(def_id); self.encode_explicit_predicates(def_id); @@ -1458,13 +1486,6 @@ impl EncodeContext<'a, 'tcx> { record!(self.tables.impl_trait_ref[def_id] <- trait_ref); } } - match item.kind { - hir::ItemKind::Enum(..) - | hir::ItemKind::Struct(..) - | hir::ItemKind::Union(..) - | hir::ItemKind::Fn(..) => self.encode_variances_of(def_id), - _ => {} - } match item.kind { hir::ItemKind::Static(..) | hir::ItemKind::Const(..) @@ -1822,7 +1843,6 @@ impl EncodeContext<'a, 'tcx> { self.encode_item_type(def_id); if let hir::ForeignItemKind::Fn(..) = nitem.kind { record!(self.tables.fn_sig[def_id] <- tcx.fn_sig(def_id)); - self.encode_variances_of(def_id); } self.encode_generics(def_id); self.encode_explicit_predicates(def_id); From dda31b97c8833d612842b87d9dd67bf76a0fc572 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sun, 6 Dec 2020 22:24:40 +0100 Subject: [PATCH 02/16] Iterate on generics_of. --- compiler/rustc_metadata/src/rmeta/encoder.rs | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index e3bb4cf5da0c6..cdbbd8579b482 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -903,6 +903,8 @@ impl EncodeContext<'a, 'tcx> { let v = self.tcx.variances_of(def_id); record!(self.tables.variances[def_id] <- v); } + let g = tcx.generics_of(def_id); + record!(self.tables.generics[def_id] <- g); } let inherent_impls = tcx.crate_inherent_impls(LOCAL_CRATE); for (def_id, implementations) in inherent_impls.inherent_impls.iter() { @@ -948,7 +950,6 @@ impl EncodeContext<'a, 'tcx> { record!(self.tables.fn_sig[def_id] <- tcx.fn_sig(ctor_def_id)); } } - self.encode_generics(def_id); self.encode_explicit_predicates(def_id); self.encode_inferred_outlives(def_id); } @@ -972,7 +973,6 @@ impl EncodeContext<'a, 'tcx> { if variant.ctor_kind == CtorKind::Fn { record!(self.tables.fn_sig[def_id] <- tcx.fn_sig(def_id)); } - self.encode_generics(def_id); self.encode_explicit_predicates(def_id); self.encode_inferred_outlives(def_id); } @@ -1033,7 +1033,6 @@ impl EncodeContext<'a, 'tcx> { record!(self.tables.kind[def_id] <- EntryKind::Field); self.encode_ident_span(def_id, field.ident); self.encode_item_type(def_id); - self.encode_generics(def_id); self.encode_explicit_predicates(def_id); self.encode_inferred_outlives(def_id); } @@ -1055,16 +1054,10 @@ impl EncodeContext<'a, 'tcx> { if variant.ctor_kind == CtorKind::Fn { record!(self.tables.fn_sig[def_id] <- tcx.fn_sig(def_id)); } - self.encode_generics(def_id); self.encode_explicit_predicates(def_id); self.encode_inferred_outlives(def_id); } - fn encode_generics(&mut self, def_id: DefId) { - debug!("EncodeContext::encode_generics({:?})", def_id); - record!(self.tables.generics[def_id] <- self.tcx.generics_of(def_id)); - } - fn encode_explicit_predicates(&mut self, def_id: DefId) { debug!("EncodeContext::encode_explicit_predicates({:?})", def_id); record!(self.tables.explicit_predicates[def_id] <- @@ -1159,7 +1152,6 @@ impl EncodeContext<'a, 'tcx> { if trait_item.kind == ty::AssocKind::Fn { record!(self.tables.fn_sig[def_id] <- tcx.fn_sig(def_id)); } - self.encode_generics(def_id); self.encode_explicit_predicates(def_id); self.encode_inferred_outlives(def_id); } @@ -1219,7 +1211,6 @@ impl EncodeContext<'a, 'tcx> { if impl_item.kind == ty::AssocKind::Fn { record!(self.tables.fn_sig[def_id] <- tcx.fn_sig(def_id)); } - self.encode_generics(def_id); self.encode_explicit_predicates(def_id); self.encode_inferred_outlives(def_id); } @@ -1498,7 +1489,6 @@ impl EncodeContext<'a, 'tcx> { | hir::ItemKind::OpaqueTy(..) | hir::ItemKind::Trait(..) | hir::ItemKind::TraitAlias(..) => { - self.encode_generics(def_id); self.encode_explicit_predicates(def_id); self.encode_inferred_outlives(def_id); } @@ -1550,7 +1540,6 @@ impl EncodeContext<'a, 'tcx> { if let ty::Closure(def_id, substs) = *ty.kind() { record!(self.tables.fn_sig[def_id] <- substs.as_closure().sig()); } - self.encode_generics(def_id.to_def_id()); } fn encode_info_for_anon_const(&mut self, def_id: LocalDefId) { @@ -1562,7 +1551,6 @@ impl EncodeContext<'a, 'tcx> { record!(self.tables.kind[def_id.to_def_id()] <- EntryKind::AnonConst(qualifs, const_data)); self.encode_item_type(def_id.to_def_id()); - self.encode_generics(def_id.to_def_id()); self.encode_explicit_predicates(def_id.to_def_id()); self.encode_inferred_outlives(def_id.to_def_id()); } @@ -1844,7 +1832,6 @@ impl EncodeContext<'a, 'tcx> { if let hir::ForeignItemKind::Fn(..) = nitem.kind { record!(self.tables.fn_sig[def_id] <- tcx.fn_sig(def_id)); } - self.encode_generics(def_id); self.encode_explicit_predicates(def_id); self.encode_inferred_outlives(def_id); } From 58bca6f658dd8cf921b90d202c0ed43b833e8dc9 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sun, 6 Dec 2020 22:22:59 +0100 Subject: [PATCH 03/16] Iterate on explicit_predicates. --- compiler/rustc_metadata/src/rmeta/encoder.rs | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index cdbbd8579b482..f042b5ad8e48b 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -905,6 +905,7 @@ impl EncodeContext<'a, 'tcx> { } let g = tcx.generics_of(def_id); record!(self.tables.generics[def_id] <- g); + record!(self.tables.explicit_predicates[def_id] <- self.tcx.explicit_predicates_of(def_id)); } let inherent_impls = tcx.crate_inherent_impls(LOCAL_CRATE); for (def_id, implementations) in inherent_impls.inherent_impls.iter() { @@ -950,7 +951,6 @@ impl EncodeContext<'a, 'tcx> { record!(self.tables.fn_sig[def_id] <- tcx.fn_sig(ctor_def_id)); } } - self.encode_explicit_predicates(def_id); self.encode_inferred_outlives(def_id); } @@ -973,7 +973,6 @@ impl EncodeContext<'a, 'tcx> { if variant.ctor_kind == CtorKind::Fn { record!(self.tables.fn_sig[def_id] <- tcx.fn_sig(def_id)); } - self.encode_explicit_predicates(def_id); self.encode_inferred_outlives(def_id); } @@ -1033,7 +1032,6 @@ impl EncodeContext<'a, 'tcx> { record!(self.tables.kind[def_id] <- EntryKind::Field); self.encode_ident_span(def_id, field.ident); self.encode_item_type(def_id); - self.encode_explicit_predicates(def_id); self.encode_inferred_outlives(def_id); } @@ -1054,16 +1052,9 @@ impl EncodeContext<'a, 'tcx> { if variant.ctor_kind == CtorKind::Fn { record!(self.tables.fn_sig[def_id] <- tcx.fn_sig(def_id)); } - self.encode_explicit_predicates(def_id); self.encode_inferred_outlives(def_id); } - fn encode_explicit_predicates(&mut self, def_id: DefId) { - debug!("EncodeContext::encode_explicit_predicates({:?})", def_id); - record!(self.tables.explicit_predicates[def_id] <- - self.tcx.explicit_predicates_of(def_id)); - } - fn encode_inferred_outlives(&mut self, def_id: DefId) { debug!("EncodeContext::encode_inferred_outlives({:?})", def_id); let inferred_outlives = self.tcx.inferred_outlives_of(def_id); @@ -1152,7 +1143,6 @@ impl EncodeContext<'a, 'tcx> { if trait_item.kind == ty::AssocKind::Fn { record!(self.tables.fn_sig[def_id] <- tcx.fn_sig(def_id)); } - self.encode_explicit_predicates(def_id); self.encode_inferred_outlives(def_id); } @@ -1211,7 +1201,6 @@ impl EncodeContext<'a, 'tcx> { if impl_item.kind == ty::AssocKind::Fn { record!(self.tables.fn_sig[def_id] <- tcx.fn_sig(def_id)); } - self.encode_explicit_predicates(def_id); self.encode_inferred_outlives(def_id); } @@ -1489,7 +1478,6 @@ impl EncodeContext<'a, 'tcx> { | hir::ItemKind::OpaqueTy(..) | hir::ItemKind::Trait(..) | hir::ItemKind::TraitAlias(..) => { - self.encode_explicit_predicates(def_id); self.encode_inferred_outlives(def_id); } _ => {} @@ -1551,7 +1539,6 @@ impl EncodeContext<'a, 'tcx> { record!(self.tables.kind[def_id.to_def_id()] <- EntryKind::AnonConst(qualifs, const_data)); self.encode_item_type(def_id.to_def_id()); - self.encode_explicit_predicates(def_id.to_def_id()); self.encode_inferred_outlives(def_id.to_def_id()); } @@ -1832,7 +1819,6 @@ impl EncodeContext<'a, 'tcx> { if let hir::ForeignItemKind::Fn(..) = nitem.kind { record!(self.tables.fn_sig[def_id] <- tcx.fn_sig(def_id)); } - self.encode_explicit_predicates(def_id); self.encode_inferred_outlives(def_id); } } From 4223db76b95aab17bd00c5fe0446e70ab60aab2a Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sun, 6 Dec 2020 22:23:48 +0100 Subject: [PATCH 04/16] Iterate on inferred_outlives. --- compiler/rustc_metadata/src/rmeta/encoder.rs | 36 +++----------------- 1 file changed, 4 insertions(+), 32 deletions(-) diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index f042b5ad8e48b..101a9dc1b6833 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -906,6 +906,10 @@ impl EncodeContext<'a, 'tcx> { let g = tcx.generics_of(def_id); record!(self.tables.generics[def_id] <- g); record!(self.tables.explicit_predicates[def_id] <- self.tcx.explicit_predicates_of(def_id)); + let inferred_outlives = self.tcx.inferred_outlives_of(def_id); + if !inferred_outlives.is_empty() { + record!(self.tables.inferred_outlives[def_id] <- inferred_outlives); + } } let inherent_impls = tcx.crate_inherent_impls(LOCAL_CRATE); for (def_id, implementations) in inherent_impls.inherent_impls.iter() { @@ -951,7 +955,6 @@ impl EncodeContext<'a, 'tcx> { record!(self.tables.fn_sig[def_id] <- tcx.fn_sig(ctor_def_id)); } } - self.encode_inferred_outlives(def_id); } fn encode_enum_variant_ctor(&mut self, def: &ty::AdtDef, index: VariantIdx) { @@ -973,7 +976,6 @@ impl EncodeContext<'a, 'tcx> { if variant.ctor_kind == CtorKind::Fn { record!(self.tables.fn_sig[def_id] <- tcx.fn_sig(def_id)); } - self.encode_inferred_outlives(def_id); } fn encode_info_for_mod(&mut self, local_def_id: LocalDefId, md: &hir::Mod<'_>) { @@ -1032,7 +1034,6 @@ impl EncodeContext<'a, 'tcx> { record!(self.tables.kind[def_id] <- EntryKind::Field); self.encode_ident_span(def_id, field.ident); self.encode_item_type(def_id); - self.encode_inferred_outlives(def_id); } fn encode_struct_ctor(&mut self, adt_def: &ty::AdtDef, def_id: DefId) { @@ -1052,15 +1053,6 @@ impl EncodeContext<'a, 'tcx> { if variant.ctor_kind == CtorKind::Fn { record!(self.tables.fn_sig[def_id] <- tcx.fn_sig(def_id)); } - self.encode_inferred_outlives(def_id); - } - - fn encode_inferred_outlives(&mut self, def_id: DefId) { - debug!("EncodeContext::encode_inferred_outlives({:?})", def_id); - let inferred_outlives = self.tcx.inferred_outlives_of(def_id); - if !inferred_outlives.is_empty() { - record!(self.tables.inferred_outlives[def_id] <- inferred_outlives); - } } fn encode_super_predicates(&mut self, def_id: DefId) { @@ -1143,7 +1135,6 @@ impl EncodeContext<'a, 'tcx> { if trait_item.kind == ty::AssocKind::Fn { record!(self.tables.fn_sig[def_id] <- tcx.fn_sig(def_id)); } - self.encode_inferred_outlives(def_id); } fn encode_info_for_impl_item(&mut self, def_id: DefId) { @@ -1201,7 +1192,6 @@ impl EncodeContext<'a, 'tcx> { if impl_item.kind == ty::AssocKind::Fn { record!(self.tables.fn_sig[def_id] <- tcx.fn_sig(def_id)); } - self.encode_inferred_outlives(def_id); } fn encode_fn_param_names_for_body(&mut self, body_id: hir::BodyId) -> Lazy<[Ident]> { @@ -1466,22 +1456,6 @@ impl EncodeContext<'a, 'tcx> { record!(self.tables.impl_trait_ref[def_id] <- trait_ref); } } - match item.kind { - hir::ItemKind::Static(..) - | hir::ItemKind::Const(..) - | hir::ItemKind::Fn(..) - | hir::ItemKind::TyAlias(..) - | hir::ItemKind::Enum(..) - | hir::ItemKind::Struct(..) - | hir::ItemKind::Union(..) - | hir::ItemKind::Impl { .. } - | hir::ItemKind::OpaqueTy(..) - | hir::ItemKind::Trait(..) - | hir::ItemKind::TraitAlias(..) => { - self.encode_inferred_outlives(def_id); - } - _ => {} - } match item.kind { hir::ItemKind::Trait(..) | hir::ItemKind::TraitAlias(..) => { self.encode_super_predicates(def_id); @@ -1539,7 +1513,6 @@ impl EncodeContext<'a, 'tcx> { record!(self.tables.kind[def_id.to_def_id()] <- EntryKind::AnonConst(qualifs, const_data)); self.encode_item_type(def_id.to_def_id()); - self.encode_inferred_outlives(def_id.to_def_id()); } fn encode_native_libraries(&mut self) -> Lazy<[NativeLib]> { @@ -1819,7 +1792,6 @@ impl EncodeContext<'a, 'tcx> { if let hir::ForeignItemKind::Fn(..) = nitem.kind { record!(self.tables.fn_sig[def_id] <- tcx.fn_sig(def_id)); } - self.encode_inferred_outlives(def_id); } } From c74a3553ae2b50d6ec11ff660240fe7ba882c65e Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sat, 16 Jan 2021 23:18:00 +0100 Subject: [PATCH 05/16] Filter generics. --- compiler/rustc_metadata/src/rmeta/encoder.rs | 49 +++++++++++++++++--- 1 file changed, 43 insertions(+), 6 deletions(-) diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index 101a9dc1b6833..1dd5aac926740 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -871,6 +871,41 @@ fn should_encode_variances(def_kind: DefKind) -> bool { } } +fn should_encode_generics(def_kind: DefKind) -> bool { + match def_kind { + DefKind::Struct + | DefKind::Union + | DefKind::Enum + | DefKind::Variant + | DefKind::Trait + | DefKind::TyAlias + | DefKind::ForeignTy + | DefKind::TraitAlias + | DefKind::AssocTy + | DefKind::Fn + | DefKind::Const + | DefKind::Static + | DefKind::Ctor(..) + | DefKind::AssocFn + | DefKind::AssocConst + | DefKind::AnonConst + | DefKind::OpaqueTy + | DefKind::Impl + | DefKind::Closure + | DefKind::Generator => true, + DefKind::Mod + | DefKind::Field + | DefKind::ForeignMod + | DefKind::TyParam + | DefKind::ConstParam + | DefKind::Macro(..) + | DefKind::Use + | DefKind::LifetimeParam + | DefKind::GlobalAsm + | DefKind::ExternCrate => false, + } +} + impl EncodeContext<'a, 'tcx> { fn encode_def_ids(&mut self) { if self.is_proc_macro { @@ -903,12 +938,14 @@ impl EncodeContext<'a, 'tcx> { let v = self.tcx.variances_of(def_id); record!(self.tables.variances[def_id] <- v); } - let g = tcx.generics_of(def_id); - record!(self.tables.generics[def_id] <- g); - record!(self.tables.explicit_predicates[def_id] <- self.tcx.explicit_predicates_of(def_id)); - let inferred_outlives = self.tcx.inferred_outlives_of(def_id); - if !inferred_outlives.is_empty() { - record!(self.tables.inferred_outlives[def_id] <- inferred_outlives); + if should_encode_generics(def_kind) { + let g = tcx.generics_of(def_id); + record!(self.tables.generics[def_id] <- g); + record!(self.tables.explicit_predicates[def_id] <- self.tcx.explicit_predicates_of(def_id)); + let inferred_outlives = self.tcx.inferred_outlives_of(def_id); + if !inferred_outlives.is_empty() { + record!(self.tables.inferred_outlives[def_id] <- inferred_outlives); + } } } let inherent_impls = tcx.crate_inherent_impls(LOCAL_CRATE); From fcd6f20700848d9220bae663b7a41cea4e94f280 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sat, 6 Feb 2021 10:36:23 +0100 Subject: [PATCH 06/16] Iterate for super_predicates. --- compiler/rustc_metadata/src/rmeta/encoder.rs | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index 1dd5aac926740..254954c83762a 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -947,6 +947,9 @@ impl EncodeContext<'a, 'tcx> { record!(self.tables.inferred_outlives[def_id] <- inferred_outlives); } } + if let DefKind::Trait | DefKind::TraitAlias = def_kind { + record!(self.tables.super_predicates[def_id] <- self.tcx.super_predicates_of(def_id)); + } } let inherent_impls = tcx.crate_inherent_impls(LOCAL_CRATE); for (def_id, implementations) in inherent_impls.inherent_impls.iter() { @@ -1092,11 +1095,6 @@ impl EncodeContext<'a, 'tcx> { } } - fn encode_super_predicates(&mut self, def_id: DefId) { - debug!("EncodeContext::encode_super_predicates({:?})", def_id); - record!(self.tables.super_predicates[def_id] <- self.tcx.super_predicates_of(def_id)); - } - fn encode_explicit_item_bounds(&mut self, def_id: DefId) { debug!("EncodeContext::encode_explicit_item_bounds({:?})", def_id); let bounds = self.tcx.explicit_item_bounds(def_id); @@ -1493,12 +1491,6 @@ impl EncodeContext<'a, 'tcx> { record!(self.tables.impl_trait_ref[def_id] <- trait_ref); } } - match item.kind { - hir::ItemKind::Trait(..) | hir::ItemKind::TraitAlias(..) => { - self.encode_super_predicates(def_id); - } - _ => {} - } } /// Serialize the text of exported macros From 1842886d636ed773b56b863eb70a9f8210ece1f2 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Wed, 23 Dec 2020 12:33:33 +0100 Subject: [PATCH 07/16] Infallible version of type_of. --- .../src/persist/dirty_clean.rs | 6 +- .../src/rmeta/decoder/cstore_impl.rs | 2 +- compiler/rustc_middle/src/query/mod.rs | 2 +- compiler/rustc_middle/src/ty/query/mod.rs | 16 ++++ compiler/rustc_typeck/src/collect.rs | 34 ++++---- compiler/rustc_typeck/src/collect/type_of.rs | 23 ++--- src/test/incremental/hashes/consts.rs | 8 +- src/test/incremental/hashes/enum_defs.rs | 38 ++++----- .../incremental/hashes/function_interfaces.rs | 6 +- src/test/incremental/hashes/inherent_impls.rs | 10 +-- src/test/incremental/hashes/statics.rs | 8 +- src/test/incremental/hashes/struct_defs.rs | 84 +++++++++---------- .../cycle-trait-default-type-trait.rs | 1 - .../cycle-trait-default-type-trait.stderr | 15 +--- .../dep-graph/dep-graph-struct-signature.rs | 14 ++-- .../dep-graph-struct-signature.stderr | 34 ++++---- src/test/ui/dep-graph/dep-graph-type-alias.rs | 14 ++-- .../ui/dep-graph/dep-graph-type-alias.stderr | 36 ++++---- src/test/ui/impl-trait/auto-trait-leak.rs | 1 - src/test/ui/impl-trait/auto-trait-leak.stderr | 34 ++------ src/test/ui/resolve/resolve-self-in-impl.rs | 8 +- .../ui/resolve/resolve-self-in-impl.stderr | 78 +---------------- 22 files changed, 191 insertions(+), 281 deletions(-) diff --git a/compiler/rustc_incremental/src/persist/dirty_clean.rs b/compiler/rustc_incremental/src/persist/dirty_clean.rs index 0b544b8ab415e..4ceb66b2245e8 100644 --- a/compiler/rustc_incremental/src/persist/dirty_clean.rs +++ b/compiler/rustc_incremental/src/persist/dirty_clean.rs @@ -37,7 +37,7 @@ const CFG: Symbol = sym::cfg; // Base and Extra labels to build up the labels /// For typedef, constants, and statics -const BASE_CONST: &[&str] = &[label_strs::type_of]; +const BASE_CONST: &[&str] = &[label_strs::try_type_of]; /// DepNodes for functions + methods const BASE_FN: &[&str] = &[ @@ -45,7 +45,7 @@ const BASE_FN: &[&str] = &[ label_strs::fn_sig, label_strs::generics_of, label_strs::predicates_of, - label_strs::type_of, + label_strs::try_type_of, // And a big part of compilation (that we eventually want to cache) is type inference // information: label_strs::typeck, @@ -71,7 +71,7 @@ const BASE_MIR: &[&str] = &[label_strs::optimized_mir, label_strs::promoted_mir] /// Note that changing the type of a field does not change the type of the struct or enum, but /// adding/removing fields or changing a fields name or visibility does. const BASE_STRUCT: &[&str] = - &[label_strs::generics_of, label_strs::predicates_of, label_strs::type_of]; + &[label_strs::generics_of, label_strs::predicates_of, label_strs::try_type_of]; /// Trait definition `DepNode`s. const BASE_TRAIT_DEF: &[&str] = &[ diff --git a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs index 0f860d11dc21a..abaef4667a613 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs @@ -90,7 +90,7 @@ impl IntoArgs for (CrateNum, DefId) { } provide! { <'tcx> tcx, def_id, other, cdata, - type_of => { cdata.get_type(def_id.index, tcx) } + try_type_of => { Ok(cdata.get_type(def_id.index, tcx)) } generics_of => { cdata.get_generics(def_id.index, tcx.sess) } explicit_predicates_of => { cdata.get_explicit_predicates(def_id.index, tcx) } inferred_outlives_of => { cdata.get_inferred_outlives(def_id.index, tcx) } diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs index b03b26d64606c..0746c3fa0e84e 100644 --- a/compiler/rustc_middle/src/query/mod.rs +++ b/compiler/rustc_middle/src/query/mod.rs @@ -94,7 +94,7 @@ rustc_queries! { } /// Records the type of every item. - query type_of(key: DefId) -> Ty<'tcx> { + query try_type_of(key: DefId) -> Result, String> { desc { |tcx| "computing type of `{}`", tcx.def_path_str(key) } cache_on_disk_if { key.is_local() } } diff --git a/compiler/rustc_middle/src/ty/query/mod.rs b/compiler/rustc_middle/src/ty/query/mod.rs index 51a214bc07bac..76d57dbbc0d5f 100644 --- a/compiler/rustc_middle/src/ty/query/mod.rs +++ b/compiler/rustc_middle/src/ty/query/mod.rs @@ -312,6 +312,14 @@ impl TyCtxt<'tcx> { self.opt_def_kind(def_id) .unwrap_or_else(|| bug!("def_kind: unsupported node: {:?}", def_id)) } + + pub fn type_of(self, def_id: impl IntoQueryParam) -> Ty<'tcx> { + let def_id = def_id.into_query_param(); + self.try_type_of(def_id).unwrap_or_else(|msg| { + let hir_id = self.hir().local_def_id_to_hir_id(def_id.expect_local()); + span_bug!(self.def_span(def_id), "type_of: {}: {:?}", msg, self.hir().find(hir_id)); + }) + } } impl TyCtxtAt<'tcx> { @@ -320,4 +328,12 @@ impl TyCtxtAt<'tcx> { self.opt_def_kind(def_id) .unwrap_or_else(|| bug!("def_kind: unsupported node: {:?}", def_id)) } + + pub fn type_of(self, def_id: impl IntoQueryParam) -> Ty<'tcx> { + let def_id = def_id.into_query_param(); + self.try_type_of(def_id).unwrap_or_else(|msg| { + let hir_id = self.hir().local_def_id_to_hir_id(def_id.expect_local()); + span_bug!(self.def_span(def_id), "type_of: {}: {:?}", msg, self.hir().find(hir_id)); + }) + } } diff --git a/compiler/rustc_typeck/src/collect.rs b/compiler/rustc_typeck/src/collect.rs index a175da3270638..3d44deb88569f 100644 --- a/compiler/rustc_typeck/src/collect.rs +++ b/compiler/rustc_typeck/src/collect.rs @@ -69,7 +69,7 @@ fn collect_mod_item_types(tcx: TyCtxt<'_>, module_def_id: LocalDefId) { pub fn provide(providers: &mut Providers) { *providers = Providers { opt_const_param_of: type_of::opt_const_param_of, - type_of: type_of::type_of, + try_type_of: type_of::try_type_of, item_bounds: item_bounds::item_bounds, explicit_item_bounds: item_bounds::explicit_item_bounds, generics_of, @@ -251,12 +251,12 @@ impl Visitor<'tcx> for CollectItemTypesVisitor<'tcx> { hir::GenericParamKind::Lifetime { .. } => {} hir::GenericParamKind::Type { default: Some(_), .. } => { let def_id = self.tcx.hir().local_def_id(param.hir_id); - self.tcx.ensure().type_of(def_id); + self.tcx.ensure().try_type_of(def_id); } hir::GenericParamKind::Type { .. } => {} hir::GenericParamKind::Const { .. } => { let def_id = self.tcx.hir().local_def_id(param.hir_id); - self.tcx.ensure().type_of(def_id); + self.tcx.ensure().try_type_of(def_id); // FIXME(const_generics_defaults) } } @@ -268,7 +268,7 @@ impl Visitor<'tcx> for CollectItemTypesVisitor<'tcx> { if let hir::ExprKind::Closure(..) = expr.kind { let def_id = self.tcx.hir().local_def_id(expr.hir_id); self.tcx.ensure().generics_of(def_id); - self.tcx.ensure().type_of(def_id); + self.tcx.ensure().try_type_of(def_id); } intravisit::walk_expr(self, expr); } @@ -727,7 +727,7 @@ fn convert_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) { for item in items { let item = tcx.hir().foreign_item(item.id); tcx.ensure().generics_of(item.def_id); - tcx.ensure().type_of(item.def_id); + tcx.ensure().try_type_of(item.def_id); tcx.ensure().predicates_of(item.def_id); if let hir::ForeignItemKind::Fn(..) = item.kind { tcx.ensure().fn_sig(item.def_id); @@ -736,13 +736,13 @@ fn convert_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) { } hir::ItemKind::Enum(ref enum_definition, _) => { tcx.ensure().generics_of(def_id); - tcx.ensure().type_of(def_id); + tcx.ensure().try_type_of(def_id); tcx.ensure().predicates_of(def_id); convert_enum_variant_types(tcx, def_id.to_def_id(), &enum_definition.variants); } hir::ItemKind::Impl { .. } => { tcx.ensure().generics_of(def_id); - tcx.ensure().type_of(def_id); + tcx.ensure().try_type_of(def_id); tcx.ensure().impl_trait_ref(def_id); tcx.ensure().predicates_of(def_id); } @@ -759,13 +759,13 @@ fn convert_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) { } hir::ItemKind::Struct(ref struct_def, _) | hir::ItemKind::Union(ref struct_def, _) => { tcx.ensure().generics_of(def_id); - tcx.ensure().type_of(def_id); + tcx.ensure().try_type_of(def_id); tcx.ensure().predicates_of(def_id); for f in struct_def.fields() { let def_id = tcx.hir().local_def_id(f.hir_id); tcx.ensure().generics_of(def_id); - tcx.ensure().type_of(def_id); + tcx.ensure().try_type_of(def_id); tcx.ensure().predicates_of(def_id); } @@ -790,7 +790,7 @@ fn convert_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) { | hir::ItemKind::Const(..) | hir::ItemKind::Fn(..) => { tcx.ensure().generics_of(def_id); - tcx.ensure().type_of(def_id); + tcx.ensure().try_type_of(def_id); tcx.ensure().predicates_of(def_id); match it.kind { hir::ItemKind::Fn(..) => tcx.ensure().fn_sig(def_id), @@ -807,16 +807,16 @@ fn convert_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::TraitItemId) { match trait_item.kind { hir::TraitItemKind::Fn(..) => { - tcx.ensure().type_of(trait_item_id.def_id); + tcx.ensure().try_type_of(trait_item_id.def_id); tcx.ensure().fn_sig(trait_item_id.def_id); } hir::TraitItemKind::Const(.., Some(_)) => { - tcx.ensure().type_of(trait_item_id.def_id); + tcx.ensure().try_type_of(trait_item_id.def_id); } hir::TraitItemKind::Const(..) => { - tcx.ensure().type_of(trait_item_id.def_id); + tcx.ensure().try_type_of(trait_item_id.def_id); // Account for `const C: _;`. let mut visitor = PlaceholderHirTyCollector::default(); visitor.visit_trait_item(trait_item); @@ -825,7 +825,7 @@ fn convert_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::TraitItemId) { hir::TraitItemKind::Type(_, Some(_)) => { tcx.ensure().item_bounds(trait_item_id.def_id); - tcx.ensure().type_of(trait_item_id.def_id); + tcx.ensure().try_type_of(trait_item_id.def_id); // Account for `type T = _;`. let mut visitor = PlaceholderHirTyCollector::default(); visitor.visit_trait_item(trait_item); @@ -849,7 +849,7 @@ fn convert_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::TraitItemId) { fn convert_impl_item(tcx: TyCtxt<'_>, impl_item_id: hir::ImplItemId) { let def_id = impl_item_id.def_id; tcx.ensure().generics_of(def_id); - tcx.ensure().type_of(def_id); + tcx.ensure().try_type_of(def_id); tcx.ensure().predicates_of(def_id); let impl_item = tcx.hir().impl_item(impl_item_id); match impl_item.kind { @@ -870,7 +870,7 @@ fn convert_impl_item(tcx: TyCtxt<'_>, impl_item_id: hir::ImplItemId) { fn convert_variant_ctor(tcx: TyCtxt<'_>, ctor_id: hir::HirId) { let def_id = tcx.hir().local_def_id(ctor_id); tcx.ensure().generics_of(def_id); - tcx.ensure().type_of(def_id); + tcx.ensure().try_type_of(def_id); tcx.ensure().predicates_of(def_id); } @@ -908,7 +908,7 @@ fn convert_enum_variant_types(tcx: TyCtxt<'_>, def_id: DefId, variants: &[hir::V for f in variant.data.fields() { let def_id = tcx.hir().local_def_id(f.hir_id); tcx.ensure().generics_of(def_id); - tcx.ensure().type_of(def_id); + tcx.ensure().try_type_of(def_id); tcx.ensure().predicates_of(def_id); } diff --git a/compiler/rustc_typeck/src/collect/type_of.rs b/compiler/rustc_typeck/src/collect/type_of.rs index 3f2f244e44fd2..3d4c5f3e3c875 100644 --- a/compiler/rustc_typeck/src/collect/type_of.rs +++ b/compiler/rustc_typeck/src/collect/type_of.rs @@ -250,7 +250,7 @@ fn get_path_containing_arg_in_pat<'hir>( arg_path } -pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> { +pub(super) fn try_type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Result, String> { let def_id = def_id.expect_local(); use rustc_hir::*; @@ -258,7 +258,8 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> { let icx = ItemCtxt::new(tcx, def_id.to_def_id()); - match tcx.hir().get(hir_id) { + let node = tcx.hir().find(hir_id).ok_or_else(|| format!("Not found in HIR: {:?}", hir_id))?; + let ty = match node { Node::TraitItem(item) => match item.kind { TraitItemKind::Fn(..) => { let substs = InternalSubsts::identity_for_item(tcx, def_id.to_def_id()); @@ -275,7 +276,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> { .unwrap_or_else(|| icx.to_ty(ty)), TraitItemKind::Type(_, Some(ref ty)) => icx.to_ty(ty), TraitItemKind::Type(_, None) => { - span_bug!(item.span, "associated type missing default"); + return Err("associated type missing default".to_owned()); } }, @@ -368,11 +369,10 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> { | ItemKind::GlobalAsm(..) | ItemKind::ExternCrate(..) | ItemKind::Use(..) => { - span_bug!( - item.span, + return Err(format!( "compute_type_of_item: unexpected item type: {:?}", item.kind - ); + )); } } } @@ -388,7 +388,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> { Node::Ctor(&ref def) | Node::Variant(Variant { data: ref def, .. }) => match *def { VariantData::Unit(..) | VariantData::Struct(..) => { - tcx.type_of(tcx.hir().get_parent_did(hir_id).to_def_id()) + return tcx.try_type_of(tcx.hir().get_parent_did(hir_id).to_def_id()); } VariantData::Tuple(..) => { let substs = InternalSubsts::identity_for_item(tcx, def_id.to_def_id()); @@ -411,7 +411,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> { if let Some(param) = tcx.opt_const_param_of(def_id) { // We defer to `type_of` of the corresponding parameter // for generic arguments. - return tcx.type_of(param); + return tcx.try_type_of(param); } let parent_node = tcx.hir().get(tcx.hir().get_parent_node(hir_id)); @@ -446,13 +446,14 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> { Node::GenericParam(param) => match ¶m.kind { GenericParamKind::Type { default: Some(ty), .. } | GenericParamKind::Const { ty, .. } => icx.to_ty(ty), - x => bug!("unexpected non-type Node::GenericParam: {:?}", x), + x => return Err(format!("unexpected non-type Node::GenericParam: {:?}", x)), }, x => { - bug!("unexpected sort of node in type_of_def_id(): {:?}", x); + return Err(format!("unexpected sort of node in type_of_def_id(): {:?}", x)); } - } + }; + Ok(ty) } fn find_opaque_ty_constraints(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Ty<'_> { diff --git a/src/test/incremental/hashes/consts.rs b/src/test/incremental/hashes/consts.rs index 6e0db6a49aae2..2458320440917 100644 --- a/src/test/incremental/hashes/consts.rs +++ b/src/test/incremental/hashes/consts.rs @@ -29,7 +29,7 @@ pub const CONST_VISIBILITY: u8 = 0; const CONST_CHANGE_TYPE_1: i32 = 0; #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,type_of")] +#[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,try_type_of")] #[rustc_clean(cfg="cfail3")] const CONST_CHANGE_TYPE_1: u32 = 0; @@ -39,7 +39,7 @@ const CONST_CHANGE_TYPE_1: u32 = 0; const CONST_CHANGE_TYPE_2: Option = None; #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,type_of")] +#[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,try_type_of")] #[rustc_clean(cfg="cfail3")] const CONST_CHANGE_TYPE_2: Option = None; @@ -99,11 +99,11 @@ mod const_change_type_indirectly { #[cfg(not(cfail1))] use super::ReferencedType2 as Type; - #[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,type_of")] + #[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,try_type_of")] #[rustc_clean(cfg="cfail3")] const CONST_CHANGE_TYPE_INDIRECTLY_1: Type = Type; - #[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,type_of")] + #[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,try_type_of")] #[rustc_clean(cfg="cfail3")] const CONST_CHANGE_TYPE_INDIRECTLY_2: Option = None; } diff --git a/src/test/incremental/hashes/enum_defs.rs b/src/test/incremental/hashes/enum_defs.rs index c73c03ca14e56..a39d7b41eee25 100644 --- a/src/test/incremental/hashes/enum_defs.rs +++ b/src/test/incremental/hashes/enum_defs.rs @@ -42,7 +42,7 @@ enum EnumChangeNameCStyleVariant { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,type_of")] +#[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,try_type_of")] #[rustc_clean(cfg="cfail3")] enum EnumChangeNameCStyleVariant { Variant1, @@ -59,7 +59,7 @@ enum EnumChangeNameTupleStyleVariant { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,type_of")] +#[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,try_type_of")] #[rustc_clean(cfg="cfail3")] enum EnumChangeNameTupleStyleVariant { Variant1, @@ -76,7 +76,7 @@ enum EnumChangeNameStructStyleVariant { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,type_of")] +#[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,try_type_of")] #[rustc_clean(cfg="cfail3")] enum EnumChangeNameStructStyleVariant { Variant1, @@ -109,7 +109,7 @@ enum EnumChangeValueCStyleVariant1 { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,type_of")] +#[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,try_type_of")] #[rustc_clean(cfg="cfail3")] enum EnumChangeValueCStyleVariant1 { Variant1, @@ -125,7 +125,7 @@ enum EnumAddCStyleVariant { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,type_of")] +#[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,try_type_of")] #[rustc_clean(cfg="cfail3")] enum EnumAddCStyleVariant { Variant1, @@ -142,7 +142,7 @@ enum EnumRemoveCStyleVariant { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,type_of")] +#[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,try_type_of")] #[rustc_clean(cfg="cfail3")] enum EnumRemoveCStyleVariant { Variant1, @@ -157,7 +157,7 @@ enum EnumAddTupleStyleVariant { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,type_of")] +#[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,try_type_of")] #[rustc_clean(cfg="cfail3")] enum EnumAddTupleStyleVariant { Variant1, @@ -174,7 +174,7 @@ enum EnumRemoveTupleStyleVariant { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,type_of")] +#[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,try_type_of")] #[rustc_clean(cfg="cfail3")] enum EnumRemoveTupleStyleVariant { Variant1, @@ -189,7 +189,7 @@ enum EnumAddStructStyleVariant { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,type_of")] +#[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,try_type_of")] #[rustc_clean(cfg="cfail3")] enum EnumAddStructStyleVariant { Variant1, @@ -206,7 +206,7 @@ enum EnumRemoveStructStyleVariant { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,type_of")] +#[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,try_type_of")] #[rustc_clean(cfg="cfail3")] enum EnumRemoveStructStyleVariant { Variant1, @@ -257,7 +257,7 @@ enum EnumChangeFieldNameStructStyleVariant { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,type_of")] +#[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,try_type_of")] #[rustc_clean(cfg="cfail3")] enum EnumChangeFieldNameStructStyleVariant { Variant1 { a: u32, c: u32 }, @@ -289,7 +289,7 @@ enum EnumChangeFieldOrderStructStyleVariant { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,type_of")] +#[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,try_type_of")] #[rustc_clean(cfg="cfail3")] enum EnumChangeFieldOrderStructStyleVariant { Variant1 { b: f32, a: u32 }, @@ -304,7 +304,7 @@ enum EnumAddFieldTupleStyleVariant { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,type_of")] +#[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,try_type_of")] #[rustc_clean(cfg="cfail3")] enum EnumAddFieldTupleStyleVariant { Variant1(u32, u32, u32), @@ -319,7 +319,7 @@ enum EnumAddFieldStructStyleVariant { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,type_of")] +#[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,try_type_of")] #[rustc_clean(cfg="cfail3")] enum EnumAddFieldStructStyleVariant { Variant1 { a: u32, b: u32, c: u32 }, @@ -353,7 +353,7 @@ enum EnumAddReprC { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="type_of")] +#[rustc_clean(cfg="cfail2", except="try_type_of")] #[rustc_clean(cfg="cfail3")] #[repr(C)] enum EnumAddReprC { @@ -435,7 +435,7 @@ enum EnumAddLifetimeParameterBound<'a, 'b> { } #[cfg(not(cfail1))] -#[rustc_dirty(cfg="cfail2", except="generics_of,type_of")] +#[rustc_dirty(cfg="cfail2", except="generics_of,try_type_of")] #[rustc_clean(cfg="cfail3")] enum EnumAddLifetimeParameterBound<'a, 'b: 'a> { Variant1(&'a u32), @@ -450,7 +450,7 @@ enum EnumAddLifetimeBoundToParameter<'a, T> { } #[cfg(not(cfail1))] -#[rustc_dirty(cfg="cfail2", except="type_of")] +#[rustc_dirty(cfg="cfail2", except="try_type_of")] #[rustc_clean(cfg="cfail3")] enum EnumAddLifetimeBoundToParameter<'a, T: 'a> { Variant1(T), @@ -482,7 +482,7 @@ enum EnumAddLifetimeParameterBoundWhere<'a, 'b> { } #[cfg(not(cfail1))] -#[rustc_dirty(cfg="cfail2", except="generics_of,type_of")] +#[rustc_dirty(cfg="cfail2", except="generics_of,try_type_of")] #[rustc_clean(cfg="cfail3")] enum EnumAddLifetimeParameterBoundWhere<'a, 'b> where 'b: 'a { Variant1(&'a u32), @@ -499,7 +499,7 @@ enum EnumAddLifetimeBoundToParameterWhere<'a, T> { } #[cfg(not(cfail1))] -#[rustc_dirty(cfg="cfail2", except="type_of")] +#[rustc_dirty(cfg="cfail2", except="try_type_of")] #[rustc_clean(cfg="cfail3")] enum EnumAddLifetimeBoundToParameterWhere<'a, T> where T: 'a { Variant1(T), diff --git a/src/test/incremental/hashes/function_interfaces.rs b/src/test/incremental/hashes/function_interfaces.rs index ed67b2dcb0480..c1062400c03db 100644 --- a/src/test/incremental/hashes/function_interfaces.rs +++ b/src/test/incremental/hashes/function_interfaces.rs @@ -107,7 +107,7 @@ pub fn type_parameter() {} #[cfg(not(cfail1))] #[rustc_clean( cfg = "cfail2", - except = "hir_owner, hir_owner_nodes, generics_of, type_of, predicates_of" + except = "hir_owner, hir_owner_nodes, generics_of, try_type_of, predicates_of" )] #[rustc_clean(cfg = "cfail3")] pub fn type_parameter() {} @@ -150,7 +150,7 @@ pub fn lifetime_bound<'a, T>() {} #[cfg(not(cfail1))] #[rustc_clean( cfg = "cfail2", - except = "hir_owner, hir_owner_nodes, generics_of, type_of, predicates_of" + except = "hir_owner, hir_owner_nodes, generics_of, try_type_of, predicates_of" )] #[rustc_clean(cfg = "cfail3")] pub fn lifetime_bound<'a, T: 'a>() {} @@ -183,7 +183,7 @@ pub fn second_lifetime_bound<'a, 'b, T: 'a>() {} #[cfg(not(cfail1))] #[rustc_clean( cfg = "cfail2", - except = "hir_owner, hir_owner_nodes, generics_of, type_of, predicates_of" + except = "hir_owner, hir_owner_nodes, generics_of, try_type_of, predicates_of" )] #[rustc_clean(cfg = "cfail3")] pub fn second_lifetime_bound<'a, 'b, T: 'a + 'b>() {} diff --git a/src/test/incremental/hashes/inherent_impls.rs b/src/test/incremental/hashes/inherent_impls.rs index ae8f2ace217dc..8d49ab4b67859 100644 --- a/src/test/incremental/hashes/inherent_impls.rs +++ b/src/test/incremental/hashes/inherent_impls.rs @@ -103,7 +103,7 @@ impl Foo { #[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes")] #[rustc_clean(cfg="cfail3")] impl Foo { - #[rustc_dirty(cfg="cfail2", except="type_of,predicates_of,promoted_mir")] + #[rustc_dirty(cfg="cfail2", except="try_type_of,predicates_of,promoted_mir")] #[rustc_clean(cfg="cfail3")] pub fn method_selfness(&self) { } } @@ -340,7 +340,7 @@ impl Foo { // appear dirty, that might be the cause. -nmatsakis #[rustc_clean( cfg="cfail2", - except="hir_owner,hir_owner_nodes,generics_of,predicates_of,type_of", + except="hir_owner,hir_owner_nodes,generics_of,predicates_of,try_type_of", )] #[rustc_clean(cfg="cfail3")] pub fn add_type_parameter_to_method(&self) { } @@ -360,7 +360,7 @@ impl Foo { impl Foo { #[rustc_clean( cfg="cfail2", - except="hir_owner,hir_owner_nodes,generics_of,predicates_of,type_of" + except="hir_owner,hir_owner_nodes,generics_of,predicates_of,try_type_of" )] #[rustc_clean(cfg="cfail3")] pub fn add_lifetime_bound_to_lifetime_param_of_method<'a, 'b: 'a>(&self) { } @@ -388,7 +388,7 @@ impl Foo { // body will be affected. So if you start to see `typeck` // appear dirty, that might be the cause. -nmatsakis #[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,generics_of,predicates_of,\ - type_of")] + try_type_of")] #[rustc_clean(cfg="cfail3")] pub fn add_lifetime_bound_to_type_param_of_method<'a, T: 'a>(&self) { } } @@ -453,7 +453,7 @@ impl Bar { impl Bar { #[rustc_clean( cfg="cfail2", - except="generics_of,fn_sig,typeck,type_of,optimized_mir" + except="generics_of,fn_sig,typeck,try_type_of,optimized_mir" )] #[rustc_clean(cfg="cfail3")] pub fn add_type_parameter_to_impl(&self) { } diff --git a/src/test/incremental/hashes/statics.rs b/src/test/incremental/hashes/statics.rs index 6f4089c60fe23..d121872ed78fd 100644 --- a/src/test/incremental/hashes/statics.rs +++ b/src/test/incremental/hashes/statics.rs @@ -74,7 +74,7 @@ static STATIC_THREAD_LOCAL: u8 = 0; static STATIC_CHANGE_TYPE_1: i16 = 0; #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,type_of")] +#[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,try_type_of")] #[rustc_clean(cfg="cfail3")] static STATIC_CHANGE_TYPE_1: u64 = 0; @@ -84,7 +84,7 @@ static STATIC_CHANGE_TYPE_1: u64 = 0; static STATIC_CHANGE_TYPE_2: Option = None; #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,type_of")] +#[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,try_type_of")] #[rustc_clean(cfg="cfail3")] static STATIC_CHANGE_TYPE_2: Option = None; @@ -144,11 +144,11 @@ mod static_change_type_indirectly { #[cfg(not(cfail1))] use super::ReferencedType2 as Type; - #[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,type_of")] + #[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,try_type_of")] #[rustc_clean(cfg="cfail3")] static STATIC_CHANGE_TYPE_INDIRECTLY_1: Type = Type; - #[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,type_of")] + #[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,try_type_of")] #[rustc_clean(cfg="cfail3")] static STATIC_CHANGE_TYPE_INDIRECTLY_2: Option = None; } diff --git a/src/test/incremental/hashes/struct_defs.rs b/src/test/incremental/hashes/struct_defs.rs index 1339a1e5bf216..97f32b1437973 100644 --- a/src/test/incremental/hashes/struct_defs.rs +++ b/src/test/incremental/hashes/struct_defs.rs @@ -26,12 +26,12 @@ pub struct LayoutPacked; #[cfg(not(cfail1))] #[rustc_clean(label="hir_owner", cfg="cfail2")] #[rustc_clean(label="hir_owner_nodes", cfg="cfail2")] -#[rustc_dirty(label="type_of", cfg="cfail2")] +#[rustc_dirty(label="try_type_of", cfg="cfail2")] #[rustc_clean(label="generics_of", cfg="cfail2")] #[rustc_clean(label="predicates_of", cfg="cfail2")] #[rustc_clean(label="hir_owner", cfg="cfail3")] #[rustc_clean(label="hir_owner_nodes", cfg="cfail3")] -#[rustc_clean(label="type_of", cfg="cfail3")] +#[rustc_clean(label="try_type_of", cfg="cfail3")] #[rustc_clean(label="generics_of", cfg="cfail3")] #[rustc_clean(label="predicates_of", cfg="cfail3")] #[repr(packed)] @@ -43,12 +43,12 @@ struct LayoutC; #[cfg(not(cfail1))] #[rustc_clean(label="hir_owner", cfg="cfail2")] #[rustc_clean(label="hir_owner_nodes", cfg="cfail2")] -#[rustc_dirty(label="type_of", cfg="cfail2")] +#[rustc_dirty(label="try_type_of", cfg="cfail2")] #[rustc_clean(label="generics_of", cfg="cfail2")] #[rustc_clean(label="predicates_of", cfg="cfail2")] #[rustc_clean(label="hir_owner", cfg="cfail3")] #[rustc_clean(label="hir_owner_nodes", cfg="cfail3")] -#[rustc_clean(label="type_of", cfg="cfail3")] +#[rustc_clean(label="try_type_of", cfg="cfail3")] #[rustc_clean(label="generics_of", cfg="cfail3")] #[rustc_clean(label="predicates_of", cfg="cfail3")] #[repr(C)] @@ -63,12 +63,12 @@ struct TupleStructFieldType(i32); #[cfg(not(cfail1))] #[rustc_dirty(label="hir_owner", cfg="cfail2")] #[rustc_dirty(label="hir_owner_nodes", cfg="cfail2")] -#[rustc_clean(label="type_of", cfg="cfail2")] +#[rustc_clean(label="try_type_of", cfg="cfail2")] #[rustc_clean(label="generics_of", cfg="cfail2")] #[rustc_clean(label="predicates_of", cfg="cfail2")] #[rustc_clean(label="hir_owner", cfg="cfail3")] #[rustc_clean(label="hir_owner_nodes", cfg="cfail3")] -#[rustc_clean(label="type_of", cfg="cfail3")] +#[rustc_clean(label="try_type_of", cfg="cfail3")] #[rustc_clean(label="generics_of", cfg="cfail3")] #[rustc_clean(label="predicates_of", cfg="cfail3")] // Note that changing the type of a field does not change the type of the struct or enum, but @@ -86,12 +86,12 @@ struct TupleStructAddField(i32); #[cfg(not(cfail1))] #[rustc_dirty(label="hir_owner", cfg="cfail2")] #[rustc_dirty(label="hir_owner_nodes", cfg="cfail2")] -#[rustc_dirty(label="type_of", cfg="cfail2")] +#[rustc_dirty(label="try_type_of", cfg="cfail2")] #[rustc_clean(label="generics_of", cfg="cfail2")] #[rustc_clean(label="predicates_of", cfg="cfail2")] #[rustc_clean(label="hir_owner", cfg="cfail3")] #[rustc_clean(label="hir_owner_nodes", cfg="cfail3")] -#[rustc_clean(label="type_of", cfg="cfail3")] +#[rustc_clean(label="try_type_of", cfg="cfail3")] #[rustc_clean(label="generics_of", cfg="cfail3")] #[rustc_clean(label="predicates_of", cfg="cfail3")] struct TupleStructAddField( @@ -108,12 +108,12 @@ struct TupleStructFieldVisibility(char); #[cfg(not(cfail1))] #[rustc_dirty(label="hir_owner", cfg="cfail2")] #[rustc_dirty(label="hir_owner_nodes", cfg="cfail2")] -#[rustc_dirty(label="type_of", cfg="cfail2")] +#[rustc_dirty(label="try_type_of", cfg="cfail2")] #[rustc_clean(label="generics_of", cfg="cfail2")] #[rustc_clean(label="predicates_of", cfg="cfail2")] #[rustc_clean(label="hir_owner", cfg="cfail3")] #[rustc_clean(label="hir_owner_nodes", cfg="cfail3")] -#[rustc_clean(label="type_of", cfg="cfail3")] +#[rustc_clean(label="try_type_of", cfg="cfail3")] #[rustc_clean(label="generics_of", cfg="cfail3")] #[rustc_clean(label="predicates_of", cfg="cfail3")] struct TupleStructFieldVisibility(pub char); @@ -127,12 +127,12 @@ struct RecordStructFieldType { x: f32 } #[cfg(not(cfail1))] #[rustc_dirty(label="hir_owner", cfg="cfail2")] #[rustc_dirty(label="hir_owner_nodes", cfg="cfail2")] -#[rustc_clean(label="type_of", cfg="cfail2")] +#[rustc_clean(label="try_type_of", cfg="cfail2")] #[rustc_clean(label="generics_of", cfg="cfail2")] #[rustc_clean(label="predicates_of", cfg="cfail2")] #[rustc_clean(label="hir_owner", cfg="cfail3")] #[rustc_clean(label="hir_owner_nodes", cfg="cfail3")] -#[rustc_clean(label="type_of", cfg="cfail3")] +#[rustc_clean(label="try_type_of", cfg="cfail3")] #[rustc_clean(label="generics_of", cfg="cfail3")] #[rustc_clean(label="predicates_of", cfg="cfail3")] // Note that changing the type of a field does not change the type of the struct or enum, but @@ -150,12 +150,12 @@ struct RecordStructFieldName { x: f32 } #[cfg(not(cfail1))] #[rustc_dirty(label="hir_owner", cfg="cfail2")] #[rustc_dirty(label="hir_owner_nodes", cfg="cfail2")] -#[rustc_dirty(label="type_of", cfg="cfail2")] +#[rustc_dirty(label="try_type_of", cfg="cfail2")] #[rustc_clean(label="generics_of", cfg="cfail2")] #[rustc_clean(label="predicates_of", cfg="cfail2")] #[rustc_clean(label="hir_owner", cfg="cfail3")] #[rustc_clean(label="hir_owner_nodes", cfg="cfail3")] -#[rustc_clean(label="type_of", cfg="cfail3")] +#[rustc_clean(label="try_type_of", cfg="cfail3")] #[rustc_clean(label="generics_of", cfg="cfail3")] #[rustc_clean(label="predicates_of", cfg="cfail3")] struct RecordStructFieldName { y: f32 } @@ -169,12 +169,12 @@ struct RecordStructAddField { x: f32 } #[cfg(not(cfail1))] #[rustc_dirty(label="hir_owner", cfg="cfail2")] #[rustc_dirty(label="hir_owner_nodes", cfg="cfail2")] -#[rustc_dirty(label="type_of", cfg="cfail2")] +#[rustc_dirty(label="try_type_of", cfg="cfail2")] #[rustc_clean(label="generics_of", cfg="cfail2")] #[rustc_clean(label="predicates_of", cfg="cfail2")] #[rustc_clean(label="hir_owner", cfg="cfail3")] #[rustc_clean(label="hir_owner_nodes", cfg="cfail3")] -#[rustc_clean(label="type_of", cfg="cfail3")] +#[rustc_clean(label="try_type_of", cfg="cfail3")] #[rustc_clean(label="generics_of", cfg="cfail3")] #[rustc_clean(label="predicates_of", cfg="cfail3")] struct RecordStructAddField { @@ -190,12 +190,12 @@ struct RecordStructFieldVisibility { x: f32 } #[cfg(not(cfail1))] #[rustc_dirty(label="hir_owner", cfg="cfail2")] #[rustc_dirty(label="hir_owner_nodes", cfg="cfail2")] -#[rustc_dirty(label="type_of", cfg="cfail2")] +#[rustc_dirty(label="try_type_of", cfg="cfail2")] #[rustc_clean(label="generics_of", cfg="cfail2")] #[rustc_clean(label="predicates_of", cfg="cfail2")] #[rustc_clean(label="hir_owner", cfg="cfail3")] #[rustc_clean(label="hir_owner_nodes", cfg="cfail3")] -#[rustc_clean(label="type_of", cfg="cfail3")] +#[rustc_clean(label="try_type_of", cfg="cfail3")] #[rustc_clean(label="generics_of", cfg="cfail3")] #[rustc_clean(label="predicates_of", cfg="cfail3")] struct RecordStructFieldVisibility { @@ -211,12 +211,12 @@ struct AddLifetimeParameter<'a>(&'a f32, &'a f64); #[cfg(not(cfail1))] #[rustc_dirty(label="hir_owner", cfg="cfail2")] #[rustc_dirty(label="hir_owner_nodes", cfg="cfail2")] -#[rustc_dirty(label="type_of", cfg="cfail2")] +#[rustc_dirty(label="try_type_of", cfg="cfail2")] #[rustc_dirty(label="generics_of", cfg="cfail2")] #[rustc_clean(label="predicates_of", cfg="cfail2")] #[rustc_clean(label="hir_owner", cfg="cfail3")] #[rustc_clean(label="hir_owner_nodes", cfg="cfail3")] -#[rustc_clean(label="type_of", cfg="cfail3")] +#[rustc_clean(label="try_type_of", cfg="cfail3")] #[rustc_clean(label="generics_of", cfg="cfail3")] #[rustc_clean(label="predicates_of", cfg="cfail3")] struct AddLifetimeParameter<'a, 'b>(&'a f32, &'b f64); @@ -230,12 +230,12 @@ struct AddLifetimeParameterBound<'a, 'b>(&'a f32, &'b f64); #[cfg(not(cfail1))] #[rustc_dirty(label="hir_owner", cfg="cfail2")] #[rustc_dirty(label="hir_owner_nodes", cfg="cfail2")] -#[rustc_clean(label="type_of", cfg="cfail2")] +#[rustc_clean(label="try_type_of", cfg="cfail2")] #[rustc_clean(label="generics_of", cfg="cfail2")] #[rustc_dirty(label="predicates_of", cfg="cfail2")] #[rustc_clean(label="hir_owner", cfg="cfail3")] #[rustc_clean(label="hir_owner_nodes", cfg="cfail3")] -#[rustc_clean(label="type_of", cfg="cfail3")] +#[rustc_clean(label="try_type_of", cfg="cfail3")] #[rustc_clean(label="generics_of", cfg="cfail3")] #[rustc_clean(label="predicates_of", cfg="cfail3")] struct AddLifetimeParameterBound<'a, 'b: 'a>( @@ -249,12 +249,12 @@ struct AddLifetimeParameterBoundWhereClause<'a, 'b>(&'a f32, &'b f64); #[cfg(not(cfail1))] #[rustc_dirty(label="hir_owner", cfg="cfail2")] #[rustc_dirty(label="hir_owner_nodes", cfg="cfail2")] -#[rustc_clean(label="type_of", cfg="cfail2")] +#[rustc_clean(label="try_type_of", cfg="cfail2")] #[rustc_clean(label="generics_of", cfg="cfail2")] #[rustc_dirty(label="predicates_of", cfg="cfail2")] #[rustc_clean(label="hir_owner", cfg="cfail3")] #[rustc_clean(label="hir_owner_nodes", cfg="cfail3")] -#[rustc_clean(label="type_of", cfg="cfail3")] +#[rustc_clean(label="try_type_of", cfg="cfail3")] #[rustc_clean(label="generics_of", cfg="cfail3")] #[rustc_clean(label="predicates_of", cfg="cfail3")] struct AddLifetimeParameterBoundWhereClause<'a, 'b>( @@ -271,12 +271,12 @@ struct AddTypeParameter(T1, T1); #[cfg(not(cfail1))] #[rustc_dirty(label="hir_owner", cfg="cfail2")] #[rustc_dirty(label="hir_owner_nodes", cfg="cfail2")] -#[rustc_dirty(label="type_of", cfg="cfail2")] +#[rustc_dirty(label="try_type_of", cfg="cfail2")] #[rustc_dirty(label="generics_of", cfg="cfail2")] #[rustc_dirty(label="predicates_of", cfg="cfail2")] #[rustc_clean(label="hir_owner", cfg="cfail3")] #[rustc_clean(label="hir_owner_nodes", cfg="cfail3")] -#[rustc_clean(label="type_of", cfg="cfail3")] +#[rustc_clean(label="try_type_of", cfg="cfail3")] #[rustc_clean(label="generics_of", cfg="cfail3")] #[rustc_clean(label="predicates_of", cfg="cfail3")] struct AddTypeParameter( @@ -295,12 +295,12 @@ struct AddTypeParameterBound(T); #[cfg(not(cfail1))] #[rustc_dirty(label="hir_owner", cfg="cfail2")] #[rustc_dirty(label="hir_owner_nodes", cfg="cfail2")] -#[rustc_clean(label="type_of", cfg="cfail2")] +#[rustc_clean(label="try_type_of", cfg="cfail2")] #[rustc_clean(label="generics_of", cfg="cfail2")] #[rustc_dirty(label="predicates_of", cfg="cfail2")] #[rustc_clean(label="hir_owner", cfg="cfail3")] #[rustc_clean(label="hir_owner_nodes", cfg="cfail3")] -#[rustc_clean(label="type_of", cfg="cfail3")] +#[rustc_clean(label="try_type_of", cfg="cfail3")] #[rustc_clean(label="generics_of", cfg="cfail3")] #[rustc_clean(label="predicates_of", cfg="cfail3")] struct AddTypeParameterBound( @@ -314,12 +314,12 @@ struct AddTypeParameterBoundWhereClause(T); #[cfg(not(cfail1))] #[rustc_dirty(label="hir_owner", cfg="cfail2")] #[rustc_dirty(label="hir_owner_nodes", cfg="cfail2")] -#[rustc_clean(label="type_of", cfg="cfail2")] +#[rustc_clean(label="try_type_of", cfg="cfail2")] #[rustc_clean(label="generics_of", cfg="cfail2")] #[rustc_dirty(label="predicates_of", cfg="cfail2")] #[rustc_clean(label="hir_owner", cfg="cfail3")] #[rustc_clean(label="hir_owner_nodes", cfg="cfail3")] -#[rustc_clean(label="type_of", cfg="cfail3")] +#[rustc_clean(label="try_type_of", cfg="cfail3")] #[rustc_clean(label="generics_of", cfg="cfail3")] #[rustc_clean(label="predicates_of", cfg="cfail3")] struct AddTypeParameterBoundWhereClause( @@ -334,12 +334,12 @@ struct AddTypeParameterBoundWhereClause( // Note: there is no #[cfg(...)], so this is ALWAYS compiled #[rustc_clean(label="hir_owner", cfg="cfail2")] #[rustc_clean(label="hir_owner_nodes", cfg="cfail2")] -#[rustc_clean(label="type_of", cfg="cfail2")] +#[rustc_clean(label="try_type_of", cfg="cfail2")] #[rustc_clean(label="generics_of", cfg="cfail2")] #[rustc_clean(label="predicates_of", cfg="cfail2")] #[rustc_clean(label="hir_owner", cfg="cfail3")] #[rustc_clean(label="hir_owner_nodes", cfg="cfail3")] -#[rustc_clean(label="type_of", cfg="cfail3")] +#[rustc_clean(label="try_type_of", cfg="cfail3")] #[rustc_clean(label="generics_of", cfg="cfail3")] #[rustc_clean(label="predicates_of", cfg="cfail3")] pub struct EmptyStruct; @@ -353,12 +353,12 @@ struct Visibility; #[cfg(not(cfail1))] #[rustc_dirty(label="hir_owner", cfg="cfail2")] #[rustc_dirty(label="hir_owner_nodes", cfg="cfail2")] -#[rustc_clean(label="type_of", cfg="cfail2")] +#[rustc_clean(label="try_type_of", cfg="cfail2")] #[rustc_clean(label="generics_of", cfg="cfail2")] #[rustc_clean(label="predicates_of", cfg="cfail2")] #[rustc_clean(label="hir_owner", cfg="cfail3")] #[rustc_clean(label="hir_owner_nodes", cfg="cfail3")] -#[rustc_clean(label="type_of", cfg="cfail3")] +#[rustc_clean(label="try_type_of", cfg="cfail3")] #[rustc_clean(label="generics_of", cfg="cfail3")] #[rustc_clean(label="predicates_of", cfg="cfail3")] pub struct Visibility; @@ -375,12 +375,12 @@ mod tuple_struct_change_field_type_indirectly { #[rustc_dirty(label="hir_owner", cfg="cfail2")] #[rustc_dirty(label="hir_owner_nodes", cfg="cfail2")] - #[rustc_clean(label="type_of", cfg="cfail2")] + #[rustc_clean(label="try_type_of", cfg="cfail2")] #[rustc_clean(label="generics_of", cfg="cfail2")] #[rustc_clean(label="predicates_of", cfg="cfail2")] #[rustc_clean(label="hir_owner", cfg="cfail3")] #[rustc_clean(label="hir_owner_nodes", cfg="cfail3")] - #[rustc_clean(label="type_of", cfg="cfail3")] + #[rustc_clean(label="try_type_of", cfg="cfail3")] #[rustc_clean(label="generics_of", cfg="cfail3")] #[rustc_clean(label="predicates_of", cfg="cfail3")] struct TupleStruct( @@ -398,12 +398,12 @@ mod record_struct_change_field_type_indirectly { #[rustc_dirty(label="hir_owner", cfg="cfail2")] #[rustc_dirty(label="hir_owner_nodes", cfg="cfail2")] - #[rustc_clean(label="type_of", cfg="cfail2")] + #[rustc_clean(label="try_type_of", cfg="cfail2")] #[rustc_clean(label="generics_of", cfg="cfail2")] #[rustc_clean(label="predicates_of", cfg="cfail2")] #[rustc_clean(label="hir_owner", cfg="cfail3")] #[rustc_clean(label="hir_owner_nodes", cfg="cfail3")] - #[rustc_clean(label="type_of", cfg="cfail3")] + #[rustc_clean(label="try_type_of", cfg="cfail3")] #[rustc_clean(label="generics_of", cfg="cfail3")] #[rustc_clean(label="predicates_of", cfg="cfail3")] struct RecordStruct { @@ -426,12 +426,12 @@ mod change_trait_bound_indirectly { #[rustc_dirty(label="hir_owner", cfg="cfail2")] #[rustc_dirty(label="hir_owner_nodes", cfg="cfail2")] - #[rustc_clean(label="type_of", cfg="cfail2")] + #[rustc_clean(label="try_type_of", cfg="cfail2")] #[rustc_clean(label="generics_of", cfg="cfail2")] #[rustc_dirty(label="predicates_of", cfg="cfail2")] #[rustc_clean(label="hir_owner", cfg="cfail3")] #[rustc_clean(label="hir_owner_nodes", cfg="cfail3")] - #[rustc_clean(label="type_of", cfg="cfail3")] + #[rustc_clean(label="try_type_of", cfg="cfail3")] #[rustc_clean(label="generics_of", cfg="cfail3")] #[rustc_clean(label="predicates_of", cfg="cfail3")] struct Struct(T); @@ -446,12 +446,12 @@ mod change_trait_bound_indirectly_in_where_clause { #[rustc_dirty(label="hir_owner", cfg="cfail2")] #[rustc_dirty(label="hir_owner_nodes", cfg="cfail2")] - #[rustc_clean(label="type_of", cfg="cfail2")] + #[rustc_clean(label="try_type_of", cfg="cfail2")] #[rustc_clean(label="generics_of", cfg="cfail2")] #[rustc_dirty(label="predicates_of", cfg="cfail2")] #[rustc_clean(label="hir_owner", cfg="cfail3")] #[rustc_clean(label="hir_owner_nodes", cfg="cfail3")] - #[rustc_clean(label="type_of", cfg="cfail3")] + #[rustc_clean(label="try_type_of", cfg="cfail3")] #[rustc_clean(label="generics_of", cfg="cfail3")] #[rustc_clean(label="predicates_of", cfg="cfail3")] struct Struct(T) where T : Trait; diff --git a/src/test/ui/cycle-trait/cycle-trait-default-type-trait.rs b/src/test/ui/cycle-trait/cycle-trait-default-type-trait.rs index b2edc1a1f66ca..6175b7df1107a 100644 --- a/src/test/ui/cycle-trait/cycle-trait-default-type-trait.rs +++ b/src/test/ui/cycle-trait/cycle-trait-default-type-trait.rs @@ -3,7 +3,6 @@ trait Foo> { //~^ ERROR cycle detected - //~| ERROR cycle detected } fn main() { } diff --git a/src/test/ui/cycle-trait/cycle-trait-default-type-trait.stderr b/src/test/ui/cycle-trait/cycle-trait-default-type-trait.stderr index 58c458709a839..3450fa4f377c4 100644 --- a/src/test/ui/cycle-trait/cycle-trait-default-type-trait.stderr +++ b/src/test/ui/cycle-trait/cycle-trait-default-type-trait.stderr @@ -11,19 +11,6 @@ note: cycle used when collecting item types in top-level module LL | trait Foo> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error[E0391]: cycle detected when computing type of `Foo::X` - --> $DIR/cycle-trait-default-type-trait.rs:4:23 - | -LL | trait Foo> { - | ^^^ - | - = note: ...which again requires computing type of `Foo::X`, completing the cycle -note: cycle used when collecting item types in top-level module - --> $DIR/cycle-trait-default-type-trait.rs:4:1 - | -LL | trait Foo> { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to 2 previous errors +error: aborting due to previous error For more information about this error, try `rustc --explain E0391`. diff --git a/src/test/ui/dep-graph/dep-graph-struct-signature.rs b/src/test/ui/dep-graph/dep-graph-struct-signature.rs index 7ef6fac48c3a6..c344347cc0769 100644 --- a/src/test/ui/dep-graph/dep-graph-struct-signature.rs +++ b/src/test/ui/dep-graph/dep-graph-struct-signature.rs @@ -24,7 +24,7 @@ struct WontChange { mod signatures { use WillChange; - #[rustc_then_this_would_need(type_of)] //~ ERROR no path + #[rustc_then_this_would_need(try_type_of)] //~ ERROR no path #[rustc_then_this_would_need(associated_item)] //~ ERROR no path #[rustc_then_this_would_need(trait_def)] //~ ERROR no path trait Bar { @@ -42,14 +42,14 @@ mod signatures { WillChange { x: x, y: y } } - #[rustc_then_this_would_need(type_of)] //~ ERROR OK + #[rustc_then_this_would_need(try_type_of)] //~ ERROR OK impl WillChange { #[rustc_then_this_would_need(fn_sig)] //~ ERROR OK #[rustc_then_this_would_need(typeck)] //~ ERROR OK fn new(x: u32, y: u32) -> WillChange { loop { } } } - #[rustc_then_this_would_need(type_of)] //~ ERROR OK + #[rustc_then_this_would_need(try_type_of)] //~ ERROR OK impl WillChange { #[rustc_then_this_would_need(fn_sig)] //~ ERROR OK #[rustc_then_this_would_need(typeck)] //~ ERROR OK @@ -57,21 +57,21 @@ mod signatures { } struct WillChanges { - #[rustc_then_this_would_need(type_of)] //~ ERROR OK + #[rustc_then_this_would_need(try_type_of)] //~ ERROR OK x: WillChange, - #[rustc_then_this_would_need(type_of)] //~ ERROR OK + #[rustc_then_this_would_need(try_type_of)] //~ ERROR OK y: WillChange } // The fields change, not the type itself. - #[rustc_then_this_would_need(type_of)] //~ ERROR no path + #[rustc_then_this_would_need(try_type_of)] //~ ERROR no path fn indirect(x: WillChanges) { } } mod invalid_signatures { use WontChange; - #[rustc_then_this_would_need(type_of)] //~ ERROR no path + #[rustc_then_this_would_need(try_type_of)] //~ ERROR no path trait A { #[rustc_then_this_would_need(fn_sig)] //~ ERROR no path fn do_something_else_twice(x: WontChange); diff --git a/src/test/ui/dep-graph/dep-graph-struct-signature.stderr b/src/test/ui/dep-graph/dep-graph-struct-signature.stderr index 9d1644a00d002..6fcdf6f74f0b8 100644 --- a/src/test/ui/dep-graph/dep-graph-struct-signature.stderr +++ b/src/test/ui/dep-graph/dep-graph-struct-signature.stderr @@ -1,8 +1,8 @@ -error: no path from `WillChange` to `type_of` +error: no path from `WillChange` to `try_type_of` --> $DIR/dep-graph-struct-signature.rs:27:5 | -LL | #[rustc_then_this_would_need(type_of)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | #[rustc_then_this_would_need(try_type_of)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: no path from `WillChange` to `associated_item` --> $DIR/dep-graph-struct-signature.rs:28:5 @@ -43,38 +43,38 @@ LL | #[rustc_then_this_would_need(typeck)] error: OK --> $DIR/dep-graph-struct-signature.rs:45:5 | -LL | #[rustc_then_this_would_need(type_of)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | #[rustc_then_this_would_need(try_type_of)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: OK --> $DIR/dep-graph-struct-signature.rs:52:5 | -LL | #[rustc_then_this_would_need(type_of)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | #[rustc_then_this_would_need(try_type_of)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: OK --> $DIR/dep-graph-struct-signature.rs:60:9 | -LL | #[rustc_then_this_would_need(type_of)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | #[rustc_then_this_would_need(try_type_of)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: OK --> $DIR/dep-graph-struct-signature.rs:62:9 | -LL | #[rustc_then_this_would_need(type_of)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | #[rustc_then_this_would_need(try_type_of)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: no path from `WillChange` to `type_of` +error: no path from `WillChange` to `try_type_of` --> $DIR/dep-graph-struct-signature.rs:67:5 | -LL | #[rustc_then_this_would_need(type_of)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | #[rustc_then_this_would_need(try_type_of)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: no path from `WillChange` to `type_of` +error: no path from `WillChange` to `try_type_of` --> $DIR/dep-graph-struct-signature.rs:74:5 | -LL | #[rustc_then_this_would_need(type_of)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | #[rustc_then_this_would_need(try_type_of)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: no path from `WillChange` to `fn_sig` --> $DIR/dep-graph-struct-signature.rs:80:5 diff --git a/src/test/ui/dep-graph/dep-graph-type-alias.rs b/src/test/ui/dep-graph/dep-graph-type-alias.rs index c9151ce79c5f6..62f57076b032f 100644 --- a/src/test/ui/dep-graph/dep-graph-type-alias.rs +++ b/src/test/ui/dep-graph/dep-graph-type-alias.rs @@ -14,23 +14,23 @@ type TypeAlias = u32; // The type alias directly affects the type of the field, // not the enclosing struct: -#[rustc_then_this_would_need(type_of)] //~ ERROR no path +#[rustc_then_this_would_need(try_type_of)] //~ ERROR no path struct Struct { - #[rustc_then_this_would_need(type_of)] //~ ERROR OK + #[rustc_then_this_would_need(try_type_of)] //~ ERROR OK x: TypeAlias, y: u32 } -#[rustc_then_this_would_need(type_of)] //~ ERROR no path +#[rustc_then_this_would_need(try_type_of)] //~ ERROR no path enum Enum { Variant1 { - #[rustc_then_this_would_need(type_of)] //~ ERROR OK + #[rustc_then_this_would_need(try_type_of)] //~ ERROR OK t: TypeAlias }, Variant2(i32) } -#[rustc_then_this_would_need(type_of)] //~ ERROR no path +#[rustc_then_this_would_need(try_type_of)] //~ ERROR no path trait Trait { #[rustc_then_this_would_need(fn_sig)] //~ ERROR OK fn method(&self, _: TypeAlias); @@ -38,14 +38,14 @@ trait Trait { struct SomeType; -#[rustc_then_this_would_need(type_of)] //~ ERROR no path +#[rustc_then_this_would_need(try_type_of)] //~ ERROR no path impl SomeType { #[rustc_then_this_would_need(fn_sig)] //~ ERROR OK #[rustc_then_this_would_need(typeck)] //~ ERROR OK fn method(&self, _: TypeAlias) {} } -#[rustc_then_this_would_need(type_of)] //~ ERROR OK +#[rustc_then_this_would_need(try_type_of)] //~ ERROR OK type TypeAlias2 = TypeAlias; #[rustc_then_this_would_need(fn_sig)] //~ ERROR OK diff --git a/src/test/ui/dep-graph/dep-graph-type-alias.stderr b/src/test/ui/dep-graph/dep-graph-type-alias.stderr index 9baaf746fc210..cc15e157e48ba 100644 --- a/src/test/ui/dep-graph/dep-graph-type-alias.stderr +++ b/src/test/ui/dep-graph/dep-graph-type-alias.stderr @@ -1,44 +1,44 @@ -error: no path from `TypeAlias` to `type_of` +error: no path from `TypeAlias` to `try_type_of` --> $DIR/dep-graph-type-alias.rs:17:1 | -LL | #[rustc_then_this_would_need(type_of)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | #[rustc_then_this_would_need(try_type_of)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: OK --> $DIR/dep-graph-type-alias.rs:19:5 | -LL | #[rustc_then_this_would_need(type_of)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | #[rustc_then_this_would_need(try_type_of)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: no path from `TypeAlias` to `type_of` +error: no path from `TypeAlias` to `try_type_of` --> $DIR/dep-graph-type-alias.rs:24:1 | -LL | #[rustc_then_this_would_need(type_of)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | #[rustc_then_this_would_need(try_type_of)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: OK --> $DIR/dep-graph-type-alias.rs:27:9 | -LL | #[rustc_then_this_would_need(type_of)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | #[rustc_then_this_would_need(try_type_of)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: no path from `TypeAlias` to `type_of` +error: no path from `TypeAlias` to `try_type_of` --> $DIR/dep-graph-type-alias.rs:33:1 | -LL | #[rustc_then_this_would_need(type_of)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | #[rustc_then_this_would_need(try_type_of)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: no path from `TypeAlias` to `type_of` +error: no path from `TypeAlias` to `try_type_of` --> $DIR/dep-graph-type-alias.rs:41:1 | -LL | #[rustc_then_this_would_need(type_of)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | #[rustc_then_this_would_need(try_type_of)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: OK --> $DIR/dep-graph-type-alias.rs:48:1 | -LL | #[rustc_then_this_would_need(type_of)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | #[rustc_then_this_would_need(try_type_of)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: OK --> $DIR/dep-graph-type-alias.rs:51:1 diff --git a/src/test/ui/impl-trait/auto-trait-leak.rs b/src/test/ui/impl-trait/auto-trait-leak.rs index 087f4582b21c3..c2fbbf94fd666 100644 --- a/src/test/ui/impl-trait/auto-trait-leak.rs +++ b/src/test/ui/impl-trait/auto-trait-leak.rs @@ -12,7 +12,6 @@ fn main() { fn cycle1() -> impl Clone { //~^ ERROR cycle detected send(cycle2().clone()); - //~^ ERROR cannot be sent between threads safely Rc::new(Cell::new(5)) } diff --git a/src/test/ui/impl-trait/auto-trait-leak.stderr b/src/test/ui/impl-trait/auto-trait-leak.stderr index e578c4b4f819e..3eb141cc2bb55 100644 --- a/src/test/ui/impl-trait/auto-trait-leak.stderr +++ b/src/test/ui/impl-trait/auto-trait-leak.stderr @@ -36,37 +36,37 @@ LL | fn cycle1() -> impl Clone { | ^^^^^^^^^^^^^^^^^^^^^^^^^ = note: ...which requires evaluating trait selection obligation `impl std::clone::Clone: std::marker::Send`... note: ...which requires computing type of `cycle2::{opaque#0}`... - --> $DIR/auto-trait-leak.rs:20:16 + --> $DIR/auto-trait-leak.rs:19:16 | LL | fn cycle2() -> impl Clone { | ^^^^^^^^^^ note: ...which requires borrow-checking `cycle2`... - --> $DIR/auto-trait-leak.rs:20:1 + --> $DIR/auto-trait-leak.rs:19:1 | LL | fn cycle2() -> impl Clone { | ^^^^^^^^^^^^^^^^^^^^^^^^^ note: ...which requires processing `cycle2`... - --> $DIR/auto-trait-leak.rs:20:1 + --> $DIR/auto-trait-leak.rs:19:1 | LL | fn cycle2() -> impl Clone { | ^^^^^^^^^^^^^^^^^^^^^^^^^ note: ...which requires processing MIR for `cycle2`... - --> $DIR/auto-trait-leak.rs:20:1 + --> $DIR/auto-trait-leak.rs:19:1 | LL | fn cycle2() -> impl Clone { | ^^^^^^^^^^^^^^^^^^^^^^^^^ note: ...which requires unsafety-checking `cycle2`... - --> $DIR/auto-trait-leak.rs:20:1 + --> $DIR/auto-trait-leak.rs:19:1 | LL | fn cycle2() -> impl Clone { | ^^^^^^^^^^^^^^^^^^^^^^^^^ note: ...which requires building MIR for `cycle2`... - --> $DIR/auto-trait-leak.rs:20:1 + --> $DIR/auto-trait-leak.rs:19:1 | LL | fn cycle2() -> impl Clone { | ^^^^^^^^^^^^^^^^^^^^^^^^^ note: ...which requires type-checking `cycle2`... - --> $DIR/auto-trait-leak.rs:20:1 + --> $DIR/auto-trait-leak.rs:19:1 | LL | fn cycle2() -> impl Clone { | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -84,22 +84,6 @@ LL | | Rc::new(String::from("foo")) LL | | } | |_^ -error[E0277]: `Rc` cannot be sent between threads safely - --> $DIR/auto-trait-leak.rs:14:5 - | -LL | fn send(_: T) {} - | ---- required by this bound in `send` -... -LL | send(cycle2().clone()); - | ^^^^ `Rc` cannot be sent between threads safely -... -LL | fn cycle2() -> impl Clone { - | ---------- within this `impl Clone` - | - = help: within `impl Clone`, the trait `Send` is not implemented for `Rc` - = note: required because it appears within the type `impl Clone` - -error: aborting due to 2 previous errors +error: aborting due to previous error -Some errors have detailed explanations: E0277, E0391. -For more information about an error, try `rustc --explain E0277`. +For more information about this error, try `rustc --explain E0391`. diff --git a/src/test/ui/resolve/resolve-self-in-impl.rs b/src/test/ui/resolve/resolve-self-in-impl.rs index 024fdc51ea318..7192633843814 100644 --- a/src/test/ui/resolve/resolve-self-in-impl.rs +++ b/src/test/ui/resolve/resolve-self-in-impl.rs @@ -12,9 +12,9 @@ impl Tr for S where S: Copy {} // OK impl Tr for S where Self::A: Copy {} // OK impl Tr for Self {} //~ ERROR cycle detected -impl Tr for S {} //~ ERROR cycle detected -impl Self {} //~ ERROR cycle detected -impl S {} //~ ERROR cycle detected -impl Tr for S {} //~ ERROR cycle detected +impl Tr for S {} +impl Self {} +impl S {} +impl Tr for S {} fn main() {} diff --git a/src/test/ui/resolve/resolve-self-in-impl.stderr b/src/test/ui/resolve/resolve-self-in-impl.stderr index 5b5c1834cad19..2026f179e6d42 100644 --- a/src/test/ui/resolve/resolve-self-in-impl.stderr +++ b/src/test/ui/resolve/resolve-self-in-impl.stderr @@ -17,82 +17,6 @@ LL | | LL | | fn main() {} | |____________^ -error[E0391]: cycle detected when computing type of `` - --> $DIR/resolve-self-in-impl.rs:15:15 - | -LL | impl Tr for S {} - | ^^^^ - | - = note: ...which again requires computing type of ``, completing the cycle -note: cycle used when collecting item types in top-level module - --> $DIR/resolve-self-in-impl.rs:1:1 - | -LL | / #![feature(associated_type_defaults)] -LL | | -LL | | struct S(T); -LL | | trait Tr { -... | -LL | | -LL | | fn main() {} - | |____________^ - -error[E0391]: cycle detected when computing type of `` - --> $DIR/resolve-self-in-impl.rs:16:6 - | -LL | impl Self {} - | ^^^^ - | - = note: ...which again requires computing type of ``, completing the cycle -note: cycle used when collecting item types in top-level module - --> $DIR/resolve-self-in-impl.rs:1:1 - | -LL | / #![feature(associated_type_defaults)] -LL | | -LL | | struct S(T); -LL | | trait Tr { -... | -LL | | -LL | | fn main() {} - | |____________^ - -error[E0391]: cycle detected when computing type of `` - --> $DIR/resolve-self-in-impl.rs:17:8 - | -LL | impl S {} - | ^^^^ - | - = note: ...which again requires computing type of ``, completing the cycle -note: cycle used when collecting item types in top-level module - --> $DIR/resolve-self-in-impl.rs:1:1 - | -LL | / #![feature(associated_type_defaults)] -LL | | -LL | | struct S(T); -LL | | trait Tr { -... | -LL | | -LL | | fn main() {} - | |____________^ - -error[E0391]: cycle detected when computing trait implemented by `` - --> $DIR/resolve-self-in-impl.rs:18:1 - | -LL | impl Tr for S {} - | ^^^^^^^^^^^^^^^^^^^^^^ - | - = note: ...which again requires computing trait implemented by ``, completing the cycle -note: cycle used when collecting item types in top-level module - --> $DIR/resolve-self-in-impl.rs:1:1 - | -LL | / #![feature(associated_type_defaults)] -LL | | -LL | | struct S(T); -LL | | trait Tr { -... | -LL | | -LL | | fn main() {} - | |____________^ - -error: aborting due to 5 previous errors +error: aborting due to previous error For more information about this error, try `rustc --explain E0391`. From 83122e6855cbe9ca09ad438b67f43167b0c0e98c Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Wed, 23 Dec 2020 12:39:10 +0100 Subject: [PATCH 08/16] Infallible version of fn_sig. --- .../src/persist/dirty_clean.rs | 2 +- .../src/rmeta/decoder/cstore_impl.rs | 2 +- compiler/rustc_middle/src/query/mod.rs | 2 +- compiler/rustc_middle/src/ty/query/mod.rs | 12 ++++++ compiler/rustc_typeck/src/collect.rs | 27 +++++++------ .../incremental/hashes/enum_constructors.rs | 6 +-- .../incremental/hashes/function_interfaces.rs | 18 ++++----- src/test/incremental/hashes/inherent_impls.rs | 16 ++++---- .../incremental/hashes/struct_constructors.rs | 4 +- .../dep-graph/dep-graph-struct-signature.rs | 16 ++++---- .../dep-graph-struct-signature.stderr | 38 +++++++++---------- src/test/ui/dep-graph/dep-graph-type-alias.rs | 6 +-- .../ui/dep-graph/dep-graph-type-alias.stderr | 12 +++--- 13 files changed, 88 insertions(+), 73 deletions(-) diff --git a/compiler/rustc_incremental/src/persist/dirty_clean.rs b/compiler/rustc_incremental/src/persist/dirty_clean.rs index 4ceb66b2245e8..0957213bfed61 100644 --- a/compiler/rustc_incremental/src/persist/dirty_clean.rs +++ b/compiler/rustc_incremental/src/persist/dirty_clean.rs @@ -42,7 +42,7 @@ const BASE_CONST: &[&str] = &[label_strs::try_type_of]; /// DepNodes for functions + methods const BASE_FN: &[&str] = &[ // Callers will depend on the signature of these items, so we better test - label_strs::fn_sig, + label_strs::try_fn_sig, label_strs::generics_of, label_strs::predicates_of, label_strs::try_type_of, diff --git a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs index abaef4667a613..429d556f1b0df 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs @@ -123,7 +123,7 @@ provide! { <'tcx> tcx, def_id, other, cdata, mir_abstract_const => { cdata.get_mir_abstract_const(tcx, def_id.index) } unused_generic_params => { cdata.get_unused_generic_params(def_id.index) } mir_const_qualif => { cdata.mir_const_qualif(def_id.index) } - fn_sig => { cdata.fn_sig(def_id.index, tcx) } + try_fn_sig => { Ok(cdata.fn_sig(def_id.index, tcx)) } inherent_impls => { cdata.get_inherent_implementations_for_type(tcx, def_id.index) } is_const_fn_raw => { cdata.is_const_fn_raw(def_id.index) } asyncness => { cdata.asyncness(def_id.index) } diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs index 0746c3fa0e84e..b6e164b4825cd 100644 --- a/compiler/rustc_middle/src/query/mod.rs +++ b/compiler/rustc_middle/src/query/mod.rs @@ -600,7 +600,7 @@ rustc_queries! { } /// The signature of functions. - query fn_sig(key: DefId) -> ty::PolyFnSig<'tcx> { + query try_fn_sig(key: DefId) -> Result, String> { desc { |tcx| "computing function signature of `{}`", tcx.def_path_str(key) } } diff --git a/compiler/rustc_middle/src/ty/query/mod.rs b/compiler/rustc_middle/src/ty/query/mod.rs index 76d57dbbc0d5f..16f07969e3a2d 100644 --- a/compiler/rustc_middle/src/ty/query/mod.rs +++ b/compiler/rustc_middle/src/ty/query/mod.rs @@ -313,6 +313,12 @@ impl TyCtxt<'tcx> { .unwrap_or_else(|| bug!("def_kind: unsupported node: {:?}", def_id)) } + pub fn fn_sig(self, def_id: impl IntoQueryParam) -> ty::PolyFnSig<'tcx> { + let def_id = def_id.into_query_param(); + self.try_fn_sig(def_id) + .unwrap_or_else(|s| span_bug!(self.def_span(def_id), "fn_sig: {}", s)) + } + pub fn type_of(self, def_id: impl IntoQueryParam) -> Ty<'tcx> { let def_id = def_id.into_query_param(); self.try_type_of(def_id).unwrap_or_else(|msg| { @@ -329,6 +335,12 @@ impl TyCtxtAt<'tcx> { .unwrap_or_else(|| bug!("def_kind: unsupported node: {:?}", def_id)) } + pub fn fn_sig(self, def_id: impl IntoQueryParam) -> ty::PolyFnSig<'tcx> { + let def_id = def_id.into_query_param(); + self.try_fn_sig(def_id) + .unwrap_or_else(|s| span_bug!(self.def_span(def_id), "fn_sig: {}", s)) + } + pub fn type_of(self, def_id: impl IntoQueryParam) -> Ty<'tcx> { let def_id = def_id.into_query_param(); self.try_type_of(def_id).unwrap_or_else(|msg| { diff --git a/compiler/rustc_typeck/src/collect.rs b/compiler/rustc_typeck/src/collect.rs index 3d44deb88569f..03cba57e31ba3 100644 --- a/compiler/rustc_typeck/src/collect.rs +++ b/compiler/rustc_typeck/src/collect.rs @@ -83,7 +83,7 @@ pub fn provide(providers: &mut Providers) { type_param_predicates, trait_def, adt_def, - fn_sig, + try_fn_sig, impl_trait_ref, impl_polarity, is_foreign_item, @@ -730,7 +730,7 @@ fn convert_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) { tcx.ensure().try_type_of(item.def_id); tcx.ensure().predicates_of(item.def_id); if let hir::ForeignItemKind::Fn(..) = item.kind { - tcx.ensure().fn_sig(item.def_id); + tcx.ensure().try_fn_sig(item.def_id); } } } @@ -793,7 +793,7 @@ fn convert_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) { tcx.ensure().try_type_of(def_id); tcx.ensure().predicates_of(def_id); match it.kind { - hir::ItemKind::Fn(..) => tcx.ensure().fn_sig(def_id), + hir::ItemKind::Fn(..) => tcx.ensure().try_fn_sig(def_id), hir::ItemKind::OpaqueTy(..) => tcx.ensure().item_bounds(def_id), _ => (), } @@ -808,7 +808,7 @@ fn convert_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::TraitItemId) { match trait_item.kind { hir::TraitItemKind::Fn(..) => { tcx.ensure().try_type_of(trait_item_id.def_id); - tcx.ensure().fn_sig(trait_item_id.def_id); + tcx.ensure().try_fn_sig(trait_item_id.def_id); } hir::TraitItemKind::Const(.., Some(_)) => { @@ -854,7 +854,7 @@ fn convert_impl_item(tcx: TyCtxt<'_>, impl_item_id: hir::ImplItemId) { let impl_item = tcx.hir().impl_item(impl_item_id); match impl_item.kind { hir::ImplItemKind::Fn(..) => { - tcx.ensure().fn_sig(def_id); + tcx.ensure().try_fn_sig(def_id); } hir::ImplItemKind::TyAlias(_) => { // Account for `type T = _;` @@ -1631,7 +1631,7 @@ pub fn get_infer_ret_ty(output: &'hir hir::FnRetTy<'hir>) -> Option<&'hir hir::T None } -fn fn_sig(tcx: TyCtxt<'_>, def_id: DefId) -> ty::PolyFnSig<'_> { +fn try_fn_sig(tcx: TyCtxt<'_>, def_id: DefId) -> Result, String> { use rustc_hir::Node::*; use rustc_hir::*; @@ -1640,7 +1640,8 @@ fn fn_sig(tcx: TyCtxt<'_>, def_id: DefId) -> ty::PolyFnSig<'_> { let icx = ItemCtxt::new(tcx, def_id.to_def_id()); - match tcx.hir().get(hir_id) { + let node = tcx.hir().find(hir_id).ok_or_else(|| "not found in HIR map".to_owned())?; + let sig = match node { TraitItem(hir::TraitItem { kind: TraitItemKind::Fn(sig, TraitFn::Provided(_)), ident, @@ -1749,15 +1750,17 @@ fn fn_sig(tcx: TyCtxt<'_>, def_id: DefId) -> ty::PolyFnSig<'_> { // `sig` method on the `ClosureSubsts`: // // substs.as_closure().sig(def_id, tcx) - bug!( - "to get the signature of a closure, use `substs.as_closure().sig()` not `fn_sig()`", + return Err( + "to get the signature of a closure, use `substs.as_closure().sig()` not `fn_sig()`" + .to_owned(), ); } - x => { - bug!("unexpected sort of node in fn_sig(): {:?}", x); + _ => { + return Err(format!("unexpected sort of node in fn_sig()")); } - } + }; + Ok(sig) } fn impl_trait_ref(tcx: TyCtxt<'_>, def_id: DefId) -> Option> { diff --git a/src/test/incremental/hashes/enum_constructors.rs b/src/test/incremental/hashes/enum_constructors.rs index 26ff6b109dc32..c467224ea8da1 100644 --- a/src/test/incremental/hashes/enum_constructors.rs +++ b/src/test/incremental/hashes/enum_constructors.rs @@ -139,7 +139,7 @@ pub mod change_constructor_path_indirectly_struct_like { #[rustc_clean( cfg="cfail2", - except="fn_sig,hir_owner,hir_owner_nodes,optimized_mir,\ + except="try_fn_sig,hir_owner,hir_owner_nodes,optimized_mir,\ typeck" )] #[rustc_clean(cfg="cfail3")] @@ -232,7 +232,7 @@ pub mod change_constructor_path_indirectly_tuple_like { #[rustc_clean( cfg="cfail2", - except="fn_sig,hir_owner,hir_owner_nodes,optimized_mir,\ + except="try_fn_sig,hir_owner,hir_owner_nodes,optimized_mir,\ typeck" )] #[rustc_clean(cfg="cfail3")] @@ -309,7 +309,7 @@ pub mod change_constructor_path_indirectly_c_like { #[rustc_clean( cfg="cfail2", - except="fn_sig,hir_owner,hir_owner_nodes,optimized_mir,\ + except="try_fn_sig,hir_owner,hir_owner_nodes,optimized_mir,\ typeck" )] #[rustc_clean(cfg="cfail3")] diff --git a/src/test/incremental/hashes/function_interfaces.rs b/src/test/incremental/hashes/function_interfaces.rs index c1062400c03db..b20364527c111 100644 --- a/src/test/incremental/hashes/function_interfaces.rs +++ b/src/test/incremental/hashes/function_interfaces.rs @@ -22,7 +22,7 @@ pub fn add_parameter() {} #[cfg(not(cfail1))] #[rustc_clean( cfg = "cfail2", - except = "hir_owner, hir_owner_nodes, optimized_mir, typeck, fn_sig" + except = "hir_owner, hir_owner_nodes, optimized_mir, typeck, try_fn_sig" )] #[rustc_clean(cfg = "cfail3")] pub fn add_parameter(p: i32) {} @@ -45,7 +45,7 @@ pub fn type_of_parameter(p: i32) {} #[cfg(not(cfail1))] #[rustc_clean( cfg = "cfail2", - except = "hir_owner, hir_owner_nodes, optimized_mir, typeck, fn_sig" + except = "hir_owner, hir_owner_nodes, optimized_mir, typeck, try_fn_sig" )] #[rustc_clean(cfg = "cfail3")] pub fn type_of_parameter(p: i64) {} @@ -58,7 +58,7 @@ pub fn type_of_parameter_ref(p: &i32) {} #[cfg(not(cfail1))] #[rustc_clean( cfg = "cfail2", - except = "hir_owner, hir_owner_nodes, optimized_mir, typeck, fn_sig" + except = "hir_owner, hir_owner_nodes, optimized_mir, typeck, try_fn_sig" )] #[rustc_clean(cfg = "cfail3")] pub fn type_of_parameter_ref(p: &mut i32) {} @@ -71,7 +71,7 @@ pub fn order_of_parameters(p1: i32, p2: i64) {} #[cfg(not(cfail1))] #[rustc_clean( cfg = "cfail2", - except = "hir_owner, hir_owner_nodes, optimized_mir, typeck, fn_sig" + except = "hir_owner, hir_owner_nodes, optimized_mir, typeck, try_fn_sig" )] #[rustc_clean(cfg = "cfail3")] pub fn order_of_parameters(p2: i64, p1: i32) {} @@ -84,7 +84,7 @@ pub fn make_unsafe() {} #[cfg(not(cfail1))] #[rustc_clean( cfg = "cfail2", - except = "hir_owner, hir_owner_nodes, optimized_mir, typeck, fn_sig" + except = "hir_owner, hir_owner_nodes, optimized_mir, typeck, try_fn_sig" )] #[rustc_clean(cfg = "cfail3")] pub unsafe fn make_unsafe() {} @@ -95,7 +95,7 @@ pub unsafe fn make_unsafe() {} pub fn make_extern() {} #[cfg(not(cfail1))] -#[rustc_clean(cfg = "cfail2", except = "hir_owner, hir_owner_nodes, typeck, fn_sig")] +#[rustc_clean(cfg = "cfail2", except = "hir_owner, hir_owner_nodes, typeck, try_fn_sig")] #[rustc_clean(cfg = "cfail3")] pub extern "C" fn make_extern() {} @@ -241,7 +241,7 @@ pub fn return_impl_trait() -> i32 { } #[cfg(not(cfail1))] -#[rustc_clean(cfg = "cfail2", except = "hir_owner, hir_owner_nodes, typeck, fn_sig")] +#[rustc_clean(cfg = "cfail2", except = "hir_owner, hir_owner_nodes, typeck, try_fn_sig")] #[rustc_clean(cfg = "cfail3")] pub fn return_impl_trait() -> impl Clone { 0 @@ -274,7 +274,7 @@ pub mod change_return_type_indirectly { #[rustc_clean( cfg = "cfail2", - except = "hir_owner, hir_owner_nodes, optimized_mir, typeck, fn_sig" + except = "hir_owner, hir_owner_nodes, optimized_mir, typeck, try_fn_sig" )] #[rustc_clean(cfg = "cfail3")] pub fn indirect_return_type() -> ReturnType { @@ -292,7 +292,7 @@ pub mod change_parameter_type_indirectly { #[rustc_clean( cfg = "cfail2", - except = "hir_owner, hir_owner_nodes, optimized_mir, typeck, fn_sig" + except = "hir_owner, hir_owner_nodes, optimized_mir, typeck, try_fn_sig" )] #[rustc_clean(cfg = "cfail3")] pub fn indirect_parameter_type(p: ParameterType) {} diff --git a/src/test/incremental/hashes/inherent_impls.rs b/src/test/incremental/hashes/inherent_impls.rs index 8d49ab4b67859..e819ae858c97f 100644 --- a/src/test/incremental/hashes/inherent_impls.rs +++ b/src/test/incremental/hashes/inherent_impls.rs @@ -120,7 +120,7 @@ impl Foo { impl Foo { #[rustc_clean( cfg="cfail2", - except="hir_owner,hir_owner_nodes,fn_sig,typeck,optimized_mir" + except="hir_owner,hir_owner_nodes,try_fn_sig,typeck,optimized_mir" )] #[rustc_clean(cfg="cfail3")] pub fn method_selfmutness(&mut self) { } @@ -160,7 +160,7 @@ impl Foo { impl Foo { #[rustc_clean( cfg="cfail2", - except="hir_owner,hir_owner_nodes,fn_sig,typeck,optimized_mir" + except="hir_owner,hir_owner_nodes,try_fn_sig,typeck,optimized_mir" )] #[rustc_clean(cfg="cfail3")] pub fn add_method_parameter(&self, _: i32) { } @@ -197,7 +197,7 @@ impl Foo { impl Foo { #[rustc_clean( cfg="cfail2", - except="hir_owner,hir_owner_nodes,fn_sig,optimized_mir,typeck")] + except="hir_owner,hir_owner_nodes,try_fn_sig,optimized_mir,typeck")] #[rustc_clean(cfg="cfail3")] pub fn change_method_return_type(&self) -> u8 { 0 } } @@ -251,7 +251,7 @@ impl Foo { impl Foo { #[rustc_clean( cfg="cfail2", - except="hir_owner,hir_owner_nodes,fn_sig,typeck,optimized_mir" + except="hir_owner,hir_owner_nodes,try_fn_sig,typeck,optimized_mir" )] #[rustc_clean(cfg="cfail3")] pub unsafe fn make_method_unsafe(&self) { } @@ -269,7 +269,7 @@ impl Foo { #[rustc_clean(cfg="cfail2")] #[rustc_clean(cfg="cfail3")] impl Foo { - #[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,fn_sig,typeck")] + #[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,try_fn_sig,typeck")] #[rustc_clean(cfg="cfail3")] pub extern "C" fn make_method_extern(&self) { } } @@ -286,7 +286,7 @@ impl Foo { #[rustc_clean(cfg="cfail2")] #[rustc_clean(cfg="cfail3")] impl Foo { - #[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,fn_sig,typeck")] + #[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,try_fn_sig,typeck")] #[rustc_clean(cfg="cfail3")] pub extern "system" fn change_method_calling_convention(&self) { } } @@ -453,7 +453,7 @@ impl Bar { impl Bar { #[rustc_clean( cfg="cfail2", - except="generics_of,fn_sig,typeck,try_type_of,optimized_mir" + except="generics_of,try_fn_sig,typeck,try_type_of,optimized_mir" )] #[rustc_clean(cfg="cfail3")] pub fn add_type_parameter_to_impl(&self) { } @@ -471,7 +471,7 @@ impl Bar { #[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes")] #[rustc_clean(cfg="cfail3")] impl Bar { - #[rustc_clean(cfg="cfail2", except="fn_sig,optimized_mir,typeck")] + #[rustc_clean(cfg="cfail2", except="try_fn_sig,optimized_mir,typeck")] #[rustc_clean(cfg="cfail3")] pub fn change_impl_self_type(&self) { } } diff --git a/src/test/incremental/hashes/struct_constructors.rs b/src/test/incremental/hashes/struct_constructors.rs index edec03d4f057e..b1264c1d6e23d 100644 --- a/src/test/incremental/hashes/struct_constructors.rs +++ b/src/test/incremental/hashes/struct_constructors.rs @@ -173,7 +173,7 @@ pub mod change_constructor_path_indirectly_regular_struct { #[rustc_clean( cfg="cfail2", - except="fn_sig,hir_owner,hir_owner_nodes,optimized_mir,typeck" + except="try_fn_sig,hir_owner,hir_owner_nodes,optimized_mir,typeck" )] #[rustc_clean(cfg="cfail3")] pub fn function() -> Struct { @@ -230,7 +230,7 @@ pub mod change_constructor_path_indirectly_tuple_struct { #[rustc_clean( cfg="cfail2", - except="fn_sig,hir_owner,hir_owner_nodes,optimized_mir,typeck" + except="try_fn_sig,hir_owner,hir_owner_nodes,optimized_mir,typeck" )] #[rustc_clean(cfg="cfail3")] pub fn function() -> Struct { diff --git a/src/test/ui/dep-graph/dep-graph-struct-signature.rs b/src/test/ui/dep-graph/dep-graph-struct-signature.rs index c344347cc0769..ab40e917f84b2 100644 --- a/src/test/ui/dep-graph/dep-graph-struct-signature.rs +++ b/src/test/ui/dep-graph/dep-graph-struct-signature.rs @@ -28,15 +28,15 @@ mod signatures { #[rustc_then_this_would_need(associated_item)] //~ ERROR no path #[rustc_then_this_would_need(trait_def)] //~ ERROR no path trait Bar { - #[rustc_then_this_would_need(fn_sig)] //~ ERROR OK + #[rustc_then_this_would_need(try_fn_sig)] //~ ERROR OK fn do_something(x: WillChange); } - #[rustc_then_this_would_need(fn_sig)] //~ ERROR OK + #[rustc_then_this_would_need(try_fn_sig)] //~ ERROR OK #[rustc_then_this_would_need(typeck)] //~ ERROR OK fn some_fn(x: WillChange) { } - #[rustc_then_this_would_need(fn_sig)] //~ ERROR OK + #[rustc_then_this_would_need(try_fn_sig)] //~ ERROR OK #[rustc_then_this_would_need(typeck)] //~ ERROR OK fn new_foo(x: u32, y: u32) -> WillChange { WillChange { x: x, y: y } @@ -44,14 +44,14 @@ mod signatures { #[rustc_then_this_would_need(try_type_of)] //~ ERROR OK impl WillChange { - #[rustc_then_this_would_need(fn_sig)] //~ ERROR OK + #[rustc_then_this_would_need(try_fn_sig)] //~ ERROR OK #[rustc_then_this_would_need(typeck)] //~ ERROR OK fn new(x: u32, y: u32) -> WillChange { loop { } } } #[rustc_then_this_would_need(try_type_of)] //~ ERROR OK impl WillChange { - #[rustc_then_this_would_need(fn_sig)] //~ ERROR OK + #[rustc_then_this_would_need(try_fn_sig)] //~ ERROR OK #[rustc_then_this_would_need(typeck)] //~ ERROR OK fn method(&self, x: u32) { } } @@ -73,14 +73,14 @@ mod invalid_signatures { #[rustc_then_this_would_need(try_type_of)] //~ ERROR no path trait A { - #[rustc_then_this_would_need(fn_sig)] //~ ERROR no path + #[rustc_then_this_would_need(try_fn_sig)] //~ ERROR no path fn do_something_else_twice(x: WontChange); } - #[rustc_then_this_would_need(fn_sig)] //~ ERROR no path + #[rustc_then_this_would_need(try_fn_sig)] //~ ERROR no path fn b(x: WontChange) { } - #[rustc_then_this_would_need(fn_sig)] //~ ERROR no path from `WillChange` + #[rustc_then_this_would_need(try_fn_sig)] //~ ERROR no path from `WillChange` #[rustc_then_this_would_need(typeck)] //~ ERROR no path from `WillChange` fn c(x: u32) { } } diff --git a/src/test/ui/dep-graph/dep-graph-struct-signature.stderr b/src/test/ui/dep-graph/dep-graph-struct-signature.stderr index 6fcdf6f74f0b8..328d67d04e502 100644 --- a/src/test/ui/dep-graph/dep-graph-struct-signature.stderr +++ b/src/test/ui/dep-graph/dep-graph-struct-signature.stderr @@ -19,8 +19,8 @@ LL | #[rustc_then_this_would_need(trait_def)] error: OK --> $DIR/dep-graph-struct-signature.rs:35:5 | -LL | #[rustc_then_this_would_need(fn_sig)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | #[rustc_then_this_would_need(try_fn_sig)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: OK --> $DIR/dep-graph-struct-signature.rs:36:5 @@ -31,8 +31,8 @@ LL | #[rustc_then_this_would_need(typeck)] error: OK --> $DIR/dep-graph-struct-signature.rs:39:5 | -LL | #[rustc_then_this_would_need(fn_sig)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | #[rustc_then_this_would_need(try_fn_sig)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: OK --> $DIR/dep-graph-struct-signature.rs:40:5 @@ -76,17 +76,17 @@ error: no path from `WillChange` to `try_type_of` LL | #[rustc_then_this_would_need(try_type_of)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: no path from `WillChange` to `fn_sig` +error: no path from `WillChange` to `try_fn_sig` --> $DIR/dep-graph-struct-signature.rs:80:5 | -LL | #[rustc_then_this_would_need(fn_sig)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | #[rustc_then_this_would_need(try_fn_sig)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: no path from `WillChange` to `fn_sig` +error: no path from `WillChange` to `try_fn_sig` --> $DIR/dep-graph-struct-signature.rs:83:5 | -LL | #[rustc_then_this_would_need(fn_sig)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | #[rustc_then_this_would_need(try_fn_sig)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: no path from `WillChange` to `typeck` --> $DIR/dep-graph-struct-signature.rs:84:5 @@ -97,20 +97,20 @@ LL | #[rustc_then_this_would_need(typeck)] error: OK --> $DIR/dep-graph-struct-signature.rs:31:9 | -LL | #[rustc_then_this_would_need(fn_sig)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | #[rustc_then_this_would_need(try_fn_sig)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: no path from `WillChange` to `fn_sig` +error: no path from `WillChange` to `try_fn_sig` --> $DIR/dep-graph-struct-signature.rs:76:9 | -LL | #[rustc_then_this_would_need(fn_sig)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | #[rustc_then_this_would_need(try_fn_sig)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: OK --> $DIR/dep-graph-struct-signature.rs:47:9 | -LL | #[rustc_then_this_would_need(fn_sig)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | #[rustc_then_this_would_need(try_fn_sig)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: OK --> $DIR/dep-graph-struct-signature.rs:48:9 @@ -121,8 +121,8 @@ LL | #[rustc_then_this_would_need(typeck)] error: OK --> $DIR/dep-graph-struct-signature.rs:54:9 | -LL | #[rustc_then_this_would_need(fn_sig)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | #[rustc_then_this_would_need(try_fn_sig)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: OK --> $DIR/dep-graph-struct-signature.rs:55:9 diff --git a/src/test/ui/dep-graph/dep-graph-type-alias.rs b/src/test/ui/dep-graph/dep-graph-type-alias.rs index 62f57076b032f..376696e6e7072 100644 --- a/src/test/ui/dep-graph/dep-graph-type-alias.rs +++ b/src/test/ui/dep-graph/dep-graph-type-alias.rs @@ -32,7 +32,7 @@ enum Enum { #[rustc_then_this_would_need(try_type_of)] //~ ERROR no path trait Trait { - #[rustc_then_this_would_need(fn_sig)] //~ ERROR OK + #[rustc_then_this_would_need(try_fn_sig)] //~ ERROR OK fn method(&self, _: TypeAlias); } @@ -40,7 +40,7 @@ struct SomeType; #[rustc_then_this_would_need(try_type_of)] //~ ERROR no path impl SomeType { - #[rustc_then_this_would_need(fn_sig)] //~ ERROR OK + #[rustc_then_this_would_need(try_fn_sig)] //~ ERROR OK #[rustc_then_this_would_need(typeck)] //~ ERROR OK fn method(&self, _: TypeAlias) {} } @@ -48,7 +48,7 @@ impl SomeType { #[rustc_then_this_would_need(try_type_of)] //~ ERROR OK type TypeAlias2 = TypeAlias; -#[rustc_then_this_would_need(fn_sig)] //~ ERROR OK +#[rustc_then_this_would_need(try_fn_sig)] //~ ERROR OK #[rustc_then_this_would_need(typeck)] //~ ERROR OK fn function(_: TypeAlias) { diff --git a/src/test/ui/dep-graph/dep-graph-type-alias.stderr b/src/test/ui/dep-graph/dep-graph-type-alias.stderr index cc15e157e48ba..1bd2f0c87ff77 100644 --- a/src/test/ui/dep-graph/dep-graph-type-alias.stderr +++ b/src/test/ui/dep-graph/dep-graph-type-alias.stderr @@ -43,8 +43,8 @@ LL | #[rustc_then_this_would_need(try_type_of)] error: OK --> $DIR/dep-graph-type-alias.rs:51:1 | -LL | #[rustc_then_this_would_need(fn_sig)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | #[rustc_then_this_would_need(try_fn_sig)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: OK --> $DIR/dep-graph-type-alias.rs:52:1 @@ -55,14 +55,14 @@ LL | #[rustc_then_this_would_need(typeck)] error: OK --> $DIR/dep-graph-type-alias.rs:35:5 | -LL | #[rustc_then_this_would_need(fn_sig)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | #[rustc_then_this_would_need(try_fn_sig)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: OK --> $DIR/dep-graph-type-alias.rs:43:5 | -LL | #[rustc_then_this_would_need(fn_sig)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | #[rustc_then_this_would_need(try_fn_sig)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: OK --> $DIR/dep-graph-type-alias.rs:44:5 From 488c3680eeedcc6566b05c31fe74cc8747973e45 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Wed, 23 Dec 2020 21:53:00 +0100 Subject: [PATCH 09/16] Infallible version of explicit_item_bounds. --- compiler/rustc_typeck/src/collect/item_bounds.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_typeck/src/collect/item_bounds.rs b/compiler/rustc_typeck/src/collect/item_bounds.rs index fe18dc5ed0c69..e43ca0b030ab6 100644 --- a/compiler/rustc_typeck/src/collect/item_bounds.rs +++ b/compiler/rustc_typeck/src/collect/item_bounds.rs @@ -97,7 +97,7 @@ pub(super) fn explicit_item_bounds( span, .. }) => opaque_type_bounds(tcx, def_id, bounds, *span), - _ => bug!("item_bounds called on {:?}", def_id), + _ => &[], } } From faee7807a52dd876294594a49b62ca7d36c4874b Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sun, 6 Dec 2020 22:19:29 +0100 Subject: [PATCH 10/16] Iterate on type_of. --- compiler/rustc_metadata/src/rmeta/encoder.rs | 57 +++----------------- 1 file changed, 7 insertions(+), 50 deletions(-) diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index 254954c83762a..600897f1c1ba8 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -950,6 +950,9 @@ impl EncodeContext<'a, 'tcx> { if let DefKind::Trait | DefKind::TraitAlias = def_kind { record!(self.tables.super_predicates[def_id] <- self.tcx.super_predicates_of(def_id)); } + if let Ok(ty) = self.tcx.try_type_of(def_id) { + record!(self.tables.ty[def_id] <- ty); + } } let inherent_impls = tcx.crate_inherent_impls(LOCAL_CRATE); for (def_id, implementations) in inherent_impls.inherent_impls.iter() { @@ -964,11 +967,6 @@ impl EncodeContext<'a, 'tcx> { } } - fn encode_item_type(&mut self, def_id: DefId) { - debug!("EncodeContext::encode_item_type({:?})", def_id); - record!(self.tables.ty[def_id] <- self.tcx.type_of(def_id)); - } - fn encode_enum_variant_info(&mut self, def: &ty::AdtDef, index: VariantIdx) { let tcx = self.tcx; let variant = &def.variants[index]; @@ -988,7 +986,6 @@ impl EncodeContext<'a, 'tcx> { f.did.index })); self.encode_ident_span(def_id, variant.ident); - self.encode_item_type(def_id); if variant.ctor_kind == CtorKind::Fn { // FIXME(eddyb) encode signature only in `encode_enum_variant_ctor`. if let Some(ctor_def_id) = variant.ctor_def_id { @@ -1012,7 +1009,6 @@ impl EncodeContext<'a, 'tcx> { }; record!(self.tables.kind[def_id] <- EntryKind::Variant(self.lazy(data))); - self.encode_item_type(def_id); if variant.ctor_kind == CtorKind::Fn { record!(self.tables.fn_sig[def_id] <- tcx.fn_sig(def_id)); } @@ -1073,7 +1069,6 @@ impl EncodeContext<'a, 'tcx> { record!(self.tables.kind[def_id] <- EntryKind::Field); self.encode_ident_span(def_id, field.ident); - self.encode_item_type(def_id); } fn encode_struct_ctor(&mut self, adt_def: &ty::AdtDef, def_id: DefId) { @@ -1089,7 +1084,6 @@ impl EncodeContext<'a, 'tcx> { }; record!(self.tables.kind[def_id] <- EntryKind::Struct(self.lazy(data), adt_def.repr)); - self.encode_item_type(def_id); if variant.ctor_kind == CtorKind::Fn { record!(self.tables.fn_sig[def_id] <- tcx.fn_sig(def_id)); } @@ -1157,16 +1151,6 @@ impl EncodeContext<'a, 'tcx> { } } self.encode_ident_span(def_id, ast_item.ident); - match trait_item.kind { - ty::AssocKind::Const | ty::AssocKind::Fn => { - self.encode_item_type(def_id); - } - ty::AssocKind::Type => { - if trait_item.defaultness.has_value() { - self.encode_item_type(def_id); - } - } - } if trait_item.kind == ty::AssocKind::Fn { record!(self.tables.fn_sig[def_id] <- tcx.fn_sig(def_id)); } @@ -1223,7 +1207,6 @@ impl EncodeContext<'a, 'tcx> { } } self.encode_ident_span(def_id, impl_item.ident); - self.encode_item_type(def_id); if impl_item.kind == ty::AssocKind::Fn { record!(self.tables.fn_sig[def_id] <- tcx.fn_sig(def_id)); } @@ -1471,18 +1454,6 @@ impl EncodeContext<'a, 'tcx> { } _ => {} } - match item.kind { - hir::ItemKind::Static(..) - | hir::ItemKind::Const(..) - | hir::ItemKind::Fn(..) - | hir::ItemKind::TyAlias(..) - | hir::ItemKind::OpaqueTy(..) - | hir::ItemKind::Enum(..) - | hir::ItemKind::Struct(..) - | hir::ItemKind::Union(..) - | hir::ItemKind::Impl { .. } => self.encode_item_type(def_id), - _ => {} - } if let hir::ItemKind::Fn(..) = item.kind { record!(self.tables.fn_sig[def_id] <- tcx.fn_sig(def_id)); } @@ -1500,11 +1471,8 @@ impl EncodeContext<'a, 'tcx> { self.encode_ident_span(def_id, macro_def.ident); } - fn encode_info_for_generic_param(&mut self, def_id: DefId, kind: EntryKind, encode_type: bool) { + fn encode_info_for_generic_param(&mut self, def_id: DefId, kind: EntryKind) { record!(self.tables.kind[def_id] <- kind); - if encode_type { - self.encode_item_type(def_id); - } } fn encode_info_for_closure(&mut self, def_id: LocalDefId) { @@ -1527,7 +1495,6 @@ impl EncodeContext<'a, 'tcx> { _ => bug!("closure that is neither generator nor closure"), } - self.encode_item_type(def_id.to_def_id()); if let ty::Closure(def_id, substs) = *ty.kind() { record!(self.tables.fn_sig[def_id] <- substs.as_closure().sig()); } @@ -1541,7 +1508,6 @@ impl EncodeContext<'a, 'tcx> { let qualifs = self.tcx.mir_const_qualif(def_id); record!(self.tables.kind[def_id.to_def_id()] <- EntryKind::AnonConst(qualifs, const_data)); - self.encode_item_type(def_id.to_def_id()); } fn encode_native_libraries(&mut self) -> Lazy<[NativeLib]> { @@ -1817,7 +1783,6 @@ impl EncodeContext<'a, 'tcx> { } } self.encode_ident_span(def_id, nitem.ident); - self.encode_item_type(def_id); if let hir::ForeignItemKind::Fn(..) = nitem.kind { record!(self.tables.fn_sig[def_id] <- tcx.fn_sig(def_id)); } @@ -1875,19 +1840,11 @@ impl EncodeContext<'a, 'tcx> { let def_id = self.tcx.hir().local_def_id(param.hir_id); match param.kind { GenericParamKind::Lifetime { .. } => continue, - GenericParamKind::Type { default, .. } => { - self.encode_info_for_generic_param( - def_id.to_def_id(), - EntryKind::TypeParam, - default.is_some(), - ); + GenericParamKind::Type { .. } => { + self.encode_info_for_generic_param(def_id.to_def_id(), EntryKind::TypeParam); } GenericParamKind::Const { .. } => { - self.encode_info_for_generic_param( - def_id.to_def_id(), - EntryKind::ConstParam, - true, - ); + self.encode_info_for_generic_param(def_id.to_def_id(), EntryKind::ConstParam); // FIXME(const_generics_defaults) } } From 478da8f510b4eff6d3f8a6201941a9116e2f917c Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sat, 16 Jan 2021 23:17:21 +0100 Subject: [PATCH 11/16] Filter type_of. --- compiler/rustc_metadata/src/rmeta/encoder.rs | 41 +++++++++++++++++++- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index 600897f1c1ba8..1f92384798980 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -906,6 +906,41 @@ fn should_encode_generics(def_kind: DefKind) -> bool { } } +fn should_encode_type(def_kind: DefKind) -> bool { + match def_kind { + DefKind::Struct + | DefKind::Union + | DefKind::Enum + | DefKind::Variant + | DefKind::TyAlias + | DefKind::ForeignTy + | DefKind::AssocTy + | DefKind::TyParam + | DefKind::Fn + | DefKind::Const + | DefKind::ConstParam + | DefKind::Static + | DefKind::Ctor(..) + | DefKind::AssocFn + | DefKind::AssocConst + | DefKind::AnonConst + | DefKind::OpaqueTy + | DefKind::Field + | DefKind::Impl + | DefKind::Closure + | DefKind::Generator => true, + DefKind::Mod + | DefKind::ForeignMod + | DefKind::Trait + | DefKind::TraitAlias + | DefKind::Macro(..) + | DefKind::Use + | DefKind::LifetimeParam + | DefKind::GlobalAsm + | DefKind::ExternCrate => false, + } +} + impl EncodeContext<'a, 'tcx> { fn encode_def_ids(&mut self) { if self.is_proc_macro { @@ -950,8 +985,10 @@ impl EncodeContext<'a, 'tcx> { if let DefKind::Trait | DefKind::TraitAlias = def_kind { record!(self.tables.super_predicates[def_id] <- self.tcx.super_predicates_of(def_id)); } - if let Ok(ty) = self.tcx.try_type_of(def_id) { - record!(self.tables.ty[def_id] <- ty); + if should_encode_type(def_kind) { + if let Ok(ty) = self.tcx.try_type_of(def_id) { + record!(self.tables.ty[def_id] <- ty); + } } } let inherent_impls = tcx.crate_inherent_impls(LOCAL_CRATE); From f738c206d886e2695247b2d1f75e4bff677dcd46 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sun, 13 Dec 2020 22:16:20 +0100 Subject: [PATCH 12/16] Iterate on fn_sig. --- compiler/rustc_metadata/src/rmeta/encoder.rs | 39 ++------------------ 1 file changed, 3 insertions(+), 36 deletions(-) diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index 1f92384798980..08eda3b5d078d 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -990,6 +990,9 @@ impl EncodeContext<'a, 'tcx> { record!(self.tables.ty[def_id] <- ty); } } + if let Ok(sig) = tcx.try_fn_sig(def_id) { + record!(self.tables.fn_sig[def_id] <- sig); + } } let inherent_impls = tcx.crate_inherent_impls(LOCAL_CRATE); for (def_id, implementations) in inherent_impls.inherent_impls.iter() { @@ -1005,7 +1008,6 @@ impl EncodeContext<'a, 'tcx> { } fn encode_enum_variant_info(&mut self, def: &ty::AdtDef, index: VariantIdx) { - let tcx = self.tcx; let variant = &def.variants[index]; let def_id = variant.def_id; debug!("EncodeContext::encode_enum_variant_info({:?})", def_id); @@ -1023,16 +1025,9 @@ impl EncodeContext<'a, 'tcx> { f.did.index })); self.encode_ident_span(def_id, variant.ident); - if variant.ctor_kind == CtorKind::Fn { - // FIXME(eddyb) encode signature only in `encode_enum_variant_ctor`. - if let Some(ctor_def_id) = variant.ctor_def_id { - record!(self.tables.fn_sig[def_id] <- tcx.fn_sig(ctor_def_id)); - } - } } fn encode_enum_variant_ctor(&mut self, def: &ty::AdtDef, index: VariantIdx) { - let tcx = self.tcx; let variant = &def.variants[index]; let def_id = variant.ctor_def_id.unwrap(); debug!("EncodeContext::encode_enum_variant_ctor({:?})", def_id); @@ -1046,9 +1041,6 @@ impl EncodeContext<'a, 'tcx> { }; record!(self.tables.kind[def_id] <- EntryKind::Variant(self.lazy(data))); - if variant.ctor_kind == CtorKind::Fn { - record!(self.tables.fn_sig[def_id] <- tcx.fn_sig(def_id)); - } } fn encode_info_for_mod(&mut self, local_def_id: LocalDefId, md: &hir::Mod<'_>) { @@ -1110,7 +1102,6 @@ impl EncodeContext<'a, 'tcx> { fn encode_struct_ctor(&mut self, adt_def: &ty::AdtDef, def_id: DefId) { debug!("EncodeContext::encode_struct_ctor({:?})", def_id); - let tcx = self.tcx; let variant = adt_def.non_enum_variant(); let data = VariantData { @@ -1121,9 +1112,6 @@ impl EncodeContext<'a, 'tcx> { }; record!(self.tables.kind[def_id] <- EntryKind::Struct(self.lazy(data), adt_def.repr)); - if variant.ctor_kind == CtorKind::Fn { - record!(self.tables.fn_sig[def_id] <- tcx.fn_sig(def_id)); - } } fn encode_explicit_item_bounds(&mut self, def_id: DefId) { @@ -1188,15 +1176,10 @@ impl EncodeContext<'a, 'tcx> { } } self.encode_ident_span(def_id, ast_item.ident); - if trait_item.kind == ty::AssocKind::Fn { - record!(self.tables.fn_sig[def_id] <- tcx.fn_sig(def_id)); - } } fn encode_info_for_impl_item(&mut self, def_id: DefId) { debug!("EncodeContext::encode_info_for_impl_item({:?})", def_id); - let tcx = self.tcx; - let hir_id = self.tcx.hir().local_def_id_to_hir_id(def_id.expect_local()); let ast_item = self.tcx.hir().expect_impl_item(hir_id); let impl_item = self.tcx.associated_item(def_id); @@ -1244,9 +1227,6 @@ impl EncodeContext<'a, 'tcx> { } } self.encode_ident_span(def_id, impl_item.ident); - if impl_item.kind == ty::AssocKind::Fn { - record!(self.tables.fn_sig[def_id] <- tcx.fn_sig(def_id)); - } } fn encode_fn_param_names_for_body(&mut self, body_id: hir::BodyId) -> Lazy<[Ident]> { @@ -1343,8 +1323,6 @@ impl EncodeContext<'a, 'tcx> { } fn encode_info_for_item(&mut self, def_id: DefId, item: &'tcx hir::Item<'tcx>) { - let tcx = self.tcx; - debug!("EncodeContext::encode_info_for_item({:?})", def_id); self.encode_ident_span(def_id, item.ident); @@ -1491,9 +1469,6 @@ impl EncodeContext<'a, 'tcx> { } _ => {} } - if let hir::ItemKind::Fn(..) = item.kind { - record!(self.tables.fn_sig[def_id] <- tcx.fn_sig(def_id)); - } if let hir::ItemKind::Impl { .. } = item.kind { if let Some(trait_ref) = self.tcx.impl_trait_ref(def_id) { record!(self.tables.impl_trait_ref[def_id] <- trait_ref); @@ -1532,9 +1507,6 @@ impl EncodeContext<'a, 'tcx> { _ => bug!("closure that is neither generator nor closure"), } - if let ty::Closure(def_id, substs) = *ty.kind() { - record!(self.tables.fn_sig[def_id] <- substs.as_closure().sig()); - } } fn encode_info_for_anon_const(&mut self, def_id: LocalDefId) { @@ -1792,8 +1764,6 @@ impl EncodeContext<'a, 'tcx> { } fn encode_info_for_foreign_item(&mut self, def_id: DefId, nitem: &hir::ForeignItem<'_>) { - let tcx = self.tcx; - debug!("EncodeContext::encode_info_for_foreign_item({:?})", def_id); match nitem.kind { @@ -1820,9 +1790,6 @@ impl EncodeContext<'a, 'tcx> { } } self.encode_ident_span(def_id, nitem.ident); - if let hir::ForeignItemKind::Fn(..) = nitem.kind { - record!(self.tables.fn_sig[def_id] <- tcx.fn_sig(def_id)); - } } } From 7aedff6b11dfee038896909140f3623517c218b7 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Fri, 18 Dec 2020 21:05:14 +0100 Subject: [PATCH 13/16] Iterate on explicit_item_bounds. --- compiler/rustc_metadata/src/rmeta/encoder.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index 08eda3b5d078d..0a56213962c4d 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -993,6 +993,7 @@ impl EncodeContext<'a, 'tcx> { if let Ok(sig) = tcx.try_fn_sig(def_id) { record!(self.tables.fn_sig[def_id] <- sig); } + self.encode_explicit_item_bounds(def_id); } let inherent_impls = tcx.crate_inherent_impls(LOCAL_CRATE); for (def_id, implementations) in inherent_impls.inherent_impls.iter() { @@ -1171,7 +1172,6 @@ impl EncodeContext<'a, 'tcx> { }))); } ty::AssocKind::Type => { - self.encode_explicit_item_bounds(def_id); record!(self.tables.kind[def_id] <- EntryKind::AssocType(container)); } } @@ -1349,10 +1349,7 @@ impl EncodeContext<'a, 'tcx> { hir::ItemKind::ForeignMod { .. } => EntryKind::ForeignMod, hir::ItemKind::GlobalAsm(..) => EntryKind::GlobalAsm, hir::ItemKind::TyAlias(..) => EntryKind::Type, - hir::ItemKind::OpaqueTy(..) => { - self.encode_explicit_item_bounds(def_id); - EntryKind::OpaqueTy - } + hir::ItemKind::OpaqueTy(..) => EntryKind::OpaqueTy, hir::ItemKind::Enum(..) => EntryKind::Enum(self.tcx.adt_def(def_id).repr), hir::ItemKind::Struct(ref struct_def, _) => { let adt_def = self.tcx.adt_def(def_id); From 45867ec2f09753870c2c3fd0c222afbd26116514 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sat, 16 Jan 2021 23:17:47 +0100 Subject: [PATCH 14/16] Filter fn_sig. --- compiler/rustc_metadata/src/rmeta/encoder.rs | 41 +++++++++++++++++++- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index 0a56213962c4d..9c608db217f1b 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -941,6 +941,41 @@ fn should_encode_type(def_kind: DefKind) -> bool { } } +fn should_encode_fn_sig(def_kind: DefKind) -> bool { + match def_kind { + DefKind::Variant + | DefKind::TraitAlias + | DefKind::Fn + | DefKind::Ctor(..) + | DefKind::AssocFn => true, + DefKind::Struct + | DefKind::Union + | DefKind::Enum + | DefKind::Trait + | DefKind::TyAlias + | DefKind::ForeignTy + | DefKind::AssocTy + | DefKind::Const + | DefKind::Static + | DefKind::AssocConst + | DefKind::AnonConst + | DefKind::OpaqueTy + | DefKind::Impl + | DefKind::Closure + | DefKind::Generator + | DefKind::Mod + | DefKind::Field + | DefKind::ForeignMod + | DefKind::TyParam + | DefKind::ConstParam + | DefKind::Macro(..) + | DefKind::Use + | DefKind::LifetimeParam + | DefKind::GlobalAsm + | DefKind::ExternCrate => false, + } +} + impl EncodeContext<'a, 'tcx> { fn encode_def_ids(&mut self) { if self.is_proc_macro { @@ -990,8 +1025,10 @@ impl EncodeContext<'a, 'tcx> { record!(self.tables.ty[def_id] <- ty); } } - if let Ok(sig) = tcx.try_fn_sig(def_id) { - record!(self.tables.fn_sig[def_id] <- sig); + if should_encode_fn_sig(def_kind) { + if let Ok(sig) = tcx.try_fn_sig(def_id) { + record!(self.tables.fn_sig[def_id] <- sig); + } } self.encode_explicit_item_bounds(def_id); } From 97008d480cf4e871c570874419f296e3b44ef879 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Fri, 5 Feb 2021 09:44:09 +0100 Subject: [PATCH 15/16] Filter explicit_item_bounds. --- compiler/rustc_metadata/src/rmeta/encoder.rs | 49 ++++++++++++++++---- 1 file changed, 40 insertions(+), 9 deletions(-) diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index 9c608db217f1b..c371e72308f6a 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -976,6 +976,40 @@ fn should_encode_fn_sig(def_kind: DefKind) -> bool { } } +fn should_encode_explicit_item_bounds(def_kind: DefKind) -> bool { + match def_kind { + DefKind::AssocTy | DefKind::OpaqueTy => true, + DefKind::Variant + | DefKind::TraitAlias + | DefKind::Fn + | DefKind::Ctor(..) + | DefKind::AssocFn + | DefKind::Struct + | DefKind::Union + | DefKind::Enum + | DefKind::Trait + | DefKind::TyAlias + | DefKind::ForeignTy + | DefKind::Const + | DefKind::Static + | DefKind::AssocConst + | DefKind::AnonConst + | DefKind::Impl + | DefKind::Closure + | DefKind::Generator + | DefKind::Mod + | DefKind::Field + | DefKind::ForeignMod + | DefKind::TyParam + | DefKind::ConstParam + | DefKind::Macro(..) + | DefKind::Use + | DefKind::LifetimeParam + | DefKind::GlobalAsm + | DefKind::ExternCrate => false, + } +} + impl EncodeContext<'a, 'tcx> { fn encode_def_ids(&mut self) { if self.is_proc_macro { @@ -1030,7 +1064,12 @@ impl EncodeContext<'a, 'tcx> { record!(self.tables.fn_sig[def_id] <- sig); } } - self.encode_explicit_item_bounds(def_id); + if should_encode_explicit_item_bounds(def_kind) { + let bounds = self.tcx.explicit_item_bounds(def_id); + if !bounds.is_empty() { + record!(self.tables.explicit_item_bounds[def_id] <- bounds); + } + } } let inherent_impls = tcx.crate_inherent_impls(LOCAL_CRATE); for (def_id, implementations) in inherent_impls.inherent_impls.iter() { @@ -1152,14 +1191,6 @@ impl EncodeContext<'a, 'tcx> { record!(self.tables.kind[def_id] <- EntryKind::Struct(self.lazy(data), adt_def.repr)); } - fn encode_explicit_item_bounds(&mut self, def_id: DefId) { - debug!("EncodeContext::encode_explicit_item_bounds({:?})", def_id); - let bounds = self.tcx.explicit_item_bounds(def_id); - if !bounds.is_empty() { - record!(self.tables.explicit_item_bounds[def_id] <- bounds); - } - } - fn encode_info_for_trait_item(&mut self, def_id: DefId) { debug!("EncodeContext::encode_info_for_trait_item({:?})", def_id); let tcx = self.tcx; From 4a5468b735435666e33d70ad4c0e7a93a8416e5b Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Wed, 24 Feb 2021 20:41:05 +0100 Subject: [PATCH 16/16] Add inline directives. --- compiler/rustc_middle/src/ty/query/mod.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/compiler/rustc_middle/src/ty/query/mod.rs b/compiler/rustc_middle/src/ty/query/mod.rs index 16f07969e3a2d..ec7106d6d6df7 100644 --- a/compiler/rustc_middle/src/ty/query/mod.rs +++ b/compiler/rustc_middle/src/ty/query/mod.rs @@ -307,18 +307,21 @@ mod sealed { use sealed::IntoQueryParam; impl TyCtxt<'tcx> { + #[inline] pub fn def_kind(self, def_id: impl IntoQueryParam) -> DefKind { let def_id = def_id.into_query_param(); self.opt_def_kind(def_id) .unwrap_or_else(|| bug!("def_kind: unsupported node: {:?}", def_id)) } + #[inline] pub fn fn_sig(self, def_id: impl IntoQueryParam) -> ty::PolyFnSig<'tcx> { let def_id = def_id.into_query_param(); self.try_fn_sig(def_id) .unwrap_or_else(|s| span_bug!(self.def_span(def_id), "fn_sig: {}", s)) } + #[inline] pub fn type_of(self, def_id: impl IntoQueryParam) -> Ty<'tcx> { let def_id = def_id.into_query_param(); self.try_type_of(def_id).unwrap_or_else(|msg| { @@ -329,18 +332,21 @@ impl TyCtxt<'tcx> { } impl TyCtxtAt<'tcx> { + #[inline] pub fn def_kind(self, def_id: impl IntoQueryParam) -> DefKind { let def_id = def_id.into_query_param(); self.opt_def_kind(def_id) .unwrap_or_else(|| bug!("def_kind: unsupported node: {:?}", def_id)) } + #[inline] pub fn fn_sig(self, def_id: impl IntoQueryParam) -> ty::PolyFnSig<'tcx> { let def_id = def_id.into_query_param(); self.try_fn_sig(def_id) .unwrap_or_else(|s| span_bug!(self.def_span(def_id), "fn_sig: {}", s)) } + #[inline] pub fn type_of(self, def_id: impl IntoQueryParam) -> Ty<'tcx> { let def_id = def_id.into_query_param(); self.try_type_of(def_id).unwrap_or_else(|msg| {