Skip to content

Commit ae74817

Browse files
committed
cleanup
1 parent 29ffa55 commit ae74817

File tree

5 files changed

+13
-6
lines changed

5 files changed

+13
-6
lines changed

src/librustc_middle/dep_graph/dep_node.rs

+1
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,7 @@ impl<'tcx> DepNodeParams<TyCtxt<'tcx>> for ty::WithOptParam<DefId> {
379379
dep_node.extract_def_id(tcx).map(|def_id| tcx.with_opt_param(def_id))
380380
}
381381
}
382+
382383
impl<'tcx> DepNodeParams<TyCtxt<'tcx>> for ty::WithOptParam<LocalDefId> {
383384
#[inline]
384385
fn can_reconstruct_query_key() -> bool {

src/librustc_middle/query/mod.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,19 @@ rustc_queries! {
8989
desc { |tcx| "HIR owner items in `{}`", tcx.def_path_str(key.to_def_id()) }
9090
}
9191

92-
/// Computes the `DefId` of the corresponding const parameter of a const argument.
93-
/// Returns `None` if `def_id` is not a const argument.
92+
/// Computes the `DefId` of the corresponding const parameter in case the `key` is a
93+
/// const argument and returns `None` otherwise.
9494
///
9595
/// ```rust
9696
/// let a = foo::<7>();
9797
/// // ^ Calling `const_param_of` for this argument,
9898
///
9999
/// fn foo<const N: usize>()
100100
/// // ^ returns this `DefId`.
101+
///
102+
/// fn bar() {
103+
/// // ^ While calling `const_param_of` for other bodies returns `None`.
104+
/// }
101105
/// ```
102106
query const_param_of(key: DefId) -> Option<DefId> {
103107
cache_on_disk_if { key.is_local() }

src/librustc_middle/ty/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1622,6 +1622,7 @@ impl<T: Ord> Ord for WithOptParam<T> {
16221622
}
16231623

16241624
impl<'tcx> TyCtxt<'tcx> {
1625+
#[inline(always)]
16251626
pub fn with_opt_param<T: IntoQueryParam<DefId> + Copy>(self, did: T) -> WithOptParam<T> {
16261627
WithOptParam { did, param_did: self.const_param_of(did) }
16271628
}

src/librustc_middle/ty/structural_impls.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -844,9 +844,7 @@ impl<'tcx> TypeFoldable<'tcx> for ty::instance::Instance<'tcx> {
844844
Self {
845845
substs: self.substs.fold_with(folder),
846846
def: match self.def {
847-
// We don't fold the param `DefId` here,
848-
// as it should only be used for `type_of`.
849-
Item(did, param_did) => Item(did.fold_with(folder), param_did),
847+
Item(did, param_did) => Item(did.fold_with(folder), param_did.fold_with(folder)),
850848
VtableShim(did) => VtableShim(did.fold_with(folder)),
851849
ReifyShim(did) => ReifyShim(did.fold_with(folder)),
852850
Intrinsic(did) => Intrinsic(did.fold_with(folder)),

src/librustc_typeck/collect/type_of.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ use rustc_trait_selection::traits;
1717
use super::ItemCtxt;
1818
use super::{bad_placeholder_type, is_suggestable_infer_ty};
1919

20+
/// Computes the relevant generic parameter for a potential generic const argument.
21+
///
22+
/// This should be called using the query `tcx.const_param_of`.
2023
pub(super) fn const_param_of(tcx: TyCtxt<'_>, def_id: DefId) -> Option<DefId> {
2124
use hir::*;
2225

@@ -127,7 +130,7 @@ pub(super) fn const_param_of(tcx: TyCtxt<'_>, def_id: DefId) -> Option<DefId> {
127130
.nth(arg_index)
128131
.map(|param| param.def_id)
129132
}
130-
_ => return None,
133+
_ => None,
131134
}
132135
} else {
133136
None

0 commit comments

Comments
 (0)