about summary refs log tree commit diff
path: root/src/test/run-pass
AgeCommit message (Collapse)AuthorLines
2017-11-05Auto merge of #45072 - nikomatsakis:issue-38714, r=arielb1bors-0/+115
new rules for merging expected and supplied types in closure signatures As uncovered in #38714, we currently have some pretty bogus code for combining the "expected signature" of a closure with the "supplied signature". To set the scene, consider a case like this: ```rust fn foo<F>(f: F) where F: for<'a> FnOnce(&'a u32) -> &'a u32 // ^ *expected* signature comes from this where-clause { ... } fn main() { foo(|x: &u32| -> &u32 { .. } // ^^^^^^^^^^^^^^^^^ supplied signature // comes from here } ``` In this case, the supplied signature (a) includes all the parts and (b) is the same as the expected signature, modulo the names used for the regions. But often people supply only *some* parts of the signature. For example, one might write `foo(|x| ..)`, leaving *everything* to be inferred, or perhaps `foo(|x: &u32| ...)`, which leaves the return type to be inferred. In the current code, we use the expected type to supply the types that are not given, but otherwise use the type the user gave, except for one case: if the user writes `fn foo(|x: _| ..)` (i.e., an underscore at the outermost level), then we will take the expected type (rather than instantiating a fresh type variable). This can result in nonsensical situations, particularly with bound regions that link the types of parameters to one another or to the return type. Consider `foo(|x: &u32| ...)` -- if we *literally* splice the expected return type of `&'a u32` together with what the user gave, we wind up with a signature like `for<'a> fn(&u32) -> &'a u32`. This is not even permitted as a type, because bound regions like `'a` must appear also in the arguments somewhere, which is why #38714 leads to an ICE. This PR institutes some new rules. These are not meant to be the *final* set of rules, but they are a kind of "lower bar" for what kind of code we accept (i.e., we can extend these rules in the future to be smarter in some cases, but -- as we will see -- these rules do accept some things that we then would not be able to back off from). These rules are derived from a few premises: - First and foremost, anonymous regions in closure annotation are mostly requests for the code to "figure out the right lifetime" and shouldn't be read too closely. So for example when people write a closure signature like `|x: &u32|`, they are really intended for us to "figure out" the right region for `x`. - In contrast, the current code treats this supplied type as being more definitive. In particular, writing `|x: &u32|` would always result in the region of `x` being bound in the closure type. In other words, the signature would be something like `for<'a> fn(&'a u32)` -- this is derived from the fact that `fn(&u32)` expands to a type where the region is bound in the fn type. - This PR takes a different approach. The "binding level" for reference types appearing in closure signatures can be informed in some cases by the expected signature. So, for example, if the expected signature is something like `(&'f u32)`, where the region of the first argument appears free, then for `|x: &u32|`, the new code would infer `x` to also have the free region `'f`. - This inference has some limits. We don't do this for bindings that appear within the selected types themselves. So e.g. `|x: fn(&u32)|`, when combined with an expected type of `fn(fn(&'f u32))`, would still result in a closure that expects `for<'a> fn(&'a u32)`. Such an annotation will ultimately result in an error, as it happens, since `foo` is supplying a `fn(&'f u32)` to the closure, but the closure signature demands a `for<'a> fn(&'a u32)`. But still we choose to trust it and have the user change it. - I wanted to preserve the rough intuition that one can copy-and-paste a type out of the fn signature and into the fn body without dramatically changing its meaning. Interestingly, if one has `|x: &u32|`, then regardless of whether the region of `x` is bound or free in the closure signature, it is also free in the region body, and that is also true when one writes `let x: &u32`, so that intuition holds here. But the same would not be true for `fn(&u32)`, hence the different behavior. - Second, we must take either **all** the references to bound regions from the expected type or **none**. The current code, as we saw, will happily take a bound region in the return type but drop the other place where it is used, in the parameters. Since bound regions are all about linking multiple things together, I think it's important not to do that. (That said, we could conceivably be a bit less strict here, since the subtyping rules will get our back, but we definitely don't want any bound regions that appear only in the return type.) - Finally, we cannot take the bound region names from the supplied types and "intermix" them with the names from the expected types. - We *could* potentially do some alpha renaming, but I didn't do that. - Ultimately, if the types the user supplied do not match expectations in some way that we cannot recover from, we fallback to deriving the closure signature solely from those expected types. - For example, if the expected type is `u32` but the user wrote `i32`. - Or, more subtle, if the user wrote e.g. `&'x u32` for some named lifetime `'x`, but the expected type includes a bound lifetime (`for<'a> (&'a u32)`). In that case, preferring the type that the user explicitly wrote would hide an appearance of a bound name from the expected type, and we try to never do that. The detailed rules that I came up with are found in the code, but for ease of reading I've also [excerpted them into a gist](https://gist.github.com/nikomatsakis/e69252a2b57e6d97d044c2f254c177f1). I am not convinced they are correct and would welcome feedback for alternative approaches. (As an aside, the way I think I would ultimately *prefer* to think about this is that the conversion from HIR types to internal types could be parameterized by an "expected type" that it uses to guide itself. However, since that would be a pain, I opted *in the code* to first instantiate the supplied types as `Ty<'tcx>` and then "merge" those types with the `Ty<'tcx>` from the expected signature.) I think we should probably FCP this before landing. cc @rust-lang/lang r? @arielb1
2017-11-05Fix MIR inlining panic in generic functionsinkuu-0/+26
2017-11-05Auto merge of #45754 - scottmcm:checked-npot, r=dtolnaybors-0/+60
Fix #18604: next_power_of_two should panic on overflow Fixes https://github.com/rust-lang/rust/issues/18604 Is it possible to write a test for this? My experiments showed `x.py test` running in release mode, so my attempt at a `#[should_panic]` didn't work.
2017-11-04Fix checking of auto trait bounds in trait objects.leonardo.yvens-0/+3
Any auto trait is allowed in trait object bounds. Fix duplicate check of type and lifetime parameter count.
2017-11-04Auto merge of #45394 - davidtwco:rfc-2008, r=petrochenkovbors-0/+253
RFC 2008: Future-proofing enums/structs with #[non_exhaustive] attribute This work-in-progress pull request contains my changes to implement [RFC 2008](https://github.com/rust-lang/rfcs/pull/2008). The related tracking issue is #44109. As of writing, enum-related functionality is not included and there are some issues related to tuple/unit structs. Enum related tests are currently ignored. WIP PR requested by @nikomatsakis [in Gitter](https://gitter.im/rust-impl-period/WG-compiler-middle?at=59e90e6297cedeb0482ade3e).
2017-11-04Ignoring pretty print for test due to #37199David Wood-0/+2
2017-11-03Add overflow tests for next_power_of_twoScott McMurray-0/+60
2017-11-03Added tests for RFC 2008.David Wood-0/+251
2017-11-03Parse auto traits the same as traits.leonardo.yvens-0/+24
This moves the well formedness checks to the AST validation pass. Tests were adjusted. The auto keyword should be back-compat now.
2017-11-03auto trait future compatibility lintleonardo.yvens-0/+2
2017-11-03Add tests for `auto trait`, fix parsing bugleonardo.yvens-0/+35
Now we can do the well formedness checks in the parser, yay!
2017-11-02new rules for merging expected/supplied types in closure signaturesNiko Matsakis-0/+115
Also, fix numbering in mir-opt tests. We are now anonymizing more consistently, I think, and hence some of the `TyAnon` indices shifted.
2017-11-01Auto merge of #45435 - eddyb:binop-subtype-lhs, r=nikomatsakisbors-0/+55
rustc_typeck: use subtyping on the LHS of binops. Fixes #45425. r? @nikomatsakis
2017-10-31rustc_typeck: use subtyping on the LHS of binops.Eduard-Mihai Burtescu-0/+55
2017-10-31Count type aliases in patternssinkuu-0/+18
2017-10-27Implement RFC 1861: Extern typesPaul Lietar-0/+207
2017-10-26Auto merge of #45519 - michaelwoerister:dedup-errors, r=arielb1bors-0/+0
Don't emit the same compiler diagnostic twice. This PR makes the compiler filter out diagnostic messages that have already been emitted during the same compilation session.
2017-10-26Auto merge of #45488 - oli-obk:ctfe_resolve, r=eddybbors-0/+28
Resolve types properly in const eval r? @eddyb cc @arielb1
2017-10-26Auto merge of #45464 - sinkuu:ice_44851, r=jseyfriedbors-0/+24
Visit attribute tokens in `DefCollector` and `BuildReducedGraphVisitor` Fixes #44851.
2017-10-25Rename some run-pass tests so they don't crash when executed from eCryptfs.Michael Woerister-0/+0
2017-10-25Add a regression test for the const eval type resolutionOliver Schneider-0/+28
2017-10-23Fix #44851 by visiting tokens in `DefCollector` and `BuildReducedGraphVisitor`sinkuu-0/+24
2017-10-22`crate` shorthand visibility modifierZack M. Davis-1/+13
With regrets, this breaks rustfmt and rls. This is in the matter of #45388.
2017-10-20Auto merge of #45348 - alexcrichton:thinlto-timp, r=michaelwoeristerbors-0/+52
rustc: Add `_imp_` symbols later in compilation On MSVC targets rustc will add symbols prefixed with `_imp_` to LLVM modules to "emulate" dllexported statics as that workaround is still in place after #27438 hasn't been solved otherwise. These statics, however, were getting gc'd by ThinLTO accidentally which later would cause linking failures. This commit updates the location we add such symbols to happen just before codegen to ensure that (a) they're not eliminated by the optimizer and (b) the optimizer doesn't even worry about them. Closes #45347
2017-10-20Auto merge of #45359 - arielb1:escaping-borrow, r=eddybbors-1/+35
Fix a few bugs in drop generation This fixes a few bugs in drop generation, one of which causes spurious MIR borrowck errors. Fixes #44832. r? @eddyb
2017-10-20Auto merge of #45316 - goffrie:exitable-breakable-block, r=nikomatsakisbors-0/+24
Mark block exits as reachable if the block can break. This only happens when desugaring `catch` expressions for now, but regular blocks (in HIR) can be broken from - respect that when doing reachability analysis. Fixes #45124.
2017-10-20Rollup merge of #45352 - alexcrichton:emscripten-tests, r=nikomatsakiskennytm-56/+55
test: Update Emscripten failures/passing All tests should now have annotation for *why* they're ignored on emscripten. A few tests no longer need such an annotation as well! Closes #41299
2017-10-19Rollup merge of #45326 - cuviper:min-llvm-3.9, r=alexcrichtonkennytm-2/+0
Bump the minimum LLVM to 3.9 Old LLVM bugs are reportedly cropping up harder, but 3.9 seems to be OK. Fixes #45277.
2017-10-18Remove two obsolete min-llvm-version testsJosh Stone-2/+0
2017-10-18rustc: Add `_imp_` symbols later in compilationAlex Crichton-0/+52
On MSVC targets rustc will add symbols prefixed with `_imp_` to LLVM modules to "emulate" dllexported statics as that workaround is still in place after #27438 hasn't been solved otherwise. These statics, however, were getting gc'd by ThinLTO accidentally which later would cause linking failures. This commit updates the location we add such symbols to happen just before codegen to ensure that (a) they're not eliminated by the optimizer and (b) the optimizer doesn't even worry about them. Closes #45347
2017-10-18Auto merge of #44501 - nikomatsakis:issue-44137-non-query-data-in-tcx, r=eddybbors-0/+36
remove or encapsulate the remaining non-query data in tcx I wound up removing the existing cache around inhabitedness since it didn't seem to be adding much value. I reworked const rvalue promotion, but not that much (i.e., I did not split the computation into bits, as @eddyb had tossed out as a suggestion). But it's now demand driven, at least. cc @michaelwoerister -- see the `forbid_reads` change in last commit r? @eddyb -- since the trickiest of this PR is the work on const rvalue promotion cc #44137
2017-10-17test: Update Emscripten failures/passingAlex Crichton-56/+55
All tests should now have annotation for *why* they're ignored on emscripten. A few tests no longer need such an annotation as well! Closes #41299
2017-10-17look past the next drop for the drop panic targetAriel Ben-Yehuda-5/+17
The previous code would leak data on a drop panic if the immediate next drop was a StorageDead that was followed by another drop.
2017-10-17fix generator drop cachingAriel Ben-Yehuda-1/+23
Fixes #45328.
2017-10-17Auto merge of #45311 - goffrie:issue-40003, r=alexcrichtonbors-0/+186
Add the test for #40003. I checked that the test failed to compile on an older nightly (I tried 2017-09-29) and that it compiles against master. Closes #40003.
2017-10-16restructure the public inhabitedness APIs and remove the cacheNiko Matsakis-0/+36
The cache was broken anyhow and this computation doesn't look that expensive. These public accessors could potentially become queries, but we'd have to add some more complex logic around lift. I'd prefer to have some test cases to profile with before doing that. Fixes #44402.
2017-10-16Auto merge of #45297 - matthewjasper:associated-item-namespaces, r=petrochenkovbors-0/+51
Check namespaces when resolving associated items in typeck Closes #35600 Closes #44247 Fixes a "cannot move a value of type..." error in the same case as #44247 but with the associated items swapped.
2017-10-15Mark block exits as reachable if the block can break.Geoffry Song-0/+24
2017-10-15Add test for #40003.Geoffry Song-0/+186
2017-10-15rustc: Fix some ThinLTO internalizationAlex Crichton-0/+34
First the `addPreservedGUID` function forgot to take care of "alias" summaries. I'm not 100% sure what this is but the current code now matches upstream. Next the `computeDeadSymbols` return value wasn't actually being used, but it needed to be used! Together these should... Closes #45195
2017-10-15Check namespaces when resolving associated items in typeckmatthewjasper-0/+51
2017-10-14Implement `dyn Trait` syntaxVadim Petrochenkov-0/+24
2017-10-13Rollup merge of #45189 - alexcrichton:thinlto-allocators, r=michaelwoeristerkennytm-41/+19
rustc: Handle `#[no_mangle]` anywhere in a crate This commit updates the reachability pass of the compiler to seed the local worklist with `#[no_mangle]`-like items anywhere in a crate, not just those reachable from public items. Closes #45165
2017-10-12rustc: Handle `#[linkage]` anywhere in a crateAlex Crichton-41/+19
This commit updates the reachability pass of the compiler to seed the local worklist with `#[linkage]`-like items anywhere in a crate, not just those reachable from public items. Closes #45165
2017-10-11Shorten some test namesVadim Petrochenkov-9/+9
Paths to object files generated from them were too long and caused errors
2017-10-10Auto merge of #44822 - frewsxcv:frewsxcv-eprintln, r=Kimundibors-3/+1
Migrate to eprint/eprintln macros where appropriate. None
2017-10-07Auto merge of #44841 - alexcrichton:thinlto, r=michaelwoeristerbors-0/+94
rustc: Implement ThinLTO This commit is an implementation of LLVM's ThinLTO for consumption in rustc itself. Currently today LTO works by merging all relevant LLVM modules into one and then running optimization passes. "Thin" LTO operates differently by having more sharded work and allowing parallelism opportunities between optimizing codegen units. Further down the road Thin LTO also allows *incremental* LTO which should enable even faster release builds without compromising on the performance we have today. This commit uses a `-Z thinlto` flag to gate whether ThinLTO is enabled. It then also implements two forms of ThinLTO: * In one mode we'll *only* perform ThinLTO over the codegen units produced in a single compilation. That is, we won't load upstream rlibs, but we'll instead just perform ThinLTO amongst all codegen units produced by the compiler for the local crate. This is intended to emulate a desired end point where we have codegen units turned on by default for all crates and ThinLTO allows us to do this without performance loss. * In anther mode, like full LTO today, we'll optimize all upstream dependencies in "thin" mode. Unlike today, however, this LTO step is fully parallelized so should finish much more quickly. There's a good bit of comments about what the implementation is doing and where it came from, but the tl;dr; is that currently most of the support here is copied from upstream LLVM. This code duplication is done for a number of reasons: * Controlling parallelism means we can use the existing jobserver support to avoid overloading machines. * We will likely want a slightly different form of incremental caching which integrates with our own incremental strategy, but this is yet to be determined. * This buys us some flexibility about when/where we run ThinLTO, as well as having it tailored to fit our needs for the time being. * Finally this allows us to reuse some artifacts such as our `TargetMachine` creation, where all our options we used today aren't necessarily supported by upstream LLVM yet. My hope is that we can get some experience with this copy/paste in tree and then eventually upstream some work to LLVM itself to avoid the duplication while still ensuring our needs are met. Otherwise I fear that maintaining these bindings may be quite costly over the years with LLVM updates!
2017-10-07rustc: Implement ThinLTOAlex Crichton-0/+94
This commit is an implementation of LLVM's ThinLTO for consumption in rustc itself. Currently today LTO works by merging all relevant LLVM modules into one and then running optimization passes. "Thin" LTO operates differently by having more sharded work and allowing parallelism opportunities between optimizing codegen units. Further down the road Thin LTO also allows *incremental* LTO which should enable even faster release builds without compromising on the performance we have today. This commit uses a `-Z thinlto` flag to gate whether ThinLTO is enabled. It then also implements two forms of ThinLTO: * In one mode we'll *only* perform ThinLTO over the codegen units produced in a single compilation. That is, we won't load upstream rlibs, but we'll instead just perform ThinLTO amongst all codegen units produced by the compiler for the local crate. This is intended to emulate a desired end point where we have codegen units turned on by default for all crates and ThinLTO allows us to do this without performance loss. * In anther mode, like full LTO today, we'll optimize all upstream dependencies in "thin" mode. Unlike today, however, this LTO step is fully parallelized so should finish much more quickly. There's a good bit of comments about what the implementation is doing and where it came from, but the tl;dr; is that currently most of the support here is copied from upstream LLVM. This code duplication is done for a number of reasons: * Controlling parallelism means we can use the existing jobserver support to avoid overloading machines. * We will likely want a slightly different form of incremental caching which integrates with our own incremental strategy, but this is yet to be determined. * This buys us some flexibility about when/where we run ThinLTO, as well as having it tailored to fit our needs for the time being. * Finally this allows us to reuse some artifacts such as our `TargetMachine` creation, where all our options we used today aren't necessarily supported by upstream LLVM yet. My hope is that we can get some experience with this copy/paste in tree and then eventually upstream some work to LLVM itself to avoid the duplication while still ensuring our needs are met. Otherwise I fear that maintaining these bindings may be quite costly over the years with LLVM updates!
2017-10-06implement pattern-binding-modes RFCTobias Schottdorf-0/+636
See the [RFC] and [tracking issue]. [tracking issue]: https://github.com/rust-lang/rust/issues/42640 [RFC]: https://github.com/rust-lang/rfcs/blob/491e0af/text/2005-match-ergonomics.md
2017-10-06Improve resolution of associated types in macros 2.0Vadim Petrochenkov-0/+34