Highlight the const fn if error happened because of a bound on the impl block#88907
Merged
bors merged 1 commit intorust-lang:masterfrom Sep 16, 2021
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
```
estebank
approved these changes
Sep 14, 2021
Contributor
estebank
left a comment
There was a problem hiding this comment.
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.
|
|
||
| fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> { | ||
| feature_err( | ||
| let mut builder = feature_err( |
Contributor
There was a problem hiding this comment.
The common naming convention for these is usually err, or less commonly, diag.
Contributor
|
@bors r+ |
Collaborator
|
📌 Commit 6ec7255 has been approved by |
Manishearth
added a commit
to Manishearth/rust
that referenced
this pull request
Sep 14, 2021
…_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
Manishearth
added a commit
to Manishearth/rust
that referenced
this pull request
Sep 15, 2021
…_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
bors
added a commit
to rust-lang-ci/rust
that referenced
this pull request
Sep 16, 2021
…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
JohnTitor
added a commit
to JohnTitor/rust
that referenced
this pull request
Sep 19, 2021
…_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
JohnTitor
added a commit
to JohnTitor/rust
that referenced
this pull request
Sep 19, 2021
…_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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
consttoken, 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 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.P.S. it's my first time contributing to diagnostics, so feedback is very appreciated!
r? @estebank
@rustbot label: +A-diagnostics