Commit graph

916 commits

Author SHA1 Message Date
bors
f2de221b00 Auto merge of #81101 - tmiasko:combine-now, r=nagisa
Combine instructions immediately
2021-01-22 13:10:48 +00:00
Ralf Jung
f62cecd807 do promote array indexing if we know it is in-bounds 2021-01-22 10:36:25 +01:00
Ralf Jung
5be27b7a70 avoid promoting division, modulo and indexing operations that could fail 2021-01-22 10:21:49 +01:00
Ömer Sinan Ağacan
e3faeb486a mir: Improve size_of handling when arg is unsized 2021-01-21 22:17:05 +03:00
bors
65767e5653 Auto merge of #81122 - tmiasko:no-drop, r=davidtwco
Visit only terminators when removing unneeded drops

No functional changes intended
2021-01-21 17:02:49 +00:00
Yuki Okushi
2ebc036220
Rollup merge of #81187 - eltociear:patch-6, r=jonas-schievink
Fix typo in counters.rs

formating -> formatting
2021-01-21 20:04:55 +09:00
Yuki Okushi
bc950c85c5
Rollup merge of #81185 - osa1:fix_80742, r=oli-obk
Fix ICE in mir when evaluating SizeOf on unsized type

Not quite ready yet. This tries to fix #80742 as discussed on [Zulip topic][1],
by using `delay_span_bug`.

I don't understand what `delay_span_bug` does. It seems like my error message
is never used. With this patch, in this program:

```rust
#![allow(incomplete_features)]
#![feature(const_evaluatable_checked)]
#![feature(const_generics)]

use std::fmt::Debug;
use std::marker::PhantomData;
use std::mem::size_of;

struct Inline<T>
where
    [u8; size_of::<T>() + 1]: ,
{
    _phantom: PhantomData<T>,
    buf: [u8; size_of::<T>() + 1],
}

impl<T> Inline<T>
where
    [u8; size_of::<T>() + 1]: ,
{
    pub fn new(val: T) -> Inline<T> {
        todo!()
    }
}

fn main() {
    let dst = Inline::<dyn Debug>::new(0); // line 27
}
```

these errors are printed, both for line 27 (annotated line above):

- "no function or associated item named `new` found for struct `Inline<dyn
  Debug>` in the current scope"
- "the size for values of type `dyn Debug` cannot be known at compilation time"

Second error makes sense, but I'm not sure about the first one and why it's
even printed.

Finally, I'm not sure about the span passing in `const_eval`.

[1]: https://rust-lang.zulipchat.com/#narrow/stream/269128-miri/topic/Help.20fixing.20.2380742
2021-01-21 20:04:53 +09:00
Yuki Okushi
cd0c54abb9
Rollup merge of #81178 - tmiasko:no-landing-pads, r=oli-obk
Visit only terminators when removing landing pads

No functional changes intended
2021-01-21 20:04:48 +09:00
Ömer Sinan Ağacan
3fb53c2c85 Fix ICE in mir when evaluating SizeOf on unsized type
Fixes #80742
2021-01-19 18:35:21 +03:00
Ikko Ashimine
203df1764c
Fix typo in counters.rs
formating -> formatting
2021-01-19 23:42:18 +09:00
bors
47121d6d88 Auto merge of #81110 - LeSeulArtichaut:fix-unused-unsafe-label, r=RalfJung
Fix `unused_unsafe` label with `unsafe_block_in_unsafe_fn

Previously, the following code:

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

unsafe fn foo() {
    unsafe { unsf() }
}

unsafe fn unsf() {}
```

Would give the following warning:

```
warning: unnecessary `unsafe` block
 --> src/lib.rs:4:5
  |
4 |     unsafe { unsf() }
  |     ^^^^^^ unnecessary `unsafe` block
  |
  = note: `#[warn(unused_unsafe)]` on by default
```
which doesn't point out that the block is in an `unsafe fn`.

Tracking issue: #71668
cc #79208
2021-01-19 08:59:37 +00:00
bors
d98d2f57d9 Auto merge of #80707 - oli-obk:stability_hole_const_intrinsics, r=RalfJung
Stability oddity with const intrinsics

cc `@RalfJung`

In https://github.com/rust-lang/rust/pull/80699#discussion_r551495670 `@usbalbin` realized we accepted some intrinsics as `const` without a `#[rustc_const_(un)stable]` attribute. I did some digging, and that example works because intrinsics inherit their stability from their parents... including `#[rustc_const_(un)stable]` attributes. While we may want to fix that (not sure, wasn't there just a MCPed PR that caused this on purpose?), we definitely want tests for it, thus this PR adding tests and some fun tracing statements.
2021-01-18 20:54:36 +00:00
LeSeulArtichaut
50e1ae15e9 Use ty::{IntTy,UintTy,FloatTy} in rustc 2021-01-18 21:09:30 +01:00
Camelid
def0e9b8a4 Fix ICE with ReadPointerAsBytes validation error 2021-01-18 11:51:18 -08:00
Tomasz Miąsko
508eec49e9 Combine instructions immediately
No functional changes intended
2021-01-18 13:15:27 +01:00
Tomasz Miąsko
a9292d871c Remove disabled transformation from instcombine 2021-01-18 13:15:27 +01:00
Ashley Mannix
0068358ba4
Rollup merge of #81142 - wcampbell0x2a:replace-Some-with-is-some, r=jonas-schievink
Replace let Some(..) = with .is_some()
2021-01-18 21:53:41 +10:00
Ashley Mannix
e1d70bc697
Rollup merge of #81121 - tmiasko:simplify-cfg-no-dbg, r=jonas-schievink
Avoid logging the whole MIR body in SimplifyCfg
2021-01-18 21:53:31 +10:00
Ashley Mannix
064e47b99e
Rollup merge of #81116 - bugadani:body-span, r=wesleywiser
ConstProp: Copy body span instead of querying it
2021-01-18 21:53:30 +10:00
oli
5bac1c9229 Only inherit const stability for methods of impl const Trait blocks 2021-01-18 11:07:35 +00:00
bors
0677d97293 Auto merge of #80865 - oliviacrain:proj_based, r=RalfJung
Use PlaceRef projection abstractions more consistently in rustc_mir

PlaceRef contains abstractions for dealing with the `projections` array. This PR uses these abstractions more consistently within the `rustc_mir` crate.

See associated issue: rust-lang/rust#80647.

r? `@RalfJung`
2021-01-18 05:44:40 +00:00
wcampbell
e23acc341c
Replace let Some(..) = with .is_some()
Signed-off-by: wcampbell <wcampbell1995@gmail.com>
2021-01-17 19:06:12 -05:00
Tomasz Miąsko
96e9562a7e Visit only terminators when removing landing pads
No functional changes intended
2021-01-18 00:00:00 +00:00
bors
4253153db2 Auto merge of #80679 - jackh726:predicate-kind-take2, r=lcnr
Remove PredicateKind and instead only use Binder<PredicateAtom>

Originally brought up in https://github.com/rust-lang/rust/pull/76814#discussion_r546858171

r? `@lcnr`
2021-01-17 20:49:11 +00:00
LeSeulArtichaut
2136a5cfad Fix unused_unsafe label with `unsafe_block_in_unsafe_fn 2021-01-17 16:42:27 +01:00
Tomasz Miąsko
c7bad7ba5d Avoid logging the whole MIR body in SimplifyCfg 2021-01-17 15:57:21 +01:00
Dániel Buga
428f948096 Copy body span instead of querying it 2021-01-17 14:50:47 +01:00
oli
949bdd8b79 Add regression test 2021-01-17 13:40:29 +00:00
oli
ad5aa2359d Remove an unnecessary field from a NonConstOp 2021-01-17 13:40:29 +00:00
Mara Bos
34e073f44b
Rollup merge of #81084 - LingMan:map, r=oli-obk
Use Option::map instead of open-coding it

r? ```@oli-obk```
```@rustbot``` modify labels +C-cleanup +T-compiler
2021-01-17 12:24:58 +00:00
Mara Bos
19f97802ca
Rollup merge of #80635 - sexxi-goose:use-place-instead-of-symbol, r=nikomatsakis`
Improve diagnostics when closure doesn't meet trait bound

Improves the diagnostics when closure doesn't meet trait bound by modifying `TypeckResuts::closure_kind_origins` such that `hir::Place` is used instead of `Symbol`. Using `hir::Place` to describe which capture influenced the decision of selecting a trait a closure satisfies to (Fn/FnMut/FnOnce, Copy) allows us to show precise path in the diagnostics when `capture_disjoint_field` feature is enabled.

Closes rust-lang/project-rfc-2229/issues/21

r? ```@nikomatsakis```
2021-01-17 12:24:44 +00:00
Mara Bos
f783871ab1
Rollup merge of #79298 - lcnr:new-elysium, r=matthewjasper
correctly deal with late-bound lifetimes in anon consts

adds support for using late bound lifetimes of the parent context in anon consts.
```rust
#![feature(const_generics)]
const fn inner<'a>() -> usize where &'a (): Sized { 3 }

fn test<'a>() {
    let _: [u8; inner::<'a>()];
}
```
The lifetime `'a` is late bound in `test` so it's not included in its generics but is instead dealt with separately in borrowck.
This didn't previously work for anon consts as they have to use the late bound lifetimes of their parent which has
to be explicitly handled.

r? ```@matthewjasper``` cc ```@varkor``` ```@eddyb```
2021-01-17 12:24:39 +00:00
Tomasz Miąsko
d0a756719f Visit only terminators when removing unneeded drops
No functional changes intended
2021-01-17 00:00:00 +00:00
Jack Huey
3dea68de1d Review changes 2021-01-16 18:56:37 -05:00
bors
8a6518427e Auto merge of #81089 - m-ou-se:rollup-z7iac6i, r=m-ou-se
Rollup of 17 pull requests

Successful merges:

 - #78455 (Introduce {Ref, RefMut}::try_map for optional projections in RefCell)
 - #80144 (Remove giant badge in README)
 - #80614 (Explain why borrows can't be held across yield point in async blocks)
 - #80670 (TrustedRandomAaccess specialization composes incorrectly for nested iter::Zips)
 - #80681 (Clarify what the effects of a 'logic error' are)
 - #80764 (Re-stabilize Weak::as_ptr and friends for unsized T)
 - #80901 (Make `x.py --color always` apply to logging too)
 - #80902 (Add a regression test for #76281)
 - #80941 (Do not suggest invalid code in pattern with loop)
 - #80968 (Stabilize the poll_map feature)
 - #80971 (Put all feature gate tests under `feature-gates/`)
 - #81021 (Remove doctree::Import)
 - #81040 (doctest: Reset errors before dropping the parse session)
 - #81060 (Add a regression test for #50041)
 - #81065 (codegen_cranelift: Fix redundant semicolon warn)
 - #81069 (Add sample code for Rc::new_cyclic)
 - #81081 (Add test for #34792)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-01-16 20:26:20 +00:00
LingMan
76003f31f1 Use Option::map instead of open-coding it 2021-01-16 20:05:02 +01:00
Bastian Kauschke
15f0921d0c correctly deal with late-bound lifetimes in anon consts 2021-01-16 19:27:42 +01:00
Mara Bos
79a8499f77
Rollup merge of #80941 - JohnTitor:ref-mut-pat-in-loops, r=varkor
Do not suggest invalid code in pattern with loop

Fixes #80913
2021-01-16 17:30:02 +00:00
Mara Bos
af5b0d9883
Rollup merge of #80614 - 1000teslas:issue-78938-fix, r=tmandry
Explain why borrows can't be held across yield point in async blocks

For https://github.com/rust-lang/rust/issues/78938.
2021-01-16 17:29:49 +00:00
bors
492b83c697 Auto merge of #80290 - RalfJung:less-intrinsic-write, r=lcnr
implement ptr::write without dedicated intrinsic

This makes `ptr::write` more consistent with `ptr::write_unaligned`, `ptr::read`, `ptr::read_unaligned`, all of which are implemented in terms of `copy_nonoverlapping`.

This means we can also remove `move_val_init` implementations in codegen and Miri, and its special handling in the borrow checker.

Also see [this Zulip discussion](https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/ptr.3A.3Aread.20vs.20ptr.3A.3Awrite).
2021-01-16 17:28:32 +00:00
Olivia Crain
65b5e4386b Use PlaceRef more consistently in rustc_mir 2021-01-16 10:44:23 -06:00
Ralf Jung
1b09dc2596 PlaceRef::ty: use method call syntax 2021-01-16 11:38:14 +01:00
1000teslas
3e9c95b9d4
Update compiler/rustc_mir/src/borrow_check/diagnostics/conflict_errors.rs
Co-authored-by: Esteban Kuber <estebank@users.noreply.github.com>
2021-01-16 03:32:54 +11:00
Yuki Okushi
a584d87417
Rollup merge of #80944 - LingMan:map_or, r=nagisa
Use Option::map_or instead of `.map(..).unwrap_or(..)`

``@rustbot`` modify labels +C-cleanup +T-compiler
2021-01-15 18:26:14 +09:00
Tomasz Miąsko
a65c050333 inline: Round word-size cost estimates up 2021-01-15 00:00:00 +00:00
LingMan
a56bffb4f9 Use Option::map_or instead of .map(..).unwrap_or(..) 2021-01-14 19:23:59 +01:00
Mara Bos
90cc815829
Rollup merge of #80969 - camelid:monomorph-ice-msg, r=nagisa
Use better ICE message when no MIR is available

The ICE message is somewhat confusing and overly specific - the issue is
that there's no MIR available.

This should make debugging these ICEs easier since the error tells you
what's actually wrong, not what it was trying to do when it failed.

cc https://github.com/rust-lang/rust/pull/80952#issuecomment-759198841
cc `````@jyn514`````
2021-01-14 18:00:16 +00:00
Jacob Pratt
edf2e3725e
Use unsigned_abs throughout repository 2021-01-13 17:58:08 -05:00
1000teslas
7f41465f6d Move help link to error index 2021-01-13 23:37:49 +11:00
Camelid
c3f7429fb4 Use better ICE message when no MIR is available
The ICE message is somewhat confusing and overly specific - the issue is
that there's no MIR available.

This should make debugging these ICEs easier since the error tells you
what's actually wrong, not what it was trying to do when it failed.

cc https://github.com/rust-lang/rust/pull/80952#issuecomment-759198841
2021-01-12 20:54:35 -08:00
bors
150d1fee04 Auto merge of #79322 - jyn514:refactor-impl, r=estebank
Separate out a `hir::Impl` struct

This makes it possible to pass the `Impl` directly to functions, instead
of having to pass each of the many fields one at a time. It also
simplifies matches in many cases.

See `rustc_save_analysis::dump_visitor::process_impl` or `rustdoc::clean::clean_impl` for a good example of how this makes `impl`s easier to work with.

r? `@petrochenkov` maybe?
2021-01-13 01:40:41 +00:00
Joshua Nelson
a8ff647deb Separate out a hir::Impl struct
This makes it possible to pass the `Impl` directly to functions, instead
of having to pass each of the many fields one at a time. It also
simplifies matches in many cases.
2021-01-12 20:32:33 -05:00
bors
704e47f78b Auto merge of #78407 - oli-obk:ub_checkable_ctfe, r=RalfJung,pnkfelix
Make CTFE able to check for UB...

... by not doing any optimizations on the `const fn` MIR used in CTFE. This means we duplicate all `const fn`'s MIR now, once for CTFE, once for runtime. This PR is for checking the perf effect, so we have some data when talking about https://github.com/rust-lang/const-eval/blob/master/rfcs/0000-const-ub.md

To do this, we now have two queries for obtaining mir: `optimized_mir` and `mir_for_ctfe`. It is now illegal to invoke `optimized_mir` to obtain the MIR of a const/static item's initializer, an array length, an inline const expression or an enum discriminant initializer. For `const fn`, both `optimized_mir` and `mir_for_ctfe` work, the former returning the MIR that LLVM should use if the function is called at runtime. Similarly it is illegal to invoke `mir_for_ctfe` on regular functions.

This is all checked via appropriate assertions and I don't think it is easy to get wrong, as there should be no `mir_for_ctfe` calls outside the const evaluator or metadata encoding. Almost all rustc devs should keep using `optimized_mir` (or `instance_mir` for that matter).
2021-01-12 17:26:56 +00:00
oli
53e3a23572 Coverage computation needs access to the MIR, too 2021-01-12 15:12:03 +00:00
bors
fc9944fe84 Auto merge of #80499 - matthiaskrgr:red_clos, r=estebank
remove redundant closures (clippy::redundant_closure)
2021-01-12 11:20:47 +00:00
Yuki Okushi
4362da13b1 Do not suggest invalid code in pattern with loop 2021-01-12 17:31:13 +09:00
Yuki Okushi
8e6472fe32
Rollup merge of #80324 - Aaron1011:loop-move-fn-self, r=oli-obk
Explain method-call move errors in loops

PR #73708 added a more detailed explanation of move errors that occur
due to a call to a method that takes `self`. This PR extends that logic
to work when a move error occurs due to a method call in the previous
iteration of a loop.
2021-01-12 07:59:10 +09:00
oli
e90b521a15 --emit=mir now emits both mir_for_ctfe and optimized_mir for const fn 2021-01-11 17:24:41 +00:00
Nym Seddon
06fd212d6a
Add ABI argument to find_mir_or_eval_fn
Add ABI argument for called function in `find_mir_or_eval_fn` and
`call_extra_fn`. Useful for comparing with expected ABI in interpreters.

Related to [miri/1631](https://github.com/rust-lang/miri/issues/1631)
2021-01-10 15:12:50 +00:00
1000teslas
757bd23503 Remove trailing whitespace 2021-01-10 16:47:41 +11:00
1000teslas
9e345a5893 Revise async block error message 2021-01-10 16:47:41 +11:00
1000teslas
12f1795743 Fix location of error message explanation 2021-01-10 16:47:40 +11:00
1000teslas
5ccef56456 Explain why borrows can't be held across yield point in async blocks 2021-01-10 16:47:40 +11:00
Aaron Hill
20979aad77
Change wording of note 2021-01-08 14:57:35 -05:00
Aaron Hill
de90afc72e
Explain method-call move errors in loops
PR #73708 added a more detailed explanation of move errors that occur
due to a call to a method that takes `self`. This PR extends that logic
to work when a move error occurs due to a method call in the previous
iteration of a loop.
2021-01-08 14:37:07 -05:00
Yuki Okushi
3acd75dd25
Rollup merge of #80521 - richkadel:llvm-coverage-counters-2.4.0, r=wesleywiser
MIR Inline is incompatible with coverage

Fixes: #80060

Fixed by disabling inlining if `-Zinstrument-coverage` is set.

The PR also adds additional use cases to the coverage test for doctests.

r? `@wesleywiser`
cc: `@tmandry`
2021-01-08 02:06:03 +09:00
bors
bf5f30684a Auto merge of #80648 - Aaron1011:expn-data-private, r=petrochenkov
Make `ExpnData` fields `krate` and `orig_id` private

These fields are only used by hygiene serialized, and should not be
accessed by anything outside of `rustc_span`.
2021-01-07 08:25:39 +00:00
oli
41a732dfd4 Remove a FIXME and explain the decision 2021-01-05 12:10:56 +00:00
oli
65ee418e5c Do not run const prop on the mir_for_ctfe of const fn 2021-01-04 22:29:45 +00:00
oli
3af7989a7c No doc comments on expressions 2021-01-04 21:40:38 +00:00
oli
9eaec139d0 Small comment adjustments 2021-01-04 21:40:38 +00:00
oli
caeb3d525d Move MIR body loading to a machine function 2021-01-04 21:40:38 +00:00
oli
f6d54aa0c1 Adjust imports 2021-01-04 21:40:38 +00:00
oli
7202054800 Document all the things 2021-01-04 21:40:38 +00:00
oli
db90150b91 Polymorphization should look at the runtime MIR of const fn 2021-01-04 21:40:38 +00:00
oli
eb4e94b2e5 Simplify the optimize_mir query 2021-01-04 21:40:38 +00:00
oli
1f5fb3e056 Differentiate between the availability of ctfe MIR and runtime MIR 2021-01-04 21:40:38 +00:00
oli
cccd40f9b5 Keep an unoptimized duplicate of const fn around
This allows CTFE to reliably detect UB, as otherwise
optimizations may hide UB.
2021-01-04 21:40:38 +00:00
oli
68ff5f0a18 Stop optimizing promoteds 2021-01-04 21:40:38 +00:00
bors
61f5a00923 Auto merge of #80624 - RalfJung:place-ref, r=oli-obk
use PlaceRef more consistently instead of loosely coupled local+projection

Instead of working directly with the `projections` array, use `iter_projections` and `last_projection`. This avoids having to construct new `PlaceRef` from the pieces everywhere.

I only did this for a few files, to see how people think about this. If y'all are happy with this, I'll open an E-mentor issue to complete this. I grepped for `Place::ty_from` to find the places that need adjusting -- this could miss some, but I am not sure what else to grep for.
2021-01-04 20:56:34 +00:00
Rich Kadel
e4aa99fe7a Inlining enabled by -mir-opt-level > 1 is incompatible with coverage
Fixes: #80060

Also adds additional test cases for coverage of doctests.
2021-01-04 11:06:42 -08:00
bors
8989689e72 Auto merge of #80418 - oli-obk:this_could_have_been_so_simple, r=RalfJung
Allow references to interior mutable data behind a feature gate

supercedes #80373 by simply not checking for interior mutability on borrows of locals that have `StorageDead` and thus can never be leaked to the final value of the constant

tracking issue: https://github.com/rust-lang/rust/issues/80384

r? `@RalfJung`
2021-01-04 02:15:57 +00:00
oli
90b56b94f6 Stylistic fixes to diagnostic messages 2021-01-03 15:11:34 +00:00
oli
d3992f36ad Refactor the non-transient cell borrow error diagnostic 2021-01-03 14:46:49 +00:00
Oli Scherer
8968c8a103
Dangling pointers point to everything and nothing
Co-authored-by: Ralf Jung <post@ralfj.de>
2021-01-03 15:19:07 +01:00
Oli Scherer
e5e4a851c4
Grammar fixes
Co-authored-by: Ralf Jung <post@ralfj.de>
2021-01-03 15:15:23 +01:00
Aaron Hill
21b8f2ecde
Make ExpnData fields krate and orig_id private
These fields are only used by hygiene serialized, and should not be
accessed by anything outside of `rustc_span`.
2021-01-03 08:58:43 -05:00
oli
a137ff1706 Update now-more-precise operation with a preciser message 2021-01-03 13:45:16 +00:00
Oli Scherer
e5330a4f52 Apply suggestions from code review
comment nits

Co-authored-by: Ralf Jung <post@ralfj.de>
2021-01-03 13:32:56 +00:00
Ralf Jung
afa7408041 use PlaceRef more consistently instead of loosely coupled local+projection 2021-01-03 14:14:55 +01:00
Matthias Krüger
e2272cdffc remove redundant closures (clippy::redundant_closure) 2021-01-03 13:34:24 +01:00
Roxane
b498870d9c use hir::Place instead of Symbol in closure_kind_origin 2021-01-02 17:49:05 -05:00
Matthias Krüger
8a90626a46 reduce borrowing and (de)referencing around match patterns (clippy::match_ref_pats) 2021-01-02 20:09:17 +01:00
oli
aaee3f27ee Don't mix feature gates and hard errors, decide on one per op and stick with it 2021-01-01 16:59:12 +00:00
oli
3ed14033f7 Reinstate the error-code error over the feature gate error 2021-01-01 16:59:12 +00:00
oli
4158e58d79 Enhance some comments 2021-01-01 16:59:12 +00:00
oli
354e510f7d Fix cell checks in const fn 2021-01-01 16:59:12 +00:00
oli
3a44a20ed1 The proper name for the rule is "enclosing scope" 2021-01-01 16:59:12 +00:00
oli
0b841846ba Allow references to interior mutable data behind a feature gate 2021-01-01 16:59:12 +00:00
Ralf Jung
db03b58f23 remove move_val_init leftovers 2020-12-31 10:53:37 +01:00
Mara Bos
067f1b7030
Rollup merge of #80491 - RalfJung:dangling-of-val, r=oli-obk
Miri: make size/align_of_val work for dangling raw ptrs

This is needed for https://github.com/rust-lang/rust/issues/80365#issuecomment-752128105.

r? `@oli-obk`
2020-12-30 20:56:56 +00:00
Mara Bos
46111c1901
Rollup merge of #80458 - RalfJung:promotion-refactor, r=oli-obk
Some Promotion Refactoring

Clean up promotion a bit:
* factor out some common code
* more exhaustive matches

This *should* not break anything... the only potentially-breaking change is that `BorrowKind::Shallow | BorrowKind::Unique` are now rejected for internal references.

r? ``@oli-obk``
2020-12-30 20:56:52 +00:00
bors
507bff92fa Auto merge of #80510 - JohnTitor:rollup-gow7y0l, r=JohnTitor
Rollup of 7 pull requests

Successful merges:

 - #80185 (Fix ICE when pointing at multi bytes character)
 - #80260 (slightly more typed interface to panic implementation)
 - #80311 (Improvements to NatVis support)
 - #80337 (Use `desc` as a doc-comment for queries if there are no doc comments)
 - #80381 (Revert "Cleanup markdown span handling")
 - #80492 (remove empty wraps, don't return Results from from infallible functions)
 - #80509 (where possible, pass slices instead of &Vec or &String (clippy::ptr_arg))

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2020-12-30 15:30:56 +00:00
bors
bbcaed03bf Auto merge of #79684 - usbalbin:const_copy, r=oli-obk
Make copy[_nonoverlapping] const

Constifies
* `intrinsics::copy` and `intrinsics::copy_nonoverlapping`
* `ptr::read` and `ptr::read_unaligned`
  * `*const T::read` and `*const T::read_unaligned`
  * `*mut T::read` and `*mut T::read_unaligned`
* `MaybeUninit::assume_init_read`
2020-12-30 12:43:02 +00:00
Matthias Krüger
bdc9291ed9 where possible, pass slices instead of &Vec or &String (clippy::ptr_arg) 2020-12-30 13:11:52 +01:00
Ralf Jung
95aed7ab3b Miri: make size/align_of_val work for dangling raw ptrs 2020-12-29 22:46:17 +01:00
Vadim Petrochenkov
4d2d0bad4e Remove compile-fail test suite 2020-12-29 23:39:56 +03:00
Ralf Jung
51cec58040 fix a comment 2020-12-29 16:32:38 +01:00
bors
e2a2592885 Auto merge of #79084 - simonvandel:instcombine-perf, r=oli-obk
Small perf changes for InstCombine
2020-12-29 06:21:18 +00:00
Ralf Jung
4a90a58c34 make more matches exhaustive 2020-12-28 23:29:16 +01:00
Simon Vandel Sillesen
0010fc8fec use exhaustive pattern match to prevent future bugs 2020-12-28 23:19:35 +01:00
Ralf Jung
c177e68015 merge two match'es for more exhaustiveness 2020-12-28 22:44:04 +01:00
Ralf Jung
122e91c4fb promotion: factor some common code into validate_ref 2020-12-28 22:09:08 +01:00
Albin Hedman
1b77f8e6ea Constify intrinsics::copy[_nonoverlapping] 2020-12-26 02:22:29 +01:00
bors
bb178237c5 Auto merge of #80235 - RalfJung:validate-promoteds, r=oli-obk
validate promoteds

Turn on const-value validation for promoteds. This is made possible now that https://github.com/rust-lang/rust/issues/67534 is resolved.

I don't think this is a breaking change. We don't promote any unsafe operation any more (since https://github.com/rust-lang/rust/pull/77526 landed). We *do* promote `const fn` calls under some circumstances (in `const`/`static` initializers), but union field access and similar operations are not allowed in `const fn`. So now is a perfect time to add this check. :D

r? `@oli-obk`
Fixes https://github.com/rust-lang/rust/issues/67465
2020-12-25 18:25:48 +00:00
bors
9a40539c38 Auto merge of #80364 - Dylan-DPC:rollup-0y96okz, r=Dylan-DPC
Rollup of 11 pull requests

Successful merges:

 - #79213 (Stabilize `core::slice::fill`)
 - #79999 (Refactored verbose print into a function)
 - #80160 (Implemented a compiler diagnostic for move async mistake)
 - #80274 (Rename rustc_middle::lint::LintSource)
 - #80280 (Add installation commands to `x` tool README)
 - #80319 (Fix elided lifetimes shown as `'_` on async functions)
 - #80327 (Updated the match with the matches macro)
 - #80330 (Fix typo in simplify_try.rs)
 - #80340 (Don't unnecessarily override attrs for Module)
 - #80342 (Fix typo)
 - #80352 (BTreeMap: make test cases more explicit on failure)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2020-12-25 05:23:24 +00:00
Dylan DPC
704f81e3cb
Rollup merge of #80330 - eltociear:patch-2, r=lcnr
Fix typo in simplify_try.rs

assigment -> assignment
2020-12-25 03:39:46 +01:00
Dylan DPC
787b016957
Rollup merge of #79999 - hencrice:yenlinc/79799, r=oli-obk
Refactored verbose print into a function

Also handle Tuple and Array separately, which was not explicitly checked.

Fixes #79799.
2020-12-25 03:39:33 +01:00
bors
cae1f4ddf2 Auto merge of #79762 - Swatinem:remap-doctest-coverage, r=Swatinem
Remap instrument-coverage line numbers in doctests

This uses the `SourceMap::doctest_offset_line` method to re-map line
numbers from doctests. Remapping columns is not yet done, and rustdoc
still does not output the correct filename when running doctests in a
workspace.

Part of #79417 although I dont consider that fixed until both filenames
and columns are mapped correctly.

r? `@richkadel`

I might jump on zulip the comming days. Still need to figure out how to properly write tests for this, and deal with other doctest issues in the meantime.
2020-12-25 02:37:08 +00:00
bors
c34c015fe2 Auto merge of #77692 - PankajChaudhary5:issue-76630, r=davidtwco
Added better error message for shared borrow treated as unique for purposes of lifetimes

Part of Issue #76630

r? `@jyn514`
2020-12-24 07:32:19 +00:00
Yenlin Chen
ecba49c1bd Fixed formatting 2020-12-23 19:10:59 +00:00
Yenlin Chen
f459b0fea5 Addressed feedbacks
Also updated the mir-opt test output files.
2020-12-23 18:55:37 +00:00
Ikko Ashimine
87397080b6
Fix typo in simplify_try.rs
assigment -> assignment
2020-12-23 21:11:59 +09:00
bors
11c94a1977 Auto merge of #79270 - RalfJung:array-repeat-consts, r=oli-obk
Acknowledge that `[CONST; N]` is stable

When `const_in_array_repeat_expressions` (RFC 2203) got unstably implemented as part of https://github.com/rust-lang/rust/pull/61749, accidentally, the special case of repeating a *constant* got stabilized immediately. That is why the following code works on stable:

```rust
const EMPTY: Vec<i32> = Vec::new();

pub const fn bar() -> [Vec<i32>; 2] {
    [EMPTY; 2]
}

fn main() {
    let x = bar();
}
```

In contrast, if we had written `[expr; 2]` for some expression that is not *literally* a constant but could be evaluated at compile-time (e.g. `(EMPTY,).0`), this would have failed.

We could take back this stabilization as it was clearly accidental. However, I propose we instead just officially accept this and stabilize a small subset of RFC 2203, while leaving the more complex case of general expressions that could be evaluated at compile-time unstable. Making that case work well is pretty much blocked on inline `const` expressions (to avoid relying too much on [implicit promotion](https://github.com/rust-lang/const-eval/blob/master/promotion.md)), so it could take a bit until it comes to full fruition. `[CONST; N]` is an uncontroversial subset of this feature that has no semantic ambiguities, does not rely on promotion, and basically provides the full expressive power of RFC 2203 but without the convenience (people have to define constants to repeat them, possibly using associated consts if generics are involved).

Well, I said "no semantic ambiguities", that is only almost true... the one point I am not sure about is `[CONST; 0]`. There are two possible behaviors here: either this is equivalent to `let x = CONST; [x; 0]`, or it is a NOP (if we argue that the constant is never actually instantiated). The difference between the two is that if `CONST` has a destructor, it should run in the former case (but currently doesn't, due to https://github.com/rust-lang/rust/issues/74836); but should not run if it is considered a NOP. For regular `[x; 0]` there seems to be consensus on running drop (there isn't really an alternative); any opinions for the `CONST` special case? Should this instantiate the const only to immediately run its destructors? That seems somewhat silly to me. After all, the `let`-expansion does *not* work in general, for `N > 1`.

Cc `@rust-lang/lang` `@rust-lang/wg-const-eval`
Cc https://github.com/rust-lang/rust/issues/49147
2020-12-21 13:12:36 +00:00
Dylan DPC
000c51611c
Rollup merge of #80199 - RalfJung:const-fake, r=oli-obk
also const-check FakeRead

We need to const-check all statements, including `FakeRead`, to avoid issues like https://github.com/rust-lang/rust/issues/77694.

Fixes https://github.com/rust-lang/rust/issues/77694.
r? ``@oli-obk``
2020-12-21 02:47:42 +01:00
Ralf Jung
97cae9c555 promoteds in statics may refer to statics 2020-12-20 19:34:29 +01:00
Ralf Jung
06ca7b700c validate promoteds 2020-12-20 15:54:20 +01:00
Ralf Jung
54a3ed3114 use exhaustive match for checking Rvalue::Repeat 2020-12-20 15:15:28 +01:00
bors
b1964e60b7 Auto merge of #80163 - jackh726:binder-refactor-part-3, r=lcnr
Make BoundRegion have a kind of BoungRegionKind

Split from #76814

Also includes making `replace_escaping_bound_vars` only return `T`

Going to r? `@lcnr`
Feel free to reassign
2020-12-20 07:01:00 +00:00
Ralf Jung
f4085f0d3a also const-check FakeRead 2020-12-19 20:52:24 +01:00
Arpad Borsos
830ceaa419 Remap instrument-coverage line numbers in doctests
This uses the `SourceMap::doctest_offset_line` method to re-map line
numbers from doctests. Remapping columns is not yet done.

Part of issue #79417.
2020-12-19 13:22:24 +01:00
Yuki Okushi
6b52475c68
Rollup merge of #80133 - Aaron1011:fix/const-mut-deref, r=estebank
Suppress `CONST_ITEM_MUTATION` lint if a dereference occurs anywhere

Fixes #79971
2020-12-19 15:16:08 +09:00
Jack Huey
328fcee4af Make BoundRegion have a kind of BoungRegionKind 2020-12-18 15:27:28 -05:00
Joshua Nelson
35f16c60e7 Switch compiler/ to intra-doc links
rustc_lint and rustc_lint_defs weren't switched because they're included
in the compiler book and so can't use intra-doc links.
2020-12-18 15:22:51 -05:00
Dylan DPC
720b6941df
Rollup merge of #78164 - Aaron1011:fix/async-region-name, r=tmandry
Prefer regions with an `external_name` in `approx_universal_upper_bound`

Fixes #75785

When displaying a MIR borrowcheck error, we may need to find an upper
bound for a region, which gives us a region to point to in the error
message. However, a region might outlive multiple distinct universal
regions, in which case the only upper bound is 'static

To try to display a meaningful error message, we compute an
'approximate' upper bound by picking one of the universal regions.
Currently, we pick the region with the lowest index - however, this
caused us to produce a suboptimal error message in issue #75785

This PR `approx_universal_upper_bound` to prefer regions with an
`external_name`. This causes us to prefer regions from function
arguments/upvars, which seems to lead to a nicer error message in some
cases.
2020-12-18 00:30:09 +01:00
Aaron Hill
dea13632a8
Suppress CONST_ITEM_MUTATION lint if a dereference occurs anywhere
Fixes #79971
2020-12-17 15:25:55 -05:00
Aaron Hill
419d3ae028
Prefer regions with an external_name in approx_universal_upper_bound
Fixes #75785

When displaying a MIR borrowcheck error, we may need to find an upper
bound for a region, which gives us a region to point to in the error
message. However, a region might outlive multiple distinct universal
regions, in which case the only upper bound is 'static

To try to display a meaningful error message, we compute an
'approximate' upper bound by picking one of the universal regions.
Currently, we pick the region with the lowest index - however, this
caused us to produce a suboptimal error message in issue #75785

This PR `approx_universal_upper_bound` to prefer regions with an
`external_name`. This causes us to prefer regions from function
arguments/upvars, which seems to lead to a nicer error message in some
cases.
2020-12-17 13:24:40 -05:00
bors
eb4fc71dc9 Auto merge of #79945 - jackh726:existential_trait_ref, r=nikomatsakis
Move binder for dyn to each list item

This essentially changes `ty::Binder<&'tcx List<ExistentialTraitRef>>` to `&'tcx List<ty::Binder<ExistentialTraitRef>>`.

This is a first step in moving the `dyn Trait` representation closer to Chalk, which we've talked about in `@rust-lang/wg-traits.`

r? `@nikomatsakis`
2020-12-17 18:21:20 +00:00
bors
caeb3335c0 Auto merge of #80114 - GuillaumeGomez:rollup-gszr5kn, r=GuillaumeGomez
Rollup of 5 pull requests

Successful merges:

 - #80006 (BTreeMap: more expressive local variables in merge)
 - #80022 (BTreeSet: simplify implementation of pop_first/pop_last)
 - #80035 (Optimization for bool's PartialOrd impl)
 - #80040 (Always run intrinsics lowering pass)
 - #80047 (Use more symbols in rustdoc)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2020-12-17 12:02:29 +00:00
Guillaume Gomez
1f5d8de062
Rollup merge of #80040 - tmiasko:always-lower-intrinsics, r=Dylan-DPC
Always run intrinsics lowering pass

Move intrinsics lowering pass from the optimization phase (where it
would not run if -Zmir-opt-level=0), to the drop lowering phase where it
runs unconditionally.

The implementation of those intrinsics in code generation and
interpreter is unnecessary. Remove it.
2020-12-17 11:36:52 +01:00
bors
001bd7762c Auto merge of #79840 - dvtkrlbs:issue-79667, r=oli-obk
Remove memoization leftovers from constant evaluation machine

Closes #79667
2020-12-17 09:11:28 +00:00
Yuki Okushi
a5b1d2252f
Rollup merge of #80072 - richkadel:llvm-coverage-counters-2.2.1, r=tmandry
Fixed conflict with drop elaboration and coverage

See
https://github.com/rust-lang/rust/issues/80045#issuecomment-745733339

Coverage statements are moved to the beginning of the BCB. This does
also affect what's counted before a panic, changing some results, but I
think these results may even be preferred? In any case, there are no
guarantees about what's counted when a panic occurs (by design).

r? `@tmandry`

FYI `@wesleywiser` `@ecstatic-morse`
2020-12-17 11:44:06 +09:00
Yuki Okushi
a611f8dbfc
Rollup merge of #79882 - wecing:master, r=oli-obk
Fix issue #78496

EarlyOtherwiseBranch finds MIR structures like:

```
bb0: {
  ...
  _2 = discriminant(X)
  ...
  switchInt(_2) -> [1_isize: bb1, otherwise: bb3]
}
bb1: {
  ...
  _3 = discriminant(Y)
  ...
  switchInt(_3) -> [1_isize: bb2, otherwise: bb3]
}
bb2: {...}
bb3: {...}
```

And transforms them into something like:

```
bb0: {
  ...
  _2 = discriminant(X)
  _3 = discriminant(Y)
  _4 = Eq(_2, _3)
  switchInt(_4) -> [true: bb4, otherwise: bb3]
}
bb2: {...} // unchanged
bb3: {...} // unchanged
bb4: {
  switchInt(_2) -> [1_isize: bb2, otherwise: bb3]
}
```

But that is not always a safe thing to do -- sometimes the early `otherwise` branch is necessary so the later block could assume the value of `discriminant(X)`.

I am not totally sure what's the best way to detect that, but fixing #78496 should be easy -- we just check if `X` is a sub-expression of `Y`. A more precise test might be to check if `Y` contains a `Downcast(1)` of `X`, but I think this might be good enough.

Fix #78496
2020-12-17 11:43:59 +09:00
Rich Kadel
1d6b455fb4 Fixed conflict with drop elaboration and coverage
See
https://github.com/rust-lang/rust/issues/80045#issuecomment-745733339

Coverage statements are moved to the beginning of the BCB. This does
also affect what's counted before a panic, changing some results, but I
think these results may even be preferred? In any case, there are no
guarantees about what's counted when a panic occurs (by design).
2020-12-15 23:33:47 -08:00
bors
4031f7b0a8 Auto merge of #78399 - vn-ki:gsgdt-graphviz, r=oli-obk
make MIR graphviz generation use gsgdt

gsgdt [https://crates.io/crates/gsgdt] is a crate which provides an
interface for stringly typed graphs. It also provides generation of
graphviz dot format from said graph.

This is the first in a series of PRs on moving graphviz code out of rustc into normal crates and then implementating graph diffing on top of these crates.

r? `@oli-obk`
2020-12-15 22:00:02 +00:00
Guillaume Gomez
5de0c5f63f
Rollup merge of #79958 - richkadel:llvm-coverage-counters-2.2.0, r=tmandry
Fixes reported bugs in Rust Coverage

Fixes: #79569

Fixes: #79566
Fixes: #79565

For the first issue (#79569), I got hit a `debug_assert!()` before
encountering the reported error message (because I have `debug = true`
enabled in my config.toml).

The assertion showed me that some `SwitchInt`s can have more than one
target pointing to the same `BasicBlock`.

I had thought that was invalid, but since it seems to be possible, I'm
allowing this now.

I added a new test for this.

----

In the last two cases above, both tests (intentionally) fail to compile,
but the `InstrumentCoverage` pass is invoked anyway.

The MIR starts with an `Unreachable` `BasicBlock`, which I hadn't
encountered before. (I had assumed the `InstrumentCoverage` pass
would only be invoked with MIRs from successful compilations.)

I don't have test infrastructure set up to test coverage on files that
fail to compile, so I didn't add a new test.

r? `@tmandry`
FYI: `@wesleywiser`
2020-12-15 16:43:23 +01:00
bors
99baddb57c Auto merge of #78068 - RalfJung:union-safe-assign, r=nikomatsakis
consider assignments of union field of ManuallyDrop type safe

Assigning to `Copy` union fields is safe because that assignment will never drop anything. However, with https://github.com/rust-lang/rust/pull/77547, unions may also have `ManuallyDrop` fields, and their assignments are currently still unsafe. That seems unnecessary though, as assigning `ManuallyDrop` does not drop anything either, and is thus safe even for union fields.

I assume this will at least require FCP.
2020-12-15 11:31:03 +00:00
bors
e99a89c7c0 Auto merge of #73210 - wesleywiser:consts_in_debuginfo, r=oli-obk
[mir-opt] Allow debuginfo to be generated for a constant or a Place

Prior to this commit, debuginfo was always generated by mapping a name
to a Place. This has the side-effect that `SimplifyLocals` cannot remove
locals that are only used for debuginfo because their other uses have
been const-propagated.

To allow these locals to be removed, we now allow debuginfo to point to
a constant value. The `ConstProp` pass detects when debuginfo points to
a local with a known constant value and replaces it with the value. This
allows the later `SimplifyLocals` pass to remove the local.
2020-12-15 08:46:00 +00:00
bors
5d77fc8d0d Auto merge of #79922 - tmiasko:lower-discriminant, r=nagisa
Lower `discriminant_value` intrinsic

This allows const propagation to evaluate comparisons involving
field-less enums using derived implementations of `PartialEq` (after
inlining `eq`).
2020-12-15 01:56:25 +00:00
Rich Kadel
36c639a2ce Convenience funcs for some_option.unwrap_or(...)
This ensures consistent handling of default values for options that are
None if not specified on the command line.
2020-12-14 17:27:27 -08:00
Wesley Wiser
0b18ed833c Disable the constant debuginfo promotion pass by default
It doesn't work correctly on *-pc-windows-gnu
2020-12-14 19:56:10 -05:00
Tomasz Miąsko
a9ff4bd838 Always run intrinsics lowering pass
Move intrinsics lowering pass from the optimization phase (where it
would not run if -Zmir-opt-level=0), to the drop lowering phase where it
runs unconditionally.

The implementation of those intrinsics in code generation and
interpreter is unnecessary. Remove it.
2020-12-15 00:00:00 +00:00
Rich Kadel
4f550f1f93 Improve warnings on incompatible options involving -Zinstrument-coverage
Adds checks for:

* `no_core` attribute
* explicitly-enabled `legacy` symbol mangling
* mir_opt_level > 1 (which enables inlining)

I removed code from the `Inline` MIR pass that forcibly disabled
inlining if `-Zinstrument-coverage` was set. The default `mir_opt_level`
does not enable inlining anyway. But if the level is explicitly set and
is greater than 1, I issue a warning.

The new warnings show up in tests, which is much better for diagnosing
potential option conflicts in these cases.
2020-12-14 12:55:46 -08:00
Yenlin Chen
b66eb696af Refactored verbose print into a function
Also handle Tuple and Array separately, which was not explicitly checked.

Fixes #79799.
2020-12-13 04:49:22 +00:00
Yuki Okushi
424e44af00
Rollup merge of #79984 - Nadrieril:remove-unused-dep, r=jyn514
Remove an unused dependency that made `rustdoc` crash

Whilst struggling with https://github.com/rust-lang/rust/issues/79980 I discovered that this dependency was unused, and that made rustdoc crash. This PR removes it.
2020-12-13 11:05:47 +09:00
Yuki Okushi
2b43980ef4
Rollup merge of #79942 - JCTyblaidd:static-mem-init, r=RalfJung
Add post-init hook for static memory for miri.

Adds a post-initialization hook to treat memory initialized using the interpreter as if it was initialized in a static context.

See: https://github.com/rust-lang/miri/pull/1644 & https://github.com/rust-lang/miri/issues/1643
2020-12-13 11:05:38 +09:00
Yuki Okushi
1b81f08d4c
Rollup merge of #79940 - matthiaskrgr:cl15ppy, r=Dylan-DPC
fix more clippy::complexity findings

fix clippy::unnecessary_filter_map
use if let Some(x) = ..  instead of ...map(|x|) to conditionally run fns that return () (clippy::option_map_unit_fn)
fix clippy::{needless_bool, manual_unwrap_or}
don't clone types that are copy (clippy::clone_on_copy)
don't convert types into identical types with .into() (clippy::useless_conversion)
use strip_prefix over slicing (clippy::manual_strip)

r? ``@Dylan-DPC``
2020-12-13 11:05:36 +09:00
Nadrieril
600efe7f10 Remove an unused dependency that made rustdoc crash 2020-12-12 22:13:03 +00:00
Rich Kadel
eb963ffe45 Fixes reported bugs in Rust Coverage
Fixes: #79569

Fixes: #79566
Fixes: #79565

For the first issue (#79569), I got hit a `debug_assert!()` before
encountering the reported error message (because I have `debug = true`
enabled in my config.toml).

The assertion showed me that some `SwitchInt`s can have more than one
target pointing to the same `BasicBlock`.

I had thought that was invalid, but since it seems to be possible, I'm
allowing this now.

I added a new test for this.

----

In the last two cases above, both tests (intentionally) fail to compile,
but the `InstrumentCoverage` pass is invoked anyway.

The MIR starts with an `Unreachable` `BasicBlock`, which I hadn't
encountered before. (I had assumed the `InstrumentCoverage` pass
would only be invoked with MIRs from successful compilations.)

I don't have test infrastructure set up to test coverage on files that
fail to compile, so I didn't add a new test.
2020-12-11 21:40:22 -08:00
bors
602899cd01 Auto merge of #79931 - RalfJung:no-redundant-storage-live, r=oli-obk
make redundant StorageLive UB

The interesting behavior of StorageLive in loops (https://github.com/rust-lang/rust/issues/42371) has been fixed, so we can now finally make it a hard error to mark a local as live that is already live. :)

r? `@oli-obk`
Fixes https://github.com/rust-lang/rust/issues/42371
2020-12-12 02:40:17 +00:00
bors
5bd9b60333 Auto merge of #79553 - sexxi-goose:mir_min_cap_writeback, r=nikomatsakis
Capture precise paths in THIR and MIR

This PR allows THIR and MIR to use the result of the new capture analysis to actually capture precise paths

To achieve we:
- Writeback min capture results to TypeckResults
- Move handling upvars to PlaceBuilder in mir_build
- Lower precise paths in THIR build by reading min_captures
- Search for ancestors in min_capture when trying to build a MIR place which starts off of an upvar

Closes: https://github.com/rust-lang/project-rfc-2229/issues/10

Partly implements: rust-lang/project-rfc-2229#18

Work that remains (not in this PR):
- [ ] [Known bugs when feature gate is enabled](https://github.com/rust-lang/project-rfc-2229/projects/1?card_filter_query=label%3Abug)
- [ ] Use min_capure_map for
  - [ ] Liveness analysis
  - [ ] rustc_mir/interpret/validity.rs
  - [ ] regionck
- [ ] rust-lang/project-rfc-2229#8
- [ ] remove closure_captures and upvar_capture_map

r? `@ghost`
2020-12-12 00:23:29 +00:00
Matthias Krüger
b7795e135a fix clippy::{needless_bool, manual_unwrap_or} 2020-12-11 23:02:19 +01:00
Matthias Krüger
db6c50998c don't clone types that are copy (clippy::clone_on_copy) 2020-12-11 23:02:19 +01:00
Matthias Krüger
82fe5c1662 don't convert types into identical types with .into() (clippy::useless_conversion) 2020-12-11 23:02:19 +01:00
Jack Huey
ed80815bf2 Move binder for dyn to each list item 2020-12-11 15:02:46 -05:00
JCTyblaidd
175226a01c Rustfmt 2020-12-11 19:28:20 +00:00
JCTyblaidd
6ce29906f1
Fix rustfmt failure 2020-12-11 19:11:39 +00:00
JCTyblaidd
56d89364a5 Add post-initialization hook for static memory initialized using the interpereter. 2020-12-11 18:42:36 +00:00
Tunahan Karlibas
a03feaae55
add missing constraints 2020-12-11 18:59:29 +03:00
bors
a9f7d19a91 Auto merge of #79910 - RalfJung:abort-msg, r=oli-obk
CTFE: tweak abort-on-uninhabited message

Having an "aborted execution:" makes it more consistent with the `Abort` terminator saying "the program aborted execution". Right now, at least one of the two errors will look weird in Miri.

r? `@oli-obk`
2020-12-11 12:30:05 +00:00
Ralf Jung
78deacc2ec make redundant StorageLive UB 2020-12-11 13:18:44 +01:00
Tyler Mandry
17ec4b8258
Rollup merge of #79809 - Eric-Arellano:split-once, r=matklad
Dogfood `str_split_once()`

Part of https://github.com/rust-lang/rust/issues/74773.

Beyond increased clarity, this fixes some instances of a common confusion with how `splitn(2)` behaves: the first element will always be `Some()`, regardless of the delimiter, and even if the value is empty.

Given this code:

```rust
fn main() {
    let val = "...";
    let mut iter = val.splitn(2, '=');
    println!("Input: {:?}, first: {:?}, second: {:?}", val, iter.next(), iter.next());
}
```

We get:

```
Input: "no_delimiter", first: Some("no_delimiter"), second: None
Input: "k=v", first: Some("k"), second: Some("v")
Input: "=", first: Some(""), second: Some("")
```

Using `str_split_once()` makes more clear what happens when the delimiter is not found.
2020-12-10 21:33:08 -08:00
Tomasz Miąsko
686237c49a Lower discriminant_value intrinsic
This allows const propagation to evaluate comparisons involving
field-less enums using derived implementations of `PartialEq` (after
inlining `eq`).
2020-12-11 03:25:40 +01:00
Tunahan Karlibas
b6f7eef946
Remove unnecessary check and fix local_def_id parameter 2020-12-11 01:59:05 +03:00
Ralf Jung
2443f642e3 CTFE: tweak abort-on-uninhabited message 2020-12-10 19:59:31 +01:00
bors
39b841dfe3 Auto merge of #79621 - usbalbin:constier_maybe_uninit, r=RalfJung
Constier maybe uninit

I was playing around trying to make `[T; N]::zip()` in #79451 be `const fn`. One of the things I bumped into was `MaybeUninit::assume_init`. Is there any reason for the intrinsic `assert_inhabited<T>()` and therefore `MaybeUninit::assume_init` not being `const`?

---

I have as best as I could tried to follow the instruction in [library/core/src/intrinsics.rs](https://github.com/rust-lang/rust/blob/master/library/core/src/intrinsics.rs#L11). I have no idea what I am doing but it seems to compile after some slight changes after the copy paste. Is this anywhere near how this should be done?

Also any ideas for name of the feature gate? I guess `const_maybe_assume_init` is quite misleading since I have added some more methods. Should I add test? If so what should be tested?
2020-12-10 10:46:38 +00:00
Chenguang Wang
78c0680b3f update comments 2020-12-09 19:50:11 -08:00
Aman Arora
237ad12698 Use closure_min_captures in borrow checker
- Use closure_min_captures to generate the Upvar structure that
  stores information for diagnostics and information about
  mutability of captures.
2020-12-09 22:34:15 -05:00
Chenguang Wang
c6f2d49ff8 fix issue #78496 2020-12-09 18:56:27 -08:00
Tyler Mandry
3b49a46c6b Rollup merge of #79818 - richkadel:llvm-coverage-counters-2.1.0, r=tmandry
Fixes to Rust coverage

Fixes: #79725

Some macros can create a situation where `fn_sig_span` and `body_span`
map to different files.

New documentation on coverage tests incorrectly assumed multiple test
binaries could just be listed at the end of the `llvm-cov` command,
but it turns out each binary needs a `--object` prefix.

This PR fixes the bug and updates the documentation to correct that
issue. It also fixes a few other minor issues in internal implementation
comments, and adds documentation on getting coverage results for doc
tests.
2020-12-09 13:38:27 -08:00
Tyler Mandry
d95948c6d3
Rollup merge of #79732 - matthiaskrgr:cl12ppy, r=Dylan-DPC
minor stylistic clippy cleanups

simplify if let Some(_) = x  to  if x.is_some()  (clippy::redundant_pattern_matching)
don't create owned values for comparison (clippy::cmp_owned)
use .contains() or .any() instead of find(x).is_some() (clippy::search_is_some)
don't wrap code block in Ok()  (clipppy::unit_arg)
2020-12-09 13:38:12 -08:00
Tunahan Karlibas
de1cd4b36d
Extra assertions in eval_body_using_ecx to disallow queries for
functions that does allocations
2020-12-09 14:53:35 +03:00
bors
cc03ee6702 Auto merge of #78679 - oli-obk:temp_lifetime, r=eddyb
Also generate `StorageDead` in constants

r? `@eddyb`

None of this special casing is actually necessary since we started promoting within constants and statics.

We may want to keep some of it around out of perf reasons, but it's not required for user visible behaviour

somewhat related: #68622
2020-12-09 11:31:32 +00:00
oli
84fe7cf24e Also generate StorageDead in constants 2020-12-09 10:59:10 +00:00
bors
c0bfe3485f Auto merge of #78363 - RalfJung:promotion, r=oli-obk
remove this weird special case from promotion

Promotion has a special case to ignore interior mutability under some specific circumstances. The purpose of this PR is to figure out what changes if we remove that. Since `Cell::new` and friends only get promoted inside `const`/`static` initializers these days, it actually is not easy to exploit this case: you need something like
```rust
const TEST_INTERIOR_MUT: () = {
    // The "0." case is already ruled out by not permitting any interior mutability in `const`.
    let _val: &'static _ = &(Cell::new(1), 2).1;
};
```

I assume something like `&Some(&(Cell::new(1), 2).1)` would hit the nested case inside `validate_rvalue`... though I am not sure why that would not just trigger nested promotion, first promoting the inner reference and then the outer one?

Fixes https://github.com/rust-lang/rust/issues/67534 (by simply rejecting that code^^)

r? `@oli-obk` (but for now this is not meant to be merged!)
Cc `@rust-lang/wg-const-eval`
2020-12-09 09:13:54 +00:00
Ralf Jung
99a44ed086 remove a hack that seems to only benefit a few very special cases 2020-12-09 09:46:22 +01:00
Tunahan Karlibas
7cb74ed191
Remove memoization leftovers
closes #79667
2020-12-09 01:17:02 +03:00
Eric Arellano
989edf4a5f Review feedback
* Use a match statement.
* Clarify why we can't use `file_stem()`.
* Error if the `:` is missing for Tidy error codes, rather than no-oping.
2020-12-08 12:51:00 -07:00
Matthias Krüger
0fa461558c use .contains() or .any() instead of find(x).is_some() (clippy::search_is_some) 2020-12-08 20:27:48 +01:00
Rich Kadel
95c268f64d Fixes to Rust coverage
Fixes: #79725

Some macros can create a situation where `fn_sig_span` and `body_span`
map to different files.

New documentation on coverage tests incorrectly assumed multiple test
binaries could just be listed at the end of the `llvm-cov` command,
but it turns out each binary needs a `--object` prefix.

This PR fixes the bug and updates the documentation to correct that
issue. It also fixes a few other minor issues in internal implementation
comments, and adds documentation on getting coverage results for doc
tests.
2020-12-07 17:56:19 -08:00
Eric Arellano
12db2225b6 Dogfood 'str_split_once() with compiler/ 2020-12-07 12:48:44 -07:00
Albin Hedman
bdda98aaba
Add comment for assert_inhabited in compiler/rustc_mir/src/interpret/intrinsics.rs
Co-authored-by: Ralf Jung <post@ralfj.de>
2020-12-07 18:59:10 +01:00
Bastian Kauschke
e3e4870bce small TypeVisitor refactor 2020-12-07 15:52:59 +01:00
Wesley Wiser
01aec8d185 [mir-opt] Allow debuginfo to be generated for a constant or a Place
Prior to this commit, debuginfo was always generated by mapping a name
to a Place. This has the side-effect that `SimplifyLocals` cannot remove
locals that are only used for debuginfo because their other uses have
been const-propagated.

To allow these locals to be removed, we now allow debuginfo to point to
a constant value. The `ConstProp` pass detects when debuginfo points to
a local with a known constant value and replaces it with the value. This
allows the later `SimplifyLocals` pass to remove the local.
2020-12-06 20:48:25 -05:00
Albin Hedman
345f230df9 Fix comments related to abort() 2020-12-06 20:25:13 +01:00
Albin Hedman
7bd754cf8c Fix tests (hopefully) 2020-12-05 18:39:10 +01:00
Albin Hedman
d366ed2730 abort() now takes a msg parameter 2020-12-05 17:32:19 +01:00
bors
e9dd18ca74 Auto merge of #79686 - Dylan-DPC:rollup-leama5f, r=Dylan-DPC
Rollup of 11 pull requests

Successful merges:

 - #77686 (Render Markdown in search results)
 - #79541 (Doc keyword lint pass)
 - #79602 (Fix SGX CI)
 - #79611 (Use more std:: instead of core:: in docs for consistency)
 - #79623 (Pass around Symbols instead of Idents in doctree)
 - #79627 (Update cargo)
 - #79631 (disable a ptr equality test on Miri)
 - #79638 (Use `item_name` instead of pretty printing for resolving `Self` on intra-doc links)
 - #79646 (rustc_metadata: Remove some dead code)
 - #79664 (move interpret::MemoryKind::Heap to const eval)
 - #79678 (Fix some clippy lints)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2020-12-04 04:51:49 +00:00
Rich Kadel
d96f351fa3 Addressed feedback from 2020-12-01
Added one more test (two files) showing coverage of generics and unused
functions across crates.

Created and referenced new Issues, as requested.

Added comments.

Added a note about the possible effects of compiler options on LLVM
coverage maps.
2020-12-03 09:50:10 -08:00
Rich Kadel
def932ca86 Combination of commits
Fixes multiple issue with counters, with simplification

  Includes a change to the implicit else span in ast_lowering, so coverage
  of the implicit else no longer spans the `then` block.

  Adds coverage for unused closures and async function bodies.

  Fixes: #78542

Adding unreachable regions for known MIR missing from coverage map

Cleaned up PR commits, and removed link-dead-code requirement and tests

  Coverage no longer depends on Issue #76038 (`-C link-dead-code` is
  no longer needed or enforced, so MSVC can use the same tests as
  Linux and MacOS now)

Restrict adding unreachable regions to covered files

  Improved the code that adds coverage for uncalled functions (with MIR
  but not-codegenned) to avoid generating coverage in files not already
  included in the files with covered functions.

Resolved last known issue requiring --emit llvm-ir workaround

  Fixed bugs in how unreachable code spans were added.
2020-12-03 09:50:10 -08:00