Commit Graph

2234 Commits

Author SHA1 Message Date
Vadim Petrochenkov
5b5964f569 rustc: Panic by default in DefIdTree::parent
Only crate root def-ids don't have a parent, and in majority of cases the argument of `DefIdTree::parent` cannot be a crate root.
So we now panic by default in `parent` and introduce a new non-panicing function `opt_parent` for cases where the argument can be a crate root.

Same applies to `local_parent`/`opt_local_parent`.
2022-05-02 01:56:50 +03:00
Camille GILLOT
74583852e8 Save colon span to suggest bounds. 2022-04-30 13:55:17 +02:00
Camille GILLOT
94449e6101 Store all generic bounds as where predicates. 2022-04-30 13:55:13 +02:00
Camille GILLOT
05b29f9a92 Inline WhereClause into Generics. 2022-04-30 13:51:49 +02:00
Camille GILLOT
71b4e2d852 Box HIR Generics and Impl. 2022-04-30 13:51:49 +02:00
Esteban Kuber
09f3ea1692 When encountering a binding that could be a const or unit variant, suggest the right path 2022-04-30 02:27:25 +00:00
bors
a707f40107 Auto merge of #95819 - oli-obk:mir_can't_hold_all_these_lifetimes, r=estebank
Enforce Copy bounds for repeat elements while considering lifetimes

fixes https://github.com/rust-lang/rust/issues/95477

this is a breaking change in order to fix a soundness bug.

Before this PR we only checked whether the repeat element type had an `impl Copy`, but not whether that impl also had the appropriate lifetimes. E.g. if the impl was for `YourType<'static>` and not a general `'a`, then copying any type other than a `'static` one should have been rejected, but wasn't.

r? `@lcnr`
2022-04-29 20:00:47 +00:00
Oli Scherer
67ce547f47 Refactor and document the repeat length check 2022-04-29 18:56:57 +00:00
Oli Scherer
be54947315 Extract copy bound check into a function 2022-04-29 18:49:02 +00:00
bors
683c582c1e Auto merge of #96468 - davidtwco:diagnostic-translation-subdiagnostic, r=oli-obk
macros: subdiagnostic derive

Add a new macro, `#[derive(SessionSubdiagnostic)]`, which can be applied to structs that represent subdiagnostics, such as labels, notes, helps or suggestions.

`#[derive(SessionSubdiagnostic)]` can be used with the existing `#[derive(SessionDiagnostic)]`. All diagnostics implemented using either derive are translatable, and this new derive should make it easier to port existing diagnostics to using these derives.

For example, consider the following subdiagnostic types...

```rust
#[derive(SessionSubdiagnostic)]
pub enum ExpectedIdentifierLabel<'tcx> {
    #[label(slug = "parser-expected-identifier")]
    WithoutFound {
        #[primary_span]
        span: Span,
    }
    #[label(slug = "parser-expected-identifier-found")]
    WithFound {
        #[primary_span]
        span: Span,
        found: String,
    }
}

#[derive(SessionSubdiagnostic)]
#[suggestion_verbose(slug = "parser-raw-identifier")]
pub struct RawIdentifierSuggestion<'tcx> {
    #[primary_span]
    span: Span,
    #[applicability]
    applicability: Applicability,
    ident: Ident,
}
```

...and the corresponding Fluent messages:

```fluent
parser-expected-identifier = expected identifier

parser-expected-identifier-found = expected identifier, found {$found}

parser-raw-identifier = escape `{$ident}` to use it as an identifier
```

These can be emitted using the new `subdiagnostic` function on `Diagnostic`...

```rust
diag.subdiagnostic(ExpectedIdentifierLabel::WithoutFound { span });
diag.subdiagnostic(RawIdentifierSuggestion { span, applicability, ident });
```

...or as part of a larger `#[derive(SessionDiagnostic)]`:

```rust
#[derive(SessionDiagnostic)]
#[error(slug = "parser-expected-identifier")]
pub struct ExpectedIdentifier {
    #[primary_span]
    span: Span,
    token_descr: String,
    #[subdiagnostic]
    label: ExpectedIdentifierLabel,
    #[subdiagnostic]
    raw_identifier_suggestion: Option<RawIdentifierSuggestion>,
}
```

```rust
sess.emit_err(ExpectedIdentifier { ... });
```

r? `@oli-obk`
cc `@pvdrz`
2022-04-29 11:58:24 +00:00
David Wood
49ec909ca7 macros: subdiagnostic derive
Add a new derive, `#[derive(SessionSubdiagnostic)]`, which enables
deriving structs for labels, notes, helps and suggestions.

Signed-off-by: David Wood <david.wood@huawei.com>
2022-04-29 02:05:20 +01:00
Oli Scherer
d22c439989 Revert diagnostic duplication and accidental stabilization 2022-04-28 13:25:36 +00:00
Oli Scherer
4e6e68e27a Check that repeat expression elements are Copy (ignoring lifetimes) in typeck and that they are Copy (with proper lifetime checks) in borrowck 2022-04-28 09:19:42 +00:00
Dylan DPC
4c628bbb1c
Rollup merge of #96471 - BoxyUwU:let_else_considered_harmful, r=lcnr
replace let else with `?`

r? `@oli-obk`
2022-04-28 02:40:36 +02:00
Dylan DPC
4a7483c905
Rollup merge of #96377 - compiler-errors:infer-rustfix, r=petrochenkov
make `fn() -> _ { .. }` suggestion MachineApplicable

This might not be valid, but it would be nice to promote this to `MachineApplicable` so people can use rustfix here.

Also de65fcf009d07019689cfad7f327667e390a325d is to [restore the suggestion for `issue-77179.rs`](de65fcf009 (diff-12e43fb5d6d12ec7cb5c6b48204a18d113cf5de0e12eb71a358b639bd9aadaf0R8)). (though in this case, the code in that issue still doesn't compile, so it's not marked with rustfix).
2022-04-28 02:40:32 +02:00
Ellen
f697955c1e tut tut tut 2022-04-27 08:51:33 +01:00
Michael Goulet
f9e7489f87 TAITs are suggestable 2022-04-26 18:55:55 -07:00
Michael Goulet
ae42f22ba0 make fn() -> _ {} suggestion MachineApplicable 2022-04-26 18:50:46 -07:00
Dylan DPC
5645732b04
Rollup merge of #96383 - compiler-errors:issue-96381, r=estebank
Fix erased region escaping into wfcheck due to #95395

We can just use `liberate_late_bound_regions` instead of `erase_late_bound_regions`... This gives us `ReEarlyBound` instead of `ReErased`, the former being something typeck actually knows how to deal with...

Fixes #96381

Side-note: We only actually get far enough in the compiler pipeline to cause this ICE when we're invoking rustdoc. We actually abort rustc right before wfcheck because of the error that we emit (having `_` in the type signature). Why does rustdoc keep going even though we raise an error?
2022-04-27 02:47:10 +02:00
Dylan DPC
e63da0ba00
Rollup merge of #96370 - compiler-errors:cleanup-report_method_error, r=estebank
Cleanup `report_method_error` a bit

1. Remove an unnecessary indentation level
2. Split out a couple of large functions from this humongo function body
2022-04-27 02:47:07 +02:00
George
14a127be3e Add new diagnostic 2022-04-26 17:04:44 -04:00
Guillaume Gomez
bb6265a739
Rollup merge of #96372 - compiler-errors:field-method-suggest, r=oli-obk
Suggest calling method on nested field when struct is missing method

Similar to the suggestion to change `x.field` to `x.nested.field`, implement a similar suggestion for when `x.method()` should be replaced with `x.nested.method()`.
2022-04-26 13:22:29 +02:00
bors
d6a57d3730 Auto merge of #94034 - willcrichton:fix-trait-suggestion-for-binops, r=estebank
Fix incorrect suggestion for trait bounds involving binary operators

This PR fixes #93927, #92347, #93744 by replacing the bespoke trait-suggestion logic in `op.rs` with a more common code path.

The downside is that this fix causes some suggestions to not include an `Output=` type, reducing their usefulness.

Note that this causes one case in the `missing-bounds.rs` test to fail rustfix. So I would need to move that code into a separate non-fix test if this PR is otherwise acceptable.
2022-04-26 07:29:15 +00:00
Will Crichton
dc41dbaf8e Update unop path, fix tests 2022-04-25 19:14:09 -07:00
Will Crichton
4d0fe27896 Replace suggest_constraining_param with suggest_restricting_param_bound
to fix incorrect suggestion for trait bounds involving binary operators.
Fixes #93927, #92347, #93744.
2022-04-25 18:12:15 -07:00
Michael Goulet
8a28aa48d2 Fix issue 96381 2022-04-25 13:31:53 -07:00
Preston From
5165295452 Delay bug when adjusting NeverToAny twice during diagnostic 2022-04-24 23:52:55 -06:00
Michael Goulet
dff7f25981 suggestion if struct field has method 2022-04-24 16:47:19 -07:00
Michael Goulet
2da65da5a7 pull some methods out of report_method_error 2022-04-24 15:41:20 -07:00
Michael Goulet
875cd8930e remove indentation in report_method_error 2022-04-24 15:05:06 -07:00
Michael Goulet
319fbe371d Fix suggestion for _ on return type for fn in impl for Trait 2022-04-24 14:50:48 -07:00
Michael Goulet
42dbbabcb0 Suggest replacing _ in type signature of impl for Trait 2022-04-24 14:49:29 -07:00
Camille GILLOT
4bbe078d92 Drop vis in Item. 2022-04-23 09:59:24 +02:00
Camille GILLOT
10d10efb21 Stop visiting visibility. 2022-04-23 09:53:45 +02:00
Matthias Krüger
b100c02fae
Rollup merge of #96273 - TaKO8Ki:make-E0117-error-clear, r=davidtwco
Make `E0117` error clear

closes #96227
2022-04-22 18:56:25 +02:00
Takayuki Maeda
f5a8ee4dd8 remove an error for type params 2022-04-22 11:25:42 +09:00
Dylan DPC
5ebb8b06d6
Rollup merge of #96289 - aDotInTheVoid:redundant-fmt, r=jackh726
Remove redundant `format!`s
2022-04-21 20:55:21 +02:00
Nixon Enraght-Moony
8fa20e01a5 Remove redundant format!s 2022-04-21 16:46:20 +01:00
Takayuki Maeda
547cb2722b make E0117 error clear 2022-04-21 16:47:01 +09:00
David Wood
437468daf7 typeck: remove unnecessary fluent attr
Specifying "suggestion" as the attribute for the only suggestion is
unnecessary, it's the default of the derive.

Signed-off-by: David Wood <david.wood@huawei.com>
2022-04-21 04:03:13 +01:00
Dylan DPC
036d200d1c
Rollup merge of #96122 - TaKO8Ki:fix-invalid-error-for-suggestion-to-add-slice-in-pattern-matching, r=nagisa
Fix an invalid error for a suggestion to add a slice in pattern-matching

closes #96103
2022-04-19 14:43:20 +02:00
bors
e2661bac6d Auto merge of #95379 - icewind1991:suggest-associated-type-more, r=jackh726
show suggestion to replace generic bounds with associated types in more cases

Moves the hint to replace generic parameters with associated type bounds from the "not all associated type bounds are specified"(`E0191`) to "to many generic type parameters provided"(`E0107`).

Since `E0191` is only emitted in places where all associated types must be specified (when creating `dyn` types), the suggesting is currently not shown for other generic type uses (such as in generic type bounds). With this change the suggesting is always emitted when the number of excess generic parameters matches the number of unbound associated types.

Main motivation for the change was a lack of useful suggesting when doing

```rust
fn foo<I: Iterator<usize>>(i: I) {}
```
2022-04-19 01:59:35 +00:00
Takayuki Maeda
5924ef874e stop using Autoderef 2022-04-18 12:51:12 +09:00
bors
edba282770 Auto merge of #95655 - kckeiks:create-hir-crate-items-query, r=cjgillot
Refactor HIR item-like traversal (part 1)

Issue  #95004

- Create hir_crate_items query which traverses tcx.hir_crate(()).owners to return a hir::ModuleItems
- use tcx.hir_crate_items in tcx.hir().items() to return an iterator of hir::ItemId
- use tcx.hir_crate_items to introduce a tcx.hir().par_items(impl Fn(hir::ItemId)) to traverse all items in parallel;

Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>

cc `@cjgillot`
2022-04-17 08:06:53 +00:00
Robin Appelman
decc04dbfb show suggestion to replace generic bounds with associated types in more cases 2022-04-17 00:44:36 +02:00
Dylan DPC
99437b303a
Rollup merge of #96112 - niluxv:strict-provenance-lint-improvements, r=nagisa
Strict provenance lint diagnostics improvements

Use `multipart_suggestion` instead of `span_suggestion` and getting a snippet for the expression. Also don't suggest unnecessary parenthesis in `lossy_provenance_casts`.
cc ``@estebank``
``@rustbot`` label A-diagnostics
2022-04-17 00:07:26 +02:00
Takayuki Maeda
a59cc5774b fix an invalid error for a suggestion to add a slice in pattern-matching 2022-04-17 01:20:11 +09:00
bors
c8422403f7 Auto merge of #96108 - Dylan-DPC:rollup-t5f2fc9, r=Dylan-DPC
Rollup of 9 pull requests

Successful merges:

 - #93969 (Only add codegen backend to dep info if -Zbinary-dep-depinfo is used)
 - #94605 (Add missing links in platform support docs)
 - #95372 (make unaligned_references lint deny-by-default)
 - #95859 (Improve diagnostics for unterminated nested block comment)
 - #95961 (implement SIMD gather/scatter via vector getelementptr)
 - #96004 (Consider lifetimes when comparing types for equality in MIR validator)
 - #96050 (Remove some now-dead code that was only relevant before deaggregation.)
 - #96070 ([test] Add test cases for untested functions for BTreeMap)
 - #96099 (MaybeUninit array cleanup)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-04-16 09:19:26 +00:00
niluxv
1d63d6db55 Improve fuzzy_provenance_casts lint diagnostics
Use `multipart_suggestion` instead of getting a snippet.
2022-04-16 10:40:06 +02:00
niluxv
02d12bc30c Improve lossy_provenance_casts lint diagnostics
Use `multipart_suggestion` and don't suggested unnecessary parenthesis.
2022-04-16 10:32:37 +02:00