Fix unsoundness bug in functions input references
Check that function input references are well formed
This commit is contained in:
parent
0e2e179571
commit
55fb12c274
3 changed files with 45 additions and 0 deletions
|
@ -898,6 +898,11 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
|
||||||
let sig = self.normalize(&sig, term_location);
|
let sig = self.normalize(&sig, term_location);
|
||||||
self.check_call_dest(mir, term, &sig, destination, 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
|
// The ordinary liveness rules will ensure that all
|
||||||
// regions in the type of the callee are live here. We
|
// regions in the type of the callee are live here. We
|
||||||
// then further constrain the late-bound regions that
|
// then further constrain the late-bound regions that
|
||||||
|
|
25
src/test/ui/issue-48803.rs
Normal file
25
src/test/ui/issue-48803.rs
Normal file
|
@ -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
src/test/ui/issue-48803.stderr
Normal file
15
src/test/ui/issue-48803.stderr
Normal file
|
@ -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`.
|
Loading…
Add table
Add a link
Reference in a new issue