rust/src
Manish Goregaokar e1acdf51bf
Rollup merge of #88907 - WaffleLapkin:targeted_const_fn_with_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 #57563 <https://github.com/rust-lang/rust/issues/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 #57563 <https://github.com/rust-lang/rust/issues/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
2021-09-15 14:57:01 -07:00
..
bootstrap Rollup merge of #88885 - GuillaumeGomez:fix-jump-def-background, r=camelid 2021-09-13 21:20:41 +02:00
build_helper
ci Disable both reproducible-build tests for crate-type=bin 2021-09-15 13:37:22 -04:00
doc Rollup merge of #87320 - danakj:debug-compilation-dir, r=michaelwoerister 2021-09-15 14:56:56 -07:00
etc
librustdoc Auto merge of #73314 - GuillaumeGomez:display-warnings, r=jyn514 2021-09-14 16:05:44 +00:00
llvm-project@86c7daa627 Update LLVM submodule 2021-09-11 00:15:38 +02:00
rustdoc-json-types rustdoc: Clean up handling of lifetime bounds 2021-09-02 14:27:59 -07:00
test Rollup merge of #88907 - WaffleLapkin:targeted_const_fn_with_a_bound_in_impl_block_error, r=estebank 2021-09-15 14:57:01 -07:00
tools Rollup merge of #88775 - pnkfelix:revert-anon-union-parsing, r=davidtwco 2021-09-15 14:56:58 -07:00
README.md
stage0.json Bump stage0 compiler to 1.56 2021-09-08 20:51:05 -04:00
version Bump version to 1.57 2021-09-03 21:54:48 -04:00

This directory contains the source code of the rust project, including:

  • The test suite
  • The bootstrapping build system
  • Various submodules for tools, like rustdoc, rls, etc.

For more information on how various parts of the compiler work, see the rustc dev guide.