Commit Graph

4598 Commits

Author SHA1 Message Date
Aaron Hill 06546d4b40
Avoid sorting predicates by `DefId`
Fixes issue #82920

Even if an item does not change between compilation sessions, it may end
up with a different `DefId`, since inserting/deleting an item affects
the `DefId`s of all subsequent items. Therefore, we use a `DefPathHash`
in the incremental compilation system, which is stable in the face of
changes to unrelated items.

In particular, the query system will consider the inputs to a query to
be unchanged if any `DefId`s in the inputs have their `DefPathHash`es
unchanged. Queries are pure functions, so the query result should be
unchanged if the query inputs are unchanged.

Unfortunately, it's possible to inadvertantly make a query result
incorrectly change across compilations, by relying on the specific value
of a `DefId`. Specifically, if the query result is a slice that gets
sorted by `DefId`, the precise order will depend on how the `DefId`s got
assigned in a particular compilation session. If some definitions end up
with different `DefId`s (but the same `DefPathHash`es) in a subsequent
compilation session, we will end up re-computing a *different* value for
the query, even though the query system expects the result to unchanged
due to the unchanged inputs.

It turns out that we have been sorting the predicates computed during
`astconv` by their `DefId`. These predicates make their way into the
`super_predicates_that_define_assoc_type`, which ends up getting used to
compute the vtables of trait objects. This, re-ordering these predicates
between compilation sessions can lead to undefined behavior at runtime -
the query system will re-use code built with a *differently ordered*
vtable, resulting in the wrong method being invoked at runtime.

This PR avoids sorting by `DefId` in `astconv`, fixing the
miscompilation. However, it's possible that other instances of this
issue exist - they could also be easily introduced in the future.

To fully fix this issue, we should
1. Turn on `-Z incremental-verify-ich` by default. This will cause the
   compiler to ICE whenver an 'unchanged' query result changes between
   compilation sessions, instead of causing a miscompilation.
2. Remove the `Ord` impls for `CrateNum` and `DefId`. This will make it
   difficult to introduce ICEs in the first place.
2021-03-13 13:45:12 -05:00
bors e7e1dc158c Auto merge of #83007 - Aaron1011:incr-verify-default, r=Mark-Simulacrum
Turn `-Z incremental-verify-ich` on by default

Issue #82920 showed that the kind of bugs caught by this flag have
soundness implications.
2021-03-13 17:52:22 +00:00
Aaron Hill 7d7c81a114
Always run `incremental_verify_ich` when re-computing query results
Issue #82920 showed that the kind of bugs caught by this flag have
soundness implications.

This causes performance regressions of up to 15.2% during incremental
compilation, but this is necessary to catch miscompilations caused by
bugs in query implementations.
2021-03-13 12:00:38 -05:00
bors 56f74c52c1 Auto merge of #83069 - tgnottingham:simplify-query-cache-iter, r=cjgillot
rustc_query_system: simplify QueryCache::iter

Minor cleanup to reduce a small amount of complexity and code bloat.
Reduces the number of mono items in rustc_query_impl by 15%.
2021-03-13 15:11:25 +00:00
Camille GILLOT ab1782975a Iterate on crate_inherent_impls for metadata. 2021-03-13 14:17:55 +01:00
bors 32dce353de Auto merge of #82891 - cjgillot:monoparent, r=petrochenkov
Make def_key and HIR parenting consistent.

r? `@petrochenkov`
2021-03-13 12:28:04 +00:00
bors 178bd9130e Auto merge of #82878 - sexxi-goose:repr_packed, r=nikomatsakis
2229: Handle capturing a reference into a repr packed struct

RFC 1240 states that it is unsafe to capture references into a
packed-struct. This PR ensures that when a closure captures a precise
path, we aren't violating this safety constraint.

To acheive so we restrict the capture precision to the struct itself.

An interesting edge case where we decided to restrict precision:
```rust
struct Foo(String);

let foo: Foo;
let c = || {
    println!("{}", foo.0);
    let x = foo.0;
}
```

Given how closures get desugared today, foo.0 will be moved into the
closure, making the `println!`, safe. However this can be very subtle
and also will be unsafe if the closure gets inline.

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

r? `@nikomatsakis`
2021-03-13 09:47:07 +00:00
bors f42888c15f Auto merge of #82436 - osa1:issue80258, r=nikomatsakis
Allow calling *const methods on *mut values

This allows `*const` methods to be called on `*mut` values.

TODOs:

- [x] ~~Remove debug logs~~ Done.
- [x] ~~I haven't tested, but I think this currently won't work when the `self` value has type like `&&&&& *mut X` because I don't do any autoderefs when probing. To fix this the new code in `rustc_typeck::check::method::probe` needs to reuse `pick_method` somehow as I think that's the function that autoderefs.~~ This works, because autoderefs are done before calling `pick_core`, in `method_autoderef_steps`, called by `probe_op`.
- [x] ~~I should probably move the new `Pick` to `pick_autorefd_method`. If not, I should move it to its own function.~~ Done.
- [ ] ~~Test this with a `Pick` with `to_ptr = true` and `unsize = true`.~~ I think this case cannot happen, because we don't have any array methods with `*mut [X]` receiver. I should confirm that this is true and document this. I've placed two assertions about this.
- [x] ~~Maybe give `(Mutability, bool)` a name and fields~~ I now have a `to_const_ptr` field in `Pick`.
- [x] ~~Changes in `adjust_self_ty` is quite hacky. The problem is we can't deref a pointer, and even if we don't have an adjustment to get the address of a value, so to go from `*mut` to `*const` we need a special case.~~ There's still a special case for `to_const_ptr`, but I'm not sure if we can avoid this.
- [ ] Figure out how `reached_raw_pointer` stuff is used. I suspect only for error messages.

Fixes #80258
2021-03-13 04:38:39 +00:00
Tyson Nottingham adcbe49b16 rustc_query_system: simplify QueryCache::iter
Minor cleanup to reduce a small amount of complexity and code bloat.
Reduces the number of mono items in rustc_query_impl by 15%.
2021-03-12 17:34:14 -08:00
Yuki Okushi fafbc91e0e
Rollup merge of #83037 - kubo39:merge-functions-in-llvm-new-pass-manager, r=nikic
Support merge_functions option in NewPM since LLVM >= 12

now we can pass this flag since https://reviews.llvm.org/D93002 has been merged.
2021-03-13 09:44:45 +09:00
Yuki Okushi 04e24ae67e
Rollup merge of #83020 - hi-rustin:rustin-patch-enum, r=lcnr
Emit the enum range assumption if the range only contains one element

close https://github.com/rust-lang/rust/issues/82871
2021-03-13 09:44:44 +09:00
Yuki Okushi fa3f1865f6
Rollup merge of #82984 - camsteffen:lower-block, r=cjgillot
Simplify ast block lowering
2021-03-13 09:44:42 +09:00
Camille GILLOT 445b4e379c Make def_key and HIR parenting consistent. 2021-03-12 22:48:32 +01:00
Yuki Okushi 0466b6ac6d Improve the wording for the `can't reassign` error 2021-03-13 06:06:54 +09:00
Oli Scherer 11ddd22510 Run rustfmt 2021-03-12 13:46:39 +00:00
Oli Scherer c51749af6e We won't support trait object constants in type level constants for the forseeable future 2021-03-12 13:00:16 +00:00
Oli Scherer 6ca1d87194 Visit `mir::Constant::user_ty` for completeness.
It's not necessary yet, but it may become necessary with things like lazy normalization.
2021-03-12 12:59:37 +00:00
Oli Scherer 20f737966e Replace a custom lift method with a Lift impl 2021-03-12 12:44:12 +00:00
Oli Scherer 3127a9c60f Prepare mir::Constant for ty::Const only supporting valtrees 2021-03-12 12:43:54 +00:00
Oli Scherer 3ecde6f5db Directly intern allocations so that we can write a `Lift` impl for them 2021-03-12 12:34:29 +00:00
Oli Scherer 914df2a493 Add `ty` helper function for mir constants
This is in preparation of the `literal` field becoming an enum that distinguishes between type level constants and runtime constants
2021-03-12 12:33:46 +00:00
Oli Scherer d5eec653c0 Use the explicit error constant instead of fake dummies 2021-03-12 12:25:08 +00:00
Oli Scherer 0bb367e070 Split pretty printer logic for scalar int and scalar ptr
Value trees won't have scalar ptr at all, so we need a scalar int printing method anyway. This way we'll be able to share that method between all const representations.
2021-03-12 12:24:29 +00:00
Oli Scherer b729cc9d61 Pull out ConstValue relating into its own function 2021-03-12 12:23:50 +00:00
Oli Scherer 5e8a89b2e5 Reduce the duplication in the relation logic for constants 2021-03-12 12:23:11 +00:00
Oli Scherer 4d917faa99 Reduce destructuring and re-interning where possible 2021-03-12 12:22:33 +00:00
Oli Scherer 019dba0ceb Resolve a FIXME around type equality checks in Relate for constants 2021-03-12 12:21:55 +00:00
Oli Scherer 09f7f91532 Add convenience conversion methods for ScalarInt 2021-03-12 12:20:54 +00:00
Oli Scherer 858216cabf Add fallible Scalar to ScalarInt conversion method 2021-03-12 12:20:14 +00:00
Oli Scherer 0fe4f38769 Intern valtree field vector 2021-03-12 12:19:17 +00:00
Oli Scherer a4fbac163e Implement valtree
valtree is a version of constants that is inherently safe to be used within types.
This is in contrast to ty::Const which can have different representations of the same value. These representation differences can show up in hashing or equality comparisons, breaking type equality of otherwise equal types.
valtrees do not have this problem.
2021-03-12 12:16:14 +00:00
bors 338647db73 Auto merge of #82422 - petrochenkov:allunst, r=oli-obk
expand: Do not allocate `Lrc` for `allow_internal_unstable` list unless necessary

This allocation is done for any macro defined in the current crate, or used from a different crate.
EDIT: This also removes an `Lrc` increment from each *use* of such macro, which may be more significant.
Noticed when reviewing https://github.com/rust-lang/rust/pull/82367.
This probably doesn't matter, but let's do a perf run.
2021-03-12 11:46:50 +00:00
bors 0cc64a34e9 Auto merge of #82935 - henryboisdequin:diagnostic-cleanups, r=estebank
Diagnostic cleanups

Follow up to #81503
Helps with #82916 (don't show note if `span` is `DUMMY_SP`)
2021-03-12 09:05:38 +00:00
hi-rustin d180f91824 Emit the enum range assumption if the range only contains one element
test: add test case

make tidy happy
2021-03-12 12:06:10 +08:00
Hiroki Noda 8357e57346 Add support for storing code model to LLVM module IR
This patch avoids undefined behavior by linking different object files.
Also this would it could be propagated properly to LTO.

See https://reviews.llvm.org/D52322 and https://reviews.llvm.org/D52323.

This patch is based on https://github.com/rust-lang/rust/pull/74002
2021-03-12 11:02:25 +09:00
Henry Boisdequin 26478c81fd Don't show note if `span` is `DUMMY_SP` 2021-03-12 06:18:33 +05:30
Yuki Okushi 14846d945d
Rollup merge of #83018 - oli-obk:float_check, r=davidtwco
Reintroduce accidentally deleted assertions.

These were removed in https://github.com/rust-lang/rust/pull/50198
2021-03-12 08:55:22 +09:00
Yuki Okushi 5ab8f53a71
Rollup merge of #83013 - hyd-dev:cfg-unix-windows, r=bjorn3
Adjust some `#[cfg]`s to take non-Unix non-Windows operating systems into account

This makes compilation to such targets (e.g. `wasm32-wasi`) easier.

cc rust-lang/miri#722 bb6d1d0a09 (r48100619)
2021-03-12 08:55:21 +09:00
Hiroki Noda 65ed23c282 Support merge_functions option in NewPM since LLVM >= 12
now we can pass this flag since https://reviews.llvm.org/D93002 has been
merged.
2021-03-12 08:16:10 +09:00
Guillaume Gomez 1d26e6b632 Improve code by removing similar function calls and using loops instead for collecting iterators 2021-03-11 22:33:40 +01:00
LeSeulArtichaut 6bf4147646 Add `-Z unpretty` flag for the THIR 2021-03-11 19:42:40 +01:00
LeSeulArtichaut 2a34428253 Make THIR data structures public 2021-03-11 19:42:39 +01:00
csmoe 77fb6a0f32 fix: check before index into generated patterns 2021-03-12 01:54:08 +08:00
csmoe 2fd2796aae add ui testcase for issue 82772 2021-03-12 01:53:55 +08:00
bors 61365c0625 Auto merge of #82495 - LeSeulArtichaut:eager-thir, r=oli-obk
Eagerly construct bodies of THIR

With this PR:
 - the THIR is no longer constructed lazily, but is entirely built before being passed to the MIR Builder
 - the THIR is now allocated in arenas instead of `Box`es

However, this PR doesn't make any changes to the way patterns are constructed: they are still boxed, and exhaustiveness checking is unchanged.

Implements MCP rust-lang/compiler-team#409.
Closes rust-lang/project-thir-unsafeck#1.
r? `@ghost` cc `@nikomatsakis` `@oli-obk`
2021-03-11 15:34:01 +00:00
Oli Scherer c69b108d2a Reintroduce accidentally deleted assertions.
These were removed in https://github.com/rust-lang/rust/pull/50198
2021-03-11 14:56:03 +00:00
Camille GILLOT 34e92bbf65 Hash SyntaxContext first. 2021-03-11 12:31:31 +01:00
Camille GILLOT fe2d728e62 Remove useless method. 2021-03-11 12:24:58 +01:00
Camille GILLOT 84bf599bac Add inlining. 2021-03-11 12:24:43 +01:00
hyd-dev 00c08727c8
Adjust some `#[cfg]`s to take non-Unix non-Windows operating systems into account 2021-03-11 18:03:32 +08:00
bors 04fce73196 Auto merge of #82641 - camelid:lang-item-docs, r=jyn514
Improve lang item generated docs

cc https://rust-lang.zulipchat.com/#narrow/stream/146229-wg-secure-code/topic/Is.20.60core.60.20part.20of.20the.20compiler.3F/near/226738260

r? `@jyn514`
2021-03-11 06:38:22 +00:00
bors b3ac52646f Auto merge of #82964 - Nicholas-Baron:shorten_middle_ty, r=jackh726
Shorten `rustc_middle::ty::mod`

Related to #60302.

This PR moves all `Adt*`, `Assoc*`, `Generic*`, and `UpVar*` types to separate files.
This, alongside some `use` reordering, puts `mod.rs` at ~2,200 lines, thus removing the `// ignore-tidy-filelength`.

The particular groups were chosen as they had 4 or more "substantive" members.
2021-03-11 04:09:44 +00:00
Josh Stone f7e75a2124 Update to rustc-rayon 0.3.1
This pulls in rust-lang/rustc-rayon#8 to fix #81425. (h/t @ammaraskar)

That revealed weak constraints on `rustc_arena::DropArena`, because its
`DropType` was holding type-erased raw pointers to generic `T`. We can
implement `Send` for `DropType` (under `cfg(parallel_compiler)`) by
requiring all `T: Send` before they're type-erased.
2021-03-10 17:53:35 -08:00
Tomasz Miąsko 49431909a6 Validate rustc_layout_scalar_valid_range_{start,end} attributes 2021-03-11 00:00:00 +00:00
Tomasz Miąsko 1ba71abddd Inline Attribute::has_name 2021-03-11 16:04:14 +01:00
Nicholas-Baron d022142ade Moved more of the capture related types into closure.rs 2021-03-10 14:32:14 -08:00
Nicholas-Baron 90cbb39d74 Moved more types into upvar.rs (now named closure.rs) 2021-03-10 14:32:14 -08:00
Nicholas-Baron 0ba5a6b6e5 Moved all Adt* types to adt.rs 2021-03-10 14:32:14 -08:00
Nicholas-Baron ffcf7e8b6d Moved all Assoc* types to assoc.rs. 2021-03-10 14:32:13 -08:00
Nicholas-Baron 11e41b052f Moved types starting with 'Generic' into generics.rs. 2021-03-10 14:32:13 -08:00
Nicholas-Baron 5375575717 Moved UpVar* types to a separate file. 2021-03-10 14:32:13 -08:00
Nicholas-Baron e4884c1d50 Grouped some ungrouped use and mod lines. 2021-03-10 14:32:13 -08:00
bors f98721f886 Auto merge of #82982 - Dylan-DPC:rollup-mt497z7, r=Dylan-DPC
Rollup of 9 pull requests

Successful merges:

 - #81309 (always eagerly eval consts in Relate)
 - #82217 (Edition-specific preludes)
 - #82807 (rustdoc: Remove redundant enableSearchInput function)
 - #82924 (WASI: Switch to crt1-command.o to enable support for new-style commands)
 - #82949 (Do not attempt to unlock envlock in child process after a fork.)
 - #82955 (fix: wrong word)
 - #82962 (Treat header as first paragraph for shortened markdown descriptions)
 - #82976 (fix error message for copy(_nonoverlapping) overflow)
 - #82977 (Rename `Option::get_or_default` to `get_or_insert_default`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-03-10 19:12:53 +00:00
Camelid ab42f96cff Remove unnecessary `#[allow(dead_code)]` 2021-03-10 10:27:04 -08:00
Camelid d31f70c87c Clarify docs 2021-03-10 09:20:53 -08:00
Camelid b782939c06 Remove `sym::` and `kw::` from generated docs 2021-03-10 09:15:16 -08:00
Cameron Steffen a808822093 Simplify lower ast block 2021-03-10 11:12:01 -06:00
Camelid 4900836ab7 Fix bug
It needs to be a variable!

Co-authored-by: Joshua Nelson <joshua@yottadb.com>
2021-03-10 09:03:45 -08:00
Dylan DPC e58313248a
Rollup merge of #82977 - camsteffen:opt-get-insert-def, r=m-ou-se
Rename `Option::get_or_default` to `get_or_insert_default`

...as [suggested](https://github.com/rust-lang/rust/issues/82901#issuecomment-793548515) by `@m-ou-se.` In hindsight this seems rather obvious, at least to me.

r? `@joshtriplett`
2021-03-10 17:55:47 +01:00
Dylan DPC f5196aea65
Rollup merge of #82976 - RalfJung:copy-nonoverlapping, r=oli-obk
fix error message for copy(_nonoverlapping) overflow

Fixes an error message regression introduced in https://github.com/rust-lang/rust/pull/77511 (and adds tests).

r? `@oli-obk`
2021-03-10 17:55:46 +01:00
Dylan DPC b9a2570c9b
Rollup merge of #82955 - ltoddy:fix/wrong, r=jonas-schievink
fix: wrong word
2021-03-10 17:55:44 +01:00
Dylan DPC 881bbb758a
Rollup merge of #82924 - sunfishcode:wasi-command, r=alexcrichton
WASI: Switch to crt1-command.o to enable support for new-style commands

This switches Rust's WASI target to use crt1-command.o instead of
crt1.o, which enables support for new-style commands. By default,
new-style commands work the same way as old-style commands, so nothing
immediately changes here, but this will be needed by later changes to
enable support for typed arguments.

See here for more information on new-style commands:
 - https://github.com/WebAssembly/wasi-libc/pull/203
 - https://reviews.llvm.org/D81689

r? ```@alexcrichton```
2021-03-10 17:55:41 +01:00
Dylan DPC 759204ffc4
Rollup merge of #82217 - m-ou-se:edition-prelude, r=nikomatsakis
Edition-specific preludes

This changes `{std,core}::prelude` to export edition-specific preludes under `rust_2015`, `rust_2018` and `rust_2021`. (As suggested in https://github.com/rust-lang/rust/issues/51418#issuecomment-395630382.) For now they all just re-export `v1::*`, but this allows us to add things to the 2021edition prelude soon.

This also changes the compiler to make the automatically injected prelude import dependent on the selected edition.

cc `@rust-lang/libs` `@djc`
2021-03-10 17:55:38 +01:00
Dylan DPC 49bf48a33d
Rollup merge of #81309 - lcnr:lazy-norm-err-msgh, r=nikomatsakis
always eagerly eval consts in Relate

r? ```@nikomatsakis``` cc ```@varkor```
2021-03-10 17:55:37 +01:00
bors 17a07d71bf Auto merge of #76570 - cratelyn:implement-rfc-2945-c-unwind-abi, r=Amanieu
Implement RFC 2945: "C-unwind" ABI

## Implement RFC 2945: "C-unwind" ABI

This branch implements [RFC 2945]. The tracking issue for this RFC is #74990.

The feature gate for the issue is `#![feature(c_unwind)]`.

This RFC was created as part of the ffi-unwind project group tracked at rust-lang/lang-team#19.

### Changes

Further details will be provided in commit messages, but a high-level overview
of the changes follows:

* A boolean `unwind` payload is added to the `C`, `System`, `Stdcall`,
and `Thiscall` variants, marking whether unwinding across FFI boundaries is
acceptable. The cases where each of these variants' `unwind` member is true
correspond with the `C-unwind`, `system-unwind`, `stdcall-unwind`, and
`thiscall-unwind` ABI strings introduced in RFC 2945 [3].

* This commit adds a `c_unwind` feature gate for the new ABI strings.
Tests for this feature gate are included in `src/test/ui/c-unwind/`, which
ensure that this feature gate works correctly for each of the new ABIs.
A new language features entry in the unstable book is added as well.

* We adjust the `rustc_middle::ty::layout::fn_can_unwind` function,
used to compute whether or not a `FnAbi` object represents a function that
should be able to unwind when `panic=unwind` is in use.

* Changes are also made to
`rustc_mir_build::build::should_abort_on_panic` so that the function ABI is
used to determind whether it should abort, assuming that the `panic=unwind`
strategy is being used, and no explicit unwind attribute was provided.

[RFC 2945]: https://github.com/rust-lang/rfcs/blob/master/text/2945-c-unwind-abi.md
2021-03-10 16:44:04 +00:00
Cameron Steffen b0514a6a0a Rename Option::get_or_insert_default 2021-03-10 09:07:16 -06:00
Ralf Jung 55c88f594c fix error message for copy(_nonoverlapping) overflow 2021-03-10 15:50:44 +01:00
bors 5fe790e3c4 Auto merge of #82884 - nagisa:nagisa/remove-most-of-sideeffect-inserts, r=nikic
Remove the -Zinsert-sideeffect

This removes all of the code we had in place to work-around LLVM's
handling of forward progress. From this removal excluded is a workaround
where we'd insert a `sideeffect` into clearly infinite loops such as
`loop {}`. This code remains conditionally effective when the LLVM
version is earlier than 12.0, which fixed the forward progress related
miscompilations at their root.
2021-03-10 14:03:00 +00:00
bors a4d9624242 Auto merge of #82967 - RalfJung:copy-nonoverlap, r=oli-obk
fix copy_nonoverlapping

Fixes a bug introduced by https://github.com/rust-lang/rust/pull/77511

r? `@oli-obk`
Fixes https://github.com/rust-lang/rust/issues/82961
2021-03-10 11:21:46 +00:00
Simonas Kazlauskas 0517acd543 Remove the -Zinsert-sideeffect
This removes all of the code we had in place to work-around LLVM's
handling of forward progress. From this removal excluded is a workaround
where we'd insert a `sideeffect` into clearly infinite loops such as
`loop {}`. This code remains conditionally effective when the LLVM
version is earlier than 12.0, which fixed the forward progress related
miscompilations at their root.
2021-03-10 12:21:43 +02:00
Guillaume Gomez bbbefa3edc Allow doc alias attributes to use both list and value 2021-03-10 10:17:37 +01:00
bors dff1edf919 Auto merge of #79519 - cjgillot:noattr, r=wesleywiser
Store HIR attributes in a side table

Same idea as #72015 but for attributes.
The objective is to reduce incr-comp invalidations due to modified attributes.
Notably, those due to modified doc comments.

Implementation:
- collect attributes during AST->HIR lowering, in `LocalDefId -> ItemLocalId -> &[Attributes]` nested tables;
- access the attributes through a `hir_owner_attrs` query;
- local refactorings to use this access;
- remove `attrs` from HIR data structures one-by-one.

Change in behaviour:
- the HIR visitor traverses all attributes at once instead of parent-by-parent;
- attribute arrays are sometimes duplicated: for statements and variant constructors;
- as a consequence, attributes are marked as used after unused-attribute lint emission to avoid duplicate lints.

~~Current bug: the lint level is not correctly applied in `std::backtrace_rs`, triggering an unused attribute warning on `#![no_std]`. I welcome suggestions.~~
2021-03-10 08:40:51 +00:00
Ralf Jung 9f27a13f5f fix copy_nonoverlapping 2021-03-10 09:21:18 +01:00
Aman Arora 612a9b2f95 2229: Handle capturing a reference into a repr packed struct
RFC 1240 states that it is unsafe to capture references into a
packed-struct. This PR ensures that when a closure captures a precise
path, we aren't violating this safety constraint.

To acheive so we restrict the capture precision to the struct itself.

An interesting edge case:
```rust
struct Foo(String);

let foo: Foo;
let c = || {
    println!("{}", foo.0);
    let x = foo.0;
}
```

Given how closures get desugared today, foo.0 will be moved into the
closure, making the `println!`, safe. However this can be very subtle
and also will be unsafe if the closure gets inline.

Closes: https://github.com/rust-lang/project-rfc-2229/issues/33
2021-03-09 20:23:02 -05:00
ltoddy 37543ce656 fix: wrong word 2021-03-10 09:09:37 +08:00
Yuki Okushi 9dc82face3
Rollup merge of #82942 - m-ou-se:diagnostics-hardcoded-prelude-v1, r=estebank
Don't hardcode the `v1` prelude in diagnostics, to allow for new preludes.

Instead of looking for `std::prelude::v1`, this changes the two places where that was hardcoded to look for `std::prelude::<anything>` instead.

This is needed for https://github.com/rust-lang/rust/pull/82217.

r? `@estebank`
2021-03-10 08:01:37 +09:00
Yuki Okushi 56b5393cc2
Rollup merge of #82938 - oli-obk:tracing_tree_bump, r=Mark-Simulacrum
Bump tracing-tree dependency

This bump fixes two small rendering things that were annoying me:

* The first level didn't have an opening line
* When wraparound happens, there was no warning, the levels just disappeared. Now there is a line that shows that wraparound is happening

See https://github.com/davidbarsky/tracing-tree/pull/31/files for how the look changes
2021-03-10 08:01:36 +09:00
Yuki Okushi 1c3fea2f8c
Rollup merge of #82849 - camsteffen:option-get-or-default, r=joshtriplett
Add Option::get_or_default

Tracking issue: #82901

The original issue is #55042, which was closed, but for an invalid reason (see discussion there). Opening this to reconsider (I hope that's okay). It seems like the only gap for `Option` being "entry-like".

I ran into a need for this method where I had a `Vec<Option<MyData>>` and wanted to do `vec[n].get_or_default().my_data_method()`. Using an `Option` as an inner component of a data structure is probably where the need for this will normally arise.
2021-03-10 08:01:32 +09:00
Yuki Okushi 761a2b389d
Rollup merge of #82733 - Yn0ga:master, r=estebank
Add powerpc-unknown-openbsd target
2021-03-10 08:01:29 +09:00
Yuki Okushi c46f948a80
Rollup merge of #79208 - LeSeulArtichaut:stable-unsafe_op_in_unsafe_fn, r=nikomatsakis
Stabilize `unsafe_op_in_unsafe_fn` lint

This makes it possible to override the level of the `unsafe_op_in_unsafe_fn`, as proposed in https://github.com/rust-lang/rust/issues/71668#issuecomment-729770896.

Tracking issue: #71668
r? ```@nikomatsakis``` cc ```@SimonSapin``` ```@RalfJung```

# Stabilization report

This is a stabilization report for `#![feature(unsafe_block_in_unsafe_fn)]`.

## Summary

Currently, the body of unsafe functions is an unsafe block, i.e. you can perform unsafe operations inside.

The `unsafe_op_in_unsafe_fn` lint, stabilized here, can be used to change this behavior, so performing unsafe operations in unsafe functions requires an unsafe block.

For now, the lint is allow-by-default, which means that this PR does not change anything without overriding the lint level.

For more information, see [RFC 2585](https://github.com/rust-lang/rfcs/blob/master/text/2585-unsafe-block-in-unsafe-fn.md)

### Example

```rust
// An `unsafe fn` for demonstration purposes.
// Calling this is an unsafe operation.
unsafe fn unsf() {}

// #[allow(unsafe_op_in_unsafe_fn)] by default,
// the behavior of `unsafe fn` is unchanged
unsafe fn allowed() {
    // Here, no `unsafe` block is needed to
    // perform unsafe operations...
    unsf();

    // ...and any `unsafe` block is considered
    // unused and is warned on by the compiler.
    unsafe {
        unsf();
    }
}

#[warn(unsafe_op_in_unsafe_fn)]
unsafe fn warned() {
    // Removing this `unsafe` block will
    // cause the compiler to emit a warning.
    // (Also, no "unused unsafe" warning will be emitted here.)
    unsafe {
        unsf();
    }
}

#[deny(unsafe_op_in_unsafe_fn)]
unsafe fn denied() {
    // Removing this `unsafe` block will
    // cause a compilation error.
    // (Also, no "unused unsafe" warning will be emitted here.)
    unsafe {
        unsf();
    }
}
```
2021-03-10 08:01:25 +09:00
katelyn a. martin 05bf037fec address pr review comments
### Add debug assertion to check `AbiDatas` ordering

    This makes a small alteration to `Abi::index`, so that we include a
    debug assertion to check that the index we are returning corresponds
    with the same abi in our data array.

    This will help prevent ordering bugs in the future, which can
    manifest in rather strange errors.

 ### Using exhaustive ABI matches

    This slightly modifies the changes from our previous commits,
    favoring exhaustive matches in place of `_ => ...` fall-through
    arms.

    This should help with maintenance in the future, when additional
    ABI's are added, or when existing ABI's are modified.

 ### List all `-unwind` ABI's in unstable book

    This updates the `c-unwind` page in the unstable book to list _all_
    of the other ABI strings that are introduced by this feature gate.

    Now, all of the ABI's specified by RFC 2945 are shown.

Co-authored-by: Amanieu d'Antras <amanieu@gmail.com>
Co-authored-by: Niko Matsakis <niko@alum.mit.edu>
2021-03-09 14:40:33 -05:00
katelyn a. martin 0f33e9f281 implement unwinding abi's (RFC 2945)
### Changes

    This commit implements unwind ABI's, specified in RFC 2945.

    We adjust the `rustc_middle::ty::layout::fn_can_unwind` function,
    used to compute whether or not a `FnAbi` object represents a
    function that should be able to unwind when `panic=unwind` is in
    use.

    Changes are also made to
    `rustc_mir_build::build::should_abort_on_panic` so that the
    function ABI is used to determind whether it should abort, assuming
    that the `panic=unwind` strategy is being used, and no explicit
    unwind attribute was provided.

 ### Tests

    Unit tests, checking that the behavior is correct for `C-unwind`,
    `stdcall-unwind`, `system-unwind`, and `thiscall-unwind`, are
    included. These alternative `unwind` ABI strings are specified in
    RFC 2945, in the "_Other `unwind` ABI strings_" section.

    Additionally, a test case is included to assert that the LLVM IR
    generated for an external function defined with the `C-unwind` ABI
    will be appropriately labeled with the `nounwind` LLVM attribute
    when the `panic=abort` compilation flag is used.

 ### Ignore Directives

    This commit uses `ignore-*` directives in two of our `*-unwind` ABI
    test cases.

    Specifically, the `stdcall-unwind` and `thiscall-unwind` test cases
    ignore architectures that do not support `stdcall` and `thiscall`,
    respectively.

    These directives are cribbed from
    `src/test/ui/c-variadic/variadic-ffi-1.rs` for `stdcall`, and
    `src/test/ui/extern/extern-thiscall.rs` for `thiscall`.
2021-03-09 14:38:29 -05:00
katelyn a. martin df45c579de rustc_target: add "unwind" payloads to `Abi`
### Overview

    This commit begins the implementation work for RFC 2945. For more
    information, see the rendered RFC [1] and tracking issue [2].

    A boolean `unwind` payload is added to the `C`, `System`, `Stdcall`,
    and `Thiscall` variants, marking whether unwinding across FFI
    boundaries is acceptable. The cases where each of these variants'
    `unwind` member is true correspond with the `C-unwind`,
    `system-unwind`, `stdcall-unwind`, and `thiscall-unwind` ABI strings
    introduced in RFC 2945 [3].

 ### Feature Gate and Unstable Book

    This commit adds a `c_unwind` feature gate for the new ABI strings.
    Tests for this feature gate are included in `src/test/ui/c-unwind/`,
    which ensure that this feature gate works correctly for each of the
    new ABIs.

    A new language features entry in the unstable book is added as well.

 ### Further Work To Be Done

    This commit does not proceed to implement the new unwinding ABIs,
    and is intentionally scoped specifically to *defining* the ABIs and
    their feature flag.

 ### One Note on Test Churn

    This will lead to some test churn, in re-blessing hash tests, as the
    deleted comment in `src/librustc_target/spec/abi.rs` mentioned,
    because we can no longer guarantee the ordering of the `Abi`
    variants.

    While this is a downside, this decision was made bearing in mind
    that RFC 2945 states the following, in the "Other `unwind` Strings"
    section [3]:

    >  More unwind variants of existing ABI strings may be introduced,
    >  with the same semantics, without an additional RFC.

    Adding a new variant for each of these cases, rather than specifying
    a payload for a given ABI, would quickly become untenable, and make
    working with the `Abi` enum prone to mistakes.

    This approach encodes the unwinding information *into* a given ABI,
    to account for the future possibility of other `-unwind` ABI
    strings.

 ### Ignore Directives

    `ignore-*` directives are used in two of our `*-unwind` ABI test
    cases.

    Specifically, the `stdcall-unwind` and `thiscall-unwind` test cases
    ignore architectures that do not support `stdcall` and
    `thiscall`, respectively.

    These directives are cribbed from
    `src/test/ui/c-variadic/variadic-ffi-1.rs` for `stdcall`, and
    `src/test/ui/extern/extern-thiscall.rs` for `thiscall`.

    This would otherwise fail on some targets, see:
    fcf697f902

 ### Footnotes

[1]: https://github.com/rust-lang/rfcs/blob/master/text/2945-c-unwind-abi.md
[2]: https://github.com/rust-lang/rust/issues/74990
[3]: https://github.com/rust-lang/rfcs/blob/master/text/2945-c-unwind-abi.md#other-unwind-abi-strings
2021-03-09 14:38:29 -05:00
kadmin 4bceb294f4 Clean up todos
Also add some span_bugs where it is unreachable
2021-03-09 19:31:31 +00:00
LeSeulArtichaut d6c737adb5 Take into account `ExprKind::Scope` when calculating span of temporary 2021-03-09 20:15:03 +01:00
LeSeulArtichaut 5f38c839ad Prevent stack overflow when building THIR 2021-03-09 20:15:01 +01:00
LeSeulArtichaut cd049ef9ea Remove useless references/dereferences 2021-03-09 20:15:01 +01:00
LeSeulArtichaut c2c4322891 Make arena allocation for the THIR work 2021-03-09 20:14:42 +01:00
LeSeulArtichaut a9f4dfc8fa Remove `Clone` impl for `thir::Expr` 2021-03-09 20:13:59 +01:00
LeSeulArtichaut 2a2b4d7257 Pull `thir::Cx` out of the MIR `Builder` 2021-03-09 20:13:58 +01:00
LeSeulArtichaut 60def4de5e [WIP] Eagerly construct bodies of THIR 2021-03-09 20:12:41 +01:00
Mara Bos 1e4d8042fc Don't hardcode the `v1` prelude in diagnostics.
Instead of looking for `std::prelude::v1`, this changes it to look for
`std::prelude::<anything>`.
2021-03-09 19:41:04 +01:00
Camille GILLOT 38d9d09a58 Use BTreeMap to store attributes. 2021-03-09 19:28:01 +01:00
Camille GILLOT 90a562c7ff Deduplicate unchecked_attrs errors. 2021-03-09 19:28:00 +01:00
Camille GILLOT 2658fb7783 Alias attributes of hir::Stmt.
The attributes for statements and those of the statements' content.
2021-03-09 19:28:00 +01:00
Camille GILLOT 27ef0eeaa4 Track HirId when visiting attributes. 2021-03-09 19:27:59 +01:00
Camille GILLOT fb753cced8 Remove hir::Expr::attrs. 2021-03-09 19:27:58 +01:00
Camille GILLOT c701872a6c Remove hir::Item::attrs. 2021-03-09 19:27:50 +01:00
Camille GILLOT 5474f17011 Remove hir::ImplItem::attrs. 2021-03-09 19:23:08 +01:00
Camille GILLOT c49359add2 Remove hir::TraitItem::attrs. 2021-03-09 19:23:08 +01:00
Camille GILLOT 4bab93a039 Remove hir::ForeignItem::attrs. 2021-03-09 19:23:07 +01:00
Camille GILLOT c298744da7 Remove hir::StructField::attrs. 2021-03-09 19:23:07 +01:00
Camille GILLOT 3c0afc3e1c Remove hir::Variant::attrs. 2021-03-09 19:23:06 +01:00
Camille GILLOT a0a4611a81 Remove hir::Param::attrs. 2021-03-09 19:23:06 +01:00
Camille GILLOT 96788df68c Remove hir::Arm::attrs. 2021-03-09 19:23:05 +01:00
Camille GILLOT a987bbb97c Remove hir::Crate::attrs. 2021-03-09 19:22:55 +01:00
Camille GILLOT c05c90275c Remove hir::MacroDef::attrs. 2021-03-09 19:09:36 +01:00
Camille GILLOT fd8a021757 Remove hir::GenericParam::attrs. 2021-03-09 19:09:36 +01:00
Camille GILLOT 7ea1eacb17 Remove hir::Local::attrs. 2021-03-09 19:09:35 +01:00
Camille GILLOT ff79ad394f Remove hir::StmtKind::attrs. 2021-03-09 19:09:35 +01:00
Camille GILLOT 4bb07bedf5 Visit attributes in one go. 2021-03-09 19:09:34 +01:00
Camille GILLOT 8e816056a5 Do not store attrs in FnKind. 2021-03-09 19:09:33 +01:00
Camille GILLOT 99ba08e6d3 Access attrs directly from HirId in rustc_passes::diagnostic_item. 2021-03-09 19:09:32 +01:00
Camille GILLOT 662f11ade6 Access attrs directly from HirId in rustc_lint::builtin. 2021-03-09 19:09:31 +01:00
Camille GILLOT 260aa9f554 Access attrs directly from HirId in rustc_passes::lang_items. 2021-03-09 19:09:31 +01:00
Camille GILLOT a50454d6c8 Access attrs directly from HirId in rustc_passes::dead. 2021-03-09 19:09:30 +01:00
Camille GILLOT f8514aaa56 Access attrs directly from HirId in rustc_passes::stability. 2021-03-09 19:09:06 +01:00
Camille GILLOT 0c883504fb Access attrs directly from HirId in rustc_incremental::assert_dep_graph. 2021-03-09 18:51:37 +01:00
Camille GILLOT 7b1dd1a9e8 Access attrs directly from HirId in rustc_passes::check_attr. 2021-03-09 18:51:37 +01:00
Camille GILLOT 7e16e1e815 Access attrs directly from HirId in rustc_lint::levels. 2021-03-09 18:51:37 +01:00
Camille GILLOT b84bdf1dae Access attrs directly from HirId in rustc_lint::late. 2021-03-09 18:51:37 +01:00
Camille GILLOT 4a21af67e3 Take a slice in stmt_let_pat. 2021-03-09 18:51:37 +01:00
Camille GILLOT 1fb257b3b4 Collect attributes during HIR lowering. 2021-03-09 18:51:37 +01:00
Camille GILLOT d50ca3cbee Introduce HirIdVec. 2021-03-09 18:51:36 +01:00
Camille GILLOT 736fc96ff3 Remove useless Clone bound in IndexVec. 2021-03-09 18:51:36 +01:00
kadmin 217ff6b7ea Switch to changing cp_non_overlap in tform
It was suggested to lower this in MIR instead of ssa, so do that instead.
2021-03-09 16:54:14 +00:00
kadmin d4ae9ff826 Build StKind::CopyOverlapping
This replaces where it was previously being constructed in intrinsics, with direct construction
of the Statement.
2021-03-09 16:54:14 +00:00
kadmin 845e4b5962 Change CopyNonOverlapping::codegen_ssa
Fixes copy_non_overlapping codegen_ssa to properly handle pointees,
and use bytes instead of elem count
2021-03-09 16:54:14 +00:00
kadmin 049045b100 Replace todos with impls
Changed to various implementations, copying the style of prior function calls in places I was
unsure of.

Also one minor style nit.
2021-03-09 16:54:14 +00:00
kadmin 982382dc03 Update cranelift 2021-03-09 16:54:14 +00:00
kadmin 37a6c04718 Update interpret step 2021-03-09 16:54:13 +00:00
kadmin 89f45ed9f3 Update match branches
This updates all places where match branches check on StatementKind or UseContext.
This doesn't properly implement them, but adds TODOs where they are, and also adds some best
guesses to what they should be in some cases.
2021-03-09 16:54:13 +00:00
kadmin 72c734d001 Update fmt and use of memcpy
I'm still not totally sure if this is the right way to implement the memcpy, but that portion
compiles correctly now. Now to fix the compile errors everywhere else :).
2021-03-09 16:54:13 +00:00
kadmin 0fdc07e197 Impl StatementKind::CopyNonOverlapping 2021-03-09 16:54:13 +00:00
Oli Scherer 62f2d72330 Bump tracing-tree dependency 2021-03-09 16:44:51 +00:00
Ömer Sinan Ağacan 98fbc09f02 Allow calling *const methods on *mut values
Fixes #80258
2021-03-09 13:40:08 +03:00
Mara Bos bb9542b016
Rollup merge of #82841 - hvdijk:x32, r=joshtriplett
Change x64 size checks to not apply to x32.

Rust contains various size checks conditional on target_arch = "x86_64", but these checks were never intended to apply to x86_64-unknown-linux-gnux32. Add target_pointer_width = "64" to the conditions.
2021-03-09 09:05:24 +00:00
Mara Bos 0d97f9b22a
Rollup merge of #82048 - mark-i-m:or-pat-type-ascription, r=petrochenkov
or-patterns: disallow in `let` bindings

~~Blocked on https://github.com/rust-lang/rust/pull/81869~~

Disallows top-level or-patterns before type ascription. We want to reserve this syntactic space for possible future generalized type ascription.

r? ``@petrochenkov``
2021-03-09 09:05:20 +00:00
Henry Boisdequin bba2bac9fe improve `const fn` `RepeatVec` diagnostics 2021-03-09 08:20:50 +05:30
Dan Gohman fdb899ba4b WASI: Switch to crt1-command.o to enable support for new-style commands
This switches Rust's WASI target to use crt1-command.o instead of
crt1.o, which enables support for new-style commands. By default,
new-style commands work the same way as old-style commands, so nothing
immediately changes here, but this will be needed by later changes to
enable support for typed arguments.

See here for more information on new-style commands:
 - https://github.com/WebAssembly/wasi-libc/pull/203
 - https://reviews.llvm.org/D81689
2021-03-08 17:49:34 -08:00
Mara Bos 3908eec60f
Rollup merge of #82881 - Manishearth:crate-root, r=estebank
diagnostics: Be clear about "crate root" and `::foo` paths in resolve diagnostics

Various changes to make sure the diagnostics are clear about the differences in `::foo` paths across editions:

 - `::foo` will say "crate root" in 2015 and "list of imported crates" in 2018
 - `crate::` will never reference imported crates in 2018

Fixes https://github.com/rust-lang/rust/issues/82876
2021-03-08 20:09:06 +01:00
Mara Bos 6a55aa1246
Rollup merge of #82854 - estebank:issue-82827, r=oli-obk
Account for `if (let pat = expr) {}`

Fix #82827.
2021-03-08 20:09:02 +01:00
Mara Bos 0ee2f4c3e0
Rollup merge of #82829 - JohnTitor:handle-neg-val, r=estebank
Handle negative literals in cast overflow warning

Closes #48535
r? `@estebank`
2021-03-08 20:09:01 +01:00
asquared31415 05ae66607f Move default inline asm dialect to Session 2021-03-08 12:16:12 -05:00
Cameron Steffen 1cc8c4de6a Use Option::get_or_default 2021-03-08 09:24:11 -06:00
Dylan DPC 08475e7873
Rollup merge of #82857 - pierwill:edit-ast-lowering-lib, r=Dylan-DPC
Edit ructc_ast_lowering docs

Fixes some punctuation and formatting; also makes some small wording changes.
2021-03-08 13:13:26 +01:00
Dylan DPC 041bc04be4
Rollup merge of #82755 - osa1:confirm_builtin_call_refactor, r=petrochenkov
Refactor confirm_builtin_call, remove partial if

Pass callee expr to `confirm_builtin_call`. This removes a partial
pattern match in `confirm_builtin_call` and the `panic` in the `else`
branch. The diff is large because of indentation changes caused by
removing the if-let.
2021-03-08 13:13:25 +01:00
Dylan DPC dd7a606804
Rollup merge of #82684 - tmiasko:dest-prop, r=jonas-schievink
Disable destination propagation on all mir-opt-levels

The new `// compile-flags: -Zunsound-mir-opts` are inserted without an extra newline to avoid introducing a large mir-opt diff.
2021-03-08 13:13:24 +01:00
Dylan DPC 9c310571a8
Rollup merge of #82682 - petrochenkov:cfgeval, r=Aaron1011
Implement built-in attribute macro `#[cfg_eval]` + some refactoring

This PR implements a built-in attribute macro `#[cfg_eval]` as it was suggested in https://github.com/rust-lang/rust/pull/79078 to avoid `#[derive()]` without arguments being abused as a way to configure input for other attributes.

The macro is used for eagerly expanding all `#[cfg]` and `#[cfg_attr]` attributes in its input ("fully configuring" the input).
The effect is identical to effect of `#[derive(Foo, Bar)]` which also fully configures its input before passing it to macros `Foo` and `Bar`, but unlike `#[derive]` `#[cfg_eval]` can be applied to any syntax nodes supporting macro attributes, not only certain items.

`cfg_eval` was the first name suggested in https://github.com/rust-lang/rust/pull/79078, but other alternatives are also possible, e.g. `cfg_expand`.

```rust
#[cfg_eval]
#[my_attr] // Receives `struct S {}` as input, the field is configured away by `#[cfg_eval]`
struct S {
    #[cfg(FALSE)]
    field: u8,
}
```

Tracking issue: https://github.com/rust-lang/rust/issues/82679
2021-03-08 13:13:23 +01:00
Dylan DPC 7b78d86d6a
Rollup merge of #82642 - sfackler:jemalloc-zone, r=pnkfelix
Fix jemalloc usage on OSX

Closes #82423
2021-03-08 13:13:22 +01:00
Dylan DPC 4a4e3e667d
Rollup merge of #82415 - petrochenkov:modin3, r=davidtwco
expand: Refactor module loading

This is an accompanying PR to https://github.com/rust-lang/rust/pull/82399, but they can be landed independently.
See individual commits for more details.

Anyone should be able to review this equally well because all people actually familiar with this code left the project.
2021-03-08 13:13:19 +01:00
Dylan DPC da74a77622
Rollup merge of #82047 - the8472:fast-rename, r=davidtwco
bypass auto_da_alloc for metadata files

This saves about 0.7% when rerunning the UI test suite. I.e. when the metadata files exist and will be overwritten. No improvements expected for a clean build. So it might show up in incr-patched perf results.
```
regular rename:

Benchmark #1: touch src/tools/compiletest/src/main.rs ; RUSTC_WRAPPER="" schedtool -B -e ./x.py test src/test/ui
  Time (mean ± σ):     47.305 s ±  0.170 s    [User: 1631.540 s, System: 412.648 s]
  Range (min … max):   47.125 s … 47.856 s    20 runs

non-durable rename:

Benchmark #1: touch src/tools/compiletest/src/main.rs ; RUSTC_WRAPPER="" schedtool -B -e ./x.py test src/test/ui
  Time (mean ± σ):     46.930 s ±  0.064 s    [User: 1634.344 s, System: 396.038 s]
  Range (min … max):   46.759 s … 47.043 s    20 runs
```

There are more places that trigger auto_da_alloc behavior by overwriting existing files with O_TRUNC, but those are much harder to locate because `O_TRUNC` is set on `open()` but the writeback is triggered on `close()`. The latter is the part which shows up in profiles.
2021-03-08 13:13:18 +01:00
bors 27885a94c6 Auto merge of #82727 - oli-obk:shrinkmem, r=pnkfelix
Test the effect of shrinking the size of Rvalue by 16 bytes

r? `@ghost`
2021-03-08 08:39:24 +00:00
bors 76c500ec6c Auto merge of #81635 - michaelwoerister:structured_def_path_hash, r=pnkfelix
Let a portion of DefPathHash uniquely identify the DefPath's crate.

This allows to directly map from a `DefPathHash` to the crate it originates from, without constructing side tables to do that mapping -- something that is useful for incremental compilation where we deal with `DefPathHash` instead of `DefId` a lot.

It also allows to reliably and cheaply check for `DefPathHash` collisions which allows the compiler to gracefully abort compilation instead of running into a subsequent ICE at some random place in the code.

The following new piece of documentation describes the most interesting aspects of the changes:

```rust
/// A `DefPathHash` is a fixed-size representation of a `DefPath` that is
/// stable across crate and compilation session boundaries. It consists of two
/// separate 64-bit hashes. The first uniquely identifies the crate this
/// `DefPathHash` originates from (see [StableCrateId]), and the second
/// uniquely identifies the corresponding `DefPath` within that crate. Together
/// they form a unique identifier within an entire crate graph.
///
/// There is a very small chance of hash collisions, which would mean that two
/// different `DefPath`s map to the same `DefPathHash`. Proceeding compilation
/// with such a hash collision would very probably lead to an ICE and, in the
/// worst case, to a silent mis-compilation. The compiler therefore actively
/// and exhaustively checks for such hash collisions and aborts compilation if
/// it finds one.
///
/// `DefPathHash` uses 64-bit hashes for both the crate-id part and the
/// crate-internal part, even though it is likely that there are many more
/// `LocalDefId`s in a single crate than there are individual crates in a crate
/// graph. Since we use the same number of bits in both cases, the collision
/// probability for the crate-local part will be quite a bit higher (though
/// still very small).
///
/// This imbalance is not by accident: A hash collision in the
/// crate-local part of a `DefPathHash` will be detected and reported while
/// compiling the crate in question. Such a collision does not depend on
/// outside factors and can be easily fixed by the crate maintainer (e.g. by
/// renaming the item in question or by bumping the crate version in a harmless
/// way).
///
/// A collision between crate-id hashes on the other hand is harder to fix
/// because it depends on the set of crates in the entire crate graph of a
/// compilation session. Again, using the same crate with a different version
/// number would fix the issue with a high probability -- but that might be
/// easier said then done if the crates in questions are dependencies of
/// third-party crates.
///
/// That being said, given a high quality hash function, the collision
/// probabilities in question are very small. For example, for a big crate like
/// `rustc_middle` (with ~50000 `LocalDefId`s as of the time of writing) there
/// is a probability of roughly 1 in 14,750,000,000 of a crate-internal
/// collision occurring. For a big crate graph with 1000 crates in it, there is
/// a probability of 1 in 36,890,000,000,000 of a `StableCrateId` collision.
```

Given the probabilities involved I hope that no one will ever actually see the error messages. Nonetheless, I'd be glad about some feedback on how to improve them. Should we create a GH issue describing the problem and possible solutions to point to? Or a page in the rustc book?

r? `@pnkfelix` (feel free to re-assign)
2021-03-07 23:45:57 +00:00
Manish Goregaokar 0eeae1abfc diagnostics: Don't mention external crates when hitting import errors on crate imports in 2018 2021-03-07 15:15:19 -08:00
Esteban Küber aa7ac6e957 Remove notes, increase S/N ratio 2021-03-07 15:03:46 -08:00
Esteban Küber 63fb294a74 Add help for `matches` for `if let` in arm guard 2021-03-07 14:44:21 -08:00
Manish Goregaokar 9d5d669b77 diagnostics: Differentiate between edition meanings of ::foo in resolve diagnostics for ::foo::Bar 2021-03-07 14:24:47 -08:00
Manish Goregaokar ac7f9ccb6f diagnostics: Differentiate between edition meanings of ::foo in resolve diagnostics (for bare `::foo`) 2021-03-07 14:21:48 -08:00
Esteban Küber 23bcea4249 Add help suggesting `matches` to `let_chains` lint 2021-03-07 14:17:10 -08:00
Esteban Küber e62a543344 Account for `if (let pat = expr) {}`
Partially address #82827.
2021-03-07 13:49:36 -08:00
bors 234781afe3 Auto merge of #82285 - nhwn:nonzero-debug, r=nagisa
Use u32 over Option<u32> in DebugLoc

~~Changes `Option<u32>` fields in `DebugLoc` to `Option<NonZeroU32>`. Since the respective fields (`line` and `col`) are guaranteed to be 1-based, this layout optimization is a freebie.~~

EDIT: Changes `Option<u32>` fields in `DebugLoc` to `u32`. As `@bugadani` pointed out, an `Option<NonZeroU32>` is probably an unnecessary layer of abstraction since the `None` variant is always used as `UNKNOWN_LINE_NUMBER` (which is just `0`).  Also, `SourceInfo` in `metadata.rs` already uses a `u32` instead of an `Option<u32>` to encode the same information, so I think this change is warranted.

Since `@jyn514` raised some concerns over measuring performance in a similar PR (#82255), does this need a perf run?
2021-03-07 20:23:23 +00:00
pierwill 6b2eb0e6c6 Edit ructc_ast_lowering docs
Fixes some punctuation and formatting; also makes some small wording changes.
2021-03-06 22:07:38 -08:00
Yuki Okushi 74ae20e2c6
Rollup merge of #82822 - henryboisdequin:fix-typo-rustc, r=oli-obk
Fix typo

we need to actually -> we actually need to

````@rustbot```` label +C-cleanup
2021-03-07 10:41:20 +09:00
Yuki Okushi b6191d7c66
Rollup merge of #82808 - bjorn3:sync_cg_clif-2021-03-05, r=bjorn3
Sync rustc_codegen_cranelift

The main highlight of this sync is removal of support for the old x86 Cranelift backend. This made it possible to use native atomic instructions rather than hackishly using a global mutex. 128bit integer support has also seen a few bugfixes and performance improvements. And finally I have formatted everything using the same rustfmt config as the rest of this repo.

r? ````@ghost````

````@rustbot```` label +A-codegen +A-cranelift +T-compiler
2021-03-07 10:41:19 +09:00
Yuki Okushi a5a825e6a3
Rollup merge of #82720 - henryboisdequin:fix-79040, r=oli-obk
Fix diagnostic suggests adding type `[type error]`

Fixes #79040

### Unresolved questions:

<del>Why does this change output the diagnostic twice (`src/test/ui/79040.rs`)?</del> Thanks `````@oli-obk`````
2021-03-07 10:41:15 +09:00
Yuki Okushi f3218dfa57
Rollup merge of #82651 - jyn514:rustdoc-warnings, r=GuillaumeGomez
Cleanup rustdoc warnings

## Clean up error reporting for deprecated passes

Using `error!` here goes all the way back to the original commit, https://github.com/rust-lang/rust/pull/8540. I don't see any reason to use logging; rustdoc should use diagnostics wherever possible. See https://github.com/rust-lang/rust/pull/81932#issuecomment-785291244 for further context.

- Use spans for deprecated attributes
- Use a proper diagnostic for unknown passes, instead of error logging
- Add tests for unknown passes
- Improve some wording in diagnostics

##  Report that `doc(plugins)` doesn't work using diagnostics instead of `eprintln!`

This also adds a test for the output.

This was added in https://github.com/rust-lang/rust/pull/52194. I don't see any particular reason not to use diagnostics here, I think it was just missed in https://github.com/rust-lang/rust/pull/50541.
2021-03-07 10:41:13 +09:00
Yuki Okushi d1dc16623f
Rollup merge of #77916 - QuiltOS:kernel-code-targets-os-none, r=joshtriplett
Change built-in kernel targets to be os = none throughout

Whether for Rust's own `target_os`, LLVM's triples, or GNU config's, the
OS-related have fields have been for code running *on* that OS, not code
hat is *part* of the OS.

The difference is huge, as syscall interfaces are nothing like
freestanding interfaces. Kernels are (hypervisors and other more exotic
situations aside) freestanding programs that use the interfaces provided
by the hardware. It's *those* interfaces, the ones external to the
program being built and its software dependencies, that are the content
of the target.

For the Linux Kernel in particular, `target_env: "gnu"` is removed for
the same reason: that `-gnu` refers to glibc or GNU/linux, neither of
which applies to the kernel itself.

Relates to #74247
2021-03-07 10:41:04 +09:00
Vadim Petrochenkov 5d27728141 rustc_builtin_macros: Share some more logic between `derive` and `cfg_eval` 2021-03-07 01:12:18 +03:00
Vadim Petrochenkov 10ed08f5b6 cfg_eval: Configure everything through mutable visitor methods
This is simpler and mirrors what invocation collector does
2021-03-07 00:23:02 +03:00
Vadim Petrochenkov f9019b7086 Move full configuration logic from `rustc_expand` to `rustc_builtin_macros`
This logic is applicable to two specific macros and not to the expansion infrastructure in general.
2021-03-07 00:17:31 +03:00
bors dfe519b344 Auto merge of #82738 - estebank:tail-expr-check-is-too-slow, r=oli-obk
Move check only relevant in error case out of critical path

Move the check for potentially forgotten `return` in a tail expression
of arbitrary expressions into the coercion error branch to avoid
computing unncessary coercion checks on successful code.

Follow up to #81458.
2021-03-06 21:02:53 +00:00
Vadim Petrochenkov 5dad6c2575 Implement built-in attribute macro `#[cfg_eval]` 2021-03-06 23:03:19 +03:00
Vadim Petrochenkov 069e612e73 rustc_ast: Replace `AstLike::finalize_tokens` with a getter `tokens_mut` 2021-03-06 21:19:31 +03:00
Harald van Dijk 95e096d623
Change x64 size checks to not apply to x32.
Rust contains various size checks conditional on target_arch = "x86_64",
but these checks were never intended to apply to
x86_64-unknown-linux-gnux32. Add target_pointer_width = "64" to the
conditions.
2021-03-06 16:02:48 +00:00
Yuki Okushi 6e4dcea0d9 Handle negative literals in cast overflow warning 2021-03-06 17:33:21 +09:00
Henry Boisdequin 0ca63ec1f7 Fix typo
we need to actually -> we actually need to

@rustbot label +C-cleanup
2021-03-06 09:16:29 +05:30
Henry Boisdequin 7d3a6f1655 address comments 2021-03-06 08:21:08 +05:30
Tomasz Miąsko 6f49aadabb Disable destination propagation on all mir-opt-levels 2021-03-06 00:00:00 +00:00
Guillaume Gomez 15c148b4f2
Rollup merge of #82736 - spastorino:mir-opt-level-perf-changes, r=oli-obk
Bump optimization from mir_opt_level 2 to 3 and 3 to 4 and make "release" be level 2 by default

r? `@oli-obk`
2021-03-05 21:44:40 +01:00
Guillaume Gomez 34b2caa79f
Rollup merge of #82714 - estebank:missing-braces, r=oli-obk
Detect match arm body without braces

Fix #82524.
2021-03-05 21:44:39 +01:00
Guillaume Gomez 8867f7f650
Rollup merge of #82708 - GuillaumeGomez:doc-test-attr-check, r=Manishearth
Warn on `#![doc(test(...))]` on items other than the crate root and use future incompatible lint

Part of #82672.

This PR does multiple things:
 * Create a new `INVALID_DOC_ATTRIBUTE` lint which is also "future incompatible", allowing us to use it as a warning for the moment until it turns (eventually) into a hard error.
 * Use this link when `#![doc(test(...))]` isn't used at the crate level.
 * Make #82702 use this new lint as well.

r? ``@jyn514``
2021-03-05 21:44:38 +01:00
Joshua Nelson 45229b0777 Rename `rustdoc` to `rustdoc::all`
When rustdoc lints were changed to be tool lints, the `rustdoc` group
was removed, leading to spurious warnings like

```
warning: unknown lint: `rustdoc`
```

The lint group still worked when rustdoc ran, since rustdoc added the group itself.

This renames the group to `rustdoc::all` for consistency with
`clippy::all` and the rest of the rustdoc lints.
2021-03-05 15:26:55 -05:00
Santiago Pastorino 663d4c8605
Fix MIR optimization level description 2021-03-05 17:13:58 -03:00
Santiago Pastorino 004465c620
Bump one missing mir_opt_level 2021-03-05 17:13:58 -03:00
Santiago Pastorino 261048f099
Fix rustc_driver self text and bump the mir_opt_level 2021-03-05 17:13:58 -03:00
Santiago Pastorino 421fd8ebbc
Make mir_opt_level default to 2 for optimized levels 2021-03-05 17:13:57 -03:00
Santiago Pastorino 782c7b04cf
Bump all mir_opt_level 2 to 3 2021-03-05 17:13:57 -03:00
Santiago Pastorino f3b8920d4b
Bump all mir_opt_level 3 to 4 2021-03-05 17:13:56 -03:00
Santiago Pastorino fde8d6ee81
For better consistency change mir_opt_level <= 1 to < 2 2021-03-05 17:13:56 -03:00