Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 5df1123

Browse files
authoredSep 30, 2024
Rollup merge of #131038 - onkoe:fix/adt_const_params_leak_118179, r=compiler-errors
Fix `adt_const_params` leaking `{type error}` in error msg Fixes the confusing diagnostic described in #118179. (users would see `{type error}` in some situations, which is pretty weird) `adt_const_params` tracking issue: #95174
2 parents dc1ccc5 + c5598d6 commit 5df1123

File tree

68 files changed

+147
-324
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+147
-324
lines changed
 

‎compiler/rustc_hir_analysis/src/check/wfcheck.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -961,13 +961,20 @@ fn check_param_wf(tcx: TyCtxt<'_>, param: &hir::GenericParam<'_>) -> Result<(),
961961
hir_ty.span,
962962
"using raw pointers as const generic parameters is forbidden",
963963
),
964-
_ => tcx.dcx().struct_span_err(
965-
hir_ty.span,
966-
format!("`{}` is forbidden as the type of a const generic parameter", ty),
967-
),
964+
_ => {
965+
// Avoid showing "{type error}" to users. See #118179.
966+
ty.error_reported()?;
967+
968+
tcx.dcx().struct_span_err(
969+
hir_ty.span,
970+
format!(
971+
"`{ty}` is forbidden as the type of a const generic parameter",
972+
),
973+
)
974+
}
968975
};
969976

970-
diag.note("the only supported types are integers, `bool` and `char`");
977+
diag.note("the only supported types are integers, `bool`, and `char`");
971978

972979
let cause = ObligationCause::misc(hir_ty.span, param.def_id);
973980
let adt_const_params_feature_string =

‎tests/ui/const-generics/adt_const_params/suggest_feature_only_when_possible.stderr

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ error: `&'static mut ()` is forbidden as the type of a const generic parameter
44
LL | fn uwu_0<const N: &'static mut ()>() {}
55
| ^^^^^^^^^^^^^^^
66
|
7-
= note: the only supported types are integers, `bool` and `char`
7+
= note: the only supported types are integers, `bool`, and `char`
88

99
error: `&'static u32` is forbidden as the type of a const generic parameter
1010
--> $DIR/suggest_feature_only_when_possible.rs:15:19
1111
|
1212
LL | fn owo_0<const N: &'static u32>() {}
1313
| ^^^^^^^^^^^^
1414
|
15-
= note: the only supported types are integers, `bool` and `char`
15+
= note: the only supported types are integers, `bool`, and `char`
1616
help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types
1717
|
1818
LL + #![feature(adt_const_params)]
@@ -28,7 +28,7 @@ error: `Meow` is forbidden as the type of a const generic parameter
2828
LL | fn meow_0<const N: Meow>() {}
2929
| ^^^^
3030
|
31-
= note: the only supported types are integers, `bool` and `char`
31+
= note: the only supported types are integers, `bool`, and `char`
3232
help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types
3333
|
3434
LL + #![feature(adt_const_params)]
@@ -40,7 +40,7 @@ error: `&'static Meow` is forbidden as the type of a const generic parameter
4040
LL | fn meow_1<const N: &'static Meow>() {}
4141
| ^^^^^^^^^^^^^
4242
|
43-
= note: the only supported types are integers, `bool` and `char`
43+
= note: the only supported types are integers, `bool`, and `char`
4444
help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types
4545
|
4646
LL + #![feature(adt_const_params)]
@@ -56,39 +56,39 @@ error: `[Meow; 100]` is forbidden as the type of a const generic parameter
5656
LL | fn meow_2<const N: [Meow; 100]>() {}
5757
| ^^^^^^^^^^^
5858
|
59-
= note: the only supported types are integers, `bool` and `char`
59+
= note: the only supported types are integers, `bool`, and `char`
6060

6161
error: `(Meow, u8)` is forbidden as the type of a const generic parameter
6262
--> $DIR/suggest_feature_only_when_possible.rs:29:20
6363
|
6464
LL | fn meow_3<const N: (Meow, u8)>() {}
6565
| ^^^^^^^^^^
6666
|
67-
= note: the only supported types are integers, `bool` and `char`
67+
= note: the only supported types are integers, `bool`, and `char`
6868

6969
error: `(Meow, String)` is forbidden as the type of a const generic parameter
7070
--> $DIR/suggest_feature_only_when_possible.rs:34:20
7171
|
7272
LL | fn meow_4<const N: (Meow, String)>() {}
7373
| ^^^^^^^^^^^^^^
7474
|
75-
= note: the only supported types are integers, `bool` and `char`
75+
= note: the only supported types are integers, `bool`, and `char`
7676

7777
error: `String` is forbidden as the type of a const generic parameter
7878
--> $DIR/suggest_feature_only_when_possible.rs:38:19
7979
|
8080
LL | fn nya_0<const N: String>() {}
8181
| ^^^^^^
8282
|
83-
= note: the only supported types are integers, `bool` and `char`
83+
= note: the only supported types are integers, `bool`, and `char`
8484

8585
error: `Vec<u32>` is forbidden as the type of a const generic parameter
8686
--> $DIR/suggest_feature_only_when_possible.rs:40:19
8787
|
8888
LL | fn nya_1<const N: Vec<u32>>() {}
8989
| ^^^^^^^^
9090
|
91-
= note: the only supported types are integers, `bool` and `char`
91+
= note: the only supported types are integers, `bool`, and `char`
9292

9393
error: aborting due to 9 previous errors
9494

0 commit comments

Comments
 (0)
Please sign in to comment.