Skip to content

Commit 326f37e

Browse files
committed
Auto merge of #15592 - Veykril:shrink, r=Veykril
Shrink some stuff
2 parents 994df3d + ccff704 commit 326f37e

File tree

7 files changed

+18
-16
lines changed

7 files changed

+18
-16
lines changed

crates/hir-ty/src/layout.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub use self::{
2424

2525
macro_rules! user_error {
2626
($it: expr) => {
27-
return Err(LayoutError::UserError(format!($it)))
27+
return Err(LayoutError::UserError(format!($it).into()))
2828
};
2929
}
3030

@@ -50,7 +50,7 @@ pub type Variants = hir_def::layout::Variants<RustcEnumVariantIdx>;
5050

5151
#[derive(Debug, PartialEq, Eq, Clone)]
5252
pub enum LayoutError {
53-
UserError(String),
53+
UserError(Box<str>),
5454
SizeOverflow,
5555
TargetLayoutNotAvailable,
5656
HasPlaceholder,
@@ -234,9 +234,9 @@ pub fn layout_of_ty_query(
234234
cx.univariant(dl, &fields, &ReprOptions::default(), kind).ok_or(LayoutError::Unknown)?
235235
}
236236
TyKind::Array(element, count) => {
237-
let count = try_const_usize(db, &count).ok_or(LayoutError::UserError(
238-
"unevaluated or mistyped const generic parameter".to_string(),
239-
))? as u64;
237+
let count = try_const_usize(db, &count).ok_or(LayoutError::UserError(Box::from(
238+
"unevaluated or mistyped const generic parameter",
239+
)))? as u64;
240240
let element = db.layout_of_ty(element.clone(), trait_env.clone())?;
241241
let size = element.size.checked_mul(count, dl).ok_or(LayoutError::SizeOverflow)?;
242242

crates/hir-ty/src/layout/adt.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ fn repr_discr(
163163
return Err(LayoutError::UserError(
164164
"Integer::repr_discr: `#[repr]` hint too small for \
165165
discriminant range of enum "
166-
.to_string(),
166+
.into(),
167167
));
168168
}
169169
return Ok((discr, ity.is_signed()));

crates/hir-ty/src/layout/tests.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -212,14 +212,14 @@ fn recursive() {
212212
}
213213
check_fail(
214214
r#"struct Goal(Goal);"#,
215-
LayoutError::UserError("infinite sized recursive type".to_string()),
215+
LayoutError::UserError("infinite sized recursive type".into()),
216216
);
217217
check_fail(
218218
r#"
219219
struct Foo<T>(Foo<T>);
220220
struct Goal(Foo<i32>);
221221
"#,
222-
LayoutError::UserError("infinite sized recursive type".to_string()),
222+
LayoutError::UserError("infinite sized recursive type".into()),
223223
);
224224
}
225225

crates/hir-ty/src/mir/borrowck.rs

+1
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ fn moved_out_of_ref(db: &dyn HirDatabase, body: &MirBody) -> Vec<MovedOutOfRef>
179179
None => (),
180180
}
181181
}
182+
result.shrink_to_fit();
182183
result
183184
}
184185

crates/hir-ty/src/mir/eval.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ pub enum MirEvalError {
339339
InvalidVTableId(usize),
340340
CoerceUnsizedError(Ty),
341341
LangItemNotFound(LangItem),
342-
BrokenLayout(Layout),
342+
BrokenLayout(Box<Layout>),
343343
}
344344

345345
impl MirEvalError {
@@ -408,7 +408,7 @@ impl MirEvalError {
408408
err.pretty_print(f, db, span_formatter)?;
409409
}
410410
MirEvalError::ConstEvalError(name, err) => {
411-
MirLowerError::ConstEvalError(name.clone(), err.clone()).pretty_print(
411+
MirLowerError::ConstEvalError((**name).into(), err.clone()).pretty_print(
412412
f,
413413
db,
414414
span_formatter,
@@ -1632,15 +1632,15 @@ impl Evaluator<'_> {
16321632
if let Some((offset, size, value)) = tag {
16331633
match result.get_mut(offset..offset + size) {
16341634
Some(it) => it.copy_from_slice(&value.to_le_bytes()[0..size]),
1635-
None => return Err(MirEvalError::BrokenLayout(variant_layout.clone())),
1635+
None => return Err(MirEvalError::BrokenLayout(Box::new(variant_layout.clone()))),
16361636
}
16371637
}
16381638
for (i, op) in values.enumerate() {
16391639
let offset = variant_layout.fields.offset(i).bytes_usize();
16401640
let op = op.get(&self)?;
16411641
match result.get_mut(offset..offset + op.len()) {
16421642
Some(it) => it.copy_from_slice(op),
1643-
None => return Err(MirEvalError::BrokenLayout(variant_layout.clone())),
1643+
None => return Err(MirEvalError::BrokenLayout(Box::new(variant_layout.clone()))),
16441644
}
16451645
}
16461646
Ok(result)

crates/hir-ty/src/mir/lower.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ struct MirLowerCtx<'a> {
7171

7272
#[derive(Debug, Clone, PartialEq, Eq)]
7373
pub enum MirLowerError {
74-
ConstEvalError(String, Box<ConstEvalError>),
74+
ConstEvalError(Box<str>, Box<ConstEvalError>),
7575
LayoutError(LayoutError),
7676
IncompleteExpr,
7777
IncompletePattern,
@@ -84,7 +84,7 @@ pub enum MirLowerError {
8484
UnsizedTemporary(Ty),
8585
MissingFunctionDefinition(DefWithBodyId, ExprId),
8686
TypeMismatch(TypeMismatch),
87-
/// This should be never happen. Type mismatch should catch everything.
87+
/// This should never happen. Type mismatch should catch everything.
8888
TypeError(&'static str),
8989
NotSupported(String),
9090
ContinueWithoutLoop,
@@ -1456,7 +1456,7 @@ impl<'ctx> MirLowerCtx<'ctx> {
14561456
let name = const_id.name(self.db.upcast());
14571457
self.db
14581458
.const_eval(const_id.into(), subst, None)
1459-
.map_err(|e| MirLowerError::ConstEvalError(name, Box::new(e)))?
1459+
.map_err(|e| MirLowerError::ConstEvalError(name.into(), Box::new(e)))?
14601460
};
14611461
Ok(Operand::Constant(c))
14621462
}
@@ -1853,7 +1853,7 @@ impl<'ctx> MirLowerCtx<'ctx> {
18531853
data.name.display(self.db.upcast()),
18541854
data.variants[variant.local_id].name.display(self.db.upcast())
18551855
);
1856-
Err(MirLowerError::ConstEvalError(name, Box::new(e)))
1856+
Err(MirLowerError::ConstEvalError(name.into(), Box::new(e)))
18571857
}
18581858
}
18591859
}

crates/ide/src/status.rs

+1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ pub(crate) fn status(db: &RootDatabase, file_id: Option<FileId>) -> String {
6666
None => format!("{}", krate.into_raw()),
6767
};
6868
format_to!(buf, "Crate: {}\n", display_crate(krate));
69+
format_to!(buf, "Enabled cfgs: {:?}\n", crate_graph[krate].cfg_options);
6970
let deps = crate_graph[krate]
7071
.dependencies
7172
.iter()

0 commit comments

Comments
 (0)