Improve generic parameters handling for #[diagnostic::on_const]#158347
Conversation
|
Some changes occurred in compiler/rustc_passes/src/check_attr.rs |
|
r? @TaKO8Ki rustbot has assigned @TaKO8Ki. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
cc @mejrs |
There was a problem hiding this comment.
r? me
This is a first proposal.
Can you explain this in words? We need to stabilize this at some point so we need to have this written down. There are three places that can have generics; the impl header, the trait and the type. And what about blanket impls?
For now it would be best if these rules are explained in the unstable book entry.
I will need some help for displaying the
Zparameter correctly.
The thing is that I don't know myself what I'd expect 😆. I think I don't like _, but is it right to just print Z? Or is there some syntax to indicate that it's a non inferred type? Maybe like <Z>? 🤔 . I'm very open to ideas here. It's also an option to just lint against it and not display it at all.
Lint against it is a good idea, because it's verbose, you're probably not able to display the value for this generic parameter, so explaining why makes sense. Displaying My problem with the lint is that we should emit it from |
|
IMO just printing |
|
By "just printing So the compiler output could be :
or
plus a lint on the diagnostic attribute, highlighting the Z argument, explaining why it cannot be displayed. Without any lints, it could be confusing. |
We have been printing it literally for e.g. diagnostic::on_unimplemented if the generic isn't actually anywhere on the trait. |
c4dba6a to
debf115
Compare
This comment has been minimized.
This comment has been minimized.
|
For now the lint part is under discussion on zulip (see my previous message). |
|
I have thought about it, I am taking a step back, I think we could do :
1 and 2 are technically feasible, but are confusing for the user (he asks to display a generic parameter that is not shown). Lint against it from |
debf115 to
4245bb5
Compare
This comment has been minimized.
This comment has been minimized.
|
In the absence of any convincing option, I think it would be best to just display |
|
We could display |
This comment has been minimized.
This comment has been minimized.
Also the user might write something like #![feature(diagnostic_on_const, const_trait_impl)]
pub struct X<A, B> {
field: (A, B),
}
pub const trait Y<Z> {
fn blah(&self) {}
}
#[diagnostic::on_const(note = "Self = {Self}, Z = {Z}, A = {A}, B = {B}")]
impl<Z, A, B> Y<Z> for X<A, B> {}
const _: () = {
Y::<u8>::blah(&X {
field: (42_u8, "hello"),
});
};where there is a concrete type for |
4245bb5 to
2690be8
Compare
This comment has been minimized.
This comment has been minimized.
|
I am opened to suggestions and willing to help if there is anything else |
There was a problem hiding this comment.
The impl looks good to me, just some things need to be done w/r/t tests
- can you add a test that shows the
OnConstMalformedFormatLiteralslint? - the test is named
report_warning_missing_format_paramaters.rs, can you rename it to something appropriate? (also, notice the typo) - can you add revisions for current and next solver, see https://github.com/rust-lang/rust/blob/main/tests/ui/diagnostic_namespace/do_not_recommend/nested.rs for example
@rustbot author
…_arguments, r=mejrs Improve generic parameters handling for #[diagnostic::on_const] cc rust-lang#155570 This Improves generic parameters handling for #[diagnostic::on_const] This is done by printing generics parameters when these are concrete Adt generics args. A lint is emitted we try to format a generic that is found anywhere. Moreover, generics parameters that are ty infer vars are no longer displayed "as-is", it is not clear and might be confusing, in this specific case the name of the generic parameter will be displayed instead. I will need some help for displaying the `Z`parameter correctly. From what I have understood, it is an `ty::Infer(ty::TyVar(_))` that is not correctly displayed via `self.tcx.short_string()` (in `on_unimplemented_components()`), or even not correctly inferred via `self.infcx.ty_to_string()`. EDIT: general descrition updated
…_arguments, r=mejrs Improve generic parameters handling for #[diagnostic::on_const] cc rust-lang#155570 This Improves generic parameters handling for #[diagnostic::on_const] This is done by printing generics parameters when these are concrete Adt generics args. A lint is emitted we try to format a generic that is found anywhere. Moreover, generics parameters that are ty infer vars are no longer displayed "as-is", it is not clear and might be confusing, in this specific case the name of the generic parameter will be displayed instead. I will need some help for displaying the `Z`parameter correctly. From what I have understood, it is an `ty::Infer(ty::TyVar(_))` that is not correctly displayed via `self.tcx.short_string()` (in `on_unimplemented_components()`), or even not correctly inferred via `self.infcx.ty_to_string()`. EDIT: general descrition updated
…uwer Rollup of 25 pull requests Successful merges: - #158871 (add relnotes for 1.97.0) - #158968 (stdarch subtree update) - #154445 (rustdoc: Represent `--output-format=json` coverage and ir differently) - #156370 (Reject linked dylib EII default overrides) - #157153 (allow `Allocator`s to be used as `#[global_allocator]`s) - #158495 (Rename HAS_CT_PROJECTION to HAS_CONST_ALIAS) - #158617 (allow mGCA const arguments to fall back to anon consts) - #158645 (Fix splat ICEs and ban it in closures) - #158655 (Fix coroutine MIR saved local remapping) - #158666 (Carry the `b_offset` inside `BackendRepr::ScalarPair`) - #158912 (Introduce new bootstrap config section for PGO configuration) - #158920 (Update wasm-component-ld to 0.5.26) - #158926 (wrapping_sh* methods: clarify underspecified reference) - #158927 (add core test run with `-Zforce-intrinsic-fallback`) - #158932 (Do not build the compiler when invoking `x perf compare`) - #158937 (Emit the emscripten entry point as `__main_argc_argv`) - #151379 (Stabilize `VecDeque::retain_back` from `truncate_front`) - #156548 ( Library support for aarch64-unknown-linux-pauthtest target) - #158307 (CI job for parallel frontend ui tests) - #158347 (Improve generic parameters handling for #[diagnostic::on_const]) - #158722 (delegation: do not always inherit `ConstArgHasType` predicates) - #158741 (Simplify `Option::into_flat_iter` signature) - #158807 (Add regression test for CString::clone_into unwind safety) - #158862 (Fix the span for parameter suggestion ) - #158883 (tests: fix enum-match.rs to handle LLVM 23)
…_arguments, r=mejrs Improve generic parameters handling for #[diagnostic::on_const] cc rust-lang#155570 This Improves generic parameters handling for #[diagnostic::on_const] This is done by printing generics parameters when these are concrete Adt generics args. A lint is emitted we try to format a generic that is found anywhere. Moreover, generics parameters that are ty infer vars are no longer displayed "as-is", it is not clear and might be confusing, in this specific case the name of the generic parameter will be displayed instead. I will need some help for displaying the `Z`parameter correctly. From what I have understood, it is an `ty::Infer(ty::TyVar(_))` that is not correctly displayed via `self.tcx.short_string()` (in `on_unimplemented_components()`), or even not correctly inferred via `self.infcx.ty_to_string()`. EDIT: general descrition updated
Rollup of 25 pull requests Successful merges: - #158871 (add relnotes for 1.97.0) - #158968 (stdarch subtree update) - #157690 (codegen_ssa: pack small const aggregates into immediate stores) - #158541 (Move `std::io::Write` to `core::io`) - #154445 (rustdoc: Represent `--output-format=json` coverage and ir differently) - #156370 (Reject linked dylib EII default overrides) - #157153 (allow `Allocator`s to be used as `#[global_allocator]`s) - #158495 (Rename HAS_CT_PROJECTION to HAS_CONST_ALIAS) - #158617 (allow mGCA const arguments to fall back to anon consts) - #158645 (Fix splat ICEs and ban it in closures) - #158655 (Fix coroutine MIR saved local remapping) - #158666 (Carry the `b_offset` inside `BackendRepr::ScalarPair`) - #158870 (std: merge the unix-like io::error modules into one file) - #158920 (Update wasm-component-ld to 0.5.26) - #158926 (wrapping_sh* methods: clarify underspecified reference) - #158927 (add core test run with `-Zforce-intrinsic-fallback`) - #158932 (Do not build the compiler when invoking `x perf compare`) - #158937 (Emit the emscripten entry point as `__main_argc_argv`) - #151379 (Stabilize `VecDeque::retain_back` from `truncate_front`) - #156144 (Better docs for PartialEq (includes macro rename)) - #156548 ( Library support for aarch64-unknown-linux-pauthtest target) - #158307 (CI job for parallel frontend ui tests) - #158347 (Improve generic parameters handling for #[diagnostic::on_const]) - #158722 (delegation: do not always inherit `ConstArgHasType` predicates) - #158741 (Simplify `Option::into_flat_iter` signature)
…_arguments, r=mejrs Improve generic parameters handling for #[diagnostic::on_const] cc rust-lang#155570 This Improves generic parameters handling for #[diagnostic::on_const] This is done by printing generics parameters when these are concrete Adt generics args. A lint is emitted we try to format a generic that is found anywhere. Moreover, generics parameters that are ty infer vars are no longer displayed "as-is", it is not clear and might be confusing, in this specific case the name of the generic parameter will be displayed instead. I will need some help for displaying the `Z`parameter correctly. From what I have understood, it is an `ty::Infer(ty::TyVar(_))` that is not correctly displayed via `self.tcx.short_string()` (in `on_unimplemented_components()`), or even not correctly inferred via `self.infcx.ty_to_string()`. EDIT: general descrition updated
…uwer Rollup of 17 pull requests Successful merges: - #158510 (Enable `static_position_independent_executables` on all gnu and musl targets) - #158541 (Move `std::io::Write` to `core::io`) - #158899 (Fix `unaligned_volatile_store` by removing `MemFlags::UNALIGNED`) - #155429 (Support `u128`/`i128` c-variadic arguments) - #156370 (Reject linked dylib EII default overrides) - #157153 (allow `Allocator`s to be used as `#[global_allocator]`s) - #158535 (Support `#[track_caller]` on EII declarations) - #158617 (allow mGCA const arguments to fall back to anon consts) - #158645 (Fix splat ICEs and ban it in closures) - #158988 (Redo `TokenStreamIter`) - #158347 (Improve generic parameters handling for #[diagnostic::on_const]) - #158722 (delegation: do not always inherit `ConstArgHasType` predicates) - #158739 (view-types: HIR lowering) - #158883 (tests: fix enum-match.rs to handle LLVM 23) - #158886 (Add documentation for the `no_std` attribute) - #158951 (Merge three `MaxUniverse`s into one) - #158961 (Reapply "LLVM 23: Run AssignGUIDPass in some places")
…_arguments, r=mejrs Improve generic parameters handling for #[diagnostic::on_const] cc rust-lang#155570 This Improves generic parameters handling for #[diagnostic::on_const] This is done by printing generics parameters when these are concrete Adt generics args. A lint is emitted we try to format a generic that is found anywhere. Moreover, generics parameters that are ty infer vars are no longer displayed "as-is", it is not clear and might be confusing, in this specific case the name of the generic parameter will be displayed instead. I will need some help for displaying the `Z`parameter correctly. From what I have understood, it is an `ty::Infer(ty::TyVar(_))` that is not correctly displayed via `self.tcx.short_string()` (in `on_unimplemented_components()`), or even not correctly inferred via `self.infcx.ty_to_string()`. EDIT: general descrition updated
…_arguments, r=mejrs Improve generic parameters handling for #[diagnostic::on_const] cc rust-lang#155570 This Improves generic parameters handling for #[diagnostic::on_const] This is done by printing generics parameters when these are concrete Adt generics args. A lint is emitted we try to format a generic that is found anywhere. Moreover, generics parameters that are ty infer vars are no longer displayed "as-is", it is not clear and might be confusing, in this specific case the name of the generic parameter will be displayed instead. I will need some help for displaying the `Z`parameter correctly. From what I have understood, it is an `ty::Infer(ty::TyVar(_))` that is not correctly displayed via `self.tcx.short_string()` (in `on_unimplemented_components()`), or even not correctly inferred via `self.infcx.ty_to_string()`. EDIT: general descrition updated
…_arguments, r=mejrs Improve generic parameters handling for #[diagnostic::on_const] cc rust-lang#155570 This Improves generic parameters handling for #[diagnostic::on_const] This is done by printing generics parameters when these are concrete Adt generics args. A lint is emitted we try to format a generic that is found anywhere. Moreover, generics parameters that are ty infer vars are no longer displayed "as-is", it is not clear and might be confusing, in this specific case the name of the generic parameter will be displayed instead. I will need some help for displaying the `Z`parameter correctly. From what I have understood, it is an `ty::Infer(ty::TyVar(_))` that is not correctly displayed via `self.tcx.short_string()` (in `on_unimplemented_components()`), or even not correctly inferred via `self.infcx.ty_to_string()`. EDIT: general descrition updated
…uwer Rollup of 21 pull requests Successful merges: - #150946 (intrinsics: Add a fallback for non-const libm float functions) - #158510 (Enable `static_position_independent_executables` on all gnu and musl targets) - #158541 (Move `std::io::Write` to `core::io`) - #158899 (Fix `unaligned_volatile_store` by removing `MemFlags::UNALIGNED`) - #155429 (Support `u128`/`i128` c-variadic arguments) - #156370 (Reject linked dylib EII default overrides) - #156508 (Infer all anonymous lifetimes in assoc consts as `'static`) - #158617 (allow mGCA const arguments to fall back to anon consts) - #158645 (Fix splat ICEs and ban it in closures) - #158859 (Improve `-Zls` diagnostic message on `.rs` files) - #158988 (Redo `TokenStreamIter`) - #158347 (Improve generic parameters handling for #[diagnostic::on_const]) - #158722 (delegation: do not always inherit `ConstArgHasType` predicates) - #158739 (view-types: HIR lowering) - #158883 (tests: fix enum-match.rs to handle LLVM 23) - #158886 (Add documentation for the `no_std` attribute) - #158940 (Implement feature `char_to_u32`) - #158951 (Merge three `MaxUniverse`s into one) - #158961 (Reapply "LLVM 23: Run AssignGUIDPass in some places") - #158996 ([compiler] Implement `PartialOrd` via `Ord` for `Span` and newtype_indexes) - #159005 (Use `as_lang_item` instead of repeatedly matching)
…_arguments, r=mejrs Improve generic parameters handling for #[diagnostic::on_const] cc rust-lang#155570 This Improves generic parameters handling for #[diagnostic::on_const] This is done by printing generics parameters when these are concrete Adt generics args. A lint is emitted we try to format a generic that is found anywhere. Moreover, generics parameters that are ty infer vars are no longer displayed "as-is", it is not clear and might be confusing, in this specific case the name of the generic parameter will be displayed instead. I will need some help for displaying the `Z`parameter correctly. From what I have understood, it is an `ty::Infer(ty::TyVar(_))` that is not correctly displayed via `self.tcx.short_string()` (in `on_unimplemented_components()`), or even not correctly inferred via `self.infcx.ty_to_string()`. EDIT: general descrition updated
…uwer Rollup of 24 pull requests Successful merges: - #150946 (intrinsics: Add a fallback for non-const libm float functions) - #158510 (Enable `static_position_independent_executables` on all gnu and musl targets) - #158541 (Move `std::io::Write` to `core::io`) - #158899 (Fix `unaligned_volatile_store` by removing `MemFlags::UNALIGNED`) - #156027 (Consider captured regions for opaque type region liveness.) - #156370 (Reject linked dylib EII default overrides) - #156508 (Infer all anonymous lifetimes in assoc consts as `'static`) - #157561 (rustdoc: do not include extra stuff in span) - #158617 (allow mGCA const arguments to fall back to anon consts) - #158645 (Fix splat ICEs and ban it in closures) - #158859 (Improve `-Zls` diagnostic message on `.rs` files) - #158988 (Redo `TokenStreamIter`) - #158347 (Improve generic parameters handling for #[diagnostic::on_const]) - #158384 (Allow BackwardIncompatibleDropHint in polonius legacy) - #158722 (delegation: do not always inherit `ConstArgHasType` predicates) - #158739 (view-types: HIR lowering) - #158877 (borrowck: Keep returned `path` from `best_blame_constraint()` consistent) - #158883 (tests: fix enum-match.rs to handle LLVM 23) - #158886 (Add documentation for the `no_std` attribute) - #158940 (Implement feature `char_to_u32`) - #158951 (Merge three `MaxUniverse`s into one) - #158961 (Reapply "LLVM 23: Run AssignGUIDPass in some places") - #158995 (Use REST API in linkchecker script) - #158996 ([compiler] Implement `PartialOrd` via `Ord` for `Span` and newtype_indexes)
…_arguments, r=mejrs Improve generic parameters handling for #[diagnostic::on_const] cc rust-lang#155570 This Improves generic parameters handling for #[diagnostic::on_const] This is done by printing generics parameters when these are concrete Adt generics args. A lint is emitted we try to format a generic that is found anywhere. Moreover, generics parameters that are ty infer vars are no longer displayed "as-is", it is not clear and might be confusing, in this specific case the name of the generic parameter will be displayed instead. I will need some help for displaying the `Z`parameter correctly. From what I have understood, it is an `ty::Infer(ty::TyVar(_))` that is not correctly displayed via `self.tcx.short_string()` (in `on_unimplemented_components()`), or even not correctly inferred via `self.infcx.ty_to_string()`. EDIT: general descrition updated
Rollup of 24 pull requests Successful merges: - #150946 (intrinsics: Add a fallback for non-const libm float functions) - #158541 (Move `std::io::Write` to `core::io`) - #156027 (Consider captured regions for opaque type region liveness.) - #156370 (Reject linked dylib EII default overrides) - #156508 (Infer all anonymous lifetimes in assoc consts as `'static`) - #157561 (rustdoc: do not include extra stuff in span) - #158617 (allow mGCA const arguments to fall back to anon consts) - #158645 (Fix splat ICEs and ban it in closures) - #158859 (Improve `-Zls` diagnostic message on `.rs` files) - #158988 (Redo `TokenStreamIter`) - #158347 (Improve generic parameters handling for #[diagnostic::on_const]) - #158384 (Allow BackwardIncompatibleDropHint in polonius legacy) - #158722 (delegation: do not always inherit `ConstArgHasType` predicates) - #158739 (view-types: HIR lowering) - #158877 (borrowck: Keep returned `path` from `best_blame_constraint()` consistent) - #158883 (tests: fix enum-match.rs to handle LLVM 23) - #158886 (Add documentation for the `no_std` attribute) - #158940 (Implement feature `char_to_u32`) - #158951 (Merge three `MaxUniverse`s into one) - #158960 (Fix bootstrap submodule path prefix matching) - #158961 (Reapply "LLVM 23: Run AssignGUIDPass in some places") - #158995 (Use REST API in linkchecker script) - #158996 ([compiler] Implement `PartialOrd` via `Ord` for `Span` and newtype_indexes) - #159036 (bootstrap: expand '@argfile' arguments to rustc shim)
Rollup merge of #158347 - rperier:diagnostic_on_const_format_arguments, r=mejrs Improve generic parameters handling for #[diagnostic::on_const] cc #155570 This Improves generic parameters handling for #[diagnostic::on_const] This is done by printing generics parameters when these are concrete Adt generics args. A lint is emitted we try to format a generic that is found anywhere. Moreover, generics parameters that are ty infer vars are no longer displayed "as-is", it is not clear and might be confusing, in this specific case the name of the generic parameter will be displayed instead. I will need some help for displaying the `Z`parameter correctly. From what I have understood, it is an `ty::Infer(ty::TyVar(_))` that is not correctly displayed via `self.tcx.short_string()` (in `on_unimplemented_components()`), or even not correctly inferred via `self.infcx.ty_to_string()`. EDIT: general descrition updated
View all comments
cc #155570
This Improves generic parameters handling for #[diagnostic::on_const]
This is done by printing generics parameters when these are concrete Adt generics args.
A lint is emitted we try to format a generic that is found anywhere.
Moreover, generics parameters that are ty infer vars are no longer displayed
"as-is", it is not clear and might be confusing, in this specific case the
name of the generic parameter will be displayed instead.
I will need some help for displaying the
Zparameter correctly. From what I have understood, it is anty::Infer(ty::TyVar(_))that is not correctly displayed viaself.tcx.short_string()(inon_unimplemented_components()), or even not correctly inferred viaself.infcx.ty_to_string().EDIT: general descrition updated