]> git.lizzy.rs Git - rust.git/log
rust.git
2 years agoRollup merge of #92307 - hiroshi-maybe:fix-minor-typos, r=camelid
Matthias Krüger [Mon, 27 Dec 2021 20:42:30 +0000 (21:42 +0100)]
Rollup merge of #92307 - hiroshi-maybe:fix-minor-typos, r=camelid

Fix minor typos

2 years agoRollup merge of #92303 - Patrick-Poitras:issue-26186, r=jackh726
Matthias Krüger [Mon, 27 Dec 2021 20:42:29 +0000 (21:42 +0100)]
Rollup merge of #92303 - Patrick-Poitras:issue-26186, r=jackh726

Add test cases for issue #26186

Closes #26186

It seems that issue #26186 has been solved at some point since the issue has been last updated. I've merged together the examples that were supplied by `@Osspial,` `@Mark-Simulacrum,` `@Diggsey,` `@eefriedman` and `@shepmaster,` so that we can add this to the testing suite and prevent these issues from re-occurring.

2 years agoRollup merge of #92264 - Shadlock0133:patch-1, r=the8472
Matthias Krüger [Mon, 27 Dec 2021 20:42:28 +0000 (21:42 +0100)]
Rollup merge of #92264 - Shadlock0133:patch-1, r=the8472

Remove `maybe_uninit_extra` feature from Vec docs

In `Vec`, two doc tests are using `MaybeUninit::write` , stabilized in 1.55. This makes docs' usage of `maybe_uninit_extra` feature unnecessary.

2 years agoRollup merge of #92161 - petrochenkov:misclean, r=cjgillot
Matthias Krüger [Mon, 27 Dec 2021 20:42:27 +0000 (21:42 +0100)]
Rollup merge of #92161 - petrochenkov:misclean, r=cjgillot

resolve: Minor miscellaneous cleanups from #89059

`@bors` rollup=always

2 years agoRollup merge of #92147 - calebcartwright:publicize-builtin_macro-asm, r=cjgillot
Matthias Krüger [Mon, 27 Dec 2021 20:42:26 +0000 (21:42 +0100)]
Rollup merge of #92147 - calebcartwright:publicize-builtin_macro-asm, r=cjgillot

rustc_builtin_macros: make asm mod public for rustfmt

Follow up to #92016, as I'd completely missed that the mod we needed was internal

2 years agoRollup merge of #92112 - SparrowLii:issue92010, r=cjgillot
Matthias Krüger [Mon, 27 Dec 2021 20:42:25 +0000 (21:42 +0100)]
Rollup merge of #92112 - SparrowLii:issue92010, r=cjgillot

Fix the error of checking `base_expr` twice in type_changing_struct_update

Fixes #92010

2 years agoRollup merge of #90586 - jswrenn:relax-privacy-lints, r=petrochenkov
Matthias Krüger [Mon, 27 Dec 2021 20:42:25 +0000 (21:42 +0100)]
Rollup merge of #90586 - jswrenn:relax-privacy-lints, r=petrochenkov

Relax priv-in-pub lint on generic bounds and where clauses of trait impls.

The priv-in-pub lint is a legacy mechanism of the compiler, supplanted by a reachability-based [type privacy](https://github.com/rust-lang/rfcs/blob/master/text/2145-type-privacy.md) analysis. This PR does **not** relax type privacy; it only relaxes the lint (as proposed by the type privacy RFC) in the case of trait impls.

## Current Behavior
On public trait impls, it's currently an **error** to have a `where` bound constraining a private type with a trait:
```rust
pub trait Trait {}
pub struct Type {}

struct Priv {}
impl Trait for Priv {}

impl Trait for Type
where
    Priv: Trait // ERROR
{}
```

...and it's a **warning** to have have a public type constrained by a private trait:
```rust
pub trait Trait {}
pub struct Type {}

pub struct Pub {}
trait Priv {}
impl Priv for Pub {}

impl Trait for Type
where
    Pub: Priv // WARNING
{}
```

This lint applies to `where` clauses in other contexts, too; e.g. on free functions:
```rust
struct Priv<T>(T);
pub trait Pub {}
impl<T: Pub> Pub for Priv<T> {}

pub fn function<T>()
where
    Priv<T>: Pub // WARNING
{}
```

**These constraints could be relaxed without issue.**

## New Behavior
This lint is relaxed for `where` clauses on trait impls, such that it's okay to have a `where` bound constraining a private type with a trait:
```rust
pub trait Trait {}
pub struct Type {}

struct Priv {}
impl Trait for Priv {}

impl Trait for Type
where
    Priv: Trait // OK
{}
```

...and it's okay to have a public type constrained by a private trait:
```rust
pub trait Trait {}
pub struct Type {}

pub struct Pub {}
trait Priv {}
impl Priv for Pub {}

impl Trait for Type
where
    Pub: Priv // OK
{}
```

## Rationale
While the priv-in-pub lint is not essential for soundness, it *can* help programmers avoid pitfalls that would make their libraries difficult to use by others. For instance, such a lint *is* useful for free functions; e.g. if a downstream crate tries to call the `function` in the previous snippet in a generic context:
```rust
fn callsite<T>()
where
    Priv<T>: Pub // ERROR: omitting this bound is a compile error, but including it is too
{
    function::<T>()
}
```
...it cannot do so without repeating `function`'s `where` bound, which we cannot do because `Priv` is out-of-scope. A lint for this case is arguably helpful.

However, this same reasoning **doesn't** hold for trait impls. To call an unconstrained method on a public trait impl with private bounds, you don't need to forward those private bounds, you can forward the public trait:
```rust
mod upstream {
    pub trait Trait {
        fn method(&self) {}
    }
    pub struct Type<T>(T);

    pub struct Pub<T>(T);
    trait Priv {}
    impl<T: Priv> Priv for Pub<T> {}

    impl<T> Trait for Type<T>
    where
        Pub<T>: Priv // WARNING
    {}
}

mod downstream {
    use super::upstream::*;

    fn function<T>(value: Type<T>)
    where
        Type<T>: Trait // <- no private deets!
    {
        value.method();
    }
}
```

**This PR only eliminates the lint on trait impls.** It leaves it intact for all other contexts, including trait definitions, inherent impls, and function definitions. It doesn't need to exist in those cases either, but I figured I'd first target a case where it's mostly pointless.

## Other Notes
- See discussion [on zulip](https://rust-lang.zulipchat.com/#narrow/stream/213817-t-lang/topic/relax.20priv-in-pub.20lint.20for.20trait.20impl.20.60where.60.20bounds/near/222458397).
- This PR effectively reverts #79291.

2 years agoAdd myself to .mailmap
Wesley Wiser [Mon, 27 Dec 2021 20:37:12 +0000 (15:37 -0500)]
Add myself to .mailmap

2 years agoVisit patterns' literal expressions before binding new idents
Michael Goulet [Fri, 24 Dec 2021 00:03:30 +0000 (16:03 -0800)]
Visit patterns' literal expressions before binding new idents

2 years agocompiletest: Remove some vestigial code
Eric Huss [Mon, 27 Dec 2021 04:33:10 +0000 (20:33 -0800)]
compiletest: Remove some vestigial code

2 years agofix typo: intialized -> initialized
Hiroshi Kori [Mon, 27 Dec 2021 00:20:38 +0000 (16:20 -0800)]
fix typo: intialized -> initialized

2 years agofix typo: the use f.pad -> then use f.pad
Hiroshi Kori [Mon, 27 Dec 2021 00:03:17 +0000 (16:03 -0800)]
fix typo: the use f.pad -> then use f.pad

2 years agorelax priv-in-pub lint on generic bounds and where clauses in trait impls
Jack Wrenn [Thu, 4 Nov 2021 16:31:18 +0000 (16:31 +0000)]
relax priv-in-pub lint on generic bounds and where clauses in trait impls

2 years agoAdd test cases for issue #26186
PFPoitras [Sun, 26 Dec 2021 20:59:25 +0000 (16:59 -0400)]
Add test cases for issue #26186

2 years agonew lint: `init-numbered-fields`
Andre Bogus [Sat, 25 Dec 2021 15:52:58 +0000 (16:52 +0100)]
new lint: `init-numbered-fields`

2 years agoAuto merge of #8133 - surechen:fix_8128, r=xFrednet
bors [Sun, 26 Dec 2021 14:05:35 +0000 (14:05 +0000)]
Auto merge of #8133 - surechen:fix_8128, r=xFrednet

Fix 8128

Fixes #8128

changelog: Fix  error suggestion of `skip(..).next()` for immutable variable.

2 years agoFixes #8128
surechen [Fri, 17 Dec 2021 02:03:59 +0000 (10:03 +0800)]
Fixes #8128

changelog: Fix error suggestion of skip(..).next() for immutable variable.

2 years agoReverts #92135 because perf regression
AngelicosPhosphoros [Sun, 26 Dec 2021 13:02:33 +0000 (16:02 +0300)]
Reverts #92135 because perf regression

2 years agoAuto merge of #92257 - fee1-dead:fix_env_further_bounds, r=oli-obk
bors [Sun, 26 Dec 2021 08:52:31 +0000 (08:52 +0000)]
Auto merge of #92257 - fee1-dead:fix_env_further_bounds, r=oli-obk

normalize env constness for nested obligations

Closes #92230.

2 years agoRemove unneeded call to `collect`
Roc Yu [Sun, 26 Dec 2021 02:35:05 +0000 (21:35 -0500)]
Remove unneeded call to `collect`

2 years agoRemove `String` allocation in loop
Roc Yu [Sun, 26 Dec 2021 00:41:19 +0000 (19:41 -0500)]
Remove `String` allocation in loop

2 years agoAuto merge of #92262 - notriddle:notriddle/unused-hash, r=jyn514
bors [Sat, 25 Dec 2021 19:41:11 +0000 (19:41 +0000)]
Auto merge of #92262 - notriddle:notriddle/unused-hash, r=jyn514

rustdoc: remove unused Hash impl

2 years agoAuto merge of #92227 - Kobzol:rustdoc-doc-hidden, r=jyn514
bors [Sat, 25 Dec 2021 14:47:12 +0000 (14:47 +0000)]
Auto merge of #92227 - Kobzol:rustdoc-doc-hidden, r=jyn514

Rustdoc: use `is_doc_hidden` method on more places

While profiling `rustdoc`, I noticed that finding out if some item is marked with `#[doc(hidden)]` is relatively hot, so I tried to optimize it.

I noticed that there is already a method called `is_doc_hidden` on `TyCtxt`, but it wasn't used much, so I replaced the manual calls to `attrs(...).has_word(...)` with this method. Just by doing that, perf. was improved locally, although I'm not sure if the semantics of the previous calls and this method are the same?

As another step, I tried to querify `is_doc_hidden`, but I didn't include that here until we see the perf. results from the first commit and until I find whether this change is OK at all :)

Can I ask for a perf. run? Thanks.

r? `@jyn514`

2 years agoAdd limitation description for `enum_variant_names`
dswij [Fri, 24 Dec 2021 04:32:12 +0000 (12:32 +0800)]
Add limitation description for `enum_variant_names`

`enum_variant_names` will consider characters with no case to be a part
of prefixes/suffixes substring that are compared. This means `Foo1` and
`Foo2` has different prefixes (`Foo1` and `Foo2` prefix respeectively).
This applies to all non-ascii characters with no casing.

2 years agoSome minor cleanup
dswij [Fri, 24 Dec 2021 04:10:34 +0000 (12:10 +0800)]
Some minor cleanup

2 years agoFix reversed suggestion on postfix
dswij [Thu, 23 Dec 2021 05:55:41 +0000 (13:55 +0800)]
Fix reversed suggestion on postfix

2 years agoUpdate str_utils test
dswij [Thu, 23 Dec 2021 03:32:04 +0000 (11:32 +0800)]
Update str_utils test

2 years agoupdate `enum_variants` test
dswij [Wed, 22 Dec 2021 09:04:48 +0000 (17:04 +0800)]
update `enum_variants` test

2 years agoAdd str_util helpers to split camelcase strings
dswij [Wed, 22 Dec 2021 15:18:24 +0000 (23:18 +0800)]
Add str_util helpers to split camelcase strings

2 years agoFix False Positive on `enum_variants` when prefixes are not camel-case
dswij [Wed, 22 Dec 2021 15:18:11 +0000 (23:18 +0800)]
Fix False Positive on `enum_variants` when prefixes are not camel-case

2 years agoRefactor `enum_variants`
dswij [Wed, 15 Dec 2021 04:08:13 +0000 (12:08 +0800)]
Refactor `enum_variants`

2 years agoAuto merge of #8167 - rust-lang:fix-8166, r=xFredNet
bors [Sat, 25 Dec 2021 13:38:08 +0000 (13:38 +0000)]
Auto merge of #8167 - rust-lang:fix-8166, r=xFredNet

fix an ICE on unwrapping a None

This very likely fixes #8166 though I wasn't able to meaningfully reduce a test case. This line is the only call to `unwrap` within that function, which was the one in the stack trace that triggered the ICE, so I think we'll be OK.

`@hackmad` can you pull and build this branch and check if it indeed fixes your problem?

---

changelog: Fixed ICE in [`unnecessary_cast`]

2 years agofix an ICE on unwrapping a None
Andre Bogus [Sat, 25 Dec 2021 12:11:54 +0000 (13:11 +0100)]
fix an ICE on unwrapping a None

2 years agoAuto merge of #8165 - ebobrow:shadow_reuse_fn, r=xFrednet
bors [Sat, 25 Dec 2021 11:58:25 +0000 (11:58 +0000)]
Auto merge of #8165 - ebobrow:shadow_reuse_fn, r=xFrednet

fix [`shadow_reuse`] false negative for if let bindings

fixes #8087

changelog: trigger [`shadow_reuse`] instead of [`shadow_unrelated`] on shadowed `if let` bindings

2 years agoAuto merge of #92247 - lnicola:rust-analyzer-2021-12-24, r=lnicola
bors [Sat, 25 Dec 2021 02:19:48 +0000 (02:19 +0000)]
Auto merge of #92247 - lnicola:rust-analyzer-2021-12-24, r=lnicola

:arrow_up: rust-analyzer

r? `@ghost`

2 years agoAuto merge of #92229 - fee1-dead:fix-rustdoc-const-drop, r=dtolnay
bors [Fri, 24 Dec 2021 23:12:14 +0000 (23:12 +0000)]
Auto merge of #92229 - fee1-dead:fix-rustdoc-const-drop, r=dtolnay

Do not display `~const Drop` in rustdoc

Although `T: ~const Drop` is still at an experimental stage, we have already begun inserting these bounds in libstd. This change hides them from rustdoc because 1. `~const` should not be documented in general as it is not yet official syntax; 2. users are not expected to know what `~const Drop` means yet.

2 years agoRemove `maybe_uninit_extra` feature from Vec docs
Shadlock0133 [Fri, 24 Dec 2021 22:04:10 +0000 (23:04 +0100)]
Remove `maybe_uninit_extra` feature from Vec docs

In `Vec`, two doc tests are using `MaybeUninit::write` , stabilized in 1.55. This makes docs' usage of `maybe_uninit_extra` feature unnecessary.

2 years agofix `shadow_reuse` false negative for if let bindings
Elliot Bobrow [Fri, 24 Dec 2021 21:20:40 +0000 (13:20 -0800)]
fix `shadow_reuse` false negative for if let bindings

2 years agorustdoc: remove unused Hash impl
Michael Howell [Fri, 24 Dec 2021 20:23:03 +0000 (13:23 -0700)]
rustdoc: remove unused Hash impl

2 years agoAuto merge of #92135 - AngelicosPhosphoros:typeid_inline_74362, r=dtolnay
bors [Fri, 24 Dec 2021 20:06:15 +0000 (20:06 +0000)]
Auto merge of #92135 - AngelicosPhosphoros:typeid_inline_74362, r=dtolnay

Add `#[inline]` modifier to `TypeId::of`

It was already inlined but it happened only in 4th InlinerPass on my testcase.
With `#[inline]` modifier it happens on 2nd pass.

Closes #74362

2 years agobless ui test
Deadbeef [Fri, 24 Dec 2021 17:15:03 +0000 (01:15 +0800)]
bless ui test

2 years agoChange to enclose both sides of Range in parentheses.
hotate29 [Tue, 21 Dec 2021 12:45:55 +0000 (21:45 +0900)]
Change to enclose both sides of Range in parentheses.

2 years agoAuto merge of #92156 - petrochenkov:ctorkind, r=davidtwco
bors [Fri, 24 Dec 2021 17:09:21 +0000 (17:09 +0000)]
Auto merge of #92156 - petrochenkov:ctorkind, r=davidtwco

rustc_metadata: Merge `get_ctor_def_id` and `get_ctor_kind`

Also avoid decoding the whole `ty::AssocItem` to get a `has_self` flag.

A small optimization and cleanup extracted from https://github.com/rust-lang/rust/pull/89059.

2 years agoChange ```floating_point_arthmetic::detect_hypot()``` to enclose the expression in...
hotate29 [Fri, 24 Dec 2021 14:54:15 +0000 (23:54 +0900)]
Change ```floating_point_arthmetic::detect_hypot()``` to enclose the expression in parentheses.

2 years agonormalize env constness for nested obligations
Deadbeef [Fri, 24 Dec 2021 16:33:23 +0000 (00:33 +0800)]
normalize env constness for nested obligations

2 years agoUse helper functions in ```Sugg``` tests.
hotate29 [Tue, 21 Dec 2021 13:20:58 +0000 (22:20 +0900)]
Use helper functions in ```Sugg``` tests.

2 years agorefactor ```Sugg::BinOp```
hotate29 [Wed, 15 Dec 2021 14:23:36 +0000 (23:23 +0900)]
refactor ```Sugg::BinOp```

2 years agoAdd test
hotate29 [Tue, 14 Dec 2021 12:27:55 +0000 (21:27 +0900)]
Add test

2 years agoAuto merge of #92253 - RalfJung:miri, r=RalfJung
bors [Fri, 24 Dec 2021 13:15:21 +0000 (13:15 +0000)]
Auto merge of #92253 - RalfJung:miri, r=RalfJung

update Miri

Fixes https://github.com/rust-lang/rust/issues/92246
r? `@ghost`

2 years agoBump `gsgdt` to 0.1.3
Krasimir Georgiev [Fri, 24 Dec 2021 12:46:37 +0000 (13:46 +0100)]
Bump `gsgdt` to 0.1.3

No functional changes intended.

The 0.1.2 -> 0.1.3 commit https://github.com/vn-ki/gsgdt-rs/commit/3e1dcec5398d281e1b33afb41e43dfb248321a1d
renames `Node::new` to `Node::from_list`.

2 years agoAuto merge of #8163 - pmnoxx:piotr-improve-unwrap-or-default, r=Manishearth
bors [Fri, 24 Dec 2021 12:34:09 +0000 (12:34 +0000)]
Auto merge of #8163 - pmnoxx:piotr-improve-unwrap-or-default, r=Manishearth

Improve `unwrap_or_else_default` when handling `unwrap_or_else(XXX::new)`

changelog:  change `unwrap_or_else_default` to work with std constructors like `Vec::new`, `HashSet::new`, `HashMap::new`.

Notes:
- Code to handle detecting those constructors is already there. I moved it out to `is_default_equivalent_call`

2 years agoupdate Miri
Ralf Jung [Fri, 24 Dec 2021 12:04:15 +0000 (13:04 +0100)]
update Miri

2 years agoAuto merge of #92226 - woppopo:const_black_box, r=joshtriplett
bors [Fri, 24 Dec 2021 10:02:54 +0000 (10:02 +0000)]
Auto merge of #92226 - woppopo:const_black_box, r=joshtriplett

Constify `core::intrinsics::black_box` and `core::hint::black_box`.

`core::intrinsics::black_box` is already constified, but it wasn't marked as const (see: https://github.com/rust-lang/rust/blob/master/compiler/rustc_const_eval/src/interpret/intrinsics.rs#L471).

Tracking issue: None

2 years ago:arrow_up: rust-analyzer
Laurențiu Nicola [Fri, 24 Dec 2021 09:20:13 +0000 (11:20 +0200)]
:arrow_up: rust-analyzer

2 years agoSimplify code
Piotr Mikulski [Fri, 24 Dec 2021 06:12:08 +0000 (22:12 -0800)]
Simplify code

2 years agoRefactor
Piotr Mikulski [Fri, 24 Dec 2021 06:00:14 +0000 (22:00 -0800)]
Refactor

2 years agoclippy
Piotr Mikulski [Fri, 24 Dec 2021 05:47:31 +0000 (21:47 -0800)]
clippy

2 years agorefactor
Piotr Mikulski [Fri, 24 Dec 2021 05:46:21 +0000 (21:46 -0800)]
refactor

2 years agocargo dev fmt
Piotr Mikulski [Fri, 24 Dec 2021 05:44:13 +0000 (21:44 -0800)]
cargo dev fmt

2 years agoFix tests
Piotr Mikulski [Fri, 24 Dec 2021 05:43:30 +0000 (21:43 -0800)]
Fix tests

2 years agoFix tests
Piotr Mikulski [Fri, 24 Dec 2021 05:42:56 +0000 (21:42 -0800)]
Fix tests

2 years agorewrite the PR
Piotr Mikulski [Fri, 24 Dec 2021 05:41:00 +0000 (21:41 -0800)]
rewrite the PR

2 years agoRetain qualified path when rewriting struct literals
Yacin Tmimi [Fri, 24 Dec 2021 01:22:09 +0000 (20:22 -0500)]
Retain qualified path when rewriting struct literals

Fixes 5151

Details about the qualified path are now passed along so that rustfmt
can include them when formatting struct literals.

2 years agoFix static async closure qualifier order
David Tolnay [Thu, 23 Dec 2021 22:23:51 +0000 (14:23 -0800)]
Fix static async closure qualifier order

2 years agoAuto merge of #91342 - RalfJung:fn-abi, r=eddyb,oli-obk
bors [Fri, 24 Dec 2021 04:59:05 +0000 (04:59 +0000)]
Auto merge of #91342 - RalfJung:fn-abi, r=eddyb,oli-obk

CTFE eval_fn_call: use FnAbi to determine argument skipping and compatibility

This makes use of the `FnAbi` type in CTFE/Miri, which `@eddyb` has been saying for years is what we should do.^^ `FnAbi` is used to
- determine which arguments to skip (rather than the previous heuristic of skipping ZST arguments with the Rust ABI)
- impose further restrictions on whether caller and callee are consistent in how a given argument is passed

I was hoping it would also simplify the code, but that is not the case -- the previous type compatibility checks are still required (AFAIK), only the ZST skipping is gone and that took barely any code. We also need some hacks because `FnAbi` assumes a certain way of implementing `caller_location` (by passing extra arguments), but Miri can just read the caller location from the call stack so it doesn't need those arguments. (The fact that every backend has to separately implement support for these arguments seems suboptimal -- looks like this might have been better implemented on the MIR level.) To avoid having to implement those unnecessary arguments in Miri, we just compute *whether* the argument is present on the caller/callee side, but don't actually pass that argument around.

I have no idea if this looks the way `@eddyb` thinks it should look... but it makes Miri's test suite pass. ;)
One of rustc's tests fails unfortunately (`ui/const-generics/issues/issue-67739.rs`), some const generic code that is evaluated too early -- I think that should raise `TooGeneric` but instead it ICEs. My assumption is this is some FnAbi code that has not been properly tested on polymorphic code, but it might also be me calling that FnAbi code the wrong way.

r? `@oli-obk` `@eddyb`
Fixes https://github.com/rust-lang/rust/issues/56166
Miri PR at https://github.com/rust-lang/miri/pull/1928

2 years agoImrpove `unwrap_or_else_default`
Piotr Mikulski [Fri, 24 Dec 2021 03:13:57 +0000 (19:13 -0800)]
Imrpove `unwrap_or_else_default`

2 years agoAuto merge of #92220 - nnethercote:RawVec-dont-recompute-capacity, r=joshtriplett
bors [Fri, 24 Dec 2021 01:54:56 +0000 (01:54 +0000)]
Auto merge of #92220 - nnethercote:RawVec-dont-recompute-capacity, r=joshtriplett

RawVec: don't recompute capacity after allocating.

Currently it sets the capacity to `ptr.len() / mem::size_of::<T>()`
after any buffer allocation/reallocation. This would be useful if
allocators ever returned a `NonNull<[u8]>` with a size larger than
requested. But this never happens, so it's not useful.

Removing this slightly reduces the size of generated LLVM IR, and
slightly speeds up the hot path of `RawVec` growth.

r? `@ghost`

2 years agoFix tidy line length lint in stringify tests
David Tolnay [Fri, 24 Dec 2021 00:51:24 +0000 (16:51 -0800)]
Fix tidy line length lint in stringify tests

2 years agoFormat with rust-lang/rust's rustfmt settings
David Tolnay [Fri, 24 Dec 2021 00:53:30 +0000 (16:53 -0800)]
Format with rust-lang/rust's rustfmt settings

2 years agoAdd a test suite for stringify macro
David Tolnay [Thu, 23 Dec 2021 21:02:31 +0000 (13:02 -0800)]
Add a test suite for stringify macro

2 years agoAuto merge of #92222 - nnethercote:rm-global_allocator-rustc-rustdoc, r=alexcrichton
bors [Thu, 23 Dec 2021 22:34:13 +0000 (22:34 +0000)]
Auto merge of #92222 - nnethercote:rm-global_allocator-rustc-rustdoc, r=alexcrichton

Remove useless `#[global_allocator]` from rustc and rustdoc.

This was added in #83152, which has several errors in its comments.

This commit also fix up the comments, which are quite wrong and
misleading.

r? `@alexcrichton`

2 years agoAuto merge of #92232 - matthiaskrgr:rollup-eqdac7z, r=matthiaskrgr
bors [Thu, 23 Dec 2021 19:43:04 +0000 (19:43 +0000)]
Auto merge of #92232 - matthiaskrgr:rollup-eqdac7z, r=matthiaskrgr

Rollup of 5 pull requests

Successful merges:

 - #90625 (Add `UnwindSafe` to `Once`)
 - #92121 (disable test with self-referential generator on Miri)
 - #92166 (Fixed a small typo in ui test comments)
 - #92203 (Store a `DefId` instead of an `AdtDef` in `AggregateKind::Adt`)
 - #92231 (Update books)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup

2 years agoImport `SourceFile`s from crate before decoding foreign `Span`
Aaron Hill [Tue, 21 Dec 2021 19:01:10 +0000 (14:01 -0500)]
Import `SourceFile`s from crate before decoding foreign `Span`

Fixes #92163
Fixes #92014

When writing to the incremental cache, we encode all `Span`s
we encounter, regardless of whether or not their `SourceFile`
comes from the local crate, or from a foreign crate.

When we decode a `Span`, we use the `StableSourceFileId` we encoded
to locate the matching `SourceFile` in the current session. If this
id corresponds to a `SourceFile` from another crate, then we need to
have already imported that `SourceFile` into our current session.

This usually happens automatically during resolution / macro expansion,
when we try to resolve definitions from other crates. In certain cases,
however, we may try to load a `Span` from a transitive dependency
without having ever imported the `SourceFile`s from that crate, leading
to an ICE.

This PR fixes the issue by calling `imported_source_files()`
when we encounter a `SourceFile` with a foreign `CrateNum`.
This ensures that all `SourceFile`s from that crate are imported
into the current session.

2 years agoRollup merge of #92231 - ehuss:update-books, r=ehuss
Matthias Krüger [Thu, 23 Dec 2021 16:48:32 +0000 (17:48 +0100)]
Rollup merge of #92231 - ehuss:update-books, r=ehuss

Update books

## nomicon

1 commits in 49681ea4a9fa81173dbe9ffed74b4d4a35eae9e3..c05c452b36358821bf4122f9c418674edd1d713d
2021-11-24 16:27:28 +0900 to 2021-12-13 15:23:48 +0900
- Update the guidance on uninitialized data with ptr::addr_of_mut (rust-lang/nomicon#325)

## reference

3 commits in 954f3d441ad880737a13e241108f791a4d2a38cd..06f9e61931bcf58b91dfe6c924057e42ce273ee1
2021-11-29 11:11:30 -0800 to 2021-12-17 07:31:40 -0800
- keep consistent for primitive types (rust-lang/reference#1118)
- README.md: link to mdbook docs (rust-lang/reference#1117)
- Say that `...` range patterns are rejected in the 2021 edition (rust-lang/reference#1114)

## book

4 commits in 5f9358faeb1f46e19b8a23a21e79fd7fe150491e..8a0bb3c96e71927b80fa2286d7a5a5f2547c6aa4
2021-12-05 21:33:16 -0500 to 2021-12-22 20:54:27 -0500
- Propagate edits back
- Fix number disagreement. Fixes rust-lang/book#2858.
- Wrap some code in main to make scopes clearer. Fixes rust-lang/book#2830.
- Respond to ch5 nostarch edits

## rustc-dev-guide

9 commits in a374e7d8bb6b79de45b92295d06b4ac0ef35bc09..9bf0028b557798ddd07a6f652e4d0c635d3d6620
2021-12-03 09:26:47 -0800 to 2021-12-20 21:53:57 +0900
- remove rustfix item in test intro (rust-lang/rustc-dev-guide#1277)
- Move date-check comment to fix Markdown syntax
- Update humor docs for special-casing ferris emoji
- Fix some broken links (rust-lang/rustc-dev-guide#1274)
- Update rustdoc internals
- Update HIR chapter to use `HirId` instead of `NodeId`
- Fix some broken links
- Update src/getting-started.md
- Improve documentation on r?

2 years agoRollup merge of #92203 - Aaron1011:mir-adt-def, r=oli-obk
Matthias Krüger [Thu, 23 Dec 2021 16:48:31 +0000 (17:48 +0100)]
Rollup merge of #92203 - Aaron1011:mir-adt-def, r=oli-obk

Store a `DefId` instead of an `AdtDef` in `AggregateKind::Adt`

The `AggregateKind` enum ends up in the final mir `Body`. Currently,
any changes to `AdtDef` (regardless of how significant they are)
will legitimately cause the overall result of `optimized_mir` to change,
invalidating any codegen re-use involving that mir.

This will get worse once we start hashing the `Span` inside `FieldDef`
(which is itself contained in `AdtDef`).

To try to reduce these kinds of invalidations, this commit changes
`AggregateKind::Adt` to store just the `DefId`, instead of the full
`AdtDef`. This allows the result of `optimized_mir` to be unchanged
if the `AdtDef` changes in a way that doesn't actually affect any
of the MIR we build.

2 years agoRollup merge of #92166 - fee1-dead:patch-2, r=jyn514
Matthias Krüger [Thu, 23 Dec 2021 16:48:30 +0000 (17:48 +0100)]
Rollup merge of #92166 - fee1-dead:patch-2, r=jyn514

Fixed a small typo in ui test comments

2 years agoRollup merge of #92121 - RalfJung:miri-core-test, r=kennytm
Matthias Krüger [Thu, 23 Dec 2021 16:48:30 +0000 (17:48 +0100)]
Rollup merge of #92121 - RalfJung:miri-core-test, r=kennytm

disable test with self-referential generator on Miri

Running the libcore test suite in Miri currently fails due to the known incompatibility of self-referential generators with Miri's aliasing checks (https://github.com/rust-lang/unsafe-code-guidelines/issues/148). So let's disable that test in Miri for now.

2 years agoRollup merge of #90625 - Milo123459:ref-unwind-safe, r=dtolnay
Matthias Krüger [Thu, 23 Dec 2021 16:48:29 +0000 (17:48 +0100)]
Rollup merge of #90625 - Milo123459:ref-unwind-safe, r=dtolnay

Add `UnwindSafe` to `Once`

Fixes #43469

2 years agoUpdate books
Eric Huss [Thu, 23 Dec 2021 16:44:14 +0000 (08:44 -0800)]
Update books

2 years agoAuto merge of #92110 - nagisa:def-inlining, r=nikic
bors [Thu, 23 Dec 2021 16:12:23 +0000 (16:12 +0000)]
Auto merge of #92110 - nagisa:def-inlining, r=nikic

Backport LLVM changes to disable deferred inlining

Fixes #91128

I was thinking of how to best add the test case from the issue, and I think rust perf infrastructure would probably be the best place for something like it.

2 years agoDo not display `~const Drop` in rustdoc
Deadbeef [Thu, 23 Dec 2021 14:52:34 +0000 (22:52 +0800)]
Do not display `~const Drop` in rustdoc

2 years agoAuto merge of #92177 - GuillaumeGomez:pattern-matching-outside-loop, r=camelid
bors [Thu, 23 Dec 2021 12:11:27 +0000 (12:11 +0000)]
Auto merge of #92177 - GuillaumeGomez:pattern-matching-outside-loop, r=camelid

Move pattern matching outside of the loop

Not sure if worth it but it's been bugging me for a while now.

r? `@camelid`

2 years agoConstify `core::intrinsics::black_box`
woppopo [Thu, 23 Dec 2021 11:07:41 +0000 (20:07 +0900)]
Constify `core::intrinsics::black_box`

2 years agoRustdoc: use `is_doc_hidden` method on more places
Jakub Beránek [Thu, 23 Dec 2021 10:31:05 +0000 (11:31 +0100)]
Rustdoc: use `is_doc_hidden` method on more places

2 years agoAuto merge of #8144 - Gh0stm4chine:master, r=xFrednet
bors [Thu, 23 Dec 2021 10:06:17 +0000 (10:06 +0000)]
Auto merge of #8144 - Gh0stm4chine:master, r=xFrednet

Add suggestion for neg_multiply lint

This fixes #8115 by adding a suggestion for [neg_multiply].

My first issue on Github, any feedback or input is welcome 😃

changelog: create a suggestion for `neg_multiply`

2 years agoAdd allow unused
Oussama [Thu, 23 Dec 2021 09:45:16 +0000 (10:45 +0100)]
Add allow unused

2 years agoAuto merge of #92167 - pierwill:chalk-update, r=jackh726
bors [Thu, 23 Dec 2021 08:59:55 +0000 (08:59 +0000)]
Auto merge of #92167 - pierwill:chalk-update, r=jackh726

Update chalk to 0.75.0

- Compute flags in `intern_ty`
- Remove `tracing-serde` from `PERMITTED_DEPENDENCIES`
- Bump `tracing-tree` to 0.2.0
- Bump `tracing-subscriber` to 0.3.3

2 years agoAdd allow precedence lint to prevent rustfix from failing
Oussama [Thu, 23 Dec 2021 08:22:29 +0000 (09:22 +0100)]
Add allow precedence lint to prevent rustfix from failing

2 years agoRemove useless `#[global_allocator]` from rustc and rustdoc.
Nicholas Nethercote [Thu, 23 Dec 2021 04:47:32 +0000 (15:47 +1100)]
Remove useless `#[global_allocator]` from rustc and rustdoc.

This was added in #83152, which has several errors in its comments.

This commit also fix up the comments, which are quite wrong and
misleading.

2 years agoAuto merge of #92155 - m-ou-se:panic-fn, r=eddyb
bors [Thu, 23 Dec 2021 05:17:47 +0000 (05:17 +0000)]
Auto merge of #92155 - m-ou-se:panic-fn, r=eddyb

Use panic() instead of panic!() in some places in core.

See https://github.com/rust-lang/rust/pull/92068 and https://github.com/rust-lang/rust/pull/92140.

This avoids the `panic!()` macro in a few potentially hot paths. This becomes more relevant when switching `core` to Rust 2021, as it'll avoid format_args!() and save some compilation time. (It doesn't make a huge difference, but still.) (Also the errors in const panic become slightly nicer.)

2 years agoRemove VCVARS_BAT
Eric Huss [Thu, 23 Dec 2021 03:18:06 +0000 (19:18 -0800)]
Remove VCVARS_BAT

2 years agoAuto merge of #92216 - matthiaskrgr:rollup-luplvuc, r=matthiaskrgr
bors [Thu, 23 Dec 2021 01:47:08 +0000 (01:47 +0000)]
Auto merge of #92216 - matthiaskrgr:rollup-luplvuc, r=matthiaskrgr

Rollup of 7 pull requests

Successful merges:

 - #88858 (Allow reverse iteration of lowercase'd/uppercase'd chars)
 - #91544 (Fix duplicate derive clone suggestion)
 - #92026 (Add some JSDoc comments to rustdoc JS)
 - #92117 (kmc-solid: Add `std::sys::solid::fs::File::read_buf`)
 - #92139 (Change Backtrace::enabled atomic from SeqCst to Relaxed)
 - #92146 (Don't emit shared files when scraping examples from dependencies in Rustdoc)
 - #92208 (Quote bat script command line)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup

2 years agoRollup merge of #92208 - ChrisDenton:win-bat-cmd, r=dtolnay
Matthias Krüger [Wed, 22 Dec 2021 23:28:56 +0000 (00:28 +0100)]
Rollup merge of #92208 - ChrisDenton:win-bat-cmd, r=dtolnay

Quote bat script command line

Fixes #91991

[`CreateProcessW`](https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-createprocessw#parameters) should only be used to run exe files but it does have some (undocumented) special handling for files with `.bat` and `.cmd` extensions. Essentially those magic extensions will cause the parameters to be automatically rewritten. Example pseudo Rust code (note that `CreateProcess` starts with an optional application name followed by the application arguments):
```rust
// These arguments...
CreateProcess(None, `@"foo.bat` "hello world""`@,` ...);
// ...are rewritten as
CreateProcess(Some(r"C:\Windows\System32\cmd.exe"), `@""foo.bat` "hello world"""`@,` ...);
```

However, when setting the first parameter (the application name) as we now do, it will omit the extra level of quotes around the arguments:

```rust
// These arguments...
CreateProcess(Some("foo.bat"), `@"foo.bat` "hello world""`@,` ...);
// ...are rewritten as
CreateProcess(Some(r"C:\Windows\System32\cmd.exe"), `@"foo.bat` "hello world""`@,` ...);
```

This means the arguments won't be passed to the script as intended.

Note that running batch files this way is undocumented but people have relied on this so we probably shouldn't break it.

2 years agoRollup merge of #92146 - willcrichton:example-analyzer, r=jyn514
Matthias Krüger [Wed, 22 Dec 2021 23:28:55 +0000 (00:28 +0100)]
Rollup merge of #92146 - willcrichton:example-analyzer, r=jyn514

Don't emit shared files when scraping examples from dependencies in Rustdoc

This PR fixes #91605. The issue is that `Context::init` gets called when scraping dependencies. By default, just calling `init` calls into `write_shared` and `build_index` which register the scraped crate into a list that later gets used for the Rustdoc sidebar. The fix is to ensure that `write_shared` is not called when scraping.

r? `@jyn514`

2 years agoRollup merge of #92139 - dtolnay:backtrace, r=m-ou-se
Matthias Krüger [Wed, 22 Dec 2021 23:28:54 +0000 (00:28 +0100)]
Rollup merge of #92139 - dtolnay:backtrace, r=m-ou-se

Change Backtrace::enabled atomic from SeqCst to Relaxed

This atomic is not synchronizing anything outside of its own value, so we don't need the `Acquire`/`Release` guarantee that all memory operations prior to the store are visible after the subsequent load, nor the `SeqCst` guarantee of all threads seeing all of the sequentially consistent operations in the same order.

Using `Relaxed` reduces the overhead of `Backtrace::capture()` in the case that backtraces are not enabled.

## Benchmark

```rust
#![feature(backtrace)]

use std::backtrace::Backtrace;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::thread;
use std::time::Instant;

fn main() {
    let begin = Instant::now();
    let mut threads = Vec::new();
    for _ in 0..64 {
        threads.push(thread::spawn(|| {
            for _ in 0..10_000_000 {
                let _ = Backtrace::capture();
                static LOL: AtomicUsize = AtomicUsize::new(0);
                LOL.store(1, Ordering::Release);
            }
        }));
    }
    for thread in threads {
        let _ = thread.join();
    }
    println!("{:?}", begin.elapsed());
}
```

**Before:**&ensp;6.73 seconds
**After:**&ensp;5.18 seconds

2 years agoRollup merge of #92117 - solid-rs:fix-kmc-solid-read-buf, r=yaahc
Matthias Krüger [Wed, 22 Dec 2021 23:28:53 +0000 (00:28 +0100)]
Rollup merge of #92117 - solid-rs:fix-kmc-solid-read-buf, r=yaahc

kmc-solid: Add `std::sys::solid::fs::File::read_buf`

This PR adds `std::sys::solid::fs::File::read_buf` to catch up with the changes introduced by #81156 and fix the [`*-kmc-solid_*`](https://doc.rust-lang.org/nightly/rustc/platform-support/kmc-solid.html) Tier 3 targets..

2 years agoRollup merge of #92026 - jsha:jsdoc-search, r=GuillaumeGomez
Matthias Krüger [Wed, 22 Dec 2021 23:28:52 +0000 (00:28 +0100)]
Rollup merge of #92026 - jsha:jsdoc-search, r=GuillaumeGomez

Add some JSDoc comments to rustdoc JS

This follows the Closure Compiler dialect of JSDoc, so we can use it to do some basic type checking. We don't plan to compile with Closure Compiler, just use it to check types. See https://github.com/google/closure-compiler/wiki/ for details.

To try checking the annotations, run:

```
npm i -g google-closure-compiler
google-closure-compiler -W VERBOSE build/x86_64-unknown-linux-gnu/doc/{search-index1.59.0.js,crates1.59.0.js} src/librustdoc/html/static/js/{search.js,main.js,storage.js} --externs src/librustdoc/html/static/js/externs.js >/dev/null
```

You'll see some warnings that "String continuations are not recommended". I'm not addressing those right now.

[Discussed on Zulip](https://rust-lang.zulipchat.com/#narrow/stream/266220-rustdoc/topic/doc.20format.20for.20JS/near/265209466).

r? `@GuillaumeGomez`

2 years agoRollup merge of #91544 - rukai:91492, r=wesleywiser
Matthias Krüger [Wed, 22 Dec 2021 23:28:51 +0000 (00:28 +0100)]
Rollup merge of #91544 - rukai:91492, r=wesleywiser

Fix duplicate derive clone suggestion

closes https://github.com/rust-lang/rust/issues/91492

The addition of:
```rust
derives.sort();
derives.dedup();
```
is what actually solves the problem.
The rest is just cleanup.

I want to improve the diagnostic message to provide the suggestion as a proper diff but ran into some problems, so I'll attempt that again in a follow up PR.

2 years agoRollup merge of #88858 - spektom:to_lower_upper_rev, r=dtolnay
Matthias Krüger [Wed, 22 Dec 2021 23:28:51 +0000 (00:28 +0100)]
Rollup merge of #88858 - spektom:to_lower_upper_rev, r=dtolnay

Allow reverse iteration of lowercase'd/uppercase'd chars

The PR implements `DoubleEndedIterator` trait for `ToLowercase` and `ToUppercase`.

This enables reverse iteration of lowercase/uppercase variants of character sequences.
One of use cases:  determining whether a char sequence is a suffix of another one.

Example:

```rust
fn endswith_ignore_case(s1: &str, s2: &str) -> bool {
    for eob in s1
        .chars()
        .flat_map(|c| c.to_lowercase())
        .rev()
        .zip_longest(s2.chars().flat_map(|c| c.to_lowercase()).rev())
    {
        match eob {
            EitherOrBoth::Both(c1, c2) => {
                if c1 != c2 {
                    return false;
                }
            }
            EitherOrBoth::Left(_) => return true,
            EitherOrBoth::Right(_) => return false,
        }
    }
    true
}
```

2 years agoAuto merge of #90408 - pierwill:untrack-localdefid-90317, r=cjgillot
bors [Wed, 22 Dec 2021 22:33:11 +0000 (22:33 +0000)]
Auto merge of #90408 - pierwill:untrack-localdefid-90317, r=cjgillot

Remove `PartialOrd`, `Ord` from `LocalDefId`

Part of work on https://github.com/rust-lang/rust/issues/90317.