Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
53d3c89
Dont bug! on user error
bjorn3 Feb 28, 2017
54a1c8b
Fix indentation in region infer docs
bjorn3 Feb 28, 2017
2a40918
Syntax highlighting in region infer docs
bjorn3 Feb 28, 2017
be49671
Improve a bit more
bjorn3 Feb 28, 2017
90e94d9
Syntax highlight and note about current rust in infer docs
bjorn3 Feb 28, 2017
234753a
Fix missing backtick typo
Nashenas88 Mar 8, 2017
3198904
Disallow subtyping between T and U in T: Unsize<U>.
eddyb Mar 7, 2017
79a7ee8
fix UB in repr(packed) tests
TimNN Mar 8, 2017
74bc7fd
Overhaul coercion to use the lazy InferOk obligations passing.
eddyb Mar 8, 2017
84d1f6a
Do not bother creating StorageLive for TyNever
nagisa Mar 8, 2017
cfb41ae
Use subtyping on the target of unsizing coercions.
eddyb Mar 9, 2017
b95b5db
update gdbr tests
TimNN Mar 9, 2017
7f19f1f
fix #40294 obligation cause.body_id is not always a NodeExpr
Mar 9, 2017
889337d
move related tests to type-check ui test directory
Mar 10, 2017
a5a3981
Add missing example for Display::fmt
GuillaumeGomez Mar 6, 2017
ea3c82c
Fix associated consts display
GuillaumeGomez Mar 10, 2017
e5d1b9c
save-analysis: cope with lack of method data after a type error
Mar 8, 2017
b959d13
Allow lints to check Bodys directly
oli-obk Mar 7, 2017
4d23ca4
rustc: Whitelist the FMA target feature
fsasm Mar 10, 2017
c60a58b
Attempt to debug sccache in more locations
alexcrichton Mar 11, 2017
45de0f9
Rollup merge of #40146 - bjorn3:few-infer-changes, r=pnkfelix
Mar 11, 2017
b933bdc
Rollup merge of #40299 - GuillaumeGomez:fmt-display-example, r=frewsxcv
Mar 11, 2017
b49036c
Rollup merge of #40315 - oli-obk:lint_body, r=eddyb
Mar 11, 2017
c886815
Rollup merge of #40319 - eddyb:it's-"unsize"-not-"unsound", r=nikomat…
Mar 11, 2017
8dc8f8f
Rollup merge of #40344 - nrc:save-container, r=eddyb
Mar 11, 2017
037e506
Rollup merge of #40345 - Nashenas88:patch-1, r=estebank
Mar 11, 2017
66436b5
Rollup merge of #40372 - nagisa:never-drop, r=eddyb
Mar 11, 2017
d75b9ad
Rollup merge of #40373 - TimNN:test-ub-packed, r=arielb1
Mar 11, 2017
25dcbca
Rollup merge of #40400 - TimNN:gdbr-updates, r=alexcrichton
Mar 11, 2017
d208b2d
Rollup merge of #40404 - cengizIO:master, r=nikomatsakis
Mar 11, 2017
7b0caa5
Rollup merge of #40419 - GuillaumeGomez:fix-const-rendering, r=frewsxcv
Mar 11, 2017
b1e03fe
Rollup merge of #40431 - fsasm:master, r=BurntSushi
Mar 11, 2017
6a5fd0f
Merge branch 'more-sccache-debug' of https://github.com/alexcrichton/…
alexcrichton Mar 12, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/librustc/infer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ course, it depends on the program.

The main case which fails today that I would like to support is:

```text
```rust
fn foo<T>(x: T, y: T) { ... }

fn bar() {
Expand All @@ -168,6 +168,8 @@ because the type variable `T` is merged with the type variable for
`X`, and thus inherits its UB/LB of `@mut int`. This leaves no
flexibility for `T` to later adjust to accommodate `@int`.

Note: `@` and `@mut` are replaced with `Rc<T>` and `Rc<RefCell<T>>` in current Rust.

### What to do when not all bounds are present

In the prior discussion we assumed that A.ub was not top and B.lb was
Expand Down
108 changes: 59 additions & 49 deletions src/librustc/infer/region_inference/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,17 +121,19 @@ every expression, block, and pattern (patterns are considered to
"execute" by testing the value they are applied to and creating any
relevant bindings). So, for example:

fn foo(x: isize, y: isize) { // -+
// +------------+ // |
// | +-----+ // |
// | +-+ +-+ +-+ // |
// | | | | | | | // |
// v v v v v v v // |
let z = x + y; // |
... // |
} // -+

fn bar() { ... }
```rust
fn foo(x: isize, y: isize) { // -+
// +------------+ // |
// | +-----+ // |
// | +-+ +-+ +-+ // |
// | | | | | | | // |
// v v v v v v v // |
let z = x + y; // |
... // |
} // -+

fn bar() { ... }
```

In this example, there is a region for the fn body block as a whole,
and then a subregion for the declaration of the local variable.
Expand Down Expand Up @@ -160,28 +162,32 @@ this, we get a lot of spurious errors around nested calls, in
particular when combined with `&mut` functions. For example, a call
like this one

self.foo(self.bar())
```rust
self.foo(self.bar())
```

where both `foo` and `bar` are `&mut self` functions will always yield
an error.

Here is a more involved example (which is safe) so we can see what's
going on:

struct Foo { f: usize, g: usize }
...
fn add(p: &mut usize, v: usize) {
*p += v;
}
...
fn inc(p: &mut usize) -> usize {
*p += 1; *p
}
fn weird() {
let mut x: Box<Foo> = box Foo { ... };
'a: add(&mut (*x).f,
'b: inc(&mut (*x).f)) // (..)
}
```rust
struct Foo { f: usize, g: usize }
// ...
fn add(p: &mut usize, v: usize) {
*p += v;
}
// ...
fn inc(p: &mut usize) -> usize {
*p += 1; *p
}
fn weird() {
let mut x: Box<Foo> = box Foo { /* ... */ };
'a: add(&mut (*x).f,
'b: inc(&mut (*x).f)) // (..)
}
```

The important part is the line marked `(..)` which contains a call to
`add()`. The first argument is a mutable borrow of the field `f`. The
Expand All @@ -197,16 +203,18 @@ can see that this error is unnecessary. Let's examine the lifetimes
involved with `'a` in detail. We'll break apart all the steps involved
in a call expression:

'a: {
'a_arg1: let a_temp1: ... = add;
'a_arg2: let a_temp2: &'a mut usize = &'a mut (*x).f;
'a_arg3: let a_temp3: usize = {
let b_temp1: ... = inc;
let b_temp2: &'b = &'b mut (*x).f;
'b_call: b_temp1(b_temp2)
};
'a_call: a_temp1(a_temp2, a_temp3) // (**)
}
```rust
'a: {
'a_arg1: let a_temp1: ... = add;
'a_arg2: let a_temp2: &'a mut usize = &'a mut (*x).f;
'a_arg3: let a_temp3: usize = {
let b_temp1: ... = inc;
let b_temp2: &'b = &'b mut (*x).f;
'b_call: b_temp1(b_temp2)
};
'a_call: a_temp1(a_temp2, a_temp3) // (**)
}
```

Here we see that the lifetime `'a` includes a number of substatements.
In particular, there is this lifetime I've called `'a_call` that
Expand All @@ -225,19 +233,21 @@ it will not be *dereferenced* during the evaluation of the second
argument, it can still be *invalidated* by that evaluation. Consider
this similar but unsound example:

struct Foo { f: usize, g: usize }
...
fn add(p: &mut usize, v: usize) {
*p += v;
}
...
fn consume(x: Box<Foo>) -> usize {
x.f + x.g
}
fn weird() {
let mut x: Box<Foo> = box Foo { ... };
'a: add(&mut (*x).f, consume(x)) // (..)
}
```rust
struct Foo { f: usize, g: usize }
// ...
fn add(p: &mut usize, v: usize) {
*p += v;
}
// ...
fn consume(x: Box<Foo>) -> usize {
x.f + x.g
}
fn weird() {
let mut x: Box<Foo> = box Foo { ... };
'a: add(&mut (*x).f, consume(x)) // (..)
}
```

In this case, the second argument to `add` actually consumes `x`, thus
invalidating the first argument.
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/infer/region_inference/graphviz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ pub fn maybe_print_constraints_for<'a, 'gcx, 'tcx>(
};

if output_template.is_empty() {
bug!("empty string provided as RUST_REGION_GRAPH");
panic!("empty string provided as RUST_REGION_GRAPH");
}

if output_template.contains('%') {
Expand Down