about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLukas Wirth <lukastw97@gmail.com>2023-09-09 22:45:01 +0200
committerLukas Wirth <lukastw97@gmail.com>2023-09-10 08:24:26 +0200
commitccff704c25482c583471312f22f9eecf2052ecc8 (patch)
treea8c7075e7bf50ef50644bd9a3a7c54dc65bb8421
parent994df3d6a31d39f11600f30a6df0b744b13937c1 (diff)
downloadrust-ccff704c25482c583471312f22f9eecf2052ecc8.tar.gz
rust-ccff704c25482c583471312f22f9eecf2052ecc8.zip
Shrink some stuff
-rw-r--r--crates/hir-ty/src/layout.rs10
-rw-r--r--crates/hir-ty/src/layout/adt.rs2
-rw-r--r--crates/hir-ty/src/layout/tests.rs4
-rw-r--r--crates/hir-ty/src/mir/borrowck.rs1
-rw-r--r--crates/hir-ty/src/mir/eval.rs8
-rw-r--r--crates/hir-ty/src/mir/lower.rs8
-rw-r--r--crates/ide/src/status.rs1
7 files changed, 18 insertions, 16 deletions
diff --git a/crates/hir-ty/src/layout.rs b/crates/hir-ty/src/layout.rs
index 714930ba667..1a6106c0244 100644
--- a/crates/hir-ty/src/layout.rs
+++ b/crates/hir-ty/src/layout.rs
@@ -24,7 +24,7 @@ pub use self::{
 
 macro_rules! user_error {
     ($it: expr) => {
-        return Err(LayoutError::UserError(format!($it)))
+        return Err(LayoutError::UserError(format!($it).into()))
     };
 }
 
@@ -50,7 +50,7 @@ pub type Variants = hir_def::layout::Variants<RustcEnumVariantIdx>;
 
 #[derive(Debug, PartialEq, Eq, Clone)]
 pub enum LayoutError {
-    UserError(String),
+    UserError(Box<str>),
     SizeOverflow,
     TargetLayoutNotAvailable,
     HasPlaceholder,
@@ -234,9 +234,9 @@ pub fn layout_of_ty_query(
             cx.univariant(dl, &fields, &ReprOptions::default(), kind).ok_or(LayoutError::Unknown)?
         }
         TyKind::Array(element, count) => {
-            let count = try_const_usize(db, &count).ok_or(LayoutError::UserError(
-                "unevaluated or mistyped const generic parameter".to_string(),
-            ))? as u64;
+            let count = try_const_usize(db, &count).ok_or(LayoutError::UserError(Box::from(
+                "unevaluated or mistyped const generic parameter",
+            )))? as u64;
             let element = db.layout_of_ty(element.clone(), trait_env.clone())?;
             let size = element.size.checked_mul(count, dl).ok_or(LayoutError::SizeOverflow)?;
 
diff --git a/crates/hir-ty/src/layout/adt.rs b/crates/hir-ty/src/layout/adt.rs
index 1c92e80f335..85ef649b895 100644
--- a/crates/hir-ty/src/layout/adt.rs
+++ b/crates/hir-ty/src/layout/adt.rs
@@ -163,7 +163,7 @@ fn repr_discr(
             return Err(LayoutError::UserError(
                 "Integer::repr_discr: `#[repr]` hint too small for \
                       discriminant range of enum "
-                    .to_string(),
+                    .into(),
             ));
         }
         return Ok((discr, ity.is_signed()));
diff --git a/crates/hir-ty/src/layout/tests.rs b/crates/hir-ty/src/layout/tests.rs
index 333ad473a8b..ffdbb9de934 100644
--- a/crates/hir-ty/src/layout/tests.rs
+++ b/crates/hir-ty/src/layout/tests.rs
@@ -212,14 +212,14 @@ fn recursive() {
     }
     check_fail(
         r#"struct Goal(Goal);"#,
-        LayoutError::UserError("infinite sized recursive type".to_string()),
+        LayoutError::UserError("infinite sized recursive type".into()),
     );
     check_fail(
         r#"
         struct Foo<T>(Foo<T>);
         struct Goal(Foo<i32>);
         "#,
-        LayoutError::UserError("infinite sized recursive type".to_string()),
+        LayoutError::UserError("infinite sized recursive type".into()),
     );
 }
 
diff --git a/crates/hir-ty/src/mir/borrowck.rs b/crates/hir-ty/src/mir/borrowck.rs
index 7f80c7be80b..41fb129652a 100644
--- a/crates/hir-ty/src/mir/borrowck.rs
+++ b/crates/hir-ty/src/mir/borrowck.rs
@@ -179,6 +179,7 @@ fn moved_out_of_ref(db: &dyn HirDatabase, body: &MirBody) -> Vec<MovedOutOfRef>
             None => (),
         }
     }
+    result.shrink_to_fit();
     result
 }
 
diff --git a/crates/hir-ty/src/mir/eval.rs b/crates/hir-ty/src/mir/eval.rs
index 7d73a4dcaa9..4364e0d323b 100644
--- a/crates/hir-ty/src/mir/eval.rs
+++ b/crates/hir-ty/src/mir/eval.rs
@@ -339,7 +339,7 @@ pub enum MirEvalError {
     InvalidVTableId(usize),
     CoerceUnsizedError(Ty),
     LangItemNotFound(LangItem),
-    BrokenLayout(Layout),
+    BrokenLayout(Box<Layout>),
 }
 
 impl MirEvalError {
@@ -408,7 +408,7 @@ impl MirEvalError {
                 err.pretty_print(f, db, span_formatter)?;
             }
             MirEvalError::ConstEvalError(name, err) => {
-                MirLowerError::ConstEvalError(name.clone(), err.clone()).pretty_print(
+                MirLowerError::ConstEvalError((**name).into(), err.clone()).pretty_print(
                     f,
                     db,
                     span_formatter,
@@ -1632,7 +1632,7 @@ impl Evaluator<'_> {
         if let Some((offset, size, value)) = tag {
             match result.get_mut(offset..offset + size) {
                 Some(it) => it.copy_from_slice(&value.to_le_bytes()[0..size]),
-                None => return Err(MirEvalError::BrokenLayout(variant_layout.clone())),
+                None => return Err(MirEvalError::BrokenLayout(Box::new(variant_layout.clone()))),
             }
         }
         for (i, op) in values.enumerate() {
@@ -1640,7 +1640,7 @@ impl Evaluator<'_> {
             let op = op.get(&self)?;
             match result.get_mut(offset..offset + op.len()) {
                 Some(it) => it.copy_from_slice(op),
-                None => return Err(MirEvalError::BrokenLayout(variant_layout.clone())),
+                None => return Err(MirEvalError::BrokenLayout(Box::new(variant_layout.clone()))),
             }
         }
         Ok(result)
diff --git a/crates/hir-ty/src/mir/lower.rs b/crates/hir-ty/src/mir/lower.rs
index bceeb185003..dd2dba717f9 100644
--- a/crates/hir-ty/src/mir/lower.rs
+++ b/crates/hir-ty/src/mir/lower.rs
@@ -71,7 +71,7 @@ struct MirLowerCtx<'a> {
 
 #[derive(Debug, Clone, PartialEq, Eq)]
 pub enum MirLowerError {
-    ConstEvalError(String, Box<ConstEvalError>),
+    ConstEvalError(Box<str>, Box<ConstEvalError>),
     LayoutError(LayoutError),
     IncompleteExpr,
     IncompletePattern,
@@ -84,7 +84,7 @@ pub enum MirLowerError {
     UnsizedTemporary(Ty),
     MissingFunctionDefinition(DefWithBodyId, ExprId),
     TypeMismatch(TypeMismatch),
-    /// This should be never happen. Type mismatch should catch everything.
+    /// This should never happen. Type mismatch should catch everything.
     TypeError(&'static str),
     NotSupported(String),
     ContinueWithoutLoop,
@@ -1456,7 +1456,7 @@ impl<'ctx> MirLowerCtx<'ctx> {
             let name = const_id.name(self.db.upcast());
             self.db
                 .const_eval(const_id.into(), subst, None)
-                .map_err(|e| MirLowerError::ConstEvalError(name, Box::new(e)))?
+                .map_err(|e| MirLowerError::ConstEvalError(name.into(), Box::new(e)))?
         };
         Ok(Operand::Constant(c))
     }
@@ -1853,7 +1853,7 @@ impl<'ctx> MirLowerCtx<'ctx> {
                     data.name.display(self.db.upcast()),
                     data.variants[variant.local_id].name.display(self.db.upcast())
                 );
-                Err(MirLowerError::ConstEvalError(name, Box::new(e)))
+                Err(MirLowerError::ConstEvalError(name.into(), Box::new(e)))
             }
         }
     }
diff --git a/crates/ide/src/status.rs b/crates/ide/src/status.rs
index d2c77e2dc79..c9ee460a1c2 100644
--- a/crates/ide/src/status.rs
+++ b/crates/ide/src/status.rs
@@ -66,6 +66,7 @@ pub(crate) fn status(db: &RootDatabase, file_id: Option<FileId>) -> String {
                 None => format!("{}", krate.into_raw()),
             };
             format_to!(buf, "Crate: {}\n", display_crate(krate));
+            format_to!(buf, "Enabled cfgs: {:?}\n", crate_graph[krate].cfg_options);
             let deps = crate_graph[krate]
                 .dependencies
                 .iter()