Skip to content

Commit

Permalink
Fix unsoundness bug in functions input references
Browse files Browse the repository at this point in the history
Check that function input references are well formed
  • Loading branch information
spastorino committed Apr 11, 2018
1 parent 0e2e179 commit 55fb12c
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/librustc_mir/borrow_check/nll/type_check/mod.rs
Expand Up @@ -898,6 +898,11 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
let sig = self.normalize(&sig, term_location);
self.check_call_dest(mir, term, &sig, destination, term_location);

self.prove_predicates(
sig.inputs().iter().map(|ty| ty::Predicate::WellFormed(ty)),
term_location,
);

// The ordinary liveness rules will ensure that all
// regions in the type of the callee are live here. We
// then further constrain the late-bound regions that
Expand Down
25 changes: 25 additions & 0 deletions src/test/ui/issue-48803.rs
@@ -0,0 +1,25 @@
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(nll)]

fn flatten<'a, 'b, T>(x: &'a &'b T) -> &'a T {
x
}

fn main() {
let mut x = "original";
let y = &x;
let z = &y;
let w = flatten(z);
x = "modified";
//~^ ERROR cannot assign to `x` because it is borrowed [E0506]
println!("{}", w); // prints "modified"
}
15 changes: 15 additions & 0 deletions src/test/ui/issue-48803.stderr
@@ -0,0 +1,15 @@
error[E0506]: cannot assign to `x` because it is borrowed
--> $DIR/issue-48803.rs:22:5
|
LL | let y = &x;
| -- borrow of `x` occurs here
...
LL | x = "modified";
| ^^^^^^^^^^^^^^ assignment to borrowed `x` occurs here
LL | //~^ ERROR cannot assign to `x` because it is borrowed [E0506]
LL | println!("{}", w); // prints "modified"
| - borrow later used here

error: aborting due to previous error

For more information about this error, try `rustc --explain E0506`.

0 comments on commit 55fb12c

Please sign in to comment.