rust/src/librustc_typeck
bors afa8acce25 Auto merge of #47489 - pnkfelix:limit-2pb-issue-46747, r=nikomatsakis
NLL: Limit two-phase borrows to autoref-introduced borrows

This imposes a restriction on two-phase borrows so that it only applies to autoref-introduced borrows.

The goal is to ensure that our initial deployment of two-phase borrows is very conservative. We want it to still cover the `v.push(v.len());` example, but we do not want it to cover cases like `let imm = &v; let mu = &mut v; mu.push(imm.len());`

(Why do we want it to be conservative? Because when you are not conservative, then the results you get, at least with the current analysis, are tightly coupled to details of the MIR construction that we would rather remain invisible to the end user.)

Fix #46747

I decided, for this PR, to add a debug-flag `-Z two-phase-beyond-autoref`, to re-enable the more general approach. But my intention here is *not* that we would eventually turn on that debugflag by default; the main reason I added it was that I thought it was useful for writing tests to be able to write source that looks like desugared MIR.
2018-02-09 02:26:43 +00:00
..
check Auto merge of #47489 - pnkfelix:limit-2pb-issue-46747, r=nikomatsakis 2018-02-09 02:26:43 +00:00
coherence change overlapping_impls to take a tcx and create the infcx 2018-01-30 14:00:24 -05:00
outlives
variance Make use of the implemented red/green algorithm for variance 2018-01-24 12:07:37 +01:00
astconv.rs Merge branch 'cache-ty-collect' of https://github.com/michaelwoerister/rust into rollup 2018-01-25 13:50:25 -08:00
Cargo.toml
check_unused.rs
collect.rs improve wording: bounds -> generic bounds 2018-02-06 16:28:25 +01:00
constrained_type_params.rs
diagnostics.rs Fill in long diagnostic 2018-02-06 11:46:42 -08:00
impl_wf_check.rs
lib.rs Merge branch 'explain' of https://github.com/estebank/rust into rollup 2018-01-26 06:50:31 -08:00
namespace.rs
README.md
structured_errors.rs Rename -Z explain to -Z teach 2018-01-23 11:34:57 -08:00

NB: This crate is part of the Rust compiler. For an overview of the compiler as a whole, see the README.md file found in librustc.

The rustc_typeck crate contains the source for "type collection" and "type checking", as well as a few other bits of related functionality. (It draws heavily on the type inferencing and trait solving code found in librustc.)

Type collection

Type "collection" is the process of converting the types found in the HIR (hir::Ty), which represent the syntactic things that the user wrote, into the internal representation used by the compiler (Ty<'tcx>) -- we also do similar conversions for where-clauses and other bits of the function signature.

To try and get a sense for the difference, consider this function:

struct Foo { }
fn foo(x: Foo, y: self::Foo) { .. }
//        ^^^     ^^^^^^^^^

Those two parameters x and y each have the same type: but they will have distinct hir::Ty nodes. Those nodes will have different spans, and of course they encode the path somewhat differently. But once they are "collected" into Ty<'tcx> nodes, they will be represented by the exact same internal type.

Collection is defined as a bundle of queries (e.g., type_of) for computing information about the various functions, traits, and other items in the crate being compiled. Note that each of these queries is concerned with interprocedural things -- for example, for a function definition, collection will figure out the type and signature of the function, but it will not visit the body of the function in any way, nor examine type annotations on local variables (that's the job of type checking).

For more details, see the collect module.

Type checking

TODO