Skip to content

Commit 4764dce

Browse files
Rollup merge of #124000 - compiler-errors:sugg-tweaks, r=wesleywiser
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.
2 parents ec1618c + c957613 commit 4764dce

11 files changed

+41
-34
lines changed

compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

+11-4
Original file line numberDiff line numberDiff line change
@@ -4545,7 +4545,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
45454545
self.type_implements_trait(default_trait, [ty], param_env).must_apply_modulo_regions()
45464546
};
45474547

4548-
Some(match ty.kind() {
4548+
Some(match *ty.kind() {
45494549
ty::Never | ty::Error(_) => return None,
45504550
ty::Bool => "false".to_string(),
45514551
ty::Char => "\'x\'".to_string(),
@@ -4572,12 +4572,19 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
45724572
if let (ty::Str, hir::Mutability::Not) = (ty.kind(), mutability) {
45734573
"\"\"".to_string()
45744574
} else {
4575-
let ty = self.ty_kind_suggestion(param_env, *ty)?;
4575+
let ty = self.ty_kind_suggestion(param_env, ty)?;
45764576
format!("&{}{ty}", mutability.prefix_str())
45774577
}
45784578
}
45794579
ty::Array(ty, len) if let Some(len) = len.try_eval_target_usize(tcx, param_env) => {
4580-
format!("[{}; {}]", self.ty_kind_suggestion(param_env, *ty)?, len)
4580+
if len == 0 {
4581+
"[]".to_string()
4582+
} else if self.type_is_copy_modulo_regions(param_env, ty) || len == 1 {
4583+
// Can only suggest `[ty; 0]` if sz == 1 or copy
4584+
format!("[{}; {}]", self.ty_kind_suggestion(param_env, ty)?, len)
4585+
} else {
4586+
"/* value */".to_string()
4587+
}
45814588
}
45824589
ty::Tuple(tys) => format!(
45834590
"({}{})",
@@ -4587,7 +4594,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
45874594
.join(", "),
45884595
if tys.len() == 1 { "," } else { "" }
45894596
),
4590-
_ => "value".to_string(),
4597+
_ => "/* value */".to_string(),
45914598
})
45924599
}
45934600
}

tests/ui/borrowck/borrowck-init-in-fru.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ LL | origin = Point { x: 10, ..origin };
88
|
99
help: consider assigning a value
1010
|
11-
LL | let mut origin: Point = value;
12-
| +++++++
11+
LL | let mut origin: Point = /* value */;
12+
| +++++++++++++
1313

1414
error: aborting due to 1 previous error
1515

tests/ui/borrowck/borrowck-uninit-ref-chain.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ LL | let _y = &**x;
2121
|
2222
help: consider assigning a value
2323
|
24-
LL | let x: &&S<i32, i32> = &&value;
25-
| +++++++++
24+
LL | let x: &&S<i32, i32> = &&/* value */;
25+
| +++++++++++++++
2626

2727
error[E0381]: used binding `x` isn't initialized
2828
--> $DIR/borrowck-uninit-ref-chain.rs:14:14

tests/ui/borrowck/issue-103250.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ LL | Err(last_error)
99
|
1010
help: consider assigning a value
1111
|
12-
LL | let mut last_error: Box<dyn std::error::Error> = Box::new(value);
13-
| +++++++++++++++++
12+
LL | let mut last_error: Box<dyn std::error::Error> = Box::new(/* value */);
13+
| +++++++++++++++++++++++
1414

1515
error: aborting due to 1 previous error
1616

tests/ui/borrowck/suggest-assign-rvalue.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ LL | println!("demo_no: {:?}", demo_no);
5050
= 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)
5151
help: consider assigning a value
5252
|
53-
LL | let demo_no: DemoNoDef = value;
54-
| +++++++
53+
LL | let demo_no: DemoNoDef = /* value */;
54+
| +++++++++++++
5555

5656
error[E0381]: used binding `arr` isn't initialized
5757
--> $DIR/suggest-assign-rvalue.rs:34:27

tests/ui/consts/value-suggestion-ice-123906.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ LL | break;
1010
|
1111
help: give the `break` a value of the expected type
1212
|
13-
LL | break value;
14-
| +++++
13+
LL | break /* value */;
14+
| +++++++++++
1515

1616
error: aborting due to 1 previous error
1717

tests/ui/loops/loop-break-value.stderr

+10-10
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,8 @@ LL | break;
246246
|
247247
help: give the `break` a value of the expected type
248248
|
249-
LL | break value;
250-
| +++++
249+
LL | break /* value */;
250+
| +++++++++++
251251

252252
error[E0308]: mismatched types
253253
--> $DIR/loop-break-value.rs:112:9
@@ -260,8 +260,8 @@ LL | break;
260260
|
261261
help: give the `break` a value of the expected type
262262
|
263-
LL | break value;
264-
| +++++
263+
LL | break /* value */;
264+
| +++++++++++
265265

266266
error[E0308]: mismatched types
267267
--> $DIR/loop-break-value.rs:124:9
@@ -274,8 +274,8 @@ LL | break 'a;
274274
|
275275
help: give the `break` a value of the expected type
276276
|
277-
LL | break 'a value;
278-
| +++++
277+
LL | break 'a /* value */;
278+
| +++++++++++
279279

280280
error[E0308]: mismatched types
281281
--> $DIR/loop-break-value.rs:135:15
@@ -297,8 +297,8 @@ LL | break 'a;
297297
|
298298
help: give the `break` a value of the expected type
299299
|
300-
LL | break 'a value;
301-
| +++++
300+
LL | break 'a /* value */;
301+
| +++++++++++
302302

303303
error[E0308]: mismatched types
304304
--> $DIR/loop-break-value.rs:147:15
@@ -320,8 +320,8 @@ LL | break 'a;
320320
|
321321
help: give the `break` a value of the expected type
322322
|
323-
LL | break 'a value;
324-
| +++++
323+
LL | break 'a /* value */;
324+
| +++++++++++
325325

326326
error[E0308]: mismatched types
327327
--> $DIR/loop-break-value.rs:159:15

tests/ui/moves/issue-72649-uninit-in-loop.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ LL | let _used = value;
8080
|
8181
help: consider assigning a value
8282
|
83-
LL | let value: NonCopy = value;
84-
| +++++++
83+
LL | let value: NonCopy = /* value */;
84+
| +++++++++++++
8585

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

100100
error: aborting due to 6 previous errors
101101

tests/ui/moves/move-into-dead-array-1.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ LL | a[i] = d();
88
|
99
help: consider assigning a value
1010
|
11-
LL | let mut a: [D; 4] = [value; 4];
12-
| ++++++++++++
11+
LL | let mut a: [D; 4] = /* value */;
12+
| +++++++++++++
1313

1414
error: aborting due to 1 previous error
1515

tests/ui/moves/move-of-addr-of-mut.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ LL | std::ptr::addr_of_mut!(x);
99
= note: this error originates in the macro `std::ptr::addr_of_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
1010
help: consider assigning a value
1111
|
12-
LL | let mut x: S = value;
13-
| +++++++
12+
LL | let mut x: S = /* value */;
13+
| +++++++++++++
1414

1515
error: aborting due to 1 previous error
1616

tests/ui/nll/match-on-borrowed.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ LL | match n {}
4343
|
4444
help: consider assigning a value
4545
|
46-
LL | let n: Never = value;
47-
| +++++++
46+
LL | let n: Never = /* value */;
47+
| +++++++++++++
4848

4949
error: aborting due to 4 previous errors
5050

0 commit comments

Comments
 (0)