From b9bd2a60085acfc046365bab4cfa009cb6b9b773 Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Fri, 19 Oct 2018 12:46:16 +0200 Subject: [PATCH 1/2] Impl items have generics --- src/librustc/util/ppaux.rs | 14 +++----------- src/librustc_mir/const_eval.rs | 7 +++++++ 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/librustc/util/ppaux.rs b/src/librustc/util/ppaux.rs index 709b8445265..abdd7fd8d40 100644 --- a/src/librustc/util/ppaux.rs +++ b/src/librustc/util/ppaux.rs @@ -251,25 +251,17 @@ impl PrintContext { fn parameterized(&mut self, f: &mut F, substs: &subst::Substs<'_>, - mut did: DefId, + did: DefId, projections: &[ty::ProjectionPredicate<'_>]) -> fmt::Result { let key = ty::tls::with(|tcx| tcx.def_key(did)); - let mut item_name = if let Some(name) = key.disambiguated_data.data.get_opt_name() { - Some(name) - } else { - did.index = key.parent.unwrap_or_else( - || bug!("finding type for {:?}, encountered def-id {:?} with no parent", - did, did)); - self.parameterized(f, substs, did, projections)?; - return write!(f, "::{}", key.disambiguated_data.data.as_interned_str()); - }; let verbose = self.is_verbose; let mut num_supplied_defaults = 0; let mut has_self = false; let mut own_counts: GenericParamCount = Default::default(); let mut is_value_path = false; + let mut item_name = Some(key.disambiguated_data.data.as_interned_str()); let fn_trait_kind = ty::tls::with(|tcx| { // Unfortunately, some kinds of items (e.g., closures) don't have // generics. So walk back up the find the closest parent that DOES @@ -282,6 +274,7 @@ impl PrintContext { DefPathData::AssocTypeInImpl(_) | DefPathData::AssocExistentialInImpl(_) | DefPathData::Trait(_) | + DefPathData::Impl | DefPathData::TypeNs(_) => { break; } @@ -292,7 +285,6 @@ impl PrintContext { } DefPathData::CrateRoot | DefPathData::Misc | - DefPathData::Impl | DefPathData::Module(_) | DefPathData::MacroDef(_) | DefPathData::ClosureExpr | diff --git a/src/librustc_mir/const_eval.rs b/src/librustc_mir/const_eval.rs index 362fbc4b135..d9200170428 100644 --- a/src/librustc_mir/const_eval.rs +++ b/src/librustc_mir/const_eval.rs @@ -612,6 +612,13 @@ pub fn const_eval_raw_provider<'a, 'tcx>( other => return other, } } + // the first trace is for replicating an ice + // There's no tracking issue, but the next two lines concatenated link to the discussion on + // zulip. It's not really possible to test this, because it doesn't show up in diagnostics + // or MIR. + // https://rust-lang.zulipchat.com/#narrow/stream/146212-t-compiler.2Fconst-eval/ + // subject/anon_const_instance_printing/near/135980032 + trace!("const eval: {}", key.value.instance); trace!("const eval: {:?}", key); let cid = key.value; From 5a48f20bd9eacbca5f0e87022605791cd651935c Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Fri, 19 Oct 2018 14:24:29 +0200 Subject: [PATCH 2/2] Update tests --- src/test/mir-opt/end_region_4.rs | 2 +- src/test/mir-opt/end_region_5.rs | 2 +- src/test/mir-opt/end_region_6.rs | 2 +- src/test/mir-opt/end_region_7.rs | 2 +- src/test/mir-opt/end_region_8.rs | 2 +- src/test/mir-opt/end_region_destruction_extents_1.rs | 8 ++++---- src/test/mir-opt/packed-struct-drop-aligned.rs | 2 +- src/test/ui/issues/issue-21554.stderr | 2 +- src/test/ui/issues/issue-35241.stderr | 2 +- src/test/ui/namespace/namespace-mix.stderr | 8 ++++---- src/test/ui/privacy/private-inferred-type-3.rs | 4 ++-- src/test/ui/privacy/private-inferred-type-3.stderr | 4 ++-- src/test/ui/privacy/private-inferred-type.rs | 4 ++-- src/test/ui/privacy/private-inferred-type.stderr | 4 ++-- 14 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/test/mir-opt/end_region_4.rs b/src/test/mir-opt/end_region_4.rs index 359ed07a9c0..3d15f20bd05 100644 --- a/src/test/mir-opt/end_region_4.rs +++ b/src/test/mir-opt/end_region_4.rs @@ -44,7 +44,7 @@ fn foo(i: i32) { // let mut _5: i32; // bb0: { // StorageLive(_1); -// _1 = D::{{constructor}}(const 0i32,); +// _1 = D(const 0i32,); // FakeRead(ForLet, _1); // StorageLive(_2); // _2 = const 0i32; diff --git a/src/test/mir-opt/end_region_5.rs b/src/test/mir-opt/end_region_5.rs index 3b632e198cd..06d1fbabe16 100644 --- a/src/test/mir-opt/end_region_5.rs +++ b/src/test/mir-opt/end_region_5.rs @@ -37,7 +37,7 @@ fn foo(f: F) where F: FnOnce() -> i32 { // let mut _4: &'18s D; // bb0: { // StorageLive(_1); -// _1 = D::{{constructor}}(const 0i32,); +// _1 = D(const 0i32,); // FakeRead(ForLet, _1); // StorageLive(_3); // StorageLive(_4); diff --git a/src/test/mir-opt/end_region_6.rs b/src/test/mir-opt/end_region_6.rs index 03c7de02ec1..d0db23e6de0 100644 --- a/src/test/mir-opt/end_region_6.rs +++ b/src/test/mir-opt/end_region_6.rs @@ -37,7 +37,7 @@ fn foo(f: F) where F: FnOnce() -> i32 { // let mut _4: &'24s D; // bb0: { // StorageLive(_1); -// _1 = D::{{constructor}}(const 0i32,); +// _1 = D(const 0i32,); // FakeRead(ForLet, _1); // StorageLive(_3); // StorageLive(_4); diff --git a/src/test/mir-opt/end_region_7.rs b/src/test/mir-opt/end_region_7.rs index 56e3e0aa6f7..c7df440ebe2 100644 --- a/src/test/mir-opt/end_region_7.rs +++ b/src/test/mir-opt/end_region_7.rs @@ -36,7 +36,7 @@ fn foo(f: F) where F: FnOnce() -> i32 { // let mut _3: [closure@NodeId(33) d:D]; // bb0: { // StorageLive(_1); -// _1 = D::{{constructor}}(const 0i32,); +// _1 = D(const 0i32,); // FakeRead(ForLet, _1); // StorageLive(_3); // _3 = [closure@NodeId(33)] { d: move _1 }; diff --git a/src/test/mir-opt/end_region_8.rs b/src/test/mir-opt/end_region_8.rs index 0a54dcaa0d3..9f2a9c3b72e 100644 --- a/src/test/mir-opt/end_region_8.rs +++ b/src/test/mir-opt/end_region_8.rs @@ -39,7 +39,7 @@ fn foo(f: F) where F: FnOnce() -> i32 { // let mut _4: [closure@NodeId(33) r:&'24s D]; // bb0: { // StorageLive(_1); -// _1 = D::{{constructor}}(const 0i32,); +// _1 = D(const 0i32,); // FakeRead(ForLet, _1); // StorageLive(_2); // _2 = &'26_1rs _1; diff --git a/src/test/mir-opt/end_region_destruction_extents_1.rs b/src/test/mir-opt/end_region_destruction_extents_1.rs index a5107d30438..eb381dfc552 100644 --- a/src/test/mir-opt/end_region_destruction_extents_1.rs +++ b/src/test/mir-opt/end_region_destruction_extents_1.rs @@ -79,16 +79,16 @@ unsafe impl<'a, #[may_dangle] 'b> Drop for D1<'a, 'b> { // StorageLive(_3); // StorageLive(_4); // StorageLive(_5); -// _5 = S1::{{constructor}}(const "ex1",); +// _5 = S1(const "ex1",); // _4 = &'15ds _5; // _3 = &'15ds (*_4); // StorageLive(_6); // StorageLive(_7); // StorageLive(_8); -// _8 = S1::{{constructor}}(const "dang1",); +// _8 = S1(const "dang1",); // _7 = &'13s _8; // _6 = &'13s (*_7); -// _2 = D1<'15ds, '13s>::{{constructor}}(move _3, move _6); +// _2 = D1<'15ds, '13s>(move _3, move _6); // EndRegion('13s); // StorageDead(_6); // StorageDead(_3); @@ -132,7 +132,7 @@ unsafe impl<'a, #[may_dangle] 'b> Drop for D1<'a, 'b> { // StorageLive(_7); // _7 = &'13s (promoted[0]: S1); // _6 = &'13s (*_7); -// _2 = D1<'15ds, '13s>::{{constructor}}(move _3, move _6); +// _2 = D1<'15ds, '13s>(move _3, move _6); // EndRegion('13s); // StorageDead(_6); // StorageDead(_3); diff --git a/src/test/mir-opt/packed-struct-drop-aligned.rs b/src/test/mir-opt/packed-struct-drop-aligned.rs index 9441c6f4085..1fe29a29e23 100644 --- a/src/test/mir-opt/packed-struct-drop-aligned.rs +++ b/src/test/mir-opt/packed-struct-drop-aligned.rs @@ -42,7 +42,7 @@ impl Drop for Droppy { // bb0: { // StorageLive(_1); // ... -// _1 = Packed::{{constructor}}(move _2,); +// _1 = Packed(move _2,); // ... // StorageLive(_6); // _6 = move (_1.0: Aligned); diff --git a/src/test/ui/issues/issue-21554.stderr b/src/test/ui/issues/issue-21554.stderr index be7762f1aa2..104970ea448 100644 --- a/src/test/ui/issues/issue-21554.stderr +++ b/src/test/ui/issues/issue-21554.stderr @@ -1,4 +1,4 @@ -error[E0606]: casting `fn(i32) -> Inches {Inches::{{constructor}}}` as `f32` is invalid +error[E0606]: casting `fn(i32) -> Inches {Inches}` as `f32` is invalid --> $DIR/issue-21554.rs:14:5 | LL | Inches as f32; diff --git a/src/test/ui/issues/issue-35241.stderr b/src/test/ui/issues/issue-35241.stderr index 42bf0aae5b1..4404f88de31 100644 --- a/src/test/ui/issues/issue-35241.stderr +++ b/src/test/ui/issues/issue-35241.stderr @@ -9,7 +9,7 @@ LL | fn test() -> Foo { Foo } //~ ERROR mismatched types | expected `Foo` because of return type | = note: expected type `Foo` - found type `fn(u32) -> Foo {Foo::{{constructor}}}` + found type `fn(u32) -> Foo {Foo}` error: aborting due to previous error diff --git a/src/test/ui/namespace/namespace-mix.stderr b/src/test/ui/namespace/namespace-mix.stderr index 6d72b6044ae..0a297e58574 100644 --- a/src/test/ui/namespace/namespace-mix.stderr +++ b/src/test/ui/namespace/namespace-mix.stderr @@ -144,11 +144,11 @@ note: required by `check` LL | fn check(_: T) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error[E0277]: the trait bound `fn() -> c::TS {c::TS::{{constructor}}}: Impossible` is not satisfied +error[E0277]: the trait bound `fn() -> c::TS {c::TS}: Impossible` is not satisfied --> $DIR/namespace-mix.rs:66:5 | LL | check(m3::TS); //~ ERROR c::TS - | ^^^^^ the trait `Impossible` is not implemented for `fn() -> c::TS {c::TS::{{constructor}}}` + | ^^^^^ the trait `Impossible` is not implemented for `fn() -> c::TS {c::TS}` | note: required by `check` --> $DIR/namespace-mix.rs:31:1 @@ -192,11 +192,11 @@ note: required by `check` LL | fn check(_: T) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error[E0277]: the trait bound `fn() -> namespace_mix::c::TS {namespace_mix::c::TS::{{constructor}}}: Impossible` is not satisfied +error[E0277]: the trait bound `fn() -> namespace_mix::c::TS {namespace_mix::c::TS}: Impossible` is not satisfied --> $DIR/namespace-mix.rs:72:5 | LL | check(xm3::TS); //~ ERROR c::TS - | ^^^^^ the trait `Impossible` is not implemented for `fn() -> namespace_mix::c::TS {namespace_mix::c::TS::{{constructor}}}` + | ^^^^^ the trait `Impossible` is not implemented for `fn() -> namespace_mix::c::TS {namespace_mix::c::TS}` | note: required by `check` --> $DIR/namespace-mix.rs:31:1 diff --git a/src/test/ui/privacy/private-inferred-type-3.rs b/src/test/ui/privacy/private-inferred-type-3.rs index 0c393f02323..5151f624b8d 100644 --- a/src/test/ui/privacy/private-inferred-type-3.rs +++ b/src/test/ui/privacy/private-inferred-type-3.rs @@ -14,8 +14,8 @@ // error-pattern:static `PRIV_STATIC` is private // error-pattern:type `ext::PrivEnum` is private // error-pattern:type `fn() {::method}` is private -// error-pattern:type `fn(u8) -> ext::PrivTupleStruct {ext::PrivTupleStruct::{{constructor}}}` is pr -// error-pattern:type `fn(u8) -> ext::PubTupleStruct {ext::PubTupleStruct::{{constructor}}}` is priv +// error-pattern:type `fn(u8) -> ext::PrivTupleStruct {ext::PrivTupleStruct}` is private +// error-pattern:type `fn(u8) -> ext::PubTupleStruct {ext::PubTupleStruct}` is private // error-pattern:type `for<'r> fn(&'r ext::Pub) {>::priv_method}` is private #![feature(decl_macro)] diff --git a/src/test/ui/privacy/private-inferred-type-3.stderr b/src/test/ui/privacy/private-inferred-type-3.stderr index 3c37a7ee1e8..590ff76b375 100644 --- a/src/test/ui/privacy/private-inferred-type-3.stderr +++ b/src/test/ui/privacy/private-inferred-type-3.stderr @@ -30,7 +30,7 @@ LL | ext::m!(); | = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) -error: type `fn(u8) -> ext::PrivTupleStruct {ext::PrivTupleStruct::{{constructor}}}` is private +error: type `fn(u8) -> ext::PrivTupleStruct {ext::PrivTupleStruct}` is private --> $DIR/private-inferred-type-3.rs:26:5 | LL | ext::m!(); @@ -38,7 +38,7 @@ LL | ext::m!(); | = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) -error: type `fn(u8) -> ext::PubTupleStruct {ext::PubTupleStruct::{{constructor}}}` is private +error: type `fn(u8) -> ext::PubTupleStruct {ext::PubTupleStruct}` is private --> $DIR/private-inferred-type-3.rs:26:5 | LL | ext::m!(); diff --git a/src/test/ui/privacy/private-inferred-type.rs b/src/test/ui/privacy/private-inferred-type.rs index 3ca8b1eb2ed..58e17b24394 100644 --- a/src/test/ui/privacy/private-inferred-type.rs +++ b/src/test/ui/privacy/private-inferred-type.rs @@ -53,9 +53,9 @@ mod m { ::method; //~ ERROR type `fn() {::method}` is private ::method; // OK PrivTupleStruct; - //~^ ERROR type `fn(u8) -> m::PrivTupleStruct {m::PrivTupleStruct::{{constructor}}}` is priv + //~^ ERROR type `fn(u8) -> m::PrivTupleStruct {m::PrivTupleStruct}` is private PubTupleStruct; - //~^ ERROR type `fn(u8) -> m::PubTupleStruct {m::PubTupleStruct::{{constructor}}}` is privat + //~^ ERROR type `fn(u8) -> m::PubTupleStruct {m::PubTupleStruct}` is private Pub(0u8).priv_method(); //~^ ERROR type `for<'r> fn(&'r m::Pub) {>::priv_method}` is private } diff --git a/src/test/ui/privacy/private-inferred-type.stderr b/src/test/ui/privacy/private-inferred-type.stderr index abbe43fe384..1ab281cfc25 100644 --- a/src/test/ui/privacy/private-inferred-type.stderr +++ b/src/test/ui/privacy/private-inferred-type.stderr @@ -115,7 +115,7 @@ LL | ::method; //~ ERROR type `fn() { m::PrivTupleStruct {m::PrivTupleStruct::{{constructor}}}` is private +error: type `fn(u8) -> m::PrivTupleStruct {m::PrivTupleStruct}` is private --> $DIR/private-inferred-type.rs:55:9 | LL | PrivTupleStruct; @@ -124,7 +124,7 @@ LL | PrivTupleStruct; LL | m::m!(); | -------- in this macro invocation -error: type `fn(u8) -> m::PubTupleStruct {m::PubTupleStruct::{{constructor}}}` is private +error: type `fn(u8) -> m::PubTupleStruct {m::PubTupleStruct}` is private --> $DIR/private-inferred-type.rs:57:9 | LL | PubTupleStruct;