diff options
| author | Waffle <waffle.lapkin@gmail.com> | 2021-09-13 16:36:14 +0300 |
|---|---|---|
| committer | Waffle <waffle.lapkin@gmail.com> | 2021-09-13 16:36:14 +0300 |
| commit | 6ec7255d7b9c96c4cc0feafec6f26a2a9db3b7aa (patch) | |
| tree | 333ca825ed2b1c1fef21c3d404a0abec64a749ea /compiler/rustc_const_eval/src | |
| parent | d2dfb0eb8e30d188fb1731e540bc1b418bcd046d (diff) | |
| download | rust-6ec7255d7b9c96c4cc0feafec6f26a2a9db3b7aa.tar.gz rust-6ec7255d7b9c96c4cc0feafec6f26a2a9db3b7aa.zip | |
Highlight the const function if error happened because of a bound on 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 #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 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 #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
```
Diffstat (limited to 'compiler/rustc_const_eval/src')
| -rw-r--r-- | compiler/rustc_const_eval/src/transform/check_consts/ops.rs | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/compiler/rustc_const_eval/src/transform/check_consts/ops.rs b/compiler/rustc_const_eval/src/transform/check_consts/ops.rs index 8923d989b29..2a296750838 100644 --- a/compiler/rustc_const_eval/src/transform/check_consts/ops.rs +++ b/compiler/rustc_const_eval/src/transform/check_consts/ops.rs @@ -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( &ccx.tcx.sess.parse_sess, sym::const_fn_trait_bound, span, "trait bounds other than `Sized` on const fn parameters are unstable", - ) + ); + + match ccx.fn_sig() { + Some(fn_sig) if !fn_sig.span.contains(span) => { + builder.span_label(fn_sig.span, "function declared as const here"); + } + _ => {} + } + + builder } } |
