Commit Graph

1119 Commits

Author SHA1 Message Date
Ralf Jung 818ec8e23a give some unwind-related terminators a more clear name 2023-08-20 15:52:38 +02:00
Kyle Lin 297ff8c97e Fix redundant explicit link in rustc_borrowck 2023-08-19 02:22:13 +08:00
Camille GILLOT 388f6a6413 Make TerminatorEdge plural. 2023-08-16 18:12:18 +00:00
Camille GILLOT 5173d85043 Allow apply_terminator_effect to customize edges. 2023-08-16 18:12:17 +00:00
Camille GILLOT 934a99eb65 Move domain_size to GenKillAnalysis. 2023-08-16 18:12:17 +00:00
lcnr e04f582e56 review 2023-08-14 15:27:14 +02:00
lcnr 95fddbc501 check for non-defining uses of RPIT 2023-08-14 15:25:20 +02:00
Matthias Krüger 3cd0a109a8
Rollup merge of #114566 - fmease:type-alias-laziness-is-crate-specific, r=oli-obk
Store the laziness of type aliases in their `DefKind`

Previously, we would treat paths referring to type aliases as *lazy* type aliases if the current crate had lazy type aliases enabled independently of whether the crate which the alias was defined in had the feature enabled or not.

With this PR, the laziness of a type alias depends on the crate it is defined in. This generally makes more sense to me especially if / once lazy type aliases become the default in a new edition and we need to think about *edition interoperability*:

Consider the hypothetical case where the dependency crate has an older edition (and thus eager type aliases), it exports a type alias with bounds & a where-clause (which are void but technically valid), the dependent crate has the latest edition (and thus lazy type aliases) and it uses that type alias. Arguably, the bounds should *not* be checked since at any time, the dependency crate should be allowed to change the bounds at will with a *non*-major version bump & without negatively affecting downstream crates.

As for the reverse case (dependency: lazy type aliases, dependent: eager type aliases), I guess it rules out anything from slight confusion to mild annoyance from upstream crate authors that would be caused by the compiler ignoring the bounds of their type aliases in downstream crates with older editions.

---

This fixes #114468 since before, my assumption that the type alias associated with a given weak projection was lazy (and therefore had its variances computed) did not necessarily hold in cross-crate scenarios (which [I kinda had a hunch about](https://github.com/rust-lang/rust/pull/114253#discussion_r1278608099)) as outlined above. Now it does hold.

`@rustbot` label F-lazy_type_alias
r? `@oli-obk`
2023-08-08 03:30:56 +02:00
León Orell Valerian Liehr 5468336d6b
Store the laziness of type aliases in the DefKind 2023-08-07 15:54:31 +02:00
Matthias Krüger 35b271306f
Rollup merge of #114477 - estebank:arc-clone, r=compiler-errors
Account for `Rc` and `Arc` when suggesting to clone

When suggesting to clone a reference-counted value, be less uncertain.
2023-08-04 21:32:00 +02:00
Matthias Krüger 99e4127d85
Rollup merge of #114434 - Nilstrieb:indexing-spans, r=est31
Improve spans for indexing expressions

fixes #114388

Indexing is similar to method calls in having an arbitrary left-hand-side and then something on the right, which is the main part of the expression. Method calls already have a span for that right part, but indexing does not. This means that long method chains that use indexing have really bad spans, especially when the indexing panics and that span in coverted into a panic location.

This does the same thing as method calls for the AST and HIR, storing an extra span which is then put into the `fn_span` field in THIR.

r? compiler-errors
2023-08-04 21:31:57 +02:00
Esteban Küber edc3e26773 Account for `Rc` and `Arc` when suggesting to clone
When suggesting to clone a reference-counted value, be less uncertain.
2023-08-04 17:50:12 +00:00
Ali MJ Al-Nasrawy d55522aad8 don't ICE on higher ranked hidden types 2023-08-04 15:11:09 +00:00
Nilstrieb 5706be1854 Improve spans for indexing expressions
Indexing is similar to method calls in having an arbitrary
left-hand-side and then something on the right, which is the main part
of the expression. Method calls already have a span for that right part,
but indexing does not. This means that long method chains that use
indexing have really bad spans, especially when the indexing panics and
that span in coverted into a panic location.

This does the same thing as method calls for the AST and HIR, storing an
extra span which is then put into the `fn_span` field in THIR.
2023-08-04 13:17:39 +02:00
Matthias Krüger 576bf82702
Rollup merge of #114022 - oli-obk:tait_ice_alias_field_projection, r=cjgillot
Perform OpaqueCast field projection on HIR, too.

fixes #105819

This is necessary for closure captures in 2021 edition, as they capture individual fields, not the full mentioned variables. So it may try to capture a field of an opaque (because the hidden type is known to be something with a field).

See https://github.com/rust-lang/rust/pull/99806 for when and why we added OpaqueCast to MIR.
2023-08-04 09:18:58 +02:00
Nilstrieb 5830ca216d Add `internal_features` lint
It lints against features that are inteded to be internal to the
compiler and standard library. Implements MCP #596.

We allow `internal_features` in the standard library and compiler as those
use many features and this _is_ the standard library from the "internal to the compiler and
standard library" after all.

Marking some features as internal wasn't exactly the most scientific approach, I just marked some
mostly obvious features. While there is a categorization in the macro,
it's not very well upheld (should probably be fixed in another PR).

We always pass `-Ainternal_features` in the testsuite
About 400 UI tests and several other tests use internal features.
Instead of throwing the attribute on each one, just always allow them.
There's nothing wrong with testing internal features^^
2023-08-03 14:50:50 +02:00
Deadbeef 4fec845c3f Remove constness from `TraitPredicate` 2023-08-02 15:38:00 +00:00
Nilstrieb 46f6b05eb7
Rollup merge of #114079 - compiler-errors:closure-upvars, r=oli-obk
Use `upvar_tys` in more places, make it return a list

Just a cleanup that fell out of a PR that I was gonna write, but that PR kinda got stuck.
2023-08-02 13:46:54 +02:00
bors 7a5d2d0138 Auto merge of #114358 - matthiaskrgr:rollup-d810m9e, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #114178 (Account for macros when suggesting a new let binding)
 - #114199 (Don't unsize coerce infer vars in select in new solver)
 - #114301 (Don't check unnecessarily that impl trait is RPIT)
 - #114314 (Tweaks to `adt_sized_constraint`)
 - #114322 (Fix invalid slice coercion suggestion reported in turbofish)
 - #114340 ([rustc_attr][nit] Replace `filter` + `is_some` with `map_or`.)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-08-02 04:30:51 +00:00
Matthias Krüger 9cdca18840
Rollup merge of #114178 - estebank:let-binding-macro, r=petrochenkov
Account for macros when suggesting a new let binding

Provide a structured suggestion when the expression comes from a macro expansion:

```
error[E0716]: temporary value dropped while borrowed
  --> $DIR/borrowck-let-suggestion.rs:2:17
   |
LL |     let mut x = vec![1].iter();
   |                 ^^^^^^^       - temporary value is freed at the end of this statement
   |                 |
   |                 creates a temporary value which is freed while still in use
LL |
LL |     x.use_mut();
   |     - borrow later used here
   |
   = note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider using a `let` binding to create a longer lived value
   |
LL ~     let binding = vec![1];
LL ~     let mut x = binding.iter();
   |
```
2023-08-02 06:22:47 +02:00
bors 90bb4184f8 Auto merge of #114170 - lcnr:add-commmentz, r=compiler-errors
add `dropck_outlives` comments
2023-08-02 02:45:47 +00:00
Michael Goulet 99969d282b Use upvar_tys in more places, make it a list 2023-08-01 23:19:31 +00:00
bors 866710c552 Auto merge of #111753 - cjgillot:simp-place-conflict, r=compiler-errors
Only consider places with the same local in each_borrow_involving_path.

This avoids having a busy loop that repeatedly checks for equality of locals.
2023-08-01 03:53:19 +00:00
lcnr fc98c5a098 update comment 2023-07-31 12:47:24 +02:00
Esteban Küber 66d23793f0 Account for macros when suggesting a new let binding 2023-07-28 14:44:03 +00:00
lcnr 84043589a6 dropck_outlives comments 2023-07-28 13:16:36 +02:00
Deadbeef e6b423aebb Remove `constness` from `ParamEnv` 2023-07-27 15:50:42 +00:00
Matthias Krüger fa21a8c6f8
Rollup merge of #114075 - matthiaskrgr:fmt_args_rustc_3, r=wesleywiser
inline format!() args from rustc_codegen_llvm to the end (4)

r? `@WaffleLapkin`
2023-07-27 06:04:13 +02:00
Matthias Krüger 0b13deb548
Rollup merge of #113661 - oli-obk:tait_wtf, r=lcnr
Double check that hidden types match the expected hidden type

Fixes https://github.com/rust-lang/rust/issues/113278 specifically, but I left a TODO for where we should also add some hardening.

It feels a bit like papering over the issue, but at least this way we don't get unsoundness, but just surprising errors. Errors will be improved and given spans before this PR lands.

r? `@compiler-errors` `@lcnr`
2023-07-25 23:34:07 +02:00
Matthias Krüger c64ef5e070 inline format!() args from rustc_codegen_llvm to the end (4)
r? @WaffleLapkin
2023-07-25 23:20:28 +02:00
David Wood 3857d9c2da
borrowck/errors: fix i18n error in delayed bug
During borrowck, the `MultiSpan` from a buffered diagnostic is cloned and
used to emit a delayed bug indicating a diagnostic was buffered - when
the buffered diagnostic is translated, then the cloned `MultiSpan` may
contain labels which can only render with the diagnostic's arguments, but
the delayed bug being emitted won't have those arguments. Adds a function
which clones `MultiSpan` without also cloning the contained labels, and
use this function when creating the buffered diagnostic delayed bug.

Signed-off-by: David Wood <david@davidtw.co>
2023-07-24 15:47:03 +01:00
Oli Scherer 1d45658329 Some tracing changes 2023-07-24 14:19:26 +00:00
Oli Scherer 44e21503a8 Double check that hidden types match the expected hidden type 2023-07-21 13:19:36 +00:00
Michael Goulet 05f6890b3e Rename arg_iter to iter_instantiated 2023-07-17 21:04:12 +00:00
Matthias Krüger f6dbf7d69b
Rollup merge of #113599 - chenyukang:yukang-fix-use-maybe_body_owned_by, r=cjgillot
Use maybe_body_owned_by for multiple suggestions

This is a continued work from https://github.com/rust-lang/rust/pull/113567

We have several other suggestions not working for closure, this PR use `maybe_body_owned_by` to fix them and add test cases for them.
2023-07-14 19:33:26 +02:00
Mahdi Dibaiee e55583c4b8 refactor(rustc_middle): Substs -> GenericArg 2023-07-14 13:27:35 +01:00
yukang bdd04a62f9 fix the issue of shorthand in suggest_cloning 2023-07-14 07:12:38 +08:00
yukang 3ddf6f7c17 use maybe_body_owned_by for closure 2023-07-14 07:12:35 +08:00
Mark Rousskov cc907f80b9 Re-format let-else per rustfmt update 2023-07-12 21:49:27 -04:00
bors da1d099f91 Auto merge of #112945 - compiler-errors:tighten-span-of-adjustment-error, r=oli-obk
(re-)tighten sourceinfo span of adjustments in MIR

Diagnostics rely on the spans of MIR statements being (approximately) correct in order to give suggestions relative to that span (i.e. `shrink_to_hi` and `shrink_to_lo`).

I discovered that we're *intentionally* lowering THIR exprs with their parent expr's span if they come from adjustments that are due to a parent expression. While I understand why that may be desirable to demonstrate the relationship of an adjustment and the expression that requires it, it leads to

1. very verbose borrowck output
2. incorrect spans for suggestions

Some diagnostics get around that by giving suggestions relative to other spans we've collected during MIR lowering, such as the span of the method's identifier (e.g. `name` in `.name()`), but this doesn't work too well when things come from desugaring.

I assume it also has lead to numerous tweaks and complications to diagnostics code down the road, which this PR doesn't necessarily aim to fix but may open the gates to fixing later... The last three commits are simplifications due to the fact that we can assume that the move span actually points to what is being moved (and a test).

This regressed in #89110, which was debated somewhat in #90286. cc `@Aaron1011` who originally made this change.

r? diagnostics

Fixes #113547
Fixes #111016
2023-07-12 12:11:09 +00:00
bors 5b733e2bca Auto merge of #113316 - DrMeepster:underefer_perf, r=oli-obk
Rewrite `UnDerefer`, again

This PR is intended to improve the perf regression introduced by #112882.

`UnDerefer` has been separated out again for borrowck reasons. It was a bit overzealous to remove it in the previous PR.

r? `@oli-obk`
2023-07-11 06:52:53 +00:00
Michael Goulet a74db1abb3 Fix another strange suggestion span 2023-07-10 20:09:28 +00:00
Michael Goulet 3a3f4a2144 Don't use method span on clone suggestion 2023-07-10 20:09:28 +00:00
Nilstrieb 2beabbbf6f Rename `adjustment::PointerCast` and variants using it to `PointerCoercion`
It makes it sound like the `ExprKind` and `Rvalue` are supposed to represent all pointer related
casts, when in reality their just used to share a some enum variants. Make it clear there these
are only coercion to make it clear why only some pointer related "casts" are in the enum.
2023-07-07 18:17:16 +02:00
Boxy 12138b8e5e Move `TyCtxt::mk_x` to `Ty::new_x` where applicable 2023-07-05 20:27:07 +01:00
DrMeepster d1c9696b7d bring back un_derefer and rewrite it again 2023-07-04 13:45:23 -07:00
bors d5a74249c8 Auto merge of #112882 - DrMeepster:new_un_derefer, r=oli-obk
Rewrite `UnDerefer`

Currently, `UnDerefer` is used by drop elaboration to undo the effects of the `Derefer` pass. However, it just recreates the original places with derefs in the middle of the projection. Because `ProjectionElem::Deref` is intended to be removed completely in the future, this will not work forever.

This PR introduces a `deref_chain` method that returns the places behind `DerefTemp` locals in a place and rewrites the move path code to use this. In the process, `UnDerefer` was merged into `MovePathLookup`. Now that move paths use the same places as in the MIR, the other uses of `UnDerefer` no longer require it.

See #98145
cc `@ouz-a`
r? `@oli-obk`
2023-07-03 02:46:39 +00:00
Matthias Krüger 9082287213
Rollup merge of #113174 - chenyukang:yukang-fix-102972-loop-next, r=compiler-errors
Better messages for next on a iterator inside for loops

Fixes #102972
2023-07-01 13:46:01 +02:00
yukang 4189faa21e add typecheck for iterator 2023-06-30 14:50:27 +08:00
yukang 44a8a8d0ca Better messages for next in a iterator inside for loops 2023-06-30 14:02:02 +08:00