Skip to content

Commit 9f9c02b

Browse files
committed
---
yaml --- r: 184253 b: refs/heads/tmp c: f2529ac h: refs/heads/master i: 184251: 76ecaef v: v3
1 parent efda805 commit 9f9c02b

File tree

5 files changed

+61
-1
lines changed

5 files changed

+61
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ refs/heads/building: 126db549b038c84269a1e4fe46f051b2c15d6970
3434
refs/heads/beta: 522d09dfecbeca1595f25ac58c6d0178bbd21d7d
3535
refs/heads/windistfix: 7608dbad651f02e837ed05eef3d74a6662a6e928
3636
refs/tags/1.0.0-alpha: e42bd6d93a1d3433c486200587f8f9e12590a4d7
37-
refs/heads/tmp: 801bc48939e6df1678ad2934ce35d981a068f253
37+
refs/heads/tmp: f2529ac10d7ba68a03ce94873076afa9eb52e365

branches/tmp/src/librustc/middle/infer/error_reporting.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,17 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
675675
sup,
676676
"");
677677
}
678+
infer::Operand(span) => {
679+
self.tcx.sess.span_err(
680+
span,
681+
"lifetime of operand does not outlive \
682+
the operation");
683+
note_and_explain_region(
684+
self.tcx,
685+
"the operand is only valid for ",
686+
sup,
687+
"");
688+
}
678689
infer::AddrOf(span) => {
679690
self.tcx.sess.span_err(
680691
span,
@@ -1593,6 +1604,11 @@ impl<'a, 'tcx> ErrorReportingHelpers<'tcx> for InferCtxt<'a, 'tcx> {
15931604
span,
15941605
"...so that return value is valid for the call");
15951606
}
1607+
infer::Operand(span) => {
1608+
self.tcx.sess.span_err(
1609+
span,
1610+
"...so that operand is valid for operation");
1611+
}
15961612
infer::AddrOf(span) => {
15971613
self.tcx.sess.span_note(
15981614
span,

branches/tmp/src/librustc/middle/infer/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,9 @@ pub enum SubregionOrigin<'tcx> {
210210
// Region in return type of invoked fn must enclose call
211211
CallReturn(Span),
212212

213+
// Operands must be in scope
214+
Operand(Span),
215+
213216
// Region resulting from a `&` expr must enclose the `&` expr
214217
AddrOf(Span),
215218

@@ -1195,6 +1198,7 @@ impl<'tcx> SubregionOrigin<'tcx> {
11951198
CallRcvr(a) => a,
11961199
CallArg(a) => a,
11971200
CallReturn(a) => a,
1201+
Operand(a) => a,
11981202
AddrOf(a) => a,
11991203
AutoBorrow(a) => a,
12001204
SafeDestructor(a) => a,
@@ -1258,6 +1262,7 @@ impl<'tcx> Repr<'tcx> for SubregionOrigin<'tcx> {
12581262
CallRcvr(a) => format!("CallRcvr({})", a.repr(tcx)),
12591263
CallArg(a) => format!("CallArg({})", a.repr(tcx)),
12601264
CallReturn(a) => format!("CallReturn({})", a.repr(tcx)),
1265+
Operand(a) => format!("Operand({})", a.repr(tcx)),
12611266
AddrOf(a) => format!("AddrOf({})", a.repr(tcx)),
12621267
AutoBorrow(a) => format!("AutoBorrow({})", a.repr(tcx)),
12631268
SafeDestructor(a) => format!("SafeDestructor({})", a.repr(tcx)),

branches/tmp/src/librustc_typeck/check/regionck.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,20 @@ fn visit_expr(rcx: &mut Rcx, expr: &ast::Expr) {
610610
visit::walk_expr(rcx, expr);
611611
}
612612

613+
ast::ExprBinary(_, ref lhs, ref rhs) => {
614+
// If you do `x OP y`, then the types of `x` and `y` must
615+
// outlive the operation you are performing.
616+
let lhs_ty = rcx.resolve_expr_type_adjusted(&**lhs);
617+
let rhs_ty = rcx.resolve_expr_type_adjusted(&**rhs);
618+
for &ty in [lhs_ty, rhs_ty].iter() {
619+
type_must_outlive(rcx,
620+
infer::Operand(expr.span),
621+
ty,
622+
ty::ReScope(CodeExtent::from_node_id(expr.id)));
623+
}
624+
visit::walk_expr(rcx, expr);
625+
}
626+
613627
ast::ExprUnary(op, ref lhs) if has_method_map => {
614628
let implicitly_ref_args = !ast_util::is_by_value_unop(op);
615629

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2015 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+
// Regression test for issue #21422, which was related to failing to
12+
// add inference constraints that the operands of a binary operator
13+
// should outlive the binary operation itself.
14+
15+
pub struct P<'a> {
16+
_ptr: *const &'a u8,
17+
}
18+
19+
impl <'a> PartialEq for P<'a> {
20+
fn eq(&self, other: &P<'a>) -> bool {
21+
(self as *const _) == (other as *const _)
22+
}
23+
}
24+
25+
fn main() {}

0 commit comments

Comments
 (0)