Commit Graph

1103 Commits

Author SHA1 Message Date
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
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
Matthias Krüger
6c22e0419f
Rollup merge of #111403 - y21:suggest-slice-swap, r=compiler-errors
suggest `slice::swap` for `mem::swap(&mut x[0], &mut x[1])` borrowck error

Recently saw someone ask why this code (example slightly modified):
```rs
fn main() {
  let mut foo = [1, 2];
  std::mem::swap(&mut foo[0], &mut foo[1]);
}
```
triggers this error and how to fix it:
```
error[E0499]: cannot borrow `foo[_]` as mutable more than once at a time
 --> src/main.rs:4:33
  |
4 |     std::mem::swap(&mut foo[0], &mut foo[1]);
  |     -------------- -----------  ^^^^^^^^^^^ second mutable borrow occurs here
  |     |              |
  |     |              first mutable borrow occurs here
  |     first borrow later used by call
  |
  = help: consider using `.split_at_mut(position)` or similar method to obtain two mutable non-overlapping sub-slices
```
The current help message is nice and goes in the right direction, but I think we can do better for this specific instance and suggest `slice::swap`, which makes this compile
2023-06-30 08:01:12 +02:00
DrMeepster
4fbd6d5af4 Merge un_derefer into MovePathLookup 2023-06-29 22:14:27 -07:00
y21
679c5be405 add slice::swap suggestion 2023-06-29 19:19:59 +02:00
Lukas Markeffsky
5e83ddd279 don't suggest move for borrows that aren't closures 2023-06-28 23:56:58 +02:00
Dylan DPC
dabcbae535
Rollup merge of #112236 - cjgillot:interval-kill, r=davidtwco
Simplify computation of killed borrows

Follow-up to https://github.com/rust-lang/rust/pull/111759

Processing the first block manually once makes the pre-order walk simpler.
2023-06-28 18:28:46 +05:30
Camille GILLOT
b7989393a4 Extract the local != local case in borrow_conflicts_with_place. 2023-06-27 18:19:09 +00:00
Camille GILLOT
372366d686 Only consider places with the same local in each_borrow_involving_path. 2023-06-27 17:57:10 +00:00
bors
b5e51db16d Auto merge of #112938 - compiler-errors:clause-3, r=oli-obk
Migrate `TyCtxt::predicates_of` and `ParamEnv::caller_bounds` to `Clause`

The last big change in the series.

I will follow-up with additional filed issues once this PR lands:
- [ ] Investigate making `TypeFoldable<TyCtxt<'tcx>> for ty::Clause<'tcx>` implementation less weird: 2efe091705/compiler/rustc_middle/src/ty/structural_impls.rs (L672)
- [ ] Clean up the elaborator since it should only be emitting child clauses, not predicates
- [ ] Rename identifiers like `pred` and `predicates` to `clause` if they're actually clauses around the codebase
- [ ] Validate that all of the `ToPredicate` impls are acutally still needed, or prune them if they're not

r? `@ghost` until the other branch lands
2023-06-27 03:14:45 +00:00
bors
b9ad9b78a2 Auto merge of #112693 - ericmarkmartin:use-more-placeref, r=spastorino
Use PlaceRef abstractions more often

Associated issue: https://github.com/rust-lang/rust/issues/80647

r? `@spastorino`
2023-06-27 00:34:49 +00:00
Michael Goulet
fbdef58414 Migrate predicates_of and caller_bounds to Clause 2023-06-26 23:12:03 +00:00
Eric Mark Martin
c07c10d1e4 use PlaceRef abstractions more consistently 2023-06-25 20:38:01 -04:00
Guillaume Gomez
696d722169
Rollup merge of #112703 - aliemjay:next-solver-root-var, r=compiler-errors
[-Ztrait-solver=next, mir-typeck] instantiate hidden types in the root universe

Fixes an ICE in the test `member-constraints-in-root-universe`.

Main motivation is to make #112691 pass under the new solver.

r? ``@compiler-errors``
2023-06-24 20:26:43 +02:00
Ali MJ Al-Nasrawy
a72013f7f0 instantiate hidden types in root universe 2023-06-24 13:00:15 +00:00
Matthias Krüger
4e8983050e
Rollup merge of #112870 - compiler-errors:clause-2, r=oli-obk
Migrate `item_bounds` to `ty::Clause`

Should be simpler than the next PR that's coming up. Last three commits are the relevant ones.

r? ``@oli-obk`` or ``@lcnr``
2023-06-23 19:39:59 +02:00
Matthias Krüger
4e96aba8f6
Rollup merge of #112933 - TaKO8Ki:avoid-&format-in-error-message-code, r=oli-obk
Avoid `&format` in error message code

follow-up of #111633
2023-06-23 13:18:14 +02:00
Michael Goulet
46a650f4e0 Migrate item_bounds to ty::Clause 2023-06-22 18:34:23 +00:00