mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-01 23:12:02 +00:00
review fixups
This commit is contained in:
parent
af51424008
commit
df925fda9c
@ -498,12 +498,13 @@ impl server::TokenStream for Rustc<'_, '_> {
|
||||
}
|
||||
builder.build()
|
||||
}
|
||||
fn into_iter(
|
||||
fn into_trees(
|
||||
&mut self,
|
||||
stream: Self::TokenStream,
|
||||
) -> Vec<TokenTree<Self::Group, Self::Punct, Self::Ident, Self::Literal>> {
|
||||
// FIXME: This is a raw port of the previous approach, and can probably
|
||||
// be optimized.
|
||||
// FIXME: This is a raw port of the previous approach (which had a
|
||||
// `TokenStreamIter` server-side object with a single `next` method),
|
||||
// and can probably be optimized (for bulk conversion).
|
||||
let mut cursor = stream.into_trees();
|
||||
let mut stack = Vec::new();
|
||||
let mut tts = Vec::new();
|
||||
|
@ -73,9 +73,9 @@ macro_rules! with_api {
|
||||
) -> $S::TokenStream;
|
||||
fn concat_streams(
|
||||
base: Option<$S::TokenStream>,
|
||||
trees: Vec<$S::TokenStream>,
|
||||
streams: Vec<$S::TokenStream>,
|
||||
) -> $S::TokenStream;
|
||||
fn into_iter(
|
||||
fn into_trees(
|
||||
$self: $S::TokenStream
|
||||
) -> Vec<TokenTree<$S::Group, $S::Punct, $S::Ident, $S::Literal>>;
|
||||
},
|
||||
@ -307,32 +307,6 @@ impl<'a, T, M> Unmark for &'a mut Marked<T, M> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Mark> Mark for Option<T> {
|
||||
type Unmarked = Option<T::Unmarked>;
|
||||
fn mark(unmarked: Self::Unmarked) -> Self {
|
||||
unmarked.map(T::mark)
|
||||
}
|
||||
}
|
||||
impl<T: Unmark> Unmark for Option<T> {
|
||||
type Unmarked = Option<T::Unmarked>;
|
||||
fn unmark(self) -> Self::Unmarked {
|
||||
self.map(T::unmark)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Mark, E: Mark> Mark for Result<T, E> {
|
||||
type Unmarked = Result<T::Unmarked, E::Unmarked>;
|
||||
fn mark(unmarked: Self::Unmarked) -> Self {
|
||||
unmarked.map(T::mark).map_err(E::mark)
|
||||
}
|
||||
}
|
||||
impl<T: Unmark, E: Unmark> Unmark for Result<T, E> {
|
||||
type Unmarked = Result<T::Unmarked, E::Unmarked>;
|
||||
fn unmark(self) -> Self::Unmarked {
|
||||
self.map(T::unmark).map_err(E::unmark)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Mark> Mark for Vec<T> {
|
||||
type Unmarked = Vec<T::Unmarked>;
|
||||
fn mark(unmarked: Self::Unmarked) -> Self {
|
||||
@ -378,7 +352,6 @@ mark_noop! {
|
||||
Level,
|
||||
LineColumn,
|
||||
Spacing,
|
||||
Bound<usize>,
|
||||
}
|
||||
|
||||
rpc_encode_decode!(
|
||||
@ -438,6 +411,28 @@ macro_rules! compound_traits {
|
||||
};
|
||||
}
|
||||
|
||||
compound_traits!(
|
||||
enum Bound<T> {
|
||||
Included(x),
|
||||
Excluded(x),
|
||||
Unbounded,
|
||||
}
|
||||
);
|
||||
|
||||
compound_traits!(
|
||||
enum Option<T> {
|
||||
Some(t),
|
||||
None,
|
||||
}
|
||||
);
|
||||
|
||||
compound_traits!(
|
||||
enum Result<T, E> {
|
||||
Ok(t),
|
||||
Err(e),
|
||||
}
|
||||
);
|
||||
|
||||
#[derive(Clone)]
|
||||
pub enum TokenTree<G, P, I, L> {
|
||||
Group(G),
|
||||
|
@ -4,7 +4,6 @@ use std::any::Any;
|
||||
use std::char;
|
||||
use std::io::Write;
|
||||
use std::num::NonZeroU32;
|
||||
use std::ops::Bound;
|
||||
use std::str;
|
||||
|
||||
pub(super) type Writer = super::buffer::Buffer;
|
||||
@ -186,28 +185,6 @@ impl<'a, S, A: for<'s> DecodeMut<'a, 's, S>, B: for<'s> DecodeMut<'a, 's, S>> De
|
||||
}
|
||||
}
|
||||
|
||||
rpc_encode_decode!(
|
||||
enum Bound<T> {
|
||||
Included(x),
|
||||
Excluded(x),
|
||||
Unbounded,
|
||||
}
|
||||
);
|
||||
|
||||
rpc_encode_decode!(
|
||||
enum Option<T> {
|
||||
None,
|
||||
Some(x),
|
||||
}
|
||||
);
|
||||
|
||||
rpc_encode_decode!(
|
||||
enum Result<T, E> {
|
||||
Ok(x),
|
||||
Err(e),
|
||||
}
|
||||
);
|
||||
|
||||
impl<S> Encode<S> for &[u8] {
|
||||
fn encode(self, w: &mut Writer, s: &mut S) {
|
||||
self.len().encode(w, s);
|
||||
|
@ -235,7 +235,7 @@ impl From<TokenTree> for TokenStream {
|
||||
|
||||
/// Non-generic helper for implementing `FromIterator<TokenTree>` and
|
||||
/// `Extend<TokenTree>` with less monomorphization in calling crates.
|
||||
struct ExtendStreamWithTreesHelper {
|
||||
struct ConcatTreesHelper {
|
||||
trees: Vec<
|
||||
bridge::TokenTree<
|
||||
bridge::client::Group,
|
||||
@ -246,9 +246,9 @@ struct ExtendStreamWithTreesHelper {
|
||||
>,
|
||||
}
|
||||
|
||||
impl ExtendStreamWithTreesHelper {
|
||||
impl ConcatTreesHelper {
|
||||
fn new(capacity: usize) -> Self {
|
||||
ExtendStreamWithTreesHelper { trees: Vec::with_capacity(capacity) }
|
||||
ConcatTreesHelper { trees: Vec::with_capacity(capacity) }
|
||||
}
|
||||
|
||||
fn push(&mut self, tree: TokenTree) {
|
||||
@ -263,7 +263,7 @@ impl ExtendStreamWithTreesHelper {
|
||||
}
|
||||
}
|
||||
|
||||
fn extend(self, stream: &mut TokenStream) {
|
||||
fn append_to(self, stream: &mut TokenStream) {
|
||||
if self.trees.is_empty() {
|
||||
return;
|
||||
}
|
||||
@ -273,13 +273,13 @@ impl ExtendStreamWithTreesHelper {
|
||||
|
||||
/// Non-generic helper for implementing `FromIterator<TokenStream>` and
|
||||
/// `Extend<TokenStream>` with less monomorphization in calling crates.
|
||||
struct ExtendStreamWithStreamsHelper {
|
||||
struct ConcatStreamsHelper {
|
||||
streams: Vec<bridge::client::TokenStream>,
|
||||
}
|
||||
|
||||
impl ExtendStreamWithStreamsHelper {
|
||||
impl ConcatStreamsHelper {
|
||||
fn new(capacity: usize) -> Self {
|
||||
ExtendStreamWithStreamsHelper { streams: Vec::with_capacity(capacity) }
|
||||
ConcatStreamsHelper { streams: Vec::with_capacity(capacity) }
|
||||
}
|
||||
|
||||
fn push(&mut self, stream: TokenStream) {
|
||||
@ -296,7 +296,7 @@ impl ExtendStreamWithStreamsHelper {
|
||||
}
|
||||
}
|
||||
|
||||
fn extend(mut self, stream: &mut TokenStream) {
|
||||
fn append_to(mut self, stream: &mut TokenStream) {
|
||||
if self.streams.is_empty() {
|
||||
return;
|
||||
}
|
||||
@ -314,7 +314,7 @@ impl ExtendStreamWithStreamsHelper {
|
||||
impl iter::FromIterator<TokenTree> for TokenStream {
|
||||
fn from_iter<I: IntoIterator<Item = TokenTree>>(trees: I) -> Self {
|
||||
let iter = trees.into_iter();
|
||||
let mut builder = ExtendStreamWithTreesHelper::new(iter.size_hint().0);
|
||||
let mut builder = ConcatTreesHelper::new(iter.size_hint().0);
|
||||
iter.for_each(|tree| builder.push(tree));
|
||||
builder.build()
|
||||
}
|
||||
@ -326,7 +326,7 @@ impl iter::FromIterator<TokenTree> for TokenStream {
|
||||
impl iter::FromIterator<TokenStream> for TokenStream {
|
||||
fn from_iter<I: IntoIterator<Item = TokenStream>>(streams: I) -> Self {
|
||||
let iter = streams.into_iter();
|
||||
let mut builder = ExtendStreamWithStreamsHelper::new(iter.size_hint().0);
|
||||
let mut builder = ConcatStreamsHelper::new(iter.size_hint().0);
|
||||
iter.for_each(|stream| builder.push(stream));
|
||||
builder.build()
|
||||
}
|
||||
@ -336,9 +336,9 @@ impl iter::FromIterator<TokenStream> for TokenStream {
|
||||
impl Extend<TokenTree> for TokenStream {
|
||||
fn extend<I: IntoIterator<Item = TokenTree>>(&mut self, trees: I) {
|
||||
let iter = trees.into_iter();
|
||||
let mut builder = ExtendStreamWithTreesHelper::new(iter.size_hint().0);
|
||||
let mut builder = ConcatTreesHelper::new(iter.size_hint().0);
|
||||
iter.for_each(|tree| builder.push(tree));
|
||||
builder.extend(self);
|
||||
builder.append_to(self);
|
||||
}
|
||||
}
|
||||
|
||||
@ -346,9 +346,9 @@ impl Extend<TokenTree> for TokenStream {
|
||||
impl Extend<TokenStream> for TokenStream {
|
||||
fn extend<I: IntoIterator<Item = TokenStream>>(&mut self, streams: I) {
|
||||
let iter = streams.into_iter();
|
||||
let mut builder = ExtendStreamWithStreamsHelper::new(iter.size_hint().0);
|
||||
let mut builder = ConcatStreamsHelper::new(iter.size_hint().0);
|
||||
iter.for_each(|stream| builder.push(stream));
|
||||
builder.extend(self);
|
||||
builder.append_to(self);
|
||||
}
|
||||
}
|
||||
|
||||
@ -393,7 +393,7 @@ pub mod token_stream {
|
||||
type IntoIter = IntoIter;
|
||||
|
||||
fn into_iter(self) -> IntoIter {
|
||||
IntoIter(self.0.map(|v| v.into_iter()).unwrap_or_default().into_iter())
|
||||
IntoIter(self.0.map(|v| v.into_trees()).unwrap_or_default().into_iter())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user