Commit graph

132202 commits

Author SHA1 Message Date
bors 36a74944cb Auto merge of #77526 - RalfJung:dont-promote-unions, r=lcnr
stop promoting union field accesses in 'const'

Turns out that promotion of union field accesses is the only difference between "promotion in `const`/`static` bodies" and "explicit promotion". So if we can remove this, we have finally achieved what I thought to already be the case -- that the bodies of `const`/`static` initializers behave the same as explicit promotion contexts.

The reason we do not want to promote union field accesses is that they can introduce UB, i.e., they can go wrong. We want to [minimize the ways promoteds can fail to evaluate](https://github.com/rust-lang/const-eval/issues/53). Also this change makes things more consistent overall, removing a special case that was added without much consideration (as far as I can tell).

Cc `@rust-lang/wg-const-eval`
2020-10-25 02:27:09 +00:00
Yuki Okushi 7b4c397b73 Do not try to report on closures to avoid ICE 2020-10-25 11:19:49 +09:00
bors 7c533c89b3 Auto merge of #78310 - ebroto:clippyup, r=Manishearth
Update Clippy

Biweekly Clippy update.

This includes a Cargo.lock update: [ca11eeb ](ca11eeb563) (should be rollup=never)

r? `@Manishearth`
2020-10-25 00:24:49 +00:00
Olivia Crain cc468c0829 Use check-pass in single-use-lifetime ui test suite 2020-10-24 19:22:53 -05:00
bors f58ffc9381 Auto merge of #78334 - jonas-schievink:rollup-z0gzbmm, r=jonas-schievink
Rollup of 12 pull requests

Successful merges:

 - #75115 (`#[deny(unsafe_op_in_unsafe_fn)]` in sys/cloudabi)
 - #76614 (change the order of type arguments on ControlFlow)
 - #77610 (revise Hermit's mutex interface to support the behaviour of StaticMutex)
 - #77830 (Simplify query proc-macros)
 - #77930 (Do not ICE with TraitPredicates containing [type error])
 - #78069 (Fix const core::panic!(non_literal_str).)
 - #78072 (Cleanup constant matching in exhaustiveness checking)
 - #78119 (Throw core::panic!("message") as &str instead of String.)
 - #78191 (Introduce a temporary for discriminant value in MatchBranchSimplification)
 - #78272 (const_evaluatable_checked: deal with unused nodes + div)
 - #78318 (TyCtxt: generate single impl block with `slice_interners` macro)
 - #78327 (resolve: Relax macro resolution consistency check to account for any errors)

Failed merges:

r? `@ghost`
2020-10-24 21:42:39 +00:00
Eduardo Broto a513919602 Add unbounded_depth to serde_json (clippy-driver) 2020-10-24 22:59:44 +02:00
Jonas Schievink 58ae889779
Rollup merge of #78327 - petrochenkov:inconsist, r=Aaron1011
resolve: Relax macro resolution consistency check to account for any errors

The check was previously omitted only when ambiguity errors or `Res::Err` were encountered, but the "macro-expanded `extern crate` items cannot shadow..." error (at least) can cause same inconsistencies as well.

Fixes https://github.com/rust-lang/rust/issues/78325
2020-10-24 22:40:00 +02:00
Jonas Schievink a8ff5a4e03
Rollup merge of #78318 - bugadani:tyctx-impl, r=petrochenkov
TyCtxt: generate single impl block with `slice_interners` macro

Reduces the work needed to check overlapping impls a bit.
2020-10-24 22:39:59 +02:00
Jonas Schievink 5ed8ac45d4
Rollup merge of #78272 - lcnr:abstract-const-unused-node, r=oli-obk
const_evaluatable_checked: deal with unused nodes + div

r? @oli-obk
2020-10-24 22:39:57 +02:00
Jonas Schievink 597b4c5bb4
Rollup merge of #78191 - tmiasko:temp-match-branch-simplification, r=oli-obk
Introduce a temporary for discriminant value in MatchBranchSimplification

The optimization introduces additional uses of the discriminant operand, but
does not ensure that it is still valid to evaluate it or that it still
evaluates to the same value.

Evaluate it once at original position, and store the result in a new temporary.

Follow up on #78151. The optimization remains disabled by default.

Closes #78239.
2020-10-24 22:39:55 +02:00
Jonas Schievink e3808edeee
Rollup merge of #78119 - fusion-engineering-forks:panic-use-as-str, r=Amanieu
Throw core::panic!("message") as &str instead of String.

This makes `core::panic!("message")` consistent with `std::panic!("message")`, which throws a `&str` and not a `String`.

This also makes any other panics from `core::panicking::panic` result in a `&str` rather than a `String`, which includes compiler-generated panics such as the panics generated for `mem::zeroed()`.

---

Demonstration:

```rust
use std::panic;
use std::any::Any;

fn main() {
    panic::set_hook(Box::new(|panic_info| check(panic_info.payload())));

    check(&*panic::catch_unwind(|| core::panic!("core")).unwrap_err());
    check(&*panic::catch_unwind(|| std::panic!("std")).unwrap_err());
}

fn check(msg: &(dyn Any + Send)) {
    if let Some(s) = msg.downcast_ref::<String>() {
        println!("Got a String: {:?}", s);
    } else if let Some(s) = msg.downcast_ref::<&str>() {
        println!("Got a &str: {:?}", s);
    }
}
```

Before:
```
Got a String: "core"
Got a String: "core"
Got a &str: "std"
Got a &str: "std"
```

After:
```
Got a &str: "core"
Got a &str: "core"
Got a &str: "std"
Got a &str: "std"
```
2020-10-24 22:39:53 +02:00
Jonas Schievink e12e97223f
Rollup merge of #78072 - Nadrieril:cleanup-constant-matching, r=varkor
Cleanup constant matching in exhaustiveness checking

This supercedes https://github.com/rust-lang/rust/pull/77390. I made the `Opaque` constructor work.
I have opened two issues https://github.com/rust-lang/rust/issues/78071 and https://github.com/rust-lang/rust/issues/78057 from the discussion we had on the previous PR. They are not regressions nor directly related to the current PR so I thought we'd deal with them separately.

I left a FIXME somewhere because I didn't know how to compare string constants for equality. There might even be some unicode things that need to happen there. In the meantime I preserved previous behavior.

EDIT: I accidentally fixed #78071
2020-10-24 22:39:51 +02:00
Jonas Schievink 0a06d7344b
Rollup merge of #78069 - fusion-engineering-forks:core-const-panic-str, r=RalfJung
Fix const core::panic!(non_literal_str).

Invocations of `core::panic!(x)` where `x` is not a string literal expand to `panic!("{}", x)`, which is not understood by the const panic logic right now. This adds `panic_str` as a lang item, and modifies the const eval implementation to hook into this item as well.

This fixes the issue mentioned here: https://github.com/rust-lang/rust/issues/51999#issuecomment-687604248

r? `@RalfJung`

`@rustbot` modify labels: +A-const-eval
2020-10-24 22:39:49 +02:00
Jonas Schievink 7428de1583
Rollup merge of #77930 - estebank:ice-77919, r=eddyb
Do not ICE with TraitPredicates containing [type error]

Fix #77919.
2020-10-24 22:39:47 +02:00
Jonas Schievink 4d72939af1
Rollup merge of #77830 - cjgillot:remacro, r=oli-obk
Simplify query proc-macros

The query code generation is split between proc-macros and regular macros in `rustc_middle::ty::query`.

This PR removes unused capabilities of the proc-macros, and tend to use regular macros for the logic.
2020-10-24 22:39:46 +02:00
Jonas Schievink e34263d86a
Rollup merge of #77610 - hermitcore:dtors, r=m-ou-se
revise Hermit's mutex interface to support the behaviour of StaticMutex

rust-lang/rust#77147 simplifies things by splitting this Mutex type into two types matching the two use cases: StaticMutex and MovableMutex. To support the new behavior of StaticMutex, we move part of the mutex implementation into libstd.

The interface to the OS changed. Consequently, I removed a few functions, which aren't longer needed.
2020-10-24 22:39:44 +02:00
Jonas Schievink a547055184
Rollup merge of #76614 - NoraCodes:nora/control_flow_enum, r=scottmcm
change the order of type arguments on ControlFlow

This allows ControlFlow<BreakType> which is much more ergonomic for common iterator combinator use cases.

Addresses one component of #75744
2020-10-24 22:39:41 +02:00
Jonas Schievink 01a38f0d9a
Rollup merge of #75115 - chansuke:sys-cloudabi-unsafe, r=KodrAus
`#[deny(unsafe_op_in_unsafe_fn)]` in sys/cloudabi

Partial fix of #73904.

This encloses unsafe operations in unsafe fn in sys/cloudabi.
2020-10-24 22:39:35 +02:00
Wesley Wiser dd683e5ab5 MIR validation should check SwitchInt values are valid for the type 2020-10-24 16:00:04 -04:00
bors ffa2e7ae8f Auto merge of #77255 - Aaron1011:feature/collect-attr-tokens, r=petrochenkov
Unconditionally capture tokens for attributes.

This allows us to avoid synthesizing tokens in `prepend_attr`, since we
have the original tokens available.

We still need to synthesize tokens when expanding `cfg_attr`,
but this is an unavoidable consequence of the syntax of `cfg_attr` -
the user does not supply the `#` and `[]` tokens that a `cfg_attr`
expands to.

This is based on PR https://github.com/rust-lang/rust/pull/77250 - this PR exposes a bug in the current `collect_tokens` implementation, which is fixed by the rewrite.
2020-10-24 19:23:32 +00:00
Ralf Jung 5d624929cf
fix typo
Co-authored-by: BlackHoleFox <blackholefoxdev@gmail.com>
2020-10-24 20:39:04 +02:00
Aaron Hill 283053a742
Compute proper module parent during resolution
Fixes #75982

The direct parent of a module may not be a module
(e.g. `const _: () =  { #[path = "foo.rs"] mod foo; };`).

To find the parent of a module for purposes of resolution, we need to
walk up the tree until we hit a module or a crate root.
2020-10-24 14:28:13 -04:00
Vadim Petrochenkov ef09ed2002 resolve: Relax macro resolution consistency check to account for any errors 2020-10-24 21:26:08 +03:00
Jake Goulding c6ab758e54 Switch from tuple matching to match guards 2020-10-24 12:58:38 -04:00
bors 89fdb30892 Auto merge of #78319 - jonas-schievink:rollup-vzj8a6l, r=jonas-schievink
Rollup of 15 pull requests

Successful merges:

 - #76649 (Add a spin loop hint for Arc::downgrade)
 - #77392 (add `insert` to `Option`)
 - #77716 (Revert "Allow dynamic linking for iOS/tvOS targets.")
 - #78109 (Check for exhaustion in RangeInclusive::contains and slicing)
 - #78198 (Simplify assert terminator only if condition evaluates to expected value)
 - #78243 (--test-args flag description)
 - #78249 (improve const infer error)
 - #78250 (Document inline-const)
 - #78264 (Add regression test for issue-77475)
 - #78274 (Update description of Empty Enum for accuracy)
 - #78278 (move `visit_predicate` into `TypeVisitor`)
 - #78292 (Loop instead of recursion)
 - #78293 (Always store Rustdoc theme when it's changed)
 - #78300 (Make codegen coverage_context optional, and check)
 - #78307 (Revert "Set .llvmbc and .llvmcmd sections as allocatable")

Failed merges:

r? `@ghost`
2020-10-24 16:12:01 +00:00
Aaron Hill ac384ac2db
Fix inconsistencies in handling of inert attributes on statements
When the 'early' and 'late' visitors visit an attribute target, they
activate any lint attributes (e.g. `#[allow]`) that apply to it.
This can affect warnings emitted on sibiling attributes. For example,
the following code does not produce an `unused_attributes` for
`#[inline]`, since the sibiling `#[allow(unused_attributes)]` suppressed
the warning.

```rust
trait Foo {
    #[allow(unused_attributes)] #[inline] fn first();
    #[inline] #[allow(unused_attributes)] fn second();
}
```

However, we do not do this for statements - instead, the lint attributes
only become active when we visit the struct nested inside `StmtKind`
(e.g. `Item`).

Currently, this is difficult to observe due to another issue - the
`HasAttrs` impl for `StmtKind` ignores attributes for `StmtKind::Item`.
As a result, the `unused_doc_comments` lint will never see attributes on
item statements.

This commit makes two interrelated fixes to the handling of inert
(non-proc-macro) attributes on statements:

* The `HasAttr` impl for `StmtKind` now returns attributes for
  `StmtKind::Item`, treating it just like every other `StmtKind`
  variant. The only place relying on the old behavior was macro
  which has been updated to explicitly ignore attributes on item
  statements. This allows the `unused_doc_comments` lint to fire for
  item statements.
* The `early` and `late` lint visitors now activate lint attributes when
  invoking the callback for `Stmt`. This ensures that a lint
  attribute (e.g. `#[allow(unused_doc_comments)]`) can be applied to
  sibiling attributes on an item statement.

For now, the `unused_doc_comments` lint is explicitly disabled on item
statements, which preserves the current behavior. The exact locatiosn
where this lint should fire are being discussed in PR #78306
2020-10-24 11:55:48 -04:00
Ralf Jung 1333206eb3 ensure that statics are inhabited 2020-10-24 16:15:42 +02:00
Philipp Oppermann eb5db6ce4f
Link directly to #build-std anchor
Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
2020-10-24 16:13:49 +02:00
est31 a21c2eb121 Iterate over the smaller list
If there are two lists of different sizes,
iterating over the smaller list and then
looking up in the larger list is cheaper
than vice versa, because lookups scale
sublinearly.
2020-10-24 15:57:42 +02:00
Stein Somers 3b6c4fe465 BTreeMap: stop mistaking node::MIN_LEN as a node level constraint 2020-10-24 15:24:37 +02:00
Philipp Oppermann 11a7087cc1
Link to cargo's build-std feature instead of xargo in custom target docs
The `xargo` tool is in maintenance mode since 2018 and the `build-std` feature of cargo already works reasonably well for most use cases.
2020-10-24 14:30:45 +02:00
Alex Macleod 75bbd80c09 Add some regression tests
Closes #56229
Closes #59494
Closes #70746
Closes #73229
2020-10-24 13:13:52 +01:00
Jonas Schievink 1ac137be93
Rollup merge of #78307 - rust-lang:revert-77961-embed-bitcode, r=tmandry
Revert "Set .llvmbc and .llvmcmd sections as allocatable"

Reverts rust-lang/rust#77961, see discussion starting from https://github.com/rust-lang/rust/pull/77961#issuecomment-712313902
2020-10-24 14:12:20 +02:00
Jonas Schievink da486467d4
Rollup merge of #78300 - richkadel:coverage-cx, r=wesleywiser
Make codegen coverage_context optional, and check

Addresses Issue #78286

Libraries compiled with coverage and linked with out enabling coverage
would fail when attempting to add the library's coverage statements to
the codegen coverage context (None).

Now, if coverage statements are encountered while compiling / linking
with `-Z instrument-coverage` disabled, codegen will *not* attempt to
add code regions to a coverage map, and it will not inject the LLVM
instrprof_increment intrinsic calls.
2020-10-24 14:12:18 +02:00
Jonas Schievink a07fc3d865
Rollup merge of #78293 - nasso:master, r=GuillaumeGomez
Always store Rustdoc theme when it's changed

`switchTheme` (too) lazily updated the value of `rustdoc-theme` in `localStorage`, leading to an incorrect stored value when the system theme is the same as the default (`light`) theme.

Fixes #78273
2020-10-24 14:12:16 +02:00
Jonas Schievink 2362659b00
Rollup merge of #78292 - bugadani:recursion, r=nagisa
Loop instead of recursion

I saw the comment `// FIXME: consider not using recursion to lower this.` and considered not using recursion :)
2020-10-24 14:12:15 +02:00
Jonas Schievink b6ae1fabee
Rollup merge of #78278 - lcnr:predicate-visit, r=matthewjasper
move `visit_predicate` into `TypeVisitor`

Seems easier than dealing with `PredicateVisitor` for me which I needed for object safety checks for `PredicateAtom::ConstEvaluatable`. Is there a reason I am missing for this split?

r? @matthewjasper
2020-10-24 14:12:13 +02:00
Jonas Schievink eaa982305d
Rollup merge of #78274 - Enet4:patch-1, r=jonas-schievink
Update description of Empty Enum for accuracy

An empty enum is similar to the never type `!`, rather than the unit type `()`.
2020-10-24 14:12:11 +02:00
Jonas Schievink 27cb587edc
Rollup merge of #78264 - JohnTitor:macro-test, r=petrochenkov
Add regression test for issue-77475

Closes #77475
2020-10-24 14:12:10 +02:00
Jonas Schievink 20ba9ffbee
Rollup merge of #78250 - camelid:document-inline-const, r=spastorino
Document inline-const

Part of #76001.

r? @spastorino
2020-10-24 14:12:08 +02:00
Jonas Schievink 77cd5b5485
Rollup merge of #78249 - lcnr:ct-infer-origin, r=varkor
improve const infer error

For type inference we probably have to be careful about subtyping and stuff but considering that subtyping shouldn't be relevant for constants I don't really see a reason why we may not want to reuse the const origin here.

r? `@varkor`
2020-10-24 14:12:06 +02:00
Jonas Schievink 6b2ed99a56
Rollup merge of #78243 - njasm:patch_test_args_description, r=jyn514
--test-args flag description

tiny enhancement/clarification for the help description of the `--test-args` option from `x.py test` subcommand.

Edit: ...as discussed in zulip [here](https://rust-lang.zulipchat.com/#narrow/stream/122651-general/topic/x.2Epy.20run.20single.20unit.20test.3F/near/214107842)
2020-10-24 14:12:05 +02:00
Jonas Schievink 86c07a4955
Rollup merge of #78198 - tmiasko:assert, r=davidtwco
Simplify assert terminator only if condition evaluates to expected value
2020-10-24 14:12:03 +02:00
Jonas Schievink d9acd7d148
Rollup merge of #78109 - cuviper:exhausted-rangeinc, r=dtolnay
Check for exhaustion in RangeInclusive::contains and slicing

When a range has finished iteration, `is_empty` returns true, so it
should also be the case that `contains` returns false.

Fixes #77941.
2020-10-24 14:12:01 +02:00
Jonas Schievink fb92b70f95
Rollup merge of #77716 - francesca64:revert-ios-dynamic-linking, r=jonas-schievink
Revert "Allow dynamic linking for iOS/tvOS targets."

This reverts PR #73516.

On macOS I compile static libs for iOS, automated using [cargo-mobile](https://github.com/BrainiumLLC/cargo-mobile), which has worked smoothly for the past 2 years. However, upon updating to Rust 1.46.0, I was no longer able to use Rust on iOS. I've bisected this to the PR referenced above.

For most projects tested, apps now immediately crash with a message like this:
```
dyld: Library not loaded: /Users/francesca/Projects/example/target/aarch64-apple-ios/debug/deps/libexample.dylib
  Referenced from: /private/var/containers/Bundle/Application/745912AF-A928-465C-B340-872BD1C9F368/example.app/example
  Reason: image not found
dyld: launch, loading dependent libraries
DYLD_LIBRARY_PATH=/usr/lib/system/introspection
DYLD_INSERT_LIBRARIES=/Developer/usr/lib/libBacktraceRecording.dylib:/Developer/usr/lib/libMainThreadChecker.dylib:/Developer/Library/PrivateFrameworks/DTDDISupport.framework/libViewDebuggerSupport.dylib:/Developer/Library/PrivateFrameworks/GPUTools.framework/libglInterpose.dylib:/usr/lib/libMTLCapture.dylib
```

This can be reproduced by using cargo-mobile to generate a winit example project, and then attempting to run it on an iOS device (`cargo mobile init && cargo apple open`).

In our projects that depend on DisplayLink, the build instead fails with a linker error:
```
= note: Undefined symbols for architecture arm64:
            "_CACurrentMediaTime", referenced from:
                display_link::ios::run_callback_ios10::hda81197ff46aedbd in libapp-4f0abc1d7684103f.rlib(app-4f0abc1d7684103f.40d4iro0yz1iy487.rcgu.o)
                display_link::ios::run_callback_pre_ios10::h91f085da19374320 in libapp-4f0abc1d7684103f.rlib(app-4f0abc1d7684103f.40d4iro0yz1iy487.rcgu.o)
          ld: symbol(s) not found for architecture arm64
```

After reverting the change to enable dynamic linking on iOS, everything works the same as it did on Rust 1.45.2 for me.

In the future, would it be possible for me to be pinged when iOS-related PRs are made? I work for a company that intends on using Rust on iOS in production, so I'd gladly provide testing.

cc @aspenluxxxy
2020-10-24 14:11:59 +02:00
Jonas Schievink d7c635b3a5
Rollup merge of #77392 - Canop:option_insert, r=m-ou-se
add `insert` to `Option`

This removes a cause of `unwrap` and code complexity.

This allows replacing

```
option_value = Some(build());
option_value.as_mut().unwrap()
```

with

```
option_value.insert(build())
```

It's also useful in contexts not requiring the mutability of the reference.

Here's a typical cache example:

```
let checked_cache = cache.as_ref().filter(|e| e.is_valid());
let content = match checked_cache {
	Some(e) => &e.content,
	None => {
	    cache = Some(compute_cache_entry());
	    // unwrap is OK because we just filled the option
	    &cache.as_ref().unwrap().content
	}
};
```

It can be changed into

```
let checked_cache = cache.as_ref().filter(|e| e.is_valid());
let content = match checked_cache {
	Some(e) => &e.content,
	None => &cache.insert(compute_cache_entry()).content,
};
```

*(edited: I removed `insert_with`)*
2020-10-24 14:11:57 +02:00
Jonas Schievink 8e756698df
Rollup merge of #76649 - nicbn:arc-spin-loop-hint, r=m-ou-se
Add a spin loop hint for Arc::downgrade

Adds `hint::spin_loop()` to the case where `Arc::downgrade` spins.
2020-10-24 14:11:56 +02:00
Dániel Buga 6533d010cf Don't generate multiple impl blocks 2020-10-24 11:55:00 +02:00
chansuke d37b8cf729 Remove unnecessary unsafe block from condvar_atomics & mutex_atomics 2020-10-24 18:22:18 +09:00
bors 2e8a54af60 Auto merge of #78316 - fusion-engineering-forks:fix-musl-ci-build, r=pietroalbini
Use different mirror for sabotage linux in musl-toolchain CI script.

Should hopefully fix the CI failure of #78309

`musl-cross-make` Makefile for reference: a54eb56f33/Makefile

r? `@pietroalbini`
2020-10-24 09:18:54 +00:00