Commit Graph

14262 Commits

Author SHA1 Message Date
Michael Goulet
eff865ca76 Fix span issues in object safety suggestions 2022-06-25 14:59:45 -07:00
Matthias Krüger
1f923c2a41
Rollup merge of #98431 - WaffleLapkin:mut_pat_suggestions, r=compiler-errors
Suggest defining variable as mutable on `&mut _` type mismatch in pats

Suggest writing `mut a` where `&mut a` was written but a non-ref type provided.

Since we still don't have "apply either one of the suggestions but not both" kind of thing, the interaction with the suggestion of removing `&[mut]` or moving it to the type is weird, and idk how to make it better..

r? ``@compiler-errors``
2022-06-25 15:14:14 +02:00
Matthias Krüger
ea07b969ea
Rollup merge of #98429 - b-naber:use-correct-substs-discriminant-cast, r=lcnr
Use correct substs in enum discriminant cast

Fixes https://github.com/rust-lang/rust/issues/97634

r? ```@lcnr```
2022-06-25 15:14:13 +02:00
Matthias Krüger
65187f51dc
Rollup merge of #98311 - eggyal:reverse-folder-hierarchy, r=jackh726
Reverse folder hierarchy

#91318 introduced a trait for infallible folders distinct from the fallible version.  For some reason (completely unfathomable to me now that I look at it with fresh eyes), the infallible trait was a supertrait of the fallible one: that is, all fallible folders were required to also be infallible.  Moreover the `Error` associated type was defined on the infallible trait!  It's so absurd that it has me questioning whether I was entirely sane.

This trait reverses the hierarchy, so that the fallible trait is a supertrait of the infallible one: all infallible folders are required to also be fallible (which is a trivial blanket implementation).  This of course makes much more sense!  It also enables the `Error` associated type to sit on the fallible trait, where it sensibly belongs.

There is one downside however: folders expose a `tcx` accessor method.  Since the blanket fallible implementation for infallible folders only has access to a generic `F: TypeFolder`, we need that trait to expose such an accessor to which we can delegate.  Alternatively it's possible to extract that accessor into a separate `HasTcx` trait (or similar) that would then be a supertrait of both the fallible and infallible folder traits: this would ensure that there's only one unambiguous `tcx` method, at the cost of a little additional boilerplate.  If desired, I can submit that as a separate PR.

r? ````@jackh726````
2022-06-25 15:14:11 +02:00
Matthias Krüger
8257ba29ef
Rollup merge of #98298 - TaKO8Ki:point-to-type-param-definition, r=compiler-errors
Point to type parameter definition when not finding variant, method and associated item

fixes #77391
2022-06-25 15:14:10 +02:00
Maybe Waffle
1dfb53b7da improve wording of a suggestion 2022-06-24 21:18:26 +04:00
Waffle Maybe
e25129b055 take advantage of a labelled block
Co-authored-by: Michael Goulet <michael@errs.io>
2022-06-24 21:14:34 +04:00
b-naber
bf48b622a5 fmt 2022-06-24 16:43:38 +02:00
Hood Chatham
ada2accf8e Set relocation_model to Pic on emscripten target 2022-06-24 06:20:46 -07:00
b-naber
f39c0d6b0a address review 2022-06-24 13:43:56 +02:00
b-naber
38814fc039 small refactor 2022-06-24 13:19:23 +02:00
bors
7036449c77 Auto merge of #98447 - JohnTitor:rollup-pponoo3, r=JohnTitor
Rollup of 9 pull requests

Successful merges:

 - #91264 (Add macro support in jump to definition feature)
 - #96955 (Remove (transitive) reliance on sorting by DefId in pretty-printer)
 - #97633 (Session object: Set OS/ABI)
 - #98039 (Fix `panic` message for `BTreeSet`'s `range` API and document `panic` cases)
 - #98214 (rustc_target: Remove some redundant target properties)
 - #98280 (Improve suggestion for calling fn-like expr on type mismatch)
 - #98394 (Fixup missing renames from `#[main]` to `#[rustc_main]`)
 - #98411 (Update tendril)
 - #98419 (Remove excess rib while resolving closures)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-06-24 10:35:00 +00:00
b-naber
2e3221a927 use correct substs in enum discriminant hack 2022-06-24 11:11:40 +02:00
Yuki Okushi
5e98e55668
Rollup merge of #98419 - WaffleLapkin:remove_excess_rib, r=compiler-errors
Remove excess rib while resolving closures

I've mentioned this on [zulip](https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/.60ClosureOrAsyncRibKind.60.20weirdness/near/286982959), in `rustc_resolve`, while resolving closures we add an excess `ClosureOrAsyncRibKind`. It's excess because we later add another one in `visit_fn`.

I couldn't find a way in which removing this will break anything, all test seem to pass, etc.

r? ``@compiler-errors``
cc ``@davidtwco``
2022-06-24 16:43:49 +09:00
Yuki Okushi
f3078d0f44
Rollup merge of #98394 - Enselic:fixup-rustc_main-renames, r=petrochenkov
Fixup missing renames from `#[main]` to `#[rustc_main]`

In #84217 `#[main]` was removed and replaced with `#[rustc_main]`. In some places the rename was forgotten, which makes the current code confusing, because at first glance it seems that `#[main]` is still around. Perform the renames also in these places.

I noticed this (after first being confused by it) when working on #97802.

r? `@petrochenkov`

(since you reviewed the other PR)
2022-06-24 16:43:47 +09:00
Yuki Okushi
964fc41b89
Rollup merge of #98280 - compiler-errors:better-call-closure-on-type-err, r=estebank
Improve suggestion for calling fn-like expr on type mismatch

1.) Suggest calling values of with RPIT types (and probably TAIT) when we expect `Ty` and have `impl Fn() -> Ty`
2.) Suggest calling closures even when they're not assigned to a local variable first
3.) Drive-by fix of a pretty-printing bug (`impl Fn()-> Ty` => `impl Fn() -> Ty`)

r? ```@estebank```
2022-06-24 16:43:46 +09:00
Yuki Okushi
33eb3c05c5
Rollup merge of #98214 - petrochenkov:islike, r=compiler-errors
rustc_target: Remove some redundant target properties

`is_like_emscripten` is equivalent to `os == "emscripten"`, so it's removed.
`is_like_fuchsia` is equivalent to `os == "fuchsia"`, so it's removed.
`is_like_osx` also falls into the same category and is equivalent to `vendor == "apple"`, but it's commonly used so I kept it as is for now.

`is_like_(solaris,windows,wasm)` are combinations of different operating systems or architectures (see compiler/rustc_target/src/spec/tests/tests_impl.rs) so they are also kept as is.

I think `is_like_wasm` (and maybe `is_like_osx`) are sufficiently closed sets, so we can remove these fields as well and replace them with methods like `fn is_like_wasm() { arch == "wasm32" || arch == "wasm64" }`.
On other hand, `is_like_solaris` and `is_like_windows` are sufficiently open and I can imagine custom targets introducing other values for `os`.
This is kind of a gray area.
2022-06-24 16:43:45 +09:00
Yuki Okushi
0af99c99c4
Rollup merge of #97633 - mkroening:object-osabi, r=petrochenkov
Session object: Set OS/ABI

Closes https://github.com/rust-lang/rust/issues/97535.

This depends on
* https://github.com/gimli-rs/object/pull/438

This adapts LLVM's behavior of [`MCELFObjectTargetWriter::getOSABI`](8c8a2679a2/llvm/include/llvm/MC/MCELFObjectWriter.h (L72-L86)).
2022-06-24 16:43:43 +09:00
Yuki Okushi
2c6feb51da
Rollup merge of #96955 - Aaron1011:pretty-print-sort, r=petrochenkov
Remove (transitive) reliance on sorting by DefId in pretty-printer

This moves us a step closer to removing the `PartialOrd/`Ord` impls
for `DefId`. See #90317
2022-06-24 16:43:42 +09:00
Yuki Okushi
97f4d7bd2c
Rollup merge of #91264 - GuillaumeGomez:macro-jump-to-def, r=jsha
Add macro support in jump to definition feature

Fixes #91174.

To do so, I check if the span comes from an expansion, and if so, I infer the original macro `DefId` or `Span` depending if it's a defined in the current crate or not.

There is one limitation due to macro expansion though:

```rust
macro_rules! yolo { () => {}}

fn foo() {
    yolo!();
}
```

In `foo`, `yolo!` won't be linked because after expansion, it is replaced by nothing (which seems logical). So I can't get an item from the `Visitor` from which I could tell if its `Span` comes from an expansion.

I added a test for this specific limitation alongside others.

Demo: https://rustdoc.crud.net/imperio/macro-jump-to-def/src/foo/check-source-code-urls-to-def-std.rs.html

As for the empty macro issue that cannot create a jump to definition, you can see it [here](https://rustdoc.crud.net/imperio/macro-jump-to-def/src/foo/check-source-code-urls-to-def-std.rs.html#35).

r? ```@jyn514```
2022-06-24 16:43:41 +09:00
bors
d017d59ed0 Auto merge of #98109 - nikomatsakis:issue-98095, r=jackh726
fix universes in the NLL type tests

In the NLL code, we were not accommodating universes in the
`type_test` logic.

Fixes #98095.

r? `@compiler-errors`

This breaks some tests, however, so the purpose of this branch is more explanatory and perhaps to do a crater run.
2022-06-24 07:39:28 +00:00
Michael Goulet
aafddd2a8a
Rollup merge of #98388 - rosehuds:master, r=davidtwco
implement `iter_projections` function on `PlaceRef`

this makes the api more flexible. the original function now calls the PlaceRef
version to avoid duplicating the code.
2022-06-23 14:39:15 -07:00
Michael Goulet
667a54623d
Rollup merge of #98365 - jyn514:improve-obligation-errors-review-comments, r=eholk
Address review comments from #98259

It got approved so fast I didn't have time to make changes xD

r? ``@eholk``
2022-06-23 14:39:14 -07:00
Michael Goulet
cc45ad50f8
Rollup merge of #98355 - hoodmane:emscripten-no-default, r=petrochenkov
Update no_default_libraries handling for emscripten target

```@sbc100``` says:

> `-sDEFAULT_LIBRARY_FUNCS_TO_INCLUDE=[]` is almost certainly wrong/out-of-date.   This setting defaults to the empty list anyway these days so its redundant.  Also we now support `-nodefaultlibs` so you can use that, as with other toolchains.

https://github.com/rust-lang/rust/issues/98303#issuecomment-1162163684
2022-06-23 14:39:12 -07:00
Michael Goulet
21085e9120
Rollup merge of #98353 - beetrees:builtin-macros-cfg-diag, r=davidtwco
Migrate two diagnostics from the `rustc_builtin_macros` crate

Migrate two diagnostics to use the struct derive and be translatable.

r? ```@davidtwco```
2022-06-23 14:39:11 -07:00
Michael Goulet
0ed2feca61
Rollup merge of #98305 - klensy:no-err-alloc, r=compiler-errors
prohibit_generics: don't alloc error string if no error emitted

Noticed unreaded allocs in DHAT.
2022-06-23 14:39:09 -07:00
Michael Goulet
41cb5e9439
Rollup merge of #98283 - TaKO8Ki:point-at-private-fields-in-struct-literal, r=compiler-errors
Point at private fields in struct literal

closes #95872
2022-06-23 14:39:08 -07:00
Michael Goulet
3b68700d0c
Rollup merge of #98269 - compiler-errors:provide-more-segment-res, r=petrochenkov
Provide a `PathSegment.res` in more cases

I find that in many cases, the `res` associated with a `PathSegment` is `Res::Err` even though the path was fully resolved. A few diagnostics use this `res` and their error messages suffer because of the lack of resolved segment.

This fixes it a bit, but it's obviously not complete and I'm not exactly sure if it's correct.
2022-06-23 14:39:07 -07:00
Michael Goulet
413e350f87
Rollup merge of #98259 - jyn514:improve-obligation-errors, r=estebank
Greatly improve error reporting for futures and generators in `note_obligation_cause_code`

Most futures don't go through this code path, because they're caught by
`maybe_note_obligation_cause_for_async_await`. But all generators do,
and `maybe_note` is imperfect and doesn't catch all futures. Improve the error message for those it misses.

At some point, we may want to consider unifying this with the code for `maybe_note_async_await`,
so that `async_await` notes all parent constraints, and `note_obligation` can point to yield points.
But both functions are quite complicated, and it's not clear to me how to combine them;
this seems like a good incremental improvement.

Helps with https://github.com/rust-lang/rust/issues/97332.

r? ``@estebank`` cc ``@eholk`` ``@compiler-errors``
2022-06-23 14:39:06 -07:00
Michael Goulet
49bcc70574
Rollup merge of #98184 - compiler-errors:elided-lifetime-in-impl-nll, r=cjgillot
Give name if anonymous region appears in impl signature

Fixes #98170

We probably should remove the two unwraps in [`report_general_error`](https://doc.rust-lang.org/nightly/nightly-rustc/src/rustc_borrowck/diagnostics/region_errors.rs.html#683-685), but I have no idea what to provide if those regions are missing, so I've kept those in. Let me know if I should try harder to remove those.
2022-06-23 14:39:06 -07:00
Niko Matsakis
e93e10516e run x.py fmt 2022-06-23 17:00:46 -04:00
Niko Matsakis
9118fafd40 remove misleading comment
per aliemjay's suggestion
2022-06-23 17:00:28 -04:00
Niko Matsakis
d8337ee2f4 try to clarify confusing comment 2022-06-23 17:00:28 -04:00
Niko Matsakis
c3137d9e8c normalize if-eq bounds before testing
Hat-tip: aliemjay
2022-06-23 17:00:28 -04:00
Niko Matsakis
e6b630c5b1
apply suggestions from oli-obk
Co-authored-by: Oli Scherer <github35764891676564198441@oli-obk.de>
2022-06-23 16:40:06 -04:00
Niko Matsakis
c9bf88ccf9 coallesce docs 2022-06-23 16:38:24 -04:00
Niko Matsakis
27e0f7a886 rename IfEqBound to IfEq 2022-06-23 16:35:47 -04:00
Niko Matsakis
893b919e64 remove VerifyBound::IfEq variant 2022-06-23 16:28:46 -04:00
Maybe Waffle
3c7f1f1601 Suggest defining variable as mutable on &mut _ type mismatch in pats 2022-06-23 21:16:32 +04:00
Martin Kröning
21625e5730 Session object: Set OS/ABI
This adapts LLVM's behavior of MCELFObjectTargetWriter::getOSABI [1].

[1]: 8c8a2679a2/llvm/include/llvm/MC/MCELFObjectWriter.h (L72-L86)
2022-06-23 11:20:52 +02:00
Maybe Waffle
9730221b9d Remove excess rib while resolving closures 2022-06-23 12:21:23 +04:00
Hood Chatham
b96ae9b204 Set no_default_libraries: false in wasm32_emscripten target 2022-06-22 17:43:10 -07:00
Aaron Hill
36ccdbefbb
Remove (transitive) reliance on sorting by DefId in pretty-printer
This moves us a step closer to removing the `PartialOrd/`Ord` impls
for `DefId`. See #90317
2022-06-22 12:58:56 -05:00
Martin Nordholts
94477e3323 Fixup missing renames from #[main] to #[rustc_main]
In fc357039f9 `#[main]` was removed and replaced with `#[rustc_main]`.
In some place the rename was forgotten, which makes the current code
confusing, because at first glance it seems that `#[main]` is still
around. Perform the renames also in these places.
2022-06-22 18:24:09 +02:00
Rose Hudson
53481a5a8f implement iter_projections function on PlaceRef
this makes the api more flexible. the original function now calls the PlaceRef
version to avoid duplicating the code.
2022-06-22 14:06:13 +01:00
bors
10f4ce324b Auto merge of #98279 - cjgillot:all-fresh-nofn, r=petrochenkov
Create elided lifetime parameters for function-like types

Split from https://github.com/rust-lang/rust/pull/97720

This PR refactor lifetime generic parameters in bare function types and parenthesized traits to introduce the additional required lifetimes as fresh parameters in a `for<>` bound.

This PR does the same to lifetimes appearing in closure signatures, and as-if introducing `for<>` bounds on closures (without the associated change in semantics).

r? `@petrochenkov`
2022-06-22 10:48:58 +00:00
Yuki Okushi
8f861dae7a
Rollup merge of #97895 - nbdd0121:unlikely, r=estebank
Simplify `likely!` and `unlikely!` macro

The corresponding intrinsics have long been safe-to-call, so the unsafe block is no longer needed.
2022-06-22 15:16:13 +09:00
Yuki Okushi
dfc6d7ac76
Rollup merge of #97818 - compiler-errors:rpit-error-spanned, r=oli-obk
Point at return expression for RPIT-related error

Certainly this needs some diagnostic refining, but I wanted to show that it was possible first and foremost. Not sure if this is the right approach. Open to feedback.

Fixes #80583
2022-06-22 15:16:12 +09:00
Takayuki Maeda
eb86daa138 add "was" to pluralize macro and use it 2022-06-22 14:56:40 +09:00
Takayuki Maeda
402dceba99 point to type param definition when not finding variant, method and assoc type
use `def_ident_span` , `body_owner_def_id` instead of `in_progress_typeck_results`, `guess_head_span`

use `body_id.owner` directly

add description to label
2022-06-22 13:40:20 +09:00