Commit graph

233 commits

Author SHA1 Message Date
Michael Goulet d473bdfdc3 Support bare unit structs in destructuring assignments 2023-12-08 19:55:07 +00:00
Esteban Küber 4e99db9e54 Tweak unclosed generics errors
Remove unnecessary span label for parse errors that already have a
suggestion.

Provide structured suggestion to close generics in more cases.
2023-12-01 20:01:39 +00:00
Matthias Krüger 13ded66513
Rollup merge of #118453 - estebank:priv-fields, r=compiler-errors
Tweak message on ADT with private fields building

When trying to create an inaccessible ADT due to private fields, handle the case when no fields were passed.

```
error: cannot construct `Foo` with struct literal syntax due to private fields
  --> $DIR/issue-76077.rs:8:5
   |
LL |     foo::Foo {};
   |     ^^^^^^^^
   |
   = note: private field `you_cant_use_this_field` that was not provided
```
2023-11-30 09:28:25 +01:00
Esteban Küber 44fd3b4d46 Make parse_pat_ident not recover bad name 2023-11-29 18:47:31 +00:00
Esteban Küber 4be07075b3 Tweak message on ADT with private fields building
When trying to create an inaccessible ADT due to private fields, handle
the case when no fields were passed.

```
error: cannot construct `Foo` with struct literal syntax due to private fields
  --> $DIR/issue-76077.rs:8:5
   |
LL |     foo::Foo {};
   |     ^^^^^^^^
   |
   = note: private field `you_cant_use_this_field` that was not provided
```
2023-11-29 18:11:57 +00:00
Nilstrieb 9b80d85722 Manual find replace updates 2023-11-24 21:04:51 +01:00
Nilstrieb 41e8d152dc Show number in error message even for one error
Co-authored-by: Adrian <adrian.iosdev@gmail.com>
2023-11-24 19:15:52 +01:00
Takayuki Maeda 9e84f6d86a
Rollup merge of #117110 - estebank:deref-field-suggestion, r=b-naber
Suggest field typo through derefs

Take into account implicit dereferences when suggesting fields.

```
error[E0609]: no field `longname` on type `Arc<S>`
  --> $DIR/suggest-field-through-deref.rs:10:15
   |
LL |     let _ = x.longname;
   |               ^^^^^^^^ help: a field with a similar name exists: `long_name`
```

CC https://github.com/rust-lang/rust/issues/78374#issuecomment-719564114
2023-11-19 04:14:41 +09:00
bors e1e60b6976 Auto merge of #117924 - estebank:issue-53841, r=petrochenkov
When a local binding shadows a fn, point at fn def in call failure

When a local binding shadows a function that is then called, this local binding will cause an E0618 error. We now point not only at the binding definition, but also at the locally defined function of the same name.

```
error[E0618]: expected function, found `&str`
  --> $DIR/issue-22468.rs:3:13
   |
LL |     let foo = "bar";
   |         --- `foo` has type `&str`
LL |     let x = foo("baz");
   |             ^^^-------
   |             |
   |             call expression requires function
...
LL | fn foo(file: &str) -> bool {
   | -------------------------- this function of the same name is available here, but it shadowed by the local binding of the same name
```

Fix #53841
2023-11-18 10:47:33 +00:00
Esteban Küber 7141399454 When a local binding shadows a fn, point at fn def in call failure
When a local binding shadows a function that is then called, this local
binding will cause an E0618 error. We now point not only at the binding
definition, but also at the locally defined function of the same name.

```
error[E0618]: expected function, found `&str`
  --> $DIR/issue-22468.rs:3:13
   |
LL |     let foo = "bar";
   |         --- `foo` has type `&str`
LL |     let x = foo("baz");
   |             ^^^-------
   |             |
   |             call expression requires function
...
LL | fn foo(file: &str) -> bool {
   | -------------------------- this function of the same name is avalable here, but it shadowed by the local binding of the same name
```

Fix #53841
2023-11-18 00:05:19 +00:00
bors 82b804c744 Auto merge of #118023 - matthiaskrgr:rollup-i9skwic, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #117338 (Remove asmjs)
 - #117549 (Use `copied` instead of manual `map`)
 - #117745 (Emit smir)
 - #117964 (When using existing fn as module, don't claim it doesn't exist)
 - #118006 (clarify `fn discriminant` guarantees: only free lifetimes may get erased)
 - #118016 (Add stable mir members to triagebot config)
 - #118022 (Miri subtree update)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-11-17 22:58:19 +00:00
Matthias Krüger ca3a02836e
Rollup merge of #117338 - workingjubilee:asmjs-meets-thanatos, r=b-naber
Remove asmjs

Fulfills [MCP 668](https://github.com/rust-lang/compiler-team/issues/668).

`asmjs-unknown-emscripten` does not work as-specified, and lacks essential upstream support for generating asm.js, so it should not exist at all.
2023-11-17 23:04:21 +01:00
Esteban Küber 4f7dddd4a1 recover primary span label 2023-11-16 17:00:23 +00:00
Esteban Küber 8bd8f3b090 Suggest unwrap() on field not found for Result/Option
When encountering a `Result<T, _>` or `Option<T>` where `T` has a field
that's being accessed, suggest calling `.unwrap()` to get to the field.
2023-11-16 17:00:23 +00:00
Esteban Küber dfa75391f8 Suggest field typo through derefs
Take into account implicit dereferences when suggesting fields.

```
error[E0609]: no field `longname` on type `Arc<S>`
  --> $DIR/suggest-field-through-deref.rs:10:15
   |
LL |     let _ = x.longname;
   |               ^^^^^^^^ help: a field with a similar name exists: `long_name`
```

CC https://github.com/rust-lang/rust/issues/78374#issuecomment-719564114
2023-11-16 17:00:23 +00:00
Esteban Küber 4e418805da More detail when expecting expression but encountering bad macro argument
Partially address #71039.
2023-11-16 16:19:04 +00:00
Esteban Küber aae391cf68 Apply structured suggestion that allows test to work since 1.64
Close #73497.
2023-11-07 01:54:00 +00:00
Michael Goulet c83f642f12 Pretty print Fn traits in rustc_on_unimplemented 2023-11-02 20:57:05 +00:00
bors a395214a3a Auto merge of #116405 - estebank:issue-103155, r=davidtwco
Detect object safety errors when assoc type is missing

When an associated type with GATs isn't specified in a `dyn Trait`, emit an object safety error instead of only complaining about the missing associated type, as it will lead the user down a path of three different errors before letting them know that what they were trying to do is impossible to begin with.

Fix #103155.
2023-10-30 22:47:48 +00:00
Esteban Küber 17a6ae2df3 Detect object safety errors when assoc type is missing
When an associated type with GATs isn't specified in a `dyn Trait`, emit
an object safety error instead of only complaining about the missing
associated type, as it will lead the user down a path of three different
errors before letting them know that what they were trying to do is
impossible to begin with.

Fix #103155.
2023-10-30 22:12:07 +00:00
bors 31bc7e2c47 Auto merge of #117415 - matthiaskrgr:rollup-jr2p1t2, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #116862 (Detect when trait is implemented for type and suggest importing it)
 - #117389 (Some diagnostics improvements of `gen` blocks)
 - #117396 (Don't treat closures/coroutine types as part of the public API)
 - #117398 (Correctly handle nested or-patterns in exhaustiveness)
 - #117403 (Poison check_well_formed if method receivers are invalid to prevent typeck from running on it)
 - #117411 (Improve some diagnostics around `?Trait` bounds)
 - #117414 (Don't normalize to an un-revealed opaque when we hit the recursion limit)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-10-30 20:50:14 +00:00
Oli Scherer 455cf5a4f6 Improve some diagnostics around ?Trait bounds 2023-10-30 17:47:07 +00:00
Esteban Küber 8c04999226 On object safety error, mention new enum as alternative
When we encounter a `dyn Trait` that isn't object safe, look for its
implementors. If there's one, mention using it directly If there are
less than 9, mention the possibility of creating a new enum and using
that instead.

Account for object unsafe `impl Trait on dyn Trait {}`.  Make a
distinction between public and sealed traits.

Fix #80194.
2023-10-29 23:55:46 +00:00
Jubilee Young e9a009fd1a Remove asmjs from tests 2023-10-28 23:11:03 -07:00
Oli Scherer beaf46f7e5 Work around the fact that check_mod_type_wf may spuriously return ErrorGuaranteed, even if that error is only emitted by check_modwitem_types 2023-10-25 12:04:54 +00:00
bors cd674d6179 Auto merge of #116300 - cjgillot:split-move, r=petrochenkov
Separate move path tracking between borrowck and drop elaboration.

The primary goal of this PR is to skip creating a `MovePathIndex` for path that do not need dropping in drop elaboration.

The 2 first commits are cleanups.

The next 2 commits displace `move` errors from move-path builder to borrowck. Move-path builder keeps the same logic, but does not carry error information any more.

The remaining commits allow to filter `MovePathIndex` creation according to types. This is used in drop elaboration, to avoid computing dataflow for paths that do not need dropping.
2023-10-24 00:25:32 +00:00
Camille GILLOT 8d535070a2 Do not report errors from move path builder. 2023-10-21 10:29:40 +00:00
Oli Scherer fd9ef69adf Avoid a track_errors by bubbling up most errors from check_well_formed 2023-10-20 08:46:27 +00:00
Esteban Küber bd8b46800d Tweak wording of type errors involving type params
Fix #78206.
2023-10-18 23:53:18 +00:00
Michael Goulet 592163fb71 Extend impl's def_span to include where clauses 2023-10-09 11:47:02 +00:00
bors 94bc9c737e Auto merge of #114811 - estebank:impl-ambiguity, r=wesleywiser
Show more information when multiple `impl`s apply

- When there are `impl`s without type params, show only those (to avoid showing overly generic `impl`s).
```
error[E0283]: type annotations needed
  --> $DIR/multiple-impl-apply.rs:34:9
   |
LL |     let y = x.into();
   |         ^     ---- type must be known at this point
   |
note: multiple `impl`s satisfying `_: From<Baz>` found
  --> $DIR/multiple-impl-apply.rs:14:1
   |
LL | impl From<Baz> for Bar {
   | ^^^^^^^^^^^^^^^^^^^^^^
...
LL | impl From<Baz> for Foo {
   | ^^^^^^^^^^^^^^^^^^^^^^
   = note: required for `Baz` to implement `Into<_>`
help: consider giving `y` an explicit type
   |
LL |     let y: /* Type */ = x.into();
   |          ++++++++++++
```

- Lower the importance of `T: Sized`, `T: WellFormed` and coercion errors, to prioritize more relevant errors. The pre-existing deduplication logic deals with hiding redundant errors better that way, and we show errors with more metadata that is useful to the user.

- Show `<SelfTy as Trait>::assoc_fn` suggestion in more cases.
```
error[E0790]: cannot call associated function on trait without specifying the corresponding `impl` type
  --> $DIR/cross-return-site-inference.rs:38:16
   |
LL |     return Err(From::from("foo"));
   |                ^^^^^^^^^^ cannot call associated function of trait
   |
help: use a fully-qualified path to a specific available implementation
   |
LL |     return Err(</* self type */ as From>::from("foo"));
   |                +++++++++++++++++++     +
```

Fix #88284.
2023-10-06 18:44:32 +00:00
Matthias Krüger c1c5ab717e
Rollup merge of #116428 - Alexendoo:note-duplicate-diagnostics, r=compiler-errors,estebank
Add a note to duplicate diagnostics

Helps explain why there may be a difference between manual testing and the test suite output and highlights them as something to potentially look into

For existing duplicate diagnostics I just blessed them other than a few files that had other `NOTE` annotations in
2023-10-05 19:24:35 +02:00
Jubilee d7b02c3d40
Rollup merge of #116431 - estebank:issue-80476, r=compiler-errors
Tweak wording of E0562

Fix #80476.
2023-10-05 00:56:30 -07:00
Alex Macleod 5453a9f34d Add a note to duplicate diagnostics 2023-10-05 01:04:41 +00:00
Michael Goulet 137b6d0b01 Point to where missing return type should go 2023-10-04 21:09:54 +00:00
Esteban Küber 041e54bd92 Tweak wording of E0562
Fix #80476.
2023-10-04 19:51:43 +00:00
Esteban Küber 91b9ffeab0 Reorder fullfillment errors to keep more interesting ones first
In `report_fullfillment_errors` push back `T: Sized`, `T: WellFormed`
and coercion errors to the end of the list. The pre-existing
deduplication logic eliminates redundant errors better that way, keeping
the resulting output with fewer errors than before, while also having
more detail.
2023-10-04 02:04:14 +00:00
Michael Goulet 07851679cd Point out the actual mismatch error 2023-10-02 23:14:29 +00:00
Michael Goulet 8be12f4ed7 For a single impl candidate, try to unify it with error trait ref 2023-10-02 23:14:29 +00:00
Esteban Küber 4b15959218 Add context to let: Ty = loop { break };
We weren't accounting for the case where `break` was immediately within
the `loop` block.
2023-09-26 23:46:10 +00:00
Esteban Küber ddb3b7e70a Use verbose suggestion for break without value 2023-09-25 22:10:08 +00:00
Matthias Krüger 952d6608fc
Rollup merge of #116062 - eduardosm:start-fn-diag, r=WaffleLapkin
Change `start` to `#[start]` in some diagnosis

They refer to a function with the `start` attribute, but not necessarily named `start`.
2023-09-22 23:12:37 +02:00
bors 959b2c703d Auto merge of #115696 - RalfJung:closure-ty-print, r=oli-obk
adjust how closure/generator types are printed

I saw `&[closure@$DIR/issue-20862.rs:2:5]` and I thought it is a slice type, because that's usually what `&[_]` is... it took me a while to realize that this is just a confusing printer and actually there's no slice. Let's use something that cannot be mistaken for a regular type.
2023-09-22 15:19:38 +00:00
Eduardo Sánchez Muñoz 17dfabff9c Change start to #[start] in some diagnosis
They refer to a function with the `start` attribute, but not necessarily named `start`.
2023-09-22 15:58:43 +02:00
Ralf Jung c4ec12f4b7 adjust how closure/generator types and rvalues are printed 2023-09-21 22:20:58 +02:00
Eduardo Sánchez Muñoz c599761140 rustc_hir_analysis: add a helper to check function the signature mismatches
This function is now used to check `#[panic_handler]`, `start` lang item, `main`, `#[start]` and intrinsic functions.

The diagnosis produced are now closer to the ones produced by trait/impl method signature mismatch.
2023-09-19 18:15:23 +02:00
Matthias Krüger 0eec5e3d0c
Rollup merge of #115869 - ferrocene:pa-fix-tests-cargo-remap, r=compiler-errors
Avoid blessing cargo deps's source code in ui tests

Before this PR, the source code of dependencies was included in UI test error messages whenever possible. Unfortunately, "whenever possible" means in some cases the source code wouldn't be injected, resulting in a test failure.

One such case is when `$CARGO_HOME` is remapped to something that is not present on disk [^1]. As the remapped path doesn't exist on disk, the source code wouldn't be showed in `tests/ui/issues/issue-21763.rs`:

```diff
    = note: required for `hashbrown::raw::RawTable<(Rc<()>, Rc<()>)>` to implement `Send`
 note: required because it appears within the type `HashMap<Rc<()>, Rc<()>, RandomState>`
   --> $HASHBROWN_SRC_LOCATION
-   |
-LL | pub struct HashMap<K, V, S = DefaultHashBuilder, A: Allocator + Clone = Global> {
-   |            ^^^^^^^
 note: required because it appears within the type `HashMap<Rc<()>, Rc<()>>`
   --> $SRC_DIR/std/src/collections/hash/map.rs:LL:COL
 note: required by a bound in `foo`
```

This PR fixes the problem by always hiding dependencies source code in the error messages generated during UI tests. This is implemented with a new internal flag, `-Z ignore-directory-in-diagnostics-source-blocks=$path`, which compiletest passes during UI tests. Once this is merged, remapping the Cargo home will be supported.

This PR is best reviewed commit-by-commit.

[^1]: After being puzzled for a bit, I discovered why this never impacted `rust-lang/rust`: we don't remap `$CARGO_HOME` 😅. Instead, we set `$CARGO_HOME` to `/cargo` in CI, which sort-of-but-not-really achieves the same effect.
2023-09-19 01:29:41 +02:00
Pietro Albini c230637b92
avoid blessing cargo deps's source code in ui tests 2023-09-15 16:22:52 +02:00
Ralf Jung 9ac8b363e3 don't point at const usage site for resolution-time errors
also share the code that emits the actual error
2023-09-14 22:34:05 +02:00
Ralf Jung 89ac57db4d move required_consts check to general post-mono-check function 2023-09-14 22:30:42 +02:00