Address review comments

This commit is contained in:
varkor 2019-08-02 01:14:42 +01:00
parent a45cde5ad0
commit b049221844
10 changed files with 25 additions and 117 deletions

View File

@ -1929,7 +1929,7 @@ pub struct OpaqueTy {
pub origin: OpaqueTyOrigin,
}
/// Where the opaque type came from
/// From whence the opaque type came.
#[derive(Copy, Clone, RustcEncodable, RustcDecodable, Debug, HashStable)]
pub enum OpaqueTyOrigin {
/// `type Foo = impl Trait;`

View File

@ -565,17 +565,12 @@ impl<'a> State<'a> {
self.s.word(";");
self.end(); // end the outer ibox
}
hir::ItemKind::OpaqueTy(ref exist) => {
hir::ItemKind::OpaqueTy(ref opaque_ty) => {
self.head(visibility_qualified(&item.vis, "type"));
self.print_ident(item.ident);
self.word_space("= impl");
self.print_generic_params(&exist.generics.params);
self.end(); // end the inner ibox
self.print_where_clause(&exist.generics.where_clause);
self.s.space();
let mut real_bounds = Vec::with_capacity(exist.bounds.len());
for b in exist.bounds.iter() {
self.print_generic_params(&opaque_ty.generics.params);
let mut real_bounds = Vec::with_capacity(opaque_ty.bounds.len());
for b in opaque_ty.bounds.iter() {
if let GenericBound::Trait(ref ptr, hir::TraitBoundModifier::Maybe) = *b {
self.s.space();
self.word_space("for ?");
@ -584,7 +579,11 @@ impl<'a> State<'a> {
real_bounds.push(b);
}
}
self.print_bounds(":", real_bounds);
self.print_bounds(" = impl", real_bounds);
self.end(); // end the inner ibox
self.print_where_clause(&opaque_ty.generics.where_clause);
self.s.word(";");
self.end(); // end the outer ibox
}

View File

@ -393,7 +393,7 @@ pub struct TypeckTables<'tcx> {
pub free_region_map: FreeRegionMap<'tcx>,
/// All the opaque types that are restricted to concrete types
/// by this function
/// by this function.
pub concrete_opaque_types: FxHashMap<DefId, ResolvedOpaqueTy<'tcx>>,
/// Given the closure ID this map provides the list of UpvarIDs used by it.

View File

@ -438,18 +438,6 @@ impl Sig for ast::Item {
refs: vec![],
})
}
ast::ItemKind::OpaqueTy(ref bounds, ref generics) => {
let text = "type ".to_owned();
let mut sig = name_and_generics(text, offset, generics, self.id, self.ident, scx)?;
if !bounds.is_empty() {
sig.text.push_str(" = impl ");
sig.text.push_str(&pprust::bounds_to_string(bounds));
}
sig.text.push(';');
Ok(sig)
}
ast::ItemKind::Ty(ref ty, ref generics) => {
let text = "type ".to_owned();
let mut sig = name_and_generics(text, offset, generics, self.id, self.ident, scx)?;
@ -461,6 +449,16 @@ impl Sig for ast::Item {
Ok(merge_sigs(sig.text.clone(), vec![sig, ty]))
}
ast::ItemKind::OpaqueTy(ref bounds, ref generics) => {
let text = "type ".to_owned();
let mut sig = name_and_generics(text, offset, generics, self.id, self.ident, scx)?;
sig.text.push_str(" = impl ");
sig.text.push_str(&pprust::bounds_to_string(bounds));
sig.text.push(';');
Ok(sig)
}
ast::ItemKind::Enum(_, ref generics) => {
let text = "enum ".to_owned();
let mut sig = name_and_generics(text, offset, generics, self.id, self.ident, scx)?;

View File

@ -219,7 +219,7 @@ fn check_associated_item(
}
}
ty::AssocKind::OpaqueTy => {
// do nothing, opaque types check themselves
// Do nothing: opaque types check themselves.
}
}

View File

@ -296,7 +296,7 @@ pub fn check_explicit_predicates<'tcx>(
// struct MyStruct<'x, X> { field: Box<dyn Trait<'x, X>> }
// ```
//
// The `where Self: 'a` predicate refers to the *opaque, hidden type*
// The `where Self: 'a` predicate refers to the *existential, hidden type*
// that is represented by the `dyn Trait`, not to the `X` type parameter
// (or any other generic parameter) declared on `MyStruct`.
//

View File

@ -10,5 +10,5 @@ extern crate std;
trait Animal { }
fn main() {
pub type ServeFut= impl : Animal;
pub type ServeFut = impl Animal;
}

View File

@ -1,6 +1,6 @@
// run-pass
#![allow(unused_must_use)]
// Tests that a heterogeneous list of opaque types can be put inside an Arc
// Tests that a heterogeneous list of existential `dyn` types can be put inside an Arc
// and shared between threads as long as all types fulfill Send.
// ignore-emscripten no threads support

View File

@ -1,89 +0,0 @@
// run-pass
#![allow(dead_code)]
#![allow(unused_assignments)]
#![allow(unused_variables)]
#![feature(type_alias_impl_trait)]
fn main() {
assert_eq!(foo().to_string(), "foo");
assert_eq!(bar1().to_string(), "bar1");
assert_eq!(bar2().to_string(), "bar2");
let mut x = bar1();
x = bar2();
assert_eq!(boo::boo().to_string(), "boo");
assert_eq!(my_iter(42u8).collect::<Vec<u8>>(), vec![42u8]);
}
// single definition
type Foo = impl std::fmt::Display;
fn foo() -> Foo {
"foo"
}
// two definitions
type Bar = impl std::fmt::Display;
fn bar1() -> Bar {
"bar1"
}
fn bar2() -> Bar {
"bar2"
}
// definition in submodule
type Boo = impl std::fmt::Display;
mod boo {
pub fn boo() -> super::Boo {
"boo"
}
}
type MyIter<T> = impl Iterator<Item = T>;
fn my_iter<T>(t: T) -> MyIter<T> {
std::iter::once(t)
}
fn my_iter2<T>(t: T) -> MyIter<T> {
std::iter::once(t)
}
// param names should not have an effect!
fn my_iter3<U>(u: U) -> MyIter<U> {
std::iter::once(u)
}
// param position should not have an effect!
fn my_iter4<U, V>(_: U, v: V) -> MyIter<V> {
std::iter::once(v)
}
// param names should not have an effect!
type MyOtherIter<T> = impl Iterator<Item = T>;
fn my_other_iter<U>(u: U) -> MyOtherIter<U> {
std::iter::once(u)
}
trait Trait {}
type GenericBound<'a, T: Trait> = impl Sized + 'a;
fn generic_bound<'a, T: Trait + 'a>(t: T) -> GenericBound<'a, T> {
t
}
mod pass_through {
pub type Passthrough<T> = impl Sized + 'static;
fn define_passthrough<T: 'static>(t: T) -> Passthrough<T> {
t
}
}
fn use_passthrough(x: pass_through::Passthrough<u32>) -> pass_through::Passthrough<u32> {
x
}