From 72cf2ee1368d385fa13772fd70b7a9e748aaec6b Mon Sep 17 00:00:00 2001 From: Michael Woerister Date: Thu, 11 Jul 2013 18:00:21 +0200 Subject: [PATCH] debuginfo: Implemented trait_method branch in create_function_metadata(). --- src/librustc/middle/trans/debuginfo.rs | 56 ++++++++++++++++---------- src/test/run-pass/issue-7712.rs | 27 +++++++++++++ 2 files changed, 61 insertions(+), 22 deletions(-) create mode 100644 src/test/run-pass/issue-7712.rs diff --git a/src/librustc/middle/trans/debuginfo.rs b/src/librustc/middle/trans/debuginfo.rs index cb76d27b8b0d..9684dbd6bf97 100644 --- a/src/librustc/middle/trans/debuginfo.rs +++ b/src/librustc/middle/trans/debuginfo.rs @@ -280,30 +280,42 @@ pub fn create_function_metadata(fcx: fn_ctxt) -> DISubprogram { let fnitem = cx.tcx.items.get_copy(&fcx.id); let (ident, ret_ty, id) = match fnitem { - ast_map::node_item(ref item, _) => { - match item.node { - ast::item_fn(ast::fn_decl { output: ref ty, _}, _, _, _, _) => { - (item.ident, ty, item.id) - } - _ => fcx.ccx.sess.span_bug(item.span, - "create_function_metadata: item bound to non-function") + ast_map::node_item(ref item, _) => { + match item.node { + ast::item_fn(ast::fn_decl { output: ref ty, _}, _, _, _, _) => { + (item.ident, ty, item.id) + } + _ => fcx.ccx.sess.span_bug(item.span, + "create_function_metadata: item bound to non-function") + } } - } - ast_map::node_method(@ast::method { decl: ast::fn_decl { output: ref ty, _ }, - id: id, ident: ident, _}, _, _) => { - (ident, ty, id) - } - ast_map::node_expr(ref expr) => { - match expr.node { - ast::expr_fn_block(ref decl, _) => { - let name = gensym_name("fn"); - (name, &decl.output, expr.id) - } - _ => fcx.ccx.sess.span_bug(expr.span, - "create_function_metadata: expected an expr_fn_block here") + ast_map::node_method(@ast::method { decl: ast::fn_decl { output: ref ty, _ }, + id: id, ident: ident, _}, _, _) => { + (ident, ty, id) } - } - _ => fcx.ccx.sess.bug("create_function_metadata: unexpected sort of node") + ast_map::node_expr(ref expr) => { + match expr.node { + ast::expr_fn_block(ref decl, _) => { + let name = gensym_name("fn"); + (name, &decl.output, expr.id) + } + _ => fcx.ccx.sess.span_bug(expr.span, + "create_function_metadata: expected an expr_fn_block here") + } + } + ast_map::node_trait_method( + @ast::provided( + @ast::method { + decl: ast::fn_decl { output: ref ty, _ }, + id: id, + ident: ident, + _} + ), + _def_id, + _path) => { + (ident, ty, id) + } + _ => fcx.ccx.sess.bug("create_function_metadata: unexpected sort of node") }; match dbg_cx(cx).created_functions.find(&id) { diff --git a/src/test/run-pass/issue-7712.rs b/src/test/run-pass/issue-7712.rs new file mode 100644 index 000000000000..d4faae415d20 --- /dev/null +++ b/src/test/run-pass/issue-7712.rs @@ -0,0 +1,27 @@ +// Copyright 2013 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. + +// compile-flags:-Z debug-info + +#[allow(default_methods)]; + +pub trait TraitWithDefaultMethod { + pub fn method(self) { + () + } +} + +struct MyStruct; + +impl TraitWithDefaultMethod for MyStruct { } + +fn main() { + MyStruct.method(); +} \ No newline at end of file