Commit graph

69353 commits

Author SHA1 Message Date
Michael Hewson
e06cd316a4 Remove the error check that I think is redundant, and change the test error messages that I don't understand why they changed, so the tests pass 2017-11-08 08:31:08 -05:00
Michael Hewson
02ce3ac1f8 add a NOTE comment to the object safety test so that it passes 2017-11-08 08:29:47 -05:00
Michael Hewson
bbe755c7a6 Switch from using At::eq to InferCtxt::can_eq and demand_eqtype_with_origin
I doubt this changes anything, I was just trying to fix an issue with
error messages and ended up doing this along with other things.
Committing it separately so I can undo it easily.
2017-11-08 08:28:36 -05:00
Michael Hewson
236974619f normalize associated types in both self_ty and self_arg_ty
I was only doing it for self_arg_ty, and ended up causing
run-pass/associated-types-projection-from-known-type-in-impl.rs to fail.
2017-11-08 08:24:33 -05:00
Michael Hewson
3902643c27 move ExplicitSelf to rustc::ty::util, and use it to implement object safety checks 2017-11-08 05:27:39 -05:00
Michael Hewson
0b27dcc665 modify ExplicitSelf::determine to take an is_self_type predicate closure, instead of infcx 2017-11-08 04:31:48 -05:00
Michael Hewson
1d29966d3b wrap error code in DiagnosticId::Error so it compiles 2017-11-07 14:32:59 -05:00
Michael Hewson
0d739b5b97 Update/improve documentation of ExpliciSelf 2017-11-07 13:36:10 -05:00
Michael Hewson
6fd215647d Add arbitrary_self_types feature gate error to some tests 2017-11-07 13:36:10 -05:00
Michael Hewson
aa0df3da3d get the old error messages back
- added some old code that used ExplicitSelf::determine to check for eqtype with the expected self type in the simple cases
- this fixes problems with error messages being worse in those cases, which caused some compile-fail tests to fail
2017-11-07 13:36:10 -05:00
Michael Hewson
d03eb2cc2d Fix some of the tests
- removed the inherent impls compile-fail test, because we’ll be
supporting them
- remove E0308-2 because it’s gonna be supported now (behind a feature
gate)
- replaced the mismatched method receiver error message with something
better, so fixed the tests that that broke
2017-11-07 13:36:10 -05:00
Michael Hewson
9a592e61ff Improve feature gate error, and return after emitting errors instead of looping forever 2017-11-07 13:36:10 -05:00
Michael Hewson
a3f5866fe8 Fix the lifetime error in ExplicitSelf
Had to take the infer context as a parameter instead of the type
context, so that the function can be called during inference
2017-11-07 13:36:10 -05:00
Michael Hewson
7dff08de57 Rewrote check_method_receiver and ExplicitSelf, got a borrow checker error
Rewrote ExplicitSelf, adding a new `Other` variant for arbitrary self
types. It’s a bit more sophisticated now, and checks for type equality,
so you have to pass the type context and param env as arguments.
There’s a borrow-checker error here that I have to fix

Rewrote check_method_receiver, so it acts as if arbitrary self types
are allowed, and then checks for ExplicitSelf::Other at the end and
disallows it unless the feature is present.
2017-11-07 13:36:10 -05:00
Michael Hewson
497397ab4b initial implementation of arbitrary_self_types
If the feature is enabled, allow method `self` types to be any type
that auto-derefs to `self`.
- Currently, this supports inherent methods as well as trait methods.
The plan AFAIK is to only allow this for trait methods, so I guess it
won’t stay this way
- Dynamic dispatch isn’t implemented yet, so the compiler will ICE if
you define a trait method that takes `self: Rc<Self>` and try to call
it on an `Rc<Trait>`. I will probably just make those methods
non-object-safe initially.
2017-11-07 13:36:10 -05:00
Michael Hewson
edc8c760e0 add tests for the arbitrary_self_types, which won't pass yet 2017-11-07 13:36:10 -05:00
bors
7ade24f672 Auto merge of #45666 - Amanieu:tls-model, r=alexcrichton
Allow overriding the TLS model

This PR adds the ability to override the default "global-dynamic" TLS model with a more specific one through a target json option or a command-line option. This allows for better code generation in certain situations.

This is similar to the `-ftls-model=` option in GCC and Clang.
2017-11-07 14:24:15 +00:00
bors
3e7f501991 Auto merge of #45620 - ollie27:rustdoc_impl_generic_dupe, r=QuietMisdreavus
rustdoc: Fix duplicated impls with generics

The same type can appear multiple times in impls so we need to use a set
to avoid adding it multiple times.

Fixes: #45584
2017-11-07 07:24:13 +00:00
bors
a17e72462f Auto merge of #45571 - zackmdavis:regenerate_char_private, r=alexcrichton
regenerate libcore/char_private.rs

(filed separately from the work in #45569, because of this matter of the updated Unicode data; see also #45567)

char_private.rs is generated programmatically by char_private.py, using data retrieved from the Unicode Consortium's website.

The motivation here was to make `is_printable` crate-visible (with `pub(crate)`), but it would seem that the Unicode data has changed slightly since char_private.rs was last generated.
2017-11-07 02:07:34 +00:00
bors
785643a5eb Auto merge of #45668 - nikomatsakis:nll-free-region, r=arielb1
extend NLL with preliminary support for free regions on functions

This PR extends https://github.com/rust-lang/rust/pull/45538 with support for free regions. This is pretty preliminary and will no doubt want to change in various ways, particularly as we add support for closures, but it's enough to get the basic idea in place:

- We now create specific regions to represent each named lifetime declared on the function.
- Region values can contain references to these regions (represented for now as a `BTreeSet<RegionIndex>`).
- If we wind up trying to infer that `'a: 'b` must hold, but no such relationship was declared, we report an error.

It also does a number of drive-by refactorings.

r? @arielb1

cc @spastorino
2017-11-06 23:30:57 +00:00
Amanieu d'Antras
fdf7ba2ce9 Move tls-model to a -Z option since it is unstable 2017-11-06 21:10:49 +00:00
bors
bd0e45a323 Auto merge of #45811 - DSpeckhals:update-rustfmt-rls, r=nikomatsakis
tools: Fix rustfmt and the RLS

These tools have been corrected in their upstream repo's, and the submodules have been updated here to reflect that. I also had to update Cargo to match what the RLS is expecting.

The tool states for `rustfmt` and `rls` where both changed from "Broken" to "Testing" in this commit, thus enabling testing and distribution again.
2017-11-06 20:43:46 +00:00
bors
dbe8055f5a Auto merge of #45322 - infinity0:master, r=alexcrichton
When cross-compiling, also build target-arch tarballs for libstd. (Closes: #42320)

Half of the logic is actually in there already in install.rs:install_std but it fails with an error like:

sh: 0: Can't open /<<BUILDDIR>>/rustc-1.21.0+dfsg1/build/tmp/dist/rust-std-1.21.0-powerpc64le-unknown-linux-gnu/install.sh

because the target-arch dist tarball wasn't built as well. This commit fixes that so the overall install works.

There is one minor bug in the existing code which this commit doesn't fix - the install.log from multiple runs of the installer gets clobbered, which seems like it might interfere with the uninstall process (I didn't look very deeply into this, because it doesn't affect what I need to do.) The actual installed files under DESTDIR seem fine though - either they are installed under an arch-specific path, or the multiple runs will clobber the same path with the same arch-independent file.
2017-11-06 18:04:13 +00:00
Dustin Speckhals
d0c1f36771 tools: Fix rustfmt and the RLS
These tools have been corrected in their upstream repo's, and the
submodules have been updated here to reflect that. I also had to update
Cargo to match what the RLS is expecting.

The tool states for `rustfmt` and `rls` where both changed from "Broken"
to "Testing" in this commit, thus enabling testing and distribution
again.
2017-11-06 13:03:06 -05:00
bors
58557fafae Auto merge of #45369 - fintelia:patch-1, r=BurntSushi
Implement is_empty() for BufReader

Simple implementation of `is_empty` method for BufReader so it is possible to tell whether there is any data in its buffer.

I didn't know correct stability annotation to place on the function. Presumably there is no reason to place this feature behind a feature flag, but I wasn't sure how to tag it as an unstable feature without that.

CC: #45323
2017-11-06 15:19:48 +00:00
bors
74be072068 Auto merge of #45737 - oli-obk:json, r=petrochenkov
Pretty print json in ui tests

I found the json output in one line to not be useful for reviewing

r? @petrochenkov
2017-11-06 12:18:12 +00:00
Ximin Luo
32cf6e64c1 Ensure dist::Std for every libstd target. (Closes: #42320)
This fixes cross-compile installation. Half of the logic is actually in there
already in install.rs:install_std but it fails with an error like:

sh: 0: Can't open /<<BUILDDIR>>/rustc-1.21.0+dfsg1/build/tmp/dist/rust-std-1.21.0-powerpc64le-unknown-linux-gnu/install.sh

because the target-arch dist tarball wasn't built as well.
2017-11-06 11:38:27 +01:00
Oliver Schneider
6d6fb2ef97
Adjust json errors to byte changes 2017-11-06 10:35:50 +01:00
bors
19402f11e1 Auto merge of #45798 - nrc:rls-bugs-3, r=eddyb
A couple more save-analysis fixes

r? @eddyb
2017-11-06 08:48:11 +00:00
bors
54bbd56715 Auto merge of #45758 - nzig:explain-span-ctxt, r=petrochenkov
Add comment explaining the ctxt field in Span

As discussed in #45747.

r? @petrochenkov
2017-11-06 05:16:15 +00:00
Nick Cameron
b709a7ebc5 save-analysis: fix bugs in method chains
Use the span we save in the PathSegment for a method call, rather than searching for it in the text.

Fixes https://github.com/nrc/rls-analysis/issues/111
2017-11-06 15:52:42 +13:00
bors
11cee74093 Auto merge of #45756 - topecongiro:fix-typos/librustc_typeck, r=kennytm
Fix typos in README.md

This nitpicky PR fixes few typos I found while reading `README.md`s.
2017-11-06 02:02:11 +00:00
Nick Cameron
099f96472f save-analysis: give better info for Unions 2017-11-06 14:56:43 +13:00
bors
44990e5b14 Auto merge of #45770 - spastorino:newtype_index, r=nikomatsakis
Make last structs indexes definitions use newtype_index macro

This PR makes the last two index structs not using newtype_index macro to use it and also fixes this https://github.com/rust-lang/rust/issues/45763 issue.
2017-11-05 22:06:15 +00:00
bors
3b82e4c74d Auto merge of #45723 - sinkuu:ice_45493, r=arielb1
Fix MIR inlining panic in generic function

MIR inlining calls `Instance::resolve` with a substs containing param, and `trans_apply_param_substs` panics. ~~This PR fixes it by making `Instance::resolve` return `None` if `substs.has_param_types()`, though I'm not sure if this is a right fix.~~

Fixes #45493.
2017-11-05 19:19:59 +00:00
bors
666687a68c Auto merge of #45072 - nikomatsakis:issue-38714, r=arielb1
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-05 16:49:08 +00:00
bors
b55d290956 Auto merge of #45759 - alexcrichton:update-openssl, r=sfackler
rustbuild: Update the OpenSSL version to link

This updates the OpenSSL tarball download to reflect OpenSSL's newest release.
2017-11-05 14:18:21 +00:00
sinkuu
afb52e1ca1 Fix MIR inlining panic in generic function 2017-11-05 22:57:53 +09:00
bors
94ede93467 Auto merge of #44042 - LukasKalbertodt:ascii-methods-on-instrinsics, r=alexcrichton
Copy all `AsciiExt` methods to the primitive types directly in order to deprecate it later

**EDIT:** [this PR is ready now](https://github.com/rust-lang/rust/pull/44042#issuecomment-333883548). I edited this post to reflect the current status of discussion, which is (apart from code review) pretty much settled.

---

This is my current progress in order to prepare stabilization of #39658. As discussed there (and in #39659), the idea is to deprecated `AsciiExt` and copy all methods to the type directly. Apparently there isn't really a reason to have those methods in an extension trait¹.

~~This is **work in progress**: copy&pasting code while slightly modifying the documentation isn't the most exciting thing to do. Therefore I wanted to already open this WIP PR after doing basically 1/4 of the job (copying methods to `&[u8]`, `char` and `&str` is still missing) to get some feedback before I continue. Some questions possibly worth discussing:~~

1. ~~Does everyone agree that deprecating `AsciiExt` is a good idea? Does everyone agree with the goal of this PR?~~ => apparently yes
2. ~~Are my changes OK so far? Did I do something wrong?~~
3. ~~The issue of the unstable-attribute is currently set to 0. I would wait until you say "Ok" to the whole thing, then create a tracking issue and then insert the correct issue id. Is that ok?~~
4. ~~I tweaked `eq_ignore_ascii_case()`: it now takes the argument `other: u8` instead of `other: &u8`. The latter was enforced by the trait. Since we're not bound to a trait anymore, we can drop the reference, ok?~~ => I reverted this, because the interface has to match the `AsciiExt` interface exactly.

¹ ~~Could it be that we can't write `impl [u8] {}`? This might be the reason for `AsciiExt`. If that is the case: is there a good reason we can't write such an impl block? What can we do instead?~~ => we couldn't at the time this PR was opened, but Simon made it possible.

/cc @SimonSapin @zackw
2017-11-05 11:42:59 +00:00
Lukas Kalbertodt
ea55596d5b Relax #[deny(warnings)] in some crate for cargotest
Otherwise changes to the compiler are unable to introduce new
warnings: some crates tested by cargotest deny all warnings and
thus, the CI build fails.

Thanks SimonSapin for the patch!
2017-11-05 10:40:06 +01:00
bors
4efcc660f0 Auto merge of #45754 - scottmcm:checked-npot, r=dtolnay
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-05 09:11:45 +00:00
bors
16e9b9f15c Auto merge of #45748 - petrochenkov:short, r=alexcrichton
Shorten paths to auxiliary files created by tests

I'm hitting issues with long file paths to object files created by the test suite, similar to https://github.com/rust-lang/rust/issues/45103#issuecomment-335622075.

If we look at the object file path in https://github.com/rust-lang/rust/issues/45103 we can see that the patch contains of few components:
```
specialization-cross-crate-defaults.stage2-x86_64-pc-windows-gnu.run-pass.libaux\specialization_cross_crate_defaults.specialization_cross_crate_defaults0.rust-cgu.o
```
=>

1. specialization-cross-crate-defaults // test name, required
2. stage2 // stage disambiguator, required
3. x86_64-pc-windows-gnu // target disambiguator, required
4. run-pass // mode disambiguator, rarely required
5. libaux // suffix, can be shortened
6. specialization_cross_crate_defaults // required, there may be several libraries in the directory
7. specialization_cross_crate_defaults0 // codegen unit name, can be shortened?
8. rust-cgu // suffix, can be shortened?
9. o // object file extension

This patch addresses items `4`, `5` and `8`.
`libaux` is shortened to `aux`, `rust-cgu` is shortened to `rcgu`, mode disambiguator is omitted unless it's necessary (for pretty-printing and debuginfo tests, see 38d26d811a)

I haven't touched names of codegen units though (`specialization_cross_crate_defaults0`).
Is it useful for them to have descriptive names including the crate name, as opposed to just `0` or `cgu0` or something?
2017-11-05 06:42:17 +00:00
bors
44183f50bc Auto merge of #45710 - alexcrichton:std-symbols, r=michaelwoerister
rustc: Handle some libstd symbole exports better

Right now symbol exports, particularly in a cdylib, are handled by
assuming that `pub extern` combined with `#[no_mangle]` means "export
this". This isn't actually what we want for some symbols that the
standard library uses to implement itself, for example symbols related
to allocation. Additionally other special symbols like
`rust_eh_personallity` have no need to be exported from cdylib crate
types (only needed in dylib crate types).

This commit updates how rustc handles these special symbols by adding to
the hardcoded logic of symbols like `rust_eh_personallity` but also
adding a new attribute, `#[rustc_std_internal_symbol]`, which forces the
export level to be considered the same as all other Rust functions
instead of looking like a C function.

The eventual goal here is to prevent functions like `__rdl_alloc` from
showing up as part of a Rust cdylib as it's just an internal
implementation detail. This then further allows such symbols to get gc'd
by the linker when creating a cdylib.
2017-11-05 04:02:07 +00:00
Alex Crichton
fbf9869702 rustc: Handle some libstd symbole exports better
Right now symbol exports, particularly in a cdylib, are handled by
assuming that `pub extern` combined with `#[no_mangle]` means "export
this". This isn't actually what we want for some symbols that the
standard library uses to implement itself, for example symbols related
to allocation. Additionally other special symbols like
`rust_eh_personallity` have no need to be exported from cdylib crate
types (only needed in dylib crate types).

This commit updates how rustc handles these special symbols by adding to
the hardcoded logic of symbols like `rust_eh_personallity` but also
adding a new attribute, `#[rustc_std_internal_symbol]`, which forces the
export level to be considered the same as all other Rust functions
instead of looking like a C function.

The eventual goal here is to prevent functions like `__rdl_alloc` from
showing up as part of a Rust cdylib as it's just an internal
implementation detail. This then further allows such symbols to get gc'd
by the linker when creating a cdylib.
2017-11-04 20:01:11 -07:00
Scott McMurray
0d745af29a Use Add::add for overflow checks instead of [rustc_inherit_overflow_checks] 2017-11-04 17:10:51 -07:00
Nadav Zingerman
0220600a0d Fix comment formatting 2017-11-05 01:24:20 +02:00
bors
12e6b53744 Auto merge of #45711 - tirr-c:unicode-span, r=estebank
Display spans correctly when there are zero-width or wide characters

Hopefully...
* fixes #45211
* fixes #8706

---

Before:
```
error: invalid width `7` for integer literal
  --> unicode_2.rs:12:25
   |
12 |     let _ = ("a̐éö̲", 0u7);
   |                         ^^^
   |
   = help: valid widths are 8, 16, 32, 64 and 128

error: invalid width `42` for integer literal
  --> unicode_2.rs:13:20
   |
13 |     let _ = ("아あ", 1i42);
   |                    ^^^^
   |
   = help: valid widths are 8, 16, 32, 64 and 128

error: aborting due to 2 previous errors
```

After:
```
error: invalid width `7` for integer literal
  --> unicode_2.rs:12:25
   |
12 |     let _ = ("a̐éö̲", 0u7);
   |                     ^^^
   |
   = help: valid widths are 8, 16, 32, 64 and 128

error: invalid width `42` for integer literal
  --> unicode_2.rs:13:20
   |
13 |     let _ = ("아あ", 1i42);
   |                      ^^^^
   |
   = help: valid widths are 8, 16, 32, 64 and 128

error: aborting due to 2 previous errors
```

Spans might display incorrectly on the browser.

r? @estebank
2017-11-04 23:09:19 +00:00
Santiago Pastorino
d19faead2d Make DefIndex use newtype_index macro 2017-11-04 19:22:37 -03:00
Santiago Pastorino
f9bc8e7c4f Make DEBUG_FORMAT = custom work
Fixes #45763, ht by @durka
2017-11-04 19:10:44 -03:00
Lukas Kalbertodt
deb7360fa7 Remove import of now unused AsciiExt
I also replaced a wildcard import with a specific one, while I was
at it.
2017-11-04 19:16:03 +01:00