Skip to content

Commit

Permalink
Mark query function as must_use.
Browse files Browse the repository at this point in the history
  • Loading branch information
cjgillot committed May 1, 2020
1 parent bd0bacc commit 6cde87d
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 56 deletions.
2 changes: 1 addition & 1 deletion src/librustc_codegen_ssa/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
// unnecessarily.
if tcx.dep_graph.is_fully_enabled() {
for cgu in codegen_units {
tcx.codegen_unit(cgu.name());
tcx.ensure().codegen_unit(cgu.name());
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/librustc_metadata/rmeta/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/librustc_middle/ty/query/plumbing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ macro_rules! define_queries_inner {

$($(#[$attr])*
#[inline(always)]
#[must_use]
pub fn $name(self, key: query_helper_param_ty!($($K)*))
-> <queries::$name<$tcx> as QueryConfig<TyCtxt<$tcx>>>::Stored
{
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/transform/check_unsafety.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_passes/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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));
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/librustc_typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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));
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_typeck/coherence/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
92 changes: 46 additions & 46 deletions src/librustc_typeck/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand All @@ -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);
}
Expand Down Expand Up @@ -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() {
Expand All @@ -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);
}
}
}
Expand All @@ -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);
Expand All @@ -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 = _;`
Expand All @@ -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<'_>]) {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 6cde87d

Please sign in to comment.