Make array suggestions slightly more accurate
This commit is contained in:
parent
8a981b6fee
commit
c95761385e
2 changed files with 12 additions and 5 deletions
|
@ -4550,7 +4550,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||||
self.type_implements_trait(default_trait, [ty], param_env).must_apply_modulo_regions()
|
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::Never | ty::Error(_) => return None,
|
||||||
ty::Bool => "false".to_string(),
|
ty::Bool => "false".to_string(),
|
||||||
ty::Char => "\'x\'".to_string(),
|
ty::Char => "\'x\'".to_string(),
|
||||||
|
@ -4577,12 +4577,19 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||||
if let (ty::Str, hir::Mutability::Not) = (ty.kind(), mutability) {
|
if let (ty::Str, hir::Mutability::Not) = (ty.kind(), mutability) {
|
||||||
"\"\"".to_string()
|
"\"\"".to_string()
|
||||||
} else {
|
} else {
|
||||||
let ty = self.ty_kind_suggestion(param_env, *ty)?;
|
let ty = self.ty_kind_suggestion(param_env, ty)?;
|
||||||
format!("&{}{ty}", mutability.prefix_str())
|
format!("&{}{ty}", mutability.prefix_str())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ty::Array(ty, len) if let Some(len) = len.try_eval_target_usize(tcx, param_env) => {
|
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!(
|
ty::Tuple(tys) => format!(
|
||||||
"({}{})",
|
"({}{})",
|
||||||
|
|
|
@ -8,8 +8,8 @@ LL | a[i] = d();
|
||||||
|
|
|
|
||||||
help: consider assigning a value
|
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
|
error: aborting due to 1 previous error
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue