Commit Graph

157 Commits

Author SHA1 Message Date
Deadbeef
703c557aaa Fix more tests 2021-08-27 05:07:38 +00:00
Deadbeef
ff24ac4f2b Try fixing some tests 2021-08-27 05:07:38 +00:00
Deadbeef
8660832086 Introduce ~const
- [x] Removed `?const` and change uses of `?const`
 - [x] Added `~const` to the AST. It is gated behind const_trait_impl.
 - [x] Validate `~const` in ast_validation.
 - [ ] Add enum `BoundConstness` to the HIR. (With variants `NotConst` and
 `ConstIfConst` allowing future extensions)
 - [ ] Adjust trait selection and pre-existing code to use `BoundConstness`.
 - [ ] Optional steps (*for this PR, obviously*)
      - [ ] Fix #88155
      - [ ] Do something with constness bounds in chalk
2021-08-27 05:07:37 +00:00
bors
adf1688447 Auto merge of #86808 - fee1-dead:constify-1, r=oli-obk
constified implementations of `Default`
2021-08-17 22:30:09 +00:00
Deadbeef
6bd2ecba72 Add ui test 2021-08-17 07:15:59 +00:00
bors
aa8f27bf4d Auto merge of #87668 - estebank:tweak-bound-output, r=oli-obk
Use note for pointing at bound introducing requirement

Modify output for pointing where a trait bound obligation is introduced in an E0277 from using a span label to using a note in order to always preserve order of the output:

Before:
```
error[E0277]: `<<Self as Case1>::A as Iterator>::Item` doesn't implement `Debug`
  --> $DIR/bounds-on-assoc-in-trait.rs:18:28
   |
LL |     type A: Iterator<Item: Debug>;
   |                            ^^^^^ `<<Self as Case1>::A as Iterator>::Item` cannot be formatted using `{:?}` because it doesn't implement `Debug`
   |
  ::: $SRC_DIR/core/src/fmt/mod.rs:LL:COL
   |
LL | pub trait Debug {
   | --------------- required by this bound in `Debug`
   |
   = help: the trait `Debug` is not implemented for `<<Self as Case1>::A as Iterator>::Item`
```
After:
```
error[E0277]: `<<Self as Case1>::A as Iterator>::Item` doesn't implement `Debug`
  --> $DIR/bounds-on-assoc-in-trait.rs:18:28
   |
LL |     type A: Iterator<Item: Debug>;
   |                            ^^^^^ `<<Self as Case1>::A as Iterator>::Item` cannot be formatted using `{:?}` because it doesn't implement `Debug`
   |
   = help: the trait `Debug` is not implemented for `<<Self as Case1>::A as Iterator>::Item`
note: required by a bound in `Debug`
  --> $SRC_DIR/core/src/fmt/mod.rs:LL:COL
   |
LL | pub trait Debug {
   | ^^^^^^^^^^^^^^^ required by this bound in `Debug`
```
2021-08-17 06:59:49 +00:00
Esteban Küber
39f220ce12 Use note to point at bound introducing requirement 2021-08-16 17:47:22 +00:00
Deadbeef
85abdf0757 Add ui test 2021-08-16 15:15:28 +00:00
Deadbeef
74627c17c5 Fix Cargo.lock and ui test 2021-08-13 11:30:33 +00:00
Deadbeef
1fa712d0ba Make assoc types work with ?const opt=out 2021-08-13 09:28:52 +00:00
Deadbeef
6b6ad781f8 Fix call-generic-method-nonconst test 2021-08-13 09:28:51 +00:00
Deadbeef
bcf0e2f528 Fix assoc-type test 2021-08-13 09:28:50 +00:00
Deadbeef
32390a0df6 move Constness into TraitPredicate 2021-08-13 09:26:33 +00:00
Esteban Küber
99f2977031 Modify structured suggestion output
* On suggestions that include deletions, use a diff inspired output format
* When suggesting addition, use `+` as underline
* Color highlight modified span
2021-08-11 09:46:24 +00:00
Jonas Schievink
550948c553 Update tests 2021-07-29 23:21:54 +02:00
Deadbeef
4b82bbeac0 Recognize bounds on impls as const bounds 2021-07-19 19:51:44 +08:00
Deadbeef
8841a426e5 Mark const_trait_impl as active 2021-07-16 11:54:00 +08:00
Deadbeef
88b29f5fb2 Test for misusing attribute 2021-07-10 20:54:50 +08:00
Deadbeef
a79e08ca2a Update tests 2021-07-10 20:54:50 +08:00
Deadbeef
56d79adf3b Skip check for calling functions in same trait 2021-07-10 20:54:48 +08:00
Deadbeef
d8d4cc3b98 Treat trait fns marked with the attr as const 2021-07-10 20:54:48 +08:00
Deadbeef
2db927d8d8 Add #[default_method_body_is_const] 2021-07-10 20:54:44 +08:00
bors
701496384f Auto merge of #86571 - fee1-dead:const-trait-impl-fix, r=jackh726
deny using default function in impl const Trait

Fixes #79450.

I don't know if my implementation is correct:

 - The check is in `rustc_passes::check_const`, should I put it somewhere else instead?
 - Is my approach (to checking the impl) optimal? It works for the current tests, but it might have some issues or there might be a better way of doing this.
2021-07-03 07:24:24 +00:00
Deadbeef
ee9c614ece Test for const trait impls behind feature gates 2021-07-01 18:43:34 +08:00
Deadbeef
b3a79832c0 Use revisions for cross-crate test 2021-07-01 17:24:45 +08:00
Deadbeef
c424510746 Add tests for cross-crate usage of impl const 2021-06-30 23:57:17 +08:00
Deadbeef
22a8d46ed3 deny using default function in impl const Trait 2021-06-23 19:21:57 +08:00
Ralf Jung
9a852776f4 don't let const_fn feature flag affect impl-block-level trait bounds 2021-04-29 09:27:45 +02:00
Ralf Jung
46d09f7a4b remove E0723 error code 2021-04-19 14:58:11 +02:00
Ralf Jung
fdad6ab3a3 move 'trait bounds on const fn' to separate feature gate 2021-04-18 18:36:41 +02:00
Esteban Küber
b8dda53e69 Remove trailing : from E0119 message 2021-04-06 18:16:11 -07:00
Noah
1e27b65d8e Recover on const impl<> X for Y 2020-12-12 14:45:54 -06:00
Jonas Schievink
cb406848ec Add some more tests 2020-11-22 15:51:05 +01:00
Jonas Schievink
e69fcea609 const fn: allow use of trait impls from bounds 2020-11-22 04:19:46 +01:00
Dylan MacKenzie
ef6d4277ed Bless tests 2020-09-22 10:05:58 -07:00
Dan Aloni
51742be6d8 specialization_graph: avoid trimmed paths for OverlapError 2020-09-03 14:09:50 +03:00
Dan Aloni
07e7823c01 pretty: trim paths of unique symbols
If a symbol name can only be imported from one place for a type, and
as long as it was not glob-imported anywhere in the current crate, we
can trim its printed path and print only the name.

This has wide implications on error messages with types, for example,
shortening `std::vec::Vec` to just `Vec`, as long as there is no other
`Vec` importable anywhere.

This adds a new '-Z trim-diagnostic-paths=false' option to control this
feature.

On the good path, with no diagnosis printed, we should try to avoid
issuing this query, so we need to prevent trimmed_def_paths query on
several cases.

This change also relies on a previous commit that differentiates
between `Debug` and `Display` on various rustc types, where the latter
is trimmed and presented to the user and the former is not.
2020-09-02 22:26:37 +03:00
Aaron Hill
e3cd43eb00 Use smaller def span for functions
Currently, the def span of a funtion encompasses the entire function
signature and body. However, this is usually unnecessarily verbose - when we are
pointing at an entire function in a diagnostic, we almost always want to
point at the signature. The actual contents of the body tends to be
irrelevant to the diagnostic we are emitting, and just takes up
additional screen space.

This commit changes the `def_span` of all function items (freestanding
functions, `impl`-block methods, and `trait`-block methods) to be the
span of the signature. For example, the function

```rust
pub fn foo<T>(val: T) -> T { val }
```

now has a `def_span` corresponding to `pub fn foo<T>(val: T) -> T`
(everything before the opening curly brace).

Trait methods without a body have a `def_span` which includes the
trailing semicolon. For example:

```rust
trait Foo {
    fn bar();
}```

the function definition `Foo::bar` has a `def_span` of `fn bar();`

This makes our diagnostic output much shorter, and emphasizes
information that is relevant to whatever diagnostic we are reporting.

We continue to use the full span (including the body) in a few of
places:

* MIR building uses the full span when building source scopes.
* 'Outlives suggestions' use the full span to sort the diagnostics being
  emitted.
* The `#[rustc_on_unimplemented(enclosing_scope="in this scope")]`
attribute points the entire scope body.
* The 'unconditional recursion' lint uses the full span to show
  additional context for the recursive call.

All of these cases work only with local items, so we don't need to
add anything extra to crate metadata.
2020-08-22 18:41:49 -04:00
Lzu Tao
c4c017a184 Suppress "const" prefix of FnDef in MIR dump 2020-08-21 00:36:49 +00:00
Dylan MacKenzie
d84f0c8d32 Update tests 2020-06-28 10:08:12 -07:00
Dylan MacKenzie
d6139f76c0 Update tests 2020-06-28 10:08:10 -07:00
Dylan MacKenzie
e8b270a4b6 Add regression test for #69615 2020-04-09 14:56:28 -07:00
Esteban Küber
713a291441 review comments 2020-03-05 15:39:35 -08:00
Esteban Küber
91525fd078 Tweak output for invalid negative impl AST errors 2020-03-04 16:15:23 -08:00
Dylan MacKenzie
19801b12c9 Update tests 2020-02-19 09:39:29 -08:00
Dylan MacKenzie
160e6304e8 Add passing test for Add on generic struct 2020-02-18 21:03:29 -08:00
Dylan MacKenzie
c8f0abb51c Add ignored test for associated types in const impl 2020-02-18 21:03:29 -08:00
Dylan MacKenzie
4992eb2c6f Test rustc_const_unstable on trait fns 2020-02-18 21:03:29 -08:00
Dylan MacKenzie
70f78797d5 Ensure const impl cannot coexist with non-const impl 2020-02-18 21:03:29 -08:00
Dylan MacKenzie
d6d6d25c34 Split const trait method test and impl ops::Add 2020-02-18 21:03:28 -08:00