Remove the InternIteratorElement
impl for &'a T
.
`InternIteratorElement` is a trait used to intern values produces by iterators. There are three impls, corresponding to iterators that produce different types: - One for `T`, which operates straightforwardly. - One for `Result<T, E>`, which is fallible, and will fail early with an error result if any of the iterator elements are errors. - One for `&'a T`, which clones the items as it iterates. That last one is bad: it's extremely easy to use it without realizing that it clones, which goes against Rust's normal "explicit is better" approach to cloning. So this commit just removes it. In practice, there weren't many use sites. For all but one of them `into_iter()` could be used, which avoids the need for cloning. And for the one remaining case `copied()` is used.
This commit is contained in:
parent
28184e7491
commit
9d5cf0f0bf
@ -264,7 +264,7 @@ fn check_lang_start_fn<'tcx>(
|
||||
let fn_generic = generics.param_at(0, tcx);
|
||||
let generic_ty = tcx.mk_ty_param(fn_generic.index, fn_generic.name);
|
||||
let expected_fn_sig =
|
||||
tcx.mk_fn_sig([].iter(), &generic_ty, false, hir::Unsafety::Normal, Abi::Rust);
|
||||
tcx.mk_fn_sig([].into_iter(), generic_ty, false, hir::Unsafety::Normal, Abi::Rust);
|
||||
let expected_ty = tcx.mk_fn_ptr(Binder::dummy(expected_fn_sig));
|
||||
|
||||
// we emit the same error to suggest changing the arg no matter what's wrong with the arg
|
||||
|
@ -312,7 +312,7 @@ pub fn resolve_interior<'a, 'tcx>(
|
||||
|
||||
// Extract type components to build the witness type.
|
||||
let type_list = fcx.tcx.mk_type_list(type_causes.iter().map(|cause| cause.ty));
|
||||
let bound_vars = fcx.tcx.mk_bound_variable_kinds(bound_vars.iter());
|
||||
let bound_vars = fcx.tcx.mk_bound_variable_kinds(bound_vars.into_iter());
|
||||
let witness =
|
||||
fcx.tcx.mk_generator_witness(ty::Binder::bind_with_vars(type_list, bound_vars.clone()));
|
||||
|
||||
|
@ -2387,7 +2387,7 @@ pub fn late_bound_vars(self, id: HirId) -> &'tcx List<ty::BoundVariableKind> {
|
||||
.unwrap_or_else(|| {
|
||||
bug!("No bound vars found for {}", self.hir().node_to_string(id))
|
||||
})
|
||||
.iter(),
|
||||
.into_iter(),
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -781,8 +781,8 @@ fn transform_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, options: TransformTyOptio
|
||||
let output = transform_ty(tcx, fn_sig.skip_binder().output(), options);
|
||||
ty = tcx.mk_fn_ptr(ty::Binder::bind_with_vars(
|
||||
tcx.mk_fn_sig(
|
||||
parameters.iter(),
|
||||
&output,
|
||||
parameters.into_iter(),
|
||||
output,
|
||||
fn_sig.c_variadic(),
|
||||
fn_sig.unsafety(),
|
||||
fn_sig.abi(),
|
||||
|
@ -359,7 +359,7 @@ fn consider_builtin_unsize_candidate(
|
||||
let b_last_ty = b_tys.last().unwrap();
|
||||
|
||||
// Substitute just the tail field of B., and require that they're equal.
|
||||
let unsized_a_ty = tcx.mk_tup(a_rest_tys.iter().chain([b_last_ty]));
|
||||
let unsized_a_ty = tcx.mk_tup(a_rest_tys.iter().chain([b_last_ty]).copied());
|
||||
let mut nested_goals = ecx.infcx.eq(goal.param_env, unsized_a_ty, b_ty)?;
|
||||
|
||||
// Similar to ADTs, require that the rest of the fields are equal.
|
||||
|
@ -141,8 +141,8 @@ fn fn_sig_for_fn_abi<'tcx>(
|
||||
|
||||
ty::Binder::bind_with_vars(
|
||||
tcx.mk_fn_sig(
|
||||
[env_ty, resume_ty].iter(),
|
||||
&ret_ty,
|
||||
[env_ty, resume_ty].into_iter(),
|
||||
ret_ty,
|
||||
false,
|
||||
hir::Unsafety::Normal,
|
||||
rustc_target::spec::abi::Abi::Rust,
|
||||
|
@ -127,17 +127,6 @@ fn intern_with<I: Iterator<Item = Self>, F: FnOnce(&[T]) -> R>(
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T, R> InternIteratorElement<T, R> for &'a T
|
||||
where
|
||||
T: Clone + 'a,
|
||||
{
|
||||
type Output = R;
|
||||
fn intern_with<I: Iterator<Item = Self>, F: FnOnce(&[T]) -> R>(iter: I, f: F) -> Self::Output {
|
||||
// This code isn't hot.
|
||||
f(&iter.cloned().collect::<SmallVec<[_; 8]>>())
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, R, E> InternIteratorElement<T, R> for Result<T, E> {
|
||||
type Output = Result<R, E>;
|
||||
fn intern_with<I: Iterator<Item = Self>, F: FnOnce(&[T]) -> R>(
|
||||
|
Loading…
Reference in New Issue
Block a user