mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-29 18:23:49 +00:00
Replace Vec with Box in Path.generic_args field
This commit is contained in:
parent
ceaec9d866
commit
91def936bc
@ -40,7 +40,7 @@ pub type LabelId = Idx<Label>;
|
||||
|
||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||
pub enum Literal {
|
||||
String(String),
|
||||
String(Box<str>),
|
||||
ByteString(Box<[u8]>),
|
||||
Char(char),
|
||||
Bool(bool),
|
||||
|
@ -22,7 +22,7 @@ pub struct ModPath {
|
||||
segments: Vec<Name>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
pub enum PathKind {
|
||||
Plain,
|
||||
/// `self::` is `Super(0)`
|
||||
@ -119,7 +119,7 @@ pub struct Path {
|
||||
type_anchor: Option<Interned<TypeRef>>,
|
||||
mod_path: Interned<ModPath>,
|
||||
/// Invariant: the same len as `self.mod_path.segments`
|
||||
generic_args: Vec<Option<Interned<GenericArgs>>>,
|
||||
generic_args: Box<[Option<Interned<GenericArgs>>]>,
|
||||
}
|
||||
|
||||
/// Generic arguments to a path segment (e.g. the `i32` in `Option<i32>`). This
|
||||
@ -171,9 +171,9 @@ impl Path {
|
||||
/// Converts a known mod path to `Path`.
|
||||
pub fn from_known_path(
|
||||
path: ModPath,
|
||||
generic_args: Vec<Option<Interned<GenericArgs>>>,
|
||||
generic_args: impl Into<Box<[Option<Interned<GenericArgs>>]>>,
|
||||
) -> Path {
|
||||
Path { type_anchor: None, mod_path: Interned::new(path), generic_args }
|
||||
Path { type_anchor: None, mod_path: Interned::new(path), generic_args: generic_args.into() }
|
||||
}
|
||||
|
||||
pub fn kind(&self) -> &PathKind {
|
||||
@ -187,7 +187,7 @@ impl Path {
|
||||
pub fn segments(&self) -> PathSegments<'_> {
|
||||
PathSegments {
|
||||
segments: self.mod_path.segments.as_slice(),
|
||||
generic_args: self.generic_args.as_slice(),
|
||||
generic_args: &self.generic_args,
|
||||
}
|
||||
}
|
||||
|
||||
@ -205,14 +205,14 @@ impl Path {
|
||||
self.mod_path.kind.clone(),
|
||||
self.mod_path.segments[..self.mod_path.segments.len() - 1].iter().cloned(),
|
||||
)),
|
||||
generic_args: self.generic_args[..self.generic_args.len() - 1].to_vec(),
|
||||
generic_args: self.generic_args[..self.generic_args.len() - 1].to_vec().into(),
|
||||
};
|
||||
Some(res)
|
||||
}
|
||||
|
||||
pub fn is_self_type(&self) -> bool {
|
||||
self.type_anchor.is_none()
|
||||
&& self.generic_args == [None]
|
||||
&& *self.generic_args == [None]
|
||||
&& self.mod_path.as_ident() == Some(&name!(Self))
|
||||
}
|
||||
}
|
||||
@ -286,7 +286,7 @@ impl From<Name> for Path {
|
||||
Path {
|
||||
type_anchor: None,
|
||||
mod_path: Interned::new(ModPath::from_segments(PathKind::Plain, iter::once(name))),
|
||||
generic_args: vec![None],
|
||||
generic_args: Box::new([None]),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -70,18 +70,13 @@ pub(super) fn lower_path(mut path: ast::Path, ctx: &LowerCtx) -> Option<Path> {
|
||||
}
|
||||
// <T as Trait<A>>::Foo desugars to Trait<Self=T, A>::Foo
|
||||
Some(trait_ref) => {
|
||||
let path = Path::from_src(trait_ref.path()?, ctx)?;
|
||||
let mod_path = (*path.mod_path).clone();
|
||||
let num_segments = path.mod_path.segments.len();
|
||||
let Path { mod_path, generic_args: path_generic_args, .. } =
|
||||
Path::from_src(trait_ref.path()?, ctx)?;
|
||||
let num_segments = mod_path.segments.len();
|
||||
kind = mod_path.kind;
|
||||
|
||||
let mut prefix_segments = mod_path.segments;
|
||||
prefix_segments.reverse();
|
||||
segments.extend(prefix_segments);
|
||||
|
||||
let mut prefix_args = path.generic_args;
|
||||
prefix_args.reverse();
|
||||
generic_args.extend(prefix_args);
|
||||
segments.extend(mod_path.segments.iter().cloned().rev());
|
||||
generic_args.extend(path_generic_args.iter().cloned().rev());
|
||||
|
||||
// Insert the type reference (T in the above example) as Self parameter for the trait
|
||||
let last_segment =
|
||||
@ -139,7 +134,7 @@ pub(super) fn lower_path(mut path: ast::Path, ctx: &LowerCtx) -> Option<Path> {
|
||||
}
|
||||
|
||||
let mod_path = Interned::new(ModPath::from_segments(kind, segments));
|
||||
return Some(Path { type_anchor, mod_path, generic_args });
|
||||
return Some(Path { type_anchor, mod_path, generic_args: generic_args.into() });
|
||||
|
||||
fn qualifier(path: &ast::Path) -> Option<ast::Path> {
|
||||
if let Some(q) = path.qualifier() {
|
||||
|
Loading…
Reference in New Issue
Block a user