Skip to content

Commit

Permalink
Make array suggestions slightly more accurate
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Apr 16, 2024
1 parent 8a981b6 commit c957613
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4550,7 +4550,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
self.type_implements_trait(default_trait, [ty], param_env).must_apply_modulo_regions()
};

Some(match ty.kind() {
Some(match *ty.kind() {
ty::Never | ty::Error(_) => return None,
ty::Bool => "false".to_string(),
ty::Char => "\'x\'".to_string(),
Expand All @@ -4577,12 +4577,19 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
if let (ty::Str, hir::Mutability::Not) = (ty.kind(), mutability) {
"\"\"".to_string()
} else {
let ty = self.ty_kind_suggestion(param_env, *ty)?;
let ty = self.ty_kind_suggestion(param_env, ty)?;
format!("&{}{ty}", mutability.prefix_str())
}
}
ty::Array(ty, len) if let Some(len) = len.try_eval_target_usize(tcx, param_env) => {
format!("[{}; {}]", self.ty_kind_suggestion(param_env, *ty)?, len)
if len == 0 {
"[]".to_string()
} else if self.type_is_copy_modulo_regions(param_env, ty) || len == 1 {
// Can only suggest `[ty; 0]` if sz == 1 or copy
format!("[{}; {}]", self.ty_kind_suggestion(param_env, ty)?, len)
} else {
"/* value */".to_string()
}
}
ty::Tuple(tys) => format!(
"({}{})",
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/moves/move-into-dead-array-1.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ LL | a[i] = d();
|
help: consider assigning a value
|
LL | let mut a: [D; 4] = [/* value */; 4];
| ++++++++++++++++++
LL | let mut a: [D; 4] = /* value */;
| +++++++++++++

error: aborting due to 1 previous error

Expand Down

0 comments on commit c957613

Please sign in to comment.