Skip to content

Rename iter::Iterator::intersperse() to ::separate() #123110

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions compiler/rustc_codegen_llvm/src/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -489,8 +489,7 @@ pub fn from_fn_attrs<'ll, 'tcx>(

let global_features = cx.tcx.global_backend_features(()).iter().map(|s| s.as_str());
let function_features = function_features.iter().map(|s| s.as_str());
let target_features: String =
global_features.chain(function_features).intersperse(",").collect();
let target_features: String = global_features.chain(function_features).separate(",").collect();
if !target_features.is_empty() {
to_add.push(llvm::CreateAttrStringValue(cx.llcx, "target-features", &target_features));
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/check/intrinsicck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
features
.iter()
.map(|f| f.as_str())
.intersperse(", ")
.separate(", ")
.collect::<String>(),
);
self.tcx.dcx().span_err(*op_sp, msg);
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1667,7 +1667,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
types_and_spans[..types_and_spans.len() - 1]
.iter()
.map(|(x, _)| x.as_str())
.intersperse(", ")
.separate(", ")
.collect::<String>()
),
[(only, _)] => only.to_string(),
Expand Down Expand Up @@ -1696,7 +1696,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
kinds[..kinds.len() - 1]
.iter()
.map(|&x| x)
.intersperse(", ")
.separate(", ")
.collect::<String>()
),
"s",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
}
_ => param.name.as_str(),
})
.intersperse(", ")
.separate(", ")
.collect()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ fn make_elided_region_spans_suggs<'a>(
consecutive_brackets += 1;
} else if let Some(bracket_span) = bracket_span.take() {
let sugg = std::iter::once("<")
.chain(std::iter::repeat(name).take(consecutive_brackets).intersperse(", "))
.chain(std::iter::repeat(name).take(consecutive_brackets).separate(", "))
.chain([">"])
.collect();
spans_suggs.push((bracket_span.shrink_to_hi(), sugg));
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_parse/src/parser/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ impl<'a> Parser<'a> {

let sugg = if !lifetimes.is_empty() {
let snippet =
lifetimes.iter().map(|param| param.ident.as_str()).intersperse(", ").collect();
lifetimes.iter().map(|param| param.ident.as_str()).separate(", ").collect();

let (left, snippet) = if let Some(span) = param_insertion_point {
(span, if params.is_empty() { snippet } else { format!(", {snippet}") })
Expand Down Expand Up @@ -1134,7 +1134,7 @@ impl<'a> Parser<'a> {
let generic_args_span = generic_args.span();
let snippet = format!(
"for<{}> ",
lifetimes.iter().map(|lt| lt.ident.as_str()).intersperse(", ").collect::<String>(),
lifetimes.iter().map(|lt| lt.ident.as_str()).separate(", ").collect::<String>(),
);
let before_fn_path = fn_path.span.shrink_to_lo();
self.dcx()
Expand Down
4 changes: 1 addition & 3 deletions compiler/rustc_resolve/src/late/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3005,9 +3005,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
}
MissingLifetimeKind::Brackets => {
let sugg: String = std::iter::once("<")
.chain(
std::iter::repeat(existing_name.as_str()).take(lt.count).intersperse(", "),
)
.chain(std::iter::repeat(existing_name.as_str()).take(lt.count).separate(", "))
.chain([">"])
.collect();
(lt.span.shrink_to_hi(), sugg)
Expand Down
7 changes: 2 additions & 5 deletions compiler/rustc_session/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2771,11 +2771,8 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
// Check `-C link-self-contained` for consistency: individual components cannot be both enabled
// and disabled at the same time.
if let Some(erroneous_components) = cg.link_self_contained.check_consistency() {
let names: String = erroneous_components
.into_iter()
.map(|c| c.as_str().unwrap())
.intersperse(", ")
.collect();
let names: String =
erroneous_components.into_iter().map(|c| c.as_str().unwrap()).separate(", ").collect();
early_dcx.early_fatal(format!(
"some `-C link-self-contained` components were both enabled and disabled: {names}"
));
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_target/src/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ impl LinkerFlavor {
.iter()
.filter(|cli| compatible(**cli))
.map(|cli| cli.desc())
.intersperse(", ")
.separate(", ")
.collect()
})
}
Expand Down
4 changes: 2 additions & 2 deletions library/core/src/iter/adapters/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ mod filter_map;
mod flatten;
mod fuse;
mod inspect;
mod intersperse;
mod map;
mod map_while;
mod map_windows;
mod peekable;
mod rev;
mod scan;
mod separate;
mod skip;
mod skip_while;
mod step_by;
Expand Down Expand Up @@ -54,7 +54,7 @@ pub use self::flatten::Flatten;
pub use self::copied::Copied;

#[unstable(feature = "iter_intersperse", reason = "recently added", issue = "79524")]
pub use self::intersperse::{Intersperse, IntersperseWith};
pub use self::separate::{Separate, SeparateWith};

#[stable(feature = "iter_map_while", since = "1.57.0")]
pub use self::map_while::MapWhile;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ use crate::iter::{Fuse, FusedIterator};

/// An iterator adapter that places a separator between all elements.
///
/// This `struct` is created by [`Iterator::intersperse`]. See its documentation
/// This `struct` is created by [`Iterator::separate`]. See its documentation
/// for more information.
#[unstable(feature = "iter_intersperse", reason = "recently added", issue = "79524")]
#[derive(Debug, Clone)]
pub struct Intersperse<I: Iterator>
pub struct Separate<I: Iterator>
where
I::Item: Clone,
{
Expand All @@ -18,14 +18,14 @@ where
}

#[unstable(feature = "iter_intersperse", reason = "recently added", issue = "79524")]
impl<I> FusedIterator for Intersperse<I>
impl<I> FusedIterator for Separate<I>
where
I: FusedIterator,
I::Item: Clone,
{
}

impl<I: Iterator> Intersperse<I>
impl<I: Iterator> Separate<I>
where
I::Item: Clone,
{
Expand All @@ -35,7 +35,7 @@ where
}

#[unstable(feature = "iter_intersperse", reason = "recently added", issue = "79524")]
impl<I> Iterator for Intersperse<I>
impl<I> Iterator for Separate<I>
where
I: Iterator,
I::Item: Clone,
Expand Down Expand Up @@ -63,7 +63,7 @@ where
}

fn size_hint(&self) -> (usize, Option<usize>) {
intersperse_size_hint(&self.iter, self.started, self.next_item.is_some())
separate_size_hint(&self.iter, self.started, self.next_item.is_some())
}

fn fold<B, F>(self, init: B, f: F) -> B
Expand All @@ -72,23 +72,16 @@ where
F: FnMut(B, Self::Item) -> B,
{
let separator = self.separator;
intersperse_fold(
self.iter,
init,
f,
move || separator.clone(),
self.started,
self.next_item,
)
separate_fold(self.iter, init, f, move || separator.clone(), self.started, self.next_item)
}
}

/// An iterator adapter that places a separator between all elements.
///
/// This `struct` is created by [`Iterator::intersperse_with`]. See its
/// This `struct` is created by [`Iterator::separate_with`]. See its
/// documentation for more information.
#[unstable(feature = "iter_intersperse", reason = "recently added", issue = "79524")]
pub struct IntersperseWith<I, G>
pub struct SeparateWith<I, G>
where
I: Iterator,
{
Expand All @@ -99,22 +92,22 @@ where
}

#[unstable(feature = "iter_intersperse", reason = "recently added", issue = "79524")]
impl<I, G> FusedIterator for IntersperseWith<I, G>
impl<I, G> FusedIterator for SeparateWith<I, G>
where
I: FusedIterator,
G: FnMut() -> I::Item,
{
}

#[unstable(feature = "iter_intersperse", reason = "recently added", issue = "79524")]
impl<I, G> fmt::Debug for IntersperseWith<I, G>
impl<I, G> fmt::Debug for SeparateWith<I, G>
where
I: Iterator + fmt::Debug,
I::Item: fmt::Debug,
G: fmt::Debug,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("IntersperseWith")
f.debug_struct("SeparateWith")
.field("started", &self.started)
.field("separator", &self.separator)
.field("iter", &self.iter)
Expand All @@ -124,7 +117,7 @@ where
}

#[unstable(feature = "iter_intersperse", reason = "recently added", issue = "79524")]
impl<I, G> Clone for IntersperseWith<I, G>
impl<I, G> Clone for SeparateWith<I, G>
where
I: Iterator + Clone,
I::Item: Clone,
Expand All @@ -140,7 +133,7 @@ where
}
}

impl<I, G> IntersperseWith<I, G>
impl<I, G> SeparateWith<I, G>
where
I: Iterator,
G: FnMut() -> I::Item,
Expand All @@ -151,7 +144,7 @@ where
}

#[unstable(feature = "iter_intersperse", reason = "recently added", issue = "79524")]
impl<I, G> Iterator for IntersperseWith<I, G>
impl<I, G> Iterator for SeparateWith<I, G>
where
I: Iterator,
G: FnMut() -> I::Item,
Expand Down Expand Up @@ -179,19 +172,19 @@ where
}

fn size_hint(&self) -> (usize, Option<usize>) {
intersperse_size_hint(&self.iter, self.started, self.next_item.is_some())
separate_size_hint(&self.iter, self.started, self.next_item.is_some())
}

fn fold<B, F>(self, init: B, f: F) -> B
where
Self: Sized,
F: FnMut(B, Self::Item) -> B,
{
intersperse_fold(self.iter, init, f, self.separator, self.started, self.next_item)
separate_fold(self.iter, init, f, self.separator, self.started, self.next_item)
}
}

fn intersperse_size_hint<I>(iter: &I, started: bool, next_is_some: bool) -> (usize, Option<usize>)
fn separate_size_hint<I>(iter: &I, started: bool, next_is_some: bool) -> (usize, Option<usize>)
where
I: Iterator,
{
Expand All @@ -208,7 +201,7 @@ where
)
}

fn intersperse_fold<I, B, F, G>(
fn separate_fold<I, B, F, G>(
mut iter: I,
init: B,
mut f: F,
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/iter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ pub use self::adapters::{
Skip, SkipWhile, Take, TakeWhile, Zip,
};
#[unstable(feature = "iter_intersperse", reason = "recently added", issue = "79524")]
pub use self::adapters::{Intersperse, IntersperseWith};
pub use self::adapters::{Separate, SeparateWith};

pub(crate) use self::adapters::try_process;
pub(crate) use self::traits::UncheckedIterator;
Expand Down
Loading
Loading