]> git.lizzy.rs Git - rust.git/log
rust.git
3 years agoadd testcase for 87076
Marcel Hellwig [Mon, 19 Jul 2021 05:24:07 +0000 (07:24 +0200)]
add testcase for 87076

using
https://github.com/rust-lang/rust/issues/87076#issuecomment-878090143 as
testcase

3 years agoRun bless
Anthony Huang [Mon, 19 Jul 2021 05:21:06 +0000 (01:21 -0400)]
Run bless

3 years agoAuto merge of #87146 - Aaron1011:better-macro-lint, r=petrochenkov
bors [Mon, 19 Jul 2021 04:22:51 +0000 (04:22 +0000)]
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.

3 years agoAuto merge of #86848 - notriddle:notriddle/drop-dyn, r=varkor
bors [Mon, 19 Jul 2021 01:41:54 +0000 (01:41 +0000)]
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>) {}
```

3 years agoAuto merge of #87004 - JamieCunliffe:pgo-gc-sections, r=Mark-Simulacrum
bors [Sun, 18 Jul 2021 23:14:31 +0000 (23:14 +0000)]
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`

3 years agoMove asm! and global_asm! to core::arch
bstrie [Sat, 17 Jul 2021 18:48:00 +0000 (14:48 -0400)]
Move asm! and global_asm! to core::arch

3 years agoAuto merge of #86950 - tmiasko:personality, r=nagisa
bors [Sun, 18 Jul 2021 20:33:23 +0000 (20:33 +0000)]
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.

3 years agotriagebot shortcut config
Llandy Riveron Del Risco [Sun, 18 Jul 2021 19:52:18 +0000 (21:52 +0200)]
triagebot shortcut config

3 years agobetter support for running libcore and liballoc tests with Miri
Ralf Jung [Sun, 18 Jul 2021 15:21:59 +0000 (17:21 +0200)]
better support for running libcore and liballoc tests with Miri

3 years agoAuto merge of #7474 - camsteffen:binop, r=Manishearth
bors [Sun, 18 Jul 2021 15:52:49 +0000 (15:52 +0000)]
Auto merge of #7474 - camsteffen:binop, r=Manishearth

Use lang items for BinOp lints

changelog: none

3 years agoExtend HIR-based WF checking to associated type defaults
Aaron Hill [Sun, 18 Jul 2021 15:36:07 +0000 (10:36 -0500)]
Extend HIR-based WF checking to associated type defaults

Previously, we would only look at associated types in `impl` blocks.

3 years agofix(clippy): add missing allow(dyn_drop)
Michael Howell [Sun, 18 Jul 2021 14:57:03 +0000 (07:57 -0700)]
fix(clippy): add missing allow(dyn_drop)

3 years agoAdd `#![allow(dyn_drop)]` to test cases with `dyn Drop` in them
Michael Howell [Sat, 3 Jul 2021 18:52:19 +0000 (11:52 -0700)]
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.

3 years agofeat(rustc_lint): add `dyn_drop`
Michael Howell [Sat, 3 Jul 2021 18:20:01 +0000 (11:20 -0700)]
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>) {}
```

3 years agoRemove unused stuff and switch to pub(crate) whenever possible.
Charles Lew [Sun, 18 Jul 2021 07:35:37 +0000 (15:35 +0800)]
Remove unused stuff and switch to pub(crate) whenever possible.

3 years agoAuto merge of #87252 - RalfJung:miri, r=RalfJung
bors [Sun, 18 Jul 2021 13:11:39 +0000 (13:11 +0000)]
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`

3 years agoFix compilation errors.
Charles Lew [Sun, 18 Jul 2021 06:52:46 +0000 (14:52 +0800)]
Fix compilation errors.

3 years agoMove `library/term/src` to `library/test/src/term/`.
Charles Lew [Sun, 18 Jul 2021 06:42:14 +0000 (14:42 +0800)]
Move `library/term/src` to `library/test/src/term/`.

3 years agoRemove impl_trait_in_bindings feature flag
Santiago Pastorino [Fri, 16 Jul 2021 13:06:26 +0000 (10:06 -0300)]
Remove impl_trait_in_bindings feature flag

3 years agoMove mir_def_id inside `eq_opaque_type_and_type`
Santiago Pastorino [Thu, 15 Jul 2021 12:55:13 +0000 (09:55 -0300)]
Move mir_def_id inside `eq_opaque_type_and_type`

3 years agoRemove `sub_types_or_anon`
Santiago Pastorino [Thu, 15 Jul 2021 12:48:14 +0000 (09:48 -0300)]
Remove `sub_types_or_anon`

3 years agoAdd `sub_types` docs
Santiago Pastorino [Thu, 15 Jul 2021 12:47:33 +0000 (09:47 -0300)]
Add `sub_types` docs

3 years agoRevert "structural_match: non-structural-match ty closures"
Santiago Pastorino [Wed, 14 Jul 2021 22:00:48 +0000 (19:00 -0300)]
Revert "structural_match: non-structural-match ty closures"

Reverts #73353

3 years agoRemove origin field from TypeAliasesOpaqueTy
Santiago Pastorino [Thu, 15 Jul 2021 15:43:54 +0000 (12:43 -0300)]
Remove origin field from TypeAliasesOpaqueTy

3 years agoUse == to compare OpaqueTyOrigin values
Santiago Pastorino [Thu, 15 Jul 2021 15:42:18 +0000 (12:42 -0300)]
Use == to compare OpaqueTyOrigin values

3 years agoRemove OpaqueTyOrigin::Misc, use TyAlias instead
Santiago Pastorino [Wed, 14 Jul 2021 21:23:36 +0000 (18:23 -0300)]
Remove OpaqueTyOrigin::Misc, use TyAlias instead

3 years agoRemoving unhandled region constraint error that is only for impl_trait_in_bindings
Santiago Pastorino [Wed, 14 Jul 2021 20:12:34 +0000 (17:12 -0300)]
Removing unhandled region constraint error that is only for impl_trait_in_bindings

3 years agoRemove impl_trait_in_bindings handling on inference error reporting
Santiago Pastorino [Wed, 14 Jul 2021 19:55:31 +0000 (16:55 -0300)]
Remove impl_trait_in_bindings handling on inference error reporting

3 years agoRemove impl trait bindings handling on const AST lowering
Santiago Pastorino [Wed, 14 Jul 2021 19:17:56 +0000 (16:17 -0300)]
Remove impl trait bindings handling on const AST lowering

3 years agoupdate Miri
Ralf Jung [Sun, 18 Jul 2021 10:43:39 +0000 (12:43 +0200)]
update Miri

3 years agoAuto merge of #86698 - cjgillot:modc, r=estebank
bors [Sun, 18 Jul 2021 10:42:23 +0000 (10:42 +0000)]
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.

3 years agoAdd test to check width of item-info
Guillaume Gomez [Sun, 18 Jul 2021 10:32:26 +0000 (12:32 +0200)]
Add test to check width of item-info

3 years agoFix implicit Sized relaxation when attempting to relax other, unsupported trait
robojumper [Sun, 18 Jul 2021 10:29:21 +0000 (12:29 +0200)]
Fix implicit Sized relaxation when attempting to relax other, unsupported trait

3 years agoFix item info display
Guillaume Gomez [Sun, 18 Jul 2021 10:25:49 +0000 (12:25 +0200)]
Fix item info display

3 years agoAdd test for unsupported bound relaxation with incorrect behavior
robojumper [Sun, 18 Jul 2021 10:21:09 +0000 (12:21 +0200)]
Add test for unsupported bound relaxation with incorrect behavior

3 years agoAdd invalid rust code for test
Guillaume Gomez [Fri, 9 Jul 2021 09:06:20 +0000 (11:06 +0200)]
Add invalid rust code for test

3 years agoDon't capture child process output at all when --no-capture is used
Guillaume Gomez [Fri, 9 Jul 2021 08:58:02 +0000 (10:58 +0200)]
Don't capture child process output at all when --no-capture is used

3 years agoAdd doc for --nocapture
Guillaume Gomez [Fri, 11 Jun 2021 20:20:40 +0000 (22:20 +0200)]
Add doc for --nocapture

3 years agoAdd test for rustdoc --nocapture option
Guillaume Gomez [Fri, 11 Jun 2021 20:11:35 +0000 (22:11 +0200)]
Add test for rustdoc --nocapture option

3 years agoAdd --nocapture option to rustdoc
Guillaume Gomez [Fri, 11 Jun 2021 14:53:32 +0000 (16:53 +0200)]
Add --nocapture option to rustdoc

3 years agoRemove deadlock virtual call.
Camille GILLOT [Mon, 28 Jun 2021 19:33:47 +0000 (21:33 +0200)]
Remove deadlock virtual call.

3 years agoMove OnDiskCache to rustc_query_impl.
Camille GILLOT [Mon, 28 Jun 2021 19:12:01 +0000 (21:12 +0200)]
Move OnDiskCache to rustc_query_impl.

3 years agomiri: better ptr-out-of-bounds errors
Ralf Jung [Sat, 17 Jul 2021 18:12:28 +0000 (20:12 +0200)]
miri: better ptr-out-of-bounds errors

3 years agoAuto merge of #87242 - JohnTitor:rollup-t9rmwpo, r=JohnTitor
bors [Sun, 18 Jul 2021 08:15:17 +0000 (08:15 +0000)]
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

3 years agoWhen pretty printing, name placeholders as bound regions
jackh726 [Sun, 18 Jul 2021 07:18:05 +0000 (03:18 -0400)]
When pretty printing, name placeholders as bound regions

3 years agoAdd tests for command line lint control
inquisitivecrystal [Fri, 9 Jul 2021 04:35:26 +0000 (21:35 -0700)]
Add tests for command line lint control

3 years agoMake `--force-warns` a normal lint level option
inquisitivecrystal [Thu, 8 Jul 2021 07:05:38 +0000 (00:05 -0700)]
Make `--force-warns` a normal lint level option

3 years agoAuto merge of #87071 - inquisitivecrystal:inclusive-range, r=estebank
bors [Sun, 18 Jul 2021 05:58:16 +0000 (05:58 +0000)]
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`

3 years agoRollup merge of #87205 - matthiaskrgr:clippy_cln, r=oli-obk
Yuki Okushi [Sun, 18 Jul 2021 05:21:59 +0000 (14:21 +0900)]
Rollup merge of #87205 - matthiaskrgr:clippy_cln, r=oli-obk

rustc_middle: remove redundant clone

found while looking through some clippy lint warnings

3 years agoRollup merge of #87183 - RalfJung:option-doctest, r=jyn514
Yuki Okushi [Sun, 18 Jul 2021 05:21:58 +0000 (14:21 +0900)]
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``

3 years agoRollup merge of #87170 - xFrednet:clippy-5393-add-diagnostic-items, r=Manishearth...
Yuki Okushi [Sun, 18 Jul 2021 05:21:57 +0000 (14:21 +0900)]
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`](https://github.com/rust-lang/rust-clippy/blob/ecf85f4bdc319f9d9d853d1fff68a8a25e64c7a8/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`

3 years agoRollup merge of #87092 - ricobbe:fix-raw-dylib-multiple-definitions, r=petrochenkov
Yuki Okushi [Sun, 18 Jul 2021 05:21:56 +0000 (14:21 +0900)]
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.

3 years agoRollup merge of #86889 - jyn514:crate-cleanup, r=camelid
Yuki Okushi [Sun, 18 Jul 2021 05:21:55 +0000 (14:21 +0900)]
Rollup merge of #86889 - jyn514:crate-cleanup, r=camelid

rustdoc: Cleanup ExternalCrate

- Remove unnecessary CrateNum from Cache.externs
- Remove trival impl Clean for CrateNum

3 years agoRollup merge of #86843 - FabianWolff:issue-86820, r=lcnr
Yuki Okushi [Sun, 18 Jul 2021 05:21:54 +0000 (14:21 +0900)]
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`

3 years agoRollup merge of #86814 - Aaron1011:inner-doc-recover, r=estebank
Yuki Okushi [Sun, 18 Jul 2021 05:21:53 +0000 (14:21 +0900)]
Rollup merge of #86814 - Aaron1011:inner-doc-recover, r=estebank

Recover from a misplaced inner doc comment

Fixes #86781

3 years agoRollup merge of #86763 - JohnTitor:test-63355, r=oli-obk
Yuki Okushi [Sun, 18 Jul 2021 05:21:52 +0000 (14:21 +0900)]
Rollup merge of #86763 - JohnTitor:test-63355, r=oli-obk

Add a regression test for issue-63355

Closes #63355
r? ``@nikomatsakis``

3 years agoAdd test for `#[allow]` for warnings on attribute macro
Aaron Hill [Sat, 17 Jul 2021 13:31:13 +0000 (08:31 -0500)]
Add test for `#[allow]` for warnings on attribute macro

3 years agoOnly use `assign_id!` for ast nodes that support attributes
Aaron Hill [Sat, 17 Jul 2021 13:22:09 +0000 (08:22 -0500)]
Only use `assign_id!` for ast nodes that support attributes

3 years agoAdd additional missing lint handling logic
Aaron Hill [Thu, 15 Jul 2021 19:26:27 +0000 (14:26 -0500)]
Add additional missing lint handling logic

3 years agoAdd missing `visit_expr_field`
Aaron Hill [Thu, 15 Jul 2021 01:07:56 +0000 (20:07 -0500)]
Add missing `visit_expr_field`

3 years agoCompute a better `lint_node_id` during expansion
Aaron Hill [Wed, 14 Jul 2021 23:24:12 +0000 (18:24 -0500)]
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.

3 years agoAuto merge of #7473 - Jarcho:ice_7340, r=Manishearth
bors [Sun, 18 Jul 2021 03:32:31 +0000 (03:32 +0000)]
Auto merge of #7473 - Jarcho:ice_7340, r=Manishearth

Fix ICE in `is_integer_const`

fixes: #7340
changelog: Fix ICE in `modulo_one` in const contexts

3 years agoRemove impl traits bindings error message handling on AST lowering
Santiago Pastorino [Wed, 14 Jul 2021 18:48:33 +0000 (15:48 -0300)]
Remove impl traits bindings error message handling on AST lowering

3 years agoFix TypeAliasesOpaqueTy origin docs
Santiago Pastorino [Wed, 14 Jul 2021 18:45:24 +0000 (15:45 -0300)]
Fix TypeAliasesOpaqueTy origin docs

3 years agoRename OtherOpaqueTy to TypeAliasesOpaqueTy
Santiago Pastorino [Wed, 14 Jul 2021 18:06:02 +0000 (15:06 -0300)]
Rename OtherOpaqueTy to TypeAliasesOpaqueTy

3 years agoRemove OpaqueTyOrigin::Binding
Santiago Pastorino [Wed, 14 Jul 2021 15:31:58 +0000 (12:31 -0300)]
Remove OpaqueTyOrigin::Binding

3 years agoAuto merge of #85686 - ptrojahn:loop_reinitialize, r=estebank
bors [Sun, 18 Jul 2021 02:13:12 +0000 (02:13 +0000)]
Auto merge of #85686 - ptrojahn:loop_reinitialize, r=estebank

Add help on reinitialization between move and access

Fixes #83760

3 years agoFactor BinOp utils
Cameron Steffen [Fri, 16 Jul 2021 19:41:19 +0000 (14:41 -0500)]
Factor BinOp utils

3 years agox.py fmt
Dan Gohman [Sun, 18 Jul 2021 01:31:51 +0000 (18:31 -0700)]
x.py fmt

3 years agoUse From to convert BinOpKind
Cameron Steffen [Mon, 28 Jun 2021 19:05:48 +0000 (14:05 -0500)]
Use From to convert BinOpKind

3 years agoFix ICE in `is_integer_const` when the expression is inside an `AnonConst` body
Jason Newcomb [Sat, 17 Jul 2021 23:01:19 +0000 (19:01 -0400)]
Fix ICE in `is_integer_const` when the expression is inside an `AnonConst` body

3 years agoAuto merge of #87129 - FabianWolff:issue-75356, r=varkor
bors [Sat, 17 Jul 2021 22:51:07 +0000 (22:51 +0000)]
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](https://github.com/llvm/llvm-project/blob/56e6d4742e6909bd7d2db201cc5e0e3e77c6f282/clang/lib/Sema/SemaExpr.cpp#L13875-L13909), my implementation also warns about self-assignments of struct fields (`s.x = s.x`).

r? `@varkor`

3 years agoAdd GUI test for <table> overflow
Guillaume Gomez [Sat, 17 Jul 2021 22:03:08 +0000 (00:03 +0200)]
Add GUI test for <table> overflow

3 years agoRemove unused file
Guillaume Gomez [Sat, 17 Jul 2021 21:56:24 +0000 (23:56 +0200)]
Remove unused file

3 years agoFix <table> overflow in doc blocks
Guillaume Gomez [Sat, 17 Jul 2021 21:39:18 +0000 (23:39 +0200)]
Fix <table> overflow in doc blocks

3 years agoRemove an unnecessary `Mutex` around argument initialization.
Dan Gohman [Sat, 17 Jul 2021 19:33:31 +0000 (12:33 -0700)]
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.

3 years agoRemove args cleanup code.
Dan Gohman [Sat, 17 Jul 2021 12:47:39 +0000 (05:47 -0700)]
Remove args cleanup code.

As of 91c3eee1735ad72b579f99cbb6919c3471747d94, the global ARGC and ARGV
no longer reference dynamically-allocated memory, so they don't need to
be cleaned up.

3 years agoAuto merge of #87203 - jackh726:logging, r=nikomatsakis
bors [Sat, 17 Jul 2021 20:23:58 +0000 (20:23 +0000)]
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.

3 years agoAdd needs_normalization
jackh726 [Fri, 16 Jul 2021 20:23:42 +0000 (16:23 -0400)]
Add needs_normalization

3 years agoSome perf optimizations and logging
jackh726 [Fri, 16 Jul 2021 20:23:42 +0000 (16:23 -0400)]
Some perf optimizations and logging

3 years agoFix sidebar-mobile test to focus on an actual focusable element
Michael Howell [Sat, 17 Jul 2021 18:53:59 +0000 (11:53 -0700)]
Fix sidebar-mobile test to focus on an actual focusable element

3 years agoFix test cases for header titles in sidebar
Michael Howell [Sat, 17 Jul 2021 16:45:07 +0000 (09:45 -0700)]
Fix test cases for header titles in sidebar

3 years agoRemove redundant CSS
Michael Howell [Sat, 17 Jul 2021 05:00:22 +0000 (22:00 -0700)]
Remove redundant CSS

3 years agoRustdoc accessibility: make the sidebar headers actual headers
Michael Howell [Sat, 17 Jul 2021 04:58:23 +0000 (21:58 -0700)]
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

3 years agoAuto merge of #86676 - cjgillot:localexpn, r=petrochenkov
bors [Sat, 17 Jul 2021 17:56:46 +0000 (17:56 +0000)]
Auto merge of #86676 - cjgillot:localexpn, r=petrochenkov

Make expansions stable for incr. comp.

This PR aims to make expansions stable for incr. comp. by using the same architecture as definitions:
- the interned identifier `ExpnId` contains a `CrateNum` and a crate-local id;
- bidirectional maps `ExpnHash <-> ExpnId` are setup;
- incr. comp. on-disk cache saves and reconstructs expansions using their `ExpnHash`.

I tried to use as many `LocalExpnId` as I could in the resolver code, but I may have missed a few opportunities.

All this will allow to use an `ExpnId` as a query key, and to force this query without recomputing caller queries. For instance, this will be used to implement #85999.

r? `@petrochenkov`

3 years agoSimplify Expn creation.
Camille GILLOT [Thu, 15 Jul 2021 11:45:38 +0000 (13:45 +0200)]
Simplify Expn creation.

3 years agoRename expn_info -> expn_data.
Camille GILLOT [Thu, 15 Jul 2021 11:34:33 +0000 (13:34 +0200)]
Rename expn_info -> expn_data.

3 years agoPass ExpnData by reference.
Camille GILLOT [Mon, 12 Jul 2021 14:56:13 +0000 (16:56 +0200)]
Pass ExpnData by reference.

3 years agoAlways hash spans in expn.
Camille GILLOT [Sun, 27 Jun 2021 19:30:20 +0000 (21:30 +0200)]
Always hash spans in expn.

3 years agoDrop ExpnData::krate.
Camille GILLOT [Sun, 27 Jun 2021 18:06:26 +0000 (20:06 +0200)]
Drop ExpnData::krate.

3 years agoDrop orig_id.
Camille GILLOT [Sun, 27 Jun 2021 17:14:29 +0000 (19:14 +0200)]
Drop orig_id.

3 years agoEncode ExpnId using ExpnHash for incr. comp.
Camille GILLOT [Sun, 27 Jun 2021 13:51:25 +0000 (15:51 +0200)]
Encode ExpnId using ExpnHash for incr. comp.

3 years agoChoose encoding format in caller code.
Camille GILLOT [Sun, 27 Jun 2021 08:38:06 +0000 (10:38 +0200)]
Choose encoding format in caller code.

3 years agoUse LocalExpnId where possible.
Camille GILLOT [Fri, 25 Jun 2021 18:43:04 +0000 (20:43 +0200)]
Use LocalExpnId where possible.

3 years agoMake the CrateNum part of the ExpnId.
Camille GILLOT [Sat, 10 Jul 2021 21:34:41 +0000 (23:34 +0200)]
Make the CrateNum part of the ExpnId.

3 years agoAuto merge of #87123 - RalfJung:miri-provenance-overhaul, r=oli-obk
bors [Sat, 17 Jul 2021 15:26:27 +0000 (15:26 +0000)]
Auto merge of #87123 - RalfJung:miri-provenance-overhaul, r=oli-obk

CTFE/Miri engine Pointer type overhaul

This fixes the long-standing problem that we are using `Scalar` as a type to represent pointers that might be integer values (since they point to a ZST). The main problem is that with int-to-ptr casts, there are multiple ways to represent the same pointer as a `Scalar` and it is unclear if "normalization" (i.e., the cast) already happened or not. This leads to ugly methods like `force_mplace_ptr` and `force_op_ptr`.
Another problem this solves is that in Miri, it would make a lot more sense to have the `Pointer::offset` field represent the full absolute address (instead of being relative to the `AllocId`). This means we can do ptr-to-int casts without access to any machine state, and it means that the overflow checks on pointer arithmetic are (finally!) accurate.

To solve this, the `Pointer` type is made entirely parametric over the provenance, so that we can use `Pointer<AllocId>` inside `Scalar` but use `Pointer<Option<AllocId>>` when accessing memory (where `None` represents the case that we could not figure out an `AllocId`; in that case the `offset` is an absolute address). Moreover, the `Provenance` trait determines if a pointer with a given provenance can be cast to an integer by simply dropping the provenance.

I hope this can be read commit-by-commit, but the first commit does the bulk of the work. It introduces some FIXMEs that are resolved later.
Fixes https://github.com/rust-lang/miri/issues/841
Miri PR: https://github.com/rust-lang/miri/pull/1851
r? `@oli-obk`

3 years agoAuto merge of #86761 - Alexhuszagh:master, r=estebank
bors [Sat, 17 Jul 2021 12:56:22 +0000 (12:56 +0000)]
Auto merge of #86761 - Alexhuszagh:master, r=estebank

Update Rust Float-Parsing Algorithms to use the Eisel-Lemire algorithm.

# Summary

Rust, although it implements a correct float parser, has major performance issues in float parsing. Even for common floats, the performance can be 3-10x [slower](https://arxiv.org/pdf/2101.11408.pdf) than external libraries such as [lexical](https://github.com/Alexhuszagh/rust-lexical) and [fast-float-rust](https://github.com/aldanor/fast-float-rust).

Recently, major advances in float-parsing algorithms have been developed by Daniel Lemire, along with others, and implement a fast, performant, and correct float parser, with speeds up to 1200 MiB/s on Apple's M1 architecture for the [canada](https://github.com/lemire/simple_fastfloat_benchmark/blob/0e2b5d163d4074cc0bde2acdaae78546d6e5c5f1/data/canada.txt) dataset, 10x faster than Rust's 130 MiB/s.

In addition, [edge-cases](https://github.com/rust-lang/rust/issues/85234) in Rust's [dec2flt](https://github.com/rust-lang/rust/tree/868c702d0c9a471a28fb55f0148eb1e3e8b1dcc5/library/core/src/num/dec2flt) algorithm can lead to over a 1600x slowdown relative to efficient algorithms. This is due to the use of Clinger's correct, but slow [AlgorithmM and Bellepheron](http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.45.4152&rep=rep1&type=pdf), which have been improved by faster big-integer algorithms and the Eisel-Lemire algorithm, respectively.

Finally, this algorithm provides substantial improvements in the number of floats the Rust core library can parse. Denormal floats with a large number of digits cannot be parsed, due to use of the `Big32x40`, which simply does not have enough digits to round a float correctly. Using a custom decimal class, with much simpler logic, we can parse all valid decimal strings of any digit count.

```rust
// Issue in Rust's dec2fly.
"2.47032822920623272088284396434110686182e-324".parse::<f64>();   // Err(ParseFloatError { kind: Invalid })
```

# Solution

This pull request implements the Eisel-Lemire algorithm, modified from [fast-float-rust](https://github.com/aldanor/fast-float-rust) (which is licensed under Apache 2.0/MIT), along with numerous modifications to make it more amenable to inclusion in the Rust core library. The following describes both features in fast-float-rust and improvements in fast-float-rust for inclusion in core.

**Documentation**

Extensive documentation has been added to ensure the code base may be maintained by others, which explains the algorithms as well as various associated constants and routines. For example, two seemingly magical constants include documentation to describe how they were derived as follows:

```rust
    // Round-to-even only happens for negative values of q
    // when q ≥ −4 in the 64-bit case and when q ≥ −17 in
    // the 32-bitcase.
    //
    // When q ≥ 0,we have that 5^q ≤ 2m+1. In the 64-bit case,we
    // have 5^q ≤ 2m+1 ≤ 2^54 or q ≤ 23. In the 32-bit case,we have
    // 5^q ≤ 2m+1 ≤ 2^25 or q ≤ 10.
    //
    // When q < 0, we have w ≥ (2m+1)×5^−q. We must have that w < 2^64
    // so (2m+1)×5^−q < 2^64. We have that 2m+1 > 2^53 (64-bit case)
    // or 2m+1 > 2^24 (32-bit case). Hence,we must have 2^53×5^−q < 2^64
    // (64-bit) and 2^24×5^−q < 2^64 (32-bit). Hence we have 5^−q < 2^11
    // or q ≥ −4 (64-bit case) and 5^−q < 2^40 or q ≥ −17 (32-bitcase).
    //
    // Thus we have that we only need to round ties to even when
    // we have that q ∈ [−4,23](in the 64-bit case) or q∈[−17,10]
    // (in the 32-bit case). In both cases,the power of five(5^|q|)
    // fits in a 64-bit word.
    const MIN_EXPONENT_ROUND_TO_EVEN: i32;
    const MAX_EXPONENT_ROUND_TO_EVEN: i32;
```

This ensures maintainability of the code base.

**Improvements for Disguised Fast-Path Cases**

The fast path in float parsing algorithms attempts to use native, machine floats to represent both the significant digits and the exponent, which is only possible if both can be exactly represented without rounding. In practice, this means that the significant digits must be 53-bits or less and the then exponent must be in the range `[-22, 22]` (for an f64). This is similar to the existing dec2flt implementation.

However, disguised fast-path cases exist, where there are few significant digits and an exponent above the valid range, such as `1.23e25`. In this case, powers-of-10 may be shifted from the exponent to the significant digits, discussed at length in https://github.com/rust-lang/rust/issues/85198.

**Digit Parsing Improvements**

Typically, integers are parsed from string 1-at-a-time, requiring unnecessary multiplications which can slow down parsing. An approach to parse 8 digits at a time using only 3 multiplications is described in length [here](https://johnnylee-sde.github.io/Fast-numeric-string-to-int/). This leads to significant performance improvements, and is implemented for both big and little-endian systems.

**Unsafe Changes**

Relative to fast-float-rust, this library makes less use of unsafe functionality and clearly documents it. This includes the refactoring and documentation of numerous unsafe methods undesirably marked as safe. The original code would look something like this, which is deceptively marked as safe for unsafe functionality.

```rust
impl AsciiStr {
    #[inline]
    pub fn step_by(&mut self, n: usize) -> &mut Self {
        unsafe { self.ptr = self.ptr.add(n) };
        self
    }
}

...

#[inline]
fn parse_scientific(s: &mut AsciiStr<'_>) -> i64 {
    // the first character is 'e'/'E' and scientific mode is enabled
    let start = *s;
    s.step();
    ...
}
```

The new code clearly documents safety concerns, and does not mark unsafe functionality as safe, leading to better safety guarantees.

```rust
impl AsciiStr {
    /// Advance the view by n, advancing it in-place to (n..).
    pub unsafe fn step_by(&mut self, n: usize) -> &mut Self {
        // SAFETY: same as step_by, safe as long n is less than the buffer length
        self.ptr = unsafe { self.ptr.add(n) };
        self
    }
}

...

/// Parse the scientific notation component of a float.
fn parse_scientific(s: &mut AsciiStr<'_>) -> i64 {
    let start = *s;
    // SAFETY: the first character is 'e'/'E' and scientific mode is enabled
    unsafe {
        s.step();
    }
    ...
}
```

This allows us to trivially demonstrate the new implementation of dec2flt is safe.

**Inline Annotations Have Been Removed**

In the previous implementation of dec2flt, inline annotations exist practically nowhere in the entire module. Therefore, these annotations have been removed, which mostly does not impact [performance](https://github.com/aldanor/fast-float-rust/issues/15#issuecomment-864485157).

**Fixed Correctness Tests**

Numerous compile errors in `src/etc/test-float-parse` were present, due to deprecation of `time.clock()`, as well as the crate dependencies with `rand`. The tests have therefore been reworked as a [crate](https://github.com/Alexhuszagh/rust/tree/master/src/etc/test-float-parse), and any errors in `runtests.py` have been patched.

**Undefined Behavior**

An implementation of `check_len` which relied on undefined behavior (in fast-float-rust) has been refactored, to ensure that the behavior is well-defined. The original code is as follows:

```rust
    #[inline]
    pub fn check_len(&self, n: usize) -> bool {
        unsafe { self.ptr.add(n) <= self.end }
    }
```

And the new implementation is as follows:

```rust
    /// Check if the slice at least `n` length.
    fn check_len(&self, n: usize) -> bool {
        n <= self.as_ref().len()
    }
```

Note that this has since been fixed in [fast-float-rust](https://github.com/aldanor/fast-float-rust/pull/29).

**Inferring Binary Exponents**

Rather than explicitly store binary exponents, this new implementation infers them from the decimal exponent, reducing the amount of static storage required. This removes the requirement to store [611 i16s](https://github.com/rust-lang/rust/blob/868c702d0c9a471a28fb55f0148eb1e3e8b1dcc5/library/core/src/num/dec2flt/table.rs#L8).

# Code Size

The code size, for all optimizations, does not considerably change relative to before for stripped builds, however it is **significantly** smaller prior to stripping the resulting binaries. These binary sizes were calculated on x86_64-unknown-linux-gnu.

**new**

Using rustc version 1.55.0-dev.

opt-level|size|size(stripped)
|:-:|:-:|:-:|
0|400k|300K
1|396k|292K
2|392k|292K
3|392k|296K
s|396k|292K
z|396k|292K

**old**

Using rustc version 1.53.0-nightly.

opt-level|size|size(stripped)
|:-:|:-:|:-:|
0|3.2M|304K
1|3.2M|292K
2|3.1M|284K
3|3.1M|284K
s|3.1M|284K
z|3.1M|284K

# Correctness

The dec2flt implementation passes all of Rust's unittests and comprehensive float parsing tests, along with numerous other tests such as Nigel Toa's comprehensive float [tests](https://github.com/nigeltao/parse-number-fxx-test-data) and Hrvoje Abraham  [strtod_tests](https://github.com/ahrvoje/numerics/blob/master/strtod/strtod_tests.toml). Therefore, it is unlikely that this algorithm will incorrectly round parsed floats.

# Issues Addressed

This will fix and close the following issues:

- resolves #85198
- resolves #85214
- resolves #85234
- fixes #31407
- fixes #31109
- fixes #53015
- resolves #68396
- closes https://github.com/aldanor/fast-float-rust/issues/15

3 years agoCorrected symbol order after adding diagnostic items
xFrednet [Sat, 17 Jul 2021 10:20:43 +0000 (12:20 +0200)]
Corrected symbol order after adding diagnostic items

3 years agoAuto merge of #87124 - Andy-Python-Programmer:code_model_uefi_patch, r=petrochenkov
bors [Sat, 17 Jul 2021 10:15:33 +0000 (10:15 +0000)]
Auto merge of #87124 - Andy-Python-Programmer:code_model_uefi_patch, r=petrochenkov

Use small code model for UEFI targets

* Since the code model only applies to the code and not the data and the code model
only applies to functions you call through using `call`, `jmp` and data with `lea`, etc…

  If you are calling functions using the function pointers from the UEFI structures the code
  model does not apply in that case. It’s just related to the address space size of your own binary.
  Since UEFI (uefi is all relocatable) uses relocatable PEs (relocatable code does not care about the
  code model) so, we use the small code model here.

* Since applications don't usually take gigabytes of memory, setting the
target to use the small code model should result in better codegen (comparable
with majority of other targets).

  Large code models are also known for generating horrible code, for
  example 16 bytes of code to load a single 8-byte value.

Signed-off-by: Andy-Python-Programmer <andypythonappdeveloper@gmail.com>
3 years agoAuto merge of #86062 - nagisa:nagisa/what-a-lie, r=estebank
bors [Sat, 17 Jul 2021 07:54:03 +0000 (07:54 +0000)]
Auto merge of #86062 - nagisa:nagisa/what-a-lie, r=estebank

Do not allow JSON targets to set is-builtin: true

Note that this will affect (and make builds fail for) all of the projects out there that have target files invalid in this way. Crater, however, does not really cover these kinds of the codebases, so it is quite difficult to measure the impact. That said, the target files invalid in this way can start causing build failures each time LLVM is upgraded, anyway, so it is probably a good opportunity to disallow this property, entirely.

Another approach considered was to simply not parse this field anymore, which would avoid making the builds explicitly fail, but it wasn't clear to me if `is-builtin` was always set unintentionally… In case this was the case, I'd expect people to file a feature request stating specifically for what purpose they were using `is-builtin`.

Fixes #86017