From 6cde87def1b9de2c7746523d7f19fe3a76d1893d Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Fri, 1 May 2020 11:32:20 +0200 Subject: [PATCH] Mark query function as must_use. --- src/librustc_codegen_ssa/base.rs | 2 +- src/librustc_metadata/rmeta/encoder.rs | 4 +- src/librustc_middle/ty/query/plumbing.rs | 1 + src/librustc_mir/transform/check_unsafety.rs | 2 +- src/librustc_passes/check_attr.rs | 4 +- src/librustc_typeck/check/mod.rs | 6 +- src/librustc_typeck/coherence/mod.rs | 2 +- src/librustc_typeck/collect.rs | 92 ++++++++++---------- 8 files changed, 57 insertions(+), 56 deletions(-) diff --git a/src/librustc_codegen_ssa/base.rs b/src/librustc_codegen_ssa/base.rs index fc6b547c5e70c..c5b95905ea012 100644 --- a/src/librustc_codegen_ssa/base.rs +++ b/src/librustc_codegen_ssa/base.rs @@ -539,7 +539,7 @@ pub fn codegen_crate( // unnecessarily. if tcx.dep_graph.is_fully_enabled() { for cgu in codegen_units { - tcx.codegen_unit(cgu.name()); + tcx.ensure().codegen_unit(cgu.name()); } } diff --git a/src/librustc_metadata/rmeta/encoder.rs b/src/librustc_metadata/rmeta/encoder.rs index da1dd1e589b00..952d3a01e3057 100644 --- a/src/librustc_metadata/rmeta/encoder.rs +++ b/src/librustc_metadata/rmeta/encoder.rs @@ -1729,8 +1729,8 @@ struct PrefetchVisitor<'tcx> { impl<'tcx> PrefetchVisitor<'tcx> { fn prefetch_mir(&self, def_id: LocalDefId) { if self.mir_keys.contains(&def_id) { - self.tcx.optimized_mir(def_id); - self.tcx.promoted_mir(def_id); + self.tcx.ensure().optimized_mir(def_id); + self.tcx.ensure().promoted_mir(def_id); } } } diff --git a/src/librustc_middle/ty/query/plumbing.rs b/src/librustc_middle/ty/query/plumbing.rs index e4237df592394..6a671c042aed3 100644 --- a/src/librustc_middle/ty/query/plumbing.rs +++ b/src/librustc_middle/ty/query/plumbing.rs @@ -430,6 +430,7 @@ macro_rules! define_queries_inner { $($(#[$attr])* #[inline(always)] + #[must_use] pub fn $name(self, key: query_helper_param_ty!($($K)*)) -> as QueryConfig>>::Stored { diff --git a/src/librustc_mir/transform/check_unsafety.rs b/src/librustc_mir/transform/check_unsafety.rs index 1c1560cbf9de7..af47721b311ff 100644 --- a/src/librustc_mir/transform/check_unsafety.rs +++ b/src/librustc_mir/transform/check_unsafety.rs @@ -617,7 +617,7 @@ pub fn check_unsafety(tcx: TyCtxt<'_>, def_id: DefId) { } UnsafetyViolationKind::BorrowPacked(lint_hir_id) => { if let Some(impl_def_id) = builtin_derive_def_id(tcx, def_id) { - tcx.unsafe_derive_on_repr_packed(impl_def_id); + tcx.ensure().unsafe_derive_on_repr_packed(impl_def_id); } else { tcx.struct_span_lint_hir( SAFE_PACKED_BORROWS, diff --git a/src/librustc_passes/check_attr.rs b/src/librustc_passes/check_attr.rs index 0fb715f450477..b54731d8881d1 100644 --- a/src/librustc_passes/check_attr.rs +++ b/src/librustc_passes/check_attr.rs @@ -77,7 +77,7 @@ impl CheckAttrVisitor<'tcx> { } if matches!(target, Target::Fn | Target::Method(_) | Target::ForeignFn) { - self.tcx.codegen_fn_attrs(self.tcx.hir().local_def_id(hir_id)); + self.tcx.ensure().codegen_fn_attrs(self.tcx.hir().local_def_id(hir_id)); } self.check_repr(attrs, span, target, item, hir_id); @@ -390,7 +390,7 @@ impl CheckAttrVisitor<'tcx> { } } if target == Target::Closure { - self.tcx.codegen_fn_attrs(self.tcx.hir().local_def_id(expr.hir_id)); + self.tcx.ensure().codegen_fn_attrs(self.tcx.hir().local_def_id(expr.hir_id)); } } diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index adbab3d4cb620..c431745198822 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -1748,11 +1748,11 @@ pub fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, it: &'tcx hir::Item<'tcx>) { // Consts can play a role in type-checking, so they are included here. hir::ItemKind::Static(..) => { let def_id = tcx.hir().local_def_id(it.hir_id); - tcx.typeck_tables_of(def_id); + tcx.ensure().typeck_tables_of(def_id); maybe_check_static_with_link_section(tcx, def_id, it.span); } hir::ItemKind::Const(..) => { - tcx.typeck_tables_of(tcx.hir().local_def_id(it.hir_id)); + tcx.ensure().typeck_tables_of(tcx.hir().local_def_id(it.hir_id)); } hir::ItemKind::Enum(ref enum_definition, _) => { check_enum(tcx, it.span, &enum_definition.variants, it.hir_id); @@ -2670,7 +2670,7 @@ pub fn check_enum<'tcx>( for v in vs { if let Some(ref e) = v.disr_expr { - tcx.typeck_tables_of(tcx.hir().local_def_id(e.hir_id)); + tcx.ensure().typeck_tables_of(tcx.hir().local_def_id(e.hir_id)); } } diff --git a/src/librustc_typeck/coherence/mod.rs b/src/librustc_typeck/coherence/mod.rs index d8ffb9f6b4c07..05d5a81217ce1 100644 --- a/src/librustc_typeck/coherence/mod.rs +++ b/src/librustc_typeck/coherence/mod.rs @@ -156,7 +156,7 @@ pub fn provide(providers: &mut Providers<'_>) { fn coherent_trait(tcx: TyCtxt<'_>, def_id: DefId) { // Trigger building the specialization graph for the trait. This will detect and report any // overlap errors. - tcx.specialization_graph_of(def_id); + tcx.ensure().specialization_graph_of(def_id); let impls = tcx.hir().trait_impls(def_id); for &hir_id in impls { diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index e6aa53dd4f3b7..df77024210193 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -207,12 +207,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.type_of(def_id); + self.tcx.ensure().type_of(def_id); } hir::GenericParamKind::Type { .. } => {} hir::GenericParamKind::Const { .. } => { let def_id = self.tcx.hir().local_def_id(param.hir_id); - self.tcx.type_of(def_id); + self.tcx.ensure().type_of(def_id); } } } @@ -222,8 +222,8 @@ impl Visitor<'tcx> for CollectItemTypesVisitor<'tcx> { fn visit_expr(&mut self, expr: &'tcx hir::Expr<'tcx>) { if let hir::ExprKind::Closure(..) = expr.kind { let def_id = self.tcx.hir().local_def_id(expr.hir_id); - self.tcx.generics_of(def_id); - self.tcx.type_of(def_id); + self.tcx.ensure().generics_of(def_id); + self.tcx.ensure().type_of(def_id); } intravisit::walk_expr(self, expr); } @@ -635,47 +635,47 @@ fn convert_item(tcx: TyCtxt<'_>, item_id: hir::HirId) { hir::ItemKind::ForeignMod(ref foreign_mod) => { for item in foreign_mod.items { let def_id = tcx.hir().local_def_id(item.hir_id); - tcx.generics_of(def_id); - tcx.type_of(def_id); - tcx.predicates_of(def_id); + tcx.ensure().generics_of(def_id); + tcx.ensure().type_of(def_id); + tcx.ensure().predicates_of(def_id); if let hir::ForeignItemKind::Fn(..) = item.kind { - tcx.fn_sig(def_id); + tcx.ensure().fn_sig(def_id); } } } hir::ItemKind::Enum(ref enum_definition, _) => { - tcx.generics_of(def_id); - tcx.type_of(def_id); - tcx.predicates_of(def_id); + tcx.ensure().generics_of(def_id); + tcx.ensure().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.generics_of(def_id); - tcx.type_of(def_id); - tcx.impl_trait_ref(def_id); - tcx.predicates_of(def_id); + tcx.ensure().generics_of(def_id); + tcx.ensure().type_of(def_id); + tcx.ensure().impl_trait_ref(def_id); + tcx.ensure().predicates_of(def_id); } hir::ItemKind::Trait(..) => { - tcx.generics_of(def_id); - tcx.trait_def(def_id); + tcx.ensure().generics_of(def_id); + tcx.ensure().trait_def(def_id); tcx.at(it.span).super_predicates_of(def_id); - tcx.predicates_of(def_id); + tcx.ensure().predicates_of(def_id); } hir::ItemKind::TraitAlias(..) => { - tcx.generics_of(def_id); + tcx.ensure().generics_of(def_id); tcx.at(it.span).super_predicates_of(def_id); - tcx.predicates_of(def_id); + tcx.ensure().predicates_of(def_id); } hir::ItemKind::Struct(ref struct_def, _) | hir::ItemKind::Union(ref struct_def, _) => { - tcx.generics_of(def_id); - tcx.type_of(def_id); - tcx.predicates_of(def_id); + tcx.ensure().generics_of(def_id); + tcx.ensure().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.generics_of(def_id); - tcx.type_of(def_id); - tcx.predicates_of(def_id); + tcx.ensure().generics_of(def_id); + tcx.ensure().type_of(def_id); + tcx.ensure().predicates_of(def_id); } if let Some(ctor_hir_id) = struct_def.ctor_hir_id() { @@ -691,11 +691,11 @@ fn convert_item(tcx: TyCtxt<'_>, item_id: hir::HirId) { | hir::ItemKind::Static(..) | hir::ItemKind::Const(..) | hir::ItemKind::Fn(..) => { - tcx.generics_of(def_id); - tcx.type_of(def_id); - tcx.predicates_of(def_id); + tcx.ensure().generics_of(def_id); + tcx.ensure().type_of(def_id); + tcx.ensure().predicates_of(def_id); if let hir::ItemKind::Fn(..) = it.kind { - tcx.fn_sig(def_id); + tcx.ensure().fn_sig(def_id); } } } @@ -704,20 +704,20 @@ fn convert_item(tcx: TyCtxt<'_>, item_id: hir::HirId) { fn convert_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::HirId) { let trait_item = tcx.hir().expect_trait_item(trait_item_id); let def_id = tcx.hir().local_def_id(trait_item.hir_id); - tcx.generics_of(def_id); + tcx.ensure().generics_of(def_id); match trait_item.kind { hir::TraitItemKind::Fn(..) => { - tcx.type_of(def_id); - tcx.fn_sig(def_id); + tcx.ensure().type_of(def_id); + tcx.ensure().fn_sig(def_id); } hir::TraitItemKind::Const(.., Some(_)) => { - tcx.type_of(def_id); + tcx.ensure().type_of(def_id); } hir::TraitItemKind::Const(..) | hir::TraitItemKind::Type(_, Some(_)) => { - tcx.type_of(def_id); + tcx.ensure().type_of(def_id); // Account for `const C: _;` and `type T = _;`. let mut visitor = PlaceholderHirTyCollector::default(); visitor.visit_trait_item(trait_item); @@ -727,18 +727,18 @@ fn convert_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::HirId) { hir::TraitItemKind::Type(_, None) => {} }; - tcx.predicates_of(def_id); + tcx.ensure().predicates_of(def_id); } fn convert_impl_item(tcx: TyCtxt<'_>, impl_item_id: hir::HirId) { let def_id = tcx.hir().local_def_id(impl_item_id); - tcx.generics_of(def_id); - tcx.type_of(def_id); - tcx.predicates_of(def_id); + tcx.ensure().generics_of(def_id); + tcx.ensure().type_of(def_id); + tcx.ensure().predicates_of(def_id); let impl_item = tcx.hir().expect_impl_item(impl_item_id); match impl_item.kind { hir::ImplItemKind::Fn(..) => { - tcx.fn_sig(def_id); + tcx.ensure().fn_sig(def_id); } hir::ImplItemKind::TyAlias(_) | hir::ImplItemKind::OpaqueTy(_) => { // Account for `type T = _;` @@ -752,9 +752,9 @@ fn convert_impl_item(tcx: TyCtxt<'_>, impl_item_id: hir::HirId) { fn convert_variant_ctor(tcx: TyCtxt<'_>, ctor_id: hir::HirId) { let def_id = tcx.hir().local_def_id(ctor_id); - tcx.generics_of(def_id); - tcx.type_of(def_id); - tcx.predicates_of(def_id); + tcx.ensure().generics_of(def_id); + tcx.ensure().type_of(def_id); + tcx.ensure().predicates_of(def_id); } fn convert_enum_variant_types(tcx: TyCtxt<'_>, def_id: DefId, variants: &[hir::Variant<'_>]) { @@ -790,9 +790,9 @@ 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.generics_of(def_id); - tcx.type_of(def_id); - tcx.predicates_of(def_id); + tcx.ensure().generics_of(def_id); + tcx.ensure().type_of(def_id); + tcx.ensure().predicates_of(def_id); } // Convert the ctor, if any. This also registers the variant as