From 87405751ae4517b4258bdd5b07077d81bdc1287e Mon Sep 17 00:00:00 2001 From: Seo Sanghyeon Date: Sat, 12 Dec 2015 00:01:08 +0900 Subject: [PATCH] Include type name in symbol for methods --- src/librustc/front/map/collector.rs | 2 +- src/librustc/front/map/definitions.rs | 7 ++----- .../symbols-include-type-name/Makefile | 9 +++++++++ .../run-make/symbols-include-type-name/lib.rs | 19 +++++++++++++++++++ 4 files changed, 31 insertions(+), 6 deletions(-) create mode 100644 src/test/run-make/symbols-include-type-name/Makefile create mode 100644 src/test/run-make/symbols-include-type-name/lib.rs diff --git a/src/librustc/front/map/collector.rs b/src/librustc/front/map/collector.rs index 17f75074ef230..e85b0ec77cbbd 100644 --- a/src/librustc/front/map/collector.rs +++ b/src/librustc/front/map/collector.rs @@ -122,7 +122,7 @@ impl<'ast> Visitor<'ast> for NodeCollector<'ast> { // Pick the def data. This need not be unique, but the more // information we encapsulate into let def_data = match i.node { - ItemDefaultImpl(..) | ItemImpl(..) => DefPathData::Impl, + ItemDefaultImpl(..) | ItemImpl(..) => DefPathData::Impl(i.name), ItemEnum(..) | ItemStruct(..) | ItemTrait(..) => DefPathData::Type(i.name), ItemExternCrate(..) | ItemMod(..) => DefPathData::Mod(i.name), ItemStatic(..) | ItemConst(..) | ItemFn(..) => DefPathData::Value(i.name), diff --git a/src/librustc/front/map/definitions.rs b/src/librustc/front/map/definitions.rs index 0f0d59e70b0b8..e903fcf6a56c2 100644 --- a/src/librustc/front/map/definitions.rs +++ b/src/librustc/front/map/definitions.rs @@ -73,7 +73,7 @@ pub enum DefPathData { Misc, // Different kinds of items and item-like things: - Impl, + Impl(ast::Name), Type(ast::Name), Mod(ast::Name), Value(ast::Name), @@ -177,6 +177,7 @@ impl DefPathData { pub fn as_interned_str(&self) -> InternedString { use self::DefPathData::*; match *self { + Impl(name) | Type(name) | Mod(name) | Value(name) | @@ -212,10 +213,6 @@ impl DefPathData { InternedString::new("?") } - Impl => { - InternedString::new("") - } - ClosureExpr => { InternedString::new("") } diff --git a/src/test/run-make/symbols-include-type-name/Makefile b/src/test/run-make/symbols-include-type-name/Makefile new file mode 100644 index 0000000000000..1add39e0cc35b --- /dev/null +++ b/src/test/run-make/symbols-include-type-name/Makefile @@ -0,0 +1,9 @@ +-include ../tools.mk + +# Check that symbol names for methods include type names, instead of . + +OUT=$(TMPDIR)/lib.s + +all: + $(RUSTC) --crate-type staticlib --emit asm lib.rs + grep Def $(OUT) diff --git a/src/test/run-make/symbols-include-type-name/lib.rs b/src/test/run-make/symbols-include-type-name/lib.rs new file mode 100644 index 0000000000000..1c478ed2598e4 --- /dev/null +++ b/src/test/run-make/symbols-include-type-name/lib.rs @@ -0,0 +1,19 @@ +// 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. + +pub struct Def { + pub id: i32, +} + +impl Def { + pub fn new(id: i32) -> Def { + Def { id: id } + } +}