Commit graph

2061 commits

Author SHA1 Message Date
Dylan DPC 270a41c33e
Rollup merge of #94960 - codehorseman:master, r=oli-obk
Fix many spelling mistakes

Signed-off-by: codehorseman <cricis@yeah.net>
2022-03-17 22:55:05 +01:00
Dylan DPC 8499a8ba88
Rollup merge of #94309 - eholk:issue-57017, r=tmandry
[generator_interior] Be more precise with scopes of borrowed places

Previously the generator interior type checking analysis would use the nearest temporary scope as the scope of a borrowed value. This ends up being overly broad for cases such as:

```rust
fn status(_client_status: &Client) -> i16 {
    200
}

fn main() {
    let client = Client;
    let g = move || match status(&client) {
        _status => yield,
    };
    assert_send(g);
}
```

In this case, the borrow `&client` could be considered in scope for the entirety of the `match` expression, meaning it would be viewed as live across the `yield`, therefore making the generator not `Send`.

In most cases, we want to use the enclosing expression as the scope for a borrowed value which will be less than or equal to the nearest temporary scope. This PR changes the analysis to use the enclosing expression as the scope for most borrows, with the exception of borrowed RValues which are true temporary values that should have the temporary scope. There's one further exception where borrows of a copy such as happens in autoref cases also should be ignored despite being RValues.

Joint work with `@nikomatsakis`

Fixes #57017

r? `@tmandry`
2022-03-17 22:55:02 +01:00
Dylan DPC 07121c88ad
Rollup merge of #93745 - tarcieri:stabilize-adx, r=cjgillot
Stabilize ADX target feature

This is a continuation of #60109, which noted that while the ADX intrinsics were stabilized, the corresponding target feature never was.

This PR follows the same general structure and stabilizes the ADX target feature.

See also https://github.com/rust-lang/rust/issues/44839 - tracking issue for target feature
2022-03-17 22:55:01 +01:00
mark bb8d4307eb rustc_error: make ErrorReported impossible to construct
There are a few places were we have to construct it, though, and a few
places that are more invasive to change. To do this, we create a
constructor with a long obvious name.
2022-03-16 10:35:24 -05:00
codehorseman 01dbfb3eb2 resolve the conflict in compiler/rustc_session/src/parse.rs
Signed-off-by: codehorseman <cricis@yeah.net>
2022-03-16 20:12:30 +08:00
bors f21488a12c Auto merge of #94925 - lcnr:relax-sus-auto-impls, r=estebank
relax `suspicious_auto_trait_impls` lint wrt lifetimes

fixes the warning for https://github.com/rust-lang/rust/issues/93367#issuecomment-1063993489.
2022-03-15 22:54:35 +00:00
Matthias Krüger 183262d8d3
Rollup merge of #94958 - est31:pluralize, r=oli-obk
Support other types of pluralization in pluralize macro
2022-03-15 17:15:55 +01:00
est31 3bf9124f14 Support other types of pluralization in pluralize macro 2022-03-15 15:37:49 +01:00
bors 95561b336c Auto merge of #94584 - pnkfelix:inject-use-suggestion-sites, r=ekuber
More robust fallback for `use` suggestion

Our old way to suggest where to add `use`s would first look for pre-existing `use`s in the relevant crate/module, and if there are *no* uses, it would fallback on trying to use another item as the basis for the suggestion.

But this was fragile, as illustrated in issue #87613

This PR instead identifies span of the first token after any inner attributes, and uses *that* as the fallback for the `use` suggestion.

Fix #87613
2022-03-15 03:56:33 +00:00
Tony Arcieri 78567df575 Stabilize ADX target feature
This is a continuation of #60109, which noted that while the ADX
intrinsics were stabilized, the corresponding target feature never was.

This PR follows the same general structure and stabilizes the ADX target
feature.
2022-03-14 18:56:39 -06:00
Matthias Krüger 0e423932f8
Rollup merge of #90621 - adamgemmell:dev/stabilise-target-feature, r=Amanieu
Stabilise `aarch64_target_feature`

This PR stabilises `aarch64_target_feature` - see https://github.com/rust-lang/rust/issues/90620
2022-03-14 17:24:56 +01:00
Adam Gemmell 5a5621791f Stabilise aarch64_target_feature 2022-03-14 11:02:50 +00:00
lcnr 82d8e8420b relax suspicious_auto_trait_impls lint 2022-03-14 09:07:49 +01:00
Devin Ragotzy c0e76d6999 Format reordered imports in tyck/pat 2022-03-12 15:16:11 -05:00
Devin Ragotzy 7ffb29d03c Only filter doc(hidden) fields/variants when not crate local 2022-03-12 15:16:11 -05:00
Devin Ragotzy 8663ee19e4 Fix omitted_patterns lint showing unstable/doc hidden fields 2022-03-12 15:02:42 -05:00
bors 258256697b Auto merge of #94870 - notriddle:notriddle/filter-regression, r=oli-obk
diagnostics: do not spurriously claim something is "not an iterator"

Fixes a minor regression caused by #94746, where `iter::Filter` is spurriously declared "not an iterator."
2022-03-12 11:58:07 +00:00
bors 012720ffb0 Auto merge of #94733 - nnethercote:fix-AdtDef-interning, r=fee1-dead
Improve `AdtDef` interning.

This commit makes `AdtDef` use `Interned`. Much of the commit is tedious
changes to introduce getter functions. The interesting changes are in
`compiler/rustc_middle/src/ty/adt.rs`.

r? `@fee1-dead`
2022-03-12 07:02:05 +00:00
Michael Howell 317f684160 diagnostics: do not spurriously claim something is "not an iterator"
Fixes a minor regression caused by #94746, where iter::Filter is
spurriously declared "not an iterator."
2022-03-11 16:59:32 -07:00
Nicholas Nethercote ca5525d564 Improve AdtDef interning.
This commit makes `AdtDef` use `Interned`. Much the commit is tedious
changes to introduce getter functions. The interesting changes are in
`compiler/rustc_middle/src/ty/adt.rs`.
2022-03-11 13:31:24 +11:00
Eric Holk 2fcd542734 Remove is_autoref parameter 2022-03-10 17:24:08 -08:00
Eric Holk 12d8ca113c Use projections rather than is_autoref
Also includes a lengthy comment arguing the correctness.

Co-authored-by: Niko Matsakis <niko@alum.mit.edu>
2022-03-10 17:14:50 -08:00
T-O-R-U-S 72a25d05bf Use implicit capture syntax in format_args
This updates the standard library's documentation to use the new syntax. The
documentation is worthwhile to update as it should be more idiomatic
(particularly for features like this, which are nice for users to get acquainted
with). The general codebase is likely more hassle than benefit to update: it'll
hurt git blame, and generally updates can be done by folks updating the code if
(and when) that makes things more readable with the new format.

A few places in the compiler and library code are updated (mostly just due to
already having been done when this commit was first authored).
2022-03-10 10:23:40 -05:00
Matthias Krüger e7281d08de
Rollup merge of #94746 - notriddle:notriddle/method-rustc-on-unimplemented, r=davidtwco
diagnostics: use rustc_on_unimplemented to recommend `[].iter()`

To make this work, the `#[rustc_on_unimplemented]` data needs to be used to
report method resolution errors, which is most of what this commit does.

Fixes #94581
2022-03-10 12:20:53 +01:00
Matthias Krüger 7473750b13
Rollup merge of #92150 - compiler-errors:better_usize_to_wide_ptr_cast, r=petrochenkov
Improve suggestion when casting usize to (possibly) wide pointer

I thought #92125 was a wonderful idea, so I went ahead and took a stab at it. Not sure if my approach is the best going forward, but I'm happy with the improvement in the error message.

Iwill definitely address any changes if people are more opinionated with the wordings or want more features.

Also, do I need to add a new error code?

(Fixes #92125)
2022-03-10 12:20:50 +01:00
bors 85ce7fdfa2 Auto merge of #94737 - lcnr:pass-stuff-by-value, r=davidtwco
add `#[rustc_pass_by_value]` to more types

the only interesting changes here should be to `TransitiveRelation`, but I believe to be highly unlikely that we will ever use a non `Copy` type with this type.
2022-03-10 00:15:39 +00:00
Michael Goulet 814c18a6dc better suggestion for int to wide ptr cast 2022-03-09 15:34:39 -08:00
Michael Howell 32d7f8145a diagnostics: use rustc_on_unimplemented to recommend [].iter()
To make this work, the `#[rustc_on_unimplemented]` data needs to be used to
report method resolution errors, which is most of what this commit does.

Fixes #94581
2022-03-09 09:52:55 -07:00
Dylan DPC 568736b98f
Rollup merge of #94689 - compiler-errors:on-unimplemented-substs, r=petrochenkov
Use impl substs in `#[rustc_on_unimplemented]`

We were using the trait-ref substs instead of impl substs in `rustc_on_unimplemented`, even when computing the `rustc_on_unimplemented` attached to an impl block. Let's not do that.

This PR also untangles impl and trait def-ids in the logic in `on_unimplemented` a bit.

Fixes #94675
2022-03-08 22:43:56 +01:00
lcnr b8135fd5c8 add #[rustc_pass_by_value] to more types 2022-03-08 15:39:52 +01:00
Felix S. Klock II 4a0c2b2aba Add a FIXME explaining how one could go about fixing this code to bring it in
sync with the method added in PR 94584.
2022-03-07 17:17:15 -05:00
Michael Howell fbd4cfa0f8 diagnostics: only talk about Cargo.toml if running under Cargo
Fixes #94646
2022-03-07 10:54:17 -07:00
Eric Holk 170b027022 Add comments based on code review feedback 2022-03-07 09:43:28 -08:00
Eric Holk 87ad6683d6 Distinguish borrows of copies from other borrows 2022-03-07 09:43:27 -08:00
Eric Holk ac804f27a8 Trying to detect autorefs to avoid unnecessary borrowed temporaries
This is all almost certainly wrong
2022-03-07 09:43:27 -08:00
Niko Matsakis 60f5cad6eb try to fix issue 57017, but not quite there yet
Co-authored-by: Eric Holk <eric@theincredibleholk.org>
2022-03-07 09:43:25 -08:00
Matthias Krüger 02539e1612
Rollup merge of #94676 - TaKO8Ki:remove-unnecessary-pattens-for-ignoring-remaining-parts, r=Dylan-DPC
Remove unnecessary `..` patterns

This patch removes unnecessary `..` patterns.
2022-03-07 06:44:03 +01:00
Matthias Krüger 9c7ff1add7
Rollup merge of #94636 - compiler-errors:issue-94599, r=davidtwco
Check extra function arg exprs even if the fn is not C-variadic

We should still call check_expr on the args that exceed the formal input ty count, so that we have expr types to emit during writeback.

Not sure where this regressed, but it wasn't due to the same root cause as #94334 I think. I thought this might've regressed in #92360, but I think that is in stable, ad the test I provided (which minimizes #94599) passes on stable in playground. Maybe it regressed in #93118.

Anywho, fixes #94599.
2022-03-07 06:44:02 +01:00
Michael Goulet b726bfb569 allow referencing impl substs from rustc_on_unimplemented 2022-03-06 19:51:30 -08:00
Nicholas Nethercote 4852291417 Introduce ConstAllocation.
Currently some `Allocation`s are interned, some are not, and it's very
hard to tell at a use point which is which.

This commit introduces `ConstAllocation` for the known-interned ones,
which makes the division much clearer. `ConstAllocation::inner()` is
used to get the underlying `Allocation`.

In some places it's natural to use an `Allocation`, in some it's natural
to use a `ConstAllocation`, and in some places there's no clear choice.
I've tried to make things look as nice as possible, while generally
favouring `ConstAllocation`, which is the type that embodies more
information. This does require quite a few calls to `inner()`.

The commit also tweaks how `PartialOrd` works for `Interned`. The
previous code was too clever by half, building on `T: Ord` to make the
code shorter. That caused problems with deriving `PartialOrd` and `Ord`
for `ConstAllocation`, so I changed it to build on `T: PartialOrd`,
which is slightly more verbose but much more standard and avoided the
problems.
2022-03-07 08:25:50 +11:00
Takayuki Maeda 51a53bf4df remove unnecessary .. patterns 2022-03-07 02:18:36 +09:00
Michael Goulet 3f17dae37d check extra args even if the function is not c_variadic 2022-03-04 20:28:35 -08:00
Dylan DPC c7d200441b
Rollup merge of #94460 - eholk:reenable-drop-tracking-tests, r=tmiasko
Reenable generator drop tracking tests and fix mutation handling

The previous PR, #94068, was overly zealous in counting mutations as borrows, which effectively nullified drop tracking. We would have caught this except the drop tracking tests were still ignored, despite having the option of using the `-Zdrop-tracking` flag now.

This PR fixes the issue introduced by #94068 by only counting mutations as borrows the mutated place has a project. This is sufficient to distinguish `x.y = 42` (which should count as a borrow of `x`) from `x = 42` (which is not a borrow of `x` because the whole variable is overwritten).

This PR also re-enables the drop tracking regression tests using the `-Zdrop-tracking` flag so we will avoid introducing these sorts of issues in the future.

Thanks to ``@tmiasko`` for noticing this problem and pointing it out!

r? ``@tmiasko``
2022-03-05 04:46:37 +01:00
Dylan DPC 3064d6ec4d
Rollup merge of #94596 - compiler-errors:delay-adjustment-duplicate, r=estebank
Delay bug in expr adjustment when check_expr is called multiple times

Instead of including slightly more complicated logic in `check_argument_types` to fix the bug (#94516) I introduced in #94438, and inevitably have this bug appear once again when some other diagnostic is written that causes `check_expr` to be called an expression during a (bad) code path, just delay the bug in adjustment logic.

I am open to other implementations that don't delay the bug here.

Fixes #94516
2022-03-04 22:58:36 +01:00
Eric Holk add169d414 Distinguish binding assignments, use Ty::needs_drop
This better captures the actual behavior, rather than using hacks around
whether the assignment has any projections.
2022-03-04 11:03:24 -08:00
Michael Goulet 8af683de34 delay bug instead of skipping check_expr 2022-03-03 20:39:50 -08:00
Dylan DPC c1585a17a3
Rollup merge of #93913 - bjorn3:remove_everybody_loops, r=jackh726
Remove the everybody loops pass

It isn't used anymore by rustdoc.

Split out of https://github.com/rust-lang/rust/pull/92895. There has been some previous discussion there.
2022-03-04 02:06:38 +01:00
Matthias Krüger fec7a79088
Rollup merge of #94057 - lcnr:simplify_type-uwu, r=nikomatsakis
improve comments for `simplify_type`

Should now correctly describe what's going on. Experimented with checking the invariant for projections
but that ended up requiring fairly involved changes. I assume that it is not possible to get unsoundness here,
at least for now and I can pretty much guarantee that it's impossible to trigger it by accident.

r? `````@nikomatsakis````` cc #92721
2022-03-03 20:01:44 +01:00
bjorn3 2f84484aac Remove the everybody loops pass
It isn't used anymore by rustdoc
2022-03-03 18:23:09 +01:00
Dylan DPC bdad4a7be7
Rollup merge of #93072 - m-ou-se:compatible-variants-suggestion-with-desugaring, r=estebank
Compatible variants suggestion with desugaring

This fixes #90553 for `for` loops and other desugarings.

r? ```@estebank```
2022-03-03 01:09:08 +01:00