mirror of
https://github.com/rust-lang/rust
synced 2024-09-05 00:24:52 +00:00
Rollup merge of #124183 - compiler-errors:unnecessary-by-ref, r=oli-obk
Stop taking `ParamTy`/`ParamConst`/`EarlyParamRegion`/`AliasTy` by ref It's unnecessary and is annoying when we have it by value.
This commit is contained in:
commit
e984447405
|
@ -1320,7 +1320,7 @@ fn suggest_adding_bounds(&self, err: &mut Diag<'_>, ty: Ty<'tcx>, def_id: DefId,
|
|||
.into_iter()
|
||||
.map(|err| match err.obligation.predicate.kind().skip_binder() {
|
||||
PredicateKind::Clause(ty::ClauseKind::Trait(predicate)) => {
|
||||
match predicate.self_ty().kind() {
|
||||
match *predicate.self_ty().kind() {
|
||||
ty::Param(param_ty) => Ok((
|
||||
generics.type_param(param_ty, tcx),
|
||||
predicate.trait_ref.print_only_trait_path().to_string(),
|
||||
|
|
|
@ -1070,7 +1070,7 @@ fn explain_captures(
|
|||
// LL | blk();
|
||||
// | ----- this value implements `FnOnce`, which causes it to be moved when called
|
||||
// ```
|
||||
if let ty::Param(param_ty) = self_ty.kind()
|
||||
if let ty::Param(param_ty) = *self_ty.kind()
|
||||
&& let generics = self.infcx.tcx.generics_of(self.mir_def_id())
|
||||
&& let param = generics.type_param(param_ty, self.infcx.tcx)
|
||||
&& let Some(hir_generics) = self
|
||||
|
|
|
@ -2697,7 +2697,7 @@ fn ban_take_value_of_method(
|
|||
|
||||
fn point_at_param_definition(&self, err: &mut Diag<'_>, param: ty::ParamTy) {
|
||||
let generics = self.tcx.generics_of(self.body_id);
|
||||
let generic_param = generics.type_param(¶m, self.tcx);
|
||||
let generic_param = generics.type_param(param, self.tcx);
|
||||
if let ty::GenericParamDefKind::Type { synthetic: true, .. } = generic_param.kind {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -2144,7 +2144,7 @@ fn label_fn_like(
|
|||
let callee_ty = callee_ty.peel_refs();
|
||||
match *callee_ty.kind() {
|
||||
ty::Param(param) => {
|
||||
let param = self.tcx.generics_of(self.body_id).type_param(¶m, self.tcx);
|
||||
let param = self.tcx.generics_of(self.body_id).type_param(param, self.tcx);
|
||||
if param.kind.is_synthetic() {
|
||||
// if it's `impl Fn() -> ..` then just fall down to the def-id based logic
|
||||
def_id = param.def_id;
|
||||
|
|
|
@ -125,11 +125,11 @@ fn predicate_bounds_generic_param<'tcx>(
|
|||
let Some(arg_ty) = args[0].as_type() else {
|
||||
return false;
|
||||
};
|
||||
let ty::Param(param) = arg_ty.kind() else {
|
||||
let ty::Param(param) = *arg_ty.kind() else {
|
||||
return false;
|
||||
};
|
||||
// Is `generic_param` the same as the arg for this trait predicate?
|
||||
generic_param.index == generics.type_param(¶m, tcx).index
|
||||
generic_param.index == generics.type_param(param, tcx).index
|
||||
} else {
|
||||
false
|
||||
}
|
||||
|
@ -156,10 +156,10 @@ fn is_iterator_predicate(predicate: ty::Predicate<'_>, tcx: TyCtxt<'_>) -> bool
|
|||
return false;
|
||||
}
|
||||
|
||||
match ty.peel_refs().kind() {
|
||||
match *ty.peel_refs().kind() {
|
||||
ty::Param(param) => {
|
||||
let generics = self.tcx.generics_of(self.body_id);
|
||||
let generic_param = generics.type_param(¶m, self.tcx);
|
||||
let generic_param = generics.type_param(param, self.tcx);
|
||||
for unsatisfied in unsatisfied_predicates.iter() {
|
||||
// The parameter implements `IntoIterator`
|
||||
// but it has called a method that requires it to implement `Iterator`
|
||||
|
@ -3232,9 +3232,9 @@ fn suggest_traits_to_import(
|
|||
.sort_by_key(|&info| (!info.def_id.is_local(), self.tcx.def_path_str(info.def_id)));
|
||||
candidates.dedup();
|
||||
|
||||
let param_type = match rcvr_ty.kind() {
|
||||
let param_type = match *rcvr_ty.kind() {
|
||||
ty::Param(param) => Some(param),
|
||||
ty::Ref(_, ty, _) => match ty.kind() {
|
||||
ty::Ref(_, ty, _) => match *ty.kind() {
|
||||
ty::Param(param) => Some(param),
|
||||
_ => None,
|
||||
},
|
||||
|
@ -3429,7 +3429,7 @@ enum Introducer {
|
|||
} else {
|
||||
param_type.map_or_else(
|
||||
|| "implement".to_string(), // FIXME: it might only need to be imported into scope, not implemented.
|
||||
ToString::to_string,
|
||||
|p| p.to_string(),
|
||||
)
|
||||
},
|
||||
},
|
||||
|
|
|
@ -2371,7 +2371,7 @@ pub fn construct_generic_bound_failure(
|
|||
|
||||
// type_param_sugg_span is (span, has_bounds)
|
||||
let (type_scope, type_param_sugg_span) = match bound_kind {
|
||||
GenericKind::Param(ref param) => {
|
||||
GenericKind::Param(param) => {
|
||||
let generics = self.tcx.generics_of(generic_param_scope);
|
||||
let def_id = generics.type_param(param, self.tcx).def_id.expect_local();
|
||||
let scope = self.tcx.local_def_id_to_hir_id(def_id).owner.def_id;
|
||||
|
|
|
@ -28,7 +28,7 @@ pub fn note_and_explain_type_err(
|
|||
|
||||
match err {
|
||||
ArgumentSorts(values, _) | Sorts(values) => {
|
||||
match (values.expected.kind(), values.found.kind()) {
|
||||
match (*values.expected.kind(), *values.found.kind()) {
|
||||
(ty::Closure(..), ty::Closure(..)) => {
|
||||
diag.note("no two closures, even if identical, have the same type");
|
||||
diag.help("consider boxing your closure and/or using it as a trait object");
|
||||
|
@ -452,7 +452,7 @@ fn foo(&self, x: T) -> T { x }
|
|||
}
|
||||
(ty::FnPtr(sig), ty::FnDef(def_id, _))
|
||||
| (ty::FnDef(def_id, _), ty::FnPtr(sig)) => {
|
||||
if tcx.fn_sig(*def_id).skip_binder().unsafety() < sig.unsafety() {
|
||||
if tcx.fn_sig(def_id).skip_binder().unsafety() < sig.unsafety() {
|
||||
diag.note(
|
||||
"unsafe functions cannot be coerced into safe function pointers",
|
||||
);
|
||||
|
@ -527,7 +527,7 @@ fn suggest_constraint(
|
|||
diag: &mut Diag<'_>,
|
||||
msg: impl Fn() -> String,
|
||||
body_owner_def_id: DefId,
|
||||
proj_ty: &ty::AliasTy<'tcx>,
|
||||
proj_ty: ty::AliasTy<'tcx>,
|
||||
ty: Ty<'tcx>,
|
||||
) -> bool {
|
||||
let tcx = self.tcx;
|
||||
|
@ -541,7 +541,7 @@ fn suggest_constraint(
|
|||
};
|
||||
// Get the `DefId` for the type parameter corresponding to `A` in `<A as T>::Foo`.
|
||||
// This will also work for `impl Trait`.
|
||||
let ty::Param(param_ty) = proj_ty.self_ty().kind() else {
|
||||
let ty::Param(param_ty) = *proj_ty.self_ty().kind() else {
|
||||
return false;
|
||||
};
|
||||
let generics = tcx.generics_of(body_owner_def_id);
|
||||
|
@ -598,7 +598,7 @@ fn suggest_constraint(
|
|||
fn expected_projection(
|
||||
&self,
|
||||
diag: &mut Diag<'_>,
|
||||
proj_ty: &ty::AliasTy<'tcx>,
|
||||
proj_ty: ty::AliasTy<'tcx>,
|
||||
values: ExpectedFound<Ty<'tcx>>,
|
||||
body_owner_def_id: DefId,
|
||||
cause_code: &ObligationCauseCode<'_>,
|
||||
|
@ -709,7 +709,7 @@ fn suggest_constraining_opaque_associated_type(
|
|||
&self,
|
||||
diag: &mut Diag<'_>,
|
||||
msg: impl Fn() -> String,
|
||||
proj_ty: &ty::AliasTy<'tcx>,
|
||||
proj_ty: ty::AliasTy<'tcx>,
|
||||
ty: Ty<'tcx>,
|
||||
) -> bool {
|
||||
let tcx = self.tcx;
|
||||
|
|
|
@ -263,7 +263,7 @@ pub fn params_to(&'tcx self, param_index: usize, tcx: TyCtxt<'tcx>) -> &'tcx [Ge
|
|||
/// Returns the `GenericParamDef` associated with this `EarlyParamRegion`.
|
||||
pub fn region_param(
|
||||
&'tcx self,
|
||||
param: &ty::EarlyParamRegion,
|
||||
param: ty::EarlyParamRegion,
|
||||
tcx: TyCtxt<'tcx>,
|
||||
) -> &'tcx GenericParamDef {
|
||||
let param = self.param_at(param.index as usize, tcx);
|
||||
|
@ -274,7 +274,7 @@ pub fn region_param(
|
|||
}
|
||||
|
||||
/// Returns the `GenericParamDef` associated with this `ParamTy`.
|
||||
pub fn type_param(&'tcx self, param: &ParamTy, tcx: TyCtxt<'tcx>) -> &'tcx GenericParamDef {
|
||||
pub fn type_param(&'tcx self, param: ParamTy, tcx: TyCtxt<'tcx>) -> &'tcx GenericParamDef {
|
||||
let param = self.param_at(param.index as usize, tcx);
|
||||
match param.kind {
|
||||
GenericParamDefKind::Type { .. } => param,
|
||||
|
@ -286,7 +286,7 @@ pub fn type_param(&'tcx self, param: &ParamTy, tcx: TyCtxt<'tcx>) -> &'tcx Gener
|
|||
/// `Generics`.
|
||||
pub fn opt_type_param(
|
||||
&'tcx self,
|
||||
param: &ParamTy,
|
||||
param: ParamTy,
|
||||
tcx: TyCtxt<'tcx>,
|
||||
) -> Option<&'tcx GenericParamDef> {
|
||||
let param = self.opt_param_at(param.index as usize, tcx)?;
|
||||
|
@ -297,7 +297,7 @@ pub fn opt_type_param(
|
|||
}
|
||||
|
||||
/// Returns the `GenericParamDef` associated with this `ParamConst`.
|
||||
pub fn const_param(&'tcx self, param: &ParamConst, tcx: TyCtxt<'tcx>) -> &GenericParamDef {
|
||||
pub fn const_param(&'tcx self, param: ParamConst, tcx: TyCtxt<'tcx>) -> &GenericParamDef {
|
||||
let param = self.param_at(param.index as usize, tcx);
|
||||
match param.kind {
|
||||
GenericParamDefKind::Const { .. } => param,
|
||||
|
|
|
@ -1276,7 +1276,7 @@ fn insert_trait_and_projection(
|
|||
|
||||
fn pretty_print_inherent_projection(
|
||||
&mut self,
|
||||
alias_ty: &ty::AliasTy<'tcx>,
|
||||
alias_ty: ty::AliasTy<'tcx>,
|
||||
) -> Result<(), PrintError> {
|
||||
let def_key = self.tcx().def_key(alias_ty.def_id);
|
||||
self.path_generic_args(
|
||||
|
@ -3204,7 +3204,7 @@ macro_rules! define_print_and_forward_display {
|
|||
|
||||
ty::AliasTy<'tcx> {
|
||||
if let DefKind::Impl { of_trait: false } = cx.tcx().def_kind(cx.tcx().parent(self.def_id)) {
|
||||
p!(pretty_print_inherent_projection(self))
|
||||
p!(pretty_print_inherent_projection(*self))
|
||||
} else {
|
||||
// If we're printing verbosely, or don't want to invoke queries
|
||||
// (`is_impl_trait_in_trait`), then fall back to printing the def path.
|
||||
|
|
|
@ -1379,7 +1379,7 @@ pub fn to_ty(self, tcx: TyCtxt<'tcx>) -> Ty<'tcx> {
|
|||
Ty::new_param(tcx, self.index, self.name)
|
||||
}
|
||||
|
||||
pub fn span_from_generics(&self, tcx: TyCtxt<'tcx>, item_with_generics: DefId) -> Span {
|
||||
pub fn span_from_generics(self, tcx: TyCtxt<'tcx>, item_with_generics: DefId) -> Span {
|
||||
let generics = tcx.generics_of(item_with_generics);
|
||||
let type_param = generics.type_param(self, tcx);
|
||||
tcx.def_span(type_param.def_id)
|
||||
|
|
|
@ -432,19 +432,19 @@ pub fn destructor_constraints(self, def: ty::AdtDef<'tcx>) -> Vec<ty::GenericArg
|
|||
.filter(|&(_, k)| {
|
||||
match k.unpack() {
|
||||
GenericArgKind::Lifetime(region) => match region.kind() {
|
||||
ty::ReEarlyParam(ref ebr) => {
|
||||
ty::ReEarlyParam(ebr) => {
|
||||
!impl_generics.region_param(ebr, self).pure_wrt_drop
|
||||
}
|
||||
// Error: not a region param
|
||||
_ => false,
|
||||
},
|
||||
GenericArgKind::Type(ty) => match ty.kind() {
|
||||
ty::Param(ref pt) => !impl_generics.type_param(pt, self).pure_wrt_drop,
|
||||
GenericArgKind::Type(ty) => match *ty.kind() {
|
||||
ty::Param(pt) => !impl_generics.type_param(pt, self).pure_wrt_drop,
|
||||
// Error: not a type param
|
||||
_ => false,
|
||||
},
|
||||
GenericArgKind::Const(ct) => match ct.kind() {
|
||||
ty::ConstKind::Param(ref pc) => {
|
||||
ty::ConstKind::Param(pc) => {
|
||||
!impl_generics.const_param(pc, self).pure_wrt_drop
|
||||
}
|
||||
// Error: not a const param
|
||||
|
|
|
@ -124,7 +124,7 @@ pub fn suggest_restriction<'tcx, G: EmissionGuarantee>(
|
|||
msg: &str,
|
||||
err: &mut Diag<'_, G>,
|
||||
fn_sig: Option<&hir::FnSig<'_>>,
|
||||
projection: Option<&ty::AliasTy<'_>>,
|
||||
projection: Option<ty::AliasTy<'_>>,
|
||||
trait_pred: ty::PolyTraitPredicate<'tcx>,
|
||||
// When we are dealing with a trait, `super_traits` will be `Some`:
|
||||
// Given `trait T: A + B + C {}`
|
||||
|
@ -142,7 +142,7 @@ pub fn suggest_restriction<'tcx, G: EmissionGuarantee>(
|
|||
let generics = tcx.generics_of(item_id);
|
||||
// Given `fn foo(t: impl Trait)` where `Trait` requires assoc type `A`...
|
||||
if let Some((param, bound_str, fn_sig)) =
|
||||
fn_sig.zip(projection).and_then(|(sig, p)| match p.self_ty().kind() {
|
||||
fn_sig.zip(projection).and_then(|(sig, p)| match *p.self_ty().kind() {
|
||||
// Shenanigans to get the `Trait` from the `impl Trait`.
|
||||
ty::Param(param) => {
|
||||
let param_def = generics.type_param(param, tcx);
|
||||
|
@ -252,7 +252,7 @@ fn suggest_restricting_param_bound(
|
|||
let trait_pred = self.resolve_numeric_literals_with_default(trait_pred);
|
||||
|
||||
let self_ty = trait_pred.skip_binder().self_ty();
|
||||
let (param_ty, projection) = match self_ty.kind() {
|
||||
let (param_ty, projection) = match *self_ty.kind() {
|
||||
ty::Param(_) => (true, None),
|
||||
ty::Alias(ty::Projection, projection) => (false, Some(projection)),
|
||||
_ => (false, None),
|
||||
|
|
|
@ -482,7 +482,7 @@ impl<'tcx> ty::TypeVisitor<TyCtxt<'tcx>> for ReferencesOnlyParentGenerics<'tcx>
|
|||
type Result = ControlFlow<()>;
|
||||
fn visit_ty(&mut self, t: Ty<'tcx>) -> Self::Result {
|
||||
// If this is a parameter from the trait item's own generics, then bail
|
||||
if let ty::Param(param) = t.kind()
|
||||
if let ty::Param(param) = *t.kind()
|
||||
&& let param_def_id = self.generics.type_param(param, self.tcx).def_id
|
||||
&& self.tcx.parent(param_def_id) == self.trait_item_def_id
|
||||
{
|
||||
|
@ -492,7 +492,7 @@ fn visit_ty(&mut self, t: Ty<'tcx>) -> Self::Result {
|
|||
}
|
||||
fn visit_region(&mut self, r: ty::Region<'tcx>) -> Self::Result {
|
||||
if let ty::ReEarlyParam(param) = r.kind()
|
||||
&& let param_def_id = self.generics.region_param(¶m, self.tcx).def_id
|
||||
&& let param_def_id = self.generics.region_param(param, self.tcx).def_id
|
||||
&& self.tcx.parent(param_def_id) == self.trait_item_def_id
|
||||
{
|
||||
return ControlFlow::Break(());
|
||||
|
@ -501,7 +501,7 @@ fn visit_region(&mut self, r: ty::Region<'tcx>) -> Self::Result {
|
|||
}
|
||||
fn visit_const(&mut self, ct: ty::Const<'tcx>) -> Self::Result {
|
||||
if let ty::ConstKind::Param(param) = ct.kind()
|
||||
&& let param_def_id = self.generics.const_param(¶m, self.tcx).def_id
|
||||
&& let param_def_id = self.generics.const_param(param, self.tcx).def_id
|
||||
&& self.tcx.parent(param_def_id) == self.trait_item_def_id
|
||||
{
|
||||
return ControlFlow::Break(());
|
||||
|
|
|
@ -130,7 +130,7 @@ fn visit_nested_body(&mut self, id: rustc_hir::BodyId) {
|
|||
TaitInBodyFinder { collector: self }.visit_expr(body);
|
||||
}
|
||||
|
||||
fn visit_opaque_ty(&mut self, alias_ty: &ty::AliasTy<'tcx>) {
|
||||
fn visit_opaque_ty(&mut self, alias_ty: ty::AliasTy<'tcx>) {
|
||||
if !self.seen.insert(alias_ty.def_id.expect_local()) {
|
||||
return;
|
||||
}
|
||||
|
@ -205,7 +205,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for OpaqueTypeCollector<'tcx> {
|
|||
#[instrument(skip(self), ret, level = "trace")]
|
||||
fn visit_ty(&mut self, t: Ty<'tcx>) {
|
||||
t.super_visit_with(self);
|
||||
match t.kind() {
|
||||
match *t.kind() {
|
||||
ty::Alias(ty::Opaque, alias_ty) if alias_ty.def_id.is_local() => {
|
||||
self.visit_opaque_ty(alias_ty);
|
||||
}
|
||||
|
@ -279,7 +279,7 @@ fn visit_ty(&mut self, t: Ty<'tcx>) {
|
|||
// assumption to the `param_env` of the default method. We also separately
|
||||
// rely on that assumption here.
|
||||
let ty = self.tcx.type_of(alias_ty.def_id).instantiate(self.tcx, alias_ty.args);
|
||||
let ty::Alias(ty::Opaque, alias_ty) = ty.kind() else { bug!("{ty:?}") };
|
||||
let ty::Alias(ty::Opaque, alias_ty) = *ty.kind() else { bug!("{ty:?}") };
|
||||
self.visit_opaque_ty(alias_ty);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue