Commit Graph

3113 Commits

Author SHA1 Message Date
Deadbeef
4f83717cf7 Use translatable diagnostics in rustc_const_eval 2023-06-01 14:45:18 +00:00
bors
642c92e630 Auto merge of #112002 - saethlin:enable-sroa, r=oli-obk,scottmcm
Enable ScalarReplacementOfAggregates in optimized builds

Like MatchBranchSimplification, this pass is known to produce significant runtime improvements in Cranelift artifacts, and I believe based on the perf runs here that the primary effect of this pass is to empower MatchBranchSimplification. ScalarReplacementOfAggregates on its own has little effect on anything, but when this was rebased up to include https://github.com/rust-lang/rust/pull/112001 we started seeing significant and majority-positive results.

Based on the fact that we see most of the regressions in debug builds (https://github.com/rust-lang/rust/pull/112002#issuecomment-1566270144) and some rather significant ones in cycles and wall time, I'm only enabling this in optimized builds at the moment.
2023-06-01 10:47:14 +00:00
bors
fabf929863 Auto merge of #112164 - Dylan-DPC:rollup-93zj7jw, r=Dylan-DPC
Rollup of 7 pull requests

Successful merges:

 - #108459 (rustdoc: Fix LinkReplacer link matching)
 - #111318 (Add a distinct `OperandValue::ZeroSized` variant for ZSTs)
 - #111892 (rustdoc: add interaction delays for tooltip popovers)
 - #111980 (Preserve substs in opaques recorded in typeck results)
 - #112024 (Don't suggest break through nested items)
 - #112128 (Don't compute inlining status of mono items in advance.)
 - #112141 (remove reference to Into in ? operator core/std docs, fix #111655)

Failed merges:

 - #112071 (Group rfcs tests)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-06-01 08:06:07 +00:00
Scott McMurray
32cc106af3 Lower unchecked_{div, rem} to BinOp::{Div, Rem} 2023-06-01 00:05:55 -07:00
Dylan DPC
02c4b4b279
Rollup merge of #112024 - compiler-errors:dont-break-thru-item, r=WaffleLapkin
Don't suggest break through nested items

Fixes #112020
2023-06-01 11:09:44 +05:30
Dylan DPC
ccf99bd769
Rollup merge of #111980 - compiler-errors:unmapped-substs, r=lcnr
Preserve substs in opaques recorded in typeck results

This means that we now prepopulate MIR with opaques with the right substs.

The first commit is a hack that I think we discussed, having to do with `DefiningAnchor::Bubble` basically being equivalent to `DefiningAnchor::Error` in the new solver, so having to use `DefiningAnchor::Bind` instead, lol.

r? `@lcnr`
2023-06-01 11:09:43 +05:30
Dylan DPC
453fc03597
Rollup merge of #111892 - notriddle:notriddle/timeout-tooltip, r=me,GuillaumeGomez,Manishearth
rustdoc: add interaction delays for tooltip popovers

Preview:

* [notable traits](http://notriddle.com/rustdoc-demo-html-3/delay-tooltip/testing/struct.Vec.html#method.iter)
* [panicking code block](http://notriddle.com/rustdoc-demo-html-3/delay-tooltip/testing/struct.Vec.html#indexing)

Designing a good hover microinteraction is a matter of guessing user intent from what are, literally, vague gestures. In this case, guessing if hovering in our out of the tooltip base is intentional or not.

To figure this out, a few different techniques are used:

* When the mouse pointer enters a tooltip anchor point, its hitbox is grown on the bottom, where the popover is/will appear. This was already there before this commit: search "hover tunnel" in rustdoc.css for the implementation.

* This commit adds a delay when the mouse pointer enters the base anchor, in case the mouse pointer was just passing through and the user didn't want to open it.

* This commit also adds a delay when the mouse pointer exits the tooltip's base anchor or its popover, before hiding it.

* A fade-out animation is layered onto the pointer exit delay to immediately inform the user that they successfully dismissed the popover, while still providing a way for them to cancel it if it was a mistake and they still wanted to interact with it.

* No animation is used for revealing it, because we don't want people to try to interact with an element while it's in the middle of fading in: either they're allowed to interact with it while it's fading in, meaning it can't serve as mistake- proofing for opening the popover, or they can't, but they might try and be frustrated.

See also:

* https://www.nngroup.com/articles/timing-exposing-content/
* https://www.nngroup.com/articles/tooltip-guidelines/
* https://bjk5.com/post/44698559168/breaking-down-amazons-mega-dropdown
2023-06-01 11:09:43 +05:30
Dylan DPC
03d4299447
Rollup merge of #111318 - scottmcm:operand-value-poison, r=compiler-errors
Add a distinct `OperandValue::ZeroSized` variant for ZSTs

These tend to have special handling in a bunch of places anyway, so the variant helps remember that.  And I think it's easier to grok than `Aggregate`s sometimes being `Immediates` (after all, I previously got that wrong and caused #109992).  As a minor bonus, it means we don't need to generate poison LLVM values for ZSTs to pass around in `OperandValue::Immediate`s.

Inspired by https://github.com/rust-lang/rust/pull/110021#discussion_r1160486991, so
r? `@compiler-errors`
2023-06-01 11:09:42 +05:30
Dylan DPC
0baa30129b
Rollup merge of #108459 - benediktwerner:rustdoc-fix-link-match, r=GuillaumeGomez
rustdoc: Fix LinkReplacer link matching

It currently just uses the first link with the same href which might not necessarily be the matching one.

This fixes replacements when there are several links to the same item but with different text (e.g. `[X] and [struct@X]`). It also fixes replacements in summaries since those use a links list with empty hrefs, so currently all links would always match the first link by href but then not match its text. This could also lead to a panic in the `original_lext[1..len() - 1]` part when the first link only has a single character, which is why the new code uses `.get(..)` instead.
2023-06-01 11:09:42 +05:30
bors
23f93a1266 Auto merge of #103877 - oli-obk:const_eval_step_limit, r=fee1-dead
Replace const eval limit by a lint and add an exponential backoff warning

The lint triggers at the first power of 2 that comes after 1 million function calls or traversed back-edges (takes less than a second on usual programs). After the first emission, an unsilenceable warning is repeated at every following power of 2 terminators, causing it to get reported less and less the longer the evaluation runs.

cc `@rust-lang/wg-const-eval`

fixes #93481
closes #67217
2023-06-01 05:32:00 +00:00
Scott McMurray
bf36193ef6 Add a distinct OperandValue::ZeroSized variant for ZSTs
These tend to have special handling in a bunch of places anyway, so the variant helps remember that.  And I think it's easier to grok than non-Scalar Aggregates sometimes being `Immediates` (like I got wrong and caused 109992).  As a minor bonus, it means we don't need to generate poison LLVM values for them to pass around in `OperandValue::Immediate`s.
2023-05-31 19:10:28 -07:00
bors
ba1690bedd Auto merge of #111567 - Urgau:uplift_cast_ref_to_mut, r=b-naber
Uplift `clippy::cast_ref_to_mut` lint

This PR aims at uplifting the `clippy::cast_ref_to_mut` lint into rustc.

## `cast_ref_to_mut`

(deny-by-default)

The `cast_ref_to_mut` lint checks for casts of `&T` to `&mut T` without using interior mutability.

### Example

```rust,compile_fail
fn x(r: &i32) {
    unsafe {
        *(r as *const i32 as *mut i32) += 1;
    }
}
```

### Explanation

Casting `&T` to `&mut T` without interior mutability is undefined behavior, as it's a violation of Rust reference aliasing requirements.

-----

Mostly followed the instructions for uplifting a clippy lint described here: https://github.com/rust-lang/rust/pull/99696#pullrequestreview-1134072751

`@rustbot` label: +I-lang-nominated
r? compiler

-----

For Clippy:

changelog: Moves: Uplifted `clippy::cast_ref_to_mut` into rustc
2023-06-01 01:27:32 +00:00
Ben Kimock
79ba7b307d Enable ScalarReplacementOfAggregates 2023-05-31 19:18:16 -04:00
bors
9af3865dec Auto merge of #110807 - petrochenkov:strictflavor, r=lqd,wesleywiser
linker: Report linker flavors incompatible with the current target

The linker flavor is checked for target compatibility even if linker is never used (e.g. we are producing a rlib).
If it causes trouble, we can move the check to `link.rs` so it will run if the linker (flavor) is actually used.

And also feature gate explicitly specifying linker flavors for tier 3 targets.

The next step is supporting all the internal linker flavors in user-visible interfaces (command line and json).
2023-05-31 22:40:25 +00:00
Ziru Niu
e8c831a03b add inline-const test for elided lifetimes being infer vars 2023-06-01 02:28:31 +08:00
Michael Goulet
df1c1afdaf Check that RPITs are compatible with the opaques inferred during HIR typeck too 2023-05-31 17:45:45 +00:00
Michael Goulet
0a51ab93cf Don't suggest break through nested items 2023-05-31 16:51:25 +00:00
bors
871b595202 Auto merge of #111913 - oli-obk:valtrees2, r=lcnr
Only rewrite valtree-constants to patterns and keep other constants opaque

Now that we can reliably fall back to comparing constants with `PartialEq::eq` to the match scrutinee, we can

1. eagerly try to convert constants to valtrees
2. then deeply convert the valtree to a pattern
3. if the to-valtree conversion failed, create an "opaque constant" pattern.

This PR specifically avoids any behavioral changes or major cleanups. What we can now do as follow ups is

* move the two remaining call sites to `destructure_mir_constant` off that query
* make valtree to pattern conversion infallible
    * this needs to be done after careful analysis of the effects. There may be user visible changes from that.

based on https://github.com/rust-lang/rust/pull/111768
2023-05-31 16:36:51 +00:00
Oli Scherer
3c02cfc3e7 Explain the reason for why a test exists 2023-05-31 14:07:16 +00:00
Oli Scherer
d030ece6f7 Only rewrite valtree-constants to patterns and keep other constants opaque 2023-05-31 14:02:57 +00:00
bors
ad8304a0d5 Auto merge of #111076 - notriddle:notriddle/silence-private-dep-trait-impl-suggestions, r=cjgillot
diagnostics: exclude indirect private deps from trait impl suggest

Fixes #88696
2023-05-31 13:47:36 +00:00
Urgau
32d4e1c3c7 Adjust tests for newly uplifted cast_ref_to_mut lint 2023-05-31 13:42:53 +02:00
Guillaume Gomez
9dedb43e87 Migrate GUI colors test to original CSS color format 2023-05-31 13:03:46 +02:00
bors
e4f7ad8e68 Auto merge of #112132 - matthiaskrgr:rollup-x2l75gf, r=matthiaskrgr
Rollup of 5 pull requests

Successful merges:

 - #111772 (Fix linkage for large binaries on mips64 platforms)
 - #111975 (Stop normalizing so many different prefixes)
 - #111979 (Respect CARGOFLAGS in bootstrap.py)
 - #112089 (Add `--warnings warn` flag to `x.py`)
 - #112103 (Bootstrap update to 1.71 beta)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-05-31 11:03:00 +00:00
Urgau
5da606779c Uplift clippy::cast_ref_to_mut to rustc 2023-05-31 12:28:38 +02:00
Oli Scherer
05eae08233 Remove const eval limit and implement an exponential backoff lint instead 2023-05-31 10:24:17 +00:00
Matthias Krüger
ef82bd4b55
Rollup merge of #111975 - jyn514:normalization, r=cjgillot
Stop normalizing so many different prefixes

Previously, we would normalize *all* of
- the absolute path to the repository checkout
- the /rustc/$sha for stage1 (if `remap-debuginfo` was enabled)
- the /rustc/$sha for download-rustc
- the sysroot for download-rustc

Now, we consistently only normalize /rustc/FAKE_PREFIX. Not only is this much simpler, but it also avoids ongoing maintenance for download-rustc and makes it much less likely that tests break by accident.

- Change `tests/ui/track-diagnostics/track6.rs` to use a relative path instead of an absolute one. I am not actually sure why `track_caller` works here, but it does seem to work 🤷

- Pass `-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX` to all suites, not just UI. In particular, mir-opt tests emit /rustc/ paths in their output.

r? ```@cjgillot``` since you reviewed https://github.com/rust-lang/rust/pull/110699 - this is the test that it doesn't regress :)
2023-05-31 11:19:07 +02:00
Matthias Krüger
fd1c0d8585
Rollup merge of #111772 - liushuyu:ubuntu/mips64-linkage, r=jackh726
Fix linkage for large binaries on mips64 platforms

This pull request fixes the linkage for large binaries on mips64 platforms by enabling the `xgot` feature in LLVM.

It is well understood that the generated binary will gain a hefty performance penalty where the external symbol jumps now cost at least three instructions each.

Also, this pull request does not address the same issue on the mips32 counterparts (due to being unable to test the changes thoroughly).

Should fix #52108
2023-05-31 11:19:07 +02:00
bors
e29821ff85 Auto merge of #111623 - BoxyUwU:move_eval_hack, r=compiler-errors
move `super_relate_consts` hack to `normalize_param_env_or_error`

`super_relate_consts` has as hack in it to work around the fact that `normalize_param_env_or_error` is broken. When relating two constants we attempt to evaluate them (aka normalize them). This is not an issue in any way specific to const generics, type aliases also have the same issue as demonstrated in [this code](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=84b6d3956a2c852a04b60782476b56c9).

Since the hack in `super_relate_consts` only exists to make `normalize_param_env_or_error` emit less errors move it to `normalize_param_env_or_error`. This makes `super_relate_consts` act more like the normal plain structural equality its supposed to and should help ensure that the hack doesnt accidentally affect other situations.

r? `@compiler-errors`
2023-05-31 08:25:28 +00:00
Matthias Krüger
1d643e16c2
Rollup merge of #112108 - GuillaumeGomez:reexport-doc-hidden-private, r=notriddle
Fix re-export of doc hidden item inside private item not displayed

This PR fixes this bug:

```rust
mod private_module {
    #[doc(hidden)]
    pub struct Public;
}

pub use crate::private_module::Public as Foo;
```

`pub use crate::private_module::Public as Foo;` should be visible in the generated doc (and not inlined!) but currently isn't. This PR fixes it.

r? `@notriddle`
2023-05-31 07:07:02 +02:00
Matthias Krüger
88160ab94c
Rollup merge of #112096 - workingjubilee:array-unzip, r=scottmcm
Remove array_zip

`[T; N]::zip` is "eager" but most zips are mapped. This causes poor optimization in generated code. This is a fundamental design issue and "zip" is "prime real estate" in terms of function names, so let's free it up again.

- FCP concluded in https://github.com/rust-lang/rust/issues/80094#issuecomment-1468300057
- Closes https://github.com/rust-lang/rust/issues/80094
- Closes https://github.com/rust-lang/rust/issues/103555

Could use review to make sure we aren't losing any essential codegen tests.
r? `@scottmcm`
2023-05-31 07:07:02 +02:00
Matthias Krüger
f5894517ec
Rollup merge of #112069 - clubby789:offset-of-sized-fields, r=WaffleLapkin
offset_of: don't require type to be `Sized`

Fixes #112051

~~The RFC [explicitly forbids](https://rust-lang.github.io/rfcs/3308-offset_of.html#limitations) non-`Sized` types, but it looks like only the fields being recursed into were checked. The sized check also seemed to have been completely missing for tuples~~
2023-05-31 07:07:01 +02:00
ScottMcMurray
374f5a8091 Test from_fn autovectorizes 2023-05-30 20:45:40 -07:00
Boxy
21cf9ea7ed update test to not rely on super_relate_consts hack 2023-05-31 02:14:15 +01:00
bors
e6e4f7ed15 Auto merge of #112070 - lcnr:disjoint-closure-capture-ub, r=oli-obk
change `BorrowKind::Unique` to be a mutating `PlaceContext`

fixes #112056

I believe that `BorrowKind::Unique` is a footgun in general, so I added a FIXME and opened https://github.com/rust-lang/rust/issues/112072. This is a bit too involved for this PR though.
2023-05-31 00:24:39 +00:00
benediktwerner
9968f3ce55
rustdoc: Fix LinkReplacer link matching 2023-05-30 21:22:30 +02:00
bors
f0411ffceb Auto merge of #111881 - lcnr:leak-check, r=nikomatsakis,jackh726
refactor and cleanup the leak check, add it to new solver

ended up being a bit more involved than I wanted but is hopefully still easy enough to review as a single PR, can split it into separate ones otherwise.

this can be reviewed commit by commit:
a473d55cdb9284aa2b01282d1b529a2a4d26547b 31a686646534ca006d906ec757ece4e771d6f973 949039c107852a5e36361c08b62821a0613656f5 242917bf5170d9a723c6c8e23e9d9d0c2fa8dc9d ed2b25a7aa28be3184be9e3022c2796a30eaad87 are all pretty straightforward.

03dd83b4c3f4ff27558f5c8ab859bd9f83db1d04 makes it easier to refactor coherence in a later commit, see the commit description, cc `@oli-obk`

4fe311d807a77b6270f384e41689bf5d58f46aec I don't quite remember what we wanted to test here, this definitely doesn't test that the occurs check doesn't cause incorrect errors in coherence, also cc `@oli-obk` here. I may end up writing a new test for this myself later.

5c200d88a91b75bd0875b973150655bd581ef97a is the main refactor of the leak check, changing it to take the `outer_universe` instead of getting it from a snapshot. Using a snapshot requires us to be in a probe which we aren't in the new solver, it also just feels dirty as snapshots don't really have anything to do with universes.

with all of this cfc230d54188d9c7ed867a9a0d1f51be77b485f9 is now kind of trivial.

r? `@nikomatsakis`
2023-05-30 18:48:12 +00:00
Guillaume Gomez
9906504c64 Add regression test for re-export of doc hidden item inside private item not displayed 2023-05-30 20:27:53 +02:00
bors
a9251b6ce1 Auto merge of #112102 - Nilstrieb:rollup-ivu1hmc, r=Nilstrieb
Rollup of 7 pull requests

Successful merges:

 - #107916 (fix comment on Allocator trait)
 - #111543 (Uplift `clippy::invalid_utf8_in_unchecked` lint)
 - #111872 (fix: dedup `static_candidates` before report)
 - #111955 (bootstrap: Various Step refactors)
 - #112060 (`EarlyBinder::new` -> `EarlyBinder::bind`)
 - #112064 (Migrate GUI colors test to original CSS color format)
 - #112100 (Don't typecheck recovered method call from suggestion)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-05-30 13:25:42 +00:00
lcnr
dccc8db17d coinductive cycle leak check test 2023-05-30 13:04:27 +02:00
lcnr
5119f7da18 directory size limit :< 2023-05-30 13:04:25 +02:00
lcnr
6f9041bd15 add the leak check to the new solver 2023-05-30 13:03:40 +02:00
lcnr
04056b5c04 update revision names 2023-05-30 13:03:40 +02:00
Nilstrieb
cc121828ee
Rollup merge of #112100 - jieyouxu:issue-106929, r=oli-obk
Don't typecheck recovered method call from suggestion

Only make the use-dot-operator-to-call-method suggestion, but do not double down and use the recovered type to perform method call typechecking as it will produce confusing diagnostics relevant for the *fixed* code.

### Code Sample

```rust
struct Client;

impl Client {
    fn post<T: std::ops::Add>(&self, _: T, _: T) {}
}

fn f() {
    let c = Client;
    post(c, ());
}
```

### Before This PR

```
error[[E0277]](https://doc.rust-lang.org/stable/error_codes/E0277.html): cannot add `()` to `()`
 --> src/lib.rs:9:5
  |
9 |     post(c, ());
  |     ^^^^^^^^^^^ no implementation for `() + ()`
  |
  = help: the trait `Add` is not implemented for `()`
note: required by a bound in `Client::post`
 --> src/lib.rs:4:16
  |
4 |     fn post<T: std::ops::Add>(&self, _: T, _: T) {}
  |                ^^^^^^^^^^^^^ required by this bound in `Client::post`

error[[E0061]](https://doc.rust-lang.org/stable/error_codes/E0061.html): this function takes 2 arguments but 1 argument was supplied
 --> src/lib.rs:9:5
  |
9 |     post(c, ());
  |     ^^^^ an argument of type `()` is missing
  |
note: method defined here
 --> src/lib.rs:4:8
  |
4 |     fn post<T: std::ops::Add>(&self, _: T, _: T) {}
  |        ^^^^                   -----  ----  ----
help: provide the argument
  |
9 |     post((), ())(c, ());
  |         ++++++++

error[[E0425]](https://doc.rust-lang.org/stable/error_codes/E0425.html): cannot find function `post` in this scope
 --> src/lib.rs:9:5
  |
9 |     post(c, ());
  |     ^^^^ not found in this scope
  |
help: use the `.` operator to call the method `post` on `&Client`
  |
9 -     post(c, ());
9 +     c.post(());
  |

Some errors have detailed explanations: E0061, E0277, E0425.
For more information about an error, try `rustc --explain E0061`.
```

### After This PR

```
error[E0425]: cannot find function `post` in this scope
 --> tests/ui/typeck/issue-106929.rs:9:5
  |
9 |     post(c, ());
  |     ^^^^ not found in this scope
  |
help: use the `.` operator to call the method `post` on `&Client`
  |
9 -     post(c, ());
9 +     c.post(());
  |

error: aborting due to previous error

For more information about this error, try `rustc --explain E0425`.
```

Fixes #106929.
2023-05-30 12:57:41 +02:00
Nilstrieb
f4b20dac81
Rollup merge of #112064 - GuillaumeGomez:migrate-gui-test-color-9, r=notriddle
Migrate GUI colors test to original CSS color format

Follow-up of https://github.com/rust-lang/rust/pull/111459.

The `browser-ui-test` update is a fix when converting the alpha value to hex format. More information [here](https://github.com/GuillaumeGomez/browser-UI-test/pull/511).

r? ````@notriddle````
2023-05-30 12:57:40 +02:00
Nilstrieb
0c9f87c986
Rollup merge of #111872 - bvanjoi:fix-103646, r=cjgillot
fix: dedup `static_candidates` before report

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

`record_static_candidate` had been executed twice, resulting in the presence of two identical `CandidateSource::Trait(Cat)`  in static_candidates. This PR aims to deduplication the `static_candidates` list, allowing it to execute `suggest_associated_call_syntax` properly.
2023-05-30 12:57:39 +02:00
Nilstrieb
7a4006cc52
Rollup merge of #111543 - Urgau:uplift_invalid_utf8_in_unchecked, r=WaffleLapkin
Uplift `clippy::invalid_utf8_in_unchecked` lint

This PR aims at uplifting the `clippy::invalid_utf8_in_unchecked` lint into two lints.

## `invalid_from_utf8_unchecked`

(deny-by-default)

The `invalid_from_utf8_unchecked` lint checks for calls to `std::str::from_utf8_unchecked` and `std::str::from_utf8_unchecked_mut` with an invalid UTF-8 literal.

### Example

```rust
unsafe {
    std::str::from_utf8_unchecked(b"cl\x82ippy");
}
```

### Explanation

Creating such a `str` would result in undefined behavior as per documentation for `std::str::from_utf8_unchecked` and `std::str::from_utf8_unchecked_mut`.

## `invalid_from_utf8`

(warn-by-default)

The `invalid_from_utf8` lint checks for calls to `std::str::from_utf8` and `std::str::from_utf8_mut` with an invalid UTF-8 literal.

### Example

```rust
std::str::from_utf8(b"ru\x82st");
```

### Explanation

Trying to create such a `str` would always return an error as per documentation for `std::str::from_utf8` and `std::str::from_utf8_mut`.

-----

Mostly followed the instructions for uplifting a clippy lint described here: https://github.com/rust-lang/rust/pull/99696#pullrequestreview-1134072751

````@rustbot```` label: +I-lang-nominated
r? compiler

-----

For Clippy:

changelog: Moves: Uplifted `clippy::invalid_utf8_in_unchecked` into rustc
2023-05-30 12:57:38 +02:00
lcnr
2a4467da9f add FIXME to a test which seems wrong. 2023-05-30 12:40:35 +02:00
lcnr
aa13288e22 remove unused revision 2023-05-30 12:40:35 +02:00
lcnr
0a6ae29fe8 coherence: don't add hidden types for opaques
we can otherwise assign a hidden type to the opaque which
causes ICE if we don't use `take_opaque_types` during
coherence. This is annoying so I didn't bother. Added a test
showing the behavior this prevents.
2023-05-30 12:40:35 +02:00
bors
3266c36624 Auto merge of #111768 - oli-obk:pair_const_llvm, r=cjgillot
Optimize scalar and scalar pair representations loaded from ByRef in llvm

in https://github.com/rust-lang/rust/pull/105653 I noticed that we were generating suboptimal LLVM IR if we had a `ConstValue::ByRef` that could be represented by a `ScalarPair`. Before https://github.com/rust-lang/rust/pull/105653 this is probably rare, but after it, every slice will go down this suboptimal code path that requires LLVM to untangle a bunch of indirections and translate static allocations that are only used once to read a scalar pair from.
2023-05-30 10:31:10 +00:00
许杰友 Jieyou Xu (Joe)
e11ffb62df
Don't typecheck suggested method call
Only make the use-dot-operator-to-call-method suggestion, but do not
double down and use the recovered type to perform method call
typechecking as it will produce confusing diagnostics on the "fixed"
code.
2023-05-30 17:57:37 +08:00
Jubilee Young
472230d192 Remove array_zip
`[T; N]::zip` is "eager" but most zips are mapped.
This causes poor optimization in generated code.
This is a fundamental design issue and "zip" is
"prime real estate" in terms of function names,
so let's free it up again.
2023-05-30 00:40:39 -07:00
bors
578bcbc2b4 Auto merge of #112083 - scottmcm:simpler-range-next, r=thomcc
Make `TrustedStep` require `Copy`

All the implementations of the trait already are `Copy`, and this seems to be enough to simplify the implementations enough to make the MIR inliner willing to inline basics like `Range::next`.

r? `@thomcc`
2023-05-30 07:27:05 +00:00
clubby789
6c18d1ecef offset_of: Don't require type to be sized 2023-05-29 21:56:10 +00:00
Scott McMurray
11fa1764ee Make TrustedStep require Copy
All the implementations of the trait already are `Copy`, and this seems to be enough to simplify the implementations enough to make the MIR inliner willing to inline basics like `Range::next`.
2023-05-29 13:19:47 -07:00
Matthias Krüger
36526cf657
Rollup merge of #112063 - WaffleLapkin:test_incremental_ice, r=cjgillot
Add a test for issue 110457/incremental ICE with closures with the same span

Closes #110457

It's probably possible to minimize the test case more, considering that we now know the underlying reason for the ICE, but I didn't.

r? `@cjgillot`
2023-05-29 21:34:18 +02:00
Matthias Krüger
880da380f1
Rollup merge of #112057 - MU001999:fix/self-sugg, r=compiler-errors
Suggest correct `self_ty`

Fixes #112036
2023-05-29 21:34:18 +02:00
Matthias Krüger
ef9a681183
Rollup merge of #112022 - compiler-errors:coercion-check-deep, r=lcnr
Check nested obligations during coercion unify in new solver

Found when triaging failing opaque tests with new solver.

r? `@lcnr`
2023-05-29 21:34:17 +02:00
Matthias Krüger
9f83e56f0d
Rollup merge of #111988 - BoxyUwU:make_tykind_debug_good, r=compiler-errors
Make `TyKind: Debug` have less verbose output

Current `TyKind: Debug` impl is basically unusable for debugging, its too verbose even for verbose debugging 🤣 This PR replaces the debug logic for `TyKind` with a more manual debug impl instead of a hand expanded derived impl. This should help make #107084 more reasonable to land since the output of `Ty: Debug` will be better.

This isn't a fully completed change to the `Debug` impl of `TyKind` as there's still logic from the derive macro for some variants. Some of the variants are also not consisten with the `-Zverbose` printing of `Ty`, ideally `-Zverbose` printing of `Ty` would also just defer to the debug impl instead of having lots of checks in pretty printing. I plan on fixing this in follow up PRs since it seems tricky to do in this one and its already a large PR 😅
2023-05-29 21:34:17 +02:00
Matthias Krüger
9e47e90071
Rollup merge of #111558 - c410-f3r:t3st3ss, r=WaffleLapkin
Move tests

r? `@petrochenkov`
2023-05-29 21:34:16 +02:00
Obei Sideg
70bbcceaec Add test for #![doc(test(...)] with literal parameter 2023-05-29 22:33:46 +03:00
Vadim Petrochenkov
2f7328d970 Fix tests on non-unix targets 2023-05-29 19:58:11 +03:00
Vadim Petrochenkov
23f177d86d rustc_session: Feature gate linker flavors for tier 3 targets 2023-05-29 19:58:11 +03:00
Vadim Petrochenkov
b0ce4164f0 linker: Report linker flavors incompatible with the current target
Previously they would be reported as link time errors about unknown linker options
2023-05-29 19:58:11 +03:00
Ximin Luo
b65c2afdfd
Fix linkage for large binaries on mips64 platforms ...
... by enabling xgot feature

Co-Authored-By: Zixing Liu <zixing.liu@canonical.com>
2023-05-29 10:57:03 -06:00
lcnr
b5732508dd add tests 2023-05-29 18:37:53 +02:00
Caio
c62d49e75e Address comment 2023-05-29 12:07:41 -03:00
Guillaume Gomez
17e3d1cd4a Migrate GUI colors test to original CSS color format 2023-05-29 16:03:56 +02:00
Maybe Waffle
8d406b8459 Add a test for issue 110457 2023-05-29 13:49:20 +00:00
Lukas Markeffsky
381b778d27 Make struct layout not depend on unsizeable tail 2023-05-29 14:54:48 +02:00
Camille GILLOT
89bf30e73d Enable SeparateConstSwitch by default. 2023-05-29 10:31:01 +00:00
bors
70e04bd88d Auto merge of #111748 - nnethercote:Cow-DiagnosticMessage, r=WaffleLapkin
Use `Cow` in `{D,Subd}iagnosticMessage`.

Each of `{D,Subd}iagnosticMessage::{Str,Eager}` has a comment:
```
// FIXME(davidtwco): can a `Cow<'static, str>` be used here?
```
This commit answers that question in the affirmative. It's not the most compelling change ever, but it might be worth merging.

This requires changing the `impl<'a> From<&'a str>` impls to `impl From<&'static str>`, which involves a bunch of knock-on changes that require/result in call sites being a little more precise about exactly what kind of string they use to create errors, and not just `&str`. This will result in fewer unnecessary allocations, though this will not have any notable perf effects given that these are error paths.

Note that I was lazy within Clippy, using `to_string` in a few places to preserve the existing string imprecision. I could have used `impl Into<{D,Subd}iagnosticMessage>` in various places as is done in the compiler, but that would have required changes to *many* call sites (mostly changing `&format("...")` to `format!("...")`) which didn't seem worthwhile.

r? `@WaffleLapkin`
2023-05-29 07:10:44 +00:00
许杰友 Jieyou Xu (Joe)
57e67e4ab2
Don't suggest changing {ImmRef,MutRef} implicit self to be mutable 2023-05-29 13:11:03 +08:00
mu001999
2f65aac667 Determine self_ty with expected ty 2023-05-29 12:26:27 +08:00
bors
dc0943d2ee Auto merge of #112055 - matthiaskrgr:rollup-y3exx8c, r=matthiaskrgr
Rollup of 5 pull requests

Successful merges:

 - #112029 (Recover upon mistyped error on typo'd `const` in const param def)
 - #112037 (Add details about `unsafe_op_in_unsafe_fn` to E0133)
 - #112039 (compiler: update solaris/illumos to enable tsan support.)
 - #112042 (Migrate GUI colors test to original CSS color format)
 - #112045 (Followup to #111973)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-05-29 03:04:06 +00:00
Matthias Krüger
760d46ed06
Rollup merge of #112042 - GuillaumeGomez:migrate-gui-test-color-8, r=notriddle
Migrate GUI colors test to original CSS color format

Follow-up of https://github.com/rust-lang/rust/pull/111459.

r? `@notriddle`
2023-05-29 04:03:03 +02:00
Matthias Krüger
45ca2f732e
Rollup merge of #112029 - jieyouxu:typo-const-in-const-param-def, r=cjgillot
Recover upon mistyped error on typo'd `const` in const param def

And add machine-applicable fix for the typo'd `const` keyword.

### Before

```
error: expected one of `,`, `:`, `=`, or `>`, found `N`
 --> src/lib.rs:1:18
  |
1 | pub fn bar<Const N: u8>() {}
  |                  ^ expected one of `,`, `:`, `=`, or `>`
```

### After This PR

```
error: `const` keyword was mistyped as `Const`
 --> test.rs:1:8
  |
1 | fn bar<Const N: u8>() {}
  |        ^^^^^
  |
help: use the `const` keyword
  |
1 | fn bar<const N: u8>() {}
  |        ~~~~~

```

Fixes #111941.
2023-05-29 04:03:01 +02:00
bors
f8447b9638 Auto merge of #111963 - nnethercote:inline-derived-hash, r=lqd
Inline derived `hash`

Because most of the other derived functions are inlined: `clone`, `default`, `eq`, `partial_cmp`, `cmp`. The exception is `fmt`, but it tends to not be on hot paths as much.

r? `@ghost`
2023-05-29 00:25:54 +00:00
Nicholas Nethercote
781111ef35 Use Cow in {D,Subd}iagnosticMessage.
Each of `{D,Subd}iagnosticMessage::{Str,Eager}` has a comment:
```
// FIXME(davidtwco): can a `Cow<'static, str>` be used here?
```
This commit answers that question in the affirmative. It's not the most
compelling change ever, but it might be worth merging.

This requires changing the `impl<'a> From<&'a str>` impls to `impl
From<&'static str>`, which involves a bunch of knock-on changes that
require/result in call sites being a little more precise about exactly
what kind of string they use to create errors, and not just `&str`. This
will result in fewer unnecessary allocations, though this will not have
any notable perf effects given that these are error paths.

Note that I was lazy within Clippy, using `to_string` in a few places to
preserve the existing string imprecision. I could have used `impl
Into<{D,Subd}iagnosticMessage>` in various places as is done in the
compiler, but that would have required changes to *many* call sites
(mostly changing `&format("...")` to `format!("...")`) which didn't seem
worthwhile.
2023-05-29 09:23:43 +10:00
bors
089677eb32 Auto merge of #111813 - scottmcm:pretty-mir, r=cjgillot
MIR: opt-in normalization of `BasicBlock` and `Local` numbering

This doesn't matter at all for actual codegen, but after spending some time reading pre-codegen MIR, I was wishing I didn't have to jump around so much in reading post-inlining code.

So this add two passes that are off by default for every mir level, but can be enabled (`-Zmir-enable-passes=+ReorderBasicBlocks,+ReorderLocals`) for humans.
2023-05-28 21:53:56 +00:00
Guillaume Gomez
2eaa4e65ff Migrate GUI colors test to original CSS color format 2023-05-28 18:47:29 +02:00
bors
39c03fb652 Auto merge of #112026 - saethlin:misaligned-addrof, r=pnkfelix
Don't check for misaligned raw pointer derefs inside Rvalue::AddressOf

From https://github.com/rust-lang/rust/pull/112026#issuecomment-1565686697:

rustc 1.70 (stable next week) added a Mir pass to add pointer alignment checks in debug mode. Adding these checks caused some crates to break, but that was expected, since they contain broken code (https://github.com/rust-lang/rust/issues/111487) for tracking that.

However, the checks added are slightly more aggressive than they should have been. Specifically, they also check the place in an `addr_of!` expression. Whether lack of alignment there is or isn't UB is unclear. This PR modifies the pass to not affect those cases.

I spot checked the crater regressions and the ones I saw were not the case that this PR is modifying. It still seems good to not land anything overaggressive though
2023-05-28 12:33:52 +00:00
bors
f59d577838 Auto merge of #112001 - saethlin:enable-matchbranchsimplification, r=cjgillot
Enable MatchBranchSimplification

This pass is one of the small number of benefits from `-Zmir-opt-level=3` that has motivated rustc_codegen_cranelift to use it:

19ed0aade6/compiler/rustc_codegen_cranelift/build_system/build_sysroot.rs (L244-L246)

Cranelift's motivation for this is _runtime_ performance improvements in debug builds. Lifting this pass all the way to `-Zmir-opt-level=1` seems to come without significant perf overhead, so that's what I'm suggesting here.
2023-05-28 09:59:20 +00:00
许杰友 Jieyou Xu (Joe)
41f5a30690
Recover upon encountering mistyped Const in const param def 2023-05-28 16:55:21 +08:00
bors
2560b80a08 Auto merge of #112000 - wesleywiser:safestack, r=Amanieu
Add support for LLVM SafeStack

Adds support for LLVM [SafeStack] which provides backward edge control
flow protection by separating the stack into two parts: data which is
only accessed in provable safe ways is allocated on the normal stack
(the "safe stack") and all other data is placed in a separate allocation
(the "unsafe stack").

SafeStack support is enabled by passing `-Zsanitizer=safestack`.

[SafeStack]: https://clang.llvm.org/docs/SafeStack.html

cc `@rcvalle` #39699
2023-05-28 04:41:13 +00:00
bors
b9c5fdc888 Auto merge of #111378 - jieyouxu:local-shadows-glob-reexport, r=petrochenkov
Add warn-by-default lint when local binding shadows exported glob re-export item

This PR introduces a warn-by-default rustc lint for when a local binding (a use statement, or a type declaration) produces a name which shadows an exported glob re-export item, causing the name from the exported glob re-export to be hidden (see #111336).

### Unresolved Questions

- [x] ~~Is this approach correct? While it passes the UI tests, I'm not entirely convinced it is correct.~~ Seems to be ok now.
- [x] ~~What should the lint be called / how should it be worded? I don't like calling `use x::*;` or `struct Foo;` a "local binding" but they are `NameBinding`s internally if I'm not mistaken.~~ ~~The lint is called `local_binding_shadows_glob_reexport` for now, unless a better name is suggested.~~ `hidden_glob_reexports`.

Fixes #111336.
2023-05-28 01:18:51 +00:00
Ben Kimock
de4dddf155 Add a test for misaligned pointer derefs inside addr_of! 2023-05-27 14:52:14 -04:00
Matthias Krüger
97fae38bf9
Rollup merge of #111181 - bvanjoi:fix-issue-111148, r=davidtwco
fix(parse): return unpected when current token is EOF

close https://github.com/rust-lang/rust/issues/111148

#111148 panic occurred because [FatalError.raise()](https://github.com/bvanjoi/rust/blob/master/compiler/rustc_parse/src/parser/mod.rs#LL540C3-L540C3) was encountered which caused by `Eof` and `Pound`(the last token) had same span, when parsing `#` in `fn a<<i<Y<w<>#`.

<img width="825" alt="image" src="https://user-images.githubusercontent.com/30187863/236612589-9e2c6a0b-18cd-408c-b636-c12a51cbcf1c.png">

There are a few ways to solve this problem:

- Change the action assign for [self.last_unexpected_token_span](https://github.com/rust-lang/rust/blob/master/compiler/rustc_parse/src/parser/diagnostics.rs#L592), for example, if current token is `Eof`, then return Error directly.
- Avoid triggering the `FatalError` when the current token is `Eof`.

I have chosen the second option because executing `expected_one_of_not_found` when the token is `Eof` but not in `ediable` seems reasonable.
2023-05-27 20:40:28 +02:00
Ben Kimock
7e04c93493 Try enabling MatchBranchSimplification 2023-05-27 13:50:13 -04:00
Michael Goulet
00c92bd873 Check nested obligations during coercion unify 2023-05-27 17:37:16 +00:00
bors
f91b634643 Auto merge of #110975 - Amanieu:panic_count, r=joshtriplett
Rework handling of recursive panics

This PR makes 2 changes to how recursive panics works (a panic while handling a panic).

1. The panic count is no longer used to determine whether to force an immediate abort. This allows code like the following to work without aborting the process immediately:

```rust
struct Double;

impl Drop for Double {
    fn drop(&mut self) {
        // 2 panics are active at once, but this is fine since it is caught.
        std::panic::catch_unwind(|| panic!("twice"));
    }
}

let _d = Double;

panic!("once");
```

Rustc already generates appropriate code so that any exceptions escaping out of a `Drop` called in the unwind path will immediately abort the process.

2. Any panics while the panic hook is executing will force an immediate abort. This is necessary to avoid potential deadlocks like #110771 where a panic happens while holding the backtrace lock. We don't even try to print the panic message in this case since the panic may have been caused by `Display` impls.

Fixes #110771
2023-05-27 15:12:24 +00:00
Amanieu d'Antras
ef7f0e697b Rework handling of recursive panics 2023-05-27 16:35:16 +02:00
Guillaume Gomez
30896536f3
Rollup merge of #112014 - notriddle:notriddle/intra-doc-weird-syntax, r=GuillaumeGomez,fmease
rustdoc: get unnormalized link destination for suggestions

Fixes #110111

This bug, and the workaround in this PR, is closely linked to [raphlinus/pulldown-cmark#441], getting offsets of link components. In particular, pulldown-cmark doesn't provide the offsets of the contents of a link.

To work around this, rustdoc parser parts of a link definition itself.

[raphlinus/pulldown-cmark#441]: https://github.com/raphlinus/pulldown-cmark/issues/441
2023-05-27 13:38:33 +02:00
Guillaume Gomez
480ac69a4c
Rollup merge of #111997 - GuillaumeGomez:re-export-doc-hidden-macros, r=notriddle
Fix re-export of doc hidden macro not showing up

It's part of the follow-up of https://github.com/rust-lang/rust/pull/109697.

Re-exports of doc hidden macros should be visible. It was the only kind of re-export of doc hidden item that didn't show up.

r? `@notriddle`
2023-05-27 13:38:33 +02:00
Guillaume Gomez
ddb5424569
Rollup merge of #111952 - cjgillot:drop-replace, r=WaffleLapkin
Remove DesugaringKind::Replace.

A simple boolean flag is enough.
2023-05-27 13:38:31 +02:00
许杰友 Jieyou Xu (Joe)
b9606589c4
Add warn-by-default lint for local binding shadowing exported glob re-export item 2023-05-27 18:49:07 +08:00
bors
a525c7ddba Auto merge of #111928 - c410-f3r:dqewdas, r=eholk
[RFC-2011] Expand more expressions

cc #44838

Expands `if`, `let`, `match` and also makes `generic_assert_internals` an allowed feature when using `assert!`. `#![feature(generic_assert)]` is still needed to activate everything.

```rust
#![feature(generic_assert)]

fn fun(a: Option<i32>, b: Option<i32>, c: Option<i32>) {
  assert!(
    if a.is_some() { 1 } else { 2 } == 3
      && if let Some(elem) = b { elem == 4 } else { false }
      && match c { Some(_) => true, None => false }
  );
}

fn main() {
  fun(Some(1), None, Some(2));
}

// Assertion failed: assert!(
//   if a.is_some() { 1 } else { 2 } == 3
//     && if let Some(elem) = b { elem == 4 } else { false }
//     && match c { Some(_) => true, None => false }
// );
//
// With captures:
//   a = Some(1)
//   b = None
//   c = Some(2)
```
2023-05-27 07:02:48 +00:00
bors
dbfc95f969 Auto merge of #111348 - ozkanonur:remove-hardcoded-rustdoc-flags, r=albertlarsan68,oli-obk
new tool `rustdoc-gui-test`

Implements new tool `rustdoc-gui-test` that allows using compiletest headers for `rustdoc-gui` tests.
2023-05-27 04:20:44 +00:00
Michael Howell
1a77d9a54d rustdoc: get unnormalized link destination for suggestions
Fixes #110111

This bug, and the workaround in this commit, is closely linked to
[raphlinus/pulldown-cmark#441], getting offsets of link
components. In particular, pulldown-cmark doesn't provide the
offsets of the contents of a link.

To work around this, rustdoc parser parts of a link definition
itself.

[raphlinus/pulldown-cmark#441]: https://github.com/raphlinus/pulldown-cmark/issues/441
2023-05-26 18:38:46 -07:00
bors
23040c4a5f Auto merge of #111245 - fee1-dead-contrib:temp-fix-tuple-struct-field, r=lcnr
fix for `Self` not respecting tuple Ctor privacy

This PR fixes #111220 by checking the privacy of tuple constructors using `Self`, so the following code now errors
```rust
mod my {
    pub struct Foo(&'static str);
}

impl AsRef<str> for my::Foo {
    fn as_ref(&self) -> &str {
        let Self(s) = self; // previously compiled, now errors correctly
        s
    }
}
```
2023-05-27 01:27:01 +00:00
Guillaume Gomez
898dfc680f Correctly handle multiple re-exports of bang macros at the same level 2023-05-27 00:25:37 +02:00
Matthias Krüger
a99209738e
Rollup merge of #111991 - BoxyUwU:change_error_term_display, r=compiler-errors
Change ty and const error's pretty printing to be in braces

`[const error]` and `[type error]` are slightly confusing since they look like either a slice with an error type for the element ty or a slice with a const argument as the type ???. This PR changes them to display as `{const error}` and `{type error}`  similar to `{integer}`.

This does not update the `Debug` impls for them which is done in #111988.

I updated some error logic to avoid printing the substs of trait refs when unable to resolve an assoc item for them, this avoids emitting errors with `{type error}` in them. The substs are not relevant for these errors since we don't take into account the substs when resolving the assoc item.

r? ``@compiler-errors``
2023-05-27 00:24:01 +02:00
Matthias Krüger
e7068ff819
Rollup merge of #111954 - asquared31415:unknown_ptr_type_error, r=compiler-errors
improve error message for calling a method on a raw pointer with an unknown pointee

The old error message had very confusing wording.
Also added some more test cases besides the single edition test.

r? `@compiler-errors`
2023-05-27 00:23:58 +02:00
Matthias Krüger
51cf1b62bc
Rollup merge of #111714 - cjgillot:lint-expect-confusion, r=wesleywiser
Stop confusing specification levels when computing expectations.

Fixes https://github.com/rust-lang/rust/issues/111682
2023-05-27 00:23:57 +02:00
Urgau
b84c190b9a Allow newly uplifted invalid_from_utf8 lint 2023-05-27 00:18:28 +02:00
Urgau
7f99c7d3e6 Add invalid_from_utf8 analogous to invalid_from_utf8_unchecked 2023-05-27 00:18:28 +02:00
Urgau
7f8846a9ef Uplift clippy::invalid_utf8_in_unchecked as invalid_from_utf8_unchecked 2023-05-27 00:16:47 +02:00
Wesley Wiser
019d75b44e Add SafeStack support to rustc
Adds support for LLVM [SafeStack] which provides backward edge control
flow protection by separating the stack into two parts: data which is
only accessed in provable safe ways is allocated on the normal stack
(the "safe stack") and all other data is placed in a separate allocation
(the "unsafe stack").

SafeStack support is enabled by passing `-Zsanitizer=safestack`.

[SafeStack]: https://clang.llvm.org/docs/SafeStack.html
2023-05-26 15:18:54 -04:00
Boxy
976adf3d6d better TyKind::Debug 2023-05-26 18:55:02 +01:00
bors
1a5f8bce74 Auto merge of #103291 - ink-feather-org:typeid_no_struct_match, r=dtolnay
Remove structural match from `TypeId`

As per https://github.com/rust-lang/rust/pull/99189#issuecomment-1203720442.

> Removing the structural equality might make sense, but is a breaking change that'd require a libs-api FCP.

https://github.com/rust-lang/rust/pull/99189#issuecomment-1197545482

> Landing this PR now (well, mainly the "remove structural equality" part) would unblock `const fn` `TypeId::of`, since we only postponed that because we were guaranteeing too much.

See also #99189, #101698
2023-05-26 17:29:03 +00:00
jyn
157d936c31 Stop normalizing so many different prefixes
Previously, we would normalize *all* of
- the absolute path to the repository checkout
- the /rustc/$sha for stage1 (if `remap-debuginfo` was enabled)
- the /rustc/$sha for download-rustc
- the sysroot for download-rustc

Now, we consistently only normalize /rustc/FAKE_PREFIX. Not only is this
much simpler, but it also avoids ongoing maintenance for download-rustc
and makes it much less likely that tests break by accident.

- Change `tests/ui/track-diagnostics/track6.rs` to use a relative path
  instead of an absolute one. I am not actually sure why `track_caller`
works here, but it does seem to work 🤷

- Pass `-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX` to all
  suites, not just UI. In particular, mir-opt tests emit /rustc/ paths
  in their output.
2023-05-26 12:16:30 -05:00
asquared31415
b19466abc2 improve error message for calling a method on a raw pointer with an unknown pointee, and add some tests 2023-05-26 13:15:15 -04:00
bohan
f78369b3af fix: dedup static_candidates before report 2023-05-27 00:52:07 +08:00
Guillaume Gomez
c908d1e4de Update tests for re-exports of doc hidden macros 2023-05-26 17:31:54 +02:00
Oli Scherer
164d041e30 Stop creating intermediate places just to immediate convert them to operands 2023-05-26 15:01:29 +00:00
Boxy
ad77bc8427 print const and type errors in braces not square brackets 2023-05-26 16:01:29 +01:00
Oli Scherer
5f66c41921 Add regression test 2023-05-26 15:00:31 +00:00
Michael Goulet
3d09b990d7 Wait until type_of to remap HIR opaques back to their defn params 2023-05-26 14:42:52 +00:00
Michael Goulet
a810b584cf Use DefiningAnchor::Bind in infer_opaque_definition_from_instantiation 2023-05-26 14:42:31 +00:00
onestacked
6827a413c8 Blesses UI tests, add known bug to typeid-equality-by-subtyping 2023-05-26 09:53:05 +02:00
Matthias Krüger
dd74ae0929
Rollup merge of #111951 - cjgillot:uninh-comment, r=Nadrieril
Correct comment on privately uninhabited pattern.

Follow-up to https://github.com/rust-lang/rust/pull/111624#discussion_r1204767933

r? `@Nadrieril`
2023-05-26 08:24:09 +02:00
Matthias Krüger
39b633ece4
Rollup merge of #111947 - obeis:issue-111943, r=compiler-errors
Add test for RPIT defined with different hidden types with different substs

Close #111943
2023-05-26 08:24:08 +02:00
Deadbeef
be44860ab9 fix for Self not respecting tuple Ctor privacy
This fixes #111220 by checking the privacy of tuple constructors using `Self`, so the following code now errors

```rust
mod my {
    pub struct Foo(&'static str);
}

impl AsRef<str> for my::Foo {
    fn as_ref(&self) -> &str {
        let Self(s) = self; // previously compiled, now errors correctly
        s
    }
}
```
2023-05-26 06:23:03 +00:00
Obei Sideg
b37cdc67be Add test for RPIT defined with different hidden types with different substs 2023-05-26 00:14:12 +03:00
Michael Goulet
cb5b40269f
Rollup merge of #111945 - GuillaumeGomez:migrate-gui-test-color-7, r=notriddle
Migrate GUI colors test to original CSS color format

Follow-up of https://github.com/rust-lang/rust/pull/111459.

r? ``@notriddle``
2023-05-25 13:58:01 -07:00
Michael Goulet
5227b68493
Rollup merge of #111929 - compiler-errors:no-newline-apit, r=wesleywiser
Don't print newlines in APITs

This is kind of a hack, but it gets the job done because the only "special" formatting that (afaict) `rustc_ast_pretty` does is break with newlines sometimes.

Fixes rust-lang/measureme#207
2023-05-25 13:58:01 -07:00
Michael Goulet
dbdb509467
Rollup merge of #111831 - clubby789:capture-slice-pat, r=cjgillot
Always capture slice when pattern requires checking the length

Fixes #111751

cc ``@zirconium-n,`` I see you were assigned to this but I've fixed some similar issues in the past and had an idea on how to investigate this.
2023-05-25 13:58:00 -07:00
Michael Goulet
9d4527bc80
Rollup merge of #111757 - lowr:fix/lint-attr-on-match-arm, r=eholk
Consider lint check attributes on match arms

Currently, lint check attributes on match arms have no effect for some lints. This PR makes some lint passes to take those attributes into account.

- `LateContextAndPass` for late lint doesn't update `last_node_with_lint_attrs` when it visits match arms. This leads to lint check attributes on match arms taking no effects on late lints that operate on the arms' pattern:

  ```rust
  match value {
      #[deny(non_snake_case)]
      PAT => {} // `non_snake_case` only warned due to default lint level
  }
  ```

  To be honest, I'm not sure whether this is intentional or just an oversight. I've dug the implementation history and searched up issues/PRs but couldn't find any discussion on this.

- `MatchVisitor` doesn't update its lint level when it visits match arms. This leads to check lint attributes on match arms taking no effect on some lints handled by this visitor, namely: `bindings_with_variant_name` and `irrefutable_let_patterns`.

  This seems to be a fallout from #108504. Before 05082f57af, when the visitor operated on HIR rather than THIR, check lint attributes for the said lints were effective. [This playground][play] compiles successfully on current stable (1.69) but fails on current beta and nightly.

  I wasn't sure where best to place the test for this. Let me know if there's a better place.

[play]: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=38432b79e535cb175f8f7d6d236d29c3
[play-match]: https://play.rust-lang.org/?version=beta&mode=debug&edition=2021&gist=629aa71b7c84b269beadeba664e2221d
2023-05-25 13:58:00 -07:00
Michael Goulet
bd7e8b5ef9
Rollup merge of #111152 - lukas-code:markdown-parsers-are-hard, r=GuillaumeGomez
update `pulldown-cmark` to `0.9.3`

This PR updates `pulldown-cmark` to version `0.9.3`, which does two main things:
* Pulls in https://github.com/raphlinus/pulldown-cmark/pull/643 to fix https://github.com/rust-lang/rust/issues/111117
* Allows parsing strikethrough with single tildes, e.g. `~foo~` -> ~foo~. This matches the [GFM spec](https://github.github.com/gfm/#strikethrough-extension-).

Full changelog: https://github.com/raphlinus/pulldown-cmark/pull/646
2023-05-25 13:57:59 -07:00
Nicholas Nethercote
5b0324fce0 Inline derived hash function.
Because most of the other derived functions are inlined: `clone`,
`default`, `eq`, `partial_cmp`, `cmp`. The exception is `fmt`, but it
tends to not be on hot paths as much.
2023-05-26 06:55:06 +10:00
Camille GILLOT
ee27c49dfc Add NOTE annotations. 2023-05-25 18:17:02 +00:00
Camille GILLOT
844c1cc5fe Remove DesugaringKind::Replace. 2023-05-25 17:40:46 +00:00
clubby789
ace794c6d7 Always capture slice when pattern requires checking the length 2023-05-25 17:08:49 +00:00
Camille GILLOT
320f6f43f6 Add inter-crate test. 2023-05-25 17:04:14 +00:00
bors
a2b1646c59 Auto merge of #86844 - bjorn3:global_alloc_improvements, r=pnkfelix
Support #[global_allocator] without the allocator shim

This makes it possible to use liballoc/libstd in combination with `--emit obj` if you use `#[global_allocator]`. This is what rust-for-linux uses right now and systemd may use in the future. Currently they have to depend on the exact implementation of the allocator shim to create one themself as `--emit obj` doesn't create an allocator shim.

Note that currently the allocator shim also defines the oom error handler, which is normally required too. Once `#![feature(default_alloc_error_handler)]` becomes the only option, this can be avoided. In addition when using only fallible allocator methods and either `--cfg no_global_oom_handling` for liballoc (like rust-for-linux) or `--gc-sections` no references to the oom error handler will exist.

To avoid this feature being insta-stable, you will have to define `__rust_no_alloc_shim_is_unstable` to avoid linker errors.

(Labeling this with both T-compiler and T-lang as it originally involved both an implementation detail and had an insta-stable user facing change. As noted above, the `__rust_no_alloc_shim_is_unstable` symbol requirement should prevent unintended dependence on this unstable feature.)
2023-05-25 16:59:57 +00:00
Michael Howell
674a3d5c1c diagnostics: exclude indirect private deps from trait impl suggest
Fixes #88696
2023-05-25 08:14:33 -07:00
Lukas Markeffsky
28ce0b9940 rustdoc: add test for strikethrough with single tildes
Also merge the two almost identical strikethrough tests together and document what the test tests.
2023-05-25 13:27:29 +00:00
Guillaume Gomez
223f6f5926 Migrate GUI colors test to original CSS color format 2023-05-25 14:32:00 +02:00
bors
eb9da7bfa3 Auto merge of #111473 - compiler-errors:opaques, r=lcnr
Handle opaques in the new solver (take 2?)

Implement a new strategy for handling opaques in the new solver.

First, queries now carry both their defining anchor and the opaques that were defined in the inference context at the time of canonicalization. These are both used to pre-populate the inference context used by the canonical query.

Second, use the normalizes-to goal to handle opaque types in the new solver. This means that opaques are handled like projection aliases, but with their own rules:
* Can only define opaques if they're "defining uses" (i.e. have unique params in all their substs).
* Can only define opaques that are from the anchor.
* Opaque type definitions are modulo regions. So that means `Opaque<'?0r> = HiddenTy1` and `Opaque<?'1r> = HiddenTy2` equate `HiddenTy1` and `HiddenTy2` instead of defining them as different opaque type keys.
2023-05-25 08:41:54 +00:00
Matthias Krüger
725cadb276
Rollup merge of #111624 - cjgillot:private-uninhabited-pattern, r=petrochenkov
Emit diagnostic for privately uninhabited uncovered witnesses.

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

cc `@Nadrieril`
2023-05-25 08:01:08 +02:00
Michael Goulet
97c11ffb22 Strongly prefer alias and param-env bounds 2023-05-25 03:35:14 +00:00
Michael Goulet
4692375389 Don't print newlines in APITs 2023-05-25 02:45:14 +00:00
bors
7664dfe433 Auto merge of #111925 - Manishearth:rollup-z6z6l2v, r=Manishearth
Rollup of 5 pull requests

Successful merges:

 - #111741 (Use `ObligationCtxt` in custom type ops)
 - #111840 (Expose more information in `get_body_with_borrowck_facts`)
 - #111876 (Roll compiler_builtins to 0.1.92)
 - #111912 (Use `Option::is_some_and` and `Result::is_ok_and` in the compiler  )
 - #111915 (libtest: Improve error when missing `-Zunstable-options`)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-05-25 00:33:43 +00:00
Caio
462a96c9e9 [RFC-2011] Expand more expressions 2023-05-24 21:15:50 -03:00
Caio
41d414e3f4 Address comments 2023-05-24 19:54:13 -03:00
Caio
25e395653d Move tests 2023-05-24 19:35:59 -03:00
Manish Goregaokar
8038606bf3
Rollup merge of #111915 - jyn514:libtest-errors, r=thomcc
libtest: Improve error when missing `-Zunstable-options`

"only accepted on the nightly compiler" is misleading when this *is* nightly.
2023-05-24 15:05:05 -07:00
Manish Goregaokar
b84ab57f90
Rollup merge of #111840 - voidc:borrowck-consumers, r=oli-obk
Expose more information in `get_body_with_borrowck_facts`

Verification tools for Rust such as, for example, Creusot or Prusti would benefit from having access to more information computed by the borrow checker.
As a first step in that direction, #86977 added the `get_body_with_borrowck_facts` API, allowing compiler consumers to obtain a `mir::Body` with accompanying borrow checker information.
At RustVerify 2023, multiple people working on verification tools expressed their need for a more comprehensive API.
While eventually borrow information could be part of Stable MIR, in the meantime, this PR proposes a more limited approach, extending the existing `get_body_with_borrowck_facts` API.
In summary, we propose the following changes:

- Permit obtaining the borrow-checked body without necessarily running Polonius
- Return the `BorrowSet` and the `RegionInferenceContext` in `BodyWithBorrowckFacts`
- Provide a way to compute the `borrows_out_of_scope_at_location` map
- Make some helper methods public

This is similar to #108328 but smaller in scope.
`@smoelius` Do you think these changes would also be sufficient for your needs?

r? `@oli-obk`
cc `@JonasAlaif`
2023-05-24 15:05:04 -07:00
Matthias Krüger
0cc987fae2
Rollup merge of #111903 - GuillaumeGomez:migrate-gui-test-color-6, r=notriddle
Migrate GUI colors test to original CSS color format

Follow-up of https://github.com/rust-lang/rust/pull/111459.

r? `@notriddle`
2023-05-24 21:36:58 +02:00
Matthias Krüger
092352f6fd
Rollup merge of #111841 - matthewjasper:validate-match-guards, r=compiler-errors
Run AST validation on match guards correctly

AST validation was being skipped on match guards other than `if let` guards.
2023-05-24 21:36:57 +02:00
Camille GILLOT
9a7ed3625f Emit diagnostic for privately uninhabited uncovered witnesses. 2023-05-24 19:16:07 +00:00
jyn
9314ed0cbd libtest: Improve error when missing -Zunstable-options
"only accepted on the nightly compiler" is misleading when this *is* nightly.
2023-05-24 11:18:20 -05:00
Guillaume Gomez
0a7293ff00 Migrate GUI colors test to original CSS color format 2023-05-24 14:41:18 +02:00
bors
d69787f098 Auto merge of #111195 - GuillaumeGomez:fix-ice-intra-doc-link, r=petrochenkov
Prevent crash when a path is not resolved in intra-doc link

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

cc `@petrochenkov`
r? `@notriddle`
2023-05-24 07:49:53 +00:00
Matthias Krüger
d49d347f15
Rollup merge of #111887 - fmease:inh-proj-pp-tests, r=compiler-errors
Add regression tests for pretty-printing inherent projections

Tests for #111486.
Fixes #111879.

r? `@matthiaskrgr`
2023-05-24 06:05:39 +02:00
Matthias Krüger
8227c4fd6e
Rollup merge of #111880 - compiler-errors:pointer-like-param-env, r=jackh726
Don't ICE when computing PointerLike trait when region vars are in param-env

Fixes #111877
2023-05-24 06:05:39 +02:00
Matthias Krüger
efea88ae08
Rollup merge of #111864 - Jules-Bertholet:sized-closures, r=compiler-errors
Always require closure parameters to be `Sized`

The `rust-call` ABI isn't compatible with `#![feature(unsized_fn_params)]`, so trying to use that feature with closures leads to an ICE (#67981). This turns that ICE into a type-check error.

`@rustbot` label A-closures F-unsized_fn_params
2023-05-24 06:05:38 +02:00
Matthias Krüger
224b6511b1
Rollup merge of #111861 - compiler-errors:rtn-in-super, r=jackh726
Don't ICE on return-type notation when promoting trait preds to associated type bounds

Fixes #111846
2023-05-24 06:05:37 +02:00
Michael Howell
b9302d7234 rustdoc: add hover indicator for notable trait tooltip 2023-05-23 17:19:35 -07:00
León Orell Valerian Liehr
4a63b07d24
Add tests for pretty-printing inherent projections 2023-05-24 01:17:38 +02:00
Michael Howell
c1d72de030 rustdoc: add interaction delays for tooltip popovers
Designing a good hover microinteraction is a matter of guessing
user intent from what are, literally, vague gestures. In this case,
guessing if hovering in our out of the tooltip base is intentional
or not.

To figure this out, a few different techniques are used:

* When the mouse pointer enters a tooltip anchor point, its hitbox
  is grown on the bottom, where the popover is/will appear. This was
  already there before this commit: search "hover tunnel" in
  rustdoc.css for the implementation.

* This commit adds a delay when the mouse pointer enters the base
  anchor, in case the mouse pointer was just passing through and the
  user didn't want to open it.

* This commit also adds a delay when the mouse pointer exits the
  tooltip's base anchor or its popover, before hiding it.

* A fade-out animation is layered onto the pointer exit delay to
  immediately inform the user that they successfully dismissed the
  popover, while still providing a way for them to cancel it if
  it was a mistake and they still wanted to interact with it.

* No animation is used for revealing it, because we don't want
  people to try to interact with an element while it's in the
  middle of fading in: either they're allowed to interact with
  it while it's fading in, meaning it can't serve as mistake-
  proofing for opening the popover, or they can't, but they
  might try and be frustrated.

See also:

* https://www.nngroup.com/articles/timing-exposing-content/
* https://www.nngroup.com/articles/tooltip-guidelines/
* https://bjk5.com/post/44698559168/breaking-down-amazons-mega-dropdown
2023-05-23 15:56:40 -07:00
bors
d5699874dc Auto merge of #111882 - matthiaskrgr:rollup-1xyv5mq, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #111427 ([rustdoc][JSON] Use exclusively externally tagged enums in the JSON representation)
 - #111486 (Pretty-print inherent projections correctly)
 - #111722 (Document stack-protector option)
 - #111761 (fix(resolve): not defined `extern crate shadow_name`)
 - #111845 (Update books)
 - #111851 (CFI: Fix encode_region: unexpected ReEarlyBound(0, 'a))
 - #111871 (Migrate GUI colors test to original CSS color format)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-05-23 18:13:36 +00:00
Matthias Krüger
f737ec40e6
Rollup merge of #111871 - GuillaumeGomez:migrate-gui-test-color-5, r=notriddle
Migrate GUI colors test to original CSS color format

Follow-up of https://github.com/rust-lang/rust/pull/111459.

r? `@notriddle`
2023-05-23 19:53:43 +02:00
Matthias Krüger
20b6e5a1d8
Rollup merge of #111851 - rcvalle:rust-cfi-fix-111515, r=bjorn3
CFI: Fix encode_region: unexpected ReEarlyBound(0, 'a)

Fixes #111515 and complements #106547 by adding support for encoding early bound regions and also excluding projections when transforming trait objects' traits into their identities before emitting type checks.
2023-05-23 19:53:43 +02:00
Matthias Krüger
37c9478b1a
Rollup merge of #111761 - bvanjoi:fix-109148, r=petrochenkov
fix(resolve): not defined `extern crate shadow_name`

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

## Why does #109148 panic?

When resolving `use std::xx` it enters `visit_scopes` from `early_resolve_ident_in_lexical_scope`, and iters twice during the loop:

|iter| `scope` | `break_result` | result |
|-|-|-|-|
| 0 | `Module` pointed to root | binding pointed to `Undetermined`, so result is `None` | scope changed to `ExternPrelude` |
| 1 | `ExternPrelude` | binding pointed to `std` | - |

Then, the result of `maybe_resolve_path` is `Module(std)`, so `import.imported_module.set` is executed.

Finally, during the `finalize_import` of `use std::xx`, `resolve_path` returns `NonModule` because `Binding(Ident(std), Module(root)`'s binding points to `extern crate blah as std`, which causes the assertion to fail at `assert!(import.imported_module.get().is_none());`.

## Investigation

The question is why `#[a] extern crate blah as std` is not defined as a binding of `std::xxx`, which causes the iteration twice during `visit_scopes` when resolving `std::xxx`. Ideally, the value of `break_result.is_some()` should have been valid in the first iteration.

After debugging, I found that because `#[a] extern crate blah as std` had been dummied by `placeholder` during `collect_invocations`, so it had lost its attrs, span, etc..., so it will not be defined. However, `expand_invoc` added them back, then the next `build_reduced_graph`, `#[a] extern crate blah as std` would have been defined, so it makes the result of `resolved_path` unexpected, and the program panics.

## Try to solve

I think there has two-way to solve this issue:

- Expand invocations before the first `resolve_imports` during `fully_expand_fragment`. However, I do not think this is a good idea because it would mess up the current design.
- As my PR described: do not define to `extern crate blah as std` during the second `build_reduced_graph`, which is very easy and more reasonable.

r? `@petrochenkov`
2023-05-23 19:53:42 +02:00
Matthias Krüger
d1e9910abf
Rollup merge of #111427 - LukeMathWalker:flatten, r=aDotInTheVoid
[rustdoc][JSON] Use exclusively externally tagged enums in the JSON representation

See [this Zulip thread](https://rust-lang.zulipchat.com/#narrow/stream/266220-rustdoc/topic/.28De.29serialization.20speed.20of.20JSON.20docs) and [this issue](https://github.com/rust-lang/rust/issues/93667) for the relevant context.
2023-05-23 19:53:40 +02:00
Michael Goulet
3a2710cdb6 Don't ICE when computing PointerLike trait when region vars are in param-env 2023-05-23 17:23:30 +00:00
Jules Bertholet
5cd02eaece
Always require closure parameters to be Sized
The `rust-call` ABI isn't compatible with
`#![feature(unsized_fn_params)]`, so trying to use that feature with
closures leads to an ICE (#67981). This turns that ICE into a
type-check error.
2023-05-23 12:46:25 -04:00
Ramon de C Valle
9bbdfea23c CFI: Fix encode_region: unexpected ReEarlyBound(0, 'a)
Fixes #111515 and complements #106547 by adding support for encoding
early bound regions and also excluding projections when transforming
trait objects' traits into their identities before emitting type checks.
2023-05-23 16:44:03 +00:00
bors
52dd1cde59 Auto merge of #107294 - JamieCunliffe:neon-fp, r=Amanieu
Fix some issues with folded AArch64 features

In #91608 the `fp` feature was removed for AArch64 and folded into the `neon` feature, however disabling the `neon` feature doesn't actually disable the `fp` feature. If my understanding on that thread is correct it should do.

While doing this, I also noticed that disabling some features would disable features that it shouldn't. For instance enabling `sve` will enable `neon`, however, when disabling `sve` it would then also disable `neon`, I wouldn't expect disabling `sve` to also disable `neon`.

cc `@workingjubilee`
2023-05-23 15:30:37 +00:00
Pietro Albini
5f0b677b86
codegen: add needs-unwind to tests that require it 2023-05-23 16:54:35 +02:00
Pietro Albini
292bc548c8
codegen: do not require the uwtables attribute
The attribute is not emitted on targets without unwinding tables.
2023-05-23 16:54:34 +02:00
Pietro Albini
dc1ed9ddd7
codegen: allow the dso_local attribute
The attribute is injected into most items when static relocation is
enabled in a target.
2023-05-23 16:54:33 +02:00
Pietro Albini
5fdeae610d
codegen: allow extra attributes to functions when panic=abort
When compiling with panic=abort (or using a target that doesn't have
unwinding support), the compiler adds the "nounwind" attribute to
functions. This results in a different LLVM IR, which results in a #NNN
added after the function name:

    tail call void @bar() #13, !dbg !467
    attributes #13 = { nounwind }

...instead of:

    tail call void @bar(), !dbg !467

This commit changes the matchers to swallow the #NNN, as it's not needed
for these specific tests.
2023-05-23 16:54:30 +02:00
Guillaume Gomez
bcdfda1b6b Add regression test for #111189 2023-05-23 15:33:43 +02:00
Guillaume Gomez
24be25f134 Migrate GUI colors test to original CSS color format 2023-05-23 15:26:59 +02:00
bors
b08148f6a7 Auto merge of #111869 - Dylan-DPC:rollup-9pydw08, r=Dylan-DPC
Rollup of 6 pull requests

Successful merges:

 - #111461 (Fix symbol conflict diagnostic mistakenly being shown instead of missing crate diagnostic)
 - #111579 (Also assume wrap-around discriminants in `as` MIR building)
 - #111704 (Remove return type sized check hack from hir typeck)
 - #111853 (Check opaques for mismatch during writeback)
 - #111854 (rustdoc: clean up `settings.css`)
 - #111860 (Don't ICE if method receiver fails to unify with `arbitrary_self_types`)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-05-23 12:47:51 +00:00
Dominik Stolz
c6e3f27864 Move BodyWithBorrowckFacts to consumers 2023-05-23 14:36:36 +02:00
Dylan DPC
c4f2a62182
Rollup merge of #111860 - compiler-errors:issue-111838, r=WaffleLapkin
Don't ICE if method receiver fails to unify with `arbitrary_self_types`

Consider:

```rust
struct Foo(u32);
impl Foo {
    fn get<R: Deref<Target=Self>>(self: R) -> u32 {
        self.0
    }
}

fn main() {
    let mut foo = Foo(1);
    foo.get::<&Foo>();
}
```

The problem here is that with `arbitrary_self_types`, we're allowed to have a method receiver that mentions generics from the method itself (`fn get<R: Deref<Target=Self>>(self: R)`). Since we don't actually take into account the user-written turbofish generics when doing method lookup (nor do we check that method predicates hold), method probing will happily infer `R = Foo` during the probe. When we later confirm the method, we do use the turbofish'd subst and instead now have that `R = &Foo`. This doesn't unify with the self type we chose during the probe, causing an ICE.

Getting this to work correctly will be difficult. Specifically, we'll need to actually pass in the turbofish generics for the method being probed for and check that the self type unifies considering those generics. This seems like a lot of work, and I'm not actually familiar with the restrictions originally called out for `#![feature(arbitrary_self_types)]`, but I think we should probably instead just deny having receivers that mention (type/const) generics that come from the method itself.

But I mostly just want to turn this ICE into an error, so I'll leave that up for later PRs.

Fixes #111838
2023-05-23 16:44:29 +05:30
Dylan DPC
32c73c23a4
Rollup merge of #111854 - notriddle:notriddle/settings-css-cleanup, r=GuillaumeGomez
rustdoc: clean up `settings.css`

An identical CSS rule was merged for settings-check, and an unneeded `position: relative` removed.
2023-05-23 16:44:28 +05:30
Dylan DPC
6583025c93
Rollup merge of #111853 - compiler-errors:opaque-check, r=oli-obk
Check opaques for mismatch during writeback

Revive #111705.

I realized that we don't need to put any substs in the writeback results since all of the hidden types have already been remapped. See the comment in `compiler/rustc_middle/src/ty/typeck_results.rs`, which should make that clear for other explorers of the codebase.

Additionally, we need to do some diagnostic stashing because the diagnostics we produce during HIR typeck is very poor and we should prefer the diagnostic that comes from MIR, if we have one.

r? `@oli-obk`
2023-05-23 16:44:28 +05:30
Dylan DPC
4b26b80dd5
Rollup merge of #111704 - compiler-errors:sized-return-cleanup, r=oli-obk
Remove return type sized check hack from hir typeck

Remove a bunch of special-cased suggestions when someone returns `-> dyn Trait` that checks for type equality, etc.

This was a pretty complex piece of code that also relied on a hack in hir typeck (see changes to `compiler/rustc_hir_typeck/src/check.rs`), and I'm not convinced that it's necessary to maintain, when all we really need to tell the user is that they should return `-> impl Trait` or `-> Box<dyn Trait>`, depending on their specific use-case.

This is necessary because we may need to move the "return type is sized" check from hir typeck to wfcheck, which does not have access to typeck results. This is a prerequisite for that, and I'm fairly confident that the diagnostics "regressions" here are not a big deal.
2023-05-23 16:44:27 +05:30
Dylan DPC
00185bec7c
Rollup merge of #111579 - scottmcm:enum-as-signed, r=oli-obk
Also assume wrap-around discriminants in `as` MIR building

Resolves this FIXME:

8d18c32b61/compiler/rustc_mir_build/src/build/expr/as_rvalue.rs (L231)

r? `@oli-obk`
2023-05-23 16:44:27 +05:30
Dylan DPC
731c1a5592
Rollup merge of #111461 - oli-obk:crate_collision, r=petrochenkov
Fix symbol conflict diagnostic mistakenly being shown instead of missing crate diagnostic

This was a refactoring mistake in https://github.com/rust-lang/rust/pull/109213

fixes #111284
2023-05-23 16:44:26 +05:30
Dominik Stolz
75e172e710 Update obtain-borrowck test 2023-05-23 13:13:40 +02:00
bors
f3d597b31c Auto merge of #111807 - erikdesjardins:noalias, r=oli-obk
[rustc_ty_utils] Treat `drop_in_place`'s *mut argument like &mut when adding LLVM attributes

This resurrects PR #103614, which has sat idle for a while.

This could probably use a new perf run, since we're on a new LLVM version now.

r? `@oli-obk`
cc `@RalfJung`

---

LLVM can make use of the `noalias` parameter attribute on the parameter to `drop_in_place` in areas like argument promotion. Because the Rust compiler fully controls the code for `drop_in_place`, it can soundly deduce parameter attributes on it.

In #103957, Miri was changed to retag `drop_in_place`'s argument as if it was `&mut`, matching this change.
2023-05-23 10:12:46 +00:00
Oli Scherer
6d1a1cf354 Fix symbol conflict diagnostic mistakenly being shown instead of missing crate diagnostic 2023-05-23 07:37:16 +00:00
bohan
c41b2089c7 fix(resolve): not defined extern crate shadow_name 2023-05-23 13:14:34 +08:00
bors
4400d8fce7 Auto merge of #110204 - compiler-errors:new-solver-hir-typeck-hacks, r=lcnr
Deal with unnormalized projections when structurally resolving types with new solver

1. Normalize types in `structurally_resolved_type` when the new solver is enabled
2. Normalize built-in autoderef targets in `Autoderef` when the new solver is enabled
3. Normalize-erasing-regions in `resolve_type` in writeback

This is motivated by the UI test provided, which currently fails with:

```
error[E0609]: no field `x` on type `<usize as SliceIndex<[Foo]>>::Output`
 --> <source>:9:11
  |
9 |     xs[0].x = 1;
  |           ^
```

 I'm pretty happy with the approach in (1.) and (2.) and think we'll inevitably need something like this in the long-term, but (3.) seems like a hack to me. It's a *lot* of work to add tons of new calls to every user of these typeck results though (mir build, late lints, etc). Happy to discuss further.

r? `@lcnr`
2023-05-23 04:41:44 +00:00
Michael Goulet
e54bc1c5ff Don't ICE on RPITIT when promoting trait preds to associated type bounds 2023-05-23 03:43:09 +00:00
Michael Goulet
05c5caa500 Don't ICE if method receiver fails to unify with arbitrary_self_types 2023-05-23 03:23:52 +00:00
Erik Desjardins
fb7f1d220c drop-in-place-noalias test: needs -O to ensure attributes are added on nopt builders 2023-05-22 20:20:45 -04:00
Michael Howell
24913bd768 rustdoc: remove unneeded position: relative setting CSS
This was added to control percentage sizes, in
79956b96e8

Now, the only percentage size is [`border-radius`], which is
based on the size of the box itself, not its containing block.
This leaves the property unused.

[`border-radius`]: https://developer.mozilla.org/en-US/docs/Web/CSS/border-radius
2023-05-22 16:46:29 -07:00
Michael Goulet
0307db4a59 Check opaques for mismatch during writeback 2023-05-22 23:33:34 +00:00
Michael Goulet
4cfafb275e Structurally normalize in the new solver 2023-05-22 21:18:20 +00:00
bors
8b4b20836b Auto merge of #111848 - Dylan-DPC:rollup-7jqydzg, r=Dylan-DPC
Rollup of 6 pull requests

Successful merges:

 - #111501 (MIR drive-by cleanups)
 - #111609 (Mark internal functions and traits unsafe to reflect preconditions)
 - #111612 (Give better error when collecting into `&[T]`)
 - #111756 (Rename `{drop,forget}_{copy,ref}` lints to more consistent naming)
 - #111843 (move lcnr to only review types stuff)
 - #111844 (Migrate GUI colors test to original CSS color format)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-05-22 20:33:51 +00:00
Dylan DPC
ec372a17e2
Rollup merge of #111844 - GuillaumeGomez:migrate-gui-test-color-4, r=notriddle
Migrate GUI colors test to original CSS color format

I updated the `browser-ui-test` version because I fixed https://github.com/GuillaumeGomez/browser-UI-test/issues/507. If inside a function, the colors were not considered, preventing the second commit of this PR.

Follow-up of https://github.com/rust-lang/rust/pull/111459.

r? `@notriddle`
2023-05-23 00:32:20 +05:30
Dylan DPC
71f78682be
Rollup merge of #111756 - Urgau:rename_drop_forget_copy_ref_lints, r=fee1-dead
Rename `{drop,forget}_{copy,ref}` lints to more consistent naming

This PR renames previous uplifted lints in https://github.com/rust-lang/rust/pull/109732 to more consistent naming.

I followed the renaming done [here](https://github.com/rust-lang/rust/issues/53224) and also advocated in this [clippy issue](https://github.com/rust-lang/rust-clippy/issues/2845):
   - `drop_copy` to `dropping_copy_types`
   - `forget_copy` to `forgetting_copy_types`
   - `drop_ref` to `dropping_references`
   - `forget_ref` to `forgetting_references`
2023-05-23 00:32:19 +05:30
Dylan DPC
df8b0dfc27
Rollup merge of #111612 - ChayimFriedman2:collect-into-slice-ref, r=petrochenkov
Give better error when collecting into `&[T]`

The detection of slice reference of `{integral}` in `rustc_on_unimplemented` is hacky, but a proper solution requires changing `FmtPrinter` to add a parameter to print integers as `{integral}` and I didn't want to change it just for `rustc_on_unimplemented`. I can do that if requested, though.

I'm open to better wording; this is the best I could come up with.
2023-05-23 00:32:18 +05:30
Dylan DPC
df86200965
Rollup merge of #111501 - WaffleLapkin:drivebycleanupuwu, r=oli-obk
MIR drive-by cleanups

Some random drive-by cleanups I did while working with MIR/THIR.
2023-05-23 00:32:17 +05:30
bors
cfcde247cd Auto merge of #111754 - lcnr:recursion-depth, r=matthewjasper
fix recursion depth handling after confirmation

fixes #111729

I think having to use `Obligation::with_depth` correctly everywhere is very hard because e.g. the nested obligations from `eq` currently do not have the correct obligation depth.

The new solver [completely removes `recursion_depth` from obligations](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/traits/solve/struct.Goal.html) and instead tracks the depth in the solver itself which is far easier to get right. Moving the old solver towards this shouldn't be that hard but is probably somewhat annoying.

r? `@matthewjasper`
2023-05-22 17:56:26 +00:00
Luca Palmieri
a5e5101375 Serialize all enums as externally tagged to guarantee compatibility with binary formats such as bincode or postcard 2023-05-22 18:22:08 +01:00
Guillaume Gomez
194960bae9 Migrate GUI colors test to original CSS color format 2023-05-22 17:34:48 +02:00
bors
2fe47b966a Auto merge of #111634 - marc0246:arc-new-uninit-bloat, r=thomcc
Fix duplicate `arcinner_layout_for_value_layout` calls when using the uninit `Arc` constructors

What this fixes is the duplicate calls to `arcinner_layout_for_value_layout` seen here: https://godbolt.org/z/jr5Gxozhj

The issue was discovered alongside #111603 but is otherwise unrelated to the duplicate `alloca`s, which remain unsolved. Everything I tried to solve said main issue has failed.

As for the duplicate layout calculations, I also tried slapping `#[inline]` and `#[inline(always)]` on everything in sight but the only thing that worked in the end is to dedup the calls by hand.
2023-05-22 15:06:32 +00:00
Matthew Jasper
72d41f3bd3 Run AST validation on match guards correctly 2023-05-22 14:52:52 +01:00
Jamie Cunliffe
a059e68d11 Create a structure to define the features from to_llvm_features.
Rather than returning an array of features from to_llvm_features, return a structure that contains
the dependencies. This also contains metadata on how the features depend on each other to allow for
the correct enabling and disabling.
2023-05-22 14:46:40 +01:00
Jamie Cunliffe
d51db4275b Make v8a match optional in the test feature list. 2023-05-22 14:27:14 +01:00
Jamie Cunliffe
aab0757c66 Only disable folded features when it makes sense.
Some features that are tied together only make sense to be folded
together when enabling the feature. For example on AArch64 sve and
neon are tied together, however it doesn't make sense to disable neon
when disabling sve.
2023-05-22 14:27:14 +01:00
Lukas Markeffsky
b63cc5c307 rustdoc: add regression test for broken link due to double backticks 2023-05-22 11:35:25 +02:00
bors
3869b7b12d Auto merge of #111824 - lukas-code:strike, r=notriddle
rustdoc: include strikethrough in item summary

Fixes https://github.com/rust-lang/rust/issues/111822. Since **bold** and *italic* are included, I don't see why ~~strikethrough~~ shouldn't be.
2023-05-22 00:56:50 +00:00
Scott McMurray
d69725d5d5 Normalize block and local orders in mir-opt tests
Since this only affects `PreCodegen MIR, and it would be nice for that to be resilient to permutations of things that don't affect the actual semantic behaviours.
2023-05-21 17:48:37 -07:00
Scott McMurray
57c5ac7894 Tweak the post-order for multi-successor blocks 2023-05-21 17:48:36 -07:00
bors
9d871b0617 Auto merge of #111731 - MU001999:fix/issue-111727, r=cjgillot
Keep only the trait when emitting the error for `MyTrait + 'a`

Fixes #111727
2023-05-21 19:19:49 +00:00
Lukas Markeffsky
f4ce0458e9 rustdoc: include strikethrough in item summary 2023-05-21 18:00:11 +02:00
bors
965cf5c1f5 Auto merge of #111820 - matthiaskrgr:rollup-9sb2lw9, r=matthiaskrgr
Rollup of 5 pull requests

Successful merges:

 - #111745 (Fix overflow in error emitter)
 - #111770 (Read beta version from the version file if building from a source tarball)
 - #111797 (Migrate GUI colors test to original CSS color format)
 - #111809 (Unset MIRI_BLESS for mir-opt-level 4 miri tests)
 - #111817 (Migrate GUI colors test to original CSS color format)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-05-21 14:14:29 +00:00
Matthias Krüger
7358166882
Rollup merge of #111817 - GuillaumeGomez:migrate-gui-test-color-3, r=notriddle
Migrate GUI colors test to original CSS color format

Follow-up of https://github.com/rust-lang/rust/pull/111459.

r? `@notriddle`
2023-05-21 16:03:01 +02:00
Matthias Krüger
0afa79b53d
Rollup merge of #111797 - GuillaumeGomez:migrate-gui-test-color-2, r=notriddle
Migrate GUI colors test to original CSS color format

Follow-up of https://github.com/rust-lang/rust/pull/111459.

r? ``@notriddle``
2023-05-21 16:03:00 +02:00
Matthias Krüger
cb5dd1d598
Rollup merge of #111745 - Badel2:emitter-add-overflow, r=compiler-errors
Fix overflow in error emitter

Fix #109854
Close #94171 (was already fixed before but missing test)

This bug happens when a multipart suggestion spans more than one line.

The fix is to update the `acc` variable, which didn't handle the case when the text to remove spans multiple lines but the text to add spans only one line.

Also, use `usize::try_from` instead of  `as usize` to detect overflows earlier in the future, and point to the source of the overflow (the original issue points to a different place where this value is used, not where the overflow had happened).

And finally add an `if start != end` check to avoid doing any extra work in case of empty ranges.

Long explanation:

Given this test case:

```rust
fn generate_setter() {
    String::with_capacity(
    //~^ ERROR this function takes 1 argument but 3 arguments were supplied
    generate_setter,
    r#"
pub(crate) struct Person<T: Clone> {}
"#,
     r#""#,
    );
}
```

The compiler will try to convert that code into the following:

```rust
fn generate_setter() {
    String::with_capacity(
    //~^ ERROR this function takes 1 argument but 3 arguments were supplied
    /* usize */,
    );
}
```

So it creates a suggestion with 3 separate parts:

```
// Replace "generate_setter" with "/* usize */"
SubstitutionPart { span: fuzz_input.rs:4:5: 4:20 (#0), snippet: "/* usize */" }
// Remove second arg (multiline string)
SubstitutionPart { span: fuzz_input.rs:4:20: 7:3 (#0), snippet: "" }
// Remove third arg (r#""#)
SubstitutionPart { span: fuzz_input.rs:7:3: 8:11 (#0), snippet: "" }
```

Each of this parts gets a separate `SubstitutionHighlight` (this marks the relevant text green in a terminal, the values are 0-indexed so `start: 4` means column 5):

```
SubstitutionHighlight { start: 4, end: 15 }
SubstitutionHighlight { start: 15, end: 15 }
SubstitutionHighlight { start: 18446744073709551614, end: 18446744073709551614 }
```

The 2nd and 3rd suggestion are empty (start = end) because they only remove text, so there are no additions to highlight. But the 3rd span has overflowed because the compiler assumes that the 3rd suggestion is on the same line as the first suggestion. The 2nd span starts at column 20 and the highlight starts at column 16 (15+1), so that suggestion is good. But since the 3rd span starts at column 3, the result is `3 - 4`, or column -1, which turns into -2 with 0-indexed, and that's equivalent to `18446744073709551614 as isize`.

With this fix, the resulting `SubstitutionHighlight` are:

```
SubstitutionHighlight { start: 4, end: 15 }
SubstitutionHighlight { start: 15, end: 15 }
SubstitutionHighlight { start: 15, end: 15 }
```

As expected. I guess ideally we shouldn't emit empty highlights when removing text, but I am too scared to change that.
2023-05-21 16:02:59 +02:00
Urgau
6b08a745a4 Rename forget_ref lint to forgetting_references 2023-05-21 14:28:09 +02:00
Urgau
c93d9c1794 Rename drop_ref lint to dropping_references 2023-05-21 14:16:41 +02:00
Urgau
85a1828943 Rename forget_copy lint to forgetting_copy_types 2023-05-21 14:09:03 +02:00
Urgau
1c7ab18c08 Rename drop_copy lint to dropping_copy_types 2023-05-21 13:37:32 +02:00
bors
06345574d9 Auto merge of #111424 - JakobDegen:inline-unsized, r=tmiasko
Don't inline functions with unsized args

Fixes #111355 .

I have some ideas for how we can get this back in the future, out of scope for this PR though.

r? `@cjgillot`
2023-05-21 11:23:26 +00:00
Guillaume Gomez
3c9964f003 Migrate GUI colors test to original CSS color format 2023-05-21 13:10:03 +02:00
bors
d77014a608 Auto merge of #111697 - rcvalle:rust-cfi-fix-111510, r=bjorn3
CFI: Fix encode_ty: unexpected Param(B/#1)

Fixes #111510 and complements #106547 by adding support for encoding type parameters and also by transforming trait objects' traits into their identities before emitting type checks.
2023-05-21 06:42:05 +00:00
bors
a11235d1bf Auto merge of #111696 - lukas-code:offset-of-erase-regions-harder, r=compiler-errors
don't skip inference for type in `offset_of!`

Fixes https://github.com/rust-lang/rust/issues/111678 by no longer skipping inference on the type in `offset_of!`. Simply erasing the regions the during writeback isn't enough and can cause ICEs. A test case for this is included.

This reverts https://github.com/rust-lang/rust/pull/111661, because it becomes redundant, since inference already erases the regions.
2023-05-21 04:02:46 +00:00
bors
1b67f8b013 Auto merge of #111675 - Urgau:fix-local-libs-for-native-static-libs, r=bjorn3
Fix local libs not included when printing native static libs

This PR fixes https://github.com/rust-lang/rust/issues/111643 by adding the local used libs to the printed `--print=native-static-libs` output.

It seems that `--print=native-static-libs` doesn't have any test, so I added one. It's very simple and doesn't even tries to compile the result to a binary as I don't know how to handle external library linking in CI. (Note that https://github.com/rust-lang/rust/blob/master/tests/run-make/staticlib-dylib-linkage/Makefile does compile to a binary)

r? `@bjorn3`
2023-05-21 01:12:45 +00:00
Jakob Degen
60cc72cf7b Don't inline functions with unsized args 2023-05-20 17:45:50 -07:00
Erik Desjardins
c4d69b717f make noalias-box-off filecheck more precise
The CHECK, -NOT, -SAME pattern ensures that the `CHECK-NOT: noalias`
is limited to only one line, and won't match unrelated lines further
down in the file.

Explicit drop call added to preserve the `foo` argument name, since
names of unused arguments are not preserved.
2023-05-20 19:41:28 -04:00
Erik Desjardins
644818351b ensure !Unpin types do not get noalias 2023-05-20 19:34:31 -04:00
Patrick Walton
21b8815b6c Apply noalias, nonnull, dereferenceable, and align attributes unconditionally.
We've done measurements with Miri and have determined that `noalias` shouldn't
break code. The requirements that allow us to add dereferenceable and align
have been long documented in the standard library documentation.
2023-05-20 18:12:54 -04:00
Patrick Walton
74dd3cb159 Fix noalias box test 2023-05-20 18:12:54 -04:00
Patrick Walton
f71741bac4 [rustc_ty_utils] Add the LLVM noalias parameter attribute to drop_in_place in certain cases.
LLVM can make use of the `noalias` parameter attribute on the parameter to
`drop_in_place` in areas like argument promotion. Because the Rust compiler
fully controls the code for `drop_in_place`, it can soundly deduce parameter
attributes on it. In the case of a value that has a programmer-defined Drop
implementation, we know that the first thing `drop_in_place` will do is pass a
pointer to the object to `Drop::drop`. `Drop::drop` takes `&mut`, so it must be
guaranteed that there are no pointers to the object upon entering that
function. Therefore, it should be safe to mark `noalias` there.

With this patch, we mark `noalias` only when the type is a value with a
programmer-defined Drop implementation. This is possibly overly conservative,
but I thought that proceeding cautiously was best in this instance.
2023-05-20 18:12:53 -04:00
Guillaume Gomez
0d8a2e58a3
Rollup merge of #111765 - GuillaumeGomez:migrate-gui-test-color, r=notriddle
Migrate GUI colors test to original CSS color format

Follow-up of https://github.com/rust-lang/rust/pull/111459.

r? `@notriddle`
2023-05-20 15:37:24 +02:00
Guillaume Gomez
7597d572ed
Rollup merge of #111726 - GuillaumeGomez:gui-test-migrate-color, r=notriddle
Migrate GUI colors test to original CSS color format

Follow-up of https://github.com/rust-lang/rust/pull/111459.

r? ```@notriddle```
2023-05-20 15:37:23 +02:00
Guillaume Gomez
8b7c8e1f82 Migrate GUI colors test to original CSS color format 2023-05-20 15:35:52 +02:00
Lukas Markeffsky
7cdb23b98a don't skip inference for type in offset_of! 2023-05-20 15:20:27 +02:00
ozkanonur
02ea750f0b add compiletest headers to rustdoc-gui tests 2023-05-20 14:41:37 +03:00
Dylan DPC
94ca44a50a
Rollup merge of #111762 - bvanjoi:fix-111749, r=compiler-errors
fix: emit error when fragment is `MethodReceiverExpr` and items is empty

Fixes https://github.com/rust-lang/rust/issues/111749
2023-05-20 12:21:02 +05:30
Dylan DPC
e892e32df4
Rollup merge of #111665 - est31:offset_of_tests, r=WaffleLapkin
Add more tests for the offset_of macro

Implements what I [suggested in the tracking issue](https://github.com/rust-lang/rust/issues/106655#issuecomment-1535007205), plus some further improvements:

* ensuring that offset_of!(Self, ...) works iff inside an impl block
* ensuring that the output type is usize and doesn't coerce. this can be changed in the future, but if it is done, it should be a conscious decision
* improving the privacy checking test
* ensuring that generics don't let you escape the unsized check

r? `````@WaffleLapkin`````
2023-05-20 12:21:00 +05:30
Dylan DPC
13f3585dc6
Rollup merge of #111652 - clubby789:self-import-improvement, r=compiler-errors
Better diagnostic for `use Self::..`

Fixes #111627

cc `@petrochenkov,` you might have thoughts on a better way to handle this (https://github.com/rust-lang/rust/issues/63720#issuecomment-591597466)
2023-05-20 12:21:00 +05:30
Dylan DPC
2294d81fb3
Rollup merge of #111491 - compiler-errors:nested-fut-must-use, r=wesleywiser
Dont check `must_use` on nested `impl Future` from fn

Fixes (but does not close, per beta policy) #111484

Also fixes a `FIXME` left in the code about (presumably) false-positives on non-async `#[must_use] fn() -> impl Future` cases, though if that's not desirable to include in the beta backport then I can certainly revert it.

Beta nominating as it fixes a beta ICE.
2023-05-20 12:20:58 +05:30
Badel2
cbb41008fd Fix overflow in error emitter 2023-05-19 20:58:06 +02:00
Maybe Waffle
140cdcbc9d Drive-by-cleanup: Don't emit thir::ExprKind::NeverToAny for ! -> ! 2023-05-19 21:50:01 +04:00
Guillaume Gomez
c2d3b23bd0 Migrate GUI colors test to original CSS color format 2023-05-19 17:01:22 +02:00
Mu001999
a9528a28f2 Keep only the trait when emitting the error for MyTrait + 'a 2023-05-19 22:11:54 +08:00
bohan
990b2899ad fix: emit error when fragment is MethodReceiverExpr and items is empty 2023-05-19 21:21:05 +08:00
bors
17a681000b Auto merge of #111641 - michaelwoerister:debugger-visualizer-fixes, r=cjgillot
Fix dependency tracking for debugger visualizers

This PR fixes dependency tracking for debugger visualizer files by changing the `debugger_visualizers` query to an `eval_always` query that scans the AST while it is still available. This way the set of visualizer files is already available when dep-info is emitted. Since the query is turned into an `eval_always` query, dependency tracking will now reliably detect changes to the visualizer script files themselves.

TODO:
 - [x] perf.rlo
 - [x] Needs a bit more documentation in some places
 - [x] Needs regression test for the incr. comp. case

Fixes https://github.com/rust-lang/rust/issues/111226
Fixes https://github.com/rust-lang/rust/issues/111227
Fixes https://github.com/rust-lang/rust/issues/111295

r? `@wesleywiser`
cc `@gibbyfree`
2023-05-19 11:30:44 +00:00
Ryo Yoshida
3a03587836
Consider lint check attributes on match arms in match checks 2023-05-19 19:04:15 +09:00