]> git.lizzy.rs Git - rust.git/commitdiff
Make `trait_of_item` return None for non associated items
authorShotaro Yamada <sinkuu@sinkuu.xyz>
Mon, 23 Apr 2018 15:31:13 +0000 (00:31 +0900)
committerShotaro Yamada <sinkuu@sinkuu.xyz>
Sat, 28 Apr 2018 01:49:45 +0000 (10:49 +0900)
It have returned `Some` for constants in a trait definition,
and `Instance::resolve` called `tcx.associated_item` for them,
causing ICE.

src/librustc_metadata/decoder.rs
src/test/run-pass/auxiliary/issue-48984-aux.rs [new file with mode: 0644]
src/test/run-pass/issue-48984.rs [new file with mode: 0644]

index 0147e8dc6075948f38e20a8fd0ac72f6e7726dc8..07a1da429431cadd846a88b9753247f9224cf38f 100644 (file)
@@ -977,7 +977,13 @@ pub fn get_implementations_for_trait(&self,
     }
 
     pub fn get_trait_of_item(&self, id: DefIndex) -> Option<DefId> {
-        self.def_key(id).parent.and_then(|parent_index| {
+        let def_key = self.def_key(id);
+        match def_key.disambiguated_data.data {
+            DefPathData::TypeNs(..) | DefPathData::ValueNs(..) => (),
+            // Not an associated item
+            _ => return None,
+        }
+        def_key.parent.and_then(|parent_index| {
             match self.entry(parent_index).kind {
                 EntryKind::Trait(_) => Some(self.local_def_id(parent_index)),
                 _ => None,
diff --git a/src/test/run-pass/auxiliary/issue-48984-aux.rs b/src/test/run-pass/auxiliary/issue-48984-aux.rs
new file mode 100644 (file)
index 0000000..6290279
--- /dev/null
@@ -0,0 +1,16 @@
+// Copyright 2018 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![crate_type = "lib"]
+#![crate_name = "issue48984aux"]
+
+pub trait Foo { type Item; }
+
+pub trait Bar: Foo<Item=[u8;1]> {  }
diff --git a/src/test/run-pass/issue-48984.rs b/src/test/run-pass/issue-48984.rs
new file mode 100644 (file)
index 0000000..227ad4e
--- /dev/null
@@ -0,0 +1,17 @@
+// Copyright 2018 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// aux-build:issue-48984-aux.rs
+extern crate issue48984aux;
+use issue48984aux::Bar;
+
+fn do_thing<T: Bar>() { }
+
+fn main() { }