Skip to content

Commit 78dc7e1

Browse files
authored
Rollup merge of #71772 - cjgillot:ensure, r=petrochenkov
Mark query function as must_use. And use the `ensure()` version when the result is not needed.
2 parents 5747d1e + 6cde87d commit 78dc7e1

File tree

8 files changed

+57
-56
lines changed

8 files changed

+57
-56
lines changed

Diff for: src/librustc_codegen_ssa/base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
539539
// unnecessarily.
540540
if tcx.dep_graph.is_fully_enabled() {
541541
for cgu in codegen_units {
542-
tcx.codegen_unit(cgu.name());
542+
tcx.ensure().codegen_unit(cgu.name());
543543
}
544544
}
545545

Diff for: src/librustc_metadata/rmeta/encoder.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1729,8 +1729,8 @@ struct PrefetchVisitor<'tcx> {
17291729
impl<'tcx> PrefetchVisitor<'tcx> {
17301730
fn prefetch_mir(&self, def_id: LocalDefId) {
17311731
if self.mir_keys.contains(&def_id) {
1732-
self.tcx.optimized_mir(def_id);
1733-
self.tcx.promoted_mir(def_id);
1732+
self.tcx.ensure().optimized_mir(def_id);
1733+
self.tcx.ensure().promoted_mir(def_id);
17341734
}
17351735
}
17361736
}

Diff for: src/librustc_middle/ty/query/plumbing.rs

+1
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,7 @@ macro_rules! define_queries_inner {
424424

425425
$($(#[$attr])*
426426
#[inline(always)]
427+
#[must_use]
427428
pub fn $name(self, key: query_helper_param_ty!($($K)*))
428429
-> <queries::$name<$tcx> as QueryConfig<TyCtxt<$tcx>>>::Stored
429430
{

Diff for: src/librustc_mir/transform/check_unsafety.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ pub fn check_unsafety(tcx: TyCtxt<'_>, def_id: DefId) {
641641
}
642642
UnsafetyViolationKind::BorrowPacked(lint_hir_id) => {
643643
if let Some(impl_def_id) = builtin_derive_def_id(tcx, def_id) {
644-
tcx.unsafe_derive_on_repr_packed(impl_def_id);
644+
tcx.ensure().unsafe_derive_on_repr_packed(impl_def_id);
645645
} else {
646646
tcx.struct_span_lint_hir(
647647
SAFE_PACKED_BORROWS,

Diff for: src/librustc_passes/check_attr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ impl CheckAttrVisitor<'tcx> {
7777
}
7878

7979
if matches!(target, Target::Fn | Target::Method(_) | Target::ForeignFn) {
80-
self.tcx.codegen_fn_attrs(self.tcx.hir().local_def_id(hir_id));
80+
self.tcx.ensure().codegen_fn_attrs(self.tcx.hir().local_def_id(hir_id));
8181
}
8282

8383
self.check_repr(attrs, span, target, item, hir_id);
@@ -390,7 +390,7 @@ impl CheckAttrVisitor<'tcx> {
390390
}
391391
}
392392
if target == Target::Closure {
393-
self.tcx.codegen_fn_attrs(self.tcx.hir().local_def_id(expr.hir_id));
393+
self.tcx.ensure().codegen_fn_attrs(self.tcx.hir().local_def_id(expr.hir_id));
394394
}
395395
}
396396

Diff for: src/librustc_typeck/check/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1748,11 +1748,11 @@ pub fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, it: &'tcx hir::Item<'tcx>) {
17481748
// Consts can play a role in type-checking, so they are included here.
17491749
hir::ItemKind::Static(..) => {
17501750
let def_id = tcx.hir().local_def_id(it.hir_id);
1751-
tcx.typeck_tables_of(def_id);
1751+
tcx.ensure().typeck_tables_of(def_id);
17521752
maybe_check_static_with_link_section(tcx, def_id, it.span);
17531753
}
17541754
hir::ItemKind::Const(..) => {
1755-
tcx.typeck_tables_of(tcx.hir().local_def_id(it.hir_id));
1755+
tcx.ensure().typeck_tables_of(tcx.hir().local_def_id(it.hir_id));
17561756
}
17571757
hir::ItemKind::Enum(ref enum_definition, _) => {
17581758
check_enum(tcx, it.span, &enum_definition.variants, it.hir_id);
@@ -2670,7 +2670,7 @@ pub fn check_enum<'tcx>(
26702670

26712671
for v in vs {
26722672
if let Some(ref e) = v.disr_expr {
2673-
tcx.typeck_tables_of(tcx.hir().local_def_id(e.hir_id));
2673+
tcx.ensure().typeck_tables_of(tcx.hir().local_def_id(e.hir_id));
26742674
}
26752675
}
26762676

Diff for: src/librustc_typeck/coherence/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ pub fn provide(providers: &mut Providers<'_>) {
156156
fn coherent_trait(tcx: TyCtxt<'_>, def_id: DefId) {
157157
// Trigger building the specialization graph for the trait. This will detect and report any
158158
// overlap errors.
159-
tcx.specialization_graph_of(def_id);
159+
tcx.ensure().specialization_graph_of(def_id);
160160

161161
let impls = tcx.hir().trait_impls(def_id);
162162
for &hir_id in impls {

Diff for: src/librustc_typeck/collect.rs

+46-46
Original file line numberDiff line numberDiff line change
@@ -207,12 +207,12 @@ impl Visitor<'tcx> for CollectItemTypesVisitor<'tcx> {
207207
hir::GenericParamKind::Lifetime { .. } => {}
208208
hir::GenericParamKind::Type { default: Some(_), .. } => {
209209
let def_id = self.tcx.hir().local_def_id(param.hir_id);
210-
self.tcx.type_of(def_id);
210+
self.tcx.ensure().type_of(def_id);
211211
}
212212
hir::GenericParamKind::Type { .. } => {}
213213
hir::GenericParamKind::Const { .. } => {
214214
let def_id = self.tcx.hir().local_def_id(param.hir_id);
215-
self.tcx.type_of(def_id);
215+
self.tcx.ensure().type_of(def_id);
216216
}
217217
}
218218
}
@@ -222,8 +222,8 @@ impl Visitor<'tcx> for CollectItemTypesVisitor<'tcx> {
222222
fn visit_expr(&mut self, expr: &'tcx hir::Expr<'tcx>) {
223223
if let hir::ExprKind::Closure(..) = expr.kind {
224224
let def_id = self.tcx.hir().local_def_id(expr.hir_id);
225-
self.tcx.generics_of(def_id);
226-
self.tcx.type_of(def_id);
225+
self.tcx.ensure().generics_of(def_id);
226+
self.tcx.ensure().type_of(def_id);
227227
}
228228
intravisit::walk_expr(self, expr);
229229
}
@@ -635,47 +635,47 @@ fn convert_item(tcx: TyCtxt<'_>, item_id: hir::HirId) {
635635
hir::ItemKind::ForeignMod(ref foreign_mod) => {
636636
for item in foreign_mod.items {
637637
let def_id = tcx.hir().local_def_id(item.hir_id);
638-
tcx.generics_of(def_id);
639-
tcx.type_of(def_id);
640-
tcx.predicates_of(def_id);
638+
tcx.ensure().generics_of(def_id);
639+
tcx.ensure().type_of(def_id);
640+
tcx.ensure().predicates_of(def_id);
641641
if let hir::ForeignItemKind::Fn(..) = item.kind {
642-
tcx.fn_sig(def_id);
642+
tcx.ensure().fn_sig(def_id);
643643
}
644644
}
645645
}
646646
hir::ItemKind::Enum(ref enum_definition, _) => {
647-
tcx.generics_of(def_id);
648-
tcx.type_of(def_id);
649-
tcx.predicates_of(def_id);
647+
tcx.ensure().generics_of(def_id);
648+
tcx.ensure().type_of(def_id);
649+
tcx.ensure().predicates_of(def_id);
650650
convert_enum_variant_types(tcx, def_id.to_def_id(), &enum_definition.variants);
651651
}
652652
hir::ItemKind::Impl { .. } => {
653-
tcx.generics_of(def_id);
654-
tcx.type_of(def_id);
655-
tcx.impl_trait_ref(def_id);
656-
tcx.predicates_of(def_id);
653+
tcx.ensure().generics_of(def_id);
654+
tcx.ensure().type_of(def_id);
655+
tcx.ensure().impl_trait_ref(def_id);
656+
tcx.ensure().predicates_of(def_id);
657657
}
658658
hir::ItemKind::Trait(..) => {
659-
tcx.generics_of(def_id);
660-
tcx.trait_def(def_id);
659+
tcx.ensure().generics_of(def_id);
660+
tcx.ensure().trait_def(def_id);
661661
tcx.at(it.span).super_predicates_of(def_id);
662-
tcx.predicates_of(def_id);
662+
tcx.ensure().predicates_of(def_id);
663663
}
664664
hir::ItemKind::TraitAlias(..) => {
665-
tcx.generics_of(def_id);
665+
tcx.ensure().generics_of(def_id);
666666
tcx.at(it.span).super_predicates_of(def_id);
667-
tcx.predicates_of(def_id);
667+
tcx.ensure().predicates_of(def_id);
668668
}
669669
hir::ItemKind::Struct(ref struct_def, _) | hir::ItemKind::Union(ref struct_def, _) => {
670-
tcx.generics_of(def_id);
671-
tcx.type_of(def_id);
672-
tcx.predicates_of(def_id);
670+
tcx.ensure().generics_of(def_id);
671+
tcx.ensure().type_of(def_id);
672+
tcx.ensure().predicates_of(def_id);
673673

674674
for f in struct_def.fields() {
675675
let def_id = tcx.hir().local_def_id(f.hir_id);
676-
tcx.generics_of(def_id);
677-
tcx.type_of(def_id);
678-
tcx.predicates_of(def_id);
676+
tcx.ensure().generics_of(def_id);
677+
tcx.ensure().type_of(def_id);
678+
tcx.ensure().predicates_of(def_id);
679679
}
680680

681681
if let Some(ctor_hir_id) = struct_def.ctor_hir_id() {
@@ -691,11 +691,11 @@ fn convert_item(tcx: TyCtxt<'_>, item_id: hir::HirId) {
691691
| hir::ItemKind::Static(..)
692692
| hir::ItemKind::Const(..)
693693
| hir::ItemKind::Fn(..) => {
694-
tcx.generics_of(def_id);
695-
tcx.type_of(def_id);
696-
tcx.predicates_of(def_id);
694+
tcx.ensure().generics_of(def_id);
695+
tcx.ensure().type_of(def_id);
696+
tcx.ensure().predicates_of(def_id);
697697
if let hir::ItemKind::Fn(..) = it.kind {
698-
tcx.fn_sig(def_id);
698+
tcx.ensure().fn_sig(def_id);
699699
}
700700
}
701701
}
@@ -704,20 +704,20 @@ fn convert_item(tcx: TyCtxt<'_>, item_id: hir::HirId) {
704704
fn convert_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::HirId) {
705705
let trait_item = tcx.hir().expect_trait_item(trait_item_id);
706706
let def_id = tcx.hir().local_def_id(trait_item.hir_id);
707-
tcx.generics_of(def_id);
707+
tcx.ensure().generics_of(def_id);
708708

709709
match trait_item.kind {
710710
hir::TraitItemKind::Fn(..) => {
711-
tcx.type_of(def_id);
712-
tcx.fn_sig(def_id);
711+
tcx.ensure().type_of(def_id);
712+
tcx.ensure().fn_sig(def_id);
713713
}
714714

715715
hir::TraitItemKind::Const(.., Some(_)) => {
716-
tcx.type_of(def_id);
716+
tcx.ensure().type_of(def_id);
717717
}
718718

719719
hir::TraitItemKind::Const(..) | hir::TraitItemKind::Type(_, Some(_)) => {
720-
tcx.type_of(def_id);
720+
tcx.ensure().type_of(def_id);
721721
// Account for `const C: _;` and `type T = _;`.
722722
let mut visitor = PlaceholderHirTyCollector::default();
723723
visitor.visit_trait_item(trait_item);
@@ -727,18 +727,18 @@ fn convert_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::HirId) {
727727
hir::TraitItemKind::Type(_, None) => {}
728728
};
729729

730-
tcx.predicates_of(def_id);
730+
tcx.ensure().predicates_of(def_id);
731731
}
732732

733733
fn convert_impl_item(tcx: TyCtxt<'_>, impl_item_id: hir::HirId) {
734734
let def_id = tcx.hir().local_def_id(impl_item_id);
735-
tcx.generics_of(def_id);
736-
tcx.type_of(def_id);
737-
tcx.predicates_of(def_id);
735+
tcx.ensure().generics_of(def_id);
736+
tcx.ensure().type_of(def_id);
737+
tcx.ensure().predicates_of(def_id);
738738
let impl_item = tcx.hir().expect_impl_item(impl_item_id);
739739
match impl_item.kind {
740740
hir::ImplItemKind::Fn(..) => {
741-
tcx.fn_sig(def_id);
741+
tcx.ensure().fn_sig(def_id);
742742
}
743743
hir::ImplItemKind::TyAlias(_) | hir::ImplItemKind::OpaqueTy(_) => {
744744
// Account for `type T = _;`
@@ -752,9 +752,9 @@ fn convert_impl_item(tcx: TyCtxt<'_>, impl_item_id: hir::HirId) {
752752

753753
fn convert_variant_ctor(tcx: TyCtxt<'_>, ctor_id: hir::HirId) {
754754
let def_id = tcx.hir().local_def_id(ctor_id);
755-
tcx.generics_of(def_id);
756-
tcx.type_of(def_id);
757-
tcx.predicates_of(def_id);
755+
tcx.ensure().generics_of(def_id);
756+
tcx.ensure().type_of(def_id);
757+
tcx.ensure().predicates_of(def_id);
758758
}
759759

760760
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
790790

791791
for f in variant.data.fields() {
792792
let def_id = tcx.hir().local_def_id(f.hir_id);
793-
tcx.generics_of(def_id);
794-
tcx.type_of(def_id);
795-
tcx.predicates_of(def_id);
793+
tcx.ensure().generics_of(def_id);
794+
tcx.ensure().type_of(def_id);
795+
tcx.ensure().predicates_of(def_id);
796796
}
797797

798798
// Convert the ctor, if any. This also registers the variant as

0 commit comments

Comments
 (0)