Commit Graph

17791 Commits

Author SHA1 Message Date
Maybe Waffle
0250f0244b allow or avoid for loops over option in compiler and tests 2022-10-09 13:07:20 +00:00
Maybe Waffle
8ca57b54c1 for_loop_over_fallibles: don't use MachineApplicable
The loop could contain `break;` that won't work with an `if let`
2022-10-09 13:05:53 +00:00
Maybe Waffle
23a7674e3e for_loop_over_fallibles: fix suggestion for "remove .next()" case
if the iterator is used after the loop, we need to use `.by_ref()`
2022-10-09 13:05:53 +00:00
Maybe Waffle
dd842ffc3d for_loop_over_fallibles: remove duplication from the message 2022-10-09 13:05:53 +00:00
Maybe Waffle
b2975ee974 for_loop_over_fallibles: suggest using ? in some cases 2022-10-09 13:05:52 +00:00
Maybe Waffle
5dcfdbf31e for_loop_over_fallibles: suggest while let loop 2022-10-09 13:05:52 +00:00
Maybe Waffle
21ec99b6fa for_loop_over_fallibles: Suggest removing .next() 2022-10-09 13:05:52 +00:00
Maybe Waffle
d030ba52e2 Use structured suggestions for for_loop_over_fallibles lint 2022-10-09 13:05:52 +00:00
Maybe Waffle
fa380a82a5 Start uplifting clippy::for_loops_over_fallibles
I refactored the code:
- Removed handling of methods, as it felt entirely unnecessary
- Removed clippy utils (obviously...)
- Used some shiny compiler features
  (let-else is very handy for lints 👀)
- I also renamed the lint to `for_loop_over_fallibles` (note: no `s`).
  I'm not sure what's the naming convention here, so maybe I'm wrong.
2022-10-09 13:05:52 +00:00
Michael Howell
5ba30a680c
Rollup merge of #102514 - b-naber:binder-print-fixes, r=jackh726
Don't repeat lifetime names from outer binder in print

Fixes https://github.com/rust-lang/rust/issues/102392
Fixes https://github.com/rust-lang/rust/issues/102414

r? ```@lcnr```
2022-10-08 18:14:59 -07:00
Michael Howell
bf37054b1f
Rollup merge of #99818 - aliemjay:fix-closure-normalize, r=jackh726
don't ICE when normalizing closure input tys

We were ICEing while rendering diagnostics because `universe_causes` is expected to track every universe created in the typeck's infcx.

`normalize_and_add_constraints` doesn't update `universe_causes`
when creating new universes, causing an ICE. Remove it!

Add spans to better track normalization constraints.

Fix couple places where `universe_causes` is not updated correctly to
track newly added universes.

Fixes #102800

~Fixess #99665~ (UPDATE: no longer true; the issue has a different failure path than when this PR was created and should be fixed by #101708, but the changes in this PR are still correct and should prevent potential future ICEs)
2022-10-08 18:14:59 -07:00
b-naber
048e637e9e handle late-bound vars from inner binders correctly and add test 2022-10-08 17:48:02 +02:00
bors
c27948d255 Auto merge of #102809 - matthiaskrgr:rollup-qq62vuv, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #101520 (Allow transmutes between the same types after erasing lifetimes)
 - #102675 (Remove `mir::CastKind::Misc`)
 - #102778 (Fix MIR inlining of asm_unwind)
 - #102785 (Remove `DefId` from some `SelectionCandidate` variants)
 - #102788 (Update rustc-dev-guide)
 - #102789 (Update browser UI test version)
 - #102797 (rustdoc: remove no-op CSS `.rightside { position: initial }`)
 - #102798 (rustdoc: add main-heading and example-wrap link CSS to big selector)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-10-08 14:58:11 +00:00
Matthias Krüger
f1a03b6e4a
Rollup merge of #102785 - fee1-dead-contrib:rm_autoimpl_defid, r=compiler-errors
Remove `DefId` from some `SelectionCandidate` variants

They are both from `obligation.predicate.def_id()`, which do not need to be on the `SelectionCandidate`.

cc ````@lcnr```` ````@compiler-errors````
2022-10-08 14:38:19 +02:00
Matthias Krüger
2f2664923b
Rollup merge of #102778 - nbdd0121:mir, r=tmiasko
Fix MIR inlining of asm_unwind

The MIR inlining currently doesn't handle inline asm's unwind edge correctly.

This code will cause ICE:
```rust
struct D;

impl Drop for D {
    fn drop(&mut self) {}
}

#[inline(always)]
fn foo() {
    let _d = D;
    unsafe { std::arch::asm!("", options(may_unwind)) };
}

pub fn main() {
    foo();
}
```

This PR fixes this issue. I also take the opportunity to extract common code into a method.
2022-10-08 14:38:19 +02:00
Matthias Krüger
c731646d6a
Rollup merge of #102675 - ouz-a:mir-technical-debt, r=oli-obk
Remove `mir::CastKind::Misc`

As discussed in #97649 `mir::CastKind::Misc` is not clear, this PR addresses that by creating a new enum variant for every valid cast.

r? ````@oli-obk````
2022-10-08 14:38:18 +02:00
Matthias Krüger
6bcdf8aa74
Rollup merge of #101520 - oli-obk:transmute_lifetimes, r=compiler-errors
Allow transmutes between the same types after erasing lifetimes

r? ````@compiler-errors````  on the impl

fixes #101081

See discussion in the issue and at https://rust-lang.zulipchat.com/#narrow/stream/326866-t-types.2Fnominated/topic/.23101081.3A.20Regression.20transmuting.20.60RwLockReadGuard.3CT.3A.20.3FSized.3E.E2.80.A6

I think this may need lang team signoff as its implications may go beyond the jurisdiction of T-types

I'll write up a proper summary later
2022-10-08 14:38:18 +02:00
bors
bba9785dd7 Auto merge of #100720 - camsteffen:representable, r=cjgillot
Rewrite representability

 * Improve placement of `Box` in the suggestion
 * Multiple items in a cycle emit 1 error instead of an error for each item in the cycle
 * Introduce `representability` query to avoid traversing an item every time it is used.
 * Also introduce `params_in_repr` query to avoid traversing generic items every time it is used.
2022-10-08 11:53:25 +00:00
Ali MJ Al-Nasrawy
fc3d7eb91d don't ICE when normalizing closure input tys
`normalize_and_add_constraints` doesn't add entries in `universe_causes`
when creating new universes, causing an ICE. Remove it!

Add spans to track normalization constraints.

Fix couple places where `universe_causes` is not updated correctly to
track newly added universes.
2022-10-08 04:56:25 +03:00
bors
8b0c05d9ad Auto merge of #102091 - RalfJung:const_err, r=oli-obk
make const_err a hard error

This lint has been deny-by-default with future incompat wording since [Rust 1.51](https://github.com/rust-lang/rust/pull/80394) and the stable release of this week starts showing it in cargo's future compat reports. I can't wait to finally get rid of at least some of the mess in our const-err-reporting-code. ;)

r? `@oli-obk`
Fixes https://github.com/rust-lang/rust/issues/71800
Fixes https://github.com/rust-lang/rust/issues/100114
2022-10-07 20:50:51 +00:00
bors
2d3a85b4f8 Auto merge of #102787 - Dylan-DPC:rollup-fvbb4t9, r=Dylan-DPC
Rollup of 6 pull requests

Successful merges:

 - #102300 (Use a macro to not have to copy-paste `ConstFnMutClosure::new(&mut fold, NeverShortCircuit::wrap_mut_2_imp)).0` everywhere)
 - #102475 (unsafe keyword: trait examples and unsafe_op_in_unsafe_fn update)
 - #102760 (Avoid repeated re-initialization of the BufReader buffer)
 - #102764 (Check `WhereClauseReferencesSelf` after all other object safety checks)
 - #102779 (Fix `type_of` ICE)
 - #102780 (run Miri CI when std::sys changes)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-10-07 17:37:39 +00:00
Dylan DPC
d70e56aef8
Rollup merge of #102779 - TaKO8Ki:fix-type-of-ice-102768, r=fee1-dead
Fix `type_of` ICE

Fixes #102768
2022-10-07 22:05:32 +05:30
Dylan DPC
34dfd82de0
Rollup merge of #102764 - compiler-errors:issue-102762, r=jackh726
Check `WhereClauseReferencesSelf` after all other object safety checks

This fixes the ICE because it causes us to detect another *non-lint* `MethodViolationCode` first, instead of breaking on `WhereClauseReferencesSelf`.

We could also approach this issue by instead returning a vector of *all* of the `MethodViolationCode`s, and just reporting the first one we see, but treating it as a hard error if we return both `WhereClauseReferencesSelf` and some other violation code -- let me know if this is desired.

Fixes #102762
2022-10-07 22:05:31 +05:30
Oli Scherer
d90d055691 Allow transmutes between the same types after erasing lifetimes 2022-10-07 16:33:32 +00:00
Ralf Jung
fd59d44f58 make const_err a hard error 2022-10-07 18:08:49 +02:00
Deadbeef
e8a2aee50d Remove DefId from some SelectionCandidate variants 2022-10-07 15:14:22 +00:00
Cameron Steffen
ff940db666 Rewrite representability 2022-10-07 09:33:46 -05:00
Cameron Steffen
283abbf0e7 Change InferCtxtBuilder from enter to build 2022-10-07 07:10:40 -05:00
Takayuki Maeda
fa767868df fix a ICE #102768 2022-10-07 21:10:08 +09:00
Cameron Steffen
91269fa5b8 Remove a reference from Inherited 2022-10-07 07:06:19 -05:00
Cameron Steffen
349415d1c6 Remove TypeckResults from InferCtxt 2022-10-07 07:06:19 -05:00
Cameron Steffen
4a68373217 Introduce TypeErrCtxt
TypeErrCtxt optionally has a TypeckResults so that InferCtxt doesn't
need to.
2022-10-07 07:06:16 -05:00
Gary Guo
242348343b Fix MIR inlining of asm_unwind 2022-10-07 12:59:38 +01:00
bors
5854680388 Auto merge of #102767 - matthiaskrgr:rollup-vcbt81v, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #102577 (Warn about Visual Studio Code branding confusion)
 - #102720 (do not reverse the expected type and found type for ObligationCauseCo…)
 - #102744 (rustdoc: remove unused CSS `.content .item-list`)
 - #102747 (rustdoc: remove unused CSS `.docblock a:not(.srclink)`)
 - #102748 (Disable compressed debug sections on i586-gnu)
 - #102761 (let-else: test else block with non-never uninhabited type)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-10-07 07:31:53 +00:00
Matthias Krüger
047ff20875
Rollup merge of #102720 - lyming2007:issue-102397-fix, r=compiler-errors
do not reverse the expected type and found type for ObligationCauseCo…

…de of IfExpressionWithNoElse

this will fix #102397
2022-10-07 07:28:10 +02:00
Matthias Krüger
1a2a3249bc
Rollup merge of #102577 - kornelski:non-code-visual-studio, r=wesleywiser
Warn about Visual Studio Code branding confusion

VS Code is a popular companion for Rust, but Microsoft's branding is confusing, and users [may not understand](https://users.rust-lang.org/t/complie-error-when-i-run-rustc/82127) they also need the *other* VS.
2022-10-07 07:28:09 +02:00
bors
cf0fa76f27 Auto merge of #101988 - petrochenkov:flavor2, r=lqd
rustc_target: Refactor internal linker flavors

In accordance with the design from https://github.com/rust-lang/rust/pull/96827#issuecomment-1208441595

`lld_flavor` and `linker_is_gnu` fields are removed from internal target specs, but still parsed from JSON specs using compatibility layer introduced in https://github.com/rust-lang/rust/pull/100552.
r? `@lqd`
2022-10-07 03:35:02 +00:00
Michael Goulet
414319468b Check WhereClauseReferencesSelf after all other object safety checks 2022-10-07 02:29:19 +00:00
Kornel
9b3db34072 Warn about Visual Studio Code branding confusion 2022-10-06 20:56:44 +01:00
Matthias Krüger
42df0a580f
Rollup merge of #102725 - nnethercote:rm-Z-time, r=davidtwco
Remove `-Ztime`

Because it has a lot of overlap with `-Ztime-passes` but is generally less useful. Plus some related cleanups.

Best reviewed one commit at a time.

r? `@davidtwco`
2022-10-06 16:29:45 +02:00
Matthias Krüger
045fc18cde
Rollup merge of #102718 - compiler-errors:opaque-bound-lint-ice, r=fee1-dead
Fix `opaque_hidden_inferred_bound` lint ICE

Fixes #102705
2022-10-06 16:29:44 +02:00
Matthias Krüger
dd0fa6f871
Rollup merge of #98496 - BoxyUwU:instancers_bad_equality, r=lcnr
make `compare_const_impl` a query and use it in `instance.rs`

Fixes #88365

the bug in #88365 was caused by some `instance.rs` code using the `PartialEq` impl on `Ty` to check that the type of the associated const in an impl is the same as the type of the associated const in the trait definition. This was wrong for two reasons:
- the check typeck does is that the impl type is a subtype of the trait definition's type (see `mismatched_impl_ty_2.rs` which [was ICEing](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=f6d60ebe6745011f0d52ab2bc712025d) before this PR on stable)
- it assumes that if two types are equal then the `PartialEq` impl will reflect that which isnt true for higher ranked types or type level constants when `feature(generic_const_exprs)` is enabled (see `mismatched_impl_ty_3.rs` for higher ranked types which was [ICEing on stable](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=d7af131a655ed515b035624626c62c71))

r? `@lcnr`
2022-10-06 16:29:43 +02:00
ouz-a
d59c7ff000 Remove mir::CastKind::Misc 2022-10-06 15:32:41 +03:00
Vadim Petrochenkov
572b6a9c60 rustc_target: Refactor internal linker flavors
In accordance with the design from https://github.com/rust-lang/rust/pull/96827#issuecomment-1208441595
2022-10-06 13:41:12 +04:00
Boxy
25ed5d5db2 reviews 2022-10-06 07:00:38 +01:00
bors
4bd30785eb Auto merge of #102726 - matthiaskrgr:rollup-2ghn38b, r=matthiaskrgr
Rollup of 5 pull requests

Successful merges:

 - #102672 (rustdoc: remove unused CSS class `in-band`)
 - #102693 (Revert "Use getentropy when possible on all Apple platforms")
 - #102694 (Suggest calling method if fn does not exist)
 - #102708 (Suggest `==` to wrong assign expr)
 - #102710 (Add test for issue 82633)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-10-06 05:58:27 +00:00
Matthias Krüger
0512a06186
Rollup merge of #102708 - TaKO8Ki:improve-eqeq-suggestion, r=estebank
Suggest `==` to wrong assign expr

Given the following code:

```rust
fn main() {
    let x = 3;
    let y = 3;
    if x == x && y = y {
        println!("{}", x);
    }
}
```

Current output is:

```
error[E0308]: mismatched types
 --> src/main.rs:4:18
  |
4 |     if x == x && y = y {
  |                  ^ expected `bool`, found integer

error[E0308]: mismatched types
 --> src/main.rs:4:8
  |
4 |     if x == x && y = y {
  |        ^^^^^^^^^^^^^^^ expected `bool`, found `()`
```

This adds a suggestion:

```diff
error[E0308]: mismatched types
 --> src/main.rs:6:18
  |
6 |     if x == x && y = y {
  |                  ^ expected `bool`, found integer

error[E0308]: mismatched types
 --> src/main.rs:6:8
  |
6 |     if x == x && y = y {
  |        ^^^^^^^^^^^^^^^ expected `bool`, found `()`
  |
+ help: you might have meant to compare for equality
+   |
+ 6 |     if x == x && y == y {
+   |                     +
```

And this fixes a part of #97469
2022-10-06 07:07:37 +02:00
Matthias Krüger
a9b3441c17
Rollup merge of #102694 - compiler-errors:fn-to-method, r=davidtwco
Suggest calling method if fn does not exist

I tried to split this up into two commits, the first where we stash the resolution error until typeck (which causes a bunch of diagnostics changes because the ordering of error messages change), then the second commit is the actual logic that actually implements the suggestion.

I am not in love with the presentation of the suggestion, so I could use some advice for how to format the actual messaging.

r? diagnostics

Fixes #102518
2022-10-06 07:07:36 +02:00
Nicholas Nethercote
4e8faff3a1 Be consistent about deciding whether to print pass data.
`print_time_passes_entry` unconditionally prints data about a pass. The
most commonly used call site, in `VerboseTimingGuard::drop`, guards it
with a `should_print_passes` test. But there are a couple of other call
sites that don't do that test.

This commit moves the `should_print_passes` test within
`print_time_passes_entry` so that all passes are treated equally.
2022-10-06 15:50:10 +11:00
Nicholas Nethercote
9110d925d0 Remove -Ztime option.
The compiler currently has `-Ztime` and `-Ztime-passes`. I've used
`-Ztime-passes` for years but only recently learned about `-Ztime`.

What's the difference? Let's look at the `-Zhelp` output:
```
  -Z        time=val -- measure time of rustc processes (default: no)
  -Z time-passes=val -- measure time of each rustc pass (default: no)
```
The `-Ztime-passes` description is clear, but the `-Ztime` one is less so.
Sounds like it measures the time for the entire process?

No. The real difference is that `-Ztime-passes` prints out info about passes,
and `-Ztime` does the same, but only for a subset of those passes. More
specifically, there is a distinction in the profiling code between a "verbose
generic activity" and an "extra verbose generic activity". `-Ztime-passes`
prints both kinds, while `-Ztime` only prints the first one. (It took me
a close reading of the source code to determine this difference.)

In practice this distinction has low value. Perhaps in the past the "extra
verbose" output was more voluminous, but now that we only print stats for a
pass if it exceeds 5ms or alters the RSS, `-Ztime-passes` is less spammy. Also,
a lot of the "extra verbose" cases are for individual lint passes, and you need
to also use `-Zno-interleave-lints` to see those anyway.

Therefore, this commit removes `-Ztime` and the associated machinery. One thing
to note is that the existing "extra verbose" activities all have an extra
string argument, so the commit adds the ability to accept an extra argument to
the "verbose" activities.
2022-10-06 15:49:44 +11:00