Conversation
estebank
commented
Sep 19, 2026
- Don't suggest braces unnecessarily for numeric literals
- Use verbose suggestion
- Tweak messages
|
HIR ty lowering was modified cc @fmease |
|
r? @adwinwhite rustbot has assigned @adwinwhite. Use Why was this reviewer chosen?The reviewer was selected based on:
|
| let sugg = if let hir::ConstArgKind::Anon(hir::AnonConst { body, .. }) = len.kind | ||
| && let hir::ExprKind::Lit(..) = tcx.hir_body(*body).value.kind |
There was a problem hiding this comment.
I'm not really up to speed with (m)GCA. Does this check fail if feature min_generic_const_args / generic_const_args is enabled since the length is no longer an AnonConst but a direct ConstArgKind::Lit?
If so, we might want to account for that, too. Of course, not high priority so feel free to ignore.
There was a problem hiding this comment.
Added revisions for all three cases, as well as the additional check, but the check doesn't trigger today (yet?).
| GenericParamDefKind::Const { .. }, | ||
| ) if tcx.type_of(param.def_id).skip_binder() == tcx.types.usize => { | ||
| err.span_label(arg.span(), "array type provided where a `usize` was expected"); | ||
| let snippet = sess.source_map().span_to_snippet(tcx.hir_span(len.hir_id)); |
There was a problem hiding this comment.
(preexisting) It should be possible to eliminate the use of span_to_snippet by using a multi-part suggestion, Span::{until,to,between,…} and the span of the entire HIR type above. 🤷 Feel free to ignore
There was a problem hiding this comment.
I'm just concerned about spans through multiple macro scopes.
56a01b2 to
f14d55b
Compare
- Don't suggest braces unnecessarily for numeric literals - Use verbose suggestion - Tweak messages ``` error[E0747]: type provided when a constant was expected --> $DIR/suggest_const_for_array.rs:6:15 | LL | example::<[usize; 3]>(); | ^^^^^^^^^^ array type provided where a `usize` was expected | help: you might have meant to use the array's length's value | LL - example::<[usize; 3]>(); LL + example::<3>(); | ```
f14d55b to
5f33ac3
Compare
|
@bors r=fmease |
…anted, r=fmease Tweak "use array's length as const param" suggestion - Don't suggest braces unnecessarily for numeric literals - Use verbose suggestion - Tweak messages ``` error[E0747]: type provided when a constant was expected --> $DIR/suggest_const_for_array.rs:6:15 | LL | example::<[usize; 3]>(); | ^^^^^^^^^^ array type provided where a `usize` was expected | help: you might have meant to use the array's length's value | LL - example::<[usize; 3]>(); LL + example::<3>(); | ```
…anted, r=fmease Tweak "use array's length as const param" suggestion - Don't suggest braces unnecessarily for numeric literals - Use verbose suggestion - Tweak messages ``` error[E0747]: type provided when a constant was expected --> $DIR/suggest_const_for_array.rs:6:15 | LL | example::<[usize; 3]>(); | ^^^^^^^^^^ array type provided where a `usize` was expected | help: you might have meant to use the array's length's value | LL - example::<[usize; 3]>(); LL + example::<3>(); | ```
…uwer Rollup of 15 pull requests Successful merges: - #162726 (std: fix unix socket address panic on a full sun_path) - #163016 (Don't claim that escaping value is a reference in diagnostics) - #163040 (Tweak "use array's length as const param" suggestion) - #163060 (Point to fields that introduce trait requirements) - #163066 (don't mark `f128` as reliable on AIX) - #162098 (Tweak `Infallible` docs) - #162854 (Add safety section for atomic_load/store) - #163015 (add `minicore::ffi::VaList`) - #163021 (`va_arg`: pass in `TyAndLayout`) - #163036 ([rustdoc] Correctly handle `dyn` trait methods linking for jump to def feature) - #163042 (Remove redundant output from suggestion) - #163046 (Use verbose suggestion for `const _`) - #163050 (Use verbose suggestion for similarly named label suggestion) - #163052 (Use verbose suggestion for wrong primitive type names) - #163055 (Use the full path of `bug_impl` to avoid bogus errors in rust-analyzer)