Skip to content

Commit b758a37

Browse files
committed
Auto merge of #25209 - llogiq:master, r=eddyb
According to @eddyb – and my tests – the following gets rid of the ICE in issue #25180.
2 parents c44d84d + a18ce4d commit b758a37

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

src/librustc/middle/check_const.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,10 @@ impl<'a, 'tcx, 'v> Visitor<'v> for CheckCrateVisitor<'a, 'tcx> {
251251
b: &'v ast::Block,
252252
s: Span,
253253
fn_id: ast::NodeId) {
254-
assert!(self.mode == Mode::Var);
255-
self.with_euv(Some(fn_id), |euv| euv.walk_fn(fd, b));
256-
visit::walk_fn(self, fk, fd, b, s);
254+
self.with_mode(Mode::Var, |v| {
255+
v.with_euv(Some(fn_id), |euv| euv.walk_fn(fd, b));
256+
visit::walk_fn(v, fk, fd, b, s);
257+
})
257258
}
258259

259260
fn visit_pat(&mut self, p: &ast::Pat) {

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
// pretty-expanded FIXME #25180
12+
13+
const EMPTY: &'static Fn() = &|| println!("ICE here");
14+
15+
const ONE_ARGUMENT: &'static Fn(u32) = &|y| println!("{}", y);
16+
17+
const PLUS_21: &'static (Fn(u32) -> u32) = &|y| y + 21;
18+
19+
const MULTI_AND_LOCAL: &'static (Fn(u32, u32) -> u32) = &|x, y| {
20+
let tmp = x + y;
21+
tmp * 2
22+
};
23+
24+
pub fn main() {
25+
EMPTY();
26+
ONE_ARGUMENT(42);
27+
assert!(PLUS_21(21) == 42);
28+
assert!(MULTI_AND_LOCAL(1, 2) == 6);
29+
}
30+

0 commit comments

Comments
 (0)