Commit Graph

2870 Commits

Author SHA1 Message Date
bors
56fd680cf9 Auto merge of #96046 - oli-obk:const_typeck, r=cjgillot
Move various checks to typeck so them failing causes the typeck result to get tainted

Fixes #69487
fixes #79047

cc `@RalfJung` this gets rid of the `Transmute` invalid program error variant
2022-05-27 11:31:37 +00:00
Matthias Krüger
5fc8a8e227 clippy::complexity fixes
clone_on_copy
useless_format
bind_instead_of_map
filter_map_identity
useless_conversion
map_flatten
unnecessary_unwrap
2022-05-26 13:14:24 +02:00
b-naber
3c6c8d5a8d rebase, use Ty in CallArgument and re-insert static_assert_size on ConstraintCategory 2022-05-26 10:11:58 +02:00
b-naber
99fa572ab1 add def_id and substs to ConstraintCategory::CallArgument 2022-05-25 18:13:03 +02:00
bors
4a99c5f504 Auto merge of #97345 - lcnr:fast_reject, r=nnethercote
add a deep fast_reject routine

continues the work on #97136.

r? `@nnethercote`

Actually agree with you on the match structure 😆 let's see how that impacted perf 😅
2022-05-25 08:36:46 +00:00
Ding Xiang Fei
4c6074fbb0
try to cache region_scope_tree as a query 2022-05-25 13:52:32 +08:00
lcnr
a76277c6c4 add a deep fast_reject routine 2022-05-25 07:40:38 +02:00
Jakob Degen
bf153a241d Add dead store elimination pass 2022-05-24 22:50:21 -04:00
Michael Goulet
d1a9a95517 Make Lazy not care about lifetimes until decode 2022-05-24 15:54:44 -07:00
Oli Scherer
0d88631059 Add the transmute and asm checks to typeck as deferred checks 2022-05-24 16:28:57 +00:00
Oli Scherer
0fdaaadb36 Remove the check_mod_intrinsics query 2022-05-24 15:46:23 +00:00
Jakob Degen
09b0936db2 Refactor call terminator to always hold a destination place 2022-05-23 17:49:04 -04:00
Tomasz Miąsko
0e7eca77e1 Fix precise field capture of univariant enums
When constructing a MIR from a THIR field expression, introduce an
additional downcast projection before accessing a field of an enum.

When rebasing a place builder on top of a captured place, account for
the fact that a single HIR enum field projection corresponds to two MIR
projection elements: a downcast element and a field element.
2022-05-23 19:07:06 +02:00
Dylan DPC
f4bf64c3f0
Rollup merge of #97292 - compiler-errors:tcxify-rustc, r=davidtwco
Lifetime variance fixes for rustc

#97287 migrates rustc to a `Ty` type that is invariant over its lifetime `'tcx`, so I need to fix a bunch of places that assume that `Ty<'a>` and `Ty<'b>` can be unified by shortening both to some common lifetime.

This is doable, since many lifetimes are already `'tcx`, so all this PR does is be a bit more explicit that elided lifetimes are actually `'tcx`.

Split out from #97287 so the compiler team can review independently.
2022-05-23 15:11:04 +02:00
Michael Goulet
1784634a39 Lifetime variance fixes for rustc 2022-05-22 14:29:32 -07:00
Jack Huey
683a9c8391 Do leak check after function ptr coercion 2022-05-22 11:18:36 -04:00
bors
653463731a Auto merge of #95563 - dingxiangfei2009:dxf-rfc66-refactor, r=nikomatsakis
Move the extended lifetime resolution into typeck context

Related to #15023

This PR is based on the [idea](https://github.com/rust-lang/rust/issues/15023#issuecomment-1070931433) of #15023 by `@nikomatsakis.`

This PR specifically proposes to
- Delay the resolution of scopes of rvalues to a later stage, so that enough type information is available to refine those scopes based on relationships of lifetimes.
- Highlight relevant parts that would help future reviews on the next installments of works to fully implement a solution to RFC 66.
2022-05-22 09:00:30 +00:00
Ding Xiang Fei
6044fbe462
factor out the rvalue lifetime rule
remove region_scope_tree from RegionCtxt

Apply suggestions from code review

Co-authored-by: Niko Matsakis <niko@alum.mit.edu>
2022-05-22 16:46:50 +08:00
bors
acfd327fd4 Auto merge of #97177 - oli-obk:const-stability, r=davidtwco
Implement proper stability check for const impl Trait, fall back to unstable const when undeclared

Continuation of #93960

`@jhpratt` it looks to me like the test was simply not testing for the failure you were looking for? Your checks actually do the right thing for const traits?
2022-05-22 06:47:36 +00:00
Yuki Okushi
97e1ab0005
Rollup merge of #97259 - jyn514:fix-typo, r=JohnTitor
Fix typo in Mir phase docs
2022-05-22 11:53:09 +09:00
bors
e52e7115c7 Auto merge of #96515 - lcnr:user-types-in-pat, r=nikomatsakis
correctly deal with user type ascriptions in pat

supersedes #93856

`thir::PatKind::AscribeUserType` previously resulted in `CanonicalUserTypeAnnotations` where the inferred type already had a subtyping relation according to `variance` to the `user_ty`.

The bug can pretty much be summarized as follows:

- during mir building
  - `user_ty -> inferred_ty`: considers variance
  - `StatementKind::AscribeUserType`: `inferred_ty` is the type of the place, so no variance needed
- during mir borrowck
  - `user_ty -> inferred_ty`: does not consider variance
  - `StatementKind::AscribeUserType`: applies variance

This mostly worked fine. The lifetimes in `inferred_ty` were only bound by its relation to `user_ty` and to the `place` of `StatementKind::AscribeUserType`, so it doesn't matter where exactly the subtyping happens.

It does however matter when having higher ranked subtying. At this point the place where the subtyping happens is forced, causing this mismatch between building and borrowck to result in unintended errors.

cc #96514 which is pretty much the same issue

r? `@nikomatsakis`
2022-05-21 23:34:30 +00:00
Joshua Nelson
0c92d1c7f3 Fix typo in Mir phase docs 2022-05-21 16:21:44 -05:00
bors
4f372b14de Auto merge of #97239 - jhpratt:remove-crate-vis, r=joshtriplett
Remove `crate` visibility modifier

FCP to remove this syntax is just about complete in #53120. Once it completes, this should be merged ASAP to avoid merge conflicts.

The first two commits remove usage of the feature in this repository, while the last removes the feature itself.
2022-05-21 06:38:49 +00:00
lcnr
db11c1939c update mir user type printing and apparently fix an ICE 2022-05-21 08:13:17 +02:00
lcnr
39a03779f8 correctly deal with user type ascriptions in pat 2022-05-21 08:13:17 +02:00
Jacob Pratt
49c82f31a8
Remove crate visibility usage in compiler 2022-05-20 20:04:54 -04:00
bors
e6a4afc3af Auto merge of #95418 - cjgillot:more-disk, r=davidtwco
Cache more queries on disk

One of the principles of incremental compilation is to allow saving results on disk to avoid recomputing them.
This PR investigates persisting a lot of queries whose result are to be saved into metadata.
Some of the queries are cheap reads from HIR, but we may also want to get rid of these reads for incremental lowering.
2022-05-20 20:49:55 +00:00
bors
22ee39504a Auto merge of #97211 - GuillaumeGomez:rollup-jul7x7e, r=GuillaumeGomez
Rollup of 6 pull requests

Successful merges:

 - #96565 (rustdoc: show implementations on `#[fundamental]` wrappers)
 - #97179 (Add new lint to enforce whitespace after keywords)
 - #97185 (interpret/validity: separately control checking numbers for being init and non-ptr)
 - #97188 (Remove unneeded null pointer asserts in ptr2int casts)
 - #97189 (Update .mailmap)
 - #97192 (Say "last" instead of "rightmost" in the documentation for `std::str:rfind`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-05-20 13:18:37 +00:00
Guillaume Gomez
706aa59efa
Rollup merge of #97185 - RalfJung:number-validity, r=oli-obk
interpret/validity: separately control checking numbers for being init and non-ptr

This lets Miri control this in a more fine-grained way.

r? `@oli-obk`
2022-05-20 14:03:03 +02:00
lcnr
4a82bc9ea0 bool to custom enum 2022-05-20 11:50:07 +02:00
lcnr
f3f68324cc move unique param check into rustc_middle 2022-05-20 11:27:06 +02:00
Ralf Jung
5514b1176f interpret/validity: separately control checking numbers for being init and non-ptr 2022-05-19 20:16:25 +02:00
bors
c067287049 Auto merge of #97024 - lcnr:simplify_type-sus, r=<try>
`simplify_type` improvements and cursed docs

the existing `TreatParams` enum pretty much mixes everything up. Not sure why this looked right to me in #94057

This also includes two changes which impact perf:
- `ty::Projection` with inference vars shouldn't be treated as a rigid type, even if fully normalized
- `ty::Placeholder` only unifies with itself, so actually return `Some` for them

r? `@nikomatsakis`
2022-05-19 13:08:51 +00:00
Jacob Pratt
f0620c9503 Proper const stability check, default to unstable
Rather than deferring to const eval for checking if a trait is const, we
now check up-front. This allows the error to be emitted earlier, notably
at the same time as other stability checks.

Also included in this commit is a change of the default const stability
level to UNstable. Previously, an item that was `const` but did not
explicitly state it was unstable was implicitly stable.
2022-05-19 12:21:45 +00:00
Jacob Pratt
a9dd4cfa6b Add and use stability helper methods
This avoids an ambiguity (when reading) where `.level.is_stable()` is
not immediately clear whether it is general stability or const
stability.
2022-05-19 12:21:45 +00:00
bors
cd282d7f75 Auto merge of #97019 - b-naber:transition-to-valtrees-pt1, r=oli-obk
Transition to valtrees pt1

Compartmentalising https://github.com/rust-lang/rust/pull/96591 as much as possible.

r? `@oli-obk`
2022-05-18 20:12:07 +00:00
lcnr
db19e2bd01 fix simplify_type 2022-05-18 09:00:30 +02:00
Dylan DPC
04f903859a
Rollup merge of #95979 - lcnr:coherence-docs, r=compiler-errors
update coherence docs, fix generator + opaque type ICE

the world is confusing, this makes it slightly less so
2022-05-18 08:41:14 +02:00
bors
00755e4ca6 Auto merge of #96959 - nbdd0121:unwind, r=Amanieu
Prevent unwinding when `-C panic=abort` is used regardless declared ABI

Ensures that Rust code will abort with `-C panic=abort` regardless ABI used.
```rust
extern "C-unwind" {
    fn may_unwind();
}

// Will be nounwind with `-C panic=abort`, despite `C-unwind` ABI.
pub unsafe extern "C-unwind" fn rust_item_that_can_unwind() {
    may_unwind();
}
```

Current behaviour is that unwind will propagate through. While the current behaviour won't cause unsoundness it is inconsistent with the text reading of [RFC2945](https://rust-lang.github.io/rfcs/2945-c-unwind-abi.html).

I tweaked `fn_can_unwind` instead of tweaking `AbortUnwindingCalls` because this approach would allow Rust (non-direct) callers to also see that this function is nounwind, so it can prevent excessive landing pads generation.

For more discussions: https://rust-lang.zulipchat.com/#narrow/stream/210922-project-ffi-unwind/topic/soundness.20in.20mixed.20panic.20mode.

cc `@alexcrichton,` `@BatmanAoD`
r? `@Amanieu`

`@rustbot` label: T-compiler T-lang F-c_unwind
2022-05-17 15:04:50 +00:00
bors
3655175a75 Auto merge of #97111 - JohnTitor:rollup-x3vjf6u, r=JohnTitor
Rollup of 7 pull requests

Successful merges:

 - #96329 (Add a couple tests for #90887 fixes)
 - #97009 (Allow `unused_macro_rules` in path tests)
 - #97075 (Add regression test for #81804)
 - #97079 (Change `Successors` to `impl Iterator<Item = BasicBlock>`)
 - #97080 (remove the `RelateResultCompare` trait)
 - #97093 (Migrate `maybe_recover_from_bad_type_plus` diagnostic)
 - #97102 (Update function pointer call error message)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-05-17 12:01:12 +00:00
Yuki Okushi
70cd85f5e3
Rollup merge of #97079 - SparrowLii:successors, r=lcnr
Change `Successors` to `impl Iterator<Item = BasicBlock>`

This PR fixes the FIXME in `compiler\rustc_middle\src\mir\mod.rs`.
This can omit several `&`, `*` or `cloned` operations on Successros' generated elements
2022-05-17 19:01:32 +09:00
bors
735efc0c70 Auto merge of #97012 - oli-obk:🦀_intrinsics, r=davidtwco
Add a query for checking whether a function is an intrinsic.

work towards #93145

This will reduce churn when we add more ways to declare intrinsics

r? `@scottmcm`
2022-05-17 09:39:26 +00:00
bors
7355d971a9 Auto merge of #96825 - kckeiks:remove-item-like-visitor-trait, r=cjgillot
Retire `ItemLikeVisitor` trait

Issue #95004
cc `@cjgillot`
2022-05-17 06:51:45 +00:00
bors
c1d65eaa45 Auto merge of #96892 - oli-obk:🐌_obligation_cause_code_🐌, r=estebank
Clean up derived obligation creation

r? `@estebank`

working on fixing the perf regression from https://github.com/rust-lang/rust/pull/91030#issuecomment-1083360210
2022-05-17 01:46:25 +00:00
SparrowLii
38bf1158bd Change Successors to impl Iterator<Item = BasicBlock> 2022-05-17 08:41:01 +08:00
b-naber
96b36d6eb2 use GlobalId in eval_to_valtree query and introduce query for valtree_to_const_val 2022-05-16 15:58:15 +02:00
Oli Scherer
0cefa5fa18 Force inline InternedObligationCauseCode creation 2022-05-16 13:34:03 +00:00
Oli Scherer
0a6b69106e Add a query for checking whether a function is an intrinsic. 2022-05-16 07:07:44 +00:00
bors
2a8a0fc423 Auto merge of #96883 - jackh726:early-binder-2, r=oli-obk
Add EarlyBinder

Chalk has no concept of `Param` (e0ade19d13/chalk-ir/src/lib.rs (L579)) or `ReEarlyBound` (e0ade19d13/chalk-ir/src/lib.rs (L1308)). Everything  is just "bound" - the equivalent of rustc's late-bound. It's not completely clear yet whether to move everything to the same time of binder in rustc or add `Param` and `ReEarlyBound` in Chalk.

Either way, tracking when we have or haven't already substituted out these in rustc can be helpful.

As a first step, I'm just adding a `EarlyBinder` newtype that is required to call `subst`. I also add a couple "transparent" `bound_*` wrappers around a couple query that are often immediately substituted.

r? `@nikomatsakis`
2022-05-14 23:53:11 +00:00
Miguel Guarniz
f77658b470 use opt_item_name to pattern match items with names
Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>
2022-05-14 11:02:14 -04:00
Jack Huey
06a1e8854c Add rustc_on_unimplemented to Subst 2022-05-14 10:16:59 -04:00
Jack Huey
91afd02632 Add bound_explicit_item_bounds and bound_item_bounds 2022-05-14 10:16:49 -04:00
bors
8019fa0dc0 Auto merge of #95826 - carbotaniuman:miri-permissive-provenance, r=RalfJung
Initial work on Miri permissive-exposed-provenance

Rustc portion of the changes for portions of a permissive ptr-to-int model for Miri. The main changes here are changing `ptr_get_alloc` and `get_alloc_id` to return an Option, and also making ptr-to-int casts have an expose side effect.
2022-05-14 10:36:47 +00:00
Jack Huey
0247faed29 Add bound_impl_trait_ref 2022-05-13 18:27:40 -04:00
Jack Huey
6c05e8d009 Add bound_fn_sig 2022-05-13 18:27:40 -04:00
Jack Huey
c92248ab9f Add bound_type_of 2022-05-13 18:27:18 -04:00
carbotaniuman
bd5fce65c6 Rustc changes for permissive provenance 2022-05-13 12:30:25 -05:00
Miguel Guarniz
df119428a2 change for_each_module's parameter to FnMut
Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>
2022-05-13 11:46:06 -04:00
Miguel Guarniz
cad1fd2f16 update rustdoc code to use new method name
Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>
2022-05-13 11:46:06 -04:00
Miguel Guarniz
f975d05116 rename visit item-like methods
Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>
2022-05-13 11:46:06 -04:00
Miguel Guarniz
93616dd539 remove ItemLikeVisitor and DeepVisitor
Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>
2022-05-13 11:46:06 -04:00
Miguel Guarniz
cdba1dcef6 add module_items
Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>
2022-05-13 11:46:06 -04:00
Oli Scherer
59bbbe78e2 Avoid invoking the full eq infrastructure when all we want is to check a discriminant 2022-05-13 09:31:46 +00:00
Camille GILLOT
29f3b3fe49 Do not cache item_attrs. 2022-05-13 08:06:48 +02:00
Camille GILLOT
9900ea352b Cache more queries on disk. 2022-05-13 08:06:48 +02:00
Matthias Krüger
f2100daf32
Rollup merge of #96989 - cjgillot:defpath-use, r=davidtwco
Be more precise than DefPathData::Misc.

This variant was used for two unrelated things. Let's make this cleaner.
2022-05-13 05:33:13 +02:00
Camille GILLOT
ecbda428ec Correct comment. 2022-05-12 20:16:11 +02:00
bors
481db40311 Auto merge of #95562 - lcnr:attr-no-encode, r=davidtwco
don't encode only locally used attrs

Part of https://github.com/rust-lang/compiler-team/issues/505.

We now filter builtin attributes before encoding them in the crate metadata in case they should only be used in the local crate. To prevent accidental misuse `get_attrs` now requires the caller to state which attribute they are interested in. For places where that isn't trivially possible, I've added a method `fn get_attrs_unchecked` which I intend to remove in a followup PR.

After this pull request landed, we can then slowly move all attributes to only be used in the local crate while being certain that we don't accidentally try to access them from extern crates.

cc https://github.com/rust-lang/rust/pull/94963#issuecomment-1082924289
2022-05-12 12:48:30 +00:00
Oli Scherer
72f144de24 Give the inliner some hints 2022-05-12 11:29:01 +00:00
bors
3a08bd7873 Auto merge of #96889 - Aaron1011:place-ref-remove, r=compiler-errors
Remove `PartialOrd`/`Ord` impl for `PlaceRef`

This is a new attempt at #93315. It removes one usage
of the `Ord` impl for `DefId`, which should make it easier
to eventually remove that impl.
2022-05-12 05:03:48 +00:00
bors
0cd939e36c Auto merge of #96150 - est31:unused_macro_rules, r=petrochenkov
Implement a lint to warn about unused macro rules

This implements a new lint to warn about unused macro rules (arms/matchers), similar to the `unused_macros` lint added by #41907 that warns about entire macros.

```rust
macro_rules! unused_empty {
    (hello) => { println!("Hello, world!") };
    () => { println!("empty") }; //~ ERROR: 1st rule of macro `unused_empty` is never used
}

fn main() {
    unused_empty!(hello);
}
```

Builds upon #96149 and #96156.

Fixes #73576
2022-05-12 00:08:08 +00:00
Gary Guo
c586bc3d76 Prevent unwinding when -C panic=abort is used regardless declared ABI 2022-05-12 00:03:48 +01:00
bors
cb9cb4d4e1 Auto merge of #96806 - cjgillot:codegen-fulfill-nice, r=oli-obk
Gracefully fail to resolve associated items instead of `delay_span_bug`.

`codegen_fulfill_obligation` is used during instance resolution for trait items.

In case of insufficient normalization issues during MIR inlining, it caused ICEs.
It's better to gracefully refuse to resolve the associated item, and let the caller decide what to do with this.

Split from https://github.com/rust-lang/rust/pull/91743
Closes #69121
Closes #73021
Closes #88599
Closes #93008
Closes #93248
Closes #94680
Closes #96170
r? `@oli-obk`
2022-05-11 21:39:02 +00:00
Aaron Hill
6b747aa397
Remove PartialOrd/Ord impl for PlaceRef
This is a new attempt at #93315. It removes one usage
of the `Ord` impl for `DefId`, which should make it easier
to eventually remove that impl.
2022-05-11 16:22:23 -04:00
Camille GILLOT
6cfe52c094 Gracefully fail to resolve associated items instead of delay_span_bug. 2022-05-11 08:28:02 +02:00
Jack Huey
319575ae8c Introduce EarlyBinder 2022-05-10 22:47:18 -04:00
Oli Scherer
d63f82e1ef Use lifetimes on type-alias-impl-trait used in function signatures to infer output type lifetimes 2022-05-10 14:50:31 +00:00
Oli Scherer
824e9e47f7 Use InternedObligationCauseCode everywhere 2022-05-10 12:01:56 +00:00
Oli Scherer
213c17486e Make FunctionArgumentObligation also use the "no allocation for misc" trick 2022-05-10 11:26:53 +00:00
Oli Scherer
1b51e1ad20 Don't allocate misc obligation parents of derived obligations 2022-05-10 11:14:07 +00:00
Oli Scherer
9ba6ddb929 Make the derived obligation cause parent private 2022-05-10 11:10:27 +00:00
Oli Scherer
5b5b549580 Add a helper function for a common piece of code 2022-05-10 11:03:52 +00:00
bors
c51871c469 Auto merge of #94799 - lcnr:list-ty-perf, r=petrochenkov
update `hash_stable` for `List<Ty<'tcx>>`

cc https://github.com/rust-lang/rust/pull/93505#issuecomment-1047538798

this is the hottest part changed since the pre-merge perf run
2022-05-10 10:53:47 +00:00
Oli Scherer
05a62c5527 Remove clone_code method 2022-05-10 10:42:29 +00:00
Oli Scherer
dc21fcb2fc Remove another use of clone_code 2022-05-10 10:32:35 +00:00
lcnr
5ee1b18a14 update clippy 2022-05-10 12:07:35 +02:00
lcnr
6c8265dc56 only_local: always check for misuse 2022-05-10 12:07:35 +02:00
Oli Scherer
704bbe5210 Move an extension trait method onto the type directly and reuse it 2022-05-10 09:26:09 +00:00
Oli Scherer
312d27d0a2 Remove some unnecessary clones 2022-05-10 08:43:39 +00:00
lcnr
58781edc54 update coherence docs, fix opaque type + generator ice 2022-05-10 09:09:06 +02:00
Dylan DPC
ec53c379cc
Rollup merge of #96872 - RalfJung:layout-sanity, r=eddyb
make sure ScalarPair enums have ScalarPair variants; add some layout sanity checks

`@eddyb` suggested that it might be reasonable for `ScalarPair` enums to simply adjust the ABI of their variants accordingly, such that the layout invariant Miri expects actually holds. This PR implements that. I should note though that I don't know much about this layout computation code and what non-Miri consumers expect from it, so tread with caution!

I also added a function to sanity-check that computed layouts are internally consistent. This helped a lot in figuring out the final shape of this PR, though I am also not 100% sure that these sanity checks are the right ones.

Cc `@oli-obk`
Fixes https://github.com/rust-lang/rust/issues/96221
2022-05-10 08:24:05 +02:00
lcnr
fc128b6764 add check and don't encode #[inline] 2022-05-10 08:09:37 +02:00
lcnr
b618cdb224 fix comment 2022-05-10 08:09:37 +02:00
lcnr
74b6d296db don't encode only locally used attrs 2022-05-10 08:09:37 +02:00
bors
cb390735b0 Auto merge of #96838 - tmiasko:lazy-switch-sources, r=oli-obk
Optimize switch sources representation and usage

* Avoid constructing switch sources unless necessary - switch sources are used by backward analysis with a custom switch int edge effects, but are otherwise unnecessarily computed.
* Use sparse representation of switch sources to avoid quadratic space overhead.
2022-05-09 22:15:30 +00:00
bors
88860d5474 Auto merge of #96473 - lcnr:querify-codegen-fn-attrs, r=cjgillot
store `codegen_fn_attrs` in crate metadata

extracted from #95562 because the change isn't trivial.
2022-05-09 19:52:59 +00:00
Ralf Jung
02eca34534 also sanity-check Abi::Vector, and slight refactoring 2022-05-09 21:40:33 +02:00
Matthias Krüger
0e00ed5f48
Rollup merge of #96854 - jackh726:subst-cleanup, r=compiler-errors
Some subst cleanup

Two separate things here. Both changes are useful for some refactoring I'm doing to add an "EarlyBinder" newtype. (Part of chalkification).

1) Remove `subst_spanned` and just use `subst`. It wasn't used much anyways. In practice, I think we can probably get most of the info just from the actual error message. If not, outputting logs should do the trick. (The specific line probably wouldn't help much anyways).

2) Call `.subst()` before `replace_bound_vars_with_fresh_vars` and `erase_late_bound_regions` in three places that do the opposite. I think there might have been some time in the past that the order here matter for something, but this shouldn't be the case anymore. Conceptually, it makes more sense to the of the *early bound* vars on `fn`s as "outside" the late bound vars.
2022-05-09 18:45:39 +02:00
lcnr
32b13ac928 review 2022-05-09 18:40:18 +02:00
lcnr
d371ebe117 only compute codegen_fn_attrs where needed 2022-05-09 18:40:18 +02:00
Ralf Jung
2c11c3d86c make sure ScalarPair enums have ScalarPair variants; add some layout sanity checks 2022-05-09 17:46:35 +02:00
lcnr
66ff6c32e5 only cache codegen_fn_attrs on disk if its local 2022-05-09 16:48:30 +02:00
lcnr
501067cb05 move panic-in-drop=abort check for drop_in_place
Whether `drop_in_place` can abort does depend on the
`panic-in-drop` option while compiling the current crate,
not `core`
2022-05-09 16:48:30 +02:00
lcnr
bd1d18660b store codegen_fn_attrs in crate metadata 2022-05-09 16:48:30 +02:00
bors
8a2fe75d0e Auto merge of #95960 - jhpratt:remove-rustc_deprecated, r=compiler-errors
Remove `#[rustc_deprecated]`

This removes `#[rustc_deprecated]` and introduces diagnostics to help users to the right direction (that being `#[deprecated]`). All uses of `#[rustc_deprecated]` have been converted. CI is expected to fail initially; this requires #95958, which includes converting `stdarch`.

I plan on following up in a short while (maybe a bootstrap cycle?) removing the diagnostics, as they're only intended to be short-term.
2022-05-09 04:47:30 +00:00
Jack Huey
e14eae6226 Remove subst_spanned 2022-05-08 21:53:25 -04:00
Tomasz Miąsko
2be012a0c6 Use sparse representation of switch sources
to avoid quadratic space overhead
2022-05-08 23:48:23 +02:00
Tomasz Miąsko
fbc3cc18be Avoid constructing switch sources unless necessary
Switch sources are used by backward analysis with a custom switch int
edge effects, but are otherwise unnecessarily computed.

Delay the computation until we know that switch sources are indeed
required and avoid the computation otherwise.
2022-05-08 23:14:56 +02:00
Fridtjof Stoldt
9516a40f1e
Fixed typo in docs and correct doc links
Co-authored-by: Philipp Krones <hello@philkrones.com>
2022-05-08 17:24:15 +02:00
xFrednet
2c5e85249f
Move lint expectation checking into a separate query (RFC 2383) 2022-05-08 14:37:14 +02:00
Guillaume Gomez
c29f8575ac
Rollup merge of #96581 - RalfJung:debug-size-align, r=oli-obk
make Size and Align debug-printing a bit more compact

In particular in `{:#?}`-mode, these take up a lot of space, so I think this is the better alternative (even though it is a bit longer in `{:?}` mode, I think it is still more readable).

We could make it even smaller by deviating further from what the actual code looks like, e.g. via something like `Size(4 bytes)`. Not sure what people would think about that?

Cc `````@oli-obk`````
2022-05-07 15:23:44 +02:00
bors
574830f573 Auto merge of #96094 - Elliot-Roberts:fix_doctests, r=compiler-errors
Begin fixing all the broken doctests in `compiler/`

Begins to fix #95994.
All of them pass now but 24 of them I've marked with `ignore HELP (<explanation>)` (asking for help) as I'm unsure how to get them to work / if we should leave them as they are.
There are also a few that I marked `ignore` that could maybe be made to work but seem less important.
Each `ignore` has a rough "reason" for ignoring after it parentheses, with

- `(pseudo-rust)` meaning "mostly rust-like but contains foreign syntax"
- `(illustrative)` a somewhat catchall for either a fragment of rust that doesn't stand on its own (like a lone type), or abbreviated rust with ellipses and undeclared types that would get too cluttered if made compile-worthy.
- `(not-rust)` stuff that isn't rust but benefits from the syntax highlighting, like MIR.
- `(internal)` uses `rustc_*` code which would be difficult to make work with the testing setup.

Those reason notes are a bit inconsistently applied and messy though. If that's important I can go through them again and try a more principled approach. When I run `rg '```ignore \(' .` on the repo, there look to be lots of different conventions other people have used for this sort of thing. I could try unifying them all if that would be helpful.

I'm not sure if there was a better existing way to do this but I wrote my own script to help me run all the doctests and wade through the output. If that would be useful to anyone else, I put it here: https://github.com/Elliot-Roberts/rust_doctest_fixing_tool
2022-05-07 06:30:29 +00:00
bors
f6e5570460 Auto merge of #96531 - kckeiks:remove-item-like-visitor-from-rustc-typeck, r=cjgillot
Remove ItemLikeVisitor impls from rustc_typeck

Issue #95004
cc `@cjgillot`
2022-05-07 01:59:11 +00:00
Guillaume Gomez
66443a1852
Rollup merge of #96557 - nbdd0121:const, r=oli-obk
Allow inline consts to reference generic params

Tracking issue: #76001

The RFC says that inline consts cannot reference to generic parameters (for now), same as array length expressions. And expresses that it's desirable for it to reference in-scope generics, when array length expressions gain that feature as well.

However it is possible to implement this for inline consts before doing this for all anon consts, because inline consts are only used as values and they won't be used in the type system. So we can have:
```rust
fn foo<T>() {
    let x = [4i32; std::mem::size_of::<T>()];   // NOT ALLOWED (for now)
    let x = const { std::mem::size_of::<T>() }; // ALLOWED with this PR!
    let x = [4i32; const { std::mem::size_of::<T>() }];   // NOT ALLOWED (for now)
}
```

This would make inline consts super useful for compile-time checks and assertions:
```rust
fn assert_zst<T>() {
    const { assert!(std::mem::size_of::<T>() == 0) };
}
```

This would create an error during monomorphization when `assert_zst` is instantiated with non-ZST `T`s. A error during mono might sound scary, but this is exactly what a "desugared" inline const would do:
```rust
fn assert_zst<T>() {
    struct F<T>(T);
    impl<T> F<T> {
        const V: () = assert!(std::mem::size_of::<T>() == 0);
    }
    let _ = F::<T>::V;
}
```

It should also be noted that the current inline const implementation can already reference the type params via type inference, so this resolver-level restriction is not any useful either:
```rust
fn foo<T>() -> usize {
    let (_, size): (PhantomData<T>, usize) = const {
        const fn my_size_of<T>() -> (PhantomData<T>, usize) {
            (PhantomData, std::mem::size_of::<T>())
        }
        my_size_of()
    };
    size
}
```

```@rustbot``` label: F-inline_const
2022-05-06 20:05:37 +02:00
Miguel Guarniz
91ef3ba71d remove all usages of hir().def_kind
Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>
2022-05-06 12:11:05 -04:00
Ralf Jung
22cc6c3482 don't debug-print ConstValue in MIR pretty-printer 2022-05-06 10:57:03 +02:00
est31
5646e9a172 Allow unused rules in some places in the compiler, library and tools 2022-05-05 19:13:00 +02:00
bors
a7d6768e3b Auto merge of #91779 - ridwanabdillahi:natvis, r=michaelwoerister
Add a new Rust attribute to support embedding debugger visualizers

Implemented [this RFC](https://github.com/rust-lang/rfcs/pull/3191) to add support for embedding debugger visualizers into a PDB.

Added a new attribute `#[debugger_visualizer]` and updated the `CrateMetadata` to store debugger visualizers for crate dependencies.

RFC: https://github.com/rust-lang/rfcs/pull/3191
2022-05-05 12:26:38 +00:00
Yuki Okushi
da57b3a832
Rollup merge of #96628 - joshtriplett:stabilize-then-some, r=m-ou-se
Stabilize `bool::then_some`

FCP completed in https://github.com/rust-lang/rust/issues/80967
2022-05-05 10:20:35 +09:00
Josh Triplett
0fc5c524f5 Stabilize bool::then_some 2022-05-04 13:22:08 +02:00
Tomasz Miąsko
a63d414031 Update ProjectionElem::Downcast documentation
`ProjectionElem:::Downcast` is used when downcasting to a variant of
an enum or a generator, regardless of the number of variants.
2022-05-03 22:29:51 +02:00
ridwanabdillahi
175a4eab84 Add support for a new attribute #[debugger_visualizer] to support embedding debugger visualizers into a generated PDB.
Cleanup `DebuggerVisualizerFile` type and other minor cleanup of queries.

Merge the queries for debugger visualizers into a single query.

Revert move of `resolve_path` to `rustc_builtin_macros`. Update dependencies in Cargo.toml for `rustc_passes`.

Respond to PR comments. Load visualizer files into opaque bytes `Vec<u8>`. Debugger visualizers for dynamically linked crates should not be embedded in the current crate.

Update the unstable book with the new feature. Add the tracking issue for the debugger_visualizer feature.

Respond to PR comments and minor cleanups.
2022-05-03 10:53:54 -07:00
Gary Guo
bf4d7fa43f Hide InlineConst's generic arg during print
The generic arg is for type inference only and shouldn't be exposed
to users.
2022-05-03 14:37:16 +01:00
Yuki Okushi
61c687a0db
Rollup merge of #96599 - tmiasko:discriminant-docs, r=estebank
Update `RValue::Discriminant` documentation

`RValue::Discriminant` returns zero for types without discriminant.
This guarantee is already documented for `discriminant_value`
intrinsics which is implemented in terms of `RValue::Discriminant`.
2022-05-03 14:58:59 +09:00
Elliot Roberts
7907385999 fix most compiler/ doctests 2022-05-02 17:40:30 -07:00
Vadim Petrochenkov
5b5964f569 rustc: Panic by default in DefIdTree::parent
Only crate root def-ids don't have a parent, and in majority of cases the argument of `DefIdTree::parent` cannot be a crate root.
So we now panic by default in `parent` and introduce a new non-panicing function `opt_parent` for cases where the argument can be a crate root.

Same applies to `local_parent`/`opt_local_parent`.
2022-05-02 01:56:50 +03:00
bors
6eda7642bd Auto merge of #96549 - ouz-a:mir-opt, r=oli-obk
Move Derefer before Retag

_Follow up work to #96116 #95857 #95649_

This moves `Derefer` before `Retag` and creates a new `LocalInfo` called `Temp` to avoid retagging created temp values.

Zulip discussion [link](https://rust-lang.zulipchat.com/#narrow/stream/189540-t-compiler.2Fwg-mir-opt/topic/deref.20as.20first.20and.20only.20projection)

r? `@oli-obk`
2022-05-01 15:25:16 +00:00
ouz-a
d9ddb6446d re-name stuff 2022-05-01 15:38:22 +03:00
Tomasz Miąsko
b37fb23d9f Update RValue::Discriminant documentation
`RValue::Discriminant` returns zero for types without discriminant.
This guarantee is already documented for `discriminant_value`
intrinsics which is implemented in terms of `RValue::Discriminant`.
2022-05-01 11:49:46 +02:00
Camille GILLOT
74583852e8 Save colon span to suggest bounds. 2022-04-30 13:55:17 +02:00
Camille GILLOT
94449e6101 Store all generic bounds as where predicates. 2022-04-30 13:55:13 +02:00
Camille GILLOT
05b29f9a92 Inline WhereClause into Generics. 2022-04-30 13:51:49 +02:00
bors
9a98c63b30 Auto merge of #96500 - SparrowLii:rpo, r=tmiasko
Reduce duplication of RPO calculation of mir

Computing the RPO of mir is not a low-cost thing, but it is duplicate in many places. In particular the `iterate_to_fixpoint` method which is called multiple times when computing the data flow.
This PR reduces the number of times the RPO is recalculated as much as possible, which should save some compile time.
2022-04-30 05:06:47 +00:00
SparrowLii
7149bbcdc5 Eliminate duplication of RPO calculation for mir
add `postorder_cache` to mir Body

add `ReversePostorderCache` struct

correct struct name and comments
2022-04-30 03:42:57 +08:00
ouz-a
4d4b0f140f remove and bless 2022-04-29 18:29:38 +03:00
ouz-a
f1c5f34f76 exp-stuff-dirty 2022-04-29 14:42:24 +03:00
bors
b2c2a32870 Auto merge of #95976 - b-naber:valtree-constval-conversion, r=oli-obk
Implement Valtree to ConstValue conversion

Once we start to use `ValTree`s in the type system we will need to be able to convert them into `ConstValue` instances, which we want to continue to use after MIR construction.

r? `@oli-obk`

cc `@RalfJung`
2022-04-28 13:18:22 +00:00
b-naber
ef5f07256c combine all unsized types and add another recursive call to process nested unsized types correctly 2022-04-27 16:58:16 +02:00
Michael Goulet
f9e7489f87 TAITs are suggestable 2022-04-26 18:55:55 -07:00
bors
a7197189cd Auto merge of #96425 - oli-obk:fix_incremental_regression_unsafety_checking, r=compiler-errors
Fix incremental perf regression unsafety checking

Perf regression introduced in #96294

We will simply avoid emitting the name of the unsafe function in MIR unsafeck, since we're moving to THIR unsafeck anyway.
2022-04-26 22:35:40 +00:00
Oli Scherer
3568bdc6cd Revert "add DefId to unsafety violations and display function path in E0133"
This reverts commit 8b8f6653cf.
2022-04-26 14:49:28 +00:00
Guillaume Gomez
f908391136
Rollup merge of #96400 - JakobDegen:shallow-init-docs, r=Dylan-DPC
Correct documentation for `Rvalue::ShallowInitBox`

As a part of the big MIR docs PR, I had added a comment indicating that `Rvalue::ShallowInitBox` is disallowed after drop elaboration, but this is not true (no idea why I thought it was). Codegen has support for it, and trying to enforce this rule in the validator causes compiling core to ICE on the very first `box` statement.

That being said, this `Rvalue` probably *should* be banned after drop elaboration - it doesn't seem like it's still useful for much. However, I do not have time right now to actually go investigate how difficult a change that is to make, so in the meantime fixing the docs to reflect the current situation seems like the right step.

r? rust-lang/mir-opt
2022-04-26 13:22:30 +02:00
Guillaume Gomez
fe49981ea0
Rollup merge of #94703 - kjetilkjeka:nvptx-kernel-args-abi2, r=nagisa
Fix codegen bug in "ptx-kernel" abi related to arg passing

I found a codegen bug in the nvptx abi related to that args are passed as ptrs ([see comment](https://github.com/rust-lang/rust/issues/38788#issuecomment-1048999928)), this is not as specified in the [ptx-interoperability doc](https://docs.nvidia.com/cuda/ptx-writers-guide-to-interoperability/) or how C/C++ does it. It will also almost always fail in practice since device/host uses different memory spaces for most hardware.

This PR fixes the bug and add tests for passing structs to ptx kernels.

I observed that all nvptx assembly tests had been marked as [ignore a long time ago](https://github.com/rust-lang/rust/pull/59752#issuecomment-501713428). I'm not sure if the new one should be marked as ignore, it passed on my computer but it might fail if ptx-linker is missing on the server? I guess this is outside scope for this PR and should be looked at in a different issue/PR.

I only fixed the nvptx64-nvidia-cuda target and not the potential code paths for the non-existing 32bit target. Even though 32bit nvptx is not a supported target there are still some code under the hood supporting codegen for 32 bit ptx. I was advised to create an MCP to find out if this code should be removed or updated.

Perhaps ``@RDambrosio016`` would have interest in taking a quick look at this.
2022-04-26 13:22:27 +02:00
b-naber
6fc3e630fb add hacky closure to struct_tail_with_normalize in order to allow us to walk valtrees in lockstep with the type 2022-04-26 11:48:59 +02:00
bors
9ea4d4127f Auto merge of #96414 - Dylan-DPC:rollup-t4ofhoa, r=Dylan-DPC
Rollup of 6 pull requests

Successful merges:

 - #90312 (Fix some confusing wording and improve slice-search-related docs)
 - #96149 (Remove unused macro rules)
 - #96279 (rustdoc: Remove .woff font files)
 - #96355 (Better handle too many `#` recovery in raw str)
 - #96379 (delay bug when adjusting `NeverToAny` twice during diagnostic code)
 - #96384 (do not consider two extern types to be similar)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-04-26 01:52:46 +00:00
Dylan DPC
93db30aa7f
Rollup merge of #96149 - est31:remove_unused_macro_matchers, r=petrochenkov
Remove unused macro rules

Removes rules of internal macros that weren't triggered.
2022-04-26 01:21:20 +02:00
bors
ec8619dca2 Auto merge of #96294 - Emilgardis:def_id-in-unsafetyviolationdetails, r=oli-obk
Display function path in unsafety violations - E0133

adds `DefId` to `UnsafetyViolationDetails`

this enables consumers to access the function definition that was reported to be unsafe and also changes the output for some E0133 diagnostics
2022-04-25 23:03:50 +00:00
bors
055bf4ccd5 Auto merge of #96116 - ouz-a:mir-opt, r=oli-obk
Make derefer work everwhere

Follow up work on previous PR's #95649 and #95857.

r? rust-lang/mir-opt

_Co-Authored-By: `@oli-obk_`
2022-04-25 19:34:52 +00:00
Jakob Degen
941e19468a Correct documentation for ShallowInitBox 2022-04-25 14:24:14 -04:00
bors
18b53cefdf Auto merge of #95604 - nbdd0121:used2, r=petrochenkov
Generate synthetic object file to ensure all exported and used symbols participate in the linking

Fix #50007 and #47384

This is the synthetic object file approach that I described in https://github.com/rust-lang/rust/pull/95363#issuecomment-1079932354, allowing all exported and used symbols to be linked while still allowing them to be GCed.

Related #93791, #95363

r? `@petrochenkov`
cc `@carbotaniuman`
2022-04-25 16:14:54 +00:00