-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Highlight the const fn
if error happened because of a bound on the impl block
#88907
Highlight the const fn
if error happened because of a bound on the impl block
#88907
Conversation
…the impl block Currently, for the following code, the compiler produces the errors like the following error: ```rust struct Type<T> impl<T: Clone> Type<T> { fn const f() {} } ``` ```text error[E0658]: trait bounds other than `Sized` on const fn parameters are unstable --> ./test.rs:3:6 | 3 | impl<T: Clone> Type<T> { | ^ | = note: see issue rust-lang#57563 <rust-lang#57563> for more information = help: add `#![feature(const_fn_trait_bound)]` to the crate attributes to enable ``` This can be confusing (especially to newcomers) since the error mentions "const fn parameters", but highlights only the impl. This commits adds function highlighting, changing the error to the following: ```text error[E0658]: trait bounds other than `Sized` on const fn parameters are unstable --> ./test.rs:3:6 | 3 | impl<T: Clone> Type<T> { | ^ 4 | pub const fn f() {} | ---------------- function declared as const here | = note: see issue rust-lang#57563 <rust-lang#57563> for more information = help: add `#![feature(const_fn_trait_bound)]` to the crate attributes to enable ```
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, since the errors for object casts in const fns (&T -> &dyn Trait) seem to trigger the same error, this PR accidentally changes these errors too. Not sure if it's desired or how to fix this.
Those should probably get their own errors instead of these, as they are today they are a bit confusing, but I think your changes are worth it.
@@ -599,12 +599,21 @@ pub mod ty { | |||
} | |||
|
|||
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> { | |||
feature_err( | |||
let mut builder = feature_err( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The common naming convention for these is usually err
, or less commonly, diag
.
@bors r+ |
📌 Commit 6ec7255 has been approved by |
…_a_bound_in_impl_block_error, r=estebank Highlight the `const fn` if error happened because of a bound on the impl block Currently, for the following code, the compiler produces the errors like the following: ```rust struct Type<T>(T); impl<T: Clone> Type<T> { const fn f() {} } ``` ```text error[E0658]: trait bounds other than `Sized` on const fn parameters are unstable --> ./test.rs:3:6 | 3 | impl<T: Clone> Type<T> { | ^ | = note: see issue rust-lang#57563 <rust-lang#57563> for more information = help: add `#![feature(const_fn_trait_bound)]` to the crate attributes to enable ``` This can be confusing (especially to newcomers) since the error mentions "const fn parameters", but highlights only the impl. This PR adds function highlighting, changing the error to the following: ```text error[E0658]: trait bounds other than `Sized` on const fn parameters are unstable --> ./test.rs:3:6 | 3 | impl<T: Clone> Type<T> { | ^ 4 | pub const fn f() {} | ---------------- function declared as const here | = note: see issue rust-lang#57563 <rust-lang#57563> for more information = help: add `#![feature(const_fn_trait_bound)]` to the crate attributes to enable ``` --- I've originally wanted to point directly to `const` token, but couldn't find a way to get it's span. It seems like this span is lost during the AST -> HIR lowering. Also, since the errors for object casts in `const fn`s (`&T` -> `&dyn Trait`) seem to trigger the same error, this PR accidentally changes these errors too. Not sure if it's desired or how to fix this. P.S. it's my first time contributing to diagnostics, so feedback is very appreciated! --- r? `@estebank` `@rustbot` label: +A-diagnostics
…_a_bound_in_impl_block_error, r=estebank Highlight the `const fn` if error happened because of a bound on the impl block Currently, for the following code, the compiler produces the errors like the following: ```rust struct Type<T>(T); impl<T: Clone> Type<T> { const fn f() {} } ``` ```text error[E0658]: trait bounds other than `Sized` on const fn parameters are unstable --> ./test.rs:3:6 | 3 | impl<T: Clone> Type<T> { | ^ | = note: see issue rust-lang#57563 <rust-lang#57563> for more information = help: add `#![feature(const_fn_trait_bound)]` to the crate attributes to enable ``` This can be confusing (especially to newcomers) since the error mentions "const fn parameters", but highlights only the impl. This PR adds function highlighting, changing the error to the following: ```text error[E0658]: trait bounds other than `Sized` on const fn parameters are unstable --> ./test.rs:3:6 | 3 | impl<T: Clone> Type<T> { | ^ 4 | pub const fn f() {} | ---------------- function declared as const here | = note: see issue rust-lang#57563 <rust-lang#57563> for more information = help: add `#![feature(const_fn_trait_bound)]` to the crate attributes to enable ``` --- I've originally wanted to point directly to `const` token, but couldn't find a way to get it's span. It seems like this span is lost during the AST -> HIR lowering. Also, since the errors for object casts in `const fn`s (`&T` -> `&dyn Trait`) seem to trigger the same error, this PR accidentally changes these errors too. Not sure if it's desired or how to fix this. P.S. it's my first time contributing to diagnostics, so feedback is very appreciated! --- r? ``@estebank`` ``@rustbot`` label: +A-diagnostics
…arth Rollup of 8 pull requests Successful merges: - rust-lang#87320 (Introduce -Z remap-cwd-prefix switch) - rust-lang#88690 (Accept `m!{ .. }.method()` and `m!{ .. }?` statements. ) - rust-lang#88775 (Revert anon union parsing) - rust-lang#88841 (feat(rustc_typeck): suggest removing bad parens in `(recv.method)()`) - rust-lang#88907 (Highlight the `const fn` if error happened because of a bound on the impl block) - rust-lang#88915 (`Wrapping<T>` has the same layout and ABI as `T`) - rust-lang#88933 (Remove implementation of `min_align_of` intrinsic) - rust-lang#88951 (Update books) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
…_trait_in_const_fn, r=estebank Add a separate error for `dyn Trait` in `const fn` Previously "trait bounds other than `Sized` on const fn parameters are unstable" error was used for both trait bounds (`<T: Trait>`) and trait objects (`dyn Trait`). This was pretty confusing. This PR adds a separate error for trait objects: "trait objects in const fn are unstable". The error for trait bounds is otherwise intact. This is follow up to rust-lang#88907 r? `@estebank` `@rustbot` label: +A-diagnostics
…_trait_in_const_fn, r=estebank Add a separate error for `dyn Trait` in `const fn` Previously "trait bounds other than `Sized` on const fn parameters are unstable" error was used for both trait bounds (`<T: Trait>`) and trait objects (`dyn Trait`). This was pretty confusing. This PR adds a separate error for trait objects: "trait objects in const fn are unstable". The error for trait bounds is otherwise intact. This is follow up to rust-lang#88907 r? ``@estebank`` ``@rustbot`` label: +A-diagnostics
Currently, for the following code, the compiler produces the errors like the
following:
This can be confusing (especially to newcomers) since the error mentions "const fn parameters", but highlights only the impl.
This PR adds function highlighting, changing the error to the following:
I've originally wanted to point directly to
const
token, but couldn't find a way to get it's span. It seems like this span is lost during the AST -> HIR lowering.Also, since the errors for object casts in
const fn
s (&T
->&dyn Trait
) seem to trigger the same error, this PR accidentally changes these errors too. Not sure if it's desired or how to fix this.P.S. it's my first time contributing to diagnostics, so feedback is very appreciated!
r? @estebank
@rustbot label: +A-diagnostics