Skip to content

Commit 55fb12c

Browse files
committed
Fix unsoundness bug in functions input references
Check that function input references are well formed
1 parent 0e2e179 commit 55fb12c

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

src/librustc_mir/borrow_check/nll/type_check/mod.rs

+5
Original file line numberDiff line numberDiff line change
@@ -898,6 +898,11 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
898898
let sig = self.normalize(&sig, term_location);
899899
self.check_call_dest(mir, term, &sig, destination, term_location);
900900

901+
self.prove_predicates(
902+
sig.inputs().iter().map(|ty| ty::Predicate::WellFormed(ty)),
903+
term_location,
904+
);
905+
901906
// The ordinary liveness rules will ensure that all
902907
// regions in the type of the callee are live here. We
903908
// then further constrain the late-bound regions that

src/test/ui/issue-48803.rs

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![feature(nll)]
12+
13+
fn flatten<'a, 'b, T>(x: &'a &'b T) -> &'a T {
14+
x
15+
}
16+
17+
fn main() {
18+
let mut x = "original";
19+
let y = &x;
20+
let z = &y;
21+
let w = flatten(z);
22+
x = "modified";
23+
//~^ ERROR cannot assign to `x` because it is borrowed [E0506]
24+
println!("{}", w); // prints "modified"
25+
}

src/test/ui/issue-48803.stderr

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0506]: cannot assign to `x` because it is borrowed
2+
--> $DIR/issue-48803.rs:22:5
3+
|
4+
LL | let y = &x;
5+
| -- borrow of `x` occurs here
6+
...
7+
LL | x = "modified";
8+
| ^^^^^^^^^^^^^^ assignment to borrowed `x` occurs here
9+
LL | //~^ ERROR cannot assign to `x` because it is borrowed [E0506]
10+
LL | println!("{}", w); // prints "modified"
11+
| - borrow later used here
12+
13+
error: aborting due to previous error
14+
15+
For more information about this error, try `rustc --explain E0506`.

0 commit comments

Comments
 (0)