Skip to content

Commit d6e2239

Browse files
committed
Auto merge of #51773 - oli-obk:cleanup_impl_trait, r=nikomatsakis
Don't inspect the generated existential type items r? @nikomatsakis My debugging led me to the `hir::ItemExistential(..)` checks, which are entirely unnecessary because we never use the items directly. The issue was that items were iterated over in a random order (due to hashmaps), so if you checked the `ItemExistential` before the function that has the actual return `impl Trait`, you'd run into those ICEs you encountered.
2 parents 0cf0691 + 28a76a9 commit d6e2239

File tree

7 files changed

+20
-124
lines changed

7 files changed

+20
-124
lines changed

src/librustc_typeck/collect.rs

+2-19
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ fn convert_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, item_id: ast::NodeId) {
419419
convert_variant_ctor(tcx, struct_def.id());
420420
}
421421
},
422-
hir::ItemExistential(..) |
422+
hir::ItemExistential(..) => {}
423423
hir::ItemTy(..) | hir::ItemStatic(..) | hir::ItemConst(..) | hir::ItemFn(..) => {
424424
tcx.generics_of(def_id);
425425
tcx.type_of(def_id);
@@ -1066,24 +1066,7 @@ fn type_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
10661066
ItemExistential(hir::ExistTy { impl_trait_fn: None, .. }) => unimplemented!(),
10671067
// existential types desugared from impl Trait
10681068
ItemExistential(hir::ExistTy { impl_trait_fn: Some(owner), .. }) => {
1069-
tcx.typeck_tables_of(owner).concrete_existential_types
1070-
.get(&def_id)
1071-
.cloned()
1072-
.unwrap_or_else(|| {
1073-
// This can occur if some error in the
1074-
// owner fn prevented us from populating
1075-
// the `concrete_existential_types` table.
1076-
tcx.sess.delay_span_bug(
1077-
DUMMY_SP,
1078-
&format!(
1079-
"owner {:?} has no existential type for {:?} in its tables",
1080-
owner,
1081-
def_id,
1082-
),
1083-
);
1084-
1085-
tcx.types.err
1086-
})
1069+
tcx.typeck_tables_of(owner).concrete_existential_types[&def_id]
10871070
},
10881071
ItemTrait(..) | ItemTraitAlias(..) |
10891072
ItemMod(..) |

src/test/ui/error-codes/E0657.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ fn free_fn_capture_hrtb_in_impl_trait()
1919
-> Box<for<'a> Id<impl Lt<'a>>>
2020
//~^ ERROR `impl Trait` can only capture lifetimes bound at the fn or impl level [E0657]
2121
{
22-
() //~ ERROR mismatched types
22+
Box::new(())
2323
}
2424

2525
struct Foo;
@@ -28,7 +28,7 @@ impl Foo {
2828
-> Box<for<'a> Id<impl Lt<'a>>>
2929
//~^ ERROR `impl Trait` can only capture lifetimes bound at the fn or impl level
3030
{
31-
() //~ ERROR mismatched types
31+
Box::new(())
3232
}
3333
}
3434

src/test/ui/error-codes/E0657.stderr

+2-21
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,6 @@ error[E0657]: `impl Trait` can only capture lifetimes bound at the fn or impl le
1010
LL | -> Box<for<'a> Id<impl Lt<'a>>>
1111
| ^^
1212

13-
error[E0308]: mismatched types
14-
--> $DIR/E0657.rs:22:5
15-
|
16-
LL | () //~ ERROR mismatched types
17-
| ^^ expected struct `std::boxed::Box`, found ()
18-
|
19-
= note: expected type `std::boxed::Box<(dyn Id<_> + 'static)>`
20-
found type `()`
21-
22-
error[E0308]: mismatched types
23-
--> $DIR/E0657.rs:31:9
24-
|
25-
LL | () //~ ERROR mismatched types
26-
| ^^ expected struct `std::boxed::Box`, found ()
27-
|
28-
= note: expected type `std::boxed::Box<(dyn Id<_> + 'static)>`
29-
found type `()`
30-
31-
error: aborting due to 4 previous errors
13+
error: aborting due to 2 previous errors
3214

33-
Some errors occurred: E0308, E0657.
34-
For more information about an error, try `rustc --explain E0308`.
15+
For more information about this error, try `rustc --explain E0657`.

src/test/ui/impl-trait/auto-trait-leak.rs

-2
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ fn main() {
2323
// return type, which can't depend on the obligation.
2424
fn cycle1() -> impl Clone {
2525
//~^ ERROR cycle detected
26-
//~| ERROR cycle detected
2726
send(cycle2().clone());
28-
//~^ ERROR `std::rc::Rc<std::string::String>` cannot be sent between threads safely
2927

3028
Rc::new(Cell::new(5))
3129
}
+9-47
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,29 @@
1-
error[E0391]: cycle detected when processing `cycle1::{{exist-impl-Trait}}`
2-
--> $DIR/auto-trait-leak.rs:24:16
3-
|
4-
LL | fn cycle1() -> impl Clone {
5-
| ^^^^^^^^^^
6-
|
7-
note: ...which requires processing `cycle1`...
1+
error[E0391]: cycle detected when processing `cycle1`
82
--> $DIR/auto-trait-leak.rs:24:1
93
|
104
LL | fn cycle1() -> impl Clone {
115
| ^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
127
note: ...which requires evaluating trait selection obligation `impl std::clone::Clone: std::marker::Send`...
138
note: ...which requires processing `cycle2::{{exist-impl-Trait}}`...
14-
--> $DIR/auto-trait-leak.rs:33:16
9+
--> $DIR/auto-trait-leak.rs:31:16
1510
|
1611
LL | fn cycle2() -> impl Clone {
1712
| ^^^^^^^^^^
1813
note: ...which requires processing `cycle2`...
19-
--> $DIR/auto-trait-leak.rs:33:1
14+
--> $DIR/auto-trait-leak.rs:31:1
2015
|
2116
LL | fn cycle2() -> impl Clone {
2217
| ^^^^^^^^^^^^^^^^^^^^^^^^^
2318
note: ...which requires evaluating trait selection obligation `impl std::clone::Clone: std::marker::Send`...
24-
= note: ...which again requires processing `cycle1::{{exist-impl-Trait}}`, completing the cycle
25-
26-
error[E0391]: cycle detected when processing `cycle1::{{exist-impl-Trait}}`
19+
note: ...which requires processing `cycle1::{{exist-impl-Trait}}`...
2720
--> $DIR/auto-trait-leak.rs:24:16
2821
|
2922
LL | fn cycle1() -> impl Clone {
3023
| ^^^^^^^^^^
31-
|
32-
note: ...which requires processing `cycle1`...
33-
--> $DIR/auto-trait-leak.rs:24:1
34-
|
35-
LL | fn cycle1() -> impl Clone {
36-
| ^^^^^^^^^^^^^^^^^^^^^^^^^
37-
note: ...which requires evaluating trait selection obligation `impl std::clone::Clone: std::marker::Send`...
38-
note: ...which requires processing `cycle2::{{exist-impl-Trait}}`...
39-
--> $DIR/auto-trait-leak.rs:33:16
40-
|
41-
LL | fn cycle2() -> impl Clone {
42-
| ^^^^^^^^^^
43-
note: ...which requires processing `cycle2`...
44-
--> $DIR/auto-trait-leak.rs:33:1
45-
|
46-
LL | fn cycle2() -> impl Clone {
47-
| ^^^^^^^^^^^^^^^^^^^^^^^^^
48-
= note: ...which again requires processing `cycle1::{{exist-impl-Trait}}`, completing the cycle
49-
50-
error[E0277]: `std::rc::Rc<std::string::String>` cannot be sent between threads safely
51-
--> $DIR/auto-trait-leak.rs:27:5
52-
|
53-
LL | send(cycle2().clone());
54-
| ^^^^ `std::rc::Rc<std::string::String>` cannot be sent between threads safely
55-
|
56-
= help: within `impl std::clone::Clone`, the trait `std::marker::Send` is not implemented for `std::rc::Rc<std::string::String>`
57-
= note: required because it appears within the type `impl std::clone::Clone`
58-
note: required by `send`
59-
--> $DIR/auto-trait-leak.rs:16:1
60-
|
61-
LL | fn send<T: Send>(_: T) {}
62-
| ^^^^^^^^^^^^^^^^^^^^^^
24+
= note: ...which again requires processing `cycle1`, completing the cycle
25+
note: cycle used when type-checking all item bodies
6326

64-
error: aborting due to 3 previous errors
27+
error: aborting due to previous error
6528

66-
Some errors occurred: E0277, E0391.
67-
For more information about an error, try `rustc --explain E0277`.
29+
For more information about this error, try `rustc --explain E0391`.

src/test/ui/impl_trait_projections.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,8 @@ fn projection_with_named_trait_is_disallowed(x: impl Iterator)
3434
fn projection_with_named_trait_inside_path_is_disallowed()
3535
-> <::std::ops::Range<impl Debug> as Iterator>::Item
3636
//~^ ERROR `impl Trait` is not allowed in path parameters
37-
//~| ERROR trait bound `impl std::fmt::Debug: std::iter::Step` is not satisfied
38-
{ //~ ERROR trait bound `impl std::fmt::Debug: std::iter::Step` is not satisfied
39-
(1i32..100).next().unwrap() //~ ERROR mismatched types
37+
{
38+
(1i32..100).next().unwrap()
4039
}
4140

4241
fn projection_from_impl_trait_inside_dyn_trait_is_disallowed()

src/test/ui/impl_trait_projections.stderr

+3-30
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ LL | -> <::std::ops::Range<impl Debug> as Iterator>::Item
1717
| ^^^^^^^^^^
1818

1919
error[E0667]: `impl Trait` is not allowed in path parameters
20-
--> $DIR/impl_trait_projections.rs:43:29
20+
--> $DIR/impl_trait_projections.rs:42:29
2121
|
2222
LL | -> <dyn Iterator<Item = impl Debug> as Iterator>::Item
2323
| ^^^^^^^^^^
@@ -30,34 +30,7 @@ LL | fn projection_is_disallowed(x: impl Iterator) -> <impl Iterator>::Item {
3030
|
3131
= note: specify the type using the syntax `<impl std::iter::Iterator as Trait>::Item`
3232

33-
error[E0277]: the trait bound `impl std::fmt::Debug: std::iter::Step` is not satisfied
34-
--> $DIR/impl_trait_projections.rs:38:1
35-
|
36-
LL | / { //~ ERROR trait bound `impl std::fmt::Debug: std::iter::Step` is not satisfied
37-
LL | | (1i32..100).next().unwrap() //~ ERROR mismatched types
38-
LL | | }
39-
| |_^ the trait `std::iter::Step` is not implemented for `impl std::fmt::Debug`
40-
|
41-
= note: required because of the requirements on the impl of `std::iter::Iterator` for `std::ops::Range<impl std::fmt::Debug>`
42-
43-
error[E0308]: mismatched types
44-
--> $DIR/impl_trait_projections.rs:39:5
45-
|
46-
LL | (1i32..100).next().unwrap() //~ ERROR mismatched types
47-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected anonymized type, found i32
48-
|
49-
= note: expected type `impl std::fmt::Debug`
50-
found type `i32`
51-
52-
error[E0277]: the trait bound `impl std::fmt::Debug: std::iter::Step` is not satisfied
53-
--> $DIR/impl_trait_projections.rs:35:8
54-
|
55-
LL | -> <::std::ops::Range<impl Debug> as Iterator>::Item
56-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::iter::Step` is not implemented for `impl std::fmt::Debug`
57-
|
58-
= note: required because of the requirements on the impl of `std::iter::Iterator` for `std::ops::Range<impl std::fmt::Debug>`
59-
60-
error: aborting due to 8 previous errors
33+
error: aborting due to 5 previous errors
6134

62-
Some errors occurred: E0223, E0277, E0308, E0667.
35+
Some errors occurred: E0223, E0667.
6336
For more information about an error, try `rustc --explain E0223`.

0 commit comments

Comments
 (0)