From 96229e82985054a7b1f95732605eeeda69bf71b9 Mon Sep 17 00:00:00 2001 From: llogiq Date: Fri, 8 May 2015 13:26:45 +0200 Subject: [PATCH 1/8] fixed ICE issue #25180 --- src/librustc/middle/check_const.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/librustc/middle/check_const.rs b/src/librustc/middle/check_const.rs index 8bb83c54da8a3..195f4f4b69568 100644 --- a/src/librustc/middle/check_const.rs +++ b/src/librustc/middle/check_const.rs @@ -251,9 +251,13 @@ impl<'a, 'tcx, 'v> Visitor<'v> for CheckCrateVisitor<'a, 'tcx> { b: &'v ast::Block, s: Span, fn_id: ast::NodeId) { - assert!(self.mode == Mode::Var); - self.with_euv(Some(fn_id), |euv| euv.walk_fn(fd, b)); - visit::walk_fn(self, fk, fd, b, s); + let (old_mode, old_qualif) = (self.mode, self.qualif); + self.mode = Mode::Var; + self.qualif = ConstQualif::empty(); + self.with_euv(Some(fn_id), |euv| euv.walk_fn(fd, b)); + visit::walk_fn(self, fk, fd, b, s); + self.mode = old_mode; + self.qualif = old_qualif; } fn visit_pat(&mut self, p: &ast::Pat) { @@ -275,7 +279,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for CheckCrateVisitor<'a, 'tcx> { let node_ty = ty::node_id_to_type(self.tcx, ex.id); check_expr(self, ex, node_ty); - + // Special-case some expressions to avoid certain flags bubbling up. match ex.node { ast::ExprCall(ref callee, ref args) => { From 29daa29981e89ba7f71dcbba06166f8c54f4682d Mon Sep 17 00:00:00 2001 From: llogiq Date: Fri, 8 May 2015 13:56:14 +0200 Subject: [PATCH 2/8] formatting correction --- src/librustc/middle/check_const.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/librustc/middle/check_const.rs b/src/librustc/middle/check_const.rs index 195f4f4b69568..2322b97de1487 100644 --- a/src/librustc/middle/check_const.rs +++ b/src/librustc/middle/check_const.rs @@ -254,10 +254,10 @@ impl<'a, 'tcx, 'v> Visitor<'v> for CheckCrateVisitor<'a, 'tcx> { let (old_mode, old_qualif) = (self.mode, self.qualif); self.mode = Mode::Var; self.qualif = ConstQualif::empty(); - self.with_euv(Some(fn_id), |euv| euv.walk_fn(fd, b)); - visit::walk_fn(self, fk, fd, b, s); - self.mode = old_mode; - self.qualif = old_qualif; + self.with_euv(Some(fn_id), |euv| euv.walk_fn(fd, b)); + visit::walk_fn(self, fk, fd, b, s); + self.mode = old_mode; + self.qualif = old_qualif; } fn visit_pat(&mut self, p: &ast::Pat) { @@ -279,7 +279,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for CheckCrateVisitor<'a, 'tcx> { let node_ty = ty::node_id_to_type(self.tcx, ex.id); check_expr(self, ex, node_ty); - + // Special-case some expressions to avoid certain flags bubbling up. match ex.node { ast::ExprCall(ref callee, ref args) => { From 1434715550c372f83ab3a138d66674d5b303d429 Mon Sep 17 00:00:00 2001 From: llogiq Date: Fri, 8 May 2015 17:07:03 +0200 Subject: [PATCH 3/8] crossed the i-s and dotted the t-s ;-) Also added a run-pass test and removed the with_mode copy, thanks to eddyb --- src/librustc/middle/check_const.rs | 8 ++------ src/test/run-pass/issue-25180.rs | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 6 deletions(-) create mode 100644 src/test/run-pass/issue-25180.rs diff --git a/src/librustc/middle/check_const.rs b/src/librustc/middle/check_const.rs index 2322b97de1487..d48d2abc660f6 100644 --- a/src/librustc/middle/check_const.rs +++ b/src/librustc/middle/check_const.rs @@ -251,13 +251,9 @@ impl<'a, 'tcx, 'v> Visitor<'v> for CheckCrateVisitor<'a, 'tcx> { b: &'v ast::Block, s: Span, fn_id: ast::NodeId) { - let (old_mode, old_qualif) = (self.mode, self.qualif); - self.mode = Mode::Var; - self.qualif = ConstQualif::empty(); - self.with_euv(Some(fn_id), |euv| euv.walk_fn(fd, b)); + self.with_mode(Mode::Var, |v| v.with_euv(Some(fn_id), + |euv| euv.walk_fn(fd, b))); visit::walk_fn(self, fk, fd, b, s); - self.mode = old_mode; - self.qualif = old_qualif; } fn visit_pat(&mut self, p: &ast::Pat) { diff --git a/src/test/run-pass/issue-25180.rs b/src/test/run-pass/issue-25180.rs new file mode 100644 index 0000000000000..3955e451639fd --- /dev/null +++ b/src/test/run-pass/issue-25180.rs @@ -0,0 +1,16 @@ +// Copyright 2015 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// pretty-expanded FIXME #25180 + +const x: &'static Fn() = &|| println!("ICE here"); + +fn main() {} + From ca5c694f439fdb86bd7314b7daaa56994e33c761 Mon Sep 17 00:00:00 2001 From: llogiq Date: Sun, 10 May 2015 04:39:51 +0200 Subject: [PATCH 4/8] Pulled walk_fn() into Var mode, extended test --- src/librustc/middle/check_const.rs | 7 ++++--- src/test/run-pass/issue-25180.rs | 4 +++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/librustc/middle/check_const.rs b/src/librustc/middle/check_const.rs index d48d2abc660f6..89a93f990df63 100644 --- a/src/librustc/middle/check_const.rs +++ b/src/librustc/middle/check_const.rs @@ -251,9 +251,10 @@ impl<'a, 'tcx, 'v> Visitor<'v> for CheckCrateVisitor<'a, 'tcx> { b: &'v ast::Block, s: Span, fn_id: ast::NodeId) { - self.with_mode(Mode::Var, |v| v.with_euv(Some(fn_id), - |euv| euv.walk_fn(fd, b))); - visit::walk_fn(self, fk, fd, b, s); + self.with_mode(Mode::Var, |v| { + v.with_euv(Some(fn_id), |euv| euv.walk_fn(fd, b)); + visit::walk_fn(v, fk, fd, b, s); + }) } fn visit_pat(&mut self, p: &ast::Pat) { diff --git a/src/test/run-pass/issue-25180.rs b/src/test/run-pass/issue-25180.rs index 3955e451639fd..d63c50192426b 100644 --- a/src/test/run-pass/issue-25180.rs +++ b/src/test/run-pass/issue-25180.rs @@ -12,5 +12,7 @@ const x: &'static Fn() = &|| println!("ICE here"); -fn main() {} +fn main() { + x() +} From 6e19cfacf42e2de001de4c2133a4321b5286f523 Mon Sep 17 00:00:00 2001 From: llogiq Date: Sun, 10 May 2015 11:57:52 +0200 Subject: [PATCH 5/8] more tests --- src/test/run-pass/issue-25180.rs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/test/run-pass/issue-25180.rs b/src/test/run-pass/issue-25180.rs index d63c50192426b..0ad5fd87e9566 100644 --- a/src/test/run-pass/issue-25180.rs +++ b/src/test/run-pass/issue-25180.rs @@ -10,9 +10,21 @@ // pretty-expanded FIXME #25180 -const x: &'static Fn() = &|| println!("ICE here"); +const empty: &'static Fn() = &|| println!("ICE here"); -fn main() { - x() +const one_argument: &'static Fn(u32) = &|y| println("{}", y); + +const plus_21: &'static Fn(u32) -> u32 = |y| y + 21; + +const multi_and_local: &'static Fn(u32, u32) -> u32 = |x, y| { + let tmp = x + y; + tmp * 2; +}; + +pub fn main() { + empty(); + one_argument(42); + assert!(plus_21(21) == 42); + assert!(multi_and_local(1, 2) == 6); } From a18ce4d47979260001e9be0a92f887e3abd4eb88 Mon Sep 17 00:00:00 2001 From: llogiq Date: Sun, 10 May 2015 12:30:06 +0200 Subject: [PATCH 6/8] fixed errors in test code --- src/test/run-pass/issue-25180.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/test/run-pass/issue-25180.rs b/src/test/run-pass/issue-25180.rs index 0ad5fd87e9566..9d2d51264e6fa 100644 --- a/src/test/run-pass/issue-25180.rs +++ b/src/test/run-pass/issue-25180.rs @@ -10,21 +10,21 @@ // pretty-expanded FIXME #25180 -const empty: &'static Fn() = &|| println!("ICE here"); +const EMPTY: &'static Fn() = &|| println!("ICE here"); -const one_argument: &'static Fn(u32) = &|y| println("{}", y); +const ONE_ARGUMENT: &'static Fn(u32) = &|y| println!("{}", y); -const plus_21: &'static Fn(u32) -> u32 = |y| y + 21; +const PLUS_21: &'static (Fn(u32) -> u32) = &|y| y + 21; -const multi_and_local: &'static Fn(u32, u32) -> u32 = |x, y| { +const MULTI_AND_LOCAL: &'static (Fn(u32, u32) -> u32) = &|x, y| { let tmp = x + y; - tmp * 2; + tmp * 2 }; pub fn main() { - empty(); - one_argument(42); - assert!(plus_21(21) == 42); - assert!(multi_and_local(1, 2) == 6); + EMPTY(); + ONE_ARGUMENT(42); + assert!(PLUS_21(21) == 42); + assert!(MULTI_AND_LOCAL(1, 2) == 6); } From 4eec41a789d1274e77a53205985a0bb223e53e49 Mon Sep 17 00:00:00 2001 From: llogiq Date: Tue, 12 May 2015 10:19:52 +0200 Subject: [PATCH 7/8] Removed println! from test --- src/test/run-pass/issue-25180.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/run-pass/issue-25180.rs b/src/test/run-pass/issue-25180.rs index 9d2d51264e6fa..8cc47b497e570 100644 --- a/src/test/run-pass/issue-25180.rs +++ b/src/test/run-pass/issue-25180.rs @@ -10,9 +10,9 @@ // pretty-expanded FIXME #25180 -const EMPTY: &'static Fn() = &|| println!("ICE here"); +const EMPTY: &'static Fn() = &|| (); -const ONE_ARGUMENT: &'static Fn(u32) = &|y| println!("{}", y); +const ONE_ARGUMENT: &'static Fn(u32) = &|y| assert!(y == 42); const PLUS_21: &'static (Fn(u32) -> u32) = &|y| y + 21; From 3715898a6a557cb926557ad7be19df21614a47c6 Mon Sep 17 00:00:00 2001 From: llogiq Date: Tue, 12 May 2015 18:20:36 +0200 Subject: [PATCH 8/8] added feature declaration --- src/test/run-pass/issue-25180.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/run-pass/issue-25180.rs b/src/test/run-pass/issue-25180.rs index 8cc47b497e570..dbfcd958ab875 100644 --- a/src/test/run-pass/issue-25180.rs +++ b/src/test/run-pass/issue-25180.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// pretty-expanded FIXME #25180 +#![feature(std_misc)] const EMPTY: &'static Fn() = &|| ();