-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #45297 - matthewjasper:associated-item-namespaces, r=pe…
…trochenkov Check namespaces when resolving associated items in typeck Closes #35600 Closes #44247 Fixes a "cannot move a value of type..." error in the same case as #44247 but with the associated items swapped.
- Loading branch information
Showing
10 changed files
with
127 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright 2017 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. | ||
|
||
use rustc::hir; | ||
use rustc::ty; | ||
|
||
// Whether an item exists in the type or value namespace. | ||
#[derive(Copy, Clone, PartialEq, Eq, Debug)] | ||
pub enum Namespace { | ||
Type, | ||
Value, | ||
} | ||
|
||
impl From<ty::AssociatedKind> for Namespace { | ||
fn from(a_kind: ty::AssociatedKind) -> Self { | ||
match a_kind { | ||
ty::AssociatedKind::Type => Namespace::Type, | ||
ty::AssociatedKind::Const | | ||
ty::AssociatedKind::Method => Namespace::Value, | ||
} | ||
} | ||
} | ||
|
||
impl<'a> From <&'a hir::ImplItemKind> for Namespace { | ||
fn from(impl_kind: &'a hir::ImplItemKind) -> Self { | ||
match *impl_kind { | ||
hir::ImplItemKind::Type(..) => Namespace::Type, | ||
hir::ImplItemKind::Const(..) | | ||
hir::ImplItemKind::Method(..) => Namespace::Value, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright 2017 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. | ||
|
||
trait Foo { | ||
type bar; | ||
fn bar(); | ||
} | ||
|
||
impl Foo for () { | ||
type bar = (); | ||
fn bar() {} | ||
} | ||
|
||
fn main() { | ||
let x: <() as Foo>::bar = (); | ||
<()>::bar(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright 2017 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. | ||
|
||
trait T { | ||
type X; | ||
const X: Self::X; | ||
} | ||
fn foo<X: T>() { | ||
let _: X::X = X::X; | ||
} | ||
|
||
trait S { | ||
const X: Self::X; | ||
type X; | ||
} | ||
fn bar<X: S>() { | ||
let _: X::X = X::X; | ||
} | ||
|
||
fn main() {} |