Skip to content

Commit 9c1783a

Browse files
authored
Auto merge of #34658 - luqmana:34592-nested_returns, r=eddyb
Just pass in NodeId to FunctionContext::new instead of looking it up. Fixes #34592.
2 parents a7f5d8a + fd3b464 commit 9c1783a

File tree

3 files changed

+54
-10
lines changed

3 files changed

+54
-10
lines changed

src/librustc_trans/base.rs

+11-10
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ use debuginfo::{self, DebugLoc, ToDebugLoc};
7575
use declare;
7676
use expr;
7777
use glue;
78-
use inline;
7978
use machine;
8079
use machine::{llalign_of_min, llsize_of, llsize_of_real};
8180
use meth;
@@ -1407,19 +1406,17 @@ impl<'blk, 'tcx> FunctionContext<'blk, 'tcx> {
14071406
pub fn new(ccx: &'blk CrateContext<'blk, 'tcx>,
14081407
llfndecl: ValueRef,
14091408
fn_ty: FnType,
1410-
definition: Option<(Instance<'tcx>, &ty::FnSig<'tcx>, Abi)>,
1409+
definition: Option<(Instance<'tcx>, &ty::FnSig<'tcx>, Abi, ast::NodeId)>,
14111410
block_arena: &'blk TypedArena<common::BlockS<'blk, 'tcx>>)
14121411
-> FunctionContext<'blk, 'tcx> {
1413-
let (param_substs, def_id) = match definition {
1414-
Some((instance, _, _)) => {
1412+
let (param_substs, def_id, inlined_id) = match definition {
1413+
Some((instance, _, _, inlined_id)) => {
14151414
common::validate_substs(instance.substs);
1416-
(instance.substs, Some(instance.def))
1415+
(instance.substs, Some(instance.def), Some(inlined_id))
14171416
}
1418-
None => (ccx.tcx().mk_substs(Substs::empty()), None)
1417+
None => (ccx.tcx().mk_substs(Substs::empty()), None, None)
14191418
};
14201419

1421-
let inlined_did = def_id.and_then(|def_id| inline::get_local_instance(ccx, def_id));
1422-
let inlined_id = inlined_did.and_then(|id| ccx.tcx().map.as_local_node_id(id));
14231420
let local_id = def_id.and_then(|id| ccx.tcx().map.as_local_node_id(id));
14241421

14251422
debug!("FunctionContext::new({})",
@@ -1454,7 +1451,7 @@ impl<'blk, 'tcx> FunctionContext<'blk, 'tcx> {
14541451
};
14551452

14561453
let debug_context = if let (false, Some(definition)) = (no_debug, definition) {
1457-
let (instance, sig, abi) = definition;
1454+
let (instance, sig, abi, _) = definition;
14581455
debuginfo::create_function_debug_context(ccx, instance, sig, abi, llfndecl)
14591456
} else {
14601457
debuginfo::empty_function_debug_context(ccx)
@@ -1850,7 +1847,11 @@ pub fn trans_closure<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
18501847

18511848
let (arena, fcx): (TypedArena<_>, FunctionContext);
18521849
arena = TypedArena::new();
1853-
fcx = FunctionContext::new(ccx, llfndecl, fn_ty, Some((instance, sig, abi)), &arena);
1850+
fcx = FunctionContext::new(ccx,
1851+
llfndecl,
1852+
fn_ty,
1853+
Some((instance, sig, abi, inlined_id)),
1854+
&arena);
18541855

18551856
if fcx.mir.is_some() {
18561857
return mir::trans_mir(&fcx);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2016 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 Request {
12+
pub id: String,
13+
pub arg: String,
14+
}
15+
16+
pub fn decode<T>() -> Result<Request, ()> {
17+
(|| {
18+
Ok(Request {
19+
id: "hi".to_owned(),
20+
arg: match Err(()) {
21+
Ok(v) => v,
22+
Err(e) => return Err(e)
23+
},
24+
})
25+
})()
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2016 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+
// aux-build:xcrate_generic_fn_nested_return.rs
12+
13+
extern crate xcrate_generic_fn_nested_return as test;
14+
15+
pub fn main() {
16+
assert!(test::decode::<()>().is_err());
17+
}

0 commit comments

Comments
 (0)