From b04922184457b1f3b5457b73051d128d39e6beec Mon Sep 17 00:00:00 2001 From: varkor Date: Fri, 2 Aug 2019 01:14:42 +0100 Subject: [PATCH] Address review comments --- src/librustc/hir/mod.rs | 2 +- src/librustc/hir/print.rs | 19 ++-- src/librustc/ty/context.rs | 2 +- src/librustc_save_analysis/sig.rs | 20 ++--- src/librustc_typeck/check/wfcheck.rs | 2 +- .../outlives/implicit_infer.rs | 2 +- src/test/ui/issues/issue-60662.stdout | 2 +- src/test/ui/traits/trait-bounds-in-arc.rs | 2 +- .../type-alias-impl-trait-pass.rs | 89 ------------------- .../type-alias-impl-trait.rs | 0 10 files changed, 24 insertions(+), 116 deletions(-) delete mode 100644 src/test/ui/type-alias-impl-trait/type-alias-impl-trait-pass.rs rename src/test/ui/{ => type-alias-impl-trait}/type-alias-impl-trait.rs (100%) diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index d954484533ac6..5fe8069e3326a 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -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;` diff --git a/src/librustc/hir/print.rs b/src/librustc/hir/print.rs index 7d6c6e1d09dfb..315e9ac98066d 100644 --- a/src/librustc/hir/print.rs +++ b/src/librustc/hir/print.rs @@ -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 } diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index f6190f3ec1b4b..ca6603b58530d 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -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>, /// Given the closure ID this map provides the list of UpvarIDs used by it. diff --git a/src/librustc_save_analysis/sig.rs b/src/librustc_save_analysis/sig.rs index 0aab8125f801c..cbfaf91cdfc99 100644 --- a/src/librustc_save_analysis/sig.rs +++ b/src/librustc_save_analysis/sig.rs @@ -438,28 +438,26 @@ impl Sig for ast::Item { refs: vec![], }) } - ast::ItemKind::OpaqueTy(ref bounds, ref generics) => { + 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)?; - if !bounds.is_empty() { - sig.text.push_str(" = impl "); - sig.text.push_str(&pprust::bounds_to_string(bounds)); - } + sig.text.push_str(" = "); + let ty = ty.make(offset + sig.text.len(), id, scx)?; + sig.text.push_str(&ty.text); sig.text.push(';'); - Ok(sig) + Ok(merge_sigs(sig.text.clone(), vec![sig, ty])) } - ast::ItemKind::Ty(ref ty, ref generics) => { + 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(" = "); - let ty = ty.make(offset + sig.text.len(), id, scx)?; - sig.text.push_str(&ty.text); + sig.text.push_str(" = impl "); + sig.text.push_str(&pprust::bounds_to_string(bounds)); sig.text.push(';'); - Ok(merge_sigs(sig.text.clone(), vec![sig, ty])) + Ok(sig) } ast::ItemKind::Enum(_, ref generics) => { let text = "enum ".to_owned(); diff --git a/src/librustc_typeck/check/wfcheck.rs b/src/librustc_typeck/check/wfcheck.rs index 35a49d95ec0ae..c1d8fde3be15b 100644 --- a/src/librustc_typeck/check/wfcheck.rs +++ b/src/librustc_typeck/check/wfcheck.rs @@ -219,7 +219,7 @@ fn check_associated_item( } } ty::AssocKind::OpaqueTy => { - // do nothing, opaque types check themselves + // Do nothing: opaque types check themselves. } } diff --git a/src/librustc_typeck/outlives/implicit_infer.rs b/src/librustc_typeck/outlives/implicit_infer.rs index 7cb9c5f04c99a..6b288347ad006 100644 --- a/src/librustc_typeck/outlives/implicit_infer.rs +++ b/src/librustc_typeck/outlives/implicit_infer.rs @@ -296,7 +296,7 @@ pub fn check_explicit_predicates<'tcx>( // struct MyStruct<'x, X> { field: Box> } // ``` // - // 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`. // diff --git a/src/test/ui/issues/issue-60662.stdout b/src/test/ui/issues/issue-60662.stdout index 21bd650bad004..e2a88dec97f7c 100644 --- a/src/test/ui/issues/issue-60662.stdout +++ b/src/test/ui/issues/issue-60662.stdout @@ -10,5 +10,5 @@ extern crate std; trait Animal { } fn main() { - pub type ServeFut= impl : Animal; + pub type ServeFut = impl Animal; } diff --git a/src/test/ui/traits/trait-bounds-in-arc.rs b/src/test/ui/traits/trait-bounds-in-arc.rs index 15e942970048f..941f66c056104 100644 --- a/src/test/ui/traits/trait-bounds-in-arc.rs +++ b/src/test/ui/traits/trait-bounds-in-arc.rs @@ -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 diff --git a/src/test/ui/type-alias-impl-trait/type-alias-impl-trait-pass.rs b/src/test/ui/type-alias-impl-trait/type-alias-impl-trait-pass.rs deleted file mode 100644 index 209134acf01f9..0000000000000 --- a/src/test/ui/type-alias-impl-trait/type-alias-impl-trait-pass.rs +++ /dev/null @@ -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![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 = impl Iterator; - -fn my_iter(t: T) -> MyIter { - std::iter::once(t) -} - -fn my_iter2(t: T) -> MyIter { - std::iter::once(t) -} - -// param names should not have an effect! -fn my_iter3(u: U) -> MyIter { - std::iter::once(u) -} - -// param position should not have an effect! -fn my_iter4(_: U, v: V) -> MyIter { - std::iter::once(v) -} - -// param names should not have an effect! -type MyOtherIter = impl Iterator; - -fn my_other_iter(u: U) -> MyOtherIter { - 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 = impl Sized + 'static; - - fn define_passthrough(t: T) -> Passthrough { - t - } -} - -fn use_passthrough(x: pass_through::Passthrough) -> pass_through::Passthrough { - x -} diff --git a/src/test/ui/type-alias-impl-trait.rs b/src/test/ui/type-alias-impl-trait/type-alias-impl-trait.rs similarity index 100% rename from src/test/ui/type-alias-impl-trait.rs rename to src/test/ui/type-alias-impl-trait/type-alias-impl-trait.rs