Commit graph

4402 commits

Author SHA1 Message Date
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
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
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
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
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
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
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
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
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
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