Skip to content

Commit ed2a11d

Browse files
committed
require a method callee's type to outlive the call
This rather crucial requirement was not checked. In most cases, that didn't cause any trouble because the argument types are required to outlive the call and are subtypes of a subformula of the callee type. However, binary ops are taken by ref only indirectly, without it being marked in the argument types, which led to the argument types not being constrained anywhere causing spurious errors (as these are basically unconstrainable, I don't think this change can break code). Of course, the old way was also incorrent with contravariance, but that is still unsound for other reasons. This also improves rustc::front to get RUST_LOG to *somewhat* work. Fixes #28999
1 parent 843e528 commit ed2a11d

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

src/librustc/front/map/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,10 @@ impl<'ast> Map<'ast> {
527527
NodeTraitItem(ti) => PathName(ti.name),
528528
NodeVariant(v) => PathName(v.node.name),
529529
NodeLifetime(lt) => PathName(lt.name),
530+
NodeTyParam(tp) => PathName(tp.name),
531+
NodeLocal(&Pat { node: PatIdent(_,l,_), .. }) => {
532+
PathName(l.node.name)
533+
},
530534
_ => panic!("no path elem for {:?}", node)
531535
}
532536
}
@@ -987,4 +991,3 @@ fn node_id_to_string(map: &Map, id: NodeId, include_id: bool) -> String {
987991
}
988992
}
989993
}
990-

src/librustc_typeck/check/regionck.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,8 @@ fn visit_expr(rcx: &mut Rcx, expr: &hir::Expr) {
592592
};
593593

594594
substs_wf_in_scope(rcx, origin, &callee.substs, expr.span, expr_region);
595+
type_must_outlive(rcx, infer::ExprTypeIsNotInScope(callee.ty, expr.span),
596+
callee.ty, expr_region);
595597
}
596598

597599
// Check any autoderefs or autorefs that appear.
@@ -664,6 +666,8 @@ fn visit_expr(rcx: &mut Rcx, expr: &hir::Expr) {
664666
}
665667
}
666668

669+
debug!("regionck::visit_expr(e={:?}, repeating_scope={}) - visiting subexprs",
670+
expr, rcx.repeating_scope);
667671
match expr.node {
668672
hir::ExprPath(..) => {
669673
rcx.fcx.opt_node_ty_substs(expr.id, |item_substs| {

src/test/run-pass/issue-28999.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
pub struct Xyz<'a, V> {
12+
pub v: (V, &'a u32),
13+
}
14+
15+
pub fn eq<'a, 's, 't, V>(this: &'s Xyz<'a, V>, other: &'t Xyz<'a, V>) -> bool
16+
where V: PartialEq {
17+
this.v == other.v
18+
}
19+
20+
fn main() {}

0 commit comments

Comments
 (0)