Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
3b92689
Relax bounds on HashMap to match hashbrown
Mark-Simulacrum Dec 26, 2019
48859db
Relax bounds on HashSet to match hashbrown
Mark-Simulacrum Dec 26, 2019
6bf2cc2
Avoid instantiating many `Parser` structs in `generic_extension`.
nnethercote Feb 4, 2020
f840a95
Remove the `Cow` from `Directory`.
nnethercote Feb 5, 2020
2a13b24
Change condition ordering in `parse_tt`.
nnethercote Feb 5, 2020
a60669d
Properly use parent generics for opaque types
Aaron1011 Feb 9, 2020
c18476e
[ImgBot] Optimize images
ImgBotApp Feb 11, 2020
34cf0b3
Only use the parent if it's an opaque type
Aaron1011 Feb 11, 2020
ad7802f
Micro-optimize the heck out of LEB128 reading and writing.
nnethercote Feb 10, 2020
1f6fb33
make the sgx arg cleanup implementation a no op
Goirad Feb 11, 2020
24be307
Suggestion when encountering assoc types from hrtb
estebank Feb 11, 2020
bde9677
Suggest named lifetime in ADT with hrtb
estebank Feb 11, 2020
33e2c1d
bootstrap: Configure cmake when building sanitizer runtimes
tmiasko Feb 12, 2020
c39b04e
When expecting `BoxFuture` and using `async {}`, suggest `Box::pin`
estebank Feb 12, 2020
a852fb7
Remove std lib `Span` from expected boxed future test
estebank Feb 12, 2020
80cdb0a
Account for `Box::new(impl Future)` and emit help `use Box::pin`
estebank Feb 12, 2020
c376fc0
Account for `Pin::new(_)` and `Pin::new(Box::new(_))` when `Box::pin(…
estebank Feb 12, 2020
248f5a4
Add trait `Self` filtering to `rustc_on_unimplemented`
estebank Feb 13, 2020
2a20133
Rollup merge of #67642 - Mark-Simulacrum:relax-bounds, r=Amanieu
Dylan-DPC Feb 13, 2020
87ba8f2
Rollup merge of #68848 - nnethercote:hasten-macro-parsing, r=petroche…
Dylan-DPC Feb 13, 2020
e9f391e
Rollup merge of #69008 - Aaron1011:fix/opaque-ty-parent, r=matthewjasper
Dylan-DPC Feb 13, 2020
8d00adf
Rollup merge of #69048 - estebank:hrlt-assoc, r=nagisa
Dylan-DPC Feb 13, 2020
53a790c
Rollup merge of #69049 - pthariensflame:improvement/imgbot, r=Guillau…
Dylan-DPC Feb 13, 2020
a50a896
Rollup merge of #69050 - nnethercote:micro-optimize-leb128, r=michael…
Dylan-DPC Feb 13, 2020
2501a10
Rollup merge of #69068 - Goirad:make-sgx-arg-cleanup-nop, r=jethrogb,…
Dylan-DPC Feb 13, 2020
ec5bf15
Rollup merge of #69082 - estebank:boxfuture-box-pin, r=tmandry
Dylan-DPC Feb 13, 2020
1ddf250
Rollup merge of #69104 - tmiasko:configure-cmake, r=Mark-Simulacrum
Dylan-DPC Feb 13, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Properly use parent generics for opaque types
Fixes #67844

Previously, opaque types would only get parent generics if they
a return-position-impl-trait (e.g. `fn foo<A>() -> impl MyTrait<A>`).

However, it's possible for opaque types to be nested inside one another:

```rust
trait WithAssoc { type AssocType; }

trait WithParam<A> {}

type Return<A> = impl WithAssoc<AssocType = impl WithParam<A>>;
```

When this occurs, we need to ensure that the nested opaque types
properly inherit generic parameters from their parent opaque type.

This commit fixes the `generics_of` query to take the parent item
into account when determining the generics for an opaque type.
  • Loading branch information
Aaron1011 committed Feb 9, 2020
commit a60669d95cdad0e28cf28790b717bbcf235153f8
14 changes: 13 additions & 1 deletion src/librustc_typeck/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1054,7 +1054,19 @@ fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> &ty::Generics {
Some(tcx.closure_base_def_id(def_id))
}
Node::Item(item) => match item.kind {
ItemKind::OpaqueTy(hir::OpaqueTy { impl_trait_fn, .. }) => impl_trait_fn,
ItemKind::OpaqueTy(hir::OpaqueTy { impl_trait_fn, .. }) => {
impl_trait_fn.or_else(|| {
let parent_id = tcx.hir().get_parent_item(hir_id);
// This opaque type might occur inside another opaque type
// (e.g. `impl Foo<MyType = impl Bar<A>>`)
if parent_id != hir_id && parent_id != CRATE_HIR_ID {
debug!("generics_of: parent of opaque ty {:?} is {:?}", def_id, parent_id);
Some(tcx.hir().local_def_id(parent_id))
} else {
None
}
})
}
_ => None,
},
_ => None,
Expand Down
32 changes: 32 additions & 0 deletions src/test/ui/type-alias-impl-trait/issue-67844-nested-opaque.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// check-pass
// Regression test for issue #67844
// Ensures that we properly handle nested TAIT occurences
// with generic parameters

#![feature(type_alias_impl_trait)]

trait WithAssoc { type AssocType; }

trait WithParam<A> {}

type Return<A> = impl WithAssoc<AssocType = impl WithParam<A>>;

struct MyParam;
impl<A> WithParam<A> for MyParam {}

struct MyStruct;

impl WithAssoc for MyStruct {
type AssocType = MyParam;
}


fn my_fun<A>() -> Return<A> {
MyStruct
}

fn my_other_fn<A>() -> impl WithAssoc<AssocType = impl WithParam<A>> {
MyStruct
}

fn main() {}