Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb56dc8e

Browse files
committed
Use verbose style when suggesting changingconst withlet
1 parentbcf1f6d commitb56dc8e

File tree

20 files changed

+153
-82
lines changed

20 files changed

+153
-82
lines changed

‎compiler/rustc_parse/src/parser/item.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -810,7 +810,7 @@ impl<'a> Parser<'a> {
810810
self.dcx().struct_span_err(non_item_span,"non-item in item list");
811811
self.consume_block(Delimiter::Brace,ConsumeClosingDelim::Yes);
812812
if is_let{
813-
err.span_suggestion(
813+
err.span_suggestion_verbose(
814814
non_item_span,
815815
"consider using `const` instead of `let` for associated const",
816816
"const",

‎compiler/rustc_resolve/src/diagnostics.rs‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -836,11 +836,12 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
836836

837837
let((with, with_label), without) =match sp{
838838
Some(sp)if !self.tcx.sess.source_map().is_multiline(sp) =>{
839-
let sp = sp.with_lo(BytePos(sp.lo().0 -(current.len()asu32)));
839+
let sp = sp
840+
.with_lo(BytePos(sp.lo().0 -(current.len()asu32)))
841+
.until(ident.span);
840842
(
841843
(Some(errs::AttemptToUseNonConstantValueInConstantWithSuggestion{
842844
span: sp,
843-
ident,
844845
suggestion,
845846
current,
846847
}),Some(errs::AttemptToUseNonConstantValueInConstantLabelWithSuggestion{span})),

‎compiler/rustc_resolve/src/errors.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,13 +242,13 @@ pub(crate) struct AttemptToUseNonConstantValueInConstant<'a> {
242242
#[derive(Subdiagnostic)]
243243
#[suggestion(
244244
resolve_attempt_to_use_non_constant_value_in_constant_with_suggestion,
245-
code ="{suggestion} {ident}",
245+
code ="{suggestion} ",
246+
style ="verbose",
246247
applicability ="maybe-incorrect"
247248
)]
248249
pub(crate)structAttemptToUseNonConstantValueInConstantWithSuggestion<'a>{
249250
#[primary_span]
250251
pub(crate)span:Span,
251-
pub(crate)ident:Ident,
252252
pub(crate)suggestion:&'astr,
253253
pub(crate)current:&'astr,
254254
}

‎tests/ui/asm/parse-error.stderr‎

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -371,47 +371,57 @@ LL | global_asm!("{}", label {});
371371
error[E0435]: attempt to use a non-constant value in a constant
372372
--> $DIR/parse-error.rs:39:37
373373
|
374-
LL | let mut foo = 0;
375-
| ----------- help: consider using `const` instead of `let`: `const foo`
376-
...
377374
LL | asm!("{}", options(), const foo);
378375
| ^^^ non-constant value
376+
|
377+
help: consider using `const` instead of `let`
378+
|
379+
LL | const foo = 0;
380+
| ~~~~~
379381

380382
error[E0435]: attempt to use a non-constant value in a constant
381383
--> $DIR/parse-error.rs:71:44
382384
|
383-
LL | let mut foo = 0;
384-
| ----------- help: consider using `const` instead of `let`: `const foo`
385-
...
386385
LL | asm!("{}", clobber_abi("C"), const foo);
387386
| ^^^ non-constant value
387+
|
388+
help: consider using `const` instead of `let`
389+
|
390+
LL | const foo = 0;
391+
| ~~~~~
388392

389393
error[E0435]: attempt to use a non-constant value in a constant
390394
--> $DIR/parse-error.rs:74:55
391395
|
392-
LL | let mut foo = 0;
393-
| ----------- help: consider using `const` instead of `let`: `const foo`
394-
...
395396
LL | asm!("{}", options(), clobber_abi("C"), const foo);
396397
| ^^^ non-constant value
398+
|
399+
help: consider using `const` instead of `let`
400+
|
401+
LL | const foo = 0;
402+
| ~~~~~
397403

398404
error[E0435]: attempt to use a non-constant value in a constant
399405
--> $DIR/parse-error.rs:76:31
400406
|
401-
LL | let mut foo = 0;
402-
| ----------- help: consider using `const` instead of `let`: `const foo`
403-
...
404407
LL | asm!("{a}", a = const foo, a = const bar);
405408
| ^^^ non-constant value
409+
|
410+
help: consider using `const` instead of `let`
411+
|
412+
LL | const foo = 0;
413+
| ~~~~~
406414

407415
error[E0435]: attempt to use a non-constant value in a constant
408416
--> $DIR/parse-error.rs:76:46
409417
|
410-
LL | let mut bar = 0;
411-
| ----------- help: consider using `const` instead of `let`: `const bar`
412-
...
413418
LL | asm!("{a}", a = const foo, a = const bar);
414419
| ^^^ non-constant value
420+
|
421+
help: consider using `const` instead of `let`
422+
|
423+
LL | const bar = 0;
424+
| ~~~~~
415425

416426
error: aborting due to 64 previous errors
417427

‎tests/ui/asm/type-check-1.stderr‎

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,35 @@
11
error[E0435]: attempt to use a non-constant value in a constant
22
--> $DIR/type-check-1.rs:41:26
33
|
4-
LL | let x = 0;
5-
| ----- help: consider using `const` instead of `let`: `const x`
6-
...
74
LL | asm!("{}", const x);
85
| ^ non-constant value
6+
|
7+
help: consider using `const` instead of `let`
8+
|
9+
LL | const x = 0;
10+
| ~~~~~
911

1012
error[E0435]: attempt to use a non-constant value in a constant
1113
--> $DIR/type-check-1.rs:44:36
1214
|
13-
LL | let x = 0;
14-
| ----- help: consider using `const` instead of `let`: `const x`
15-
...
1615
LL | asm!("{}", const const_foo(x));
1716
| ^ non-constant value
17+
|
18+
help: consider using `const` instead of `let`
19+
|
20+
LL | const x = 0;
21+
| ~~~~~
1822

1923
error[E0435]: attempt to use a non-constant value in a constant
2024
--> $DIR/type-check-1.rs:47:36
2125
|
22-
LL | let x = 0;
23-
| ----- help: consider using `const` instead of `let`: `const x`
24-
...
2526
LL | asm!("{}", const const_bar(x));
2627
| ^ non-constant value
28+
|
29+
help: consider using `const` instead of `let`
30+
|
31+
LL | const x = 0;
32+
| ~~~~~
2733

2834
error: invalid `sym` operand
2935
--> $DIR/type-check-1.rs:49:24

‎tests/ui/asm/x86_64/x86_64_parse_error.stderr‎

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,35 @@ LL | asm!("{1}", in("eax") foo, const bar);
1515
error[E0435]: attempt to use a non-constant value in a constant
1616
--> $DIR/x86_64_parse_error.rs:13:46
1717
|
18-
LL | let mut bar = 0;
19-
| ----------- help: consider using `const` instead of `let`: `const bar`
20-
...
2118
LL | asm!("{a}", in("eax") foo, a = const bar);
2219
| ^^^ non-constant value
20+
|
21+
help: consider using `const` instead of `let`
22+
|
23+
LL | const bar = 0;
24+
| ~~~~~
2325

2426
error[E0435]: attempt to use a non-constant value in a constant
2527
--> $DIR/x86_64_parse_error.rs:15:46
2628
|
27-
LL | let mut bar = 0;
28-
| ----------- help: consider using `const` instead of `let`: `const bar`
29-
...
3029
LL | asm!("{a}", in("eax") foo, a = const bar);
3130
| ^^^ non-constant value
31+
|
32+
help: consider using `const` instead of `let`
33+
|
34+
LL | const bar = 0;
35+
| ~~~~~
3236

3337
error[E0435]: attempt to use a non-constant value in a constant
3438
--> $DIR/x86_64_parse_error.rs:17:42
3539
|
36-
LL | let mut bar = 0;
37-
| ----------- help: consider using `const` instead of `let`: `const bar`
38-
...
3940
LL | asm!("{1}", in("eax") foo, const bar);
4041
| ^^^ non-constant value
42+
|
43+
help: consider using `const` instead of `let`
44+
|
45+
LL | const bar = 0;
46+
| ~~~~~
4147

4248
error: aborting due to 5 previous errors
4349

‎tests/ui/const-generics/legacy-const-generics-bad.stderr‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
error[E0435]: attempt to use a non-constant value in a constant
22
--> $DIR/legacy-const-generics-bad.rs:7:35
33
|
4-
LL | let a = 1;
5-
| ----- help: consider using `const` instead of `let`: `const a`
64
LL | legacy_const_generics::foo(0, a, 2);
75
| ^ non-constant value
6+
|
7+
help: consider using `const` instead of `let`
8+
|
9+
LL | const a = 1;
10+
| ~~~~~
811

912
error: generic parameters may not be used in const operations
1013
--> $DIR/legacy-const-generics-bad.rs:12:35

‎tests/ui/consts/issue-3521.stderr‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
error[E0435]: attempt to use a non-constant value in a constant
22
--> $DIR/issue-3521.rs:8:15
33
|
4-
LL | let foo: isize = 100;
5-
| ------- help: consider using `const` instead of `let`: `const foo`
6-
...
74
LL | Bar = foo
85
| ^^^ non-constant value
6+
|
7+
help: consider using `const` instead of `let`
8+
|
9+
LL | const foo: isize = 100;
10+
| ~~~~~
911

1012
error: aborting due to 1 previous error
1113

‎tests/ui/consts/issue-91560.stderr‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
error[E0435]: attempt to use a non-constant value in a constant
22
--> $DIR/issue-91560.rs:10:19
33
|
4-
LL | let mut length: usize = 2;
5-
| -------------- help: consider using `const` instead of `let`: `const length`
6-
LL |
74
LL | let arr = [0; length];
85
| ^^^^^^ non-constant value
6+
|
7+
help: consider using `const` instead of `let`
8+
|
9+
LL | const length: usize = 2;
10+
| ~~~~~
911

1012
error[E0435]: attempt to use a non-constant value in a constant
1113
--> $DIR/issue-91560.rs:17:19
1214
|
13-
LL | let length: usize = 2;
14-
| ------------ help: consider using `const` instead of `let`: `const length`
15-
LL |
1615
LL | let arr = [0; length];
1716
| ^^^^^^ non-constant value
17+
|
18+
help: consider using `const` instead of `let`
19+
|
20+
LL | const length: usize = 2;
21+
| ~~~~~
1822

1923
error: aborting due to 2 previous errors
2024

‎tests/ui/consts/non-const-value-in-const.stderr‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,23 @@ error[E0435]: attempt to use a non-constant value in a constant
22
--> $DIR/non-const-value-in-const.rs:3:20
33
|
44
LL | const Y: i32 = x;
5-
| ------- ^ non-constant value
6-
| |
7-
| help: consider using `let` instead of `const`: `let Y`
5+
| ^ non-constant value
6+
|
7+
help: consider using `let` instead of `const`
8+
|
9+
LL | let Y: i32 = x;
10+
| ~~~
811

912
error[E0435]: attempt to use a non-constant value in a constant
1013
--> $DIR/non-const-value-in-const.rs:6:17
1114
|
12-
LL | let x = 5;
13-
| ----- help: consider using `const` instead of `let`: `const x`
14-
...
1515
LL | let _ = [0; x];
1616
| ^ non-constant value
17+
|
18+
help: consider using `const` instead of `let`
19+
|
20+
LL | const x = 5;
21+
| ~~~~~
1722

1823
error: aborting due to 2 previous errors
1924

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp