diff options
| author | Lukas Wirth <lukastw97@gmail.com> | 2021-11-20 16:37:41 +0100 |
|---|---|---|
| committer | Lukas Wirth <lukastw97@gmail.com> | 2021-11-20 16:37:41 +0100 |
| commit | 91def936bc0ecabd574eb312e376afa801f12dca (patch) | |
| tree | 62f2c391d78c87aa19f98d00baff033272149959 | |
| parent | ceaec9d8666614f6e84506b84f4b740538cb6d50 (diff) | |
| download | rust-91def936bc0ecabd574eb312e376afa801f12dca.tar.gz rust-91def936bc0ecabd574eb312e376afa801f12dca.zip | |
Replace Vec with Box in Path.generic_args field
| -rw-r--r-- | crates/hir_def/src/expr.rs | 2 | ||||
| -rw-r--r-- | crates/hir_def/src/path.rs | 16 | ||||
| -rw-r--r-- | crates/hir_def/src/path/lower.rs | 17 |
3 files changed, 15 insertions, 20 deletions
diff --git a/crates/hir_def/src/expr.rs b/crates/hir_def/src/expr.rs index e6518c3e2d7..6534f970ee6 100644 --- a/crates/hir_def/src/expr.rs +++ b/crates/hir_def/src/expr.rs @@ -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), diff --git a/crates/hir_def/src/path.rs b/crates/hir_def/src/path.rs index a54352439ca..5bb8afa5cc9 100644 --- a/crates/hir_def/src/path.rs +++ b/crates/hir_def/src/path.rs @@ -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]), } } } diff --git a/crates/hir_def/src/path/lower.rs b/crates/hir_def/src/path/lower.rs index b08708bd28a..c84cd50ce6e 100644 --- a/crates/hir_def/src/path/lower.rs +++ b/crates/hir_def/src/path/lower.rs @@ -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() { |
