Skip to content

Commit 96b4f43

Browse files
committed
Handle region errors where the actual scope is a statement
Prevents a case of "unknown scope, this is a bug". I judged this too small to review. Closes #4500
1 parent e51ec26 commit 96b4f43

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

src/librustc/middle/region.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ fn determine_rp_in_ty(ty: @ast::Ty,
622622
&&cx: determine_rp_ctxt,
623623
visitor: visit::vt<determine_rp_ctxt>) {
624624

625-
// we are only interesting in types that will require an item to
625+
// we are only interested in types that will require an item to
626626
// be region-parameterized. if cx.item_id is zero, then this type
627627
// is not a member of a type defn nor is it a constitutent of an
628628
// impl etc. So we can ignore it and its components.

src/librustc/util/ppaux.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ fn explain_region_and_span(cx: ctxt, region: ty::Region)
8282
_ => explain_span(cx, "expression", expr.span)
8383
}
8484
}
85+
Some(ast_map::node_stmt(stmt)) => {
86+
explain_span(cx, "statement", stmt.span)
87+
}
8588
Some(_) | None => {
8689
// this really should not happen
8790
(fmt!("unknown scope: %d. Please report a bug.", node_id),

src/test/compile-fail/issue-4500.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2012 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+
fn main () {
12+
let mut _p: & int = & 4;
13+
_p = ~3; //~ ERROR illegal borrow: borrowed value does not live long enough
14+
//~^ NOTE ...but borrowed value is only valid for the statement
15+
}

0 commit comments

Comments
 (0)