forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Only run for `QPath::Resolved` with `Some` self parameter (`<X as Y>::T`) - Fall back to the previous behavior if the path can't be resolved - Show what the behavior is if the type can't be normalized - Run `resolve_vars_if_possible` It's not clear whether or not this is necessary. See rust-lang#77616 for more context. - Add a test for cross-crate re-exports - Use the same code for both `hir::Ty` and `Ty`
- Loading branch information
Showing
3 changed files
with
120 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#![crate_name = "inner"] | ||
pub trait MyTrait { | ||
type Y; | ||
} | ||
|
||
impl MyTrait for u32 { | ||
type Y = i32; | ||
} | ||
|
||
pub fn foo() -> <u32 as MyTrait>::Y { | ||
0 | ||
} |
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,63 @@ | ||
// ignore-tidy-linelength | ||
// aux-build:normalize-assoc-item.rs | ||
// build-aux-docs | ||
|
||
pub trait Trait { | ||
type X; | ||
} | ||
|
||
impl Trait for usize { | ||
type X = isize; | ||
} | ||
|
||
// @has 'normalize_assoc_item/fn.f.html' '//pre[@class="rust fn"]' 'pub fn f() -> isize' | ||
pub fn f() -> <usize as Trait>::X { | ||
0 | ||
} | ||
|
||
pub struct S { | ||
// @has 'normalize_assoc_item/struct.S.html' '//span[@id="structfield.box_me_up"]' 'box_me_up: Box<S>' | ||
pub box_me_up: <S as Trait>::X, | ||
// @has 'normalize_assoc_item/struct.S.html' '//span[@id="structfield.generic"]' 'generic: (usize, isize)' | ||
pub generic: <Generic<usize> as Trait>::X, | ||
} | ||
|
||
impl Trait for S { | ||
type X = Box<S>; | ||
} | ||
|
||
pub struct Generic<Inner>(Inner); | ||
|
||
impl<Inner: Trait> Trait for Generic<Inner> { | ||
type X = (Inner, Inner::X); | ||
} | ||
|
||
// These can't be normalized because they depend on a generic parameter. | ||
// However the user can choose whether the text should be displayed as `Inner::X` or `<Inner as Trait>::X`. | ||
|
||
// @has 'normalize_assoc_item/struct.Unknown.html' '//pre[@class="rust struct"]' 'pub struct Unknown<Inner: Trait>(pub <Inner as Trait>::X);' | ||
pub struct Unknown<Inner: Trait>(pub <Inner as Trait>::X); | ||
|
||
// @has 'normalize_assoc_item/struct.Unknown2.html' '//pre[@class="rust struct"]' 'pub struct Unknown2<Inner: Trait>(pub Inner::X);' | ||
pub struct Unknown2<Inner: Trait>(pub Inner::X); | ||
|
||
trait Lifetimes<'a> { | ||
type Y; | ||
} | ||
|
||
impl<'a> Lifetimes<'a> for usize { | ||
type Y = &'a isize; | ||
} | ||
|
||
// @has 'normalize_assoc_item/fn.g.html' '//pre[@class="rust fn"]' "pub fn g() -> &isize" | ||
pub fn g() -> <usize as Lifetimes<'static>>::Y { | ||
&0 | ||
} | ||
|
||
// @has 'normalize_assoc_item/constant.A.html' '//pre[@class="rust const"]' "pub const A: &isize" | ||
pub const A: <usize as Lifetimes<'static>>::Y = &0; | ||
|
||
// test cross-crate re-exports | ||
extern crate inner; | ||
// @has 'normalize_assoc_item/fn.foo.html' '//pre[@class="rust fn"]' "pub fn foo() -> i32" | ||
pub use inner::foo; |