Skip to content

Commit

Permalink
Rollup merge of #124000 - compiler-errors:sugg-tweaks, r=wesleywiser
Browse files Browse the repository at this point in the history
Use `/* value */` as a placeholder

The expression `value` isn't a valid suggestion; let's use `/* value */` as a placeholder (which is also invalid) since it more clearly signals to the user that they need to fill it in with something meaningful. This parallels the suggestions we have in a couple other places, like arguments.

We could also print the type name instead of `/* value */`, especially if it's suggestable, but I don't care strongly about that.
  • Loading branch information
GuillaumeGomez authored Apr 16, 2024
2 parents ec1618c + c957613 commit 4764dce
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4545,7 +4545,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 @@ -4572,12 +4572,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 All @@ -4587,7 +4594,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
.join(", "),
if tys.len() == 1 { "," } else { "" }
),
_ => "value".to_string(),
_ => "/* value */".to_string(),
})
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/borrowck/borrowck-init-in-fru.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ LL | origin = Point { x: 10, ..origin };
|
help: consider assigning a value
|
LL | let mut origin: Point = value;
| +++++++
LL | let mut origin: Point = /* value */;
| +++++++++++++

error: aborting due to 1 previous error

Expand Down
4 changes: 2 additions & 2 deletions tests/ui/borrowck/borrowck-uninit-ref-chain.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ LL | let _y = &**x;
|
help: consider assigning a value
|
LL | let x: &&S<i32, i32> = &&value;
| +++++++++
LL | let x: &&S<i32, i32> = &&/* value */;
| +++++++++++++++

error[E0381]: used binding `x` isn't initialized
--> $DIR/borrowck-uninit-ref-chain.rs:14:14
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/borrowck/issue-103250.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ LL | Err(last_error)
|
help: consider assigning a value
|
LL | let mut last_error: Box<dyn std::error::Error> = Box::new(value);
| +++++++++++++++++
LL | let mut last_error: Box<dyn std::error::Error> = Box::new(/* value */);
| +++++++++++++++++++++++

error: aborting due to 1 previous error

Expand Down
4 changes: 2 additions & 2 deletions tests/ui/borrowck/suggest-assign-rvalue.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ LL | println!("demo_no: {:?}", demo_no);
= note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider assigning a value
|
LL | let demo_no: DemoNoDef = value;
| +++++++
LL | let demo_no: DemoNoDef = /* value */;
| +++++++++++++

error[E0381]: used binding `arr` isn't initialized
--> $DIR/suggest-assign-rvalue.rs:34:27
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/consts/value-suggestion-ice-123906.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ LL | break;
|
help: give the `break` a value of the expected type
|
LL | break value;
| +++++
LL | break /* value */;
| +++++++++++

error: aborting due to 1 previous error

Expand Down
20 changes: 10 additions & 10 deletions tests/ui/loops/loop-break-value.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,8 @@ LL | break;
|
help: give the `break` a value of the expected type
|
LL | break value;
| +++++
LL | break /* value */;
| +++++++++++

error[E0308]: mismatched types
--> $DIR/loop-break-value.rs:112:9
Expand All @@ -260,8 +260,8 @@ LL | break;
|
help: give the `break` a value of the expected type
|
LL | break value;
| +++++
LL | break /* value */;
| +++++++++++

error[E0308]: mismatched types
--> $DIR/loop-break-value.rs:124:9
Expand All @@ -274,8 +274,8 @@ LL | break 'a;
|
help: give the `break` a value of the expected type
|
LL | break 'a value;
| +++++
LL | break 'a /* value */;
| +++++++++++

error[E0308]: mismatched types
--> $DIR/loop-break-value.rs:135:15
Expand All @@ -297,8 +297,8 @@ LL | break 'a;
|
help: give the `break` a value of the expected type
|
LL | break 'a value;
| +++++
LL | break 'a /* value */;
| +++++++++++

error[E0308]: mismatched types
--> $DIR/loop-break-value.rs:147:15
Expand All @@ -320,8 +320,8 @@ LL | break 'a;
|
help: give the `break` a value of the expected type
|
LL | break 'a value;
| +++++
LL | break 'a /* value */;
| +++++++++++

error[E0308]: mismatched types
--> $DIR/loop-break-value.rs:159:15
Expand Down
8 changes: 4 additions & 4 deletions tests/ui/moves/issue-72649-uninit-in-loop.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ LL | let _used = value;
|
help: consider assigning a value
|
LL | let value: NonCopy = value;
| +++++++
LL | let value: NonCopy = /* value */;
| +++++++++++++

error[E0381]: used binding `value` isn't initialized
--> $DIR/issue-72649-uninit-in-loop.rs:73:21
Expand All @@ -94,8 +94,8 @@ LL | let _used = value;
|
help: consider assigning a value
|
LL | let mut value: NonCopy = value;
| +++++++
LL | let mut value: NonCopy = /* value */;
| +++++++++++++

error: aborting due to 6 previous errors

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
4 changes: 2 additions & 2 deletions tests/ui/moves/move-of-addr-of-mut.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ LL | std::ptr::addr_of_mut!(x);
= note: this error originates in the macro `std::ptr::addr_of_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider assigning a value
|
LL | let mut x: S = value;
| +++++++
LL | let mut x: S = /* value */;
| +++++++++++++

error: aborting due to 1 previous error

Expand Down
4 changes: 2 additions & 2 deletions tests/ui/nll/match-on-borrowed.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ LL | match n {}
|
help: consider assigning a value
|
LL | let n: Never = value;
| +++++++
LL | let n: Never = /* value */;
| +++++++++++++

error: aborting due to 4 previous errors

Expand Down

0 comments on commit 4764dce

Please sign in to comment.