summary refs log tree commit diff
path: root/src/librustc
AgeCommit message (Collapse)AuthorLines
2017-03-09Fix const expression macro invocations.Jeffrey Seyfried-10/+11
2017-02-23Fix ICE when accessing mutably an immutable enumEsteban Küber-1/+3
2017-02-23remove vestiges of the old suggestion machineryNiko Matsakis-256/+26
2017-01-30cleanup: Refactor away `DtorKind`Vadim Petrochenkov-24/+1
2017-01-30Implement Drop for BoxVadim Petrochenkov-26/+4
2017-01-30Merge ty::TyBox into ty::TyAdtVadim Petrochenkov-95/+92
2017-01-28Auto merge of #39305 - eddyb:synelide, r=nikomatsakisbors-515/+1328
Perform lifetime elision (more) syntactically, before type-checking. The *initial* goal of this patch was to remove the (contextual) `&RegionScope` argument passed around `rustc_typeck::astconv` and allow converting arbitrary (syntactic) `hir::Ty` to (semantic) `Ty`. I've tried to closely match the existing behavior while moving the logic to the earlier `resolve_lifetime` pass, and [the crater report](https://gist.github.com/eddyb/4ac5b8516f87c1bfa2de528ed2b7779a) suggests none of the changes broke real code, but I will try to list everything: There are few cases in lifetime elision that could trip users up due to "hidden knowledge": ```rust type StaticStr = &'static str; // hides 'static trait WithLifetime<'a> { type Output; // can hide 'a } // This worked because the type of the first argument contains // 'static, although StaticStr doesn't even have parameters. fn foo(x: StaticStr) -> &str { x } // This worked because the compiler resolved the argument type // to <T as WithLifetime<'a>>::Output which has the hidden 'a. fn bar<'a, T: WithLifetime<'a>>(_: T::Output) -> &str { "baz" } ``` In the two examples above, elision wasn't using lifetimes that were in the source, not even *needed* by paths in the source, but rather *happened* to be part of the semantic representation of the types. To me, this suggests they should have never worked through elision (and they don't with this PR). Next we have an actual rule with a strange result, that is, the return type here elides to `&'x str`: ```rust impl<'a, 'b> Trait for Foo<'a, 'b> { fn method<'x, 'y>(self: &'x Foo<'a, 'b>, _: Bar<'y>) -> &str { &self.name } } ``` All 3 of `'a`, `'b` and `'y` are being ignored, because the `&self` elision rule only cares that the first argument is "`self` by reference". Due implementation considerations (elision running before typeck), I've limited it in this PR to a reference to a primitive/`struct`/`enum`/`union`, but not other types, but I am doing another crater run to assess the impact of limiting it to literally `&self` and `self: &Self` (they're identical in HIR). It's probably ideal to keep an "implicit `Self` for `self`" type around and *only* apply the rule to `&self` itself, but that would result in more bikeshed, and #21400 suggests some people expect otherwise. Another decent option is treating `self: X, ... -> Y` like `X -> Y` (one unique lifetime in `X` used for `Y`). The remaining changes have to do with "object lifetime defaults" (see RFCs [599](https://github.com/rust-lang/rfcs/blob/master/text/0599-default-object-bound.md) and [1156](https://github.com/rust-lang/rfcs/blob/master/text/1156-adjust-default-object-bounds.md)): ```rust trait Trait {} struct Ref2<'a, 'b, T: 'a+'b>(&'a T, &'b T); // These apply specifically within a (fn) body, // which allows type and lifetime inference: fn main() { // Used to be &'a mut (Trait+'a) - where 'a is one // inference variable - &'a mut (Trait+'b) in this PR. let _: &mut Trait; // Used to be an ambiguity error, but in this PR it's // Ref2<'a, 'b, Trait+'c> (3 inference variables). let _: Ref2<Trait>; } ``` What's happening here is that inference variables are created on the fly by typeck whenever a lifetime has no resolution attached to it - while it would be possible to alter the implementation to reuse inference variables based on decisions made early by `resolve_lifetime`, not doing that is more flexible and works better - it can compile all testcases from #38624 by not ending up with `&'static mut (Trait+'static)`. The ambiguity specifically cannot be an early error, because this is only the "default" (typeck can still pick something better based on the definition of `Trait` and whether it has any lifetime bounds), and having an error at all doesn't help anyone, as we can perfectly infer an appropriate lifetime inside the `fn` body. **TODO**: write tests for the user-visible changes. cc @nikomatsakis @arielb1
2017-01-28rustc: remove unused `bounds` field from `RegionParameterDef`.Eduard-Mihai Burtescu-27/+9
2017-01-28rustc: move object default lifetimes to resolve_lifetimes.Eduard-Mihai Burtescu-75/+329
2017-01-28rustc: always keep an explicit lifetime in trait objects.Eduard-Mihai Burtescu-14/+54
2017-01-28rustc: lower trait type paths as TyTraitObject.Eduard-Mihai Burtescu-42/+40
2017-01-28rustc: move most of lifetime elision to resolve_lifetimes.Eduard-Mihai Burtescu-11/+557
2017-01-28rustc: simplify scope-tracking in resolve_lifetime.Eduard-Mihai Burtescu-321/+220
2017-01-28rustc: clean up the style of middle::resolve_lifetime.Eduard-Mihai Burtescu-69/+99
2017-01-28rustc: always include elidable lifetimes in HIR types.Eduard-Mihai Burtescu-102/+166
2017-01-27Rollup merge of #39351 - nikomatsakis:incr-comp-skip-typeck-1, r=eddybAlex Crichton-7/+7
move `cast_kinds` into `TypeckTables` where it belongs r? @eddyb
2017-01-27Rollup merge of #39321 - king6cong:master, r=frewsxcvAlex Crichton-1/+1
doc comment typo fix
2017-01-27Rollup merge of #39290 - canndrew:hide-uninhabitedness, r=nikomatsakisAlex Crichton-5/+1
Hide uninhabitedness checks behind feature gate This reverts the fix to match exhaustiveness checking so that it can be discussed. The new code is now hidden behind the `never_type` feature gate.
2017-01-27Auto merge of #37057 - brson:nosuggest, r=nikomatsakisbors-714/+4
rustc: Remove all "consider using an explicit lifetime parameter" suggestions These give so many incorrect suggestions that having them is detrimental to the user experience. The compiler should not be suggesting changes to the code that are wrong - it is infuriating: not only is the compiler telling you that _you don't understand_ borrowing, _the compiler itself_ appears to not understand borrowing. It does not inspire confidence. r? @nikomatsakis
2017-01-27move `cast_kinds` into `TypeckTables` where it belongsNiko Matsakis-7/+7
2017-01-27Auto merge of #39281 - michaelwoerister:make-cc-incr-comp-opt-in, r=nikomatsakisbors-0/+2
incr.comp.: Make cross-crate tracking for incr. comp. opt-in. The current implementation of cross-crate dependency tracking can cause quite long compile times and high memory usage for some crates (see #39208 for example). This PR therefore makes that part of dependency tracking optional. Incremental compilation still works, it will only have very coarse dep-tracking for upstream crates. r? @nikomatsakis
2017-01-27Auto merge of #39139 - estebank:issue-38147, r=nikomatsakisbors-2/+61
Point to immutable arg/fields when trying to use as &mut Present the following output when trying to access an immutable borrow's field as mutable: ``` error[E0389]: cannot borrow data mutably in a `&` reference --> $DIR/issue-38147-1.rs:27:9 | 26 | fn f(&self) { | ----- use `&mut self` here to make mutable 27 | f.s.push('x'); | ^^^ assignment into an immutable reference ``` And the following when trying to access an immutable struct field as mutable: ``` error: cannot borrow immutable borrowed content `*self.s` as mutable --> $DIR/issue-38147-3.rs:17:9 | 12 | s: &'a String | ------------- use `&'a mut String` here to make mutable ...| 16 | fn f(&self) { | ----- use `&mut self` here to make mutable 17 | self.s.push('x'); | ^^^^^^ cannot borrow as mutable ``` Fixes #38147.
2017-01-26rustc: Remove all "consider using an explicit lifetime parameter" suggestionsBrian Anderson-714/+4
These give so many incorrect suggestions that having them is detrimental to the user experience. The compiler should not be suggesting changes to the code that are wrong - it is infuriating: not only is the compiler telling you that _you don't understand_ borrowing, _the compiler itself_ appears to not understand borrowing. It does not inspire confidence.
2017-01-26Point to immutable arg/fields when trying to use as &mutEsteban Küber-2/+61
Point to immutable borrow arguments and fields when trying to use them as mutable borrows. Add label to primary span on "cannot borrow as mutable" errors. Present the following output when trying to access an immutable borrow's field as mutable: ``` error[E0389]: cannot borrow data mutably in a `&` reference --> $DIR/issue-38147-1.rs:27:9 | 26 | fn f(&self) { | ----- use `&mut self` here to make mutable 27 | f.s.push('x'); | ^^^ assignment into an immutable reference ``` And the following when trying to access an immutable struct field as mutable: ``` error: cannot borrow immutable borrowed content `*self.s` as mutable --> $DIR/issue-38147-3.rs:17:9 | 12 | s: &'a String | ------------- use `&'a mut String` here to make mutable ...| 16 | fn f(&self) { | ----- use `&mut self` here to make mutable 17 | self.s.push('x'); | ^^^^^^ cannot borrow as mutable ```
2017-01-27doc comment typo fixking6cong-1/+1
2017-01-26Auto merge of #39066 - arielb1:lifetime-extension-test, r=nikomatsakisbors-24/+74
End temporary lifetimes being extended by `let X: &_` hints cc #39283 r? @nikomatsakis
2017-01-26Auto merge of #39309 - eddyb:map-shmap, r=nikomatsakisbors-380/+380
Rename tcx.map to the far more descriptive tcx.hir. Also a bit more renaming because `ast_map` and `'ast` were still used with HIR. Main motivation is to "free up" `tcx.map`, or rather, `tcx.maps`, to consolidate `ty::maps` there. r? @nikomatsakis
2017-01-26Auto merge of #38819 - GuillaumeGomez:main_func_wrong_type, r=GuillaumeGomezbors-2/+29
Add a distinct error code and description for "main function has wron… …g type"
2017-01-26rustc: don't call the HIR AST.Eduard-Mihai Burtescu-219/+219
2017-01-26rustc: rename TyCtxt's `map` field to `hir`.Eduard-Mihai Burtescu-164/+164
2017-01-26Update error code numberGuillaume Gomez-3/+3
2017-01-26Add a distinct error code and description for "main function has wrong type"Guillaume Gomez-2/+29
2017-01-26Auto merge of #39075 - est31:remove_reflect, r=nikomatsakisbors-57/+3
Remove Reflect PR for removing the `Reflect` trait. Opened so that a crater run can be done for testing the impact: https://github.com/rust-lang/rust/issues/27749#issuecomment-272665163 Fixes #27749
2017-01-25rename `Tables` to `TypeckTables`Niko Matsakis-59/+59
2017-01-25remove outdated textNiko Matsakis-21/+0
2017-01-25merge TypeckItemBody and Tables depnodesNiko Matsakis-16/+15
2017-01-25Rollup merge of #39267 - king6cong:master, r=steveklabnikGuillaume Gomez-2/+2
doc comment rewording
2017-01-25Hide uninhabitedness checks behind feature gateAndrew Cann-5/+1
2017-01-25Auto merge of #35712 - oli-obk:exclusive_range_patterns, r=nikomatsakisbors-8/+26
exclusive range patterns adds `..` patterns to the language under a feature gate (`exclusive_range_pattern`). This allows turning ``` rust match i { 0...9 => {}, 10...19 => {}, 20...29 => {}, _ => {} } ``` into ``` rust match i { 0..10 => {}, 10..20 => {}, 20..30 => {}, _ => {} } ```
2017-01-25end temporary lifetimes being extended by `let X: &_` hintsAriel Ben-Yehuda-24/+74
Fixes #36082.
2017-01-24incr.comp.: Make cross-crate tracking for incr. comp. opt-in.Michael Woerister-0/+2
2017-01-24Remove Reflectest31-57/+3
* Remove the Reflect trait * Remove the "reflect" lang feature
2017-01-24doc typo fixking6cong-1/+1
2017-01-24doc comment rewordingking6cong-1/+1
2017-01-22Auto merge of #39238 - king6cong:pr, r=frewsxcvbors-1/+1
better comment wording
2017-01-22Auto merge of #39127 - canndrew:unreachable-pattern-errors-into-warnings, ↵bors-7/+35
r=arielb1 Change unreachable pattern ICEs to warnings Allow code with unreachable `?` and `for` patterns to compile. Add some tests.
2017-01-22better comment wordingking6cong-1/+1
2017-01-22Remove unused `extern crate`s.Jeffrey Seyfried-8/+0
2017-01-22Warn on unused `#[macro_use]` imports.Jeffrey Seyfried-1/+1
2017-01-21Fix commentAndrew Cann-6/+3