Commit graph

8873 commits

Author SHA1 Message Date
Esteban Kuber
ef212e7fb3 Point at overlapping impls when type annotations are needed 2021-10-24 18:33:04 +00:00
bors
ed08a67566 Auto merge of #85254 - cjgillot:reveal-mir, r=lcnr
Normalize MIR with RevealAll before optimizations.

Fixes #78442
2021-10-24 11:04:54 +00:00
bors
bdcb528512 Auto merge of #90208 - Mark-Simulacrum:hash-bytes-fast, r=oli-obk
Specialize HashStable for [u8] slices

Particularly for ctfe-stress-4, the hashing of byte slices as part of the
MIR Allocation is quite hot. Previously, we were falling back on byte-by-byte
copying of the slice into the SipHash buffer (64 bytes long) before hashing a 64
byte chunk, and then doing that again and again; now we use the dedicated byte-slice write.
2021-10-24 06:29:41 +00:00
bors
45591408b1 Auto merge of #90175 - cuviper:min-llvm-12, r=nagisa
Update the minimum external LLVM to 12

With this change, we'll have stable support for LLVM 12 and 13.
For reference, the previous increase to LLVM 10 was #83387,
and this replaces the pending increase to LLVM 11 in #90062.

r? `@nagisa` `@nikic`
2021-10-23 20:59:29 +00:00
Mark Rousskov
3cd5c95ab0 Specialize HashStable for [u8] slices
Particularly for ctfe-stress-4, the hashing of byte slices as part of the
MIR Allocation is quite hot. Previously, we were falling back on byte-by-byte
copying of the slice into the SipHash buffer (64 bytes long) before hashing a 64
byte chunk, and then doing that again and again.

This should hopefully be an improvement for that code.
2021-10-23 12:11:05 -04:00
bors
91b931926f Auto merge of #90203 - matthiaskrgr:rollup-v215wew, r=matthiaskrgr
Rollup of 5 pull requests

Successful merges:

 - #85833 (Scrape code examples from examples/ directory for Rustdoc)
 - #88041 (Make all proc-macro back-compat lints deny-by-default)
 - #89829 (Consider types appearing in const expressions to be invariant)
 - #90168 (Reset qualifs when a storage of a local ends)
 - #90198 (Add caveat about changing parallelism and function call overhead)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-10-23 15:53:50 +00:00
Matthias Krüger
74a0c492c1
Rollup merge of #90168 - tmiasko:const-qualif-storage, r=matthewjasper
Reset qualifs when a storage of a local ends

Reset qualifs when a storage of a local ends to ensure that the local qualifs
are affected by the state from previous loop iterations only if the local is
kept alive.

The change should be forward compatible with a stricter handling of indirect
assignments, since storage dead invalidates all existing pointers to the local.
2021-10-23 14:58:42 +02:00
Matthias Krüger
2b874f0242
Rollup merge of #89829 - voidc:assoc-const-variance, r=lcnr
Consider types appearing in const expressions to be invariant

This is an approach to fix #80977.
Currently, a type parameter which is only used in a constant expression is considered bivariant and will trigger error E0392 *"parameter T is never used"*.
Here is a short example:

```rust
pub trait Foo {
    const N: usize;
}

struct Bar<T: Foo>([u8; T::N])
where [(); T::N]:;
```
([playgound](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2015&gist=b51a272853f75925e72efc1597478aa5))

While it is possible to silence this error by adding a `PhantomData<T>` field, I think the better solution would be to make `T` invariant.
This would be analogous to the invariance constraints added for associated types.
However, I'm quite new to the compiler and unsure whether this is the right approach.

r? ``@varkor`` (since you authored #60058)
2021-10-23 14:58:41 +02:00
Matthias Krüger
17c602d423
Rollup merge of #88041 - Aaron1011:deny-proc-macro-hack, r=wesleywiser
Make all proc-macro back-compat lints deny-by-default

The affected crates have had plenty of time to update.
By keeping these as lints rather than making them hard errors,
we ensure that downstream crates will still be able to compile,
even if they transitive depend on broken versions of the affected
crates.

This should hopefully discourage anyone from writing any
new code which relies on the backwards-compatibility behavior.
2021-10-23 14:58:40 +02:00
bors
aa5740c715 Auto merge of #90104 - spastorino:coherence-for-negative-trait, r=nikomatsakis
Implement coherence checks for negative trait impls

The main purpose of this PR is to be able to [move Error trait to core](https://github.com/rust-lang/project-error-handling/issues/3).

This feature is necessary to handle the following from impl on box.

```rust
impl From<&str> for Box<dyn Error> { ... }
```

Without having negative traits affect coherence moving the error trait into `core` and moving that `From` impl to `alloc` will cause the from impl to no longer compiler because of a potential future incompatibility. The compiler indicates that `&str` _could_ introduce an `Error` impl in the future, and thus prevents the `From` impl in `alloc` that would cause overlap with `From<E: Error> for Box<dyn Error>`. Adding `impl !Error for &str {}` with the negative trait coherence feature will disable this error by encoding a stability guarantee that `&str` will never implement `Error`, making the `From` impl compile.

We would have this in `alloc`:

```rust
impl From<&str> for Box<dyn Error> {} // A
impl<E> From<E> for Box<dyn Error> where E: Error {} // B
```

and this in `core`:

```rust
trait Error {}
impl !Error for &str {}
```

r? `@nikomatsakis`

This PR was built on top of `@yaahc` PR #85764.

Language team proposal: to https://github.com/rust-lang/lang-team/issues/96
2021-10-23 12:51:15 +00:00
Santiago Pastorino
3287f72d39
Avoid code duplication by extracting checks into fns 2021-10-23 08:55:48 -03:00
bors
55ccbd090d Auto merge of #90065 - cjgillot:novalcache, r=Mark-Simulacrum
Do not depend on the stored value when trying to cache on disk.

Having different criteria for loading and saving of query results can lead to saved results that may never be loaded.
Since the on-disk cache is discarded as soon as a compilation error is issued, there should not be any need for an exclusion mecanism based on errors.

As a result, the possibility to condition the storage on the value itself does not appear useful.
2021-10-23 09:21:45 +00:00
Tomasz Miąsko
e4aeeca667 Reset qualifs when a storage of a local ends
to ensure that the local qualifs are affected by the state from previous
loop iterations only if the local is kept alive.

The change should be forward compatible with a stricter handling of
indirect assignments, since storage dead invalidates all existing
pointers to the local.
2021-10-23 09:26:22 +02:00
Matthias Krüger
8fb194c86f
Rollup merge of #89920 - hudson-ayers:location-detail-control, r=davidtwco
Implement -Z location-detail flag

This PR implements the `-Z location-detail` flag as described in https://github.com/rust-lang/rfcs/pull/2091 .

`-Z location-detail=val` controls what location details are tracked when using `caller_location`. This allows users to control what location details are printed as part of panic messages, by allowing them to exclude any combination of filenames, line numbers, and column numbers. This option is intended to provide users with a way to mitigate the size impact of `#[track_caller]`.

Some measurements of the savings of this approach on an embedded binary can be found here: https://github.com/rust-lang/rust/issues/70579#issuecomment-942556822 .

Closes #70580 (unless people want to leave that open as a place for discussion of further improvements).

This is my first real PR to rust, so any help correcting mistakes / understanding side effects / improving my tests is appreciated :)

I have one question: RFC 2091 specified this as a debugging option (I think that is what -Z implies?). Does that mean this can never be stabilized without a separate MCP? If so, do I need to submit an MCP now, or is the initial RFC specifying this option sufficient for this to be merged as is, and then an MCP would be needed for eventual stabilization?
2021-10-23 05:28:23 +02:00
Matthias Krüger
736e8ebd1c
Rollup merge of #89730 - crlf0710:type_changing_feature, r=jackh726
add feature flag for `type_changing_struct_update`

This implements the PR0 part of the mentoring notes within #86618.

overrides the previous inactive #86646 pr.

r? ```@nikomatsakis```
2021-10-23 05:28:22 +02:00
Matthias Krüger
0f81c7faf5
Rollup merge of #89468 - FabianWolff:issue-89358, r=jackh726
Report fatal lexer errors in `--cfg` command line arguments

Fixes #89358. The erroneous behavior was apparently introduced by `@Mark-Simulacrum` in a678e31911; the idea is to silence individual parser errors and instead emit one catch-all error message after parsing. However, for the example in #89358, a fatal lexer error is created here:
edebf77e00/compiler/rustc_parse/src/lexer/mod.rs (L340-L349)

This fatal error aborts the compilation, and so the call to `new_parser_from_source_str()` never returns and the catch-all error message is never emitted. I have therefore changed the `SilentEmitter` to silence only non-fatal errors; with my changes, for the rustc invocation described in #89358:
```sh
rustc --cfg "abc\""
```
I get the following output:
```
error[E0765]: unterminated double quote string
  |
  = note: this error occurred on the command line: `--cfg=abc"`
```
2021-10-23 05:28:22 +02:00
Michael Howell
98ed5548d7 nice_region_error: Include lifetime placeholders in error output
As you can see in src/test/ui/traits/self-without-lifetime-constraint.stderr
you can get very confusing type names if you don't have this.

Fixes #87763
2021-10-22 15:26:20 -07:00
Santiago Pastorino
9534186857
Hide negative coherence checks under negative_impls feature flag 2021-10-22 17:54:20 -03:00
Santiago Pastorino
132409f0c6
Assemple trait alias candidates for negative polarity
This doesn't work properly yet, we would probably need to implement an
`assembly_neg_candidates` and consider things like `T: !AB` as `T: !A`
|| `T: !B`
2021-10-22 15:49:54 -03:00
Santiago Pastorino
da79fa964c
Add rustc_strict_coherence attribute and use it to check overlap 2021-10-22 15:49:46 -03:00
Josh Stone
e9f545b9a9 Update the minimum external LLVM to 12 2021-10-22 10:50:07 -07:00
bors
01198792a6 Auto merge of #89893 - camsteffen:redundant-dump-enabled, r=matthewjasper
Remove redundant dump_enabled check
2021-10-22 17:32:20 +00:00
Josh Stone
65150af1b4 Update the minimum external LLVM to 11 2021-10-22 09:22:18 -07:00
Charles Lew
7d7ebf8805 add feature flag for type_changing_struct_update 2021-10-22 11:46:55 -04:00
Santiago Pastorino
74454c4888
Add comment about the only way to prove NotImplemented here 2021-10-22 11:04:30 -03:00
Santiago Pastorino
2e9fb8b68b
Fix filter_impls comment 2021-10-22 10:58:38 -03:00
Santiago Pastorino
b03a0df737
Fix debug method name 2021-10-22 10:57:10 -03:00
Santiago Pastorino
5b5a2e600e
Move const filter to filter_impls 2021-10-22 10:56:32 -03:00
Santiago Pastorino
c4c76a4fbd
Document flip polarity 2021-10-22 09:34:36 -03:00
Santiago Pastorino
7829d9dde3
Document overlap check filter 2021-10-22 09:22:19 -03:00
Yuki Okushi
a656bc5b08
Rollup merge of #90069 - tmiasko:promoted-const-qualif, r=oli-obk
Fix const qualification when executed after promotion

The const qualification was so far performed before the promotion and
the implementation assumed that it will never encounter a promoted.

With `const_precise_live_drops` feature, checking for live drops is
delayed until after drop elaboration, which in turn runs after
promotion. so the assumption is no longer true. When evaluating
`NeedsNonConstDrop` it is now possible to encounter promoteds.

Use type base qualification for the promoted. It is a sound
approximation in general, and in the specific case of promoteds and
`NeedsNonConstDrop` it is precise.

Fixes #89938.
2021-10-22 19:42:49 +09:00
Yuki Okushi
9ed9025ea9
Rollup merge of #90028 - tmiasko:structural-match-closure, r=spastorino
Reject closures in patterns

Fixes #90013.
2021-10-22 19:42:48 +09:00
Yuki Okushi
cbebdd8e67
Rollup merge of #89991 - petrochenkov:visitok2, r=jackh726
rustc_ast: Turn `MutVisitor::token_visiting_enabled` into a constant

It's a visitor property rather than something that needs to be determined at runtime
2021-10-22 19:42:48 +09:00
Yuki Okushi
327d8073e2
Rollup merge of #89922 - JohnTitor:update-e0637, r=jackh726
Update E0637 description to mention `&` w/o an explicit lifetime name

Deal with https://github.com/rust-lang/rust/issues/89824#issuecomment-941598647. Another solution would be splitting the error code into two as (I think) it's a bit unclear to users why they have the same error code.
2021-10-22 19:42:46 +09:00
Yuki Okushi
91fb223f59
Rollup merge of #89895 - camsteffen:for-loop-head-span, r=davidtwco
Don't mark for loop iter expression as desugared

We typically don't mark spans of lowered things as desugared. This helps Clippy rightly discern when code is (not) from expansion. This was discovered by ``@flip1995`` at https://github.com/rust-lang/rust-clippy/pull/7789#issuecomment-939289501.
2021-10-22 19:42:45 +09:00
Yuki Okushi
8738d5d611
Rollup merge of #89257 - aDotInTheVoid:macro-error-2, r=estebank
Give better error for `macro_rules name`

follow up to #89221

r? ``@estebank``

``@rustbot`` modify labels: +A-diagnostics +A-parser
2021-10-22 19:42:43 +09:00
Camille GILLOT
0a5666b838 Do not depend on the stored value when trying to cache on disk. 2021-10-21 20:00:45 +02:00
Hudson Ayers
b802629311 add tests for -Zlocation-detail 2021-10-21 10:44:22 -07:00
Hudson Ayers
e1d94b8fd1 Configure saved panic locations based on location-detail flag 2021-10-21 10:41:19 -07:00
bors
547a6ffee0 Auto merge of #90130 - Mark-Simulacrum:revert-namebinding, r=oli-obk
Revert "resolve: Use NameBinding for local variables and generic parameters"

This reverts commit 6162529a01, that is, PR #89100.

Reverting per performance regression noted post-merge on that PR (https://github.com/rust-lang/rust/pull/89100#issuecomment-948065457).
2021-10-21 15:45:00 +00:00
Mark Rousskov
7552af2f6f Revert "Auto merge of #89100 - petrochenkov:localbind, r=cjgillot"
This reverts commit 6162529a01.
2021-10-21 09:09:24 -04:00
Tomasz Miąsko
74c6636d27 Verify that only NeedsNonConstDrop expects promoteds 2021-10-21 11:14:41 +02:00
bors
e015ef5b26 Auto merge of #90119 - JohnTitor:rollup-e5t6khz, r=JohnTitor
Rollup of 14 pull requests

Successful merges:

 - #86984 (Reject octal zeros in IPv4 addresses)
 - #87440 (Remove unnecessary condition in Barrier::wait())
 - #88644 (`AbstractConst` private fields)
 - #89292 (Stabilize CString::from_vec_with_nul[_unchecked])
 - #90010 (Avoid overflow in `VecDeque::with_capacity_in()`.)
 - #90029 (Add test for debug logging during incremental compilation)
 - #90031 (config: add the option to enable LLVM tests)
 - #90048 (Add test for line-number setting)
 - #90071 (Remove hir::map::blocks and use FnKind instead)
 - #90074 (2229 migrations small cleanup)
 - #90077 (Make `From` impls of NonZero integer const.)
 - #90097 (Add test for duplicated sidebar entries for reexported macro)
 - #90098 (Add test to ensure that the missing_doc_code_examples is not triggered on foreign trait implementations)
 - #90099 (Fix MIRI UB in `Vec::swap_remove`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-10-21 08:04:19 +00:00
Yuki Okushi
371fd4f1c0
Rollup merge of #90074 - klensy:upvar-all, r=wesleywiser
2229 migrations small cleanup

This removes needless `format!`'ing of empty string and replaces `vec!` with const strings with const array.
2021-10-21 14:11:09 +09:00
Yuki Okushi
afdd0c3ade
Rollup merge of #90071 - cjgillot:no-blocks, r=oli-obk
Remove hir::map::blocks and use FnKind instead

The principal tool is `FnLikeNode`, which is not often used and can be easily implemented using `rustc_hir::intravisit::FnKind`.
2021-10-21 14:11:08 +09:00
Yuki Okushi
6f0acbcbd0
Rollup merge of #88644 - eopb:abstractconst_leaf_subst, r=lcnr
`AbstractConst` private fields

Calls `subst` in `AbstractConst::root` when `Node` is `Leaf`.

r? ``@lcnr``
2021-10-21 14:11:03 +09:00
bors
40ebd07382 Auto merge of #90072 - ehuss:empty-rmeta-no-warn, r=Mark-Simulacrum
Don't emit a warning for empty rmeta files.

This avoids displaying a warning when attempting to load an empty rmeta file. Warnings were enabled via #89634 which can cause a lot of noise (for example, running `./x.py check`).  rustc generates empty rmeta files for things like binaries, which can happen when checking libraries as unittests.

Closes #89795
2021-10-21 05:04:39 +00:00
Santiago Pastorino
5a727538f8
Fix allow_negative_impls logic 2021-10-20 18:05:06 -03:00
bors
efd0483949 Auto merge of #89978 - cjgillot:qarray, r=Mark-Simulacrum
Merge the two depkind vtables

Knowledge of `DepKind`s is managed using two arrays containing flags (is_anon, eval_always, fingerprint_style), and function pointers (forcing and loading code).

This PR aims at merging the two arrays so as to reduce unneeded indirect calls and (hopefully) increase code locality.
r? `@ghost`
2021-10-20 17:57:35 +00:00
Santiago Pastorino
68d444ffa1
Add TraitObligation::polarity() for better encapsulation 2021-10-20 14:45:10 -03:00