Commit graph

151683 commits

Author SHA1 Message Date
Guillaume Gomez
6df9df7e36
Rollup merge of #87236 - sunfishcode:avoid-locking-args, r=joshtriplett
Simplify command-line argument initialization on unix

Simplify Rust's command-line argument initialization code on unix:
 - The cleanup code isn't needed, because it was just zeroing out non-owning variables at runtime cleanup time. After 91c3eee173, Rust's command-line initialization code on unix no longer allocates `CString`s and a `Vec` at startup time.
 - The `Mutex` isn't needed; if there's somehow a call to `args()` before argument initialization has happened, the code returns return an empty list, which we can do with a null check.

With these changes, a simple cdylib that doesn't use threads avoids getting `pthread_mutex_lock`/`pthread_mutex_unlock` in its symbol table.
2021-07-19 11:37:45 +02:00
Guillaume Gomez
65b7aa98c7
Rollup merge of #87227 - bstrie:asm2arch, r=Amanieu
Move asm! and global_asm! to core::arch

Follow-up to https://github.com/rust-lang/stdarch/pull/1183 .

Implements the libs-api team decision from rust-lang/rust#84019 (comment) .

In order to not break nightly users, this PR also adds the newly-moved items to the prelude. However, a decision will need to be made before stabilization as to whether these items should remain in the prelude. I will file an issue for this separately.

Fixes #84019 .

r? `@Amanieu`
2021-07-19 11:37:44 +02:00
Guillaume Gomez
456ebd30d5
Rollup merge of #87210 - notriddle:notriddle/rustdoc-sidebar-headers, r=GuillaumeGomez
Rustdoc accessibility: make the sidebar headers actual headers

Part of #87059

Preview it at: https://notriddle.com/notriddle-rustdoc-test/rustdoc-sidebar-header/std/index.html
2021-07-19 11:37:42 +02:00
Guillaume Gomez
0fce468fe8
Rollup merge of #86230 - GuillaumeGomez:nocapture, r=camelid
Add --nocapture option to rustdoc

Fixes https://github.com/rust-lang/rust/issues/26309.
Fixes #45724.

Once this PR is merged, I'll send a PR to cargo to also pass `--nocapture` to rustdoc.

cc `@jyn514`
r? `@camelid`
2021-07-19 11:37:41 +02:00
bors
83f08223a9 Auto merge of #87196 - oxalica:option-insert-must-use, r=joshtriplett
Mark `Option::insert` as must_use

Some people seems misled by the function name and use it in case where a simple assignment just works.
If the return value is not used, `option = Some(value);` should be preferred instead of `option.insert(value);`
2021-07-19 07:03:36 +00:00
bors
0ecff8c623 Auto merge of #87146 - Aaron1011:better-macro-lint, r=petrochenkov
Compute a better `lint_node_id` during expansion

When we need to emit a lint at a macro invocation, we currently use the
`NodeId` of its parent definition (e.g. the enclosing function). This
means that any `#[allow]` / `#[deny]` attributes placed 'closer' to the
macro (e.g. on an enclosing block or statement) will have no effect.

This commit computes a better `lint_node_id` in `InvocationCollector`.
When we visit/flat_map an AST node, we assign it a `NodeId` (earlier
than we normally would), and store than `NodeId` in current
`ExpansionData`. When we collect a macro invocation, the current
`lint_node_id` gets cloned along with our `ExpansionData`, allowing it
to be used if we need to emit a lint later on.

This improves the handling of `#[allow]` / `#[deny]` for
`SEMICOLON_IN_EXPRESSIONS_FROM_MACROS` and some `asm!`-related lints.
The 'legacy derive helpers' lint retains its current behavior
(I've inlined the now-removed `lint_node_id` function), since
there isn't an `ExpansionData` readily available.
2021-07-19 04:22:51 +00:00
bors
10c0b003db Auto merge of #86848 - notriddle:notriddle/drop-dyn, r=varkor
feat(rustc_lint): add `dyn_drop`

Based on the conversation in #86747.

Explanation
-----------

A trait object bound of the form `dyn Drop` is most likely misleading and not what the programmer intended.

`Drop` bounds do not actually indicate whether a type can be trivially dropped or not, because a composite type containing `Drop` types does not necessarily implement `Drop` itself. Naïvely, one might be tempted to write a deferred drop system, to pull cleaning up memory out of a latency-sensitive code path, using `dyn Drop` trait objects. However, this breaks down e.g. when `T` is `String`, which does not implement `Drop`, but should probably be accepted.

To write a trait object bound that accepts anything, use a placeholder trait with a blanket implementation.

```rust
trait Placeholder {}
impl<T> Placeholder for T {}
fn foo(_x: Box<dyn Placeholder>) {}
```
2021-07-19 01:41:54 +00:00
bors
b548d9f1c6 Auto merge of #87004 - JamieCunliffe:pgo-gc-sections, r=Mark-Simulacrum
Don't use gc-sections with profile-generate.

When building with profile-generate don't call gc_sections as this can
can sometimes strip out profile data. This missing information in the
prof files can then result in missing functions when using the profile
information.

#78226

r? `@Mark-Simulacrum`
2021-07-18 23:14:31 +00:00
bstrie
f26fbe2453 Move asm! and global_asm! to core::arch 2021-07-18 18:30:58 -04:00
bors
59216858a3 Auto merge of #86950 - tmiasko:personality, r=nagisa
Use existing declaration of rust_eh_personality

If crate declares `rust_eh_personality`, re-use existing declaration
as otherwise attempts to set function attributes that follow the
declaration will fail (unless it happens to have exactly the same
type signature as the one predefined in the compiler).

Fixes #70117.
Fixes https://github.com/rust-lang/rust/pull/81469#issuecomment-809428126; probably.
2021-07-18 20:33:23 +00:00
Michael Howell
e054522b01 fix(clippy): add missing allow(dyn_drop) 2021-07-18 07:57:03 -07:00
Michael Howell
83d3a94b04 Add #![allow(dyn_drop)] to test cases with dyn Drop in them
These are all testing corner-cases in the compiler.
Adding a new warning broke these test cases, but --cap-lints stops
it from actually breaking things in production.
2021-07-18 07:55:57 -07:00
Michael Howell
dbd4fd5716 feat(rustc_lint): add dyn_drop
Based on the conversation in #86747.

Explanation
-----------

A trait object bound of the form `dyn Drop` is most likely misleading
and not what the programmer intended.

`Drop` bounds do not actually indicate whether a type can be trivially
dropped or not, because a composite type containing `Drop` types does
not necessarily implement `Drop` itself. Naïvely, one might be tempted
to write a deferred drop system, to pull cleaning up memory out of a
latency-sensitive code path, using `dyn Drop` trait objects. However,
this breaks down e.g. when `T` is `String`, which does not implement
`Drop`, but should probably be accepted.

To write a trait object bound that accepts anything, use a placeholder
trait with a blanket implementation.

```rust
trait Placeholder {}
impl<T> Placeholder for T {}
fn foo(_x: Box<dyn Placeholder>) {}
```
2021-07-18 07:55:57 -07:00
bors
331da5820c Auto merge of #87252 - RalfJung:miri, r=RalfJung
update Miri

Fixes https://github.com/rust-lang/rust/issues/87222
Cc `@rust-lang/miri` r? `@ghost`
2021-07-18 13:11:39 +00:00
Ralf Jung
0fcd59ad65 update Miri 2021-07-18 12:43:39 +02:00
bors
18073052d8 Auto merge of #86698 - cjgillot:modc, r=estebank
Move OnDiskCache to rustc_query_impl.

This should be the last remnant of the query implementation that was still in rustc_middle.
2021-07-18 10:42:23 +00:00
Guillaume Gomez
d5e3294734 Add invalid rust code for test 2021-07-18 12:07:51 +02:00
Guillaume Gomez
6461cde51f Don't capture child process output at all when --no-capture is used 2021-07-18 11:54:40 +02:00
Guillaume Gomez
893e07e1b0 Add doc for --nocapture 2021-07-18 11:54:39 +02:00
Guillaume Gomez
111cca1fa7 Add test for rustdoc --nocapture option 2021-07-18 11:54:39 +02:00
Guillaume Gomez
6ca0e5ed39 Add --nocapture option to rustdoc 2021-07-18 11:54:39 +02:00
Camille GILLOT
5b921505ef Remove deadlock virtual call. 2021-07-18 11:14:08 +02:00
Camille GILLOT
81241cbf3a Move OnDiskCache to rustc_query_impl. 2021-07-18 11:14:07 +02:00
bors
5a8a44196b Auto merge of #87242 - JohnTitor:rollup-t9rmwpo, r=JohnTitor
Rollup of 8 pull requests

Successful merges:

 - #86763 (Add a regression test for issue-63355)
 - #86814 (Recover from a misplaced inner doc comment)
 - #86843 (Check that const parameters of trait methods have compatible types)
 - #86889 (rustdoc: Cleanup ExternalCrate)
 - #87092 (Remove nondeterminism in multiple-definitions test)
 - #87170 (Add diagnostic items for Clippy)
 - #87183 (fix typo in compile_fail doctest)
 - #87205 (rustc_middle: remove redundant clone)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-07-18 08:15:17 +00:00
bors
3ab6b60337 Auto merge of #87071 - inquisitivecrystal:inclusive-range, r=estebank
Add diagnostics for mistyped inclusive range

Inclusive ranges are correctly typed as `..=`. However, it's quite easy to think of it as being like `==`, and type `..==` instead. This PR adds helpful diagnostics for this case.

Resolves #86395 (there are some other cases there, but I think those should probably have separate issues).

r? `@estebank`
2021-07-18 05:58:16 +00:00
Yuki Okushi
810e47897a
Rollup merge of #87205 - matthiaskrgr:clippy_cln, r=oli-obk
rustc_middle: remove redundant clone

found while looking through some clippy lint warnings
2021-07-18 14:21:59 +09:00
Yuki Okushi
c1ee9a3a03
Rollup merge of #87183 - RalfJung:option-doctest, r=jyn514
fix typo in compile_fail doctest

Fixes a typo introduced by https://github.com/rust-lang/rust/pull/86211. For some reason this typo makes Miri go all crazy when running libcore doctests (https://github.com/rust-lang/miri/issues/1852). Kudos to ``@hyd-dev`` for noticing the typo.

Cc ``@tlyu`` ``@joshtriplett``
2021-07-18 14:21:58 +09:00
Yuki Okushi
07faa2e32c
Rollup merge of #87170 - xFrednet:clippy-5393-add-diagnostic-items, r=Manishearth,oli-obk
Add diagnostic items for Clippy

This adds a bunch of diagnostic items to `std`/`core`/`alloc` functions, structs and traits used in Clippy. The actual refactorings in Clippy to use these items will be done in a different PR in Clippy after the next sync.

This PR doesn't include all paths Clippy uses, I've only gone through the first 85 lines of Clippy's [`paths.rs`](ecf85f4bdc/clippy_utils/src/paths.rs) (after rust-lang/rust-clippy#7466) to get some feedback early on. I've also decided against adding diagnostic items to methods, as it would be nicer and more scalable to access them in a nicer fashion, like adding a `is_diagnostic_assoc_item(did, sym::Iterator, sym::map)` function or something similar (Suggested by `@camsteffen` [on Zulip](https://rust-lang.zulipchat.com/#narrow/stream/147480-t-compiler.2Fwg-diagnostics/topic/Diagnostic.20Item.20Naming.20Convention.3F/near/225024603))

There seems to be some different naming conventions when it comes to diagnostic items, some use UpperCamelCase (`BinaryHeap`) and some snake_case (`hashmap_type`). This PR uses UpperCamelCase for structs and traits and snake_case with the module name as a prefix for functions. Any feedback on is this welcome.

cc: rust-lang/rust-clippy#5393

r? `@Manishearth`
2021-07-18 14:21:57 +09:00
Yuki Okushi
81d0b70402
Rollup merge of #87092 - ricobbe:fix-raw-dylib-multiple-definitions, r=petrochenkov
Remove nondeterminism in multiple-definitions test

Compare all fields in `DllImport` when sorting to avoid nondeterminism in the error for multiple inconsistent definitions of an extern function.  Restore the multiple-definitions test.

Resolves #87084.
2021-07-18 14:21:56 +09:00
Yuki Okushi
eef510865a
Rollup merge of #86889 - jyn514:crate-cleanup, r=camelid
rustdoc: Cleanup ExternalCrate

- Remove unnecessary CrateNum from Cache.externs
- Remove trival impl Clean for CrateNum
2021-07-18 14:21:55 +09:00
Yuki Okushi
783efd29ae
Rollup merge of #86843 - FabianWolff:issue-86820, r=lcnr
Check that const parameters of trait methods have compatible types

This PR fixes #86820. The problem is that this currently passes the type checker:
```rust
trait Tr {
    fn foo<const N: u8>(self) -> u8;
}

impl Tr for f32 {
    fn foo<const N: bool>(self) -> u8 { 42 }
}
```
i.e. the type checker fails to check whether const parameters in `impl` methods have the same type as the corresponding declaration in the trait. With my changes, I get, for the above code:
```
error[E0053]: method `foo` has an incompatible const parameter type for trait
 --> test.rs:6:18
  |
6 |     fn foo<const N: bool>(self) -> u8 { 42 }
  |                  ^
  |
note: the const parameter `N` has type `bool`, but the declaration in trait `Tr::foo` has type `u8`
 --> test.rs:2:18
  |
2 |     fn foo<const N: u8>(self) -> u8;
  |                  ^

error: aborting due to previous error
```
This fixes #86820, where an ICE happens later on because the trait method is declared with a const parameter of type `u8`, but the `impl` uses one of type `usize`:
> `expected int of size 8, but got size 1`
2021-07-18 14:21:54 +09:00
Yuki Okushi
469935f7a4
Rollup merge of #86814 - Aaron1011:inner-doc-recover, r=estebank
Recover from a misplaced inner doc comment

Fixes #86781
2021-07-18 14:21:53 +09:00
Yuki Okushi
76300d52f7
Rollup merge of #86763 - JohnTitor:test-63355, r=oli-obk
Add a regression test for issue-63355

Closes #63355
r? ``@nikomatsakis``
2021-07-18 14:21:52 +09:00
Aaron Hill
1c1c7949ab
Add test for #[allow] for warnings on attribute macro 2021-07-17 23:03:58 -05:00
Aaron Hill
7ca089c6d2
Only use assign_id! for ast nodes that support attributes 2021-07-17 23:03:58 -05:00
Aaron Hill
d6e3c11101
Add additional missing lint handling logic 2021-07-17 23:03:58 -05:00
Aaron Hill
2bd15a25ef
Add missing visit_expr_field 2021-07-17 23:03:57 -05:00
Aaron Hill
ddd544856e
Compute a better lint_node_id during expansion
When we need to emit a lint at a macro invocation, we currently use the
`NodeId` of its parent definition (e.g. the enclosing function). This
means that any `#[allow]` / `#[deny]` attributes placed 'closer' to the
macro (e.g. on an enclosing block or statement) will have no effect.

This commit computes a better `lint_node_id` in `InvocationCollector`.
When we visit/flat_map an AST node, we assign it a `NodeId` (earlier
than we normally would), and store than `NodeId` in current
`ExpansionData`. When we collect a macro invocation, the current
`lint_node_id` gets cloned along with our `ExpansionData`, allowing it
to be used if we need to emit a lint later on.

This improves the handling of `#[allow]` / `#[deny]` for
`SEMICOLON_IN_EXPRESSIONS_FROM_MACROS` and some `asm!`-related lints.
The 'legacy derive helpers' lint retains its current behavior
(I've inlined the now-removed `lint_node_id` function), since
there isn't an `ExpansionData` readily available.
2021-07-17 23:03:56 -05:00
bors
77d155973c Auto merge of #85686 - ptrojahn:loop_reinitialize, r=estebank
Add help on reinitialization between move and access

Fixes #83760
2021-07-18 02:13:12 +00:00
Dan Gohman
c3df0ae97f x.py fmt 2021-07-17 18:31:51 -07:00
bors
eb0b95b55a Auto merge of #87129 - FabianWolff:issue-75356, r=varkor
Warn about useless assignments of variables/fields to themselves

This PR fixes #75356. Following `@varkor's` suggestion in https://github.com/rust-lang/rust/issues/75356#issuecomment-700339154, I have implemented this warning as part of the `dead_code` lint. Unlike the `-Wself-assign` implementation in [Clang](56e6d4742e/clang/lib/Sema/SemaExpr.cpp (L13875-L13909)), my implementation also warns about self-assignments of struct fields (`s.x = s.x`).

r? `@varkor`
2021-07-17 22:51:07 +00:00
Dan Gohman
9bb11ba511 Remove an unnecessary Mutex around argument initialization.
In the command-line argument initialization code, remove the Mutex
around the `ARGV` and `ARGC` variables, and simply check whether
ARGV is non-null before dereferencing it. This way, if either of
ARGV or ARGC is not initialized, we'll get an empty argument list.

This allows simple cdylibs to avoid having
`pthread_mutex_lock`/`pthread_mutex_unlock` appear in their symbol
tables if they don't otherwise use threads.
2021-07-17 13:35:38 -07:00
Dan Gohman
46010c4618 Remove args cleanup code.
As of 91c3eee173, the global ARGC and ARGV
no longer reference dynamically-allocated memory, so they don't need to
be cleaned up.
2021-07-17 13:35:27 -07:00
bors
c7331d65bd Auto merge of #87203 - jackh726:logging, r=nikomatsakis
Some perf optimizations and logging

Various bits of (potential) perf optimizations and some logging additions/changes pulled out from #85499

The only not extremely straightforward change is adding `needs_normalization` in `trait::project`. This is just a perf optimization to avoid fold through a type with *only* opaque types in `UserFacing` mode (as they aren't replaced).

This should be a simple PR for *anyone* to review, so I'm going to let highfive assign. But I'll go ahead and cc `@nikomatsakis` in case he has time today.
2021-07-17 20:23:58 +00:00
jackh726
fa839b1194 Add needs_normalization 2021-07-17 16:09:22 -04:00
jackh726
d954a8ee8e Some perf optimizations and logging 2021-07-17 16:09:17 -04:00
Michael Howell
1941764607 Fix sidebar-mobile test to focus on an actual focusable element 2021-07-17 11:53:59 -07:00
Michael Howell
10bdc42be8 Fix test cases for header titles in sidebar 2021-07-17 11:32:36 -07:00
Michael Howell
ee97b4a528 Remove redundant CSS 2021-07-17 11:32:36 -07:00
Michael Howell
30d49a401a Rustdoc accessibility: make the sidebar headers actual headers
Part of #87059

Preview it at: https://notriddle.com/notriddle-rustdoc-test/rustdoc-sidebar-header/std/index.html
2021-07-17 11:32:36 -07:00