Commit graph

161195 commits

Author SHA1 Message Date
Cameron Steffen be6d6934b6 Fix Visitor::NestedFilter in Clippy 2022-01-16 16:02:36 -06:00
Cameron Steffen 1a6312ee0f Format clippy 2022-01-16 16:02:36 -06:00
Cameron Steffen 45db716902 Replace NestedVisitorMap with NestedFilter 2022-01-16 16:02:36 -06:00
bors bd3cb52565 Auto merge of #92970 - matthiaskrgr:rollup-tcx7cfb, r=matthiaskrgr
Rollup of 10 pull requests

Successful merges:

 - #92487 (Fix unclosed boxes in pretty printing of TraitAlias)
 - #92581 (ARMv6K Horizon - Enable default libraries)
 - #92619 (Add diagnostic items for macros)
 - #92635 (rustdoc: Yet more intra-doc links cleanup)
 - #92646 (feat: rustc_pass_by_value lint attribute)
 - #92706 (Clarify explicitly that BTree{Map,Set} are ordered.)
 - #92710 (Include Projections when elaborating TypeOutlives)
 - #92746 (Parse `Ty?` as `Option<Ty>` and provide structured suggestion)
 - #92792 (rustdoc: fix intra-link for generic trait impls)
 - #92814 (remove unused FIXME)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-01-16 17:22:57 +00:00
Matthias Krüger 2b6b49e1d7
Rollup merge of #92814 - lcnr:unused-fixme, r=Mark-Simulacrum
remove unused FIXME

#56935 seems to be fixed.
2022-01-16 16:58:20 +01:00
Matthias Krüger 682ad02b49
Rollup merge of #92792 - mdibaiee:92662/fix-intra-doc-generics, r=camelid
rustdoc: fix intra-link for generic trait impls

fixes #92662

r? `````@camelid`````
2022-01-16 16:58:19 +01:00
Matthias Krüger 9323a0d1be
Rollup merge of #92746 - estebank:question-mark-in-type, r=davidtwco
Parse `Ty?` as `Option<Ty>` and provide structured suggestion

Swift has specific syntax that desugars to `Option<T>` similar to our
`?` operator, which means that people might try to use it in Rust. Parse
it and gracefully recover.
2022-01-16 16:58:18 +01:00
Matthias Krüger 9835b90c91
Rollup merge of #92710 - jackh726:issue-92280, r=nikomatsakis
Include Projections when elaborating TypeOutlives

Fixes #92280

In `Elaborator`, we elaborate that `Foo<<Bar as Baz>::Assoc>: 'a` -> `<Bar as Baz>::Assoc: 'a`. This is the same rule that would be applied to any other `Param`. If there are escaping vars, we continue to do nothing.

r? `@nikomatsakis`
2022-01-16 16:58:17 +01:00
Matthias Krüger 039d6dc289
Rollup merge of #92706 - umanwizard:btree, r=dtolnay
Clarify explicitly that BTree{Map,Set} are ordered.

One of the main reasons one would want to use a BTree{Map,Set} rather than a Hash{Map,Set} is because they maintain their keys in sorted order; but this was never explicitly stated in the top-level docs (it was only indirectly alluded to there, and stated explicitly in the docs for `iter`, `values`, etc.)

This PR states the ordering guarantee more prominently.
2022-01-16 16:58:16 +01:00
Matthias Krüger c5041f88ea
Rollup merge of #92646 - mdibaiee:76935/pass-by-value, r=lcnr
feat: rustc_pass_by_value lint attribute

Useful for thin wrapper attributes that are best passed as value instead
of reference.

Fixes #76935
2022-01-16 16:58:15 +01:00
Matthias Krüger e1b943991f
Rollup merge of #92635 - camelid:yet-more-cleanup, r=Manishearth
rustdoc: Yet more intra-doc links cleanup

r? `@Manishearth`
2022-01-16 16:58:14 +01:00
Matthias Krüger cf4549c920
Rollup merge of #92619 - Alexendoo:macro-diagnostic-items, r=matthewjasper
Add diagnostic items for macros

For use in Clippy, it adds diagnostic items to all the stable public macros

Clippy has lints that look for almost all of these (currently by name or path), but there are a few that aren't currently part of any lint, I could remove those if it's preferred to add them as needed rather than ahead of time
2022-01-16 16:58:14 +01:00
Matthias Krüger 391b66ccff
Rollup merge of #92581 - Meziu:armv6k-3ds-target, r=nagisa
ARMv6K Horizon - Enable default libraries

Due to the nature of the external gcc linker, default libraries are required, even for `no_std` programs.
2022-01-16 16:58:12 +01:00
Matthias Krüger 9527533408
Rollup merge of #92487 - dtolnay:traitalias, r=matthewjasper
Fix unclosed boxes in pretty printing of TraitAlias

This was causing trait aliases to not even render at all in stringified / pretty printed output.

```rust
macro_rules! repro {
    ($item:item) => {
        stringify!($item)
    };
}

fn main() {
    println!("{:?}", repro!(pub trait Trait<T> = Sized where T: 'a;));
}
```

Before:&ensp;`""`
After:&ensp;`"pub trait Trait<T> = Sized where T: 'a;"`

The fix is copied from how `head`/`end` for `ItemKind::Use`, `ItemKind::ExternCrate`, and `ItemKind::Mod` are all done in the pretty printer:

dd3ac41495/compiler/rustc_ast_pretty/src/pprust/state.rs (L1178-L1184)
2022-01-16 16:58:10 +01:00
bors 48e89b00ca Auto merge of #92245 - petrochenkov:cmrval, r=nagisa
rustc_metadata: Switch all decoder methods from vectors to iterators

To avoid allocations in some cases.

Also remove unnecessary `is_proc_macro_crate` checks from decoder, currently the general strategy is to shift all the work to the encoder and assume that all the encoded data is correct and can be decoded unconditionally in the decoder.
2022-01-16 14:25:25 +00:00
bors 7be8693984 Auto merge of #92805 - BoxyUwU:revert-lazy-anon-const-substs, r=lcnr
partially revertish `lazily "compute" anon const default substs`

reverts #87280 except for some of the changes around `ty::Unevaluated` having a visitor and a generic for promoted
why revert: <https://github.com/rust-lang/rust/pull/92805#issuecomment-1010736049>

r? `@lcnr`
2022-01-16 11:19:21 +00:00
bors 42852d7857 Auto merge of #92740 - cuviper:update-rayons, r=Mark-Simulacrum
Update rayon and rustc-rayon

This updates rayon for various tools and rustc-rayon for the compiler's parallel mode.

- rayon v1.3.1 -> v1.5.1
- rayon-core v1.7.1 -> v1.9.1
- rustc-rayon v0.3.1 -> v0.3.2
- rustc-rayon-core v0.3.1 -> v0.3.2

... and indirectly, this updates all of crossbeam-* to their latest versions.

Fixes #92677 by removing crossbeam-queue, but there's still a lingering question about how tidy discovers "runtime" dependencies. None of this is truly in the standard library's dependency tree at all.
2022-01-16 08:12:23 +00:00
Vadim Petrochenkov 4549b13571 rustc_metadata: Switch all decoder methods from vectors to iterators
Also remove unnecessary `is_proc_macro_crate` checks from decoder
2022-01-16 14:14:39 +08:00
bors 26c06cf8e2 Auto merge of #92356 - kellerkindt:saturating_int_assign_impl, r=dtolnay
Add {Add,Sub,Mul,Div,Rem,BitXor,BitOr,BitAnd}{,Assign}<$t> to Saturat…

Tracking issue #92354
2022-01-16 05:23:44 +00:00
Jack Huey ea562aeed5 Add nll revision for issue-92096 test that passes 2022-01-15 23:17:32 -05:00
David Tolnay ad6408dd7a
Tweak btree iterator wording to not use 'yield'
Yield means something else in the context of generators, which are
sufficiently close to iterators that it's better to avoid the
terminology collision here.
2022-01-15 19:28:21 -08:00
bors a0984b4e4c Auto merge of #92598 - Badel2:panic-update-hook, r=yaahc
Implement `panic::update_hook`

Add a new function `panic::update_hook` to allow creating panic hooks that forward the call to the previously set panic hook, without race conditions. It works by taking a closure that transforms the old panic hook into a new one, while ensuring that during the execution of the closure no other thread can modify the panic hook. This is a small function so I hope it can be discussed here without a formal RFC, however if you prefer I can write one.

Consider the following example:

```rust
let prev = panic::take_hook();
panic::set_hook(Box::new(move |info| {
    println!("panic handler A");
    prev(info);
}));
```

This is a common pattern in libraries that need to do something in case of panic: log panic to a file, record code coverage, send panic message to a monitoring service, print custom message with link to github to open a new issue, etc. However it is impossible to avoid race conditions with the current API, because two threads can execute in this order:

* Thread A calls `panic::take_hook()`
* Thread B calls `panic::take_hook()`
* Thread A calls `panic::set_hook()`
* Thread B calls `panic::set_hook()`

And the result is that the original panic hook has been lost, as well as the panic hook set by thread A. The resulting panic hook will be the one set by thread B, which forwards to the default panic hook. This is not considered a big issue because the panic handler setup is usually run during initialization code, probably before spawning any other threads.

Using the new `panic::update_hook` function, this race condition is impossible, and the result will be either `A, B, original` or `B, A, original`.

```rust
panic::update_hook(|prev| {
    Box::new(move |info| {
        println!("panic handler A");
        prev(info);
    })
});
```

I found one real world use case here: 988cf403e7/src/detection.rs (L32) the workaround is to detect the race condition and panic in that case.

The pattern of `take_hook` + `set_hook` is very common, you can see some examples in this pull request, so I think it's natural to have a function that combines them both. Also using `update_hook` instead of `take_hook` + `set_hook` reduces the number of calls to `HOOK_LOCK.write()` from 2 to 1, but I don't expect this to make any difference in performance.

### Unresolved questions:

* `panic::update_hook` takes a closure, if that closure panics the error message is "panicked while processing panic" which is not nice. This is a consequence of holding the `HOOK_LOCK` while executing the closure. Could be avoided using `catch_unwind`?

* Reimplement `panic::set_hook` as `panic::update_hook(|_prev| hook)`?
2022-01-16 02:18:42 +00:00
bors f9d61cd2ed Auto merge of #90146 - cjgillot:no-id-map, r=nagisa
Reduce use of LocalDefId <-> HirId maps

This is an attempt to reduce the perf effect of https://github.com/rust-lang/rust/pull/89278.
r? `@ghost`
2022-01-15 23:10:14 +00:00
Camille GILLOT 8617ff0f0b Add inline. 2022-01-15 21:26:25 +01:00
Camille GILLOT d9c6e70c57 Do not ICE when accesing large LocalDefId. 2022-01-15 21:26:25 +01:00
Camille GILLOT 67727aa7c3 Reduce use of local_def_id_to_hir_id. 2022-01-15 21:26:25 +01:00
Camille GILLOT ebcc847369 Make ty_param_owner return a LocalDefId. 2022-01-15 21:26:24 +01:00
Camille GILLOT 79afe99973 Use LocalDefId in rustc_passes::hir_id_validator. 2022-01-15 21:26:24 +01:00
Camille GILLOT a5b7e235d3 Simplify DefIdForest. 2022-01-15 21:26:24 +01:00
Camille GILLOT c9de7d7a20 Use LocalDefId in rustc_passes::entry. 2022-01-15 21:26:24 +01:00
Camille GILLOT 60064726ae Return a LocalDefId in get_parent_item. 2022-01-15 21:26:20 +01:00
Camille GILLOT 5a123c265b Add fast path to opt_local_def_id. 2022-01-15 21:17:34 +01:00
Noah Lev 554c7659e8 Fix broken link 2022-01-15 10:18:24 -08:00
bors ec4bcaac45 Auto merge of #92441 - cjgillot:resolve-trait-impl-item, r=matthewjasper
Link impl items to corresponding trait items in late resolver.

Hygienically linking trait impl items to declarations in the trait can be done directly by the late resolver. In fact, it is already done to diagnose unknown items.

This PR uses this resolution work and stores the `DefId` of the trait item in the HIR. This avoids having to do this resolution manually later.

r? `@matthewjasper`
Related to #90639. The added `trait_item_id` field can be moved to `ImplItemRef` to be used directly by your PR.
2022-01-15 14:43:45 +00:00
bors b13a5bf3c4 Auto merge of #92927 - matthiaskrgr:rollup-pgzwfcm, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #92747 (Simplification of BigNum::bit_length)
 - #92767 (Use the new language identifier for Rust in the PDB debug format)
 - #92775 (Inline std::os::unix::ffi::OsStringExt methods)
 - #92863 (Remove `&mut` from `io::read_to_string` signature)
 - #92865 (Ignore static lifetimes for GATs outlives lint)
 - #92873 (Generate more precise generator names)
 - #92879 (Add Sync bound to allocator parameter in vec::IntoIter)
 - #92892 (Do not fail evaluation in const blocks)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-01-15 10:57:03 +00:00
Matthias Krüger 539175c026
Rollup merge of #92892 - compiler-errors:const-param-env-for-const-block, r=fee1-dead
Do not fail evaluation in const blocks

Evaluate const blocks with a const param-env, so we properly check `~const` trait bounds.

Fixes #92713
(I will fix the poor diagnostics in #92713 and #92712 in a separate PR)

cc `@nbdd0121` who wrote the code this PR touches in #89561
2022-01-15 11:28:28 +01:00
Matthias Krüger 784e4ba9a4
Rollup merge of #92879 - compiler-errors:into_iter_unsound, r=dtolnay
Add Sync bound to allocator parameter in vec::IntoIter

The `A: Sync` bound was forgotten in 8725e4c337 (diff-b78c3ab6d37f4ede32195707528f8a76c49d4557cc9d3a7a09417b5157729b9fR3132)

Similar `unsafe impl Sync` in that commit _do_ include the `A: Sync` bound (and around the alloc lib), so I think this was just an honest mistake.

Here's an example of the unsoundness:  https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=16cbfeff7c934ae72ab632c1476fdd8b

`@steffahn` found this, I'm just putting up the fix cause nobody else did :^)

Fixes #92633
2022-01-15 11:28:27 +01:00
Matthias Krüger 85c119cd51
Rollup merge of #92873 - eholk:async-symbol-names, r=tmandry
Generate more precise generator names

Currently all generators are named with a `generator$N` suffix, regardless of where they come from. This means an `async fn` shows up as a generator in stack traces, which can be surprising to async programmers since they should not need to know that async functions are implementated using generators.

This change generators a different name depending on the generator kind, allowing us to tell whether the generator is the result of an async block, an async closure, an async fn, or a plain generator.

r? `@tmandry`
cc `@michaelwoerister` `@wesleywiser` `@dpaoliello`
2022-01-15 11:28:26 +01:00
Matthias Krüger cd93be0094
Rollup merge of #92865 - jackh726:gats-outlives-no-static, r=nikomatsakis
Ignore static lifetimes for GATs outlives lint

cc https://github.com/rust-lang/rust/issues/87479#issuecomment-1010484170

Also included a bit of cleanup of `ty_known_to_outlive` and `region_known_to_outlive`

r? `@nikomatsakis`
2022-01-15 11:28:25 +01:00
Matthias Krüger d878ad0559
Rollup merge of #92863 - camelid:read_to_string-rm-mut, r=m-ou-se
Remove `&mut` from `io::read_to_string` signature

``@m-ou-se`` [realized][1] that because `Read` is implemented for `&mut impl
Read`, there's no need to take `&mut` in `io::read_to_string`.

Removing the `&mut` from the signature allows users to remove the `&mut`
from their calls (and thus pass an owned reader) if they don't use the
reader later.

r? `@m-ou-se`

[1]: https://github.com/rust-lang/rust/issues/80218#issuecomment-874322129
2022-01-15 11:28:24 +01:00
Matthias Krüger 1b241bb703
Rollup merge of #92775 - xfix:osstringext-inline, r=m-ou-se
Inline std::os::unix::ffi::OsStringExt methods

Those methods essentially do nothing at assembly level. On Unix systems, `OsString` is represented as a `Vec` without performing any transformations.
2022-01-15 11:28:23 +01:00
Matthias Krüger ff1db43b50
Rollup merge of #92767 - arlosi:pdbenum, r=cuviper
Use the new language identifier for Rust in the PDB debug format

Rust currently identifies as MASM (Microsoft Assembler) in the PDB
debug info format on Windows because no identifier was available.

This change pulls in a cherry-pick to Rust's LLVM that includes the
change to use the new identifier for Rust.

https://docs.microsoft.com/en-us/visualstudio/debugger/debug-interface-access/cv-cfl-lang
2022-01-15 11:28:22 +01:00
Matthias Krüger f511360fd2
Rollup merge of #92747 - swenson:bignum-bit-length-optimization, r=scottmcm
Simplification of BigNum::bit_length

As indicated in the comment, the BigNum::bit_length function could be
optimized by using CLZ, which is often a single instruction instead a
loop.

I think the code is also simpler now without the loop.

I added some additional tests for Big8x3 and Big32x40 to ensure that
there were no regressions.
2022-01-15 11:28:22 +01:00
bors 38c22af015 Auto merge of #92604 - nnethercote:optimize-impl_read_unsigned_leb128, r=michaelwoerister
Optimize `impl_read_unsigned_leb128`

I see instruction count improvements of up to 3.5% locally with these changes, mostly on the smaller benchmarks.

r? `@michaelwoerister`
2022-01-15 07:27:30 +00:00
bors 69d25fc582 Auto merge of #92915 - matthiaskrgr:rollup-pxxk8jp, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - #92191 (Prefer projection candidates instead of param_env candidates for Sized predicates)
 - #92382 (Extend const_convert to rest of blanket core::convert impls)
 - #92625 (Add `#[track_caller]` to `mirbug`)
 - #92684 (Export `tcp::IntoIncoming`)
 - #92743 (Use pre-interned symbols in a couple of places)
 - #92838 (Clean up some links in RELEASES)
 - #92868 (librustdoc: Address some clippy lints)
 - #92875 (Make `opt_const_param_of` work in the presence of `GenericArg::Infer`)
 - #92891 (Add myself to .mailmap)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-01-15 04:24:13 +00:00
Matthias Krüger ff6c17598f
Rollup merge of #92891 - JamesHinshelwood:patch-1, r=Mark-Simulacrum
Add myself to .mailmap

(to de-duplicate my identities in the contributors list)
2022-01-15 02:25:21 +01:00
Matthias Krüger 6c94f99d83
Rollup merge of #92875 - BoxyUwU:infer_arg_opt_const_param_of, r=lcnr
Make `opt_const_param_of` work in the presence of `GenericArg::Infer`

highly recommend viewing the first and second commits on their own rather than looking at file changes 🤣

Because we filtered args down to just const args we would ignore `GenericArg::Infer` which made us get a `arg_index` which was wrong by however many const `GenericArg::Infer` came previously

[example](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=46dba6a53aca6333028a10908ef16e0b) of the [bugs](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=a8eebced26eefa4119fc2e7ae0c76de6) fixed.

r? ```@lcnr```
2022-01-15 02:25:20 +01:00
Matthias Krüger 8f4155909c
Rollup merge of #92868 - pierwill:librustdoc-clippy, r=camelid
librustdoc: Address some clippy lints
2022-01-15 02:25:19 +01:00
Matthias Krüger c693442f4c
Rollup merge of #92838 - ehuss:cleanup-release-links, r=Mark-Simulacrum
Clean up some links in RELEASES

This fixes some issues with markdown links in the RELEASES file.
2022-01-15 02:25:18 +01:00
Matthias Krüger 8326f3f317
Rollup merge of #92743 - bjorn3:less_symbol_intern, r=camelid
Use pre-interned symbols in a couple of places

Re-open of https://github.com/rust-lang/rust/pull/92733 as bors glitched.
2022-01-15 02:25:17 +01:00