Skip to content

Commit 54faa67

Browse files
committed
rustc: support impl's in PrintCx::parameterized.
1 parent f7d5593 commit 54faa67

12 files changed

+34
-18
lines changed

src/librustc/util/ppaux.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,22 @@ impl PrintCx<'a, 'gcx, 'tcx> {
352352

353353
write!(f, "::{}", key.disambiguated_data.data.as_interned_str())?;
354354
} else {
355+
// Try to print `impl`s more like how you'd refer to their associated items.
356+
if let DefPathData::Impl = key.disambiguated_data.data {
357+
if let Some(trait_ref) = self.tcx.impl_trait_ref(def_id) {
358+
// HACK(eddyb) this is in lieu of more specific disambiguation.
359+
print!(f, self, write("{}", self.tcx.item_path_str(def_id)))?;
360+
361+
let trait_ref = trait_ref.subst(self.tcx, substs);
362+
print!(f, self, print_debug(trait_ref))?;
363+
} else {
364+
let self_ty = self.tcx.type_of(def_id).subst(self.tcx, substs);
365+
// FIXME(eddyb) omit the <> where possible.
366+
print!(f, self, write("<"), print(self_ty), write(">"))?;
367+
}
368+
return Ok(());
369+
}
370+
355371
print!(f, self, write("{}", self.tcx.item_path_str(def_id)))?;
356372
}
357373

src/test/ui/hygiene/impl_items.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ mod foo {
99
}
1010

1111
pub macro m() {
12-
let _: () = S.f(); //~ ERROR type `for<'r> fn(&'r foo::S) {foo::S::f}` is private
12+
let _: () = S.f(); //~ ERROR type `for<'r> fn(&'r foo::S) {<foo::S>::f}` is private
1313
}
1414
}
1515

src/test/ui/hygiene/impl_items.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
error: type `for<'r> fn(&'r foo::S) {foo::S::f}` is private
1+
error: type `for<'r> fn(&'r foo::S) {<foo::S>::f}` is private
22
--> $DIR/impl_items.rs:12:23
33
|
4-
LL | let _: () = S.f(); //~ ERROR type `for<'r> fn(&'r foo::S) {foo::S::f}` is private
4+
LL | let _: () = S.f(); //~ ERROR type `for<'r> fn(&'r foo::S) {<foo::S>::f}` is private
55
| ^
66
...
77
LL | foo::m!();

src/test/ui/issues/issue-22638.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ struct D (Box<A>);
5050

5151
impl D {
5252
pub fn matches<F: Fn()>(&self, f: &F) {
53-
//~^ ERROR reached the type-length limit while instantiating `D::matches::<[closure
53+
//~^ ERROR reached the type-length limit while instantiating `<D>::matches::<[closure
5454
let &D(ref a) = self;
5555
a.matches(f)
5656
}

src/test/ui/issues/issue-22638.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error: reached the type-length limit while instantiating `D::matches::$CLOSURE`
1+
error: reached the type-length limit while instantiating `<D>::matches::$CLOSURE`
22
--> $DIR/issue-22638.rs:52:5
33
|
44
LL | / pub fn matches<F: Fn()>(&self, f: &F) {
5-
LL | | //~^ ERROR reached the type-length limit while instantiating `D::matches::<[closure
5+
LL | | //~^ ERROR reached the type-length limit while instantiating `<D>::matches::<[closure
66
LL | | let &D(ref a) = self;
77
LL | | a.matches(f)
88
LL | | }

src/test/ui/issues/issue-24322.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | let x: &fn(&B) -> u32 = &B::func; //~ ERROR mismatched types
55
| ^^^^^^^^ expected fn pointer, found fn item
66
|
77
= note: expected type `&for<'r> fn(&'r B) -> u32`
8-
found type `&for<'r> fn(&'r B) -> u32 {B::func}`
8+
found type `&for<'r> fn(&'r B) -> u32 {<B>::func}`
99

1010
error: aborting due to previous error
1111

src/test/ui/issues/issue-29124.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ fn func() -> Ret {
1313

1414
fn main() {
1515
Obj::func.x();
16-
//~^ ERROR no method named `x` found for type `fn() -> Ret {Obj::func}` in the current scope
16+
//~^ ERROR no method named `x` found for type `fn() -> Ret {<Obj>::func}` in the current scope
1717
func.x();
1818
//~^ ERROR no method named `x` found for type `fn() -> Ret {func}` in the current scope
1919
}

src/test/ui/issues/issue-29124.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0599]: no method named `x` found for type `fn() -> Ret {Obj::func}` in the current scope
1+
error[E0599]: no method named `x` found for type `fn() -> Ret {<Obj>::func}` in the current scope
22
--> $DIR/issue-29124.rs:15:15
33
|
44
LL | Obj::func.x();

src/test/ui/issues/issue-39559-2.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ error[E0080]: evaluation of constant value failed
88
--> $DIR/issue-39559-2.rs:14:24
99
|
1010
LL | let array: [usize; Dim3::dim()]
11-
| ^^^^^^^^^^^ calling non-const function `<Dim3 as Dim>::dim`
11+
| ^^^^^^^^^^^ calling non-const function `<Dim3 as Dim><Dim3 as Dim>::dim`
1212

1313
error[E0015]: calls in constants are limited to constant functions, tuple structs and tuple variants
1414
--> $DIR/issue-39559-2.rs:17:15
@@ -20,7 +20,7 @@ error[E0080]: evaluation of constant value failed
2020
--> $DIR/issue-39559-2.rs:17:15
2121
|
2222
LL | = [0; Dim3::dim()];
23-
| ^^^^^^^^^^^ calling non-const function `<Dim3 as Dim>::dim`
23+
| ^^^^^^^^^^^ calling non-const function `<Dim3 as Dim><Dim3 as Dim>::dim`
2424

2525
error: aborting due to 4 previous errors
2626

src/test/ui/privacy/associated-item-privacy-inherent.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ mod priv_nominal {
1111

1212
pub macro mac() {
1313
let value = Pub::method;
14-
//~^ ERROR type `for<'r> fn(&'r priv_nominal::Pub) {priv_nominal::Pub::method}` is private
14+
//~^ ERROR type `for<'r> fn(&'r priv_nominal::Pub) {<priv_nominal::Pub>::method}` is private
1515
value;
16-
//~^ ERROR type `for<'r> fn(&'r priv_nominal::Pub) {priv_nominal::Pub::method}` is private
16+
//~^ ERROR type `for<'r> fn(&'r priv_nominal::Pub) {<priv_nominal::Pub>::method}` is private
1717
Pub.method();
18-
//~^ ERROR type `for<'r> fn(&'r priv_nominal::Pub) {priv_nominal::Pub::method}` is private
18+
//~^ ERROR type `for<'r> fn(&'r priv_nominal::Pub) {<priv_nominal::Pub>::method}` is private
1919
Pub::CONST;
2020
//~^ ERROR associated constant `CONST` is private
2121
// let _: Pub::AssocTy;

0 commit comments

Comments
 (0)