Commit Graph

96259 Commits

Author SHA1 Message Date
Mazdak Farrokhzad
03c26f9b74
Rollup merge of #62519 - pnkfelix:add-test-for-30786, r=pnkfelix
Regression test for HRTB bug (issue 30786).

Close #30786.
2019-07-11 04:33:19 +02:00
Mazdak Farrokhzad
7697b2927f
Rollup merge of #62476 - petrochenkov:expref, r=matthewjasper
Continue refactoring macro expansion and resolution

This PR continues the work started in https://github.com/rust-lang/rust/pull/62042.
It contains a set of more or less related refactorings with the general goal of making things simpler and more orthogonal.
Along the way most of the issues uncovered in https://github.com/rust-lang/rust/pull/62086 are fixed.

The PR is better read in per-commit fashion with whitespace changes ignored.
I tried to leave some more detailed commit messages describing the motivation behind the individual changes.

Fixes https://github.com/rust-lang/rust/issues/44692
Fixes https://github.com/rust-lang/rust/issues/52363
Unblocks https://github.com/rust-lang/rust/pull/62086
r? @matthewjasper
2019-07-11 04:33:17 +02:00
Mazdak Farrokhzad
e07df9c9df
Rollup merge of #62425 - cyphar:linux-cloexec-use-fcntl, r=alexcrichton
filedesc: don't use ioctl(FIOCLEX) on Linux

All `ioctl(2)`s will fail on `O_PATH` file descriptors on Linux (because
they use `&empty_fops` as a security measure against `O_PATH` descriptors
affecting the backing file).

As a result, `File::try_clone()` and various other methods would always
fail with `-EBADF` on `O_PATH` file descriptors. The solution is to simply
use `F_SETFD` (as is used on other unices) which works on `O_PATH`
descriptors because it operates through the `fnctl(2)` layer and not
through `ioctl(2)`s.

Since this code is usually only used in strange error paths (a broken or
ancient kernel), the extra overhead of one syscall shouldn't cause any
dramas. Most other systems programming languages also use the fnctl(2)
so this brings us in line with them.

Fixes: rust-lang/rust#62314
Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
2019-07-11 04:33:16 +02:00
Mazdak Farrokhzad
8fe7ed02d5
Rollup merge of #62270 - agnxy:move-async-test, r=Centril,tmandry
Move async-await tests from run-pass to ui

fix #62236

r? @Centril
2019-07-11 04:33:14 +02:00
Mazdak Farrokhzad
618fc02fac
Rollup merge of #61923 - Zoxc:dep-stream-prefix-2, r=pnkfelix
Prerequisites from dep graph refactoring #2

Split out from https://github.com/rust-lang/rust/pull/60035 and overlaps with https://github.com/rust-lang/rust/pull/60559.
2019-07-11 04:33:12 +02:00
Mazdak Farrokhzad
ea62f9b3ec
Rollup merge of #61665 - aschampion:slice-eq-ptr, r=sfackler
core: check for pointer equality when comparing Eq slices

Because `Eq` types must be reflexively equal, an equal-length slice to the same memory location must be equal.

This is related to #33892 (and #32699) answering this comment from that PR:

> Great! One more easy question: why does this optimization not apply in the non-BytewiseEquality implementation directly above?

Because slices of non-reflexively equal types (like `f64`) are not equal even if it's the same slice. But if the types are `Eq`, we can use this same-address optimization, which this PR implements. Obviously this changes behavior if types violate the reflexivity condition of `Eq`, because their impls of `PartialEq` will no longer be called per-item, but 🤷‍♂ .

It's not clear how often this optimization comes up in the real world outside of the same-`&str` case covered by #33892, so **I'm requesting a perf run** (on MacOS today, so can't run `rustc_perf` myself). I'm going ahead and making the PR on the basis of being surprised things didn't already work this way.

This is my first time hacking rust itself, so as a perf sanity check I ran `./x.py bench --stage 0 src/lib{std,alloc}`, but the differences were noisy.

To make the existing specialization for `BytewiseEquality` explicit, it's now a supertrait of `Eq + Copy`. `Eq` should be sufficient, but `Copy` was included for clarity.
2019-07-11 04:33:11 +02:00
Yuki Okushi
37942c4753 Add test for #49919 2019-07-11 09:58:09 +09:00
John Kåre Alsaker
29e7bfd0c7 Refactor diagnostic emission for green nodes 2019-07-11 02:09:37 +02:00
bors
35cacbce16 Auto merge of #62561 - Centril:rollup-5pxj3bo, r=Centril
Rollup of 5 pull requests

Successful merges:

 - #62275 (rustc_mir: treat DropAndReplace as Drop + Assign in qualify_consts.)
 - #62465 (Sometimes generate storage statements for temporaries with type `!`)
 - #62481 (Use `fold` in `Iterator::last` default implementation)
 - #62493 (#62357: doc(ptr): add example for {read,write}_unaligned)
 - #62532 (Some more cleanups to syntax::print)

Failed merges:

r? @ghost
2019-07-10 23:02:44 +00:00
Vadim Petrochenkov
e86e5cb38f Add a regression test for #44692
Add a test for the issue resolved by removing `resolve_macro_path`

Add a test making sure that extern prelude entries introduced from an opaque macro are not visible anywhere, even it that macro

Fix test output after rebase
2019-07-11 00:35:01 +03:00
Vadim Petrochenkov
7b74d72d9a Fix failing tests 2019-07-11 00:12:57 +03:00
Vadim Petrochenkov
baddce5155 expand: Move "derive containers" into a separate InvocationKind variant
`InvocationKind::Attr { attr: None, .. }` meaning something entirely different from a regular attribute was confusing as hell.
2019-07-11 00:12:57 +03:00
Vadim Petrochenkov
b003dd6d9b expand: Merge expand_{bang,attr,derive}_invoc into a single function
It's more convenient to have all this highly related stuff together on one screen (for future refactorings).
The `expand_invoc` function is compact enough now, after all the previous refactorings.
2019-07-11 00:12:57 +03:00
Vadim Petrochenkov
374a80a86d expand: It's always possible to create a dummy AST fragment
Remove a bunch of `Option`s that assumed that dummy fragment creation could fail.

The test output changed due to not performing the expansion in `fn expand_invoc` in case of the recursion limit hit.
2019-07-11 00:12:57 +03:00
Vadim Petrochenkov
eac900ac87 hygiene: Make sure each Mark has an associated expansion info
The root expansion was missing one.
Expansions created for "derive containers" (see one of the next commits for the description) also didn't get expansion info.
2019-07-11 00:12:57 +03:00
Vadim Petrochenkov
dcd30a4b17 hygiene: Fix wording of desugaring descriptions
Use variant names rather than descriptions for identifying desugarings in `#[rustc_on_unimplemented]`.
Both are highly unstable, but variant name is at least a single identifier.
2019-07-11 00:12:57 +03:00
Vadim Petrochenkov
99c7432896 hygiene: Introduce a helper method for creating new expansions
Creating a fresh expansion and immediately generating a span from it is the most common scenario.

Also avoid allocating `allow_internal_unstable` lists for derive markers repeatedly.
And rename `ExpnInfo::with_unstable` to `ExpnInfo::allow_unstable`, seems to be a better fitting name.
2019-07-11 00:12:57 +03:00
Vadim Petrochenkov
d1949b1ab0 expand: Do not overwrite existing ExpnInfo when injecting derive markers
Create a fresh expansion for them instead - this is the usual way to allow unstable features for generated/desugared code.
Fixes https://github.com/rust-lang/rust/issues/52363
2019-07-11 00:12:08 +03:00
Vadim Petrochenkov
0ec6ea7333 resolve: Fix access to extern and stdlib prelude from opaque macros
Ok, it's hard to explain what happens, but identifier's hygienic contexts need to be "adjusted" to modules/scopes before they are resolved in them.
To be resolved in all kinds on preludes the identifier needs to be adjusted to the root expansion (aka "no expansion").

Previously this was done for the `macro m() { ::my_crate::foo }` case, but forgotten for all other cases.
2019-07-11 00:12:08 +03:00
Vadim Petrochenkov
f923942094 resolve: Divide macro path resolution into speculative and error reporting parts
Also move macro stability checking closer to other checks performed on obtained resolutions.
Tighten the stability spans as well, it is an error to *refer* to and unstable entity in any way, not only "call" it.
2019-07-11 00:12:08 +03:00
Vadim Petrochenkov
8bc187d104 resolve: Include stdlib prelude into name lookup in macro namespace
This is going to be used when built-in macros are defined through libcore and made available to other crates through standard library prelude
2019-07-11 00:12:08 +03:00
Vadim Petrochenkov
3041ec6118 resolve/expand: Catch macro kind mismatches early in resolve
This way we are processing all of them in a single point, rather than separately for each syntax extension kind.
Also, the standard expected/found wording is used.
2019-07-11 00:12:08 +03:00
Vadim Petrochenkov
f16993d4ac resolve/expand: resolve_macro_invocation no longer returns determinate errors
It either returns the indeterminacy error, or valid (but perhaps dummy) `SyntaxExtension`.

With this change enum `Determinacy` is no longer used in libsyntax and can be moved to resolve.

The regressions in diagnosics are fixed in the next commits.
2019-07-11 00:12:08 +03:00
Vadim Petrochenkov
cd0fd630e8 resolve: Make proc macro stubs less stubby
Create real working and registered (even if dummy) `SyntaxExtension`s for them.
This improves error recovery and allows to avoid all special cases for proc macro stubs (except for the error on use, of course).

The introduced dummy `SyntaxExtension`s can be used for any other inappropriately resolved macros as well.
2019-07-11 00:12:08 +03:00
Vadim Petrochenkov
b392781edc def_collector: parent_def is no longer optional 2019-07-11 00:12:08 +03:00
Vadim Petrochenkov
e272946066 def_collector: Simplify tracking of macro invocation parents
Avoid the tricky scheme with callbacks and keep the invocation parent data where it logically belongs - in `Definitions`.

This also allows to create `InvocationData` entries in resolve when the data is actually ready, and remove cells and "uninitialized" variants from it.
2019-07-11 00:12:08 +03:00
Vadim Petrochenkov
aff9738462 hygiene: Reuse MacroKind in ExpnKind
Orthogonality and reuse are good.
2019-07-11 00:12:08 +03:00
Vadim Petrochenkov
4dcf9b15c4 hygiene: Remove some unused impls 2019-07-11 00:12:08 +03:00
Vadim Petrochenkov
3eafaae510 syntax: Make def-site span mandatory in ExpnInfo/MacroBacktrace/DiagnosticSpanMacroExpansion
We have to deal with dummy spans anyway

Remove def-site span from expander interfaces.
It's not used by the expansion infra, only by specific expanders, which can keep it themselves if they want it.
2019-07-11 00:12:07 +03:00
Vadim Petrochenkov
a138e9d625 expand: Get rid of resolve_macro_path
It was used to choose whether to apply derive markers like `#[rustc_copy_clone_marker]` or not,
but it was called before all the data required for resolution is available, so it could work incorrectly in some corner cases (like user-defined derives name `Copy` or `Eq`).
Delay the decision about markers until the proper resolution results are available instead.
2019-07-11 00:12:07 +03:00
Vadim Petrochenkov
62a1f5dbc0 hygiene: Remove some dead code 2019-07-11 00:12:07 +03:00
Vadim Petrochenkov
f1d4ebf015 Remove unnecessary expansions created by #[test_case/test/bench]
The expansions were created to allow unstable things inside `#[test_case/test/bench]`, but that's not a proper way to do that.
Put the required `allow_internal_unstable`s into the macros' properties instead.
2019-07-11 00:12:07 +03:00
Vadim Petrochenkov
16918a8e28 Rename some things in syntax_pos/hygiene
More consistent with other naming:
ExpnFormat -> ExpnKind
ExpnKind::name -> ExpnKind::descr
DesugaringKind::name -> DesugaringKind::descr

Shorter, no tautology:
CompilerDesugaring -> Desugaring
CompilerDesugaringKind -> DesugaringKind
2019-07-11 00:12:07 +03:00
Vadim Petrochenkov
ec376c783e Move MacroKind into libsyntax_pos
So it can be eventually used in `ExpnInfo`
2019-07-11 00:12:07 +03:00
Vadim Petrochenkov
48635226d8 Remove MacroKind::ProcMacroStub
It's internal to resolve and always results in `Res::Err` outside of resolve.
Instead put `DefKind::Fn`s themselves into the macro namespace, it's ok.

Proc macro stubs are items placed into macro namespase for functions that define proc macros.
https://github.com/rust-lang/rust/pull/52383

The rustdoc test is changed because the old test didn't actually reproduce the ICE it was supposed to reproduce.
2019-07-11 00:12:07 +03:00
bors
cd2cd4c962 Auto merge of #62564 - Mark-Simulacrum:azure-line-endings, r=pietroalbini
Ensure that checkout is with \n line endings

During installation of mingw, at least, the git directories change, so
we need to reset the core.autocrlf config to false.

Once we finish checking out submodules, check that the line endings are
\n and not \r\n.

Artifacts were built via the last try on #62545; I've manually confirmed that `install.sh` appears to no longer have `\r\n` line endings.

Fixes #62276.
2019-07-10 19:36:42 +00:00
John Kåre Alsaker
498bdc9b42 Add an AtomicCell abstraction 2019-07-10 17:04:42 +02:00
Felix S. Klock II
fa0809d3cd Regression test for issue 30786. 2019-07-10 16:43:19 +02:00
Pietro Albini
2d2dcb0dc7
ci: add a pr builder to test tools when submodules are updated
The builder will skip time consuming tasks (like the actual tests) when
it detects no updated submodules.
2019-07-10 16:14:25 +02:00
Mazdak Farrokhzad
3c299a987c
Rollup merge of #62532 - Mark-Simulacrum:syntax-print-cleanup, r=petrochenkov
Some more cleanups to syntax::print

All of these changes should be functionally equivalent to previous code.

Each commit mostly stands alone and this PR is easiest to review by-commit.
2019-07-10 16:08:26 +02:00
Mazdak Farrokhzad
d0cec040de
Rollup merge of #62493 - Freyskeyd:valid_example_read-write_unaligned, r=rkruppe
#62357: doc(ptr): add example for {read,write}_unaligned

related to #62357

> With #62323 the only example (that had UB and was thus invalid) in std::ptr::read_unaligned and std::ptr::write_unaligned is removed.

> We should add a valid example of using the aforementioned functions.

Signed-off-by: Freyskeyd <simon.paitrault@gmail.com>
2019-07-10 16:08:24 +02:00
Mazdak Farrokhzad
ad21558b85
Rollup merge of #62481 - czipperz:iterator-last-nth-use-for_each, r=scottmcm
Use `fold` in `Iterator::last` default implementation

We already use it in all the other methods.  Consistency + potential perf is a pretty nice win!
2019-07-10 16:08:23 +02:00
Mazdak Farrokhzad
5760bc6e98
Rollup merge of #62465 - matthewjasper:never-type-storage, r=pnkfelix
Sometimes generate storage statements for temporaries with type `!`

Closes #62165
cc #42371
2019-07-10 16:08:21 +02:00
Mazdak Farrokhzad
a2cbae8ad3
Rollup merge of #62275 - eddyb:const-drop-replace, r=pnkfelix
rustc_mir: treat DropAndReplace as Drop + Assign in qualify_consts.

This slipped through the cracks and never got implemented (thankfully that just meant it was overly conservative and didn't allow assignments that don't *actually* drop the previous value).
Fixes #62273.

r? @oli-obk
2019-07-10 16:08:19 +02:00
Aleksa Sarai
6031a07a46
filedesc: don't use ioctl(FIOCLEX) on Linux
All ioctl(2)s will fail on O_PATH file descriptors on Linux (because
they use &empty_fops as a security measure against O_PATH descriptors
affecting the backing file).

As a result, File::try_clone() and various other methods would always
fail with -EBADF on O_PATH file descriptors. The solution is to simply
use F_SETFD (as is used on other unices) which works on O_PATH
descriptors because it operates through the fnctl(2) layer and not
through ioctl(2)s.

Since this code is usually only used in strange error paths (a broken or
ancient kernel), the extra overhead of one syscall shouldn't cause any
dramas. Most other systems programming languages also use the fnctl(2)
so this brings us in line with them.

Fixes: rust-lang/rust#62314
Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
2019-07-10 23:59:46 +10:00
Mark Rousskov
df725c28d6 Ensure that checkout is with \n line endings
During installation of mingw, at least, the git directories change, so
we need to reset the core.autocrlf config to false.

Once we finish checking out submodules, check that the line endings are
\n and not \r\n.
2019-07-10 09:56:47 -04:00
Andrew Xu
128143c4e5
Ignore async-fn-size-moved-locals test on wasm
The sizes for wasm are different.

Co-Authored-By: Tyler Mandry <tmandry@gmail.com>
2019-07-10 21:18:51 +08:00
bors
c6a9e766f9 Auto merge of #62339 - pnkfelix:issue-61188-use-visitor-for-structural-match-check, r=nikomatsakis
use visitor for #[structural_match] check

This changes the code so that we recur down the structure of a type of a const (rather than just inspecting at a shallow one or two levels) when we are looking to see if it has an ADT that did not derive `PartialEq` and `Eq`.

Fix #61188

Fix #62307

Cc #62336
2019-07-10 12:26:44 +00:00
Mark Rousskov
56a9237b59 File is now short enough for tidy 2019-07-10 07:13:59 -04:00
Mark Rousskov
096cb4137d Remove writer function from PrintState 2019-07-10 07:13:57 -04:00