Commit Graph

157 Commits

Author SHA1 Message Date
Oli Scherer
c72c6e01c8 Merge the ~const and impl const checks and add some explanatory notes 2022-10-04 08:59:20 +00:00
Oli Scherer
33bcea8f61 Only allow ~const bounds for traits with #[const_trait] 2022-10-04 08:06:54 +00:00
Deadbeef
27b280e1b5 Fix ICE in const_trait check code
This fixes #102156.
2022-09-27 13:47:32 +00:00
lcnr
1fc86a63f4 rustc_typeck to rustc_hir_analysis 2022-09-27 10:37:23 +02:00
Matthias Krüger
e9bec2fdd4 Rollup merge of #102273 - woppopo:relax_const_bound, r=fee1-dead
Allow `~const` bounds on non-const functions

Makes the behavior of bound of trait-associated functions and non-associated functions consistent.
2022-09-26 19:19:21 +02:00
woppopo
e4b08ab241 Allow ~const bounds on non-const functions 2022-09-26 05:00:31 +00:00
Deadbeef
36e8c113f6 added tests 2022-09-24 20:32:16 +00:00
bors
7a8636c843 Auto merge of #100982 - fee1-dead-contrib:const-impl-requires-const-trait, r=oli-obk
Require `#[const_trait]` on `Trait` for `impl const Trait`

r? `@oli-obk`
2022-09-22 04:22:24 +00:00
Deadbeef
898c76cd82 Make error messages great again (and fix clippy and add test) 2022-09-21 15:02:15 +00:00
Deadbeef
ee96ae0a32 make projection bounds with const bounds satisfy const 2022-09-18 18:05:30 +00:00
Deadbeef
f8813cf10e do const trait method bounds check later in rustc_const_eval 2022-09-16 11:48:43 +08:00
Deadbeef
1bcc26a6b1 bless tests 2022-09-16 11:48:43 +08:00
Deadbeef
03ac7e0d0b Add test 2022-09-16 11:48:42 +08:00
Dylan DPC
14c8a68e49 Rollup merge of #100336 - fee1-dead-contrib:fix-wf-const-trait, r=oli-obk
Fix two const_trait_impl issues

r? ``@oli-obk``

Fixes #100222.
Fixes #100543.
2022-08-22 20:34:13 +05:30
Deadbeef
f1db3be9cf fix tidy 2022-08-22 11:44:04 +00:00
Deadbeef
f019b6c5e8 Overhaul 100222 test; wf always remap to nonconst 2022-08-22 11:28:01 +00:00
Deadbeef
d744f36ea2 Fix wf check on #[const_trait] return types 2022-08-22 10:53:26 +00:00
Dylan DPC
3842117ef2 Rollup merge of #99915 - WaffleLapkin:recover_keyword_bounds, r=compiler-errors
Recover keywords in trait bounds

(_this pr was inspired by [this tweet](https://twitter.com/Azumanga/status/1552982326409367561)_)

Recover keywords in trait bound, motivational example:
```rust
fn f(_: impl fn()) {} // mistyped, meant `Fn`
```

<details><summary>Current nightly (3 needless and confusing errors!)</summary>
<p>

```text
error: expected identifier, found keyword `fn`
 --> ./t.rs:1:15
  |
1 | fn _f(_: impl fn()) {}
  |               ^^ expected identifier, found keyword
  |
help: escape `fn` to use it as an identifier
  |
1 | fn _f(_: impl r#fn()) {}
  |               ++

error: expected one of `:` or `|`, found `)`
 --> ./t.rs:1:19
  |
1 | fn _f(_: impl fn()) {}
  |                   ^ expected one of `:` or `|`

error: expected one of `!`, `(`, `)`, `,`, `?`, `for`, `~`, lifetime, or path, found keyword `fn`
 --> ./t.rs:1:15
  |
1 | fn _f(_: impl fn()) {}
  |              -^^ expected one of 9 possible tokens
  |              |
  |              help: missing `,`

error: at least one trait must be specified
 --> ./t.rs:1:10
  |
1 | fn _f(_: impl fn()) {}
  |          ^^^^
```

</p>
</details>

This PR:
```text
error: expected identifier, found keyword `fn`
 --> ./t.rs:1:15
  |
1 | fn _f(_: impl fn()) {}
  |               ^^ expected identifier, found keyword
  |
help: escape `fn` to use it as an identifier
  |
1 | fn _f(_: impl r#fn()) {}
  |               ++

error[E0405]: cannot find trait `r#fn` in this scope
  --> ./t.rs:1:15
   |
1  | fn _f(_: impl fn()) {}
   |               ^^ help: a trait with a similar name exists (notice the capitalization): `Fn`
   |
  ::: /home/waffle/projects/repos/rust/library/core/src/ops/function.rs:74:1
   |
74 | pub trait Fn<Args>: FnMut<Args> {
   | ------------------------------- similarly named trait `Fn` defined here
```

It would be nice to have suggestion in the first error like "have you meant `Fn` trait", instead of a separate error, but the recovery is deep inside ident parsing, which makes it a lot harder to do.

r? `@compiler-errors`
2022-08-22 11:45:42 +05:30
Maybe Waffle
5d5e451618 recover const Tr bounds (no ~) 2022-08-21 14:58:42 +04:00
Michael Goulet
d2f54b1990 Adjust messages, address some nits 2022-08-21 02:35:11 +00:00
Michael Goulet
d05fea6ac4 Account for relative paths 2022-08-21 02:34:52 +00:00
Michael Goulet
c005e760f5 Rework point-at-arg 2022-08-21 02:34:52 +00:00
Andy Wang
84a199369b Reword "Required because of the requirements on the impl of ..." 2022-08-18 21:08:08 +01:00
Fabian Wolff
e3c7e04a44 Warn about dead tuple struct fields 2022-08-03 12:17:23 +02:00
Maybe Waffle
c6558c0bc7 Recover keywords in bounds
For example, this fixes a error for `impl fn()` (notice the capitalization)
2022-07-29 21:43:35 +04:00
Deadbeef
71e162e6ca Fix diagnostics for unfulfilled obligations 2022-07-26 14:14:21 +00:00
Deadbeef
d60ebe366b bless tests, remove nonexistent E0395 2022-07-26 14:14:21 +00:00
Deadbeef
05bb26fdb6 Add tests 2022-07-23 14:25:56 +00:00
klensy
0ff8ae3111 diagnostics: fix trailing space 2022-06-16 14:40:28 +03:00
Michael Goulet
9c47afe9fa Handle empty where-clause better 2022-06-11 16:27:01 -07:00
Deadbeef
257f06587c Remove #[default..] and add #[const_trait] 2022-05-30 08:52:24 +00:00
Oli Scherer
f9c4f2b7ad Fix up tests 2022-05-19 14:48:39 +00:00
Oli Scherer
aa9eae50f3 Stable const things need a stability attribute 2022-05-19 12:30:38 +00:00
Jacob Pratt
5ff331142e Move check to existing pass
This alters the diagnostics a bit, as the trait method is still stable.
The only thing this check does is ensure that compilation fails if a
trait implementation is declared const-stable.
2022-05-19 12:21:45 +00:00
Jacob Pratt
f0620c9503 Proper const stability check, default to unstable
Rather than deferring to const eval for checking if a trait is const, we
now check up-front. This allows the error to be emitted earlier, notably
at the same time as other stability checks.

Also included in this commit is a change of the default const stability
level to UNstable. Previously, an item that was `const` but did not
explicitly state it was unstable was implicitly stable.
2022-05-19 12:21:45 +00:00
Takayuki Maeda
547cb2722b make E0117 error clear 2022-04-21 16:47:01 +09:00
bors
d12b857816 Auto merge of #94243 - compiler-errors:compiler-flags-typo, r=Mark-Simulacrum
`s/compiler-flags/compile-flags` in compiletest

Also make compiletest panic so this doesn't happen in the future! I literally always forget which it's called, so I wanted to make my life easier in the future.

Also open to the possibility of parsing both.
2022-04-11 00:58:22 +00:00
ohno418
0d2a00058b Suggest derivable trait on E0277 2022-04-05 11:14:32 +09:00
Esteban Kuber
5fd37862d9 Properly track ImplObligations
Instead of probing for all possible impls that could have caused an
`ImplObligation`, keep track of its `DefId` and obligation spans for
accurate error reporting.

Follow up to #89580. Addresses #89418.

Remove some unnecessary clones.

Tweak output for auto trait impl obligations.
2022-03-24 02:08:49 +00:00
Deadbeef
fe5b81348f Tidy up 2022-03-21 17:07:09 +11:00
Deadbeef
1f3ee7f32e Rename ~const Drop to ~const Destruct 2022-03-21 17:04:03 +11:00
Eric Holk
8fc835831c Update tests after feature stabilization 2022-03-07 08:47:18 -08:00
Camille GILLOT
27d8cd7db0 Cleanup feature gates. 2022-03-03 18:50:28 +01:00
Michael Goulet
ad430f541c rename compiler-flags to compile-flags 2022-02-21 17:53:16 -08:00
Deadbeef
88d433e56f Rebless 2022-02-12 19:34:52 +11:00
Deadbeef
12397ab48b Report the selection error when possible 2022-02-12 19:24:43 +11:00
Deadbeef
b5235ea732 bless you 2022-02-12 19:24:41 +11:00
Michael Goulet
1ab97dbc52 add note suggesting that predicate is satisfied but is not const 2022-01-26 19:09:44 -08:00
Deadbeef
8b76cad0a7 Add a minimal working append_const_msg argument 2022-01-26 00:48:08 +11:00
Deadbeef
fdf7d01088 Improve selection errors for ~const trait bounds 2022-01-26 00:48:01 +11:00