Skip to content

Commit 0afd9c3

Browse files
Rollup merge of rust-lang#152879 - nnethercote:rm-impl-IntoQueryParam-ref-P, r=oli-obk
Remove `impl IntoQueryParam<P> for &'a P`. `IntoQueryParam` is a trait that lets query callers be a bit sloppy with the passed-in key. - Types similar to `DefId` will be auto-converted to `DefId`. Likewise for `LocalDefId`. - Reference types will be auto-derefed. The auto-conversion is genuinely useful; the auto-derefing much less so. In practice it's only used for passing `&DefId` to queries that accept `DefId`, which is an anti-pattern because `DefId` is marked with `#[rustc_pass_by_value]`. This commit removes the auto-deref impl and makes the necessary sigil adjustments. (I generally avoid using `*` to deref manually at call sites, preferring to deref via `&` in patterns or via `*` in match expressions. Mostly because that way a single deref often covers multiple call sites.) r? @cjgillot
2 parents 503064b + a3d5908 commit 0afd9c3

File tree

51 files changed

+108
-118
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+108
-118
lines changed

compiler/rustc_borrowck/src/diagnostics/move_errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
626626
let predicates = match parent.kind {
627627
hir::ExprKind::Call(callee, _) => {
628628
let ty = typeck_result.node_type_opt(callee.hir_id)?;
629-
let ty::FnDef(fn_def_id, args) = ty.kind() else { return None };
629+
let ty::FnDef(fn_def_id, args) = *ty.kind() else { return None };
630630
tcx.predicates_of(fn_def_id).instantiate(tcx, args)
631631
}
632632
hir::ExprKind::MethodCall(..) => {

compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
614614
}
615615
_ => {
616616
let local = &self.body.local_decls[local];
617-
match local.local_info() {
617+
match *local.local_info() {
618618
LocalInfo::StaticRef { def_id, .. } => {
619619
let span = self.infcx.tcx.def_span(def_id);
620620
err.span_label(span, format!("this `static` cannot be {acted_on}"));

compiler/rustc_borrowck/src/diagnostics/region_errors.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -926,7 +926,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
926926
let tcx = self.infcx.tcx;
927927

928928
let ConstraintCategory::CallArgument(Some(func_ty)) = category else { return };
929-
let ty::FnDef(fn_did, args) = func_ty.kind() else { return };
929+
let ty::FnDef(fn_did, args) = *func_ty.kind() else { return };
930930
debug!(?fn_did, ?args);
931931

932932
// Only suggest this on function calls, not closures
@@ -938,7 +938,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
938938
let Ok(Some(instance)) = ty::Instance::try_resolve(
939939
tcx,
940940
self.infcx.typing_env(self.infcx.param_env),
941-
*fn_did,
941+
fn_did,
942942
self.infcx.resolve_vars_if_possible(args),
943943
) else {
944944
return;

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,12 +1013,12 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
10131013
let is_implicit_coercion = coercion_source == CoercionSource::Implicit;
10141014
let src_ty = op.ty(self.body, tcx);
10151015
let mut src_sig = src_ty.fn_sig(tcx);
1016-
if let ty::FnDef(def_id, _) = src_ty.kind()
1016+
if let ty::FnDef(def_id, _) = *src_ty.kind()
10171017
&& let ty::FnPtr(_, target_hdr) = *ty.kind()
10181018
&& tcx.codegen_fn_attrs(def_id).safe_target_features
10191019
&& target_hdr.safety.is_safe()
10201020
&& let Some(safe_sig) = tcx.adjust_target_feature_sig(
1021-
*def_id,
1021+
def_id,
10221022
src_sig,
10231023
self.body.source.def_id(),
10241024
)

compiler/rustc_const_eval/src/check_consts/check.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
577577

578578
Rvalue::Aggregate(kind, ..) => {
579579
if let AggregateKind::Coroutine(def_id, ..) = kind.as_ref()
580-
&& let Some(coroutine_kind) = self.tcx.coroutine_kind(def_id)
580+
&& let Some(coroutine_kind) = self.tcx.coroutine_kind(*def_id)
581581
{
582582
self.check_op(ops::Coroutine(coroutine_kind));
583583
}

compiler/rustc_hir_analysis/src/check/check.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1221,7 +1221,7 @@ fn check_impl_items_against_trait<'tcx>(
12211221
match impl_trait_header.polarity {
12221222
ty::ImplPolarity::Reservation | ty::ImplPolarity::Positive => {}
12231223
ty::ImplPolarity::Negative => {
1224-
if let [first_item_ref, ..] = impl_item_refs {
1224+
if let [first_item_ref, ..] = *impl_item_refs {
12251225
let first_item_span = tcx.def_span(first_item_ref);
12261226
struct_span_code_err!(
12271227
tcx.dcx(),

compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1333,7 +1333,7 @@ fn check_region_late_boundedness<'tcx>(
13331333
.iter()
13341334
.map(|param| {
13351335
let (LateEarlyMismatch::EarlyInImpl(impl_param_def_id, ..)
1336-
| LateEarlyMismatch::LateInImpl(impl_param_def_id, ..)) = param;
1336+
| LateEarlyMismatch::LateInImpl(impl_param_def_id, ..)) = *param;
13371337
tcx.def_span(impl_param_def_id)
13381338
})
13391339
.collect();

compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2445,12 +2445,12 @@ fn is_late_bound_map(
24452445
)) => {
24462446
// See comments on `ConstrainedCollectorPostHirTyLowering` for why this arm does not
24472447
// just consider args to be unconstrained.
2448-
let generics = self.tcx.generics_of(alias_def);
2448+
let generics = self.tcx.generics_of(*alias_def);
24492449
let mut walker = ConstrainedCollectorPostHirTyLowering {
24502450
arg_is_constrained: vec![false; generics.own_params.len()]
24512451
.into_boxed_slice(),
24522452
};
2453-
walker.visit_ty(self.tcx.type_of(alias_def).instantiate_identity());
2453+
walker.visit_ty(self.tcx.type_of(*alias_def).instantiate_identity());
24542454

24552455
match segments.last() {
24562456
Some(hir::PathSegment { args: Some(args), .. }) => {

compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
214214
if let [best_trait] = visible_traits
215215
.iter()
216216
.copied()
217-
.filter(|trait_def_id| {
217+
.filter(|&trait_def_id| {
218218
tcx.associated_items(trait_def_id)
219219
.filter_by_name_unhygienic(suggested_name)
220220
.any(|item| item.tag() == assoc_tag)
@@ -1234,7 +1234,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
12341234
&& let name = Symbol::intern(&format!("{ident2}_{ident3}"))
12351235
&& let Some(item) = inherent_impls
12361236
.iter()
1237-
.flat_map(|inherent_impl| {
1237+
.flat_map(|&inherent_impl| {
12381238
tcx.associated_items(inherent_impl).filter_by_name_unhygienic(name)
12391239
})
12401240
.next()

compiler/rustc_hir_analysis/src/impl_wf_check.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ pub(crate) fn enforce_impl_lifetime_params_are_constrained(
101101
let lifetimes_in_associated_types: FxHashSet<_> = tcx
102102
.associated_item_def_ids(impl_def_id)
103103
.iter()
104-
.flat_map(|def_id| {
104+
.flat_map(|&def_id| {
105105
let item = tcx.associated_item(def_id);
106106
match item.kind {
107107
ty::AssocKind::Type { .. } => {

0 commit comments

Comments
 (0)