From: Oliver Schneider Date: Tue, 3 Jul 2018 17:38:14 +0000 (+0200) Subject: Implement existential types X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=53d2ebb0adbe677a811ae130523ebceb285a8029;p=rust.git Implement existential types --- diff --git a/src/librustc/hir/def.rs b/src/librustc/hir/def.rs index 7a26a239aef..1c355e35fd6 100644 --- a/src/librustc/hir/def.rs +++ b/src/librustc/hir/def.rs @@ -37,11 +37,15 @@ pub enum Def { Enum(DefId), Variant(DefId), Trait(DefId), + /// `existential type Foo: Bar;` Existential(DefId), + /// `type Foo = Bar;` TyAlias(DefId), TyForeign(DefId), TraitAlias(DefId), AssociatedTy(DefId), + /// `existential type Foo: Bar;` + AssociatedExistential(DefId), PrimTy(hir::PrimTy), TyParam(DefId), SelfTy(Option /* trait */, Option /* impl */), @@ -245,7 +249,7 @@ pub fn def_id(&self) -> DefId { Def::AssociatedTy(id) | Def::TyParam(id) | Def::Struct(id) | Def::StructCtor(id, ..) | Def::Union(id) | Def::Trait(id) | Def::Method(id) | Def::Const(id) | Def::AssociatedConst(id) | Def::Macro(id, ..) | - Def::Existential(id) | + Def::Existential(id) | Def::AssociatedExistential(id) | Def::GlobalAsm(id) | Def::TyForeign(id) => { id } @@ -276,6 +280,7 @@ pub fn kind_name(&self) -> &'static str { Def::TyAlias(..) => "type alias", Def::TraitAlias(..) => "trait alias", Def::AssociatedTy(..) => "associated type", + Def::AssociatedExistential(..) => "associated existential type", Def::Struct(..) => "struct", Def::StructCtor(.., CtorKind::Fn) => "tuple struct", Def::StructCtor(.., CtorKind::Const) => "unit struct", diff --git a/src/librustc/hir/intravisit.rs b/src/librustc/hir/intravisit.rs index 2fefd2b3318..4274cd3a0a6 100644 --- a/src/librustc/hir/intravisit.rs +++ b/src/librustc/hir/intravisit.rs @@ -907,6 +907,10 @@ pub fn walk_impl_item<'v, V: Visitor<'v>>(visitor: &mut V, impl_item: &'v ImplIt visitor.visit_id(impl_item.id); visitor.visit_ty(ty); } + ImplItemKind::Existential(ref bounds) => { + visitor.visit_id(impl_item.id); + walk_list!(visitor, visit_param_bound, bounds); + } } } diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index 722934ac39a..80e9b4caef5 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -323,6 +323,7 @@ fn visit_item(&mut self, item: &'lcx Item) { | ItemKind::Union(_, ref generics) | ItemKind::Enum(_, ref generics) | ItemKind::Ty(_, ref generics) + | ItemKind::Existential(_, ref generics) | ItemKind::Trait(_, _, ref generics, ..) => { let def_id = self.lctx.resolver.definitions().local_def_id(item.id); let count = generics @@ -2632,6 +2633,11 @@ fn lower_item_kind( self.lower_ty(t, ImplTraitContext::Disallowed), self.lower_generics(generics, ImplTraitContext::Disallowed), ), + ItemKind::Existential(ref b, ref generics) => hir::ItemKind::Existential(hir::ExistTy { + generics: self.lower_generics(generics, ImplTraitContext::Disallowed), + bounds: self.lower_param_bounds(b, ImplTraitContext::Disallowed), + impl_trait_fn: None, + }), ItemKind::Enum(ref enum_definition, ref generics) => hir::ItemKind::Enum( hir::EnumDef { variants: enum_definition @@ -3037,6 +3043,12 @@ fn lower_impl_item(&mut self, i: &ImplItem) -> hir::ImplItem { self.lower_generics(&i.generics, ImplTraitContext::Disallowed), hir::ImplItemKind::Type(self.lower_ty(ty, ImplTraitContext::Disallowed)), ), + ImplItemKind::Existential(ref bounds) => ( + self.lower_generics(&i.generics, ImplTraitContext::Disallowed), + hir::ImplItemKind::Existential( + self.lower_param_bounds(bounds, ImplTraitContext::Disallowed), + ), + ), ImplItemKind::Macro(..) => panic!("Shouldn't exist any more"), }; @@ -3065,6 +3077,7 @@ fn lower_impl_item_ref(&mut self, i: &ImplItem) -> hir::ImplItemRef { kind: match i.node { ImplItemKind::Const(..) => hir::AssociatedItemKind::Const, ImplItemKind::Type(..) => hir::AssociatedItemKind::Type, + ImplItemKind::Existential(..) => hir::AssociatedItemKind::Existential, ImplItemKind::Method(ref sig, _) => hir::AssociatedItemKind::Method { has_self: sig.decl.has_self(), }, @@ -4331,7 +4344,7 @@ fn lower_visibility( respan(v.span, node) } - fn lower_defaultness(&mut self, d: Defaultness, has_value: bool) -> hir::Defaultness { + fn lower_defaultness(&self, d: Defaultness, has_value: bool) -> hir::Defaultness { match d { Defaultness::Default => hir::Defaultness::Default { has_value: has_value, diff --git a/src/librustc/hir/map/def_collector.rs b/src/librustc/hir/map/def_collector.rs index c1de6c15d41..cab620aeec5 100644 --- a/src/librustc/hir/map/def_collector.rs +++ b/src/librustc/hir/map/def_collector.rs @@ -116,7 +116,7 @@ fn visit_item(&mut self, i: &'a Item) { ItemKind::Impl(..) => DefPathData::Impl, ItemKind::Trait(..) => DefPathData::Trait(i.ident.as_interned_str()), ItemKind::Enum(..) | ItemKind::Struct(..) | ItemKind::Union(..) | - ItemKind::TraitAlias(..) | + ItemKind::TraitAlias(..) | ItemKind::Existential(..) | ItemKind::ExternCrate(..) | ItemKind::ForeignMod(..) | ItemKind::Ty(..) => DefPathData::TypeNs(i.ident.as_interned_str()), ItemKind::Mod(..) if i.ident == keywords::Invalid.ident() => { @@ -250,6 +250,9 @@ fn visit_impl_item(&mut self, ii: &'a ImplItem) { ImplItemKind::Method(..) | ImplItemKind::Const(..) => DefPathData::ValueNs(ii.ident.as_interned_str()), ImplItemKind::Type(..) => DefPathData::AssocTypeInImpl(ii.ident.as_interned_str()), + ImplItemKind::Existential(..) => { + DefPathData::AssocExistentialInImpl(ii.ident.as_interned_str()) + }, ImplItemKind::Macro(..) => return self.visit_macro_invoc(ii.id), }; diff --git a/src/librustc/hir/map/definitions.rs b/src/librustc/hir/map/definitions.rs index 9b1bb3310f2..c4b28fe2c43 100644 --- a/src/librustc/hir/map/definitions.rs +++ b/src/librustc/hir/map/definitions.rs @@ -330,6 +330,8 @@ pub enum DefPathData { AssocTypeInTrait(InternedString), /// An associated type **value** (i.e., in an impl) AssocTypeInImpl(InternedString), + /// An existential associated type **value** (i.e., in an impl) + AssocExistentialInImpl(InternedString), /// Something in the type NS TypeNs(InternedString), /// Something in the value NS @@ -605,6 +607,7 @@ pub fn get_opt_name(&self) -> Option { Trait(name) | AssocTypeInTrait(name) | AssocTypeInImpl(name) | + AssocExistentialInImpl(name) | ValueNs(name) | Module(name) | MacroDef(name) | @@ -631,6 +634,7 @@ pub fn as_interned_str(&self) -> InternedString { Trait(name) | AssocTypeInTrait(name) | AssocTypeInImpl(name) | + AssocExistentialInImpl(name) | ValueNs(name) | Module(name) | MacroDef(name) | diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index d413a544c4e..49231e58cf0 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -470,6 +470,7 @@ pub fn describe_def(&self, node_id: NodeId) -> Option { ImplItemKind::Const(..) => Some(Def::AssociatedConst(def_id)), ImplItemKind::Method(..) => Some(Def::Method(def_id)), ImplItemKind::Type(..) => Some(Def::AssociatedTy(def_id)), + ImplItemKind::Existential(..) => Some(Def::AssociatedExistential(def_id)), } } NodeVariant(variant) => { @@ -1323,7 +1324,7 @@ fn node_id_to_string(map: &Map, id: NodeId, include_id: bool) -> String { ItemKind::ForeignMod(..) => "foreign mod", ItemKind::GlobalAsm(..) => "global asm", ItemKind::Ty(..) => "ty", - ItemKind::Existential(..) => "existential", + ItemKind::Existential(..) => "existential type", ItemKind::Enum(..) => "enum", ItemKind::Struct(..) => "struct", ItemKind::Union(..) => "union", @@ -1347,6 +1348,9 @@ fn node_id_to_string(map: &Map, id: NodeId, include_id: bool) -> String { ImplItemKind::Type(_) => { format!("assoc type {} in {}{}", ii.ident, path_str(), id_str) } + ImplItemKind::Existential(_) => { + format!("assoc existential type {} in {}{}", ii.ident, path_str(), id_str) + } } } Some(NodeTraitItem(ti)) => { diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index c1a885d80bf..b16c97172f1 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -1620,6 +1620,8 @@ pub enum ImplItemKind { Method(MethodSig, BodyId), /// An associated type Type(P), + /// An associated existential type + Existential(GenericBounds), } // Bind a type to an associated type: `A=Foo`. @@ -2080,7 +2082,7 @@ pub enum ItemKind { GlobalAsm(P), /// A type alias, e.g. `type Foo = Bar` Ty(P, Generics), - /// A type alias, e.g. `type Foo = Bar` + /// An existential type definition, e.g. `existential type Foo: Bar;` Existential(ExistTy), /// An enum definition, e.g. `enum Foo {C, D}` Enum(EnumDef, Generics), @@ -2138,6 +2140,7 @@ pub fn generics(&self) -> Option<&Generics> { Some(match *self { ItemKind::Fn(_, _, ref generics, _) | ItemKind::Ty(_, ref generics) | + ItemKind::Existential(ExistTy { ref generics, impl_trait_fn: None, .. }) | ItemKind::Enum(_, ref generics) | ItemKind::Struct(_, ref generics) | ItemKind::Union(_, ref generics) | @@ -2184,6 +2187,7 @@ pub enum AssociatedItemKind { Const, Method { has_self: bool }, Type, + Existential, } #[derive(Clone, RustcEncodable, RustcDecodable, Debug)] diff --git a/src/librustc/hir/print.rs b/src/librustc/hir/print.rs index e637a18d1cd..4499a378be2 100644 --- a/src/librustc/hir/print.rs +++ b/src/librustc/hir/print.rs @@ -627,9 +627,7 @@ pub fn print_item(&mut self, item: &hir::Item) -> io::Result<()> { self.end()? } hir::ItemKind::Ty(ref ty, ref generics) => { - self.ibox(indent_unit)?; - self.ibox(0)?; - self.word_nbsp(&visibility_qualified(&item.vis, "type"))?; + self.head(&visibility_qualified(&item.vis, "type"))?; self.print_name(item.name)?; self.print_generic_params(&generics.params)?; self.end()?; // end the inner ibox @@ -642,9 +640,7 @@ pub fn print_item(&mut self, item: &hir::Item) -> io::Result<()> { self.end()?; // end the outer ibox } hir::ItemKind::Existential(ref exist) => { - self.ibox(indent_unit)?; - self.ibox(0)?; - self.word_nbsp(&visibility_qualified(&item.vis, "existential type"))?; + self.head(&visibility_qualified(&item.vis, "existential type"))?; self.print_name(item.name)?; self.print_generic_params(&exist.generics.params)?; self.end()?; // end the inner ibox @@ -994,6 +990,10 @@ pub fn print_impl_item(&mut self, ii: &hir::ImplItem) -> io::Result<()> { hir::ImplItemKind::Type(ref ty) => { self.print_associated_type(ii.ident, None, Some(ty))?; } + hir::ImplItemKind::Existential(ref bounds) => { + self.word_space("existential")?; + self.print_associated_type(ii.ident, Some(bounds), None)?; + } } self.ann.post(self, NodeSubItem(ii.id)) } diff --git a/src/librustc/ich/impls_hir.rs b/src/librustc/ich/impls_hir.rs index d1fb05ceafb..2ce7749172b 100644 --- a/src/librustc/ich/impls_hir.rs +++ b/src/librustc/ich/impls_hir.rs @@ -701,6 +701,7 @@ fn hash_stable(&self, impl_stable_hash_for!(enum hir::ImplItemKind { Const(t, body), Method(sig, body), + Existential(bounds), Type(t) }); @@ -890,6 +891,7 @@ fn hash_stable(&self, mem::discriminant(self).hash_stable(hcx, hasher); match *self { hir::AssociatedItemKind::Const | + hir::AssociatedItemKind::Existential | hir::AssociatedItemKind::Type => { // No fields to hash. } @@ -997,6 +999,7 @@ fn to_stable_hash_key(&self, TyAlias(def_id), TraitAlias(def_id), AssociatedTy(def_id), + AssociatedExistential(def_id), PrimTy(prim_ty), TyParam(def_id), SelfTy(trait_def_id, impl_def_id), diff --git a/src/librustc/ich/impls_ty.rs b/src/librustc/ich/impls_ty.rs index a3600c04800..cb685f83aba 100644 --- a/src/librustc/ich/impls_ty.rs +++ b/src/librustc/ich/impls_ty.rs @@ -1055,6 +1055,7 @@ fn hash_stable(&self, impl_stable_hash_for!(enum ty::AssociatedKind { Const, Method, + Existential, Type }); diff --git a/src/librustc/infer/anon_types/mod.rs b/src/librustc/infer/anon_types/mod.rs index 2924016670b..5e731871e28 100644 --- a/src/librustc/infer/anon_types/mod.rs +++ b/src/librustc/infer/anon_types/mod.rs @@ -691,10 +691,22 @@ fn instantiate_anon_types_in_map>(&mut self, value: &T) -> // ``` if let Some(anon_node_id) = tcx.hir.as_local_node_id(def_id) { let anon_parent_def_id = match tcx.hir.expect_item(anon_node_id).node { + // impl trait hir::ItemKind::Existential(hir::ExistTy { impl_trait_fn: Some(parent), .. }) => parent, + // named existential types + hir::ItemKind::Existential(hir::ExistTy { + impl_trait_fn: None, + .. + }) if may_define_existential_type( + tcx, + self.parent_def_id, + anon_node_id, + ) => { + return self.fold_anon_ty(ty, def_id, substs); + }, _ => { let anon_parent_node_id = tcx.hir.get_parent(anon_node_id); tcx.hir.local_def_id(anon_parent_node_id) @@ -742,6 +754,10 @@ fn fold_anon_ty( let ty_var = infcx.next_ty_var(TypeVariableOrigin::TypeInference(span)); let predicates_of = tcx.predicates_of(def_id); + debug!( + "instantiate_anon_types: predicates: {:#?}", + predicates_of, + ); let bounds = predicates_of.instantiate(tcx, substs); debug!("instantiate_anon_types: bounds={:?}", bounds); @@ -751,6 +767,18 @@ fn fold_anon_ty( required_region_bounds ); + // make sure that we are in fact defining the *entire* type + // e.g. `existential type Foo: Bar;` needs to be + // defined by a function like `fn foo() -> Foo`. + debug!( + "instantiate_anon_types: param_env: {:#?}", + self.param_env, + ); + debug!( + "instantiate_anon_types: generics: {:#?}", + tcx.generics_of(def_id), + ); + self.anon_types.insert( def_id, AnonTypeDecl { @@ -778,3 +806,25 @@ fn fold_anon_ty( ty_var } } + +/// Whether `anon_node_id` is a sibling or a child of a sibling of `def_id` +pub fn may_define_existential_type( + tcx: TyCtxt, + def_id: DefId, + anon_node_id: ast::NodeId, +) -> bool { + let mut node_id = tcx + .hir + .as_local_node_id(def_id) + .unwrap(); + // named existential types can be defined by any siblings or + // children of siblings + let mod_id = tcx.hir.get_parent(anon_node_id); + // so we walk up the node tree until we hit the root or the parent + // of the anon type + while node_id != mod_id && node_id != ast::CRATE_NODE_ID { + node_id = tcx.hir.get_parent(node_id); + } + // syntactically we are allowed to define the concrete type + node_id == mod_id +} diff --git a/src/librustc/infer/error_reporting/mod.rs b/src/librustc/infer/error_reporting/mod.rs index 8da0dc365b0..1ec9c9489e9 100644 --- a/src/librustc/infer/error_reporting/mod.rs +++ b/src/librustc/infer/error_reporting/mod.rs @@ -279,7 +279,9 @@ fn trait_item_scope_tag(item: &hir::TraitItem) -> &'static str { fn impl_item_scope_tag(item: &hir::ImplItem) -> &'static str { match item.node { hir::ImplItemKind::Method(..) => "method body", - hir::ImplItemKind::Const(..) | hir::ImplItemKind::Type(_) => "associated item", + hir::ImplItemKind::Const(..) | + hir::ImplItemKind::Existential(..) | + hir::ImplItemKind::Type(..) => "associated item", } } diff --git a/src/librustc/middle/dead.rs b/src/librustc/middle/dead.rs index da59bced760..aa1951efba3 100644 --- a/src/librustc/middle/dead.rs +++ b/src/librustc/middle/dead.rs @@ -622,6 +622,7 @@ fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem) { } self.visit_nested_body(body_id) } + hir::ImplItemKind::Existential(..) | hir::ImplItemKind::Type(..) => {} } } diff --git a/src/librustc/middle/reachable.rs b/src/librustc/middle/reachable.rs index a504697008e..7f4b0bb126b 100644 --- a/src/librustc/middle/reachable.rs +++ b/src/librustc/middle/reachable.rs @@ -210,6 +210,7 @@ fn def_id_represents_local_inlined_item(&self, def_id: DefId) -> bool { } } } + hir::ImplItemKind::Existential(..) | hir::ImplItemKind::Type(_) => false, } } @@ -319,6 +320,7 @@ fn propagate_node(&mut self, node: &hir_map::Node<'tcx>, self.visit_nested_body(body) } } + hir::ImplItemKind::Existential(..) | hir::ImplItemKind::Type(_) => {} } } diff --git a/src/librustc/middle/resolve_lifetime.rs b/src/librustc/middle/resolve_lifetime.rs index 05a6cd9c243..39a57e985e8 100644 --- a/src/librustc/middle/resolve_lifetime.rs +++ b/src/librustc/middle/resolve_lifetime.rs @@ -627,6 +627,30 @@ fn visit_ty(&mut self, ty: &'tcx hir::Ty) { } hir::TyKind::Path(hir::QPath::Resolved(None, ref path)) => { if let Def::Existential(exist_ty_did) = path.def { + let id = self.tcx.hir.as_local_node_id(exist_ty_did).unwrap(); + + // Resolve the lifetimes in the bounds to the lifetime defs in the generics. + // `fn foo<'a>() -> impl MyTrait<'a> { ... }` desugars to + // `abstract type MyAnonTy<'b>: MyTrait<'b>;` + // ^ ^ this gets resolved in the scope of + // the exist_ty generics + let (generics, bounds) = match self.tcx.hir.expect_item(id).node { + // named existential types don't need these hacks + hir::ItemKind::Existential(hir::ExistTy{ impl_trait_fn: None, .. }) => { + intravisit::walk_ty(self, ty); + return; + }, + hir::ItemKind::Existential(hir::ExistTy{ + ref generics, + ref bounds, + .. + }) => ( + generics, + bounds, + ), + ref i => bug!("impl Trait pointed to non-existential type?? {:#?}", i), + }; + assert!(exist_ty_did.is_local()); // Resolve the lifetimes that are applied to the existential type. // These are resolved in the current scope. @@ -667,23 +691,6 @@ fn visit_ty(&mut self, ty: &'tcx hir::Ty) { } } - let id = self.tcx.hir.as_local_node_id(exist_ty_did).unwrap(); - - // Resolve the lifetimes in the bounds to the lifetime defs in the generics. - // `fn foo<'a>() -> impl MyTrait<'a> { ... }` desugars to - // `abstract type MyAnonTy<'b>: MyTrait<'b>;` - // ^ ^ this gets resolved in the scope of - // the exist_ty generics - let (generics, bounds) = match self.tcx.hir.expect_item(id).node { - hir::ItemKind::Existential( - hir::ExistTy { ref generics, ref bounds, .. } - ) => ( - generics, - bounds, - ), - ref i => bug!("impl Trait pointed to non-existential type?? {:#?}", i), - }; - // We want to start our early-bound indices at the end of the parent scope, // not including any parent `impl Trait`s. let mut index = self.next_early_index_for_abstract_type(); @@ -847,6 +854,35 @@ fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem) { this.visit_ty(ty); }); } + Existential(ref bounds) => { + let generics = &impl_item.generics; + let mut index = self.next_early_index(); + let mut next_early_index = index; + debug!("visit_ty: index = {}", index); + let lifetimes = generics.params.iter().filter_map(|param| match param.kind { + GenericParamKind::Lifetime { .. } => { + Some(Region::early(&self.tcx.hir, &mut index, param)) + } + GenericParamKind::Type { .. } => { + next_early_index += 1; + None + } + }).collect(); + + let scope = Scope::Binder { + lifetimes, + next_early_index, + s: self.scope, + track_lifetime_uses: true, + abstract_type_parent: true, + }; + self.with(scope, |_old_scope, this| { + this.visit_generics(generics); + for bound in bounds { + this.visit_param_bound(bound); + } + }); + } Const(_, _) => { // Only methods and types support generics. assert!(impl_item.generics.params.is_empty()); @@ -1213,6 +1249,7 @@ fn compute_object_lifetime_defaults( hir::ItemKind::Struct(_, ref generics) | hir::ItemKind::Union(_, ref generics) | hir::ItemKind::Enum(_, ref generics) + | hir::ItemKind::Existential(hir::ExistTy { ref generics, impl_trait_fn: None, .. }) | hir::ItemKind::Ty(_, ref generics) | hir::ItemKind::Trait(_, _, ref generics, ..) => { let result = object_lifetime_defaults_for_item(tcx, generics); diff --git a/src/librustc/ty/item_path.rs b/src/librustc/ty/item_path.rs index 95da68bc9ff..a44962c77b5 100644 --- a/src/librustc/ty/item_path.rs +++ b/src/librustc/ty/item_path.rs @@ -212,6 +212,7 @@ pub fn push_item_path(self, buffer: &mut T, def_id: DefId) data @ DefPathData::Trait(..) | data @ DefPathData::AssocTypeInTrait(..) | data @ DefPathData::AssocTypeInImpl(..) | + data @ DefPathData::AssocExistentialInImpl(..) | data @ DefPathData::ValueNs(..) | data @ DefPathData::Module(..) | data @ DefPathData::TypeParam(..) | diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index 5aa6542a027..2e221424e3c 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -192,6 +192,7 @@ pub struct AssociatedItem { pub enum AssociatedKind { Const, Method, + Existential, Type } @@ -201,6 +202,7 @@ pub fn def(&self) -> Def { AssociatedKind::Const => Def::AssociatedConst(self.def_id), AssociatedKind::Method => Def::Method(self.def_id), AssociatedKind::Type => Def::AssociatedTy(self.def_id), + AssociatedKind::Existential => Def::AssociatedExistential(self.def_id), } } @@ -208,7 +210,8 @@ pub fn def(&self) -> Def { /// for ! pub fn relevant_for_never<'tcx>(&self) -> bool { match self.kind { - AssociatedKind::Const => true, + AssociatedKind::Existential | + AssociatedKind::Const | AssociatedKind::Type => true, // FIXME(canndrew): Be more thorough here, check if any argument is uninhabited. AssociatedKind::Method => !self.method_has_self_argument, @@ -225,6 +228,7 @@ pub fn signature<'a, 'tcx>(&self, tcx: &TyCtxt<'a, 'tcx, 'tcx>) -> String { format!("{}", tcx.fn_sig(self.def_id).skip_binder()) } ty::AssociatedKind::Type => format!("type {};", self.ident), + ty::AssociatedKind::Existential => format!("existential type {};", self.ident), ty::AssociatedKind::Const => { format!("const {}: {:?};", self.ident, tcx.type_of(self.def_id)) } @@ -2491,6 +2495,7 @@ fn associated_item_from_trait_item_ref(self, (ty::AssociatedKind::Method, has_self) } hir::AssociatedItemKind::Type => (ty::AssociatedKind::Type, false), + hir::AssociatedItemKind::Existential => bug!("only impls can have existentials"), }; AssociatedItem { @@ -2516,6 +2521,7 @@ fn associated_item_from_impl_item_ref(self, (ty::AssociatedKind::Method, has_self) } hir::AssociatedItemKind::Type => (ty::AssociatedKind::Type, false), + hir::AssociatedItemKind::Existential => (ty::AssociatedKind::Existential, false), }; AssociatedItem { @@ -2857,8 +2863,15 @@ fn param_env<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, // The param_env of an existential type is its parent's param_env if let Some(Def::Existential(_)) = tcx.describe_def(def_id) { - let parent = tcx.parent_def_id(def_id).expect("impl trait item w/o a parent"); - return param_env(tcx, parent); + if let Some(node_id) = tcx.hir.as_local_node_id(def_id) { + if let hir::map::NodeItem(item) = tcx.hir.get(node_id) { + if let hir::ItemKind::Existential(ref exist_ty) = item.node { + if let Some(parent) = exist_ty.impl_trait_fn { + return param_env(tcx, parent); + } + } + } + } } // Compute the bounds on Self and the type parameters. diff --git a/src/librustc/ty/sty.rs b/src/librustc/ty/sty.rs index 934bf9a416a..dd381888243 100644 --- a/src/librustc/ty/sty.rs +++ b/src/librustc/ty/sty.rs @@ -158,8 +158,10 @@ pub enum TypeVariants<'tcx> { TyProjection(ProjectionTy<'tcx>), /// Anonymized (`impl Trait`) type found in a return type. - /// The DefId comes from the `impl Trait` ast::Ty node, and the - /// substitutions are for the generics of the function in question. + /// The DefId comes either from + /// * the `impl Trait` ast::Ty node, + /// * or the `existential type` declaration + /// The substitutions are for the generics of the function in question. /// After typeck, the concrete type can be found in the `types` map. TyAnon(DefId, &'tcx Substs<'tcx>), diff --git a/src/librustc/util/ppaux.rs b/src/librustc/util/ppaux.rs index c17fd79df2a..c67453d2b20 100644 --- a/src/librustc/util/ppaux.rs +++ b/src/librustc/util/ppaux.rs @@ -271,6 +271,7 @@ fn parameterized(&mut self, match key.disambiguated_data.data { DefPathData::AssocTypeInTrait(_) | DefPathData::AssocTypeInImpl(_) | + DefPathData::AssocExistentialInImpl(_) | DefPathData::Trait(_) | DefPathData::TypeNs(_) => { break; @@ -1081,6 +1082,20 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { } ty::tls::with(|tcx| { + let def_key = tcx.def_key(def_id); + if let Some(name) = def_key.disambiguated_data.data.get_opt_name() { + write!(f, "{}", name)?; + let mut substs = substs.iter(); + if let Some(first) = substs.next() { + write!(f, "::<")?; + write!(f, "{}", first)?; + for subst in substs { + write!(f, ", {}", subst)?; + } + write!(f, ">")?; + } + return Ok(()); + } // Grab the "TraitA + TraitB" from `impl TraitA + TraitB`, // by looking up the projections associated with the def_id. let predicates_of = tcx.predicates_of(def_id); diff --git a/src/librustc_incremental/persist/dirty_clean.rs b/src/librustc_incremental/persist/dirty_clean.rs index 39e674a6095..7f2da5a326a 100644 --- a/src/librustc_incremental/persist/dirty_clean.rs +++ b/src/librustc_incremental/persist/dirty_clean.rs @@ -417,6 +417,7 @@ fn auto_labels(&mut self, item_id: ast::NodeId, attr: &Attribute) -> (&'static s ImplItemKind::Method(..) => ("NodeImplItem", LABELS_FN_IN_IMPL), ImplItemKind::Const(..) => ("NodeImplConst", LABELS_CONST_IN_IMPL), ImplItemKind::Type(..) => ("NodeImplType", LABELS_CONST_IN_IMPL), + ImplItemKind::Existential(..) => ("NodeImplType", LABELS_CONST_IN_IMPL), } }, _ => self.tcx.sess.span_fatal( diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index 8a674449880..af40f3c64ed 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -461,6 +461,7 @@ fn check_impl_item(&mut self, cx: &LateContext, impl_item: &hir::ImplItem) { hir::ImplItemKind::Const(..) => "an associated constant", hir::ImplItemKind::Method(..) => "a method", hir::ImplItemKind::Type(_) => "an associated type", + hir::ImplItemKind::Existential(_) => "an associated existential type", }; self.check_missing_docs_attrs(cx, Some(impl_item.id), diff --git a/src/librustc_metadata/decoder.rs b/src/librustc_metadata/decoder.rs index b8c64383950..ab566654c38 100644 --- a/src/librustc_metadata/decoder.rs +++ b/src/librustc_metadata/decoder.rs @@ -421,6 +421,7 @@ fn to_def(&self, did: DefId) -> Option { EntryKind::Type => Def::TyAlias(did), EntryKind::Existential => Def::Existential(did), EntryKind::AssociatedType(_) => Def::AssociatedTy(did), + EntryKind::AssociatedExistential(_) => Def::AssociatedExistential(did), EntryKind::Mod(_) => Def::Mod(did), EntryKind::Variant(_) => Def::Variant(did), EntryKind::Trait(_) => Def::Trait(did), diff --git a/src/librustc_metadata/encoder.rs b/src/librustc_metadata/encoder.rs index b9cb97ed7d0..7ed991e0de3 100644 --- a/src/librustc_metadata/encoder.rs +++ b/src/librustc_metadata/encoder.rs @@ -840,6 +840,8 @@ fn encode_info_for_trait_item(&mut self, def_id: DefId) -> Entry<'tcx> { })) } ty::AssociatedKind::Type => EntryKind::AssociatedType(container), + ty::AssociatedKind::Existential => + span_bug!(ast_item.span, "existential type in trait"), }; Entry { @@ -863,6 +865,7 @@ fn encode_info_for_trait_item(&mut self, def_id: DefId) -> Entry<'tcx> { None } } + ty::AssociatedKind::Existential => unreachable!(), }, inherent_impls: LazySeq::empty(), variances: if trait_item.kind == ty::AssociatedKind::Method { @@ -933,6 +936,7 @@ fn encode_info_for_impl_item(&mut self, def_id: DefId) -> Entry<'tcx> { has_self: impl_item.method_has_self_argument, })) } + ty::AssociatedKind::Existential => EntryKind::AssociatedExistential(container), ty::AssociatedKind::Type => EntryKind::AssociatedType(container) }; @@ -948,6 +952,7 @@ fn encode_info_for_impl_item(&mut self, def_id: DefId) -> Entry<'tcx> { let always_encode_mir = self.tcx.sess.opts.debugging_opts.always_encode_mir; needs_inline || is_const_fn || always_encode_mir }, + hir::ImplItemKind::Existential(..) | hir::ImplItemKind::Type(..) => false, }; diff --git a/src/librustc_metadata/schema.rs b/src/librustc_metadata/schema.rs index 430cbf9b529..d7c54cbc81d 100644 --- a/src/librustc_metadata/schema.rs +++ b/src/librustc_metadata/schema.rs @@ -321,6 +321,7 @@ pub enum EntryKind<'tcx> { Impl(Lazy>), Method(Lazy>), AssociatedType(AssociatedContainer), + AssociatedExistential(AssociatedContainer), AssociatedConst(AssociatedContainer, ConstQualif, Lazy), } @@ -382,6 +383,7 @@ fn hash_stable(&self, EntryKind::Method(ref method_data) => { method_data.hash_stable(hcx, hasher); } + EntryKind::AssociatedExistential(associated_container) | EntryKind::AssociatedType(associated_container) => { associated_container.hash_stable(hcx, hasher); } diff --git a/src/librustc_privacy/lib.rs b/src/librustc_privacy/lib.rs index ab383287773..7b13c98b31d 100644 --- a/src/librustc_privacy/lib.rs +++ b/src/librustc_privacy/lib.rs @@ -237,7 +237,7 @@ fn visit_item(&mut self, item: &'tcx hir::Item) { hir::ItemKind::Use(..) => {} // The interface is empty hir::ItemKind::GlobalAsm(..) => {} - hir::ItemKind::Existential(..) => { + hir::ItemKind::Existential(hir::ExistTy { impl_trait_fn: Some(_), .. }) => { if item_level.is_some() { // Reach the (potentially private) type and the API being exposed self.reach(item.id).ty().predicates(); @@ -245,6 +245,7 @@ fn visit_item(&mut self, item: &'tcx hir::Item) { } // Visit everything hir::ItemKind::Const(..) | hir::ItemKind::Static(..) | + hir::ItemKind::Existential(..) | hir::ItemKind::Fn(..) | hir::ItemKind::Ty(..) => { if item_level.is_some() { self.reach(item.id).generics().predicates().ty(); @@ -1165,6 +1166,7 @@ fn visit_item(&mut self, item: &'tcx hir::Item) { hir::ImplItemKind::Method(..) => { self.access_levels.is_reachable(impl_item.id) } + hir::ImplItemKind::Existential(..) | hir::ImplItemKind::Type(_) => false, } }); @@ -1566,7 +1568,7 @@ fn visit_item(&mut self, item: &'tcx hir::Item) { hir::ItemKind::Use(..) => {} // No subitems hir::ItemKind::GlobalAsm(..) => {} - hir::ItemKind::Existential(..) => { + hir::ItemKind::Existential(hir::ExistTy { impl_trait_fn: Some(_), .. }) => { // Check the traits being exposed, as they're separate, // e.g. `impl Iterator` has two predicates, // `X: Iterator` and `::Item == T`, @@ -1577,6 +1579,7 @@ fn visit_item(&mut self, item: &'tcx hir::Item) { } // Subitems of these items have inherited publicity hir::ItemKind::Const(..) | hir::ItemKind::Static(..) | hir::ItemKind::Fn(..) | + hir::ItemKind::Existential(..) | hir::ItemKind::Ty(..) => { self.check(item.id, item_visibility).generics().predicates().ty(); diff --git a/src/librustc_resolve/build_reduced_graph.rs b/src/librustc_resolve/build_reduced_graph.rs index 29312912a24..e00919547fc 100644 --- a/src/librustc_resolve/build_reduced_graph.rs +++ b/src/librustc_resolve/build_reduced_graph.rs @@ -361,6 +361,11 @@ fn build_reduced_graph_for_item(&mut self, item: &Item, expansion: Mark) { self.define(parent, ident, TypeNS, (def, vis, sp, expansion)); } + ItemKind::Existential(_, _) => { + let def = Def::Existential(self.definitions.local_def_id(item.id)); + self.define(parent, ident, TypeNS, (def, vis, sp, expansion)); + } + ItemKind::Enum(ref enum_definition, _) => { let def = Def::Enum(self.definitions.local_def_id(item.id)); let module_kind = ModuleKind::Def(def, ident.name); diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index f388b911feb..617ae4b787f 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -207,7 +207,7 @@ fn resolve_struct_error<'sess, 'a>(resolver: &'sess Resolver, Def::AssociatedTy(..) | Def::PrimTy(..) | Def::Fn(..) | Def::Const(..) | Def::Static(..) | Def::StructCtor(..) | Def::VariantCtor(..) | Def::Method(..) | Def::AssociatedConst(..) | Def::Local(..) | Def::Upvar(..) | Def::Label(..) | - Def::Existential(..) | + Def::Existential(..) | Def::AssociatedExistential(..) | Def::Macro(..) | Def::GlobalAsm(..) | Def::Err => bug!("TypeParametersFromOuterFunction should only be used with Def::SelfTy or \ Def::TyParam") @@ -535,6 +535,7 @@ fn is_expected(self, def: Def) -> bool { Def::Struct(..) | Def::Union(..) | Def::Enum(..) | Def::Trait(..) | Def::TyAlias(..) | Def::AssociatedTy(..) | Def::PrimTy(..) | Def::TyParam(..) | Def::SelfTy(..) | + Def::Existential(..) | Def::TyForeign(..) => true, _ => false, }, @@ -2148,6 +2149,7 @@ fn resolve_item(&mut self, item: &Item) { match item.node { ItemKind::Enum(_, ref generics) | ItemKind::Ty(_, ref generics) | + ItemKind::Existential(_, ref generics) | ItemKind::Struct(_, ref generics) | ItemKind::Union(_, ref generics) | ItemKind::Fn(_, _, ref generics, _) => { @@ -2486,6 +2488,18 @@ fn resolve_implementation(&mut self, this.visit_ty(ty); } + ImplItemKind::Existential(ref bounds) => { + // If this is a trait impl, ensure the type + // exists in trait + this.check_trait_item(impl_item.ident, + TypeNS, + impl_item.span, + |n, s| TypeNotMemberOfTrait(n, s)); + + for bound in bounds { + this.visit_param_bound(bound); + } + } ImplItemKind::Macro(_) => panic!("unexpanded macro in resolve!"), } diff --git a/src/librustc_save_analysis/dump_visitor.rs b/src/librustc_save_analysis/dump_visitor.rs index 34dcdfb757f..58189ee0a2f 100644 --- a/src/librustc_save_analysis/dump_visitor.rs +++ b/src/librustc_save_analysis/dump_visitor.rs @@ -1238,6 +1238,16 @@ fn process_impl_item(&mut self, impl_item: &'l ast::ImplItem, impl_id: DefId) { // trait. self.visit_ty(ty) } + ast::ImplItemKind::Existential(ref bounds) => { + // FIXME uses of the assoc type should ideally point to this + // 'def' and the name here should be a ref to the def in the + // trait. + for bound in bounds.iter() { + if let ast::GenericBound::Trait(ref trait_ref, _) = *bound { + self.process_path(trait_ref.trait_ref.ref_id, &trait_ref.trait_ref.path) + } + } + } ast::ImplItemKind::Macro(_) => {} } } @@ -1477,6 +1487,36 @@ fn visit_item(&mut self, item: &'l ast::Item) { self.visit_ty(&ty); self.process_generic_params(ty_params, item.span, &qualname, item.id); } + Existential(ref _bounds, ref ty_params) => { + let qualname = format!("::{}", self.tcx.node_path_str(item.id)); + // FIXME do something with _bounds + let value = String::new(); + let sub_span = self.span.sub_span_after_keyword(item.span, keywords::Type); + if !self.span.filter_generated(sub_span, item.span) { + let span = self.span_from_span(sub_span.expect("No span found for typedef")); + let id = ::id_from_node_id(item.id, &self.save_ctxt); + + self.dumper.dump_def( + &access_from!(self.save_ctxt, item), + Def { + kind: DefKind::Type, + id, + span, + name: item.ident.to_string(), + qualname: qualname.clone(), + value, + parent: None, + children: vec![], + decl_id: None, + docs: self.save_ctxt.docs_for_attrs(&item.attrs), + sig: sig::item_signature(item, &self.save_ctxt), + attributes: lower_attributes(item.attrs.clone(), &self.save_ctxt), + }, + ); + } + + self.process_generic_params(ty_params, item.span, &qualname, item.id); + } Mac(_) => (), _ => visit::walk_item(self, item), } diff --git a/src/librustc_save_analysis/lib.rs b/src/librustc_save_analysis/lib.rs index f2620c04754..c84f194f023 100644 --- a/src/librustc_save_analysis/lib.rs +++ b/src/librustc_save_analysis/lib.rs @@ -749,6 +749,7 @@ fn fn_type(path: &ast::Path) -> bool { HirDef::TyAlias(def_id) | HirDef::TyForeign(def_id) | HirDef::TraitAlias(def_id) | + HirDef::AssociatedExistential(def_id) | HirDef::AssociatedTy(def_id) | HirDef::Trait(def_id) | HirDef::Existential(def_id) | diff --git a/src/librustc_save_analysis/sig.rs b/src/librustc_save_analysis/sig.rs index 70feba1eff8..13032562879 100644 --- a/src/librustc_save_analysis/sig.rs +++ b/src/librustc_save_analysis/sig.rs @@ -444,6 +444,18 @@ fn make(&self, offset: usize, _parent_id: Option, scx: &SaveContext) -> refs: vec![], }) } + ast::ItemKind::Existential(ref bounds, ref generics) => { + let text = "existential 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(": "); + 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)?; diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index f85e7b06858..60aea074f24 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -1035,6 +1035,26 @@ pub fn def_to_ty(&self, let span = path.span; match path.def { + Def::Existential(did) => { + // check for desugared impl trait + if let Some(node_id) = tcx.hir.as_local_node_id(did) { + if let hir::map::NodeItem(item) = tcx.hir.get(node_id) { + if let hir::ItemKind::Existential(ref exist_ty) = item.node { + if exist_ty.impl_trait_fn.is_some() { + let lifetimes = &path.segments[0].args.as_ref().unwrap().args; + return self.impl_trait_ty_to_ty(did, lifetimes); + } + } + } + } + let item_segment = path.segments.split_last().unwrap(); + self.prohibit_generics(item_segment.1); + let substs = self.ast_path_substs_for_ty(span, did, item_segment.0); + self.normalize_ty( + span, + tcx.mk_anon(did, substs), + ) + } Def::Enum(did) | Def::TyAlias(did) | Def::Struct(did) | Def::Union(did) | Def::TyForeign(did) => { assert_eq!(opt_self_ty, None); @@ -1095,11 +1115,6 @@ pub fn def_to_ty(&self, hir::TyStr => tcx.mk_str() } } - Def::Existential(exist_ty_did) => { - assert!(exist_ty_did.is_local()); - let lifetimes = &path.segments[0].args.as_ref().unwrap().args; - self.impl_trait_ty_to_ty(exist_ty_did, lifetimes) - } Def::Err => { self.set_tainted_by_errors(); return self.tcx().types.err; diff --git a/src/librustc_typeck/check/method/probe.rs b/src/librustc_typeck/check/method/probe.rs index bee866db9e4..301072778d0 100644 --- a/src/librustc_typeck/check/method/probe.rs +++ b/src/librustc_typeck/check/method/probe.rs @@ -1332,6 +1332,7 @@ fn has_applicable_self(&self, item: &ty::AssociatedItem) -> bool { match self.mode { Mode::MethodCall => item.method_has_self_argument, Mode::Path => match item.kind { + ty::AssociatedKind::Existential | ty::AssociatedKind::Type => false, ty::AssociatedKind::Method | ty::AssociatedKind::Const => true }, diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 9f83f8a00b1..e74652ff932 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -1410,6 +1410,7 @@ fn check_specialization_validity<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, let kind = match impl_item.node { hir::ImplItemKind::Const(..) => ty::AssociatedKind::Const, hir::ImplItemKind::Method(..) => ty::AssociatedKind::Method, + hir::ImplItemKind::Existential(..) => ty::AssociatedKind::Existential, hir::ImplItemKind::Type(_) => ty::AssociatedKind::Type }; @@ -1503,6 +1504,7 @@ fn check_impl_items_against_trait<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, err.emit() } } + hir::ImplItemKind::Existential(..) | hir::ImplItemKind::Type(_) => { if ty_trait_item.kind == ty::AssociatedKind::Type { if ty_trait_item.defaultness.has_value() { diff --git a/src/librustc_typeck/check/wfcheck.rs b/src/librustc_typeck/check/wfcheck.rs index d876f41ce13..df8323f8513 100644 --- a/src/librustc_typeck/check/wfcheck.rs +++ b/src/librustc_typeck/check/wfcheck.rs @@ -13,11 +13,12 @@ use hir::def_id::DefId; use rustc::traits::{self, ObligationCauseCode}; -use rustc::ty::{self, Lift, Ty, TyCtxt, GenericParamDefKind}; -use rustc::ty::subst::Substs; +use rustc::ty::{self, Lift, Ty, TyCtxt, GenericParamDefKind, TypeFoldable}; +use rustc::ty::subst::{Subst, Substs}; use rustc::ty::util::ExplicitSelf; use rustc::util::nodemap::{FxHashSet, FxHashMap}; use rustc::middle::lang_items; +use rustc::infer::anon_types::may_define_existential_type; use syntax::ast; use syntax::feature_gate::{self, GateIssue}; @@ -209,6 +210,10 @@ fn check_associated_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, fcx.register_wf_obligation(ty, span, code.clone()); } } + ty::AssociatedKind::Existential => { + // FIXME(oli-obk) implement existential types in trait impls + unimplemented!() + } } implied_bounds @@ -282,7 +287,7 @@ fn check_type_defn<'a, 'tcx, F>(tcx: TyCtxt<'a, 'tcx, 'tcx>, } } - check_where_clauses(tcx, fcx, item.span, def_id); + check_where_clauses(tcx, fcx, item.span, def_id, None); vec![] // no implied bounds in a struct def'n }); @@ -291,7 +296,7 @@ fn check_type_defn<'a, 'tcx, F>(tcx: TyCtxt<'a, 'tcx, 'tcx>, fn check_trait<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, item: &hir::Item) { let trait_def_id = tcx.hir.local_def_id(item.id); for_item(tcx, item).with_fcx(|fcx, _| { - check_where_clauses(tcx, fcx, item.span, trait_def_id); + check_where_clauses(tcx, fcx, item.span, trait_def_id, None); vec![] }); } @@ -357,7 +362,7 @@ fn check_impl<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, } } - check_where_clauses(tcx, fcx, item.span, item_def_id); + check_where_clauses(tcx, fcx, item.span, item_def_id, None); fcx.impl_implied_bounds(item_def_id, item.span) }); @@ -369,6 +374,7 @@ fn check_where_clauses<'a, 'gcx, 'fcx, 'tcx>( fcx: &FnCtxt<'fcx, 'gcx, 'tcx>, span: Span, def_id: DefId, + return_ty: Option>, ) { use ty::subst::Subst; use rustc::ty::TypeFoldable; @@ -482,7 +488,12 @@ fn visit_region(&mut self, _: ty::Region<'tcx>) -> bool { traits::Obligation::new(cause, fcx.param_env, pred) }); - let predicates = predicates.instantiate_identity(fcx.tcx); + let mut predicates = predicates.instantiate_identity(fcx.tcx); + + if let Some(return_ty) = return_ty { + predicates.predicates.extend(check_existential_types(tcx, fcx, def_id, span, return_ty)); + } + let predicates = fcx.normalize_associated_types_in(span, &predicates); debug!("check_where_clauses: predicates={:?}", predicates.predicates); @@ -521,7 +532,79 @@ fn check_fn_or_method<'a, 'fcx, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'gcx>, // FIXME(#25759) return types should not be implied bounds implied_bounds.push(sig.output()); - check_where_clauses(tcx, fcx, span, def_id); + check_where_clauses(tcx, fcx, span, def_id, Some(sig.output())); +} + +fn check_existential_types<'a, 'fcx, 'gcx, 'tcx>( + tcx: TyCtxt<'a, 'gcx, 'gcx>, + fcx: &FnCtxt<'fcx, 'gcx, 'tcx>, + fn_def_id: DefId, + span: Span, + ty: Ty<'tcx>, +) -> Vec> { + trace!("check_existential_types: {:?}, {:?}", ty, ty.sty); + let mut substituted_predicates = Vec::new(); + ty.fold_with(&mut ty::fold::BottomUpFolder { + tcx: fcx.tcx, + fldop: |ty| { + if let ty::TyAnon(def_id, substs) = ty.sty { + trace!("check_existential_types: anon_ty, {:?}, {:?}", def_id, substs); + let anon_node_id = tcx.hir.as_local_node_id(def_id).unwrap(); + if may_define_existential_type(tcx, fn_def_id, anon_node_id) { + let generics = tcx.generics_of(def_id); + trace!("check_existential_types may define. Generics: {:#?}", generics); + for (subst, param) in substs.iter().zip(&generics.params) { + if let ty::subst::UnpackedKind::Type(ty) = subst.unpack() { + match ty.sty { + ty::TyParam(..) => {}, + // prevent `fn foo() -> Foo` from being defining + _ => { + tcx + .sess + .struct_span_err( + span, + "non-defining existential type use in defining scope", + ) + .span_note( + tcx.def_span(param.def_id), + &format!( + "used non-generic type {} for generic parameter", + ty, + ), + ) + .emit(); + return tcx.types.err; + }, + } // match ty + } // if let Type = subst + } // for (subst, param) + } // if may_define_existential_type + + // now register the bounds on the parameters of the existential type + // so the parameters given by the function need to fulfil them + // ```rust + // existential type Foo: 'static; + // fn foo() -> Foo { .. *} + // ``` + // becomes + // ```rust + // existential type Foo: 'static; + // fn foo() -> Foo { .. *} + // ``` + let predicates = tcx.predicates_of(def_id); + trace!("check_existential_types may define. adding predicates: {:#?}", predicates); + for &pred in predicates.predicates.iter() { + let substituted_pred = pred.subst(fcx.tcx, substs); + // Avoid duplication of predicates that contain no parameters, for example. + if !predicates.predicates.contains(&substituted_pred) { + substituted_predicates.push(substituted_pred); + } + } + } // if let TyAnon + ty + }, + }); + substituted_predicates } fn check_method_receiver<'fcx, 'gcx, 'tcx>(fcx: &FnCtxt<'fcx, 'gcx, 'tcx>, diff --git a/src/librustc_typeck/check/writeback.rs b/src/librustc_typeck/check/writeback.rs index 3207ac44948..d82ad0d180b 100644 --- a/src/librustc_typeck/check/writeback.rs +++ b/src/librustc_typeck/check/writeback.rs @@ -17,9 +17,10 @@ use rustc::hir::def_id::{DefId, DefIndex}; use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc::infer::InferCtxt; +use rustc::ty::subst::UnpackedKind; use rustc::ty::{self, Ty, TyCtxt}; use rustc::ty::adjustment::{Adjust, Adjustment}; -use rustc::ty::fold::{TypeFoldable, TypeFolder}; +use rustc::ty::fold::{TypeFoldable, TypeFolder, BottomUpFolder}; use rustc::util::nodemap::DefIdSet; use syntax::ast; use syntax_pos::Span; @@ -388,11 +389,65 @@ fn visit_anon_types(&mut self, span: Span) { for (&def_id, anon_defn) in self.fcx.anon_types.borrow().iter() { let node_id = self.tcx().hir.as_local_node_id(def_id).unwrap(); let instantiated_ty = self.resolve(&anon_defn.concrete_ty, &node_id); - let definition_ty = self.fcx.infer_anon_definition_from_instantiation( + let mut definition_ty = self.fcx.infer_anon_definition_from_instantiation( def_id, anon_defn, instantiated_ty, ); + + let generics = self.tcx().generics_of(def_id); + + // named existential type, not an impl trait + if generics.parent.is_none() { + // prevent + // * `fn foo() -> Foo` + // * `fn foo() -> Foo` + // from being defining + + // Also replace all generic params with the ones from the existential type + // definition so + // ```rust + // existential type Foo: 'static; + // fn foo() -> Foo { .. } + // ``` + // figures out the concrete type with `U`, but the stored type is with `T` + definition_ty = definition_ty.fold_with(&mut BottomUpFolder { + tcx: self.tcx().global_tcx(), + fldop: |ty| { + // find a type parameter + if let ty::TyParam(..) = ty.sty { + // look it up in the substitution list + assert_eq!(anon_defn.substs.len(), generics.params.len()); + for (subst, param) in anon_defn.substs.iter().zip(&generics.params) { + if let UnpackedKind::Type(subst) = subst.unpack() { + if subst == ty { + // found it in the substitution list, replace with the + // parameter from the existential type + return self + .tcx() + .global_tcx() + .mk_ty_param(param.index, param.name); + } + } + } + self.tcx() + .sess + .struct_span_err( + span, + &format!( + "type parameter `{}` is part of concrete type but not used \ + in parameter list for existential type", + ty, + ), + ) + .emit(); + return self.tcx().types.err; + } + ty + }, + }); + } + let old = self.tables.concrete_existential_types.insert(def_id, definition_ty); if let Some(old) = old { if old != definition_ty { diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index 4b628d6ffad..ab81cb8788f 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -269,6 +269,7 @@ fn type_param_predicates<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, ItemKind::Fn(.., ref generics, _) | ItemKind::Impl(_, _, _, ref generics, ..) | ItemKind::Ty(_, ref generics) | + ItemKind::Existential(ExistTy { ref generics, impl_trait_fn: None, ..}) | ItemKind::Enum(_, ref generics) | ItemKind::Struct(_, ref generics) | ItemKind::Union(_, ref generics) => generics, @@ -419,7 +420,11 @@ fn convert_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, item_id: ast::NodeId) { convert_variant_ctor(tcx, struct_def.id()); } }, - hir::ItemKind::Existential(..) => {} + + // Desugared from `impl Trait` -> visited by the function's return type + hir::ItemKind::Existential(hir::ExistTy { impl_trait_fn: Some(_), .. }) => {} + + hir::ItemKind::Existential(..) | hir::ItemKind::Ty(..) | hir::ItemKind::Static(..) | hir::ItemKind::Const(..) | @@ -1002,6 +1007,13 @@ fn generics_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, }) } +fn report_assoc_ty_on_inherent_impl<'a, 'tcx>( + tcx: TyCtxt<'a, 'tcx, 'tcx>, + span: Span, +) { + span_err!(tcx.sess, span, E0202, "associated types are not allowed in inherent impls"); +} + fn type_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Ty<'tcx> { @@ -1034,10 +1046,16 @@ fn type_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, tcx.mk_fn_def(def_id, substs) } ImplItemKind::Const(ref ty, _) => icx.to_ty(ty), + ImplItemKind::Existential(ref _bounds) => { + if tcx.impl_trait_ref(tcx.hir.get_parent_did(node_id)).is_none() { + report_assoc_ty_on_inherent_impl(tcx, item.span); + } + // FIXME(oli-obk) implement existential types in trait impls + unimplemented!() + } ImplItemKind::Type(ref ty) => { if tcx.impl_trait_ref(tcx.hir.get_parent_did(node_id)).is_none() { - span_err!(tcx.sess, item.span, E0202, - "associated types are not allowed in inherent impls"); + report_assoc_ty_on_inherent_impl(tcx, item.span); } icx.to_ty(ty) @@ -1062,8 +1080,9 @@ fn type_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, let substs = Substs::identity_for_item(tcx, def_id); tcx.mk_adt(def, substs) } - // this is only reachable once we have named existential types - ItemKind::Existential(hir::ExistTy { impl_trait_fn: None, .. }) => unimplemented!(), + ItemKind::Existential(hir::ExistTy { impl_trait_fn: None, .. }) => { + find_existential_constraints(tcx, def_id) + }, // existential types desugared from impl Trait ItemKind::Existential(hir::ExistTy { impl_trait_fn: Some(owner), .. }) => { tcx.typeck_tables_of(owner).concrete_existential_types[&def_id] @@ -1153,6 +1172,95 @@ fn type_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, } } +fn find_existential_constraints<'a, 'tcx>( + tcx: TyCtxt<'a, 'tcx, 'tcx>, + def_id: DefId, +) -> ty::Ty<'tcx> { + use rustc::hir::map::*; + use rustc::hir::*; + + struct ConstraintLocator<'a, 'tcx: 'a> { + tcx: TyCtxt<'a, 'tcx, 'tcx>, + def_id: DefId, + found: Option<(Span, ty::Ty<'tcx>)>, + } + impl<'a, 'tcx> ConstraintLocator<'a, 'tcx> { + fn check(&mut self, node_id: ast::NodeId) { + let def_id = self.tcx.hir.local_def_id(node_id); + // don't try to check items that cannot possibly constrain the type + if !self.tcx.has_typeck_tables(def_id) { + return; + } + let ty = self + .tcx + .typeck_tables_of(def_id) + .concrete_existential_types + .get(&self.def_id) + .cloned(); + if let Some(ty) = ty { + // FIXME(oli-obk): trace the actual span from inference to improve errors + let span = self.tcx.def_span(def_id); + if let Some((prev_span, prev_ty)) = self.found { + if ty != prev_ty { + // found different concrete types for the existential type + let mut err = self.tcx.sess.struct_span_err( + span, + "defining existential type use differs from previous", + ); + err.span_note(prev_span, "previous use here"); + err.emit(); + } + } else { + self.found = Some((span, ty)); + } + } + } + } + impl<'a, 'tcx> intravisit::Visitor<'tcx> for ConstraintLocator<'a, 'tcx> { + fn nested_visit_map<'this>(&'this mut self) -> intravisit::NestedVisitorMap<'this, 'tcx> { + intravisit::NestedVisitorMap::All(&self.tcx.hir) + } + fn visit_item(&mut self, it: &'tcx Item) { + // the existential type itself or its children are not within its reveal scope + if self.tcx.hir.local_def_id(it.id) != self.def_id { + self.check(it.id); + intravisit::walk_item(self, it); + } + } + fn visit_impl_item(&mut self, it: &'tcx ImplItem) { + // the existential type itself or its children are not within its reveal scope + if self.tcx.hir.local_def_id(it.id) != self.def_id { + self.check(it.id); + intravisit::walk_impl_item(self, it); + } + } + fn visit_trait_item(&mut self, it: &'tcx TraitItem) { + self.check(it.id); + intravisit::walk_trait_item(self, it); + } + } + let mut locator = ConstraintLocator { def_id, tcx, found: None }; + let node_id = tcx.hir.as_local_node_id(def_id).unwrap(); + let parent = tcx.hir.get_parent(node_id); + if parent == ast::CRATE_NODE_ID { + intravisit::walk_crate(&mut locator, tcx.hir.krate()); + } else { + match tcx.hir.get(parent) { + NodeItem(ref it) => intravisit::walk_item(&mut locator, it), + NodeImplItem(ref it) => intravisit::walk_impl_item(&mut locator, it), + other => bug!("{:?} is not a valid parent of an existential type item", other), + } + } + match locator.found { + Some((_, ty)) => ty, + None => { + let span = tcx.def_span(def_id); + tcx.sess.span_err(span, "could not find defining uses"); + tcx.types.err + } + } +} + fn fn_sig<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> ty::PolyFnSig<'tcx> { @@ -1366,6 +1474,9 @@ fn explicit_predicates_of<'a, 'tcx>( let icx = ItemCtxt::new(tcx, def_id); let no_generics = hir::Generics::empty(); + + let mut predicates = vec![]; + let ast_generics = match node { NodeTraitItem(item) => { &item.generics @@ -1391,23 +1502,28 @@ fn explicit_predicates_of<'a, 'tcx>( is_trait = Some((ty::TraitRef::identity(tcx, def_id), items)); generics } - ItemKind::Existential(ref exist_ty) => { + ItemKind::Existential(ExistTy { ref bounds, impl_trait_fn, ref generics }) => { let substs = Substs::identity_for_item(tcx, def_id); let anon_ty = tcx.mk_anon(def_id, substs); // Collect the bounds, i.e. the `A+B+'c` in `impl A+B+'c`. let bounds = compute_bounds(&icx, anon_ty, - &exist_ty.bounds, + bounds, SizedByDefault::Yes, tcx.def_span(def_id)); - let predicates = bounds.predicates(tcx, anon_ty); - - return ty::GenericPredicates { - parent: None, - predicates: predicates - }; + if impl_trait_fn.is_some() { + // impl Trait + return ty::GenericPredicates { + parent: None, + predicates: bounds.predicates(tcx, anon_ty), + }; + } else { + // named existential types + predicates.extend(bounds.predicates(tcx, anon_ty)); + generics + } } _ => &no_generics, @@ -1429,8 +1545,6 @@ fn explicit_predicates_of<'a, 'tcx>( let parent_count = generics.parent_count as u32; let has_own_self = generics.has_self && parent_count == 0; - let mut predicates = vec![]; - // Below we'll consider the bounds on the type parameters (including `Self`) // and the explicit where-clauses, but to get the full set of predicates // on a trait we need to add in the supertrait bounds and bounds found on diff --git a/src/librustc_typeck/namespace.rs b/src/librustc_typeck/namespace.rs index 6f0e46b3afe..690bf1c550c 100644 --- a/src/librustc_typeck/namespace.rs +++ b/src/librustc_typeck/namespace.rs @@ -21,6 +21,7 @@ pub enum Namespace { impl From for Namespace { fn from(a_kind: ty::AssociatedKind) -> Self { match a_kind { + ty::AssociatedKind::Existential | ty::AssociatedKind::Type => Namespace::Type, ty::AssociatedKind::Const | ty::AssociatedKind::Method => Namespace::Value, @@ -31,6 +32,7 @@ fn from(a_kind: ty::AssociatedKind) -> Self { impl<'a> From <&'a hir::ImplItemKind> for Namespace { fn from(impl_kind: &'a hir::ImplItemKind) -> Self { match *impl_kind { + hir::ImplItemKind::Existential(..) | hir::ImplItemKind::Type(..) => Namespace::Type, hir::ImplItemKind::Const(..) | hir::ImplItemKind::Method(..) => Namespace::Value, diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 2bf1f6e553f..cf4eec97d8c 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -512,6 +512,7 @@ pub enum ItemEnum { FunctionItem(Function), ModuleItem(Module), TypedefItem(Typedef, bool /* is associated type */), + ExistentialItem(Existential, bool /* is associated type */), StaticItem(Static), ConstantItem(Constant), TraitItem(Trait), @@ -545,6 +546,7 @@ pub fn generics(&self) -> Option<&Generics> { ItemEnum::EnumItem(ref e) => &e.generics, ItemEnum::FunctionItem(ref f) => &f.generics, ItemEnum::TypedefItem(ref t, _) => &t.generics, + ItemEnum::ExistentialItem(ref t, _) => &t.generics, ItemEnum::TraitItem(ref t) => &t.generics, ItemEnum::ImplItem(ref i) => &i.generics, ItemEnum::TyMethodItem(ref i) => &i.generics, @@ -596,6 +598,7 @@ fn clean(&self, cx: &DocContext) -> Item { items.extend(self.foreigns.iter().flat_map(|x| x.clean(cx))); items.extend(self.mods.iter().map(|x| x.clean(cx))); items.extend(self.typedefs.iter().map(|x| x.clean(cx))); + items.extend(self.existentials.iter().map(|x| x.clean(cx))); items.extend(self.statics.iter().map(|x| x.clean(cx))); items.extend(self.constants.iter().map(|x| x.clean(cx))); items.extend(self.traits.iter().map(|x| x.clean(cx))); @@ -2411,6 +2414,10 @@ fn clean(&self, cx: &DocContext) -> Item { type_: ty.clean(cx), generics: Generics::default(), }, true), + hir::ImplItemKind::Existential(ref bounds) => ExistentialItem(Existential { + bounds: bounds.clean(cx), + generics: Generics::default(), + }, true), }; Item { name: Some(self.ident.name.clean(cx)), @@ -2554,6 +2561,7 @@ fn clean(&self, cx: &DocContext) -> Item { }, true) } } + ty::AssociatedKind::Existential => unimplemented!(), }; let visibility = match self.container { @@ -3696,6 +3704,30 @@ fn clean(&self, cx: &DocContext) -> Item { } } +#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +pub struct Existential { + pub bounds: Vec, + pub generics: Generics, +} + +impl Clean for doctree::Existential { + fn clean(&self, cx: &DocContext) -> Item { + Item { + name: Some(self.name.clean(cx)), + attrs: self.attrs.clean(cx), + source: self.whence.clean(cx), + def_id: cx.tcx.hir.local_def_id(self.id.clone()), + visibility: self.vis.clean(cx), + stability: self.stab.clean(cx), + deprecation: self.depr.clean(cx), + inner: ExistentialItem(Existential { + bounds: self.exist_ty.bounds.clean(cx), + generics: self.exist_ty.generics.clean(cx), + }, false), + } + } +} + #[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Eq, Debug, Hash)] pub struct BareFunctionDecl { pub unsafety: hir::Unsafety, diff --git a/src/librustdoc/doctree.rs b/src/librustdoc/doctree.rs index 6fd9ef234f4..591c660138a 100644 --- a/src/librustdoc/doctree.rs +++ b/src/librustdoc/doctree.rs @@ -37,6 +37,7 @@ pub struct Module { pub mods: Vec, pub id: NodeId, pub typedefs: Vec, + pub existentials: Vec, pub statics: Vec, pub constants: Vec, pub traits: Vec, @@ -68,6 +69,7 @@ pub fn new(name: Option) -> Module { fns : Vec::new(), mods : Vec::new(), typedefs : Vec::new(), + existentials: Vec::new(), statics : Vec::new(), constants : Vec::new(), traits : Vec::new(), @@ -167,6 +169,17 @@ pub struct Typedef { pub depr: Option, } +pub struct Existential { + pub exist_ty: hir::ExistTy, + pub name: Name, + pub id: ast::NodeId, + pub attrs: hir::HirVec, + pub whence: Span, + pub vis: hir::Visibility, + pub stab: Option, + pub depr: Option, +} + #[derive(Debug)] pub struct Static { pub type_: P, diff --git a/src/librustdoc/html/item_type.rs b/src/librustdoc/html/item_type.rs index 9b8ada1f6e6..a5131e327e0 100644 --- a/src/librustdoc/html/item_type.rs +++ b/src/librustdoc/html/item_type.rs @@ -43,6 +43,7 @@ pub enum ItemType { Union = 19, ForeignType = 20, Keyword = 21, + Existential = 22, } @@ -70,6 +71,7 @@ fn from(item: &'a clean::Item) -> ItemType { clean::EnumItem(..) => ItemType::Enum, clean::FunctionItem(..) => ItemType::Function, clean::TypedefItem(..) => ItemType::Typedef, + clean::ExistentialItem(..) => ItemType::Existential, clean::StaticItem(..) => ItemType::Static, clean::ConstantItem(..) => ItemType::Constant, clean::TraitItem(..) => ItemType::Trait, @@ -135,6 +137,7 @@ pub fn css_class(&self) -> &'static str { ItemType::AssociatedConst => "associatedconstant", ItemType::ForeignType => "foreigntype", ItemType::Keyword => "keyword", + ItemType::Existential => "existential", } } @@ -148,6 +151,7 @@ pub fn name_space(&self) -> NameSpace { ItemType::Trait | ItemType::Primitive | ItemType::AssociatedType | + ItemType::Existential | ItemType::ForeignType => NameSpace::Type, ItemType::ExternCrate | diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 41c08dbf4ab..928d7d38351 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -1570,6 +1570,7 @@ struct AllTypes { macros: HashSet, functions: HashSet, typedefs: HashSet, + existentials: HashSet, statics: HashSet, constants: HashSet, keywords: HashSet, @@ -1586,6 +1587,7 @@ fn new() -> AllTypes { macros: HashSet::with_capacity(100), functions: HashSet::with_capacity(100), typedefs: HashSet::with_capacity(100), + existentials: HashSet::with_capacity(100), statics: HashSet::with_capacity(100), constants: HashSet::with_capacity(100), keywords: HashSet::with_capacity(100), @@ -1607,6 +1609,7 @@ fn append(&mut self, item_name: String, item_type: &ItemType) { ItemType::Macro => self.macros.insert(ItemEntry::new(new_url, name)), ItemType::Function => self.functions.insert(ItemEntry::new(new_url, name)), ItemType::Typedef => self.typedefs.insert(ItemEntry::new(new_url, name)), + ItemType::Existential => self.existentials.insert(ItemEntry::new(new_url, name)), ItemType::Static => self.statics.insert(ItemEntry::new(new_url, name)), ItemType::Constant => self.constants.insert(ItemEntry::new(new_url, name)), _ => true, @@ -1650,6 +1653,7 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { print_entries(f, &self.macros, "Macros", "macros")?; print_entries(f, &self.functions, "Functions", "functions")?; print_entries(f, &self.typedefs, "Typedefs", "typedefs")?; + print_entries(f, &self.existentials, "Existentials", "existentials")?; print_entries(f, &self.statics, "Statics", "statics")?; print_entries(f, &self.constants, "Constants", "constants") } @@ -4400,6 +4404,7 @@ fn item_ty_to_strs(ty: &ItemType) -> (&'static str, &'static str) { ItemType::AssociatedConst => ("associated-consts", "Associated Constants"), ItemType::ForeignType => ("foreign-types", "Foreign Types"), ItemType::Keyword => ("keywords", "Keywords"), + ItemType::Existential => ("existentials", "Existentials"), } } diff --git a/src/librustdoc/passes/mod.rs b/src/librustdoc/passes/mod.rs index fe116a22ecc..699ee25436a 100644 --- a/src/librustdoc/passes/mod.rs +++ b/src/librustdoc/passes/mod.rs @@ -84,6 +84,7 @@ fn fold_item(&mut self, i: Item) -> Option { return ret; } // These items can all get re-exported + clean::ExistentialItem(..) | clean::TypedefItem(..) | clean::StaticItem(..) | clean::StructItem(..) | clean::EnumItem(..) | clean::TraitItem(..) | clean::FunctionItem(..) | diff --git a/src/librustdoc/visit_ast.rs b/src/librustdoc/visit_ast.rs index 875ba111ec0..267b7000948 100644 --- a/src/librustdoc/visit_ast.rs +++ b/src/librustdoc/visit_ast.rs @@ -439,6 +439,19 @@ pub fn visit_item(&mut self, item: &hir::Item, }; om.typedefs.push(t); }, + hir::ItemKind::Existential(ref exist_ty) => { + let t = Existential { + exist_ty: exist_ty.clone(), + name, + id: item.id, + attrs: item.attrs.clone(), + whence: item.span, + vis: item.vis.clone(), + stab: self.stability(item.id), + depr: self.deprecation(item.id), + }; + om.existentials.push(t); + }, hir::ItemKind::Static(ref ty, ref mut_, ref exp) => { let s = Static { type_: ty.clone(), @@ -523,9 +536,6 @@ pub fn visit_item(&mut self, item: &hir::Item, om.impls.push(i); } }, - hir::ItemKind::Existential(_) => { - // FIXME(oli-obk): actually generate docs for real existential items - } } } diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index bcdad92bc32..1b6b47f5489 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -1394,6 +1394,7 @@ pub enum ImplItemKind { Const(P, P), Method(MethodSig, P), Type(P), + Existential(GenericBounds), Macro(Mac), } @@ -2132,6 +2133,10 @@ pub enum ItemKind { /// /// E.g. `type Foo = Bar;` Ty(P, Generics), + /// An existential type declaration (`existential type`). + /// + /// E.g. `existential type Foo: Bar + Boo;` + Existential(GenericBounds, Generics), /// An enum definition (`enum` or `pub enum`). /// /// E.g. `enum Foo { C, D }` @@ -2183,6 +2188,7 @@ pub fn descriptive_variant(&self) -> &str { ItemKind::ForeignMod(..) => "foreign module", ItemKind::GlobalAsm(..) => "global asm", ItemKind::Ty(..) => "type alias", + ItemKind::Existential(..) => "existential type", ItemKind::Enum(..) => "enum", ItemKind::Struct(..) => "struct", ItemKind::Union(..) => "union", diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index 1a73096505f..aef6b8ba5a8 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -419,6 +419,9 @@ pub fn walk_feature_fields(&self, mut f: F) // Allows macro invocations in `extern {}` blocks (active, macros_in_extern, "1.27.0", Some(49476), None), + // `existential type` + (active, existential_type, "1.28.0", Some(34511), None), + // unstable #[target_feature] directives (active, arm_target_feature, "1.27.0", Some(44839), None), (active, aarch64_target_feature, "1.27.0", Some(44839), None), @@ -1643,6 +1646,15 @@ fn visit_item(&mut self, i: &'a ast::Item) { gate_feature_post!(&self, decl_macro, i.span, msg); } + ast::ItemKind::Existential(..) => { + gate_feature_post!( + &self, + existential_type, + i.span, + "existential types are unstable" + ); + } + _ => {} } @@ -1842,6 +1854,15 @@ fn visit_impl_item(&mut self, ii: &'a ast::ImplItem) { gate_feature_post!(&self, const_fn, ii.span, "const fn is unstable"); } } + ast::ImplItemKind::Existential(..) => { + gate_feature_post!( + &self, + existential_type, + ii.span, + "existential types are unstable" + ); + } + ast::ImplItemKind::Type(_) if !ii.generics.params.is_empty() => { gate_feature_post!(&self, generic_associated_types, ii.span, "generic associated types are unstable"); diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index d9d3febc4fe..9d5982c1e28 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -912,6 +912,10 @@ pub fn noop_fold_item_kind(i: ItemKind, folder: &mut T) -> ItemKind { ItemKind::Ty(t, generics) => { ItemKind::Ty(folder.fold_ty(t), folder.fold_generics(generics)) } + ItemKind::Existential(bounds, generics) => ItemKind::Existential( + folder.fold_bounds(bounds), + folder.fold_generics(generics), + ), ItemKind::Enum(enum_definition, generics) => { let generics = folder.fold_generics(generics); let variants = enum_definition.variants.move_map(|x| folder.fold_variant(x)); @@ -1002,6 +1006,9 @@ pub fn noop_fold_impl_item(i: ImplItem, folder: &mut T) folder.fold_block(body)) } ast::ImplItemKind::Type(ty) => ast::ImplItemKind::Type(folder.fold_ty(ty)), + ast::ImplItemKind::Existential(bounds) => { + ast::ImplItemKind::Existential(folder.fold_bounds(bounds)) + }, ast::ImplItemKind::Macro(mac) => ast::ImplItemKind::Macro(folder.fold_mac(mac)) }, span: folder.new_span(i.span), diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 62bb5fbd04f..2eaa56ebeb8 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -63,6 +63,15 @@ use std::path::{self, Path, PathBuf}; use std::slice; +#[derive(Debug)] +/// Whether the type alias or associated type is a concrete type or an existential type +pub enum AliasKind { + /// Just a new name for the same type + Weak(P), + /// Only trait impls of the type will be usable, not the actual type itself + Existential(GenericBounds), +} + bitflags! { struct Restrictions: u8 { const STMT_EXPR = 1 << 0; @@ -5502,16 +5511,13 @@ fn parse_impl_item_(&mut self, let lo = self.span; let vis = self.parse_visibility(false)?; let defaultness = self.parse_defaultness(); - let (name, node, generics) = if self.eat_keyword(keywords::Type) { - // This parses the grammar: - // ImplItemAssocTy = Ident ["<"...">"] ["where" ...] "=" Ty ";" - let name = self.parse_ident()?; - let mut generics = self.parse_generics()?; - generics.where_clause = self.parse_where_clause()?; - self.expect(&token::Eq)?; - let typ = self.parse_ty()?; - self.expect(&token::Semi)?; - (name, ast::ImplItemKind::Type(typ), generics) + let (name, node, generics) = if let Some(type_) = self.eat_type() { + let (name, alias, generics) = type_?; + let kind = match alias { + AliasKind::Weak(typ) => ast::ImplItemKind::Type(typ), + AliasKind::Existential(bounds) => ast::ImplItemKind::Existential(bounds), + }; + (name, kind, generics) } else if self.is_const_item() { // This parses the grammar: // ImplItemConst = "const" Ident ":" Ty "=" Expr ";" @@ -6563,14 +6569,43 @@ fn parse_item_foreign_mod(&mut self, } /// Parse type Foo = Bar; - fn parse_item_type(&mut self) -> PResult<'a, ItemInfo> { + /// or + /// existential type Foo: Bar; + /// or + /// return None without modifying the parser state + fn eat_type(&mut self) -> Option> { + // This parses the grammar: + // Ident ["<"...">"] ["where" ...] ("=" | ":") Ty ";" + if self.check_keyword(keywords::Type) || + self.check_keyword(keywords::Existential) && + self.look_ahead(1, |t| t.is_keyword(keywords::Type)) { + let existential = self.eat_keyword(keywords::Existential); + assert!(self.eat_keyword(keywords::Type)); + Some(self.parse_existential_or_alias(existential)) + } else { + None + } + } + + /// Parse type alias or existential type + fn parse_existential_or_alias( + &mut self, + existential: bool, + ) -> PResult<'a, (Ident, AliasKind, ast::Generics)> { let ident = self.parse_ident()?; let mut tps = self.parse_generics()?; tps.where_clause = self.parse_where_clause()?; - self.expect(&token::Eq)?; - let ty = self.parse_ty()?; + let alias = if existential { + self.expect(&token::Colon)?; + let bounds = self.parse_generic_bounds()?; + AliasKind::Existential(bounds) + } else { + self.expect(&token::Eq)?; + let ty = self.parse_ty()?; + AliasKind::Weak(ty) + }; self.expect(&token::Semi)?; - Ok((ident, ItemKind::Ty(ty, tps), None)) + Ok((ident, alias, tps)) } /// Parse the part of an "enum" decl following the '{' @@ -6926,15 +6961,19 @@ fn parse_item_(&mut self, attrs: Vec, maybe_append(attrs, extra_attrs)); return Ok(Some(item)); } - if self.eat_keyword(keywords::Type) { + if let Some(type_) = self.eat_type() { + let (ident, alias, generics) = type_?; // TYPE ITEM - let (ident, item_, extra_attrs) = self.parse_item_type()?; + let item_ = match alias { + AliasKind::Weak(ty) => ItemKind::Ty(ty, generics), + AliasKind::Existential(bounds) => ItemKind::Existential(bounds, generics), + }; let prev_span = self.prev_span; let item = self.mk_item(lo.to(prev_span), ident, item_, visibility, - maybe_append(attrs, extra_attrs)); + attrs); return Ok(Some(item)); } if self.eat_keyword(keywords::Enum) { diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index b0a9003a456..de68780ef2c 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -1280,9 +1280,7 @@ pub fn print_item(&mut self, item: &ast::Item) -> io::Result<()> { self.end()?; } ast::ItemKind::Ty(ref ty, ref generics) => { - self.ibox(INDENT_UNIT)?; - self.ibox(0)?; - self.word_nbsp(&visibility_qualified(&item.vis, "type"))?; + self.head(&visibility_qualified(&item.vis, "type"))?; self.print_ident(item.ident)?; self.print_generic_params(&generics.params)?; self.end()?; // end the inner ibox @@ -1294,6 +1292,18 @@ pub fn print_item(&mut self, item: &ast::Item) -> io::Result<()> { self.s.word(";")?; self.end()?; // end the outer ibox } + ast::ItemKind::Existential(ref bounds, ref generics) => { + self.head(&visibility_qualified(&item.vis, "existential type"))?; + self.print_ident(item.ident)?; + self.print_generic_params(&generics.params)?; + self.end()?; // end the inner ibox + + self.print_where_clause(&generics.where_clause)?; + self.s.space()?; + self.print_type_bounds(":", bounds)?; + self.s.word(";")?; + self.end()?; // end the outer ibox + } ast::ItemKind::Enum(ref enum_definition, ref params) => { self.print_enum_def( enum_definition, @@ -1501,8 +1511,8 @@ pub fn print_visibility(&mut self, vis: &ast::Visibility) -> io::Result<()> { } } - pub fn print_defaultness(&mut self, defatulness: ast::Defaultness) -> io::Result<()> { - if let ast::Defaultness::Default = defatulness { + pub fn print_defaultness(&mut self, defaultness: ast::Defaultness) -> io::Result<()> { + if let ast::Defaultness::Default = defaultness { try!(self.word_nbsp("default")); } Ok(()) @@ -1650,6 +1660,10 @@ pub fn print_impl_item(&mut self, ii: &ast::ImplItem) -> io::Result<()> { ast::ImplItemKind::Type(ref ty) => { self.print_associated_type(ii.ident, None, Some(ty))?; } + ast::ImplItemKind::Existential(ref bounds) => { + self.word_space("existential")?; + self.print_associated_type(ii.ident, Some(bounds), None)?; + } ast::ImplItemKind::Macro(ref mac) => { self.print_mac(mac)?; match mac.node.delim { diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index 9211a2383b6..51be129737e 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -252,6 +252,10 @@ pub fn walk_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a Item) { visitor.visit_ty(typ); visitor.visit_generics(type_parameters) } + ItemKind::Existential(ref bounds, ref type_parameters) => { + walk_list!(visitor, visit_param_bound, bounds); + visitor.visit_generics(type_parameters) + } ItemKind::Enum(ref enum_definition, ref type_parameters) => { visitor.visit_generics(type_parameters); visitor.visit_enum_def(enum_definition, type_parameters, item.id, item.span) @@ -600,6 +604,9 @@ pub fn walk_impl_item<'a, V: Visitor<'a>>(visitor: &mut V, impl_item: &'a ImplIt ImplItemKind::Type(ref ty) => { visitor.visit_ty(ty); } + ImplItemKind::Existential(ref bounds) => { + walk_list!(visitor, visit_param_bound, bounds); + } ImplItemKind::Macro(ref mac) => { visitor.visit_mac(mac); } diff --git a/src/libsyntax_pos/symbol.rs b/src/libsyntax_pos/symbol.rs index 9a0c92f6793..62f22475e7d 100644 --- a/src/libsyntax_pos/symbol.rs +++ b/src/libsyntax_pos/symbol.rs @@ -426,6 +426,7 @@ pub fn fresh() -> Self { (56, Default, "default") (57, Dyn, "dyn") (58, Union, "union") + (59, Existential, "existential") } impl Symbol { diff --git a/src/test/parse-fail/issue-20711-2.rs b/src/test/parse-fail/issue-20711-2.rs index 05df16d21d8..d0836d4af97 100644 --- a/src/test/parse-fail/issue-20711-2.rs +++ b/src/test/parse-fail/issue-20711-2.rs @@ -9,6 +9,7 @@ // except according to those terms. // compile-flags: -Z parse-only +// ignore-tidy-linelength struct Foo; @@ -16,6 +17,6 @@ impl Foo { fn foo() {} #[stable(feature = "rust1", since = "1.0.0")] -} //~ ERROR expected one of `async`, `const`, `crate`, `default`, `extern`, `fn`, `pub`, `type`, or +} //~ ERROR expected one of `async`, `const`, `crate`, `default`, `existential`, `extern`, `fn`, `pub`, `type`, or fn main() {} diff --git a/src/test/parse-fail/issue-20711.rs b/src/test/parse-fail/issue-20711.rs index f30e20ad7db..d9442247988 100644 --- a/src/test/parse-fail/issue-20711.rs +++ b/src/test/parse-fail/issue-20711.rs @@ -9,11 +9,12 @@ // except according to those terms. // compile-flags: -Z parse-only +// ignore-tidy-linelength struct Foo; impl Foo { #[stable(feature = "rust1", since = "1.0.0")] -} //~ ERROR expected one of `async`, `const`, `crate`, `default`, `extern`, `fn`, `pub`, `type`, or +} //~ ERROR expected one of `async`, `const`, `crate`, `default`, `existential`, `extern`, `fn`, `pub`, `type`, or fn main() {} diff --git a/src/test/parse-fail/removed-syntax-static-fn.rs b/src/test/parse-fail/removed-syntax-static-fn.rs index fbc6848f372..4c0cd3358dd 100644 --- a/src/test/parse-fail/removed-syntax-static-fn.rs +++ b/src/test/parse-fail/removed-syntax-static-fn.rs @@ -9,10 +9,11 @@ // except according to those terms. // compile-flags: -Z parse-only +// ignore-tidy-linelength struct S; impl S { static fn f() {} } -//~^^ ERROR expected one of `async`, `const`, `crate`, `default`, `extern`, `fn`, `pub`, `type`, +//~^^ ERROR expected one of `async`, `const`, `crate`, `default`, `existential`, `extern`, `fn`, `pub`, `type`, diff --git a/src/test/run-pass/existential_type.rs b/src/test/run-pass/existential_type.rs new file mode 100644 index 00000000000..d2cecd83036 --- /dev/null +++ b/src/test/run-pass/existential_type.rs @@ -0,0 +1,113 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![feature(existential_type)] + +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 +existential type Foo: std::fmt::Display; + +fn foo() -> Foo { + "foo" +} + +// two definitions +existential type Bar: std::fmt::Display; + +fn bar1() -> Bar { + "bar1" +} + +fn bar2() -> Bar { + "bar2" +} + +// definition in submodule +existential type Boo: std::fmt::Display; + +mod boo { + pub fn boo() -> super::Boo { + "boo" + } +} + +existential type MyIter: 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! +existential type MyOtherIter: Iterator; + +fn my_other_iter(u: U) -> MyOtherIter { + std::iter::once(u) +} + +trait Trait {} +existential type GenericBound: 'static; + +fn generic_bound(_: T) -> GenericBound { + unimplemented!() +} + +mod pass_through { + pub existential type Passthrough: 'static; + + fn define_passthrough(t: T) -> Passthrough { + t + } +} + +fn use_passthrough(x: pass_through::Passthrough) -> pass_through::Passthrough { + x +} + +existential type PartiallyDefined: 'static; + +// doesn't declare all PartiallyDefined for all possible `T`, but since it's the only +// function producing the value, noone can ever get a value that is problematic +fn partially_defined(_: T) -> PartiallyDefined { + 4u32 +} + +existential type PartiallyDefined2: 'static; + +fn partially_defined2(_: T) -> PartiallyDefined2 { + 4u32 +} + +// fully defines PartiallyDefine2 +fn partially_defined22(_: T) -> PartiallyDefined2 { + 4u32 +} diff --git a/src/test/ui/as-ref.rs b/src/test/ui/as-ref.rs new file mode 100644 index 00000000000..ae1c98c8564 --- /dev/null +++ b/src/test/ui/as-ref.rs @@ -0,0 +1,25 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +struct Foo; +fn takes_ref(_: &Foo) {} + +fn main() { + let ref opt = Some(Foo); + opt.map(|arg| takes_ref(arg)); + //~^ ERROR mismatched types [E0308] + opt.and_then(|arg| Some(takes_ref(arg))); + //~^ ERROR mismatched types [E0308] + let ref opt: Result<_, ()> = Ok(Foo); + opt.map(|arg| takes_ref(arg)); + //~^ ERROR mismatched types [E0308] + opt.and_then(|arg| Ok(takes_ref(arg))); + //~^ ERROR mismatched types [E0308] +} diff --git a/src/test/ui/as-ref.stderr b/src/test/ui/as-ref.stderr new file mode 100644 index 00000000000..27016445ec5 --- /dev/null +++ b/src/test/ui/as-ref.stderr @@ -0,0 +1,47 @@ +error[E0308]: mismatched types + --> $DIR/as-ref.rs:16:27 + | +LL | opt.map(|arg| takes_ref(arg)); + | - ^^^ expected &Foo, found struct `Foo` + | | + | help: consider using `as_ref` instead: `as_ref().` + | + = note: expected type `&Foo` + found type `Foo` + +error[E0308]: mismatched types + --> $DIR/as-ref.rs:18:37 + | +LL | opt.and_then(|arg| Some(takes_ref(arg))); + | - ^^^ expected &Foo, found struct `Foo` + | | + | help: consider using `as_ref` instead: `as_ref().` + | + = note: expected type `&Foo` + found type `Foo` + +error[E0308]: mismatched types + --> $DIR/as-ref.rs:21:27 + | +LL | opt.map(|arg| takes_ref(arg)); + | - ^^^ expected &Foo, found struct `Foo` + | | + | help: consider using `as_ref` instead: `as_ref().` + | + = note: expected type `&Foo` + found type `Foo` + +error[E0308]: mismatched types + --> $DIR/as-ref.rs:23:35 + | +LL | opt.and_then(|arg| Ok(takes_ref(arg))); + | - ^^^ expected &Foo, found struct `Foo` + | | + | help: consider using `as_ref` instead: `as_ref().` + | + = note: expected type `&Foo` + found type `Foo` + +error: aborting due to 4 previous errors + +For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/auxiliary/m1.rs b/src/test/ui/auxiliary/m1.rs new file mode 100644 index 00000000000..b61667cfd88 --- /dev/null +++ b/src/test/ui/auxiliary/m1.rs @@ -0,0 +1,11 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +pub fn foo() {} diff --git a/src/test/ui/auxiliary/m2.rs b/src/test/ui/auxiliary/m2.rs new file mode 100644 index 00000000000..94ff5e4497f --- /dev/null +++ b/src/test/ui/auxiliary/m2.rs @@ -0,0 +1,11 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +pub fn bar() {} diff --git a/src/test/ui/auxiliary/macro-in-other-crate.rs b/src/test/ui/auxiliary/macro-in-other-crate.rs new file mode 100644 index 00000000000..01282f2ad24 --- /dev/null +++ b/src/test/ui/auxiliary/macro-in-other-crate.rs @@ -0,0 +1,14 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#[macro_export] +macro_rules! mac { + ($ident:ident) => { let $ident = 42; } +} diff --git a/src/test/ui/auxiliary/removing-extern-crate.rs b/src/test/ui/auxiliary/removing-extern-crate.rs new file mode 100644 index 00000000000..4275e80e7fe --- /dev/null +++ b/src/test/ui/auxiliary/removing-extern-crate.rs @@ -0,0 +1,11 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// intentionally blank diff --git a/src/test/ui/closure-immutable-outer-variable.fixed b/src/test/ui/closure-immutable-outer-variable.fixed new file mode 100644 index 00000000000..b3a0d592f76 --- /dev/null +++ b/src/test/ui/closure-immutable-outer-variable.fixed @@ -0,0 +1,22 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// run-rustfix + +// Point at the captured immutable outer variable + +fn foo(mut f: Box) { + f(); +} + +fn main() { + let mut y = true; + foo(Box::new(move || y = false) as Box<_>); //~ ERROR cannot assign to captured outer variable +} diff --git a/src/test/ui/closure-immutable-outer-variable.nll.stderr b/src/test/ui/closure-immutable-outer-variable.nll.stderr new file mode 100644 index 00000000000..335ccefe8a0 --- /dev/null +++ b/src/test/ui/closure-immutable-outer-variable.nll.stderr @@ -0,0 +1,9 @@ +error[E0594]: cannot assign to immutable item `y` + --> $DIR/closure-immutable-outer-variable.rs:21:26 + | +LL | foo(Box::new(move || y = false) as Box<_>); //~ ERROR cannot assign to captured outer variable + | ^^^^^^^^^ cannot assign + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0594`. diff --git a/src/test/ui/closure-immutable-outer-variable.rs b/src/test/ui/closure-immutable-outer-variable.rs new file mode 100644 index 00000000000..e162678460c --- /dev/null +++ b/src/test/ui/closure-immutable-outer-variable.rs @@ -0,0 +1,22 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// run-rustfix + +// Point at the captured immutable outer variable + +fn foo(mut f: Box) { + f(); +} + +fn main() { + let y = true; + foo(Box::new(move || y = false) as Box<_>); //~ ERROR cannot assign to captured outer variable +} diff --git a/src/test/ui/closure-immutable-outer-variable.rs.fixed b/src/test/ui/closure-immutable-outer-variable.rs.fixed new file mode 100644 index 00000000000..80a5a45a305 --- /dev/null +++ b/src/test/ui/closure-immutable-outer-variable.rs.fixed @@ -0,0 +1,20 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Point at the captured immutable outer variable + +fn foo(mut f: Box) { + f(); +} + +fn main() { + let mut y = true; + foo(Box::new(move || y = false) as Box<_>); //~ ERROR cannot assign to captured outer variable +} diff --git a/src/test/ui/closure-immutable-outer-variable.stderr b/src/test/ui/closure-immutable-outer-variable.stderr new file mode 100644 index 00000000000..0ee11d8cf15 --- /dev/null +++ b/src/test/ui/closure-immutable-outer-variable.stderr @@ -0,0 +1,11 @@ +error[E0594]: cannot assign to captured outer variable in an `FnMut` closure + --> $DIR/closure-immutable-outer-variable.rs:21:26 + | +LL | let y = true; + | - help: consider making `y` mutable: `mut y` +LL | foo(Box::new(move || y = false) as Box<_>); //~ ERROR cannot assign to captured outer variable + | ^^^^^^^^^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0594`. diff --git a/src/test/ui/confuse-field-and-method/issue-18343.rs b/src/test/ui/confuse-field-and-method/issue-18343.rs new file mode 100644 index 00000000000..ef1566ab56a --- /dev/null +++ b/src/test/ui/confuse-field-and-method/issue-18343.rs @@ -0,0 +1,19 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +struct Obj where F: FnMut() -> u32 { + closure: F, +} + +fn main() { + let o = Obj { closure: || 42 }; + o.closure(); + //~^ ERROR no method named `closure` found +} diff --git a/src/test/ui/confuse-field-and-method/issue-18343.stderr b/src/test/ui/confuse-field-and-method/issue-18343.stderr new file mode 100644 index 00000000000..b1e3105a5f9 --- /dev/null +++ b/src/test/ui/confuse-field-and-method/issue-18343.stderr @@ -0,0 +1,14 @@ +error[E0599]: no method named `closure` found for type `Obj<[closure@$DIR/issue-18343.rs:16:28: 16:33]>` in the current scope + --> $DIR/issue-18343.rs:17:7 + | +LL | struct Obj where F: FnMut() -> u32 { + | ------------------------------------- method `closure` not found for this +... +LL | o.closure(); + | ^^^^^^^ field, not a method + | + = help: use `(o.closure)(...)` if you meant to call the function stored in the `closure` field + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0599`. diff --git a/src/test/ui/confuse-field-and-method/issue-2392.rs b/src/test/ui/confuse-field-and-method/issue-2392.rs new file mode 100644 index 00000000000..f0c5a2a913f --- /dev/null +++ b/src/test/ui/confuse-field-and-method/issue-2392.rs @@ -0,0 +1,83 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![feature(core, fnbox)] + +use std::boxed::FnBox; + +struct FuncContainer { + f1: fn(data: u8), + f2: extern "C" fn(data: u8), + f3: unsafe fn(data: u8), +} + +struct FuncContainerOuter { + container: Box +} + +struct Obj where F: FnOnce() -> u32 { + closure: F, + not_closure: usize, +} + +struct BoxedObj { + boxed_closure: Box u32>, +} + +struct Wrapper where F: FnMut() -> u32 { + wrap: Obj, +} + +fn func() -> u32 { + 0 +} + +fn check_expression() -> Obj u32>> { + Obj { closure: Box::new(|| 42_u32) as Box u32>, not_closure: 42 } +} + +fn main() { + // test variations of function + + let o_closure = Obj { closure: || 42, not_closure: 42 }; + o_closure.closure(); //~ ERROR no method named `closure` found + + o_closure.not_closure(); + //~^ ERROR no method named `not_closure` found + + let o_func = Obj { closure: func, not_closure: 5 }; + o_func.closure(); //~ ERROR no method named `closure` found + + let boxed_fn = BoxedObj { boxed_closure: Box::new(func) }; + boxed_fn.boxed_closure();//~ ERROR no method named `boxed_closure` found + + let boxed_closure = BoxedObj { boxed_closure: Box::new(|| 42_u32) as Box u32> }; + boxed_closure.boxed_closure();//~ ERROR no method named `boxed_closure` found + + // test expression writing in the notes + + let w = Wrapper { wrap: o_func }; + w.wrap.closure();//~ ERROR no method named `closure` found + + w.wrap.not_closure(); + //~^ ERROR no method named `not_closure` found + + check_expression().closure();//~ ERROR no method named `closure` found +} + +impl FuncContainerOuter { + fn run(&self) { + unsafe { + (*self.container).f1(1); //~ ERROR no method named `f1` found + (*self.container).f2(1); //~ ERROR no method named `f2` found + (*self.container).f3(1); //~ ERROR no method named `f3` found + } + } +} diff --git a/src/test/ui/confuse-field-and-method/issue-2392.stderr b/src/test/ui/confuse-field-and-method/issue-2392.stderr new file mode 100644 index 00000000000..9049ffd4090 --- /dev/null +++ b/src/test/ui/confuse-field-and-method/issue-2392.stderr @@ -0,0 +1,124 @@ +error[E0599]: no method named `closure` found for type `Obj<[closure@$DIR/issue-2392.rs:49:36: 49:41]>` in the current scope + --> $DIR/issue-2392.rs:50:15 + | +LL | struct Obj where F: FnOnce() -> u32 { + | -------------------------------------- method `closure` not found for this +... +LL | o_closure.closure(); //~ ERROR no method named `closure` found + | ^^^^^^^ field, not a method + | + = help: use `(o_closure.closure)(...)` if you meant to call the function stored in the `closure` field + +error[E0599]: no method named `not_closure` found for type `Obj<[closure@$DIR/issue-2392.rs:49:36: 49:41]>` in the current scope + --> $DIR/issue-2392.rs:52:15 + | +LL | struct Obj where F: FnOnce() -> u32 { + | -------------------------------------- method `not_closure` not found for this +... +LL | o_closure.not_closure(); + | ^^^^^^^^^^^ field, not a method + | + = help: did you mean to write `o_closure.not_closure` instead of `o_closure.not_closure(...)`? + +error[E0599]: no method named `closure` found for type `Obj u32 {func}>` in the current scope + --> $DIR/issue-2392.rs:56:12 + | +LL | struct Obj where F: FnOnce() -> u32 { + | -------------------------------------- method `closure` not found for this +... +LL | o_func.closure(); //~ ERROR no method named `closure` found + | ^^^^^^^ field, not a method + | + = help: use `(o_func.closure)(...)` if you meant to call the function stored in the `closure` field + +error[E0599]: no method named `boxed_closure` found for type `BoxedObj` in the current scope + --> $DIR/issue-2392.rs:59:14 + | +LL | struct BoxedObj { + | --------------- method `boxed_closure` not found for this +... +LL | boxed_fn.boxed_closure();//~ ERROR no method named `boxed_closure` found + | ^^^^^^^^^^^^^ field, not a method + | + = help: use `(boxed_fn.boxed_closure)(...)` if you meant to call the function stored in the `boxed_closure` field + +error[E0599]: no method named `boxed_closure` found for type `BoxedObj` in the current scope + --> $DIR/issue-2392.rs:62:19 + | +LL | struct BoxedObj { + | --------------- method `boxed_closure` not found for this +... +LL | boxed_closure.boxed_closure();//~ ERROR no method named `boxed_closure` found + | ^^^^^^^^^^^^^ field, not a method + | + = help: use `(boxed_closure.boxed_closure)(...)` if you meant to call the function stored in the `boxed_closure` field + +error[E0599]: no method named `closure` found for type `Obj u32 {func}>` in the current scope + --> $DIR/issue-2392.rs:67:12 + | +LL | struct Obj where F: FnOnce() -> u32 { + | -------------------------------------- method `closure` not found for this +... +LL | w.wrap.closure();//~ ERROR no method named `closure` found + | ^^^^^^^ field, not a method + | + = help: use `(w.wrap.closure)(...)` if you meant to call the function stored in the `closure` field + +error[E0599]: no method named `not_closure` found for type `Obj u32 {func}>` in the current scope + --> $DIR/issue-2392.rs:69:12 + | +LL | struct Obj where F: FnOnce() -> u32 { + | -------------------------------------- method `not_closure` not found for this +... +LL | w.wrap.not_closure(); + | ^^^^^^^^^^^ field, not a method + | + = help: did you mean to write `w.wrap.not_closure` instead of `w.wrap.not_closure(...)`? + +error[E0599]: no method named `closure` found for type `Obj + 'static)>>` in the current scope + --> $DIR/issue-2392.rs:72:24 + | +LL | struct Obj where F: FnOnce() -> u32 { + | -------------------------------------- method `closure` not found for this +... +LL | check_expression().closure();//~ ERROR no method named `closure` found + | ^^^^^^^ field, not a method + | + = help: use `(check_expression().closure)(...)` if you meant to call the function stored in the `closure` field + +error[E0599]: no method named `f1` found for type `FuncContainer` in the current scope + --> $DIR/issue-2392.rs:78:31 + | +LL | struct FuncContainer { + | -------------------- method `f1` not found for this +... +LL | (*self.container).f1(1); //~ ERROR no method named `f1` found + | ^^ field, not a method + | + = help: use `((*self.container).f1)(...)` if you meant to call the function stored in the `f1` field + +error[E0599]: no method named `f2` found for type `FuncContainer` in the current scope + --> $DIR/issue-2392.rs:79:31 + | +LL | struct FuncContainer { + | -------------------- method `f2` not found for this +... +LL | (*self.container).f2(1); //~ ERROR no method named `f2` found + | ^^ field, not a method + | + = help: use `((*self.container).f2)(...)` if you meant to call the function stored in the `f2` field + +error[E0599]: no method named `f3` found for type `FuncContainer` in the current scope + --> $DIR/issue-2392.rs:80:31 + | +LL | struct FuncContainer { + | -------------------- method `f3` not found for this +... +LL | (*self.container).f3(1); //~ ERROR no method named `f3` found + | ^^ field, not a method + | + = help: use `((*self.container).f3)(...)` if you meant to call the function stored in the `f3` field + +error: aborting due to 11 previous errors + +For more information about this error, try `rustc --explain E0599`. diff --git a/src/test/ui/confuse-field-and-method/issue-32128.rs b/src/test/ui/confuse-field-and-method/issue-32128.rs new file mode 100644 index 00000000000..d306b38e00e --- /dev/null +++ b/src/test/ui/confuse-field-and-method/issue-32128.rs @@ -0,0 +1,25 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +struct Example { + example: Box i32> +} + +fn main() { + let demo = Example { + example: Box::new(|x| { + x + 1 + }) + }; + + demo.example(1); + //~^ ERROR no method named `example` + // (demo.example)(1); +} diff --git a/src/test/ui/confuse-field-and-method/issue-32128.stderr b/src/test/ui/confuse-field-and-method/issue-32128.stderr new file mode 100644 index 00000000000..95b764b43ed --- /dev/null +++ b/src/test/ui/confuse-field-and-method/issue-32128.stderr @@ -0,0 +1,14 @@ +error[E0599]: no method named `example` found for type `Example` in the current scope + --> $DIR/issue-32128.rs:22:10 + | +LL | struct Example { + | -------------- method `example` not found for this +... +LL | demo.example(1); + | ^^^^^^^ field, not a method + | + = help: use `(demo.example)(...)` if you meant to call the function stored in the `example` field + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0599`. diff --git a/src/test/ui/confuse-field-and-method/issue-33784.rs b/src/test/ui/confuse-field-and-method/issue-33784.rs new file mode 100644 index 00000000000..4cd50be50d4 --- /dev/null +++ b/src/test/ui/confuse-field-and-method/issue-33784.rs @@ -0,0 +1,43 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +use std::ops::Deref; + +struct Obj where F: FnMut() -> u32 { + fn_ptr: fn() -> (), + closure: F, +} + +struct C { + c_fn_ptr: fn() -> (), +} + +struct D(C); + +impl Deref for D { + type Target = C; + fn deref(&self) -> &C { + &self.0 + } +} + + +fn empty() {} + +fn main() { + let o = Obj { fn_ptr: empty, closure: || 42 }; + let p = &o; + p.closure(); //~ ERROR no method named `closure` found + let q = &p; + q.fn_ptr(); //~ ERROR no method named `fn_ptr` found + let r = D(C { c_fn_ptr: empty }); + let s = &r; + s.c_fn_ptr(); //~ ERROR no method named `c_fn_ptr` found +} diff --git a/src/test/ui/confuse-field-and-method/issue-33784.stderr b/src/test/ui/confuse-field-and-method/issue-33784.stderr new file mode 100644 index 00000000000..b7f13320eec --- /dev/null +++ b/src/test/ui/confuse-field-and-method/issue-33784.stderr @@ -0,0 +1,27 @@ +error[E0599]: no method named `closure` found for type `&Obj<[closure@$DIR/issue-33784.rs:35:43: 35:48]>` in the current scope + --> $DIR/issue-33784.rs:37:7 + | +LL | p.closure(); //~ ERROR no method named `closure` found + | ^^^^^^^ field, not a method + | + = help: use `(p.closure)(...)` if you meant to call the function stored in the `closure` field + +error[E0599]: no method named `fn_ptr` found for type `&&Obj<[closure@$DIR/issue-33784.rs:35:43: 35:48]>` in the current scope + --> $DIR/issue-33784.rs:39:7 + | +LL | q.fn_ptr(); //~ ERROR no method named `fn_ptr` found + | ^^^^^^ field, not a method + | + = help: use `(q.fn_ptr)(...)` if you meant to call the function stored in the `fn_ptr` field + +error[E0599]: no method named `c_fn_ptr` found for type `&D` in the current scope + --> $DIR/issue-33784.rs:42:7 + | +LL | s.c_fn_ptr(); //~ ERROR no method named `c_fn_ptr` found + | ^^^^^^^^ field, not a method + | + = help: use `(s.c_fn_ptr)(...)` if you meant to call the function stored in the `c_fn_ptr` field + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0599`. diff --git a/src/test/ui/confuse-field-and-method/private-field.rs b/src/test/ui/confuse-field-and-method/private-field.rs new file mode 100644 index 00000000000..4cf939bbed6 --- /dev/null +++ b/src/test/ui/confuse-field-and-method/private-field.rs @@ -0,0 +1,29 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +pub mod animal { + pub struct Dog { + pub age: usize, + dog_age: usize, + } + + impl Dog { + pub fn new(age: usize) -> Dog { + Dog { age: age, dog_age: age * 7 } + } + } +} + +fn main() { + let dog = animal::Dog::new(3); + let dog_age = dog.dog_age(); //~ ERROR no method + //let dog_age = dog.dog_age; + println!("{}", dog_age); +} diff --git a/src/test/ui/confuse-field-and-method/private-field.stderr b/src/test/ui/confuse-field-and-method/private-field.stderr new file mode 100644 index 00000000000..145df8b156b --- /dev/null +++ b/src/test/ui/confuse-field-and-method/private-field.stderr @@ -0,0 +1,12 @@ +error[E0599]: no method named `dog_age` found for type `animal::Dog` in the current scope + --> $DIR/private-field.rs:26:23 + | +LL | pub struct Dog { + | -------------- method `dog_age` not found for this +... +LL | let dog_age = dog.dog_age(); //~ ERROR no method + | ^^^^^^^ private field, not a method + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0599`. diff --git a/src/test/ui/const-type-mismatch.rs b/src/test/ui/const-type-mismatch.rs new file mode 100644 index 00000000000..ddad4e79cfd --- /dev/null +++ b/src/test/ui/const-type-mismatch.rs @@ -0,0 +1,21 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// `const`s shouldn't suggest `.into()` + +const TEN: u8 = 10; +const TWELVE: u16 = TEN + 2; +//~^ ERROR mismatched types [E0308] + +fn main() { + const TEN: u8 = 10; + const ALSO_TEN: u16 = TEN; + //~^ ERROR mismatched types [E0308] +} diff --git a/src/test/ui/const-type-mismatch.stderr b/src/test/ui/const-type-mismatch.stderr new file mode 100644 index 00000000000..965995f82c5 --- /dev/null +++ b/src/test/ui/const-type-mismatch.stderr @@ -0,0 +1,15 @@ +error[E0308]: mismatched types + --> $DIR/const-type-mismatch.rs:14:21 + | +LL | const TWELVE: u16 = TEN + 2; + | ^^^^^^^ expected u16, found u8 + +error[E0308]: mismatched types + --> $DIR/const-type-mismatch.rs:19:27 + | +LL | const ALSO_TEN: u16 = TEN; + | ^^^ expected u16, found u8 + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/conversion-methods.rs b/src/test/ui/conversion-methods.rs new file mode 100644 index 00000000000..8a53bc3ca93 --- /dev/null +++ b/src/test/ui/conversion-methods.rs @@ -0,0 +1,23 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +use std::path::{Path, PathBuf}; + + +fn main() { + let _tis_an_instants_play: String = "'Tis a fond Ambush—"; //~ ERROR mismatched types + let _just_to_make_bliss: PathBuf = Path::new("/ern/her/own/surprise"); + //~^ ERROR mismatched types + + let _but_should_the_play: String = 2; // Perhaps surprisingly, we suggest .to_string() here + //~^ ERROR mismatched types + + let _prove_piercing_earnest: Vec = &[1, 2, 3]; //~ ERROR mismatched types +} diff --git a/src/test/ui/conversion-methods.stderr b/src/test/ui/conversion-methods.stderr new file mode 100644 index 00000000000..970ccad2316 --- /dev/null +++ b/src/test/ui/conversion-methods.stderr @@ -0,0 +1,51 @@ +error[E0308]: mismatched types + --> $DIR/conversion-methods.rs:15:41 + | +LL | let _tis_an_instants_play: String = "'Tis a fond Ambush—"; //~ ERROR mismatched types + | ^^^^^^^^^^^^^^^^^^^^^ + | | + | expected struct `std::string::String`, found reference + | help: try using a conversion method: `"'Tis a fond Ambush—".to_string()` + | + = note: expected type `std::string::String` + found type `&'static str` + +error[E0308]: mismatched types + --> $DIR/conversion-methods.rs:16:40 + | +LL | let _just_to_make_bliss: PathBuf = Path::new("/ern/her/own/surprise"); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | expected struct `std::path::PathBuf`, found reference + | help: try using a conversion method: `Path::new("/ern/her/own/surprise").to_path_buf()` + | + = note: expected type `std::path::PathBuf` + found type `&std::path::Path` + +error[E0308]: mismatched types + --> $DIR/conversion-methods.rs:19:40 + | +LL | let _but_should_the_play: String = 2; // Perhaps surprisingly, we suggest .to_string() here + | ^ + | | + | expected struct `std::string::String`, found integral variable + | help: try using a conversion method: `2.to_string()` + | + = note: expected type `std::string::String` + found type `{integer}` + +error[E0308]: mismatched types + --> $DIR/conversion-methods.rs:22:47 + | +LL | let _prove_piercing_earnest: Vec = &[1, 2, 3]; //~ ERROR mismatched types + | ^^^^^^^^^^ + | | + | expected struct `std::vec::Vec`, found reference + | help: try using a conversion method: `&[1, 2, 3].to_vec()` + | + = note: expected type `std::vec::Vec` + found type `&[{integer}; 3]` + +error: aborting due to 4 previous errors + +For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/dont-suggest-private-trait-method.rs b/src/test/ui/dont-suggest-private-trait-method.rs new file mode 100644 index 00000000000..99bee0d3c59 --- /dev/null +++ b/src/test/ui/dont-suggest-private-trait-method.rs @@ -0,0 +1,16 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +struct T; + +fn main() { + T::new(); + //~^ ERROR no function or associated item named `new` found for type `T` in the current scope +} diff --git a/src/test/ui/dont-suggest-private-trait-method.stderr b/src/test/ui/dont-suggest-private-trait-method.stderr new file mode 100644 index 00000000000..81ecc546a6d --- /dev/null +++ b/src/test/ui/dont-suggest-private-trait-method.stderr @@ -0,0 +1,12 @@ +error[E0599]: no function or associated item named `new` found for type `T` in the current scope + --> $DIR/dont-suggest-private-trait-method.rs:14:5 + | +LL | struct T; + | --------- function or associated item `new` not found for this +... +LL | T::new(); + | ^^^^^^ function or associated item not found in `T` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0599`. diff --git a/src/test/ui/dotdotdot-expr.rs b/src/test/ui/dotdotdot-expr.rs new file mode 100644 index 00000000000..afb73a526a8 --- /dev/null +++ b/src/test/ui/dotdotdot-expr.rs @@ -0,0 +1,14 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn main() { + let _redemptive = 1...21; + //~^ ERROR unexpected token +} diff --git a/src/test/ui/dotdotdot-expr.stderr b/src/test/ui/dotdotdot-expr.stderr new file mode 100644 index 00000000000..3315538f2f7 --- /dev/null +++ b/src/test/ui/dotdotdot-expr.stderr @@ -0,0 +1,16 @@ +error: unexpected token: `...` + --> $DIR/dotdotdot-expr.rs:12:24 + | +LL | let _redemptive = 1...21; + | ^^^ +help: use `..` for an exclusive range + | +LL | let _redemptive = 1..21; + | ^^ +help: or `..=` for an inclusive range + | +LL | let _redemptive = 1..=21; + | ^^^ + +error: aborting due to previous error + diff --git a/src/test/ui/existential_type.nll.stderr b/src/test/ui/existential_type.nll.stderr new file mode 100644 index 00000000000..90840bf205c --- /dev/null +++ b/src/test/ui/existential_type.nll.stderr @@ -0,0 +1,111 @@ +error: defining existential type use differs from previous + --> $DIR/existential_type.rs:23:1 + | +LL | / fn bar() -> Foo { //~ ERROR defining existential type use differs from previous +LL | | 42i32 +LL | | } + | |_^ + | +note: previous use here + --> $DIR/existential_type.rs:19:1 + | +LL | / fn foo() -> Foo { +LL | | "" +LL | | } + | |_^ + +error[E0308]: mismatched types + --> $DIR/existential_type.rs:36:5 + | +LL | fn bomp() -> boo::Boo { + | -------- expected `Boo` because of return type +LL | "" //~ ERROR mismatched types + | ^^ expected anonymized type, found reference + | + = note: expected type `Boo` + found type `&'static str` + +error[E0308]: mismatched types + --> $DIR/existential_type.rs:50:23 + | +LL | let _: &str = bomp(); //~ ERROR mismatched types + | ^^^^^^ expected &str, found anonymized type + | + = note: expected type `&str` + found type `Boo` + +error[E0308]: mismatched types + --> $DIR/existential_type.rs:54:9 + | +LL | fn bomp() -> boo::Boo { + | -------- expected `Boo` because of return type +LL | "" //~ ERROR mismatched types + | ^^ expected anonymized type, found reference + | + = note: expected type `Boo` + found type `&'static str` + +error[E0277]: the trait bound `T: Trait` is not satisfied + --> $DIR/existential_type.rs:61:1 + | +LL | existential type Underconstrained: 'static; //~ ERROR the trait bound `T: Trait` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Trait` is not implemented for `T` + | + = help: consider adding a `where T: Trait` bound + = note: the return type of a function must have a statically known size + +warning: not reporting region error due to nll + --> $DIR/existential_type.rs:78:1 + | +LL | existential type WrongGeneric: 'static; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error[E0308]: mismatched types + --> $DIR/existential_type.rs:93:27 + | +LL | let _: &'static str = x; //~ mismatched types + | ^ expected reference, found anonymized type + | + = note: expected type `&'static str` + found type `NoReveal` + +error[E0605]: non-primitive cast: `NoReveal` as `&'static str` + --> $DIR/existential_type.rs:94:13 + | +LL | let _ = x as &'static str; //~ non-primitive cast + | ^^^^^^^^^^^^^^^^^ + | + = note: an `as` expression can only be used to convert between primitive types. Consider using the `From` trait + +error: could not find defining uses + --> $DIR/existential_type.rs:28:1 + | +LL | existential type Bar: std::fmt::Debug; //~ ERROR could not find defining uses + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: could not find defining uses + --> $DIR/existential_type.rs:32:5 + | +LL | pub existential type Boo: ::std::fmt::Debug; //~ ERROR could not find defining uses + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: defining existential type use differs from previous + --> $DIR/existential_type.rs:74:1 + | +LL | / fn my_iter2(t: T) -> MyIter { //~ ERROR defining existential type use differs from previous +LL | | Some(t).into_iter() +LL | | } + | |_^ + | +note: previous use here + --> $DIR/existential_type.rs:70:1 + | +LL | / fn my_iter(t: T) -> MyIter { +LL | | std::iter::once(t) +LL | | } + | |_^ + +error: aborting due to 10 previous errors + +Some errors occurred: E0277, E0308, E0605. +For more information about an error, try `rustc --explain E0277`. diff --git a/src/test/ui/existential_type.rs b/src/test/ui/existential_type.rs new file mode 100644 index 00000000000..6824d362049 --- /dev/null +++ b/src/test/ui/existential_type.rs @@ -0,0 +1,95 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + + +#![feature(existential_type)] + +fn main() {} + +// two definitions with different types +existential type Foo: std::fmt::Debug; + +fn foo() -> Foo { + "" +} + +fn bar() -> Foo { //~ ERROR defining existential type use differs from previous + 42i32 +} + +// declared but never defined +existential type Bar: std::fmt::Debug; //~ ERROR could not find defining uses + +mod boo { + // declared in module but not defined inside of it + pub existential type Boo: ::std::fmt::Debug; //~ ERROR could not find defining uses +} + +fn bomp() -> boo::Boo { + "" //~ ERROR mismatched types +} + +mod boo2 { + mod boo { + pub existential type Boo: ::std::fmt::Debug; + fn bomp() -> Boo { + "" + } + } + + // don't actually know the type here + + fn bomp2() { + let _: &str = bomp(); //~ ERROR mismatched types + } + + fn bomp() -> boo::Boo { + "" //~ ERROR mismatched types + } +} + +// generics + +trait Trait {} +existential type Underconstrained: 'static; //~ ERROR the trait bound `T: Trait` + +// no `Trait` bound +fn underconstrain(_: T) -> Underconstrained { + unimplemented!() +} + +existential type MyIter: Iterator; + +fn my_iter(t: T) -> MyIter { + std::iter::once(t) +} + +fn my_iter2(t: T) -> MyIter { //~ ERROR defining existential type use differs from previous + Some(t).into_iter() +} + +existential type WrongGeneric: 'static; +//~^ ERROR the parameter type `T` may not live long enough + +fn wrong_generic(t: T) -> WrongGeneric { + t +} + +// don't reveal the concrete type +existential type NoReveal: std::fmt::Debug; + +fn define_no_reveal() -> NoReveal { + "" +} + +fn no_reveal(x: NoReveal) { + let _: &'static str = x; //~ mismatched types + let _ = x as &'static str; //~ non-primitive cast +} diff --git a/src/test/ui/existential_type.stderr b/src/test/ui/existential_type.stderr new file mode 100644 index 00000000000..3e7476448bf --- /dev/null +++ b/src/test/ui/existential_type.stderr @@ -0,0 +1,120 @@ +error: defining existential type use differs from previous + --> $DIR/existential_type.rs:23:1 + | +LL | / fn bar() -> Foo { //~ ERROR defining existential type use differs from previous +LL | | 42i32 +LL | | } + | |_^ + | +note: previous use here + --> $DIR/existential_type.rs:19:1 + | +LL | / fn foo() -> Foo { +LL | | "" +LL | | } + | |_^ + +error[E0308]: mismatched types + --> $DIR/existential_type.rs:36:5 + | +LL | fn bomp() -> boo::Boo { + | -------- expected `Boo` because of return type +LL | "" //~ ERROR mismatched types + | ^^ expected anonymized type, found reference + | + = note: expected type `Boo` + found type `&'static str` + +error[E0308]: mismatched types + --> $DIR/existential_type.rs:50:23 + | +LL | let _: &str = bomp(); //~ ERROR mismatched types + | ^^^^^^ expected &str, found anonymized type + | + = note: expected type `&str` + found type `Boo` + +error[E0308]: mismatched types + --> $DIR/existential_type.rs:54:9 + | +LL | fn bomp() -> boo::Boo { + | -------- expected `Boo` because of return type +LL | "" //~ ERROR mismatched types + | ^^ expected anonymized type, found reference + | + = note: expected type `Boo` + found type `&'static str` + +error[E0277]: the trait bound `T: Trait` is not satisfied + --> $DIR/existential_type.rs:61:1 + | +LL | existential type Underconstrained: 'static; //~ ERROR the trait bound `T: Trait` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Trait` is not implemented for `T` + | + = help: consider adding a `where T: Trait` bound + = note: the return type of a function must have a statically known size + +error[E0310]: the parameter type `T` may not live long enough + --> $DIR/existential_type.rs:78:1 + | +LL | existential type WrongGeneric: 'static; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +... +LL | fn wrong_generic(t: T) -> WrongGeneric { + | - help: consider adding an explicit lifetime bound `T: 'static`... + | +note: ...so that the type `T` will meet its required lifetime bounds + --> $DIR/existential_type.rs:78:1 + | +LL | existential type WrongGeneric: 'static; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error[E0308]: mismatched types + --> $DIR/existential_type.rs:93:27 + | +LL | let _: &'static str = x; //~ mismatched types + | ^ expected reference, found anonymized type + | + = note: expected type `&'static str` + found type `NoReveal` + +error[E0605]: non-primitive cast: `NoReveal` as `&'static str` + --> $DIR/existential_type.rs:94:13 + | +LL | let _ = x as &'static str; //~ non-primitive cast + | ^^^^^^^^^^^^^^^^^ + | + = note: an `as` expression can only be used to convert between primitive types. Consider using the `From` trait + +error: could not find defining uses + --> $DIR/existential_type.rs:28:1 + | +LL | existential type Bar: std::fmt::Debug; //~ ERROR could not find defining uses + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: could not find defining uses + --> $DIR/existential_type.rs:32:5 + | +LL | pub existential type Boo: ::std::fmt::Debug; //~ ERROR could not find defining uses + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: defining existential type use differs from previous + --> $DIR/existential_type.rs:74:1 + | +LL | / fn my_iter2(t: T) -> MyIter { //~ ERROR defining existential type use differs from previous +LL | | Some(t).into_iter() +LL | | } + | |_^ + | +note: previous use here + --> $DIR/existential_type.rs:70:1 + | +LL | / fn my_iter(t: T) -> MyIter { +LL | | std::iter::once(t) +LL | | } + | |_^ + +error: aborting due to 11 previous errors + +Some errors occurred: E0277, E0308, E0310, E0605. +For more information about an error, try `rustc --explain E0277`. diff --git a/src/test/ui/existential_type2.rs b/src/test/ui/existential_type2.rs new file mode 100644 index 00000000000..bffb6b5ee10 --- /dev/null +++ b/src/test/ui/existential_type2.rs @@ -0,0 +1,30 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + + +#![feature(existential_type)] + +fn main() {} + +existential type Underconstrained: 'static; +//~^ ERROR `U` doesn't implement `std::fmt::Debug` + +// not a defining use, because it doesn't define *all* possible generics +fn underconstrained(_: U) -> Underconstrained { + 5u32 +} + +existential type Underconstrained2: 'static; +//~^ ERROR `V` doesn't implement `std::fmt::Debug` + +// not a defining use, because it doesn't define *all* possible generics +fn underconstrained2(_: U, _: V) -> Underconstrained2 { + 5u32 +} diff --git a/src/test/ui/existential_type2.stderr b/src/test/ui/existential_type2.stderr new file mode 100644 index 00000000000..53003a4f05d --- /dev/null +++ b/src/test/ui/existential_type2.stderr @@ -0,0 +1,23 @@ +error[E0277]: `U` doesn't implement `std::fmt::Debug` + --> $DIR/existential_type2.rs:16:1 + | +LL | existential type Underconstrained: 'static; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `U` cannot be formatted using `{:?}` because it doesn't implement `std::fmt::Debug` + | + = help: the trait `std::fmt::Debug` is not implemented for `U` + = help: consider adding a `where U: std::fmt::Debug` bound + = note: the return type of a function must have a statically known size + +error[E0277]: `V` doesn't implement `std::fmt::Debug` + --> $DIR/existential_type2.rs:24:1 + | +LL | existential type Underconstrained2: 'static; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `V` cannot be formatted using `{:?}` because it doesn't implement `std::fmt::Debug` + | + = help: the trait `std::fmt::Debug` is not implemented for `V` + = help: consider adding a `where V: std::fmt::Debug` bound + = note: the return type of a function must have a statically known size + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/existential_type3.rs b/src/test/ui/existential_type3.rs new file mode 100644 index 00000000000..b090cf26b87 --- /dev/null +++ b/src/test/ui/existential_type3.rs @@ -0,0 +1,21 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + + +#![feature(existential_type)] + +fn main() {} + +existential type WrongGeneric: 'static; + +fn wrong_generic(_: U, v: V) -> WrongGeneric { +//~^ ERROR type parameter `V` is part of concrete type but not used in parameter list + v +} diff --git a/src/test/ui/existential_type3.stderr b/src/test/ui/existential_type3.stderr new file mode 100644 index 00000000000..90800728d7c --- /dev/null +++ b/src/test/ui/existential_type3.stderr @@ -0,0 +1,12 @@ +error: type parameter `V` is part of concrete type but not used in parameter list for existential type + --> $DIR/existential_type3.rs:18:73 + | +LL | fn wrong_generic(_: U, v: V) -> WrongGeneric { + | _________________________________________________________________________^ +LL | | //~^ ERROR type parameter `V` is part of concrete type but not used in parameter list +LL | | v +LL | | } + | |_^ + +error: aborting due to previous error + diff --git a/src/test/ui/existential_type4.rs b/src/test/ui/existential_type4.rs new file mode 100644 index 00000000000..a4b74d6751b --- /dev/null +++ b/src/test/ui/existential_type4.rs @@ -0,0 +1,21 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + + +#![feature(existential_type)] + +fn main() {} + +existential type Cmp: 'static; + +// not a defining use, because it doesn't define *all* possible generics +fn cmp() -> Cmp { //~ ERROR non-defining existential type use in defining scope + 5u32 +} diff --git a/src/test/ui/existential_type4.stderr b/src/test/ui/existential_type4.stderr new file mode 100644 index 00000000000..b11988746ea --- /dev/null +++ b/src/test/ui/existential_type4.stderr @@ -0,0 +1,16 @@ +error: non-defining existential type use in defining scope + --> $DIR/existential_type4.rs:19:1 + | +LL | / fn cmp() -> Cmp { //~ ERROR non-defining existential type use in defining scope +LL | | 5u32 +LL | | } + | |_^ + | +note: used non-generic type u32 for generic parameter + --> $DIR/existential_type4.rs:16:22 + | +LL | existential type Cmp: 'static; + | ^ + +error: aborting due to previous error + diff --git a/src/test/ui/extern-crate-rename.rs b/src/test/ui/extern-crate-rename.rs new file mode 100644 index 00000000000..b58149fb0b8 --- /dev/null +++ b/src/test/ui/extern-crate-rename.rs @@ -0,0 +1,18 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// aux-build:m1.rs +// aux-build:m2.rs + + +extern crate m1; +extern crate m2 as m1; //~ ERROR is defined multiple times + +fn main() {} diff --git a/src/test/ui/extern-crate-rename.stderr b/src/test/ui/extern-crate-rename.stderr new file mode 100644 index 00000000000..2c2723fe4c5 --- /dev/null +++ b/src/test/ui/extern-crate-rename.stderr @@ -0,0 +1,16 @@ +error[E0259]: the name `m1` is defined multiple times + --> $DIR/extern-crate-rename.rs:16:1 + | +LL | extern crate m1; + | ---------------- previous import of the extern crate `m1` here +LL | extern crate m2 as m1; //~ ERROR is defined multiple times + | ^^^^^^^^^^^^^^^^^^^^^^ + | | + | `m1` reimported here + | You can use `as` to change the binding name of the import + | + = note: `m1` must be defined only once in the type namespace of this module + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0259`. diff --git a/src/test/ui/feature-gate-existential-type.rs b/src/test/ui/feature-gate-existential-type.rs new file mode 100644 index 00000000000..b35a3916377 --- /dev/null +++ b/src/test/ui/feature-gate-existential-type.rs @@ -0,0 +1,25 @@ +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Check that existential types must be ungated to use the `existential` keyword + + + +existential type Foo: std::fmt::Debug; //~ ERROR existential types are unstable + +trait Bar { + type Baa: std::fmt::Debug; +} + +impl Bar for () { + existential type Baa: std::fmt::Debug; //~ ERROR existential types are unstable +} + +fn main() {} diff --git a/src/test/ui/feature-gate-existential-type.stderr b/src/test/ui/feature-gate-existential-type.stderr new file mode 100644 index 00000000000..6db5fa2ce6b --- /dev/null +++ b/src/test/ui/feature-gate-existential-type.stderr @@ -0,0 +1,19 @@ +error[E0658]: existential types are unstable (see issue #34511) + --> $DIR/feature-gate-existential-type.rs:15:1 + | +LL | existential type Foo: std::fmt::Debug; //~ ERROR existential types are unstable + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: add #![feature(existential_type)] to the crate attributes to enable + +error[E0658]: existential types are unstable (see issue #34511) + --> $DIR/feature-gate-existential-type.rs:22:5 + | +LL | existential type Baa: std::fmt::Debug; //~ ERROR existential types are unstable + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: add #![feature(existential_type)] to the crate attributes to enable + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/fn-closure-mutable-capture.nll.stderr b/src/test/ui/fn-closure-mutable-capture.nll.stderr new file mode 100644 index 00000000000..7ef21d3720d --- /dev/null +++ b/src/test/ui/fn-closure-mutable-capture.nll.stderr @@ -0,0 +1,9 @@ +error[E0594]: cannot assign to `x` which is behind a `&` reference + --> $DIR/fn-closure-mutable-capture.rs:15:17 + | +LL | bar(move || x = 1); + | ^^^^^ cannot assign + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0594`. diff --git a/src/test/ui/fn-closure-mutable-capture.rs b/src/test/ui/fn-closure-mutable-capture.rs new file mode 100644 index 00000000000..385efebd590 --- /dev/null +++ b/src/test/ui/fn-closure-mutable-capture.rs @@ -0,0 +1,20 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +pub fn bar(_f: F) {} + +pub fn foo() { + let mut x = 0; + bar(move || x = 1); + //~^ ERROR cannot assign to captured outer variable in an `Fn` closure + //~| NOTE `Fn` closures cannot capture their enclosing environment for modifications +} + +fn main() {} diff --git a/src/test/ui/fn-closure-mutable-capture.stderr b/src/test/ui/fn-closure-mutable-capture.stderr new file mode 100644 index 00000000000..a58d663dc0a --- /dev/null +++ b/src/test/ui/fn-closure-mutable-capture.stderr @@ -0,0 +1,16 @@ +error[E0594]: cannot assign to captured outer variable in an `Fn` closure + --> $DIR/fn-closure-mutable-capture.rs:15:17 + | +LL | bar(move || x = 1); + | ^^^^^ + | + = note: `Fn` closures cannot capture their enclosing environment for modifications +help: consider changing this closure to take self by mutable reference + --> $DIR/fn-closure-mutable-capture.rs:15:9 + | +LL | bar(move || x = 1); + | ^^^^^^^^^^^^^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0594`. diff --git a/src/test/ui/for-c-in-str.rs b/src/test/ui/for-c-in-str.rs new file mode 100644 index 00000000000..011886e8073 --- /dev/null +++ b/src/test/ui/for-c-in-str.rs @@ -0,0 +1,21 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// E0277 should point exclusively at line 14, not the entire for loop span + +fn main() { + for c in "asdf" { + //~^ ERROR the trait bound `&str: std::iter::Iterator` is not satisfied + //~| NOTE `&str` is not an iterator + //~| HELP the trait `std::iter::Iterator` is not implemented for `&str` + //~| NOTE required by `std::iter::IntoIterator::into_iter` + println!(""); + } +} diff --git a/src/test/ui/for-c-in-str.stderr b/src/test/ui/for-c-in-str.stderr new file mode 100644 index 00000000000..b249df3b4ef --- /dev/null +++ b/src/test/ui/for-c-in-str.stderr @@ -0,0 +1,12 @@ +error[E0277]: the trait bound `&str: std::iter::Iterator` is not satisfied + --> $DIR/for-c-in-str.rs:14:14 + | +LL | for c in "asdf" { + | ^^^^^^ `&str` is not an iterator; try calling `.chars()` or `.bytes()` + | + = help: the trait `std::iter::Iterator` is not implemented for `&str` + = note: required by `std::iter::IntoIterator::into_iter` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/issue-32354-suggest-import-rename.fixed b/src/test/ui/issue-32354-suggest-import-rename.fixed new file mode 100644 index 00000000000..251f7eb9a24 --- /dev/null +++ b/src/test/ui/issue-32354-suggest-import-rename.fixed @@ -0,0 +1,26 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// run-rustfix + +#![allow(unused_imports)] + +pub mod extension1 { + pub trait ConstructorExtension {} +} + +pub mod extension2 { + pub trait ConstructorExtension {} +} + +use extension1::ConstructorExtension; +use extension2::ConstructorExtension as OtherConstructorExtension; //~ ERROR is defined multiple times + +fn main() {} diff --git a/src/test/ui/issue-32354-suggest-import-rename.rs b/src/test/ui/issue-32354-suggest-import-rename.rs new file mode 100644 index 00000000000..57cbeb47a1e --- /dev/null +++ b/src/test/ui/issue-32354-suggest-import-rename.rs @@ -0,0 +1,26 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// run-rustfix + +#![allow(unused_imports)] + +pub mod extension1 { + pub trait ConstructorExtension {} +} + +pub mod extension2 { + pub trait ConstructorExtension {} +} + +use extension1::ConstructorExtension; +use extension2::ConstructorExtension; //~ ERROR is defined multiple times + +fn main() {} diff --git a/src/test/ui/issue-32354-suggest-import-rename.stderr b/src/test/ui/issue-32354-suggest-import-rename.stderr new file mode 100644 index 00000000000..f45a5f7dd61 --- /dev/null +++ b/src/test/ui/issue-32354-suggest-import-rename.stderr @@ -0,0 +1,17 @@ +error[E0252]: the name `ConstructorExtension` is defined multiple times + --> $DIR/issue-32354-suggest-import-rename.rs:24:5 + | +LL | use extension1::ConstructorExtension; + | -------------------------------- previous import of the trait `ConstructorExtension` here +LL | use extension2::ConstructorExtension; //~ ERROR is defined multiple times + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `ConstructorExtension` reimported here + | + = note: `ConstructorExtension` must be defined only once in the type namespace of this module +help: You can use `as` to change the binding name of the import + | +LL | use extension2::ConstructorExtension as OtherConstructorExtension; //~ ERROR is defined multiple times + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0252`. diff --git a/src/test/ui/issue-43420-no-over-suggest.rs b/src/test/ui/issue-43420-no-over-suggest.rs new file mode 100644 index 00000000000..8c5bde45bae --- /dev/null +++ b/src/test/ui/issue-43420-no-over-suggest.rs @@ -0,0 +1,19 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// check that we substitute type parameters before we suggest anything - otherwise +// we would suggest function such as `as_slice` for the `&[u16]`. + +fn foo(b: &[u16]) {} + +fn main() { + let a: Vec = Vec::new(); + foo(&a); //~ ERROR mismatched types +} diff --git a/src/test/ui/issue-43420-no-over-suggest.stderr b/src/test/ui/issue-43420-no-over-suggest.stderr new file mode 100644 index 00000000000..80bbdd11289 --- /dev/null +++ b/src/test/ui/issue-43420-no-over-suggest.stderr @@ -0,0 +1,12 @@ +error[E0308]: mismatched types + --> $DIR/issue-43420-no-over-suggest.rs:18:9 + | +LL | foo(&a); //~ ERROR mismatched types + | ^^ expected slice, found struct `std::vec::Vec` + | + = note: expected type `&[u16]` + found type `&std::vec::Vec` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/issue-45562.fixed b/src/test/ui/issue-45562.fixed new file mode 100644 index 00000000000..7c01f0d1ee5 --- /dev/null +++ b/src/test/ui/issue-45562.fixed @@ -0,0 +1,16 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// run-rustfix + +#[no_mangle] pub static RAH: usize = 5; +//~^ ERROR const items should never be #[no_mangle] + +fn main() {} diff --git a/src/test/ui/issue-45562.rs b/src/test/ui/issue-45562.rs new file mode 100644 index 00000000000..c27d52fcdd3 --- /dev/null +++ b/src/test/ui/issue-45562.rs @@ -0,0 +1,16 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// run-rustfix + +#[no_mangle] pub const RAH: usize = 5; +//~^ ERROR const items should never be #[no_mangle] + +fn main() {} diff --git a/src/test/ui/issue-45562.stderr b/src/test/ui/issue-45562.stderr new file mode 100644 index 00000000000..d9e624cadc7 --- /dev/null +++ b/src/test/ui/issue-45562.stderr @@ -0,0 +1,12 @@ +error: const items should never be #[no_mangle] + --> $DIR/issue-45562.rs:13:14 + | +LL | #[no_mangle] pub const RAH: usize = 5; + | ---------^^^^^^^^^^^^^^^^ + | | + | help: try a static value: `pub static` + | + = note: #[deny(no_mangle_const_items)] on by default + +error: aborting due to previous error + diff --git a/src/test/ui/issue-45799-bad-extern-crate-rename-suggestion-formatting.fixed b/src/test/ui/issue-45799-bad-extern-crate-rename-suggestion-formatting.fixed new file mode 100644 index 00000000000..e3287030408 --- /dev/null +++ b/src/test/ui/issue-45799-bad-extern-crate-rename-suggestion-formatting.fixed @@ -0,0 +1,15 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// run-rustfix + +extern crate std as other_std; +fn main() {} +//~^^ ERROR the name `std` is defined multiple times [E0259] diff --git a/src/test/ui/issue-45799-bad-extern-crate-rename-suggestion-formatting.rs b/src/test/ui/issue-45799-bad-extern-crate-rename-suggestion-formatting.rs new file mode 100644 index 00000000000..f47ea474d51 --- /dev/null +++ b/src/test/ui/issue-45799-bad-extern-crate-rename-suggestion-formatting.rs @@ -0,0 +1,15 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// run-rustfix + +extern crate std; +fn main() {} +//~^^ ERROR the name `std` is defined multiple times [E0259] diff --git a/src/test/ui/issue-45799-bad-extern-crate-rename-suggestion-formatting.stderr b/src/test/ui/issue-45799-bad-extern-crate-rename-suggestion-formatting.stderr new file mode 100644 index 00000000000..ecdfec2b3bf --- /dev/null +++ b/src/test/ui/issue-45799-bad-extern-crate-rename-suggestion-formatting.stderr @@ -0,0 +1,15 @@ +error[E0259]: the name `std` is defined multiple times + --> $DIR/issue-45799-bad-extern-crate-rename-suggestion-formatting.rs:13:1 + | +LL | extern crate std; + | ^^^^^^^^^^^^^^^^^ `std` reimported here + | + = note: `std` must be defined only once in the type namespace of this module +help: You can use `as` to change the binding name of the import + | +LL | extern crate std as other_std; + | + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0259`. diff --git a/src/test/ui/issue-46302.rs b/src/test/ui/issue-46302.rs new file mode 100644 index 00000000000..6ae6b549b07 --- /dev/null +++ b/src/test/ui/issue-46302.rs @@ -0,0 +1,19 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn foo() { + let s = "abc"; + let u: &str = if true { s[..2] } else { s }; + //~^ ERROR mismatched types +} + +fn main() { + foo(); +} diff --git a/src/test/ui/issue-46302.stderr b/src/test/ui/issue-46302.stderr new file mode 100644 index 00000000000..8e399136fad --- /dev/null +++ b/src/test/ui/issue-46302.stderr @@ -0,0 +1,15 @@ +error[E0308]: mismatched types + --> $DIR/issue-46302.rs:13:27 + | +LL | let u: &str = if true { s[..2] } else { s }; + | ^^^^^^ + | | + | expected &str, found str + | help: consider borrowing here: `&s[..2]` + | + = note: expected type `&str` + found type `str` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/issue-46756-consider-borrowing-cast-or-binexpr.fixed b/src/test/ui/issue-46756-consider-borrowing-cast-or-binexpr.fixed new file mode 100644 index 00000000000..77171cad6e7 --- /dev/null +++ b/src/test/ui/issue-46756-consider-borrowing-cast-or-binexpr.fixed @@ -0,0 +1,26 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// run-rustfix + +#![allow(unused)] + +fn light_flows_our_war_of_mocking_words(and_yet: &usize) -> usize { + and_yet + 1 +} + +fn main() { + let behold: isize = 2; + let with_tears: usize = 3; + light_flows_our_war_of_mocking_words(&(behold as usize)); + //~^ ERROR mismatched types [E0308] + light_flows_our_war_of_mocking_words(&(with_tears + 4)); + //~^ ERROR mismatched types [E0308] +} diff --git a/src/test/ui/issue-46756-consider-borrowing-cast-or-binexpr.rs b/src/test/ui/issue-46756-consider-borrowing-cast-or-binexpr.rs new file mode 100644 index 00000000000..e5ea9b5ed09 --- /dev/null +++ b/src/test/ui/issue-46756-consider-borrowing-cast-or-binexpr.rs @@ -0,0 +1,26 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// run-rustfix + +#![allow(unused)] + +fn light_flows_our_war_of_mocking_words(and_yet: &usize) -> usize { + and_yet + 1 +} + +fn main() { + let behold: isize = 2; + let with_tears: usize = 3; + light_flows_our_war_of_mocking_words(behold as usize); + //~^ ERROR mismatched types [E0308] + light_flows_our_war_of_mocking_words(with_tears + 4); + //~^ ERROR mismatched types [E0308] +} diff --git a/src/test/ui/issue-46756-consider-borrowing-cast-or-binexpr.stderr b/src/test/ui/issue-46756-consider-borrowing-cast-or-binexpr.stderr new file mode 100644 index 00000000000..9c492751ca1 --- /dev/null +++ b/src/test/ui/issue-46756-consider-borrowing-cast-or-binexpr.stderr @@ -0,0 +1,27 @@ +error[E0308]: mismatched types + --> $DIR/issue-46756-consider-borrowing-cast-or-binexpr.rs:22:42 + | +LL | light_flows_our_war_of_mocking_words(behold as usize); + | ^^^^^^^^^^^^^^^ + | | + | expected &usize, found usize + | help: consider borrowing here: `&(behold as usize)` + | + = note: expected type `&usize` + found type `usize` + +error[E0308]: mismatched types + --> $DIR/issue-46756-consider-borrowing-cast-or-binexpr.rs:24:42 + | +LL | light_flows_our_war_of_mocking_words(with_tears + 4); + | ^^^^^^^^^^^^^^ + | | + | expected &usize, found usize + | help: consider borrowing here: `&(with_tears + 4)` + | + = note: expected type `&usize` + found type `usize` + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/issue-48364.rs b/src/test/ui/issue-48364.rs new file mode 100644 index 00000000000..82cb722a656 --- /dev/null +++ b/src/test/ui/issue-48364.rs @@ -0,0 +1,16 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn foo() -> bool { + b"".starts_with(stringify!(foo)) + //~^ ERROR mismatched types +} + +fn main() {} diff --git a/src/test/ui/issue-48364.stderr b/src/test/ui/issue-48364.stderr new file mode 100644 index 00000000000..b420654a32d --- /dev/null +++ b/src/test/ui/issue-48364.stderr @@ -0,0 +1,12 @@ +error[E0308]: mismatched types + --> $DIR/issue-48364.rs:12:21 + | +LL | b"".starts_with(stringify!(foo)) + | ^^^^^^^^^^^^^^^ expected slice, found str + | + = note: expected type `&[u8]` + found type `&'static str` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/issue-51244.nll.stderr b/src/test/ui/issue-51244.nll.stderr new file mode 100644 index 00000000000..ce02ae2aec2 --- /dev/null +++ b/src/test/ui/issue-51244.nll.stderr @@ -0,0 +1,11 @@ +error[E0594]: cannot assign to `*my_ref` which is behind a `&` reference + --> $DIR/issue-51244.rs:13:5 + | +LL | let ref my_ref @ _ = 0; + | -------------- help: consider changing this to be a mutable reference: `ref mut my_ref @ _` +LL | *my_ref = 0; //~ ERROR cannot assign to immutable borrowed content `*my_ref` [E0594] + | ^^^^^^^^^^^ `my_ref` is a `&` reference, so the data it refers to cannot be written + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0594`. diff --git a/src/test/ui/issue-51244.rs b/src/test/ui/issue-51244.rs new file mode 100644 index 00000000000..50a21184a98 --- /dev/null +++ b/src/test/ui/issue-51244.rs @@ -0,0 +1,14 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn main() { + let ref my_ref @ _ = 0; + *my_ref = 0; //~ ERROR cannot assign to immutable borrowed content `*my_ref` [E0594] +} diff --git a/src/test/ui/issue-51244.stderr b/src/test/ui/issue-51244.stderr new file mode 100644 index 00000000000..997a74295e5 --- /dev/null +++ b/src/test/ui/issue-51244.stderr @@ -0,0 +1,11 @@ +error[E0594]: cannot assign to immutable borrowed content `*my_ref` + --> $DIR/issue-51244.rs:13:5 + | +LL | let ref my_ref @ _ = 0; + | -------------- help: use a mutable reference instead: `ref mut my_ref @ _` +LL | *my_ref = 0; //~ ERROR cannot assign to immutable borrowed content `*my_ref` [E0594] + | ^^^^^^^^^^^ cannot borrow as mutable + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0594`. diff --git a/src/test/ui/issue-51515.rs b/src/test/ui/issue-51515.rs new file mode 100644 index 00000000000..3e0a3b757a3 --- /dev/null +++ b/src/test/ui/issue-51515.rs @@ -0,0 +1,24 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![feature(nll)] + +fn main() { + let foo = &16; + //~^ HELP consider changing this to be a mutable reference + //~| SUGGESTION &mut 16 + *foo = 32; + //~^ ERROR cannot assign to `*foo` which is behind a `&` reference + let bar = foo; + //~^ HELP consider changing this to be a mutable reference + //~| SUGGESTION &mut i32 + *bar = 64; + //~^ ERROR cannot assign to `*bar` which is behind a `&` reference +} diff --git a/src/test/ui/issue-51515.stderr b/src/test/ui/issue-51515.stderr new file mode 100644 index 00000000000..3e7349b5aca --- /dev/null +++ b/src/test/ui/issue-51515.stderr @@ -0,0 +1,21 @@ +error[E0594]: cannot assign to `*foo` which is behind a `&` reference + --> $DIR/issue-51515.rs:17:5 + | +LL | let foo = &16; + | --- help: consider changing this to be a mutable reference: `&mut 16` +... +LL | *foo = 32; + | ^^^^^^^^^ `foo` is a `&` reference, so the data it refers to cannot be written + +error[E0594]: cannot assign to `*bar` which is behind a `&` reference + --> $DIR/issue-51515.rs:22:5 + | +LL | let bar = foo; + | --- help: consider changing this to be a mutable reference: `&mut i32` +... +LL | *bar = 64; + | ^^^^^^^^^ `bar` is a `&` reference, so the data it refers to cannot be written + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0594`. diff --git a/src/test/ui/issue-52049.nll.stderr b/src/test/ui/issue-52049.nll.stderr new file mode 100644 index 00000000000..6f71f167611 --- /dev/null +++ b/src/test/ui/issue-52049.nll.stderr @@ -0,0 +1,13 @@ +error[E0597]: borrowed value does not live long enough + --> $DIR/issue-52049.rs:16:10 + | +LL | foo(&unpromotable(5u32)); + | ^^^^^^^^^^^^^^^^^^ temporary value does not live long enough +LL | } + | - temporary value only lives until here + | + = note: borrowed value must be valid for the static lifetime... + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0597`. diff --git a/src/test/ui/issue-52049.rs b/src/test/ui/issue-52049.rs new file mode 100644 index 00000000000..daff2258d36 --- /dev/null +++ b/src/test/ui/issue-52049.rs @@ -0,0 +1,18 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn foo(_: &'static u32) {} + +fn unpromotable(t: T) -> T { t } + +fn main() { + foo(&unpromotable(5u32)); +} +//~^^ ERROR borrowed value does not live long enough diff --git a/src/test/ui/issue-52049.stderr b/src/test/ui/issue-52049.stderr new file mode 100644 index 00000000000..e1e501023fc --- /dev/null +++ b/src/test/ui/issue-52049.stderr @@ -0,0 +1,13 @@ +error[E0597]: borrowed value does not live long enough + --> $DIR/issue-52049.rs:16:10 + | +LL | foo(&unpromotable(5u32)); + | ^^^^^^^^^^^^^^^^^^ - temporary value only lives until here + | | + | temporary value does not live long enough + | + = note: borrowed value must be valid for the static lifetime... + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0597`. diff --git a/src/test/ui/method-on-ambiguous-numeric-type.rs b/src/test/ui/method-on-ambiguous-numeric-type.rs new file mode 100644 index 00000000000..2b6e830ec59 --- /dev/null +++ b/src/test/ui/method-on-ambiguous-numeric-type.rs @@ -0,0 +1,42 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// aux-build:macro-in-other-crate.rs + +#[macro_use] extern crate macro_in_other_crate; + +macro_rules! local_mac { + ($ident:ident) => { let $ident = 42; } +} + +fn main() { + let x = 2.0.neg(); + //~^ ERROR can't call method `neg` on ambiguous numeric type `{float}` + + let y = 2.0; + let x = y.neg(); + //~^ ERROR can't call method `neg` on ambiguous numeric type `{float}` + println!("{:?}", x); + + for i in 0..100 { + println!("{}", i.pow(2)); + //~^ ERROR can't call method `pow` on ambiguous numeric type `{integer}` + } + + local_mac!(local_bar); + local_bar.pow(2); + //~^ ERROR can't call method `pow` on ambiguous numeric type `{integer}` +} + +fn qux() { + mac!(bar); + bar.pow(2); + //~^ ERROR can't call method `pow` on ambiguous numeric type `{integer}` +} diff --git a/src/test/ui/method-on-ambiguous-numeric-type.stderr b/src/test/ui/method-on-ambiguous-numeric-type.stderr new file mode 100644 index 00000000000..796520e0ec7 --- /dev/null +++ b/src/test/ui/method-on-ambiguous-numeric-type.stderr @@ -0,0 +1,51 @@ +error[E0689]: can't call method `neg` on ambiguous numeric type `{float}` + --> $DIR/method-on-ambiguous-numeric-type.rs:20:17 + | +LL | let x = 2.0.neg(); + | ^^^ +help: you must specify a concrete type for this numeric value, like `f32` + | +LL | let x = 2.0_f32.neg(); + | ^^^^^^^ + +error[E0689]: can't call method `neg` on ambiguous numeric type `{float}` + --> $DIR/method-on-ambiguous-numeric-type.rs:24:15 + | +LL | let x = y.neg(); + | ^^^ +help: you must specify a type for this binding, like `f32` + | +LL | let y: f32 = 2.0; + | ^^^^^^ + +error[E0689]: can't call method `pow` on ambiguous numeric type `{integer}` + --> $DIR/method-on-ambiguous-numeric-type.rs:29:26 + | +LL | for i in 0..100 { + | - you must specify a type for this binding, like `i32` +LL | println!("{}", i.pow(2)); + | ^^^ + +error[E0689]: can't call method `pow` on ambiguous numeric type `{integer}` + --> $DIR/method-on-ambiguous-numeric-type.rs:34:15 + | +LL | local_bar.pow(2); + | ^^^ +help: you must specify a type for this binding, like `i32` + | +LL | ($ident:ident) => { let $ident: i32 = 42; } + | ^^^^^^^^^^^ + +error[E0689]: can't call method `pow` on ambiguous numeric type `{integer}` + --> $DIR/method-on-ambiguous-numeric-type.rs:40:9 + | +LL | mac!(bar); + | ---------- you must specify a type for this binding, like `i32` +LL | bar.pow(2); + | ^^^ + | + = 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: aborting due to 5 previous errors + +For more information about this error, try `rustc --explain E0689`. diff --git a/src/test/ui/missing-comma-in-match.fixed b/src/test/ui/missing-comma-in-match.fixed new file mode 100644 index 00000000000..4832f35f42d --- /dev/null +++ b/src/test/ui/missing-comma-in-match.fixed @@ -0,0 +1,21 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// run-rustfix + +fn main() { + match &Some(3) { + &None => 1, + &Some(2) => { 3 } + //~^ ERROR expected one of `,`, `.`, `?`, `}`, or an operator, found `=>` + //~| NOTE expected one of `,`, `.`, `?`, `}`, or an operator here + _ => 2 + }; +} diff --git a/src/test/ui/missing-comma-in-match.rs b/src/test/ui/missing-comma-in-match.rs new file mode 100644 index 00000000000..e39b20e77ea --- /dev/null +++ b/src/test/ui/missing-comma-in-match.rs @@ -0,0 +1,21 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// run-rustfix + +fn main() { + match &Some(3) { + &None => 1 + &Some(2) => { 3 } + //~^ ERROR expected one of `,`, `.`, `?`, `}`, or an operator, found `=>` + //~| NOTE expected one of `,`, `.`, `?`, `}`, or an operator here + _ => 2 + }; +} diff --git a/src/test/ui/missing-comma-in-match.stderr b/src/test/ui/missing-comma-in-match.stderr new file mode 100644 index 00000000000..77935934107 --- /dev/null +++ b/src/test/ui/missing-comma-in-match.stderr @@ -0,0 +1,10 @@ +error: expected one of `,`, `.`, `?`, `}`, or an operator, found `=>` + --> $DIR/missing-comma-in-match.rs:16:18 + | +LL | &None => 1 + | - help: missing a comma here to end this `match` arm +LL | &Some(2) => { 3 } + | ^^ expected one of `,`, `.`, `?`, `}`, or an operator here + +error: aborting due to previous error + diff --git a/src/test/ui/numeric-cast-2.rs b/src/test/ui/numeric-cast-2.rs new file mode 100644 index 00000000000..2092b6bce37 --- /dev/null +++ b/src/test/ui/numeric-cast-2.rs @@ -0,0 +1,21 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn foo() -> i32 { + 4 +} +fn main() { + let x: u16 = foo(); + //~^ ERROR mismatched types + let y: i64 = x + x; + //~^ ERROR mismatched types + let z: i32 = x + x; + //~^ ERROR mismatched types +} diff --git a/src/test/ui/numeric-cast-2.stderr b/src/test/ui/numeric-cast-2.stderr new file mode 100644 index 00000000000..3d485583717 --- /dev/null +++ b/src/test/ui/numeric-cast-2.stderr @@ -0,0 +1,21 @@ +error[E0308]: mismatched types + --> $DIR/numeric-cast-2.rs:15:18 + | +LL | let x: u16 = foo(); + | ^^^^^ expected u16, found i32 + +error[E0308]: mismatched types + --> $DIR/numeric-cast-2.rs:17:18 + | +LL | let y: i64 = x + x; + | ^^^^^ expected i64, found u16 + +error[E0308]: mismatched types + --> $DIR/numeric-cast-2.rs:19:18 + | +LL | let z: i32 = x + x; + | ^^^^^ expected i32, found u16 + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/numeric-cast.rs b/src/test/ui/numeric-cast.rs new file mode 100644 index 00000000000..69bfdfa94b1 --- /dev/null +++ b/src/test/ui/numeric-cast.rs @@ -0,0 +1,320 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + + +fn foo(_x: N) {} + +fn main() { + let x_usize: usize = 1; + let x_u64: u64 = 2; + let x_u32: u32 = 3; + let x_u16: u16 = 4; + let x_u8: u8 = 5; + let x_isize: isize = 6; + let x_i64: i64 = 7; + let x_i32: i32 = 8; + let x_i16: i16 = 9; + let x_i8: i8 = 10; + let x_f64: f64 = 11.0; + let x_f32: f32 = 12.0; + + foo::(x_usize); + foo::(x_u64); + //~^ ERROR mismatched types + foo::(x_u32); + //~^ ERROR mismatched types + foo::(x_u16); + //~^ ERROR mismatched types + foo::(x_u8); + //~^ ERROR mismatched types + foo::(x_isize); + //~^ ERROR mismatched types + foo::(x_i64); + //~^ ERROR mismatched types + foo::(x_i32); + //~^ ERROR mismatched types + foo::(x_i16); + //~^ ERROR mismatched types + foo::(x_i8); + //~^ ERROR mismatched types + foo::(x_f64); + //~^ ERROR mismatched types + foo::(x_f32); + //~^ ERROR mismatched types + + foo::(x_usize); + //~^ ERROR mismatched types + foo::(x_u64); + //~^ ERROR mismatched types + foo::(x_u32); + //~^ ERROR mismatched types + foo::(x_u16); + //~^ ERROR mismatched types + foo::(x_u8); + //~^ ERROR mismatched types + foo::(x_isize); + foo::(x_i64); + //~^ ERROR mismatched types + foo::(x_i32); + //~^ ERROR mismatched types + foo::(x_i16); + //~^ ERROR mismatched types + foo::(x_i8); + //~^ ERROR mismatched types + foo::(x_f64); + //~^ ERROR mismatched types + foo::(x_f32); + //~^ ERROR mismatched types + + foo::(x_usize); + //~^ ERROR mismatched types + foo::(x_u64); + foo::(x_u32); + //~^ ERROR mismatched types + foo::(x_u16); + //~^ ERROR mismatched types + foo::(x_u8); + //~^ ERROR mismatched types + foo::(x_isize); + //~^ ERROR mismatched types + foo::(x_i64); + //~^ ERROR mismatched types + foo::(x_i32); + //~^ ERROR mismatched types + foo::(x_i16); + //~^ ERROR mismatched types + foo::(x_i8); + //~^ ERROR mismatched types + foo::(x_f64); + //~^ ERROR mismatched types + foo::(x_f32); + //~^ ERROR mismatched types + + foo::(x_usize); + //~^ ERROR mismatched types + foo::(x_u64); + //~^ ERROR mismatched types + foo::(x_u32); + //~^ ERROR mismatched types + foo::(x_u16); + //~^ ERROR mismatched types + foo::(x_u8); + //~^ ERROR mismatched types + foo::(x_isize); + //~^ ERROR mismatched types + foo::(x_i64); + foo::(x_i32); + //~^ ERROR mismatched types + foo::(x_i16); + //~^ ERROR mismatched types + foo::(x_i8); + //~^ ERROR mismatched types + foo::(x_f64); + //~^ ERROR mismatched types + foo::(x_f32); + //~^ ERROR mismatched types + + foo::(x_usize); + //~^ ERROR mismatched types + foo::(x_u64); + //~^ ERROR mismatched types + foo::(x_u32); + foo::(x_u16); + //~^ ERROR mismatched types + foo::(x_u8); + //~^ ERROR mismatched types + foo::(x_isize); + //~^ ERROR mismatched types + foo::(x_i64); + //~^ ERROR mismatched types + foo::(x_i32); + //~^ ERROR mismatched types + foo::(x_i16); + //~^ ERROR mismatched types + foo::(x_i8); + //~^ ERROR mismatched types + foo::(x_f64); + //~^ ERROR mismatched types + foo::(x_f32); + //~^ ERROR mismatched types + + foo::(x_usize); + //~^ ERROR mismatched types + foo::(x_u64); + //~^ ERROR mismatched types + foo::(x_u32); + //~^ ERROR mismatched types + foo::(x_u16); + //~^ ERROR mismatched types + foo::(x_u8); + //~^ ERROR mismatched types + foo::(x_isize); + //~^ ERROR mismatched types + foo::(x_i64); + //~^ ERROR mismatched types + foo::(x_i32); + foo::(x_i16); + //~^ ERROR mismatched types + foo::(x_i8); + //~^ ERROR mismatched types + foo::(x_f64); + //~^ ERROR mismatched types + foo::(x_f32); + //~^ ERROR mismatched types + + foo::(x_usize); + //~^ ERROR mismatched types + foo::(x_u64); + //~^ ERROR mismatched types + foo::(x_u32); + //~^ ERROR mismatched types + foo::(x_u16); + foo::(x_u8); + //~^ ERROR mismatched types + foo::(x_isize); + //~^ ERROR mismatched types + foo::(x_i64); + //~^ ERROR mismatched types + foo::(x_i32); + //~^ ERROR mismatched types + foo::(x_i16); + //~^ ERROR mismatched types + foo::(x_i8); + //~^ ERROR mismatched types + foo::(x_f64); + //~^ ERROR mismatched types + foo::(x_f32); + //~^ ERROR mismatched types + + foo::(x_usize); + //~^ ERROR mismatched types + foo::(x_u64); + //~^ ERROR mismatched types + foo::(x_u32); + //~^ ERROR mismatched types + foo::(x_u16); + //~^ ERROR mismatched types + foo::(x_u8); + //~^ ERROR mismatched types + foo::(x_isize); + //~^ ERROR mismatched types + foo::(x_i64); + //~^ ERROR mismatched types + foo::(x_i32); + //~^ ERROR mismatched types + foo::(x_i16); + foo::(x_i8); + //~^ ERROR mismatched types + foo::(x_f64); + //~^ ERROR mismatched types + foo::(x_f32); + //~^ ERROR mismatched types + + foo::(x_usize); + //~^ ERROR mismatched types + foo::(x_u64); + //~^ ERROR mismatched types + foo::(x_u32); + //~^ ERROR mismatched types + foo::(x_u16); + //~^ ERROR mismatched types + foo::(x_u8); + foo::(x_isize); + //~^ ERROR mismatched types + foo::(x_i64); + //~^ ERROR mismatched types + foo::(x_i32); + //~^ ERROR mismatched types + foo::(x_i16); + //~^ ERROR mismatched types + foo::(x_i8); + //~^ ERROR mismatched types + foo::(x_f64); + //~^ ERROR mismatched types + foo::(x_f32); + //~^ ERROR mismatched types + + foo::(x_usize); + //~^ ERROR mismatched types + foo::(x_u64); + //~^ ERROR mismatched types + foo::(x_u32); + //~^ ERROR mismatched types + foo::(x_u16); + //~^ ERROR mismatched types + foo::(x_u8); + //~^ ERROR mismatched types + foo::(x_isize); + //~^ ERROR mismatched types + foo::(x_i64); + //~^ ERROR mismatched types + foo::(x_i32); + //~^ ERROR mismatched types + foo::(x_i16); + //~^ ERROR mismatched types + foo::(x_i8); + foo::(x_f64); + //~^ ERROR mismatched types + foo::(x_f32); + //~^ ERROR mismatched types + + foo::(x_usize); + //~^ ERROR mismatched types + foo::(x_u64); + //~^ ERROR mismatched types + foo::(x_u32); + //~^ ERROR mismatched types + foo::(x_u16); + //~^ ERROR mismatched types + foo::(x_u8); + //~^ ERROR mismatched types + foo::(x_isize); + //~^ ERROR mismatched types + foo::(x_i64); + //~^ ERROR mismatched types + foo::(x_i32); + //~^ ERROR mismatched types + foo::(x_i16); + //~^ ERROR mismatched types + foo::(x_i8); + //~^ ERROR mismatched types + foo::(x_f64); + foo::(x_f32); + //~^ ERROR mismatched types + + foo::(x_usize); + //~^ ERROR mismatched types + foo::(x_u64); + //~^ ERROR mismatched types + foo::(x_u32); + //~^ ERROR mismatched types + foo::(x_u16); + //~^ ERROR mismatched types + foo::(x_u8); + //~^ ERROR mismatched types + foo::(x_isize); + //~^ ERROR mismatched types + foo::(x_i64); + //~^ ERROR mismatched types + foo::(x_i32); + //~^ ERROR mismatched types + foo::(x_i16); + //~^ ERROR mismatched types + foo::(x_i8); + //~^ ERROR mismatched types + foo::(x_f64); + //~^ ERROR mismatched types + foo::(x_f32); + + foo::(x_u8 as u16); + //~^ ERROR mismatched types + foo::(-x_i8); + //~^ ERROR mismatched types +} diff --git a/src/test/ui/numeric-cast.stderr b/src/test/ui/numeric-cast.stderr new file mode 100644 index 00000000000..4aac65ff4cb --- /dev/null +++ b/src/test/ui/numeric-cast.stderr @@ -0,0 +1,907 @@ +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:29:18 + | +LL | foo::(x_u64); + | ^^^^^ expected usize, found u64 + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:31:18 + | +LL | foo::(x_u32); + | ^^^^^ expected usize, found u32 + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:33:18 + | +LL | foo::(x_u16); + | ^^^^^ expected usize, found u16 + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:35:18 + | +LL | foo::(x_u8); + | ^^^^ expected usize, found u8 + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:37:18 + | +LL | foo::(x_isize); + | ^^^^^^^ expected usize, found isize + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:39:18 + | +LL | foo::(x_i64); + | ^^^^^ expected usize, found i64 + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:41:18 + | +LL | foo::(x_i32); + | ^^^^^ expected usize, found i32 + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:43:18 + | +LL | foo::(x_i16); + | ^^^^^ expected usize, found i16 + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:45:18 + | +LL | foo::(x_i8); + | ^^^^ expected usize, found i8 + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:47:18 + | +LL | foo::(x_f64); + | ^^^^^ expected usize, found f64 + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:49:18 + | +LL | foo::(x_f32); + | ^^^^^ expected usize, found f32 + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:52:18 + | +LL | foo::(x_usize); + | ^^^^^^^ expected isize, found usize + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:54:18 + | +LL | foo::(x_u64); + | ^^^^^ expected isize, found u64 + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:56:18 + | +LL | foo::(x_u32); + | ^^^^^ expected isize, found u32 + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:58:18 + | +LL | foo::(x_u16); + | ^^^^^ expected isize, found u16 + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:60:18 + | +LL | foo::(x_u8); + | ^^^^ expected isize, found u8 + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:63:18 + | +LL | foo::(x_i64); + | ^^^^^ expected isize, found i64 + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:65:18 + | +LL | foo::(x_i32); + | ^^^^^ expected isize, found i32 + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:67:18 + | +LL | foo::(x_i16); + | ^^^^^ expected isize, found i16 + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:69:18 + | +LL | foo::(x_i8); + | ^^^^ expected isize, found i8 + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:71:18 + | +LL | foo::(x_f64); + | ^^^^^ expected isize, found f64 + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:73:18 + | +LL | foo::(x_f32); + | ^^^^^ expected isize, found f32 + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:76:16 + | +LL | foo::(x_usize); + | ^^^^^^^ expected u64, found usize + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:79:16 + | +LL | foo::(x_u32); + | ^^^^^ expected u64, found u32 +help: you can cast an `u32` to `u64`, which will zero-extend the source value + | +LL | foo::(x_u32.into()); + | ^^^^^^^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:81:16 + | +LL | foo::(x_u16); + | ^^^^^ expected u64, found u16 +help: you can cast an `u16` to `u64`, which will zero-extend the source value + | +LL | foo::(x_u16.into()); + | ^^^^^^^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:83:16 + | +LL | foo::(x_u8); + | ^^^^ expected u64, found u8 +help: you can cast an `u8` to `u64`, which will zero-extend the source value + | +LL | foo::(x_u8.into()); + | ^^^^^^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:85:16 + | +LL | foo::(x_isize); + | ^^^^^^^ expected u64, found isize + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:87:16 + | +LL | foo::(x_i64); + | ^^^^^ expected u64, found i64 + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:89:16 + | +LL | foo::(x_i32); + | ^^^^^ expected u64, found i32 + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:91:16 + | +LL | foo::(x_i16); + | ^^^^^ expected u64, found i16 + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:93:16 + | +LL | foo::(x_i8); + | ^^^^ expected u64, found i8 + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:95:16 + | +LL | foo::(x_f64); + | ^^^^^ expected u64, found f64 + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:97:16 + | +LL | foo::(x_f32); + | ^^^^^ expected u64, found f32 + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:100:16 + | +LL | foo::(x_usize); + | ^^^^^^^ expected i64, found usize + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:102:16 + | +LL | foo::(x_u64); + | ^^^^^ expected i64, found u64 + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:104:16 + | +LL | foo::(x_u32); + | ^^^^^ expected i64, found u32 + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:106:16 + | +LL | foo::(x_u16); + | ^^^^^ expected i64, found u16 + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:108:16 + | +LL | foo::(x_u8); + | ^^^^ expected i64, found u8 + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:110:16 + | +LL | foo::(x_isize); + | ^^^^^^^ expected i64, found isize + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:113:16 + | +LL | foo::(x_i32); + | ^^^^^ expected i64, found i32 +help: you can cast an `i32` to `i64`, which will sign-extend the source value + | +LL | foo::(x_i32.into()); + | ^^^^^^^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:115:16 + | +LL | foo::(x_i16); + | ^^^^^ expected i64, found i16 +help: you can cast an `i16` to `i64`, which will sign-extend the source value + | +LL | foo::(x_i16.into()); + | ^^^^^^^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:117:16 + | +LL | foo::(x_i8); + | ^^^^ expected i64, found i8 +help: you can cast an `i8` to `i64`, which will sign-extend the source value + | +LL | foo::(x_i8.into()); + | ^^^^^^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:119:16 + | +LL | foo::(x_f64); + | ^^^^^ expected i64, found f64 + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:121:16 + | +LL | foo::(x_f32); + | ^^^^^ expected i64, found f32 + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:124:16 + | +LL | foo::(x_usize); + | ^^^^^^^ expected u32, found usize + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:126:16 + | +LL | foo::(x_u64); + | ^^^^^ expected u32, found u64 + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:129:16 + | +LL | foo::(x_u16); + | ^^^^^ expected u32, found u16 +help: you can cast an `u16` to `u32`, which will zero-extend the source value + | +LL | foo::(x_u16.into()); + | ^^^^^^^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:131:16 + | +LL | foo::(x_u8); + | ^^^^ expected u32, found u8 +help: you can cast an `u8` to `u32`, which will zero-extend the source value + | +LL | foo::(x_u8.into()); + | ^^^^^^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:133:16 + | +LL | foo::(x_isize); + | ^^^^^^^ expected u32, found isize + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:135:16 + | +LL | foo::(x_i64); + | ^^^^^ expected u32, found i64 + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:137:16 + | +LL | foo::(x_i32); + | ^^^^^ expected u32, found i32 + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:139:16 + | +LL | foo::(x_i16); + | ^^^^^ expected u32, found i16 + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:141:16 + | +LL | foo::(x_i8); + | ^^^^ expected u32, found i8 + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:143:16 + | +LL | foo::(x_f64); + | ^^^^^ expected u32, found f64 + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:145:16 + | +LL | foo::(x_f32); + | ^^^^^ expected u32, found f32 + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:148:16 + | +LL | foo::(x_usize); + | ^^^^^^^ expected i32, found usize + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:150:16 + | +LL | foo::(x_u64); + | ^^^^^ expected i32, found u64 + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:152:16 + | +LL | foo::(x_u32); + | ^^^^^ expected i32, found u32 + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:154:16 + | +LL | foo::(x_u16); + | ^^^^^ expected i32, found u16 + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:156:16 + | +LL | foo::(x_u8); + | ^^^^ expected i32, found u8 + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:158:16 + | +LL | foo::(x_isize); + | ^^^^^^^ expected i32, found isize + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:160:16 + | +LL | foo::(x_i64); + | ^^^^^ expected i32, found i64 + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:163:16 + | +LL | foo::(x_i16); + | ^^^^^ expected i32, found i16 +help: you can cast an `i16` to `i32`, which will sign-extend the source value + | +LL | foo::(x_i16.into()); + | ^^^^^^^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:165:16 + | +LL | foo::(x_i8); + | ^^^^ expected i32, found i8 +help: you can cast an `i8` to `i32`, which will sign-extend the source value + | +LL | foo::(x_i8.into()); + | ^^^^^^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:167:16 + | +LL | foo::(x_f64); + | ^^^^^ expected i32, found f64 + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:169:16 + | +LL | foo::(x_f32); + | ^^^^^ expected i32, found f32 + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:172:16 + | +LL | foo::(x_usize); + | ^^^^^^^ expected u16, found usize + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:174:16 + | +LL | foo::(x_u64); + | ^^^^^ expected u16, found u64 + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:176:16 + | +LL | foo::(x_u32); + | ^^^^^ expected u16, found u32 + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:179:16 + | +LL | foo::(x_u8); + | ^^^^ expected u16, found u8 +help: you can cast an `u8` to `u16`, which will zero-extend the source value + | +LL | foo::(x_u8.into()); + | ^^^^^^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:181:16 + | +LL | foo::(x_isize); + | ^^^^^^^ expected u16, found isize + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:183:16 + | +LL | foo::(x_i64); + | ^^^^^ expected u16, found i64 + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:185:16 + | +LL | foo::(x_i32); + | ^^^^^ expected u16, found i32 + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:187:16 + | +LL | foo::(x_i16); + | ^^^^^ expected u16, found i16 + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:189:16 + | +LL | foo::(x_i8); + | ^^^^ expected u16, found i8 + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:191:16 + | +LL | foo::(x_f64); + | ^^^^^ expected u16, found f64 + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:193:16 + | +LL | foo::(x_f32); + | ^^^^^ expected u16, found f32 + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:196:16 + | +LL | foo::(x_usize); + | ^^^^^^^ expected i16, found usize + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:198:16 + | +LL | foo::(x_u64); + | ^^^^^ expected i16, found u64 + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:200:16 + | +LL | foo::(x_u32); + | ^^^^^ expected i16, found u32 + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:202:16 + | +LL | foo::(x_u16); + | ^^^^^ expected i16, found u16 + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:204:16 + | +LL | foo::(x_u8); + | ^^^^ expected i16, found u8 + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:206:16 + | +LL | foo::(x_isize); + | ^^^^^^^ expected i16, found isize + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:208:16 + | +LL | foo::(x_i64); + | ^^^^^ expected i16, found i64 + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:210:16 + | +LL | foo::(x_i32); + | ^^^^^ expected i16, found i32 + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:213:16 + | +LL | foo::(x_i8); + | ^^^^ expected i16, found i8 +help: you can cast an `i8` to `i16`, which will sign-extend the source value + | +LL | foo::(x_i8.into()); + | ^^^^^^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:215:16 + | +LL | foo::(x_f64); + | ^^^^^ expected i16, found f64 + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:217:16 + | +LL | foo::(x_f32); + | ^^^^^ expected i16, found f32 + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:220:15 + | +LL | foo::(x_usize); + | ^^^^^^^ expected u8, found usize + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:222:15 + | +LL | foo::(x_u64); + | ^^^^^ expected u8, found u64 + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:224:15 + | +LL | foo::(x_u32); + | ^^^^^ expected u8, found u32 + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:226:15 + | +LL | foo::(x_u16); + | ^^^^^ expected u8, found u16 + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:229:15 + | +LL | foo::(x_isize); + | ^^^^^^^ expected u8, found isize + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:231:15 + | +LL | foo::(x_i64); + | ^^^^^ expected u8, found i64 + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:233:15 + | +LL | foo::(x_i32); + | ^^^^^ expected u8, found i32 + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:235:15 + | +LL | foo::(x_i16); + | ^^^^^ expected u8, found i16 + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:237:15 + | +LL | foo::(x_i8); + | ^^^^ expected u8, found i8 + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:239:15 + | +LL | foo::(x_f64); + | ^^^^^ expected u8, found f64 + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:241:15 + | +LL | foo::(x_f32); + | ^^^^^ expected u8, found f32 + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:244:15 + | +LL | foo::(x_usize); + | ^^^^^^^ expected i8, found usize + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:246:15 + | +LL | foo::(x_u64); + | ^^^^^ expected i8, found u64 + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:248:15 + | +LL | foo::(x_u32); + | ^^^^^ expected i8, found u32 + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:250:15 + | +LL | foo::(x_u16); + | ^^^^^ expected i8, found u16 + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:252:15 + | +LL | foo::(x_u8); + | ^^^^ expected i8, found u8 + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:254:15 + | +LL | foo::(x_isize); + | ^^^^^^^ expected i8, found isize + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:256:15 + | +LL | foo::(x_i64); + | ^^^^^ expected i8, found i64 + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:258:15 + | +LL | foo::(x_i32); + | ^^^^^ expected i8, found i32 + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:260:15 + | +LL | foo::(x_i16); + | ^^^^^ expected i8, found i16 + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:263:15 + | +LL | foo::(x_f64); + | ^^^^^ expected i8, found f64 + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:265:15 + | +LL | foo::(x_f32); + | ^^^^^ expected i8, found f32 + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:268:16 + | +LL | foo::(x_usize); + | ^^^^^^^ expected f64, found usize + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:270:16 + | +LL | foo::(x_u64); + | ^^^^^ expected f64, found u64 + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:272:16 + | +LL | foo::(x_u32); + | ^^^^^ expected f64, found u32 +help: you can cast an `u32` to `f64`, producing the floating point representation of the integer + | +LL | foo::(x_u32.into()); + | ^^^^^^^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:274:16 + | +LL | foo::(x_u16); + | ^^^^^ expected f64, found u16 +help: you can cast an `u16` to `f64`, producing the floating point representation of the integer + | +LL | foo::(x_u16.into()); + | ^^^^^^^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:276:16 + | +LL | foo::(x_u8); + | ^^^^ expected f64, found u8 +help: you can cast an `u8` to `f64`, producing the floating point representation of the integer + | +LL | foo::(x_u8.into()); + | ^^^^^^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:278:16 + | +LL | foo::(x_isize); + | ^^^^^^^ expected f64, found isize + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:280:16 + | +LL | foo::(x_i64); + | ^^^^^ expected f64, found i64 + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:282:16 + | +LL | foo::(x_i32); + | ^^^^^ expected f64, found i32 +help: you can cast an `i32` to `f64`, producing the floating point representation of the integer + | +LL | foo::(x_i32.into()); + | ^^^^^^^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:284:16 + | +LL | foo::(x_i16); + | ^^^^^ expected f64, found i16 +help: you can cast an `i16` to `f64`, producing the floating point representation of the integer + | +LL | foo::(x_i16.into()); + | ^^^^^^^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:286:16 + | +LL | foo::(x_i8); + | ^^^^ expected f64, found i8 +help: you can cast an `i8` to `f64`, producing the floating point representation of the integer + | +LL | foo::(x_i8.into()); + | ^^^^^^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:289:16 + | +LL | foo::(x_f32); + | ^^^^^ expected f64, found f32 +help: you can cast an `f32` to `f64` in a lossless way + | +LL | foo::(x_f32.into()); + | ^^^^^^^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:292:16 + | +LL | foo::(x_usize); + | ^^^^^^^ expected f32, found usize + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:294:16 + | +LL | foo::(x_u64); + | ^^^^^ expected f32, found u64 + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:296:16 + | +LL | foo::(x_u32); + | ^^^^^ expected f32, found u32 + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:298:16 + | +LL | foo::(x_u16); + | ^^^^^ expected f32, found u16 +help: you can cast an `u16` to `f32`, producing the floating point representation of the integer + | +LL | foo::(x_u16.into()); + | ^^^^^^^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:300:16 + | +LL | foo::(x_u8); + | ^^^^ expected f32, found u8 +help: you can cast an `u8` to `f32`, producing the floating point representation of the integer + | +LL | foo::(x_u8.into()); + | ^^^^^^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:302:16 + | +LL | foo::(x_isize); + | ^^^^^^^ expected f32, found isize + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:304:16 + | +LL | foo::(x_i64); + | ^^^^^ expected f32, found i64 + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:306:16 + | +LL | foo::(x_i32); + | ^^^^^ expected f32, found i32 + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:308:16 + | +LL | foo::(x_i16); + | ^^^^^ expected f32, found i16 +help: you can cast an `i16` to `f32`, producing the floating point representation of the integer + | +LL | foo::(x_i16.into()); + | ^^^^^^^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:310:16 + | +LL | foo::(x_i8); + | ^^^^ expected f32, found i8 +help: you can cast an `i8` to `f32`, producing the floating point representation of the integer + | +LL | foo::(x_i8.into()); + | ^^^^^^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:312:16 + | +LL | foo::(x_f64); + | ^^^^^ expected f32, found f64 + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:316:16 + | +LL | foo::(x_u8 as u16); + | ^^^^^^^^^^^ expected u32, found u16 +help: you can cast an `u16` to `u32`, which will zero-extend the source value + | +LL | foo::((x_u8 as u16).into()); + | ^^^^^^^^^^^^^^^^^^^^ + +error[E0308]: mismatched types + --> $DIR/numeric-cast.rs:318:16 + | +LL | foo::(-x_i8); + | ^^^^^ expected i32, found i8 +help: you can cast an `i8` to `i32`, which will sign-extend the source value + | +LL | foo::((-x_i8).into()); + | ^^^^^^^^^^^^^^ + +error: aborting due to 134 previous errors + +For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/placement-syntax.rs b/src/test/ui/placement-syntax.rs new file mode 100644 index 00000000000..39252597a23 --- /dev/null +++ b/src/test/ui/placement-syntax.rs @@ -0,0 +1,17 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn main() { + let x = -5; + if x<-1 { + //~^ ERROR emplacement syntax is obsolete + println!("ok"); + } +} diff --git a/src/test/ui/placement-syntax.stderr b/src/test/ui/placement-syntax.stderr new file mode 100644 index 00000000000..933ba96519c --- /dev/null +++ b/src/test/ui/placement-syntax.stderr @@ -0,0 +1,14 @@ +error: emplacement syntax is obsolete (for now, anyway) + --> $DIR/placement-syntax.rs:13:8 + | +LL | if x<-1 { + | ^^^^ + | + = note: for more information, see +help: if you meant to write a comparison against a negative value, add a space in between `<` and `-` + | +LL | if x< -1 { + | ^^^ + +error: aborting due to previous error + diff --git a/src/test/ui/pub-ident-fn-2.rs b/src/test/ui/pub-ident-fn-2.rs new file mode 100644 index 00000000000..44884bfcdfd --- /dev/null +++ b/src/test/ui/pub-ident-fn-2.rs @@ -0,0 +1,16 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +pub foo(s: usize) { bar() } +//~^ ERROR missing `fn` for method definition + +fn main() { + foo(2); +} diff --git a/src/test/ui/pub-ident-fn-2.stderr b/src/test/ui/pub-ident-fn-2.stderr new file mode 100644 index 00000000000..bbbb3df8769 --- /dev/null +++ b/src/test/ui/pub-ident-fn-2.stderr @@ -0,0 +1,12 @@ +error: missing `fn` for method definition + --> $DIR/pub-ident-fn-2.rs:11:4 + | +LL | pub foo(s: usize) { bar() } + | ^ +help: add `fn` here to parse `foo` as a public method + | +LL | pub fn foo(s: usize) { bar() } + | ^^ + +error: aborting due to previous error + diff --git a/src/test/ui/pub-ident-fn-or-struct-2.rs b/src/test/ui/pub-ident-fn-or-struct-2.rs new file mode 100644 index 00000000000..1ccadc8a40b --- /dev/null +++ b/src/test/ui/pub-ident-fn-or-struct-2.rs @@ -0,0 +1,14 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +pub S(); +//~^ ERROR missing `fn` or `struct` for method or struct definition + +fn main() {} diff --git a/src/test/ui/pub-ident-fn-or-struct-2.stderr b/src/test/ui/pub-ident-fn-or-struct-2.stderr new file mode 100644 index 00000000000..e492a8c4756 --- /dev/null +++ b/src/test/ui/pub-ident-fn-or-struct-2.stderr @@ -0,0 +1,8 @@ +error: missing `fn` or `struct` for method or struct definition + --> $DIR/pub-ident-fn-or-struct-2.rs:11:4 + | +LL | pub S(); + | ---^- help: if you meant to call a macro, try: `S!` + +error: aborting due to previous error + diff --git a/src/test/ui/pub-ident-fn-or-struct.rs b/src/test/ui/pub-ident-fn-or-struct.rs new file mode 100644 index 00000000000..0664918945b --- /dev/null +++ b/src/test/ui/pub-ident-fn-or-struct.rs @@ -0,0 +1,14 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +pub S (foo) bar +//~^ ERROR missing `fn` or `struct` for method or struct definition + +fn main() {} diff --git a/src/test/ui/pub-ident-fn-or-struct.stderr b/src/test/ui/pub-ident-fn-or-struct.stderr new file mode 100644 index 00000000000..c1bff34cec3 --- /dev/null +++ b/src/test/ui/pub-ident-fn-or-struct.stderr @@ -0,0 +1,8 @@ +error: missing `fn` or `struct` for method or struct definition + --> $DIR/pub-ident-fn-or-struct.rs:11:4 + | +LL | pub S (foo) bar + | ---^- help: if you meant to call a macro, try: `S!` + +error: aborting due to previous error + diff --git a/src/test/ui/pub-ident-fn.fixed b/src/test/ui/pub-ident-fn.fixed new file mode 100644 index 00000000000..f2d0c6c3e1d --- /dev/null +++ b/src/test/ui/pub-ident-fn.fixed @@ -0,0 +1,18 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// run-rustfix + +pub fn foo(_s: usize) -> bool { true } +//~^ ERROR missing `fn` for method definition + +fn main() { + foo(2); +} diff --git a/src/test/ui/pub-ident-fn.rs b/src/test/ui/pub-ident-fn.rs new file mode 100644 index 00000000000..82c32f57eea --- /dev/null +++ b/src/test/ui/pub-ident-fn.rs @@ -0,0 +1,18 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// run-rustfix + +pub foo(_s: usize) -> bool { true } +//~^ ERROR missing `fn` for method definition + +fn main() { + foo(2); +} diff --git a/src/test/ui/pub-ident-fn.stderr b/src/test/ui/pub-ident-fn.stderr new file mode 100644 index 00000000000..f7c96b8b9f4 --- /dev/null +++ b/src/test/ui/pub-ident-fn.stderr @@ -0,0 +1,12 @@ +error: missing `fn` for method definition + --> $DIR/pub-ident-fn.rs:13:4 + | +LL | pub foo(_s: usize) -> bool { true } + | ^^^ +help: add `fn` here to parse `foo` as a public method + | +LL | pub fn foo(_s: usize) -> bool { true } + | ^^ + +error: aborting due to previous error + diff --git a/src/test/ui/pub-ident-struct.rs b/src/test/ui/pub-ident-struct.rs new file mode 100644 index 00000000000..d08d498f87a --- /dev/null +++ b/src/test/ui/pub-ident-struct.rs @@ -0,0 +1,14 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +pub S { +//~^ ERROR missing `struct` for struct definition +} +fn main() {} diff --git a/src/test/ui/pub-ident-struct.stderr b/src/test/ui/pub-ident-struct.stderr new file mode 100644 index 00000000000..cd53cea7212 --- /dev/null +++ b/src/test/ui/pub-ident-struct.stderr @@ -0,0 +1,12 @@ +error: missing `struct` for struct definition + --> $DIR/pub-ident-struct.rs:11:4 + | +LL | pub S { + | ^ +help: add `struct` here to parse `S` as a public struct + | +LL | pub struct S { + | ^^^^^^ + +error: aborting due to previous error + diff --git a/src/test/ui/removing-extern-crate.fixed b/src/test/ui/removing-extern-crate.fixed new file mode 100644 index 00000000000..83b35cec809 --- /dev/null +++ b/src/test/ui/removing-extern-crate.fixed @@ -0,0 +1,27 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// compile-flags: --edition 2018 +// aux-build:removing-extern-crate.rs +// run-rustfix +// compile-pass + +#![warn(rust_2018_idioms)] +#![allow(unused_imports)] + + + + +mod another { + + +} + +fn main() {} diff --git a/src/test/ui/removing-extern-crate.rs b/src/test/ui/removing-extern-crate.rs new file mode 100644 index 00000000000..29479086460 --- /dev/null +++ b/src/test/ui/removing-extern-crate.rs @@ -0,0 +1,27 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// compile-flags: --edition 2018 +// aux-build:removing-extern-crate.rs +// run-rustfix +// compile-pass + +#![warn(rust_2018_idioms)] +#![allow(unused_imports)] + +extern crate std as foo; +extern crate core; + +mod another { + extern crate std as foo; + extern crate std; +} + +fn main() {} diff --git a/src/test/ui/removing-extern-crate.stderr b/src/test/ui/removing-extern-crate.stderr new file mode 100644 index 00000000000..f2eed27a266 --- /dev/null +++ b/src/test/ui/removing-extern-crate.stderr @@ -0,0 +1,31 @@ +warning: unused extern crate + --> $DIR/removing-extern-crate.rs:19:1 + | +LL | extern crate std as foo; + | ^^^^^^^^^^^^^^^^^^^^^^^^ help: remove it + | +note: lint level defined here + --> $DIR/removing-extern-crate.rs:16:9 + | +LL | #![warn(rust_2018_idioms)] + | ^^^^^^^^^^^^^^^^ + = note: #[warn(unused_extern_crates)] implied by #[warn(rust_2018_idioms)] + +warning: unused extern crate + --> $DIR/removing-extern-crate.rs:20:1 + | +LL | extern crate core; + | ^^^^^^^^^^^^^^^^^^ help: remove it + +warning: unused extern crate + --> $DIR/removing-extern-crate.rs:23:5 + | +LL | extern crate std as foo; + | ^^^^^^^^^^^^^^^^^^^^^^^^ help: remove it + +warning: unused extern crate + --> $DIR/removing-extern-crate.rs:24:5 + | +LL | extern crate std; + | ^^^^^^^^^^^^^^^^^ help: remove it + diff --git a/src/test/ui/repr.rs b/src/test/ui/repr.rs new file mode 100644 index 00000000000..312f60202c6 --- /dev/null +++ b/src/test/ui/repr.rs @@ -0,0 +1,28 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// compile-pass + +#[repr] +//^ WARN `repr` attribute must have a hint +struct _A {} + +#[repr = "B"] +//^ WARN `repr` attribute isn't configurable with a literal +struct _B {} + +#[repr = "C"] +//^ WARN `repr` attribute isn't configurable with a literal +struct _C {} + +#[repr(C)] +struct _D {} + +fn main() {} diff --git a/src/test/ui/repr.stderr b/src/test/ui/repr.stderr new file mode 100644 index 00000000000..7a99d8c0448 --- /dev/null +++ b/src/test/ui/repr.stderr @@ -0,0 +1,25 @@ +warning: `repr` attribute must have a hint + --> $DIR/repr.rs:13:1 + | +LL | #[repr] + | ^^^^^^^ needs a hint + | + = note: #[warn(bad_repr)] on by default + = help: valid hints include `#[repr(C)]`, `#[repr(packed)]`, `#[repr(rust)]` and `#[repr(transparent)]` + = note: for more information, visit + +warning: `repr` attribute isn't configurable with a literal + --> $DIR/repr.rs:17:1 + | +LL | #[repr = "B"] + | ^^^^^^^^^^^^^ needs a hint + | + = help: valid hints include `#[repr(C)]`, `#[repr(packed)]`, `#[repr(rust)]` and `#[repr(transparent)]` + = note: for more information, visit + +warning: `repr` attribute isn't configurable with a literal + --> $DIR/repr.rs:21:1 + | +LL | #[repr = "C"] + | ^^^^^^^^^^^^^ help: give `repr` a hint: `#[repr(C)]` + diff --git a/src/test/ui/return-type.rs b/src/test/ui/return-type.rs new file mode 100644 index 00000000000..e63787949a4 --- /dev/null +++ b/src/test/ui/return-type.rs @@ -0,0 +1,24 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +struct S { + t: T, +} + +fn foo(x: T) -> S { + S { t: x } +} + +fn bar() { + foo(4 as usize) + //~^ ERROR mismatched types +} + +fn main() {} diff --git a/src/test/ui/return-type.stderr b/src/test/ui/return-type.stderr new file mode 100644 index 00000000000..7d7653eee28 --- /dev/null +++ b/src/test/ui/return-type.stderr @@ -0,0 +1,20 @@ +error[E0308]: mismatched types + --> $DIR/return-type.rs:20:5 + | +LL | foo(4 as usize) + | ^^^^^^^^^^^^^^^ expected (), found struct `S` + | + = note: expected type `()` + found type `S` +help: try adding a semicolon + | +LL | foo(4 as usize); + | ^ +help: try adding a return type + | +LL | fn bar() -> S { + | ^^^^^^^^^^^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/single-use-lifetime/one-use-in-fn-argument-in-band.stderr b/src/test/ui/single-use-lifetime/one-use-in-fn-argument-in-band.stderr index 3dd2675646c..6d18075ba37 100644 --- a/src/test/ui/single-use-lifetime/one-use-in-fn-argument-in-band.stderr +++ b/src/test/ui/single-use-lifetime/one-use-in-fn-argument-in-band.stderr @@ -1,11 +1,11 @@ -error: lifetime parameter `'b` only used once - --> $DIR/one-use-in-fn-argument-in-band.rs:19:22 +error: lifetime parameter `'a` only used once + --> $DIR/one-use-in-fn-argument-in-band.rs:19:10 | LL | fn a(x: &'a u32, y: &'b u32) { - | ^^ - | | - | this lifetime... - | ...is used only here + | ^^ + | | + | this lifetime... + | ...is used only here | note: lint level defined here --> $DIR/one-use-in-fn-argument-in-band.rs:12:9 @@ -13,14 +13,14 @@ note: lint level defined here LL | #![deny(single_use_lifetimes)] | ^^^^^^^^^^^^^^^^^^^^ -error: lifetime parameter `'a` only used once - --> $DIR/one-use-in-fn-argument-in-band.rs:19:10 +error: lifetime parameter `'b` only used once + --> $DIR/one-use-in-fn-argument-in-band.rs:19:22 | LL | fn a(x: &'a u32, y: &'b u32) { - | ^^ - | | - | this lifetime... - | ...is used only here + | ^^ + | | + | this lifetime... + | ...is used only here error: aborting due to 2 previous errors diff --git a/src/test/ui/str-array-assignment.rs b/src/test/ui/str-array-assignment.rs new file mode 100644 index 00000000000..9d6cf5fe598 --- /dev/null +++ b/src/test/ui/str-array-assignment.rs @@ -0,0 +1,21 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn main() { + let s = "abc"; + let t = if true { s[..2] } else { s }; + //~^ ERROR if and else have incompatible types + let u: &str = if true { s[..2] } else { s }; + //~^ ERROR mismatched types + let v = s[..2]; + //~^ ERROR the size for values of type + let w: &str = s[..2]; + //~^ ERROR mismatched types +} diff --git a/src/test/ui/str-array-assignment.stderr b/src/test/ui/str-array-assignment.stderr new file mode 100644 index 00000000000..7a774cab38e --- /dev/null +++ b/src/test/ui/str-array-assignment.stderr @@ -0,0 +1,49 @@ +error[E0308]: if and else have incompatible types + --> $DIR/str-array-assignment.rs:13:11 + | +LL | let t = if true { s[..2] } else { s }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected str, found &str + | + = note: expected type `str` + found type `&str` + +error[E0308]: mismatched types + --> $DIR/str-array-assignment.rs:15:27 + | +LL | let u: &str = if true { s[..2] } else { s }; + | ^^^^^^ + | | + | expected &str, found str + | help: consider borrowing here: `&s[..2]` + | + = note: expected type `&str` + found type `str` + +error[E0277]: the size for values of type `str` cannot be known at compilation time + --> $DIR/str-array-assignment.rs:17:7 + | +LL | let v = s[..2]; + | ^ ------ help: consider borrowing here: `&s[..2]` + | | + | doesn't have a size known at compile-time + | + = help: the trait `std::marker::Sized` is not implemented for `str` + = note: to learn more, visit + = note: all local variables must have a statically known size + +error[E0308]: mismatched types + --> $DIR/str-array-assignment.rs:19:17 + | +LL | let w: &str = s[..2]; + | ^^^^^^ + | | + | expected &str, found str + | help: consider borrowing here: `&s[..2]` + | + = note: expected type `&str` + found type `str` + +error: aborting due to 4 previous errors + +Some errors occurred: E0277, E0308. +For more information about an error, try `rustc --explain E0277`. diff --git a/src/test/ui/str-as-char.fixed b/src/test/ui/str-as-char.fixed new file mode 100644 index 00000000000..c0dad38e436 --- /dev/null +++ b/src/test/ui/str-as-char.fixed @@ -0,0 +1,16 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// run-rustfix + +fn main() { + println!("●●"); + //~^ ERROR character literal may only contain one codepoint +} diff --git a/src/test/ui/str-as-char.rs b/src/test/ui/str-as-char.rs new file mode 100644 index 00000000000..b5a5df0af7f --- /dev/null +++ b/src/test/ui/str-as-char.rs @@ -0,0 +1,16 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// run-rustfix + +fn main() { + println!('●●'); + //~^ ERROR character literal may only contain one codepoint +} diff --git a/src/test/ui/str-as-char.stderr b/src/test/ui/str-as-char.stderr new file mode 100644 index 00000000000..60eb182adf1 --- /dev/null +++ b/src/test/ui/str-as-char.stderr @@ -0,0 +1,12 @@ +error: character literal may only contain one codepoint + --> $DIR/str-as-char.rs:14:14 + | +LL | println!('●●'); + | ^^^^ +help: if you meant to write a `str` literal, use double quotes + | +LL | println!("●●"); + | ^^^^ + +error: aborting due to previous error + diff --git a/src/test/ui/suggest-labels.rs b/src/test/ui/suggest-labels.rs new file mode 100644 index 00000000000..9fb519c57ed --- /dev/null +++ b/src/test/ui/suggest-labels.rs @@ -0,0 +1,26 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#[allow(unreachable_code, unused_labels)] +fn main() { + 'foo: loop { + break 'fo; //~ ERROR use of undeclared label + } + + 'bar: loop { + continue 'bor; //~ ERROR use of undeclared label + } + + 'longlabel: loop { + 'longlabel1: loop { + break 'longlable; //~ ERROR use of undeclared label + } + } +} diff --git a/src/test/ui/suggest-labels.stderr b/src/test/ui/suggest-labels.stderr new file mode 100644 index 00000000000..671ff1a56db --- /dev/null +++ b/src/test/ui/suggest-labels.stderr @@ -0,0 +1,21 @@ +error[E0426]: use of undeclared label `'fo` + --> $DIR/suggest-labels.rs:14:15 + | +LL | break 'fo; //~ ERROR use of undeclared label + | ^^^ did you mean `'foo`? + +error[E0426]: use of undeclared label `'bor` + --> $DIR/suggest-labels.rs:18:18 + | +LL | continue 'bor; //~ ERROR use of undeclared label + | ^^^^ did you mean `'bar`? + +error[E0426]: use of undeclared label `'longlable` + --> $DIR/suggest-labels.rs:23:19 + | +LL | break 'longlable; //~ ERROR use of undeclared label + | ^^^^^^^^^^ did you mean `'longlabel1`? + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0426`. diff --git a/src/test/ui/suggest-methods.rs b/src/test/ui/suggest-methods.rs new file mode 100644 index 00000000000..49027deecc1 --- /dev/null +++ b/src/test/ui/suggest-methods.rs @@ -0,0 +1,40 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +struct Foo; + +impl Foo { + fn bar(self) {} + fn baz(&self, x: f64) {} +} + +trait FooT { + fn bag(&self); +} + +impl FooT for Foo { + fn bag(&self) {} +} + +fn main() { + let f = Foo; + f.bat(1.0); //~ ERROR no method named + + let s = "foo".to_string(); + let _ = s.is_emtpy(); //~ ERROR no method named + + // Generates a warning for `count_zeros()`. `count_ones()` is also a close + // match, but the former is closer. + let _ = 63u32.count_eos(); //~ ERROR no method named + + // Does not generate a warning + let _ = 63u32.count_o(); //~ ERROR no method named + +} diff --git a/src/test/ui/suggest-methods.stderr b/src/test/ui/suggest-methods.stderr new file mode 100644 index 00000000000..cb352361f33 --- /dev/null +++ b/src/test/ui/suggest-methods.stderr @@ -0,0 +1,36 @@ +error[E0599]: no method named `bat` found for type `Foo` in the current scope + --> $DIR/suggest-methods.rs:28:7 + | +LL | struct Foo; + | ----------- method `bat` not found for this +... +LL | f.bat(1.0); //~ ERROR no method named + | ^^^ + | + = help: did you mean `bar`? + +error[E0599]: no method named `is_emtpy` found for type `std::string::String` in the current scope + --> $DIR/suggest-methods.rs:31:15 + | +LL | let _ = s.is_emtpy(); //~ ERROR no method named + | ^^^^^^^^ + | + = help: did you mean `is_empty`? + +error[E0599]: no method named `count_eos` found for type `u32` in the current scope + --> $DIR/suggest-methods.rs:35:19 + | +LL | let _ = 63u32.count_eos(); //~ ERROR no method named + | ^^^^^^^^^ + | + = help: did you mean `count_zeros`? + +error[E0599]: no method named `count_o` found for type `u32` in the current scope + --> $DIR/suggest-methods.rs:38:19 + | +LL | let _ = 63u32.count_o(); //~ ERROR no method named + | ^^^^^^^ + +error: aborting due to 4 previous errors + +For more information about this error, try `rustc --explain E0599`. diff --git a/src/test/ui/suggest-ref-mut.rs b/src/test/ui/suggest-ref-mut.rs new file mode 100644 index 00000000000..30b5371af1a --- /dev/null +++ b/src/test/ui/suggest-ref-mut.rs @@ -0,0 +1,42 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![feature(nll)] + +struct X(usize); + +impl X { + fn zap(&self) { + //~^ HELP + //~| SUGGESTION &mut self + self.0 = 32; + //~^ ERROR + } +} + +fn main() { + let ref foo = 16; + //~^ HELP + //~| SUGGESTION ref mut foo + *foo = 32; + //~^ ERROR + if let Some(ref bar) = Some(16) { + //~^ HELP + //~| SUGGESTION ref mut bar + *bar = 32; + //~^ ERROR + } + match 16 { + ref quo => { *quo = 32; }, + //~^ ERROR + //~| HELP + //~| SUGGESTION ref mut quo + } +} diff --git a/src/test/ui/suggest-ref-mut.stderr b/src/test/ui/suggest-ref-mut.stderr new file mode 100644 index 00000000000..0b2b240ef53 --- /dev/null +++ b/src/test/ui/suggest-ref-mut.stderr @@ -0,0 +1,38 @@ +error[E0594]: cannot assign to `self.0` which is behind a `&` reference + --> $DIR/suggest-ref-mut.rs:19:9 + | +LL | fn zap(&self) { + | ----- help: consider changing this to be a mutable reference: `&mut self` +... +LL | self.0 = 32; + | ^^^^^^^^^^^ `self` is a `&` reference, so the data it refers to cannot be written + +error[E0594]: cannot assign to `*foo` which is behind a `&` reference + --> $DIR/suggest-ref-mut.rs:28:5 + | +LL | let ref foo = 16; + | ------- help: consider changing this to be a mutable reference: `ref mut foo` +... +LL | *foo = 32; + | ^^^^^^^^^ `foo` is a `&` reference, so the data it refers to cannot be written + +error[E0594]: cannot assign to `*bar` which is behind a `&` reference + --> $DIR/suggest-ref-mut.rs:33:9 + | +LL | if let Some(ref bar) = Some(16) { + | ------- help: consider changing this to be a mutable reference: `ref mut bar` +... +LL | *bar = 32; + | ^^^^^^^^^ `bar` is a `&` reference, so the data it refers to cannot be written + +error[E0594]: cannot assign to `*quo` which is behind a `&` reference + --> $DIR/suggest-ref-mut.rs:37:22 + | +LL | ref quo => { *quo = 32; }, + | ------- ^^^^^^^^^ `quo` is a `&` reference, so the data it refers to cannot be written + | | + | help: consider changing this to be a mutable reference: `ref mut quo` + +error: aborting due to 4 previous errors + +For more information about this error, try `rustc --explain E0594`. diff --git a/src/test/ui/suggestions/as-ref.rs b/src/test/ui/suggestions/as-ref.rs deleted file mode 100644 index ae1c98c8564..00000000000 --- a/src/test/ui/suggestions/as-ref.rs +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright 2018 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -struct Foo; -fn takes_ref(_: &Foo) {} - -fn main() { - let ref opt = Some(Foo); - opt.map(|arg| takes_ref(arg)); - //~^ ERROR mismatched types [E0308] - opt.and_then(|arg| Some(takes_ref(arg))); - //~^ ERROR mismatched types [E0308] - let ref opt: Result<_, ()> = Ok(Foo); - opt.map(|arg| takes_ref(arg)); - //~^ ERROR mismatched types [E0308] - opt.and_then(|arg| Ok(takes_ref(arg))); - //~^ ERROR mismatched types [E0308] -} diff --git a/src/test/ui/suggestions/as-ref.stderr b/src/test/ui/suggestions/as-ref.stderr deleted file mode 100644 index 27016445ec5..00000000000 --- a/src/test/ui/suggestions/as-ref.stderr +++ /dev/null @@ -1,47 +0,0 @@ -error[E0308]: mismatched types - --> $DIR/as-ref.rs:16:27 - | -LL | opt.map(|arg| takes_ref(arg)); - | - ^^^ expected &Foo, found struct `Foo` - | | - | help: consider using `as_ref` instead: `as_ref().` - | - = note: expected type `&Foo` - found type `Foo` - -error[E0308]: mismatched types - --> $DIR/as-ref.rs:18:37 - | -LL | opt.and_then(|arg| Some(takes_ref(arg))); - | - ^^^ expected &Foo, found struct `Foo` - | | - | help: consider using `as_ref` instead: `as_ref().` - | - = note: expected type `&Foo` - found type `Foo` - -error[E0308]: mismatched types - --> $DIR/as-ref.rs:21:27 - | -LL | opt.map(|arg| takes_ref(arg)); - | - ^^^ expected &Foo, found struct `Foo` - | | - | help: consider using `as_ref` instead: `as_ref().` - | - = note: expected type `&Foo` - found type `Foo` - -error[E0308]: mismatched types - --> $DIR/as-ref.rs:23:35 - | -LL | opt.and_then(|arg| Ok(takes_ref(arg))); - | - ^^^ expected &Foo, found struct `Foo` - | | - | help: consider using `as_ref` instead: `as_ref().` - | - = note: expected type `&Foo` - found type `Foo` - -error: aborting due to 4 previous errors - -For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/suggestions/auxiliary/m1.rs b/src/test/ui/suggestions/auxiliary/m1.rs deleted file mode 100644 index b61667cfd88..00000000000 --- a/src/test/ui/suggestions/auxiliary/m1.rs +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright 2017 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -pub fn foo() {} diff --git a/src/test/ui/suggestions/auxiliary/m2.rs b/src/test/ui/suggestions/auxiliary/m2.rs deleted file mode 100644 index 94ff5e4497f..00000000000 --- a/src/test/ui/suggestions/auxiliary/m2.rs +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright 2017 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -pub fn bar() {} diff --git a/src/test/ui/suggestions/auxiliary/macro-in-other-crate.rs b/src/test/ui/suggestions/auxiliary/macro-in-other-crate.rs deleted file mode 100644 index 01282f2ad24..00000000000 --- a/src/test/ui/suggestions/auxiliary/macro-in-other-crate.rs +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright 2018 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#[macro_export] -macro_rules! mac { - ($ident:ident) => { let $ident = 42; } -} diff --git a/src/test/ui/suggestions/auxiliary/removing-extern-crate.rs b/src/test/ui/suggestions/auxiliary/removing-extern-crate.rs deleted file mode 100644 index 4275e80e7fe..00000000000 --- a/src/test/ui/suggestions/auxiliary/removing-extern-crate.rs +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright 2018 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// intentionally blank diff --git a/src/test/ui/suggestions/closure-immutable-outer-variable.fixed b/src/test/ui/suggestions/closure-immutable-outer-variable.fixed deleted file mode 100644 index b3a0d592f76..00000000000 --- a/src/test/ui/suggestions/closure-immutable-outer-variable.fixed +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright 2017 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// run-rustfix - -// Point at the captured immutable outer variable - -fn foo(mut f: Box) { - f(); -} - -fn main() { - let mut y = true; - foo(Box::new(move || y = false) as Box<_>); //~ ERROR cannot assign to captured outer variable -} diff --git a/src/test/ui/suggestions/closure-immutable-outer-variable.nll.fixed b/src/test/ui/suggestions/closure-immutable-outer-variable.nll.fixed deleted file mode 100644 index e162678460c..00000000000 --- a/src/test/ui/suggestions/closure-immutable-outer-variable.nll.fixed +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright 2017 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// run-rustfix - -// Point at the captured immutable outer variable - -fn foo(mut f: Box) { - f(); -} - -fn main() { - let y = true; - foo(Box::new(move || y = false) as Box<_>); //~ ERROR cannot assign to captured outer variable -} diff --git a/src/test/ui/suggestions/closure-immutable-outer-variable.nll.stderr b/src/test/ui/suggestions/closure-immutable-outer-variable.nll.stderr deleted file mode 100644 index 335ccefe8a0..00000000000 --- a/src/test/ui/suggestions/closure-immutable-outer-variable.nll.stderr +++ /dev/null @@ -1,9 +0,0 @@ -error[E0594]: cannot assign to immutable item `y` - --> $DIR/closure-immutable-outer-variable.rs:21:26 - | -LL | foo(Box::new(move || y = false) as Box<_>); //~ ERROR cannot assign to captured outer variable - | ^^^^^^^^^ cannot assign - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0594`. diff --git a/src/test/ui/suggestions/closure-immutable-outer-variable.rs b/src/test/ui/suggestions/closure-immutable-outer-variable.rs deleted file mode 100644 index e162678460c..00000000000 --- a/src/test/ui/suggestions/closure-immutable-outer-variable.rs +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright 2017 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// run-rustfix - -// Point at the captured immutable outer variable - -fn foo(mut f: Box) { - f(); -} - -fn main() { - let y = true; - foo(Box::new(move || y = false) as Box<_>); //~ ERROR cannot assign to captured outer variable -} diff --git a/src/test/ui/suggestions/closure-immutable-outer-variable.rs.fixed b/src/test/ui/suggestions/closure-immutable-outer-variable.rs.fixed deleted file mode 100644 index 80a5a45a305..00000000000 --- a/src/test/ui/suggestions/closure-immutable-outer-variable.rs.fixed +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright 2017 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// Point at the captured immutable outer variable - -fn foo(mut f: Box) { - f(); -} - -fn main() { - let mut y = true; - foo(Box::new(move || y = false) as Box<_>); //~ ERROR cannot assign to captured outer variable -} diff --git a/src/test/ui/suggestions/closure-immutable-outer-variable.stderr b/src/test/ui/suggestions/closure-immutable-outer-variable.stderr deleted file mode 100644 index 0ee11d8cf15..00000000000 --- a/src/test/ui/suggestions/closure-immutable-outer-variable.stderr +++ /dev/null @@ -1,11 +0,0 @@ -error[E0594]: cannot assign to captured outer variable in an `FnMut` closure - --> $DIR/closure-immutable-outer-variable.rs:21:26 - | -LL | let y = true; - | - help: consider making `y` mutable: `mut y` -LL | foo(Box::new(move || y = false) as Box<_>); //~ ERROR cannot assign to captured outer variable - | ^^^^^^^^^ - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0594`. diff --git a/src/test/ui/suggestions/confuse-field-and-method/issue-18343.rs b/src/test/ui/suggestions/confuse-field-and-method/issue-18343.rs deleted file mode 100644 index ef1566ab56a..00000000000 --- a/src/test/ui/suggestions/confuse-field-and-method/issue-18343.rs +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright 2014 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -struct Obj where F: FnMut() -> u32 { - closure: F, -} - -fn main() { - let o = Obj { closure: || 42 }; - o.closure(); - //~^ ERROR no method named `closure` found -} diff --git a/src/test/ui/suggestions/confuse-field-and-method/issue-18343.stderr b/src/test/ui/suggestions/confuse-field-and-method/issue-18343.stderr deleted file mode 100644 index b1e3105a5f9..00000000000 --- a/src/test/ui/suggestions/confuse-field-and-method/issue-18343.stderr +++ /dev/null @@ -1,14 +0,0 @@ -error[E0599]: no method named `closure` found for type `Obj<[closure@$DIR/issue-18343.rs:16:28: 16:33]>` in the current scope - --> $DIR/issue-18343.rs:17:7 - | -LL | struct Obj where F: FnMut() -> u32 { - | ------------------------------------- method `closure` not found for this -... -LL | o.closure(); - | ^^^^^^^ field, not a method - | - = help: use `(o.closure)(...)` if you meant to call the function stored in the `closure` field - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0599`. diff --git a/src/test/ui/suggestions/confuse-field-and-method/issue-2392.rs b/src/test/ui/suggestions/confuse-field-and-method/issue-2392.rs deleted file mode 100644 index f0c5a2a913f..00000000000 --- a/src/test/ui/suggestions/confuse-field-and-method/issue-2392.rs +++ /dev/null @@ -1,83 +0,0 @@ -// Copyright 2014 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#![feature(core, fnbox)] - -use std::boxed::FnBox; - -struct FuncContainer { - f1: fn(data: u8), - f2: extern "C" fn(data: u8), - f3: unsafe fn(data: u8), -} - -struct FuncContainerOuter { - container: Box -} - -struct Obj where F: FnOnce() -> u32 { - closure: F, - not_closure: usize, -} - -struct BoxedObj { - boxed_closure: Box u32>, -} - -struct Wrapper where F: FnMut() -> u32 { - wrap: Obj, -} - -fn func() -> u32 { - 0 -} - -fn check_expression() -> Obj u32>> { - Obj { closure: Box::new(|| 42_u32) as Box u32>, not_closure: 42 } -} - -fn main() { - // test variations of function - - let o_closure = Obj { closure: || 42, not_closure: 42 }; - o_closure.closure(); //~ ERROR no method named `closure` found - - o_closure.not_closure(); - //~^ ERROR no method named `not_closure` found - - let o_func = Obj { closure: func, not_closure: 5 }; - o_func.closure(); //~ ERROR no method named `closure` found - - let boxed_fn = BoxedObj { boxed_closure: Box::new(func) }; - boxed_fn.boxed_closure();//~ ERROR no method named `boxed_closure` found - - let boxed_closure = BoxedObj { boxed_closure: Box::new(|| 42_u32) as Box u32> }; - boxed_closure.boxed_closure();//~ ERROR no method named `boxed_closure` found - - // test expression writing in the notes - - let w = Wrapper { wrap: o_func }; - w.wrap.closure();//~ ERROR no method named `closure` found - - w.wrap.not_closure(); - //~^ ERROR no method named `not_closure` found - - check_expression().closure();//~ ERROR no method named `closure` found -} - -impl FuncContainerOuter { - fn run(&self) { - unsafe { - (*self.container).f1(1); //~ ERROR no method named `f1` found - (*self.container).f2(1); //~ ERROR no method named `f2` found - (*self.container).f3(1); //~ ERROR no method named `f3` found - } - } -} diff --git a/src/test/ui/suggestions/confuse-field-and-method/issue-2392.stderr b/src/test/ui/suggestions/confuse-field-and-method/issue-2392.stderr deleted file mode 100644 index 9049ffd4090..00000000000 --- a/src/test/ui/suggestions/confuse-field-and-method/issue-2392.stderr +++ /dev/null @@ -1,124 +0,0 @@ -error[E0599]: no method named `closure` found for type `Obj<[closure@$DIR/issue-2392.rs:49:36: 49:41]>` in the current scope - --> $DIR/issue-2392.rs:50:15 - | -LL | struct Obj where F: FnOnce() -> u32 { - | -------------------------------------- method `closure` not found for this -... -LL | o_closure.closure(); //~ ERROR no method named `closure` found - | ^^^^^^^ field, not a method - | - = help: use `(o_closure.closure)(...)` if you meant to call the function stored in the `closure` field - -error[E0599]: no method named `not_closure` found for type `Obj<[closure@$DIR/issue-2392.rs:49:36: 49:41]>` in the current scope - --> $DIR/issue-2392.rs:52:15 - | -LL | struct Obj where F: FnOnce() -> u32 { - | -------------------------------------- method `not_closure` not found for this -... -LL | o_closure.not_closure(); - | ^^^^^^^^^^^ field, not a method - | - = help: did you mean to write `o_closure.not_closure` instead of `o_closure.not_closure(...)`? - -error[E0599]: no method named `closure` found for type `Obj u32 {func}>` in the current scope - --> $DIR/issue-2392.rs:56:12 - | -LL | struct Obj where F: FnOnce() -> u32 { - | -------------------------------------- method `closure` not found for this -... -LL | o_func.closure(); //~ ERROR no method named `closure` found - | ^^^^^^^ field, not a method - | - = help: use `(o_func.closure)(...)` if you meant to call the function stored in the `closure` field - -error[E0599]: no method named `boxed_closure` found for type `BoxedObj` in the current scope - --> $DIR/issue-2392.rs:59:14 - | -LL | struct BoxedObj { - | --------------- method `boxed_closure` not found for this -... -LL | boxed_fn.boxed_closure();//~ ERROR no method named `boxed_closure` found - | ^^^^^^^^^^^^^ field, not a method - | - = help: use `(boxed_fn.boxed_closure)(...)` if you meant to call the function stored in the `boxed_closure` field - -error[E0599]: no method named `boxed_closure` found for type `BoxedObj` in the current scope - --> $DIR/issue-2392.rs:62:19 - | -LL | struct BoxedObj { - | --------------- method `boxed_closure` not found for this -... -LL | boxed_closure.boxed_closure();//~ ERROR no method named `boxed_closure` found - | ^^^^^^^^^^^^^ field, not a method - | - = help: use `(boxed_closure.boxed_closure)(...)` if you meant to call the function stored in the `boxed_closure` field - -error[E0599]: no method named `closure` found for type `Obj u32 {func}>` in the current scope - --> $DIR/issue-2392.rs:67:12 - | -LL | struct Obj where F: FnOnce() -> u32 { - | -------------------------------------- method `closure` not found for this -... -LL | w.wrap.closure();//~ ERROR no method named `closure` found - | ^^^^^^^ field, not a method - | - = help: use `(w.wrap.closure)(...)` if you meant to call the function stored in the `closure` field - -error[E0599]: no method named `not_closure` found for type `Obj u32 {func}>` in the current scope - --> $DIR/issue-2392.rs:69:12 - | -LL | struct Obj where F: FnOnce() -> u32 { - | -------------------------------------- method `not_closure` not found for this -... -LL | w.wrap.not_closure(); - | ^^^^^^^^^^^ field, not a method - | - = help: did you mean to write `w.wrap.not_closure` instead of `w.wrap.not_closure(...)`? - -error[E0599]: no method named `closure` found for type `Obj + 'static)>>` in the current scope - --> $DIR/issue-2392.rs:72:24 - | -LL | struct Obj where F: FnOnce() -> u32 { - | -------------------------------------- method `closure` not found for this -... -LL | check_expression().closure();//~ ERROR no method named `closure` found - | ^^^^^^^ field, not a method - | - = help: use `(check_expression().closure)(...)` if you meant to call the function stored in the `closure` field - -error[E0599]: no method named `f1` found for type `FuncContainer` in the current scope - --> $DIR/issue-2392.rs:78:31 - | -LL | struct FuncContainer { - | -------------------- method `f1` not found for this -... -LL | (*self.container).f1(1); //~ ERROR no method named `f1` found - | ^^ field, not a method - | - = help: use `((*self.container).f1)(...)` if you meant to call the function stored in the `f1` field - -error[E0599]: no method named `f2` found for type `FuncContainer` in the current scope - --> $DIR/issue-2392.rs:79:31 - | -LL | struct FuncContainer { - | -------------------- method `f2` not found for this -... -LL | (*self.container).f2(1); //~ ERROR no method named `f2` found - | ^^ field, not a method - | - = help: use `((*self.container).f2)(...)` if you meant to call the function stored in the `f2` field - -error[E0599]: no method named `f3` found for type `FuncContainer` in the current scope - --> $DIR/issue-2392.rs:80:31 - | -LL | struct FuncContainer { - | -------------------- method `f3` not found for this -... -LL | (*self.container).f3(1); //~ ERROR no method named `f3` found - | ^^ field, not a method - | - = help: use `((*self.container).f3)(...)` if you meant to call the function stored in the `f3` field - -error: aborting due to 11 previous errors - -For more information about this error, try `rustc --explain E0599`. diff --git a/src/test/ui/suggestions/confuse-field-and-method/issue-32128.rs b/src/test/ui/suggestions/confuse-field-and-method/issue-32128.rs deleted file mode 100644 index d306b38e00e..00000000000 --- a/src/test/ui/suggestions/confuse-field-and-method/issue-32128.rs +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright 2016 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -struct Example { - example: Box i32> -} - -fn main() { - let demo = Example { - example: Box::new(|x| { - x + 1 - }) - }; - - demo.example(1); - //~^ ERROR no method named `example` - // (demo.example)(1); -} diff --git a/src/test/ui/suggestions/confuse-field-and-method/issue-32128.stderr b/src/test/ui/suggestions/confuse-field-and-method/issue-32128.stderr deleted file mode 100644 index 95b764b43ed..00000000000 --- a/src/test/ui/suggestions/confuse-field-and-method/issue-32128.stderr +++ /dev/null @@ -1,14 +0,0 @@ -error[E0599]: no method named `example` found for type `Example` in the current scope - --> $DIR/issue-32128.rs:22:10 - | -LL | struct Example { - | -------------- method `example` not found for this -... -LL | demo.example(1); - | ^^^^^^^ field, not a method - | - = help: use `(demo.example)(...)` if you meant to call the function stored in the `example` field - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0599`. diff --git a/src/test/ui/suggestions/confuse-field-and-method/issue-33784.rs b/src/test/ui/suggestions/confuse-field-and-method/issue-33784.rs deleted file mode 100644 index 4cd50be50d4..00000000000 --- a/src/test/ui/suggestions/confuse-field-and-method/issue-33784.rs +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright 2016 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -use std::ops::Deref; - -struct Obj where F: FnMut() -> u32 { - fn_ptr: fn() -> (), - closure: F, -} - -struct C { - c_fn_ptr: fn() -> (), -} - -struct D(C); - -impl Deref for D { - type Target = C; - fn deref(&self) -> &C { - &self.0 - } -} - - -fn empty() {} - -fn main() { - let o = Obj { fn_ptr: empty, closure: || 42 }; - let p = &o; - p.closure(); //~ ERROR no method named `closure` found - let q = &p; - q.fn_ptr(); //~ ERROR no method named `fn_ptr` found - let r = D(C { c_fn_ptr: empty }); - let s = &r; - s.c_fn_ptr(); //~ ERROR no method named `c_fn_ptr` found -} diff --git a/src/test/ui/suggestions/confuse-field-and-method/issue-33784.stderr b/src/test/ui/suggestions/confuse-field-and-method/issue-33784.stderr deleted file mode 100644 index b7f13320eec..00000000000 --- a/src/test/ui/suggestions/confuse-field-and-method/issue-33784.stderr +++ /dev/null @@ -1,27 +0,0 @@ -error[E0599]: no method named `closure` found for type `&Obj<[closure@$DIR/issue-33784.rs:35:43: 35:48]>` in the current scope - --> $DIR/issue-33784.rs:37:7 - | -LL | p.closure(); //~ ERROR no method named `closure` found - | ^^^^^^^ field, not a method - | - = help: use `(p.closure)(...)` if you meant to call the function stored in the `closure` field - -error[E0599]: no method named `fn_ptr` found for type `&&Obj<[closure@$DIR/issue-33784.rs:35:43: 35:48]>` in the current scope - --> $DIR/issue-33784.rs:39:7 - | -LL | q.fn_ptr(); //~ ERROR no method named `fn_ptr` found - | ^^^^^^ field, not a method - | - = help: use `(q.fn_ptr)(...)` if you meant to call the function stored in the `fn_ptr` field - -error[E0599]: no method named `c_fn_ptr` found for type `&D` in the current scope - --> $DIR/issue-33784.rs:42:7 - | -LL | s.c_fn_ptr(); //~ ERROR no method named `c_fn_ptr` found - | ^^^^^^^^ field, not a method - | - = help: use `(s.c_fn_ptr)(...)` if you meant to call the function stored in the `c_fn_ptr` field - -error: aborting due to 3 previous errors - -For more information about this error, try `rustc --explain E0599`. diff --git a/src/test/ui/suggestions/confuse-field-and-method/private-field.rs b/src/test/ui/suggestions/confuse-field-and-method/private-field.rs deleted file mode 100644 index 4cf939bbed6..00000000000 --- a/src/test/ui/suggestions/confuse-field-and-method/private-field.rs +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright 2017 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -pub mod animal { - pub struct Dog { - pub age: usize, - dog_age: usize, - } - - impl Dog { - pub fn new(age: usize) -> Dog { - Dog { age: age, dog_age: age * 7 } - } - } -} - -fn main() { - let dog = animal::Dog::new(3); - let dog_age = dog.dog_age(); //~ ERROR no method - //let dog_age = dog.dog_age; - println!("{}", dog_age); -} diff --git a/src/test/ui/suggestions/confuse-field-and-method/private-field.stderr b/src/test/ui/suggestions/confuse-field-and-method/private-field.stderr deleted file mode 100644 index 145df8b156b..00000000000 --- a/src/test/ui/suggestions/confuse-field-and-method/private-field.stderr +++ /dev/null @@ -1,12 +0,0 @@ -error[E0599]: no method named `dog_age` found for type `animal::Dog` in the current scope - --> $DIR/private-field.rs:26:23 - | -LL | pub struct Dog { - | -------------- method `dog_age` not found for this -... -LL | let dog_age = dog.dog_age(); //~ ERROR no method - | ^^^^^^^ private field, not a method - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0599`. diff --git a/src/test/ui/suggestions/const-type-mismatch.rs b/src/test/ui/suggestions/const-type-mismatch.rs deleted file mode 100644 index ddad4e79cfd..00000000000 --- a/src/test/ui/suggestions/const-type-mismatch.rs +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2018 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// `const`s shouldn't suggest `.into()` - -const TEN: u8 = 10; -const TWELVE: u16 = TEN + 2; -//~^ ERROR mismatched types [E0308] - -fn main() { - const TEN: u8 = 10; - const ALSO_TEN: u16 = TEN; - //~^ ERROR mismatched types [E0308] -} diff --git a/src/test/ui/suggestions/const-type-mismatch.stderr b/src/test/ui/suggestions/const-type-mismatch.stderr deleted file mode 100644 index 965995f82c5..00000000000 --- a/src/test/ui/suggestions/const-type-mismatch.stderr +++ /dev/null @@ -1,15 +0,0 @@ -error[E0308]: mismatched types - --> $DIR/const-type-mismatch.rs:14:21 - | -LL | const TWELVE: u16 = TEN + 2; - | ^^^^^^^ expected u16, found u8 - -error[E0308]: mismatched types - --> $DIR/const-type-mismatch.rs:19:27 - | -LL | const ALSO_TEN: u16 = TEN; - | ^^^ expected u16, found u8 - -error: aborting due to 2 previous errors - -For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/suggestions/conversion-methods.rs b/src/test/ui/suggestions/conversion-methods.rs deleted file mode 100644 index 8a53bc3ca93..00000000000 --- a/src/test/ui/suggestions/conversion-methods.rs +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright 2017 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -use std::path::{Path, PathBuf}; - - -fn main() { - let _tis_an_instants_play: String = "'Tis a fond Ambush—"; //~ ERROR mismatched types - let _just_to_make_bliss: PathBuf = Path::new("/ern/her/own/surprise"); - //~^ ERROR mismatched types - - let _but_should_the_play: String = 2; // Perhaps surprisingly, we suggest .to_string() here - //~^ ERROR mismatched types - - let _prove_piercing_earnest: Vec = &[1, 2, 3]; //~ ERROR mismatched types -} diff --git a/src/test/ui/suggestions/conversion-methods.stderr b/src/test/ui/suggestions/conversion-methods.stderr deleted file mode 100644 index 970ccad2316..00000000000 --- a/src/test/ui/suggestions/conversion-methods.stderr +++ /dev/null @@ -1,51 +0,0 @@ -error[E0308]: mismatched types - --> $DIR/conversion-methods.rs:15:41 - | -LL | let _tis_an_instants_play: String = "'Tis a fond Ambush—"; //~ ERROR mismatched types - | ^^^^^^^^^^^^^^^^^^^^^ - | | - | expected struct `std::string::String`, found reference - | help: try using a conversion method: `"'Tis a fond Ambush—".to_string()` - | - = note: expected type `std::string::String` - found type `&'static str` - -error[E0308]: mismatched types - --> $DIR/conversion-methods.rs:16:40 - | -LL | let _just_to_make_bliss: PathBuf = Path::new("/ern/her/own/surprise"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | | - | expected struct `std::path::PathBuf`, found reference - | help: try using a conversion method: `Path::new("/ern/her/own/surprise").to_path_buf()` - | - = note: expected type `std::path::PathBuf` - found type `&std::path::Path` - -error[E0308]: mismatched types - --> $DIR/conversion-methods.rs:19:40 - | -LL | let _but_should_the_play: String = 2; // Perhaps surprisingly, we suggest .to_string() here - | ^ - | | - | expected struct `std::string::String`, found integral variable - | help: try using a conversion method: `2.to_string()` - | - = note: expected type `std::string::String` - found type `{integer}` - -error[E0308]: mismatched types - --> $DIR/conversion-methods.rs:22:47 - | -LL | let _prove_piercing_earnest: Vec = &[1, 2, 3]; //~ ERROR mismatched types - | ^^^^^^^^^^ - | | - | expected struct `std::vec::Vec`, found reference - | help: try using a conversion method: `&[1, 2, 3].to_vec()` - | - = note: expected type `std::vec::Vec` - found type `&[{integer}; 3]` - -error: aborting due to 4 previous errors - -For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/suggestions/dont-suggest-private-trait-method.rs b/src/test/ui/suggestions/dont-suggest-private-trait-method.rs deleted file mode 100644 index 99bee0d3c59..00000000000 --- a/src/test/ui/suggestions/dont-suggest-private-trait-method.rs +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2018 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -struct T; - -fn main() { - T::new(); - //~^ ERROR no function or associated item named `new` found for type `T` in the current scope -} diff --git a/src/test/ui/suggestions/dont-suggest-private-trait-method.stderr b/src/test/ui/suggestions/dont-suggest-private-trait-method.stderr deleted file mode 100644 index 81ecc546a6d..00000000000 --- a/src/test/ui/suggestions/dont-suggest-private-trait-method.stderr +++ /dev/null @@ -1,12 +0,0 @@ -error[E0599]: no function or associated item named `new` found for type `T` in the current scope - --> $DIR/dont-suggest-private-trait-method.rs:14:5 - | -LL | struct T; - | --------- function or associated item `new` not found for this -... -LL | T::new(); - | ^^^^^^ function or associated item not found in `T` - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0599`. diff --git a/src/test/ui/suggestions/dotdotdot-expr.rs b/src/test/ui/suggestions/dotdotdot-expr.rs deleted file mode 100644 index afb73a526a8..00000000000 --- a/src/test/ui/suggestions/dotdotdot-expr.rs +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright 2018 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -fn main() { - let _redemptive = 1...21; - //~^ ERROR unexpected token -} diff --git a/src/test/ui/suggestions/dotdotdot-expr.stderr b/src/test/ui/suggestions/dotdotdot-expr.stderr deleted file mode 100644 index 3315538f2f7..00000000000 --- a/src/test/ui/suggestions/dotdotdot-expr.stderr +++ /dev/null @@ -1,16 +0,0 @@ -error: unexpected token: `...` - --> $DIR/dotdotdot-expr.rs:12:24 - | -LL | let _redemptive = 1...21; - | ^^^ -help: use `..` for an exclusive range - | -LL | let _redemptive = 1..21; - | ^^ -help: or `..=` for an inclusive range - | -LL | let _redemptive = 1..=21; - | ^^^ - -error: aborting due to previous error - diff --git a/src/test/ui/suggestions/extern-crate-rename.rs b/src/test/ui/suggestions/extern-crate-rename.rs deleted file mode 100644 index b58149fb0b8..00000000000 --- a/src/test/ui/suggestions/extern-crate-rename.rs +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright 2017 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// aux-build:m1.rs -// aux-build:m2.rs - - -extern crate m1; -extern crate m2 as m1; //~ ERROR is defined multiple times - -fn main() {} diff --git a/src/test/ui/suggestions/extern-crate-rename.stderr b/src/test/ui/suggestions/extern-crate-rename.stderr deleted file mode 100644 index 2c2723fe4c5..00000000000 --- a/src/test/ui/suggestions/extern-crate-rename.stderr +++ /dev/null @@ -1,16 +0,0 @@ -error[E0259]: the name `m1` is defined multiple times - --> $DIR/extern-crate-rename.rs:16:1 - | -LL | extern crate m1; - | ---------------- previous import of the extern crate `m1` here -LL | extern crate m2 as m1; //~ ERROR is defined multiple times - | ^^^^^^^^^^^^^^^^^^^^^^ - | | - | `m1` reimported here - | You can use `as` to change the binding name of the import - | - = note: `m1` must be defined only once in the type namespace of this module - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0259`. diff --git a/src/test/ui/suggestions/fn-closure-mutable-capture.nll.stderr b/src/test/ui/suggestions/fn-closure-mutable-capture.nll.stderr deleted file mode 100644 index 7ef21d3720d..00000000000 --- a/src/test/ui/suggestions/fn-closure-mutable-capture.nll.stderr +++ /dev/null @@ -1,9 +0,0 @@ -error[E0594]: cannot assign to `x` which is behind a `&` reference - --> $DIR/fn-closure-mutable-capture.rs:15:17 - | -LL | bar(move || x = 1); - | ^^^^^ cannot assign - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0594`. diff --git a/src/test/ui/suggestions/fn-closure-mutable-capture.rs b/src/test/ui/suggestions/fn-closure-mutable-capture.rs deleted file mode 100644 index 385efebd590..00000000000 --- a/src/test/ui/suggestions/fn-closure-mutable-capture.rs +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright 2018 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -pub fn bar(_f: F) {} - -pub fn foo() { - let mut x = 0; - bar(move || x = 1); - //~^ ERROR cannot assign to captured outer variable in an `Fn` closure - //~| NOTE `Fn` closures cannot capture their enclosing environment for modifications -} - -fn main() {} diff --git a/src/test/ui/suggestions/fn-closure-mutable-capture.stderr b/src/test/ui/suggestions/fn-closure-mutable-capture.stderr deleted file mode 100644 index a58d663dc0a..00000000000 --- a/src/test/ui/suggestions/fn-closure-mutable-capture.stderr +++ /dev/null @@ -1,16 +0,0 @@ -error[E0594]: cannot assign to captured outer variable in an `Fn` closure - --> $DIR/fn-closure-mutable-capture.rs:15:17 - | -LL | bar(move || x = 1); - | ^^^^^ - | - = note: `Fn` closures cannot capture their enclosing environment for modifications -help: consider changing this closure to take self by mutable reference - --> $DIR/fn-closure-mutable-capture.rs:15:9 - | -LL | bar(move || x = 1); - | ^^^^^^^^^^^^^ - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0594`. diff --git a/src/test/ui/suggestions/for-c-in-str.rs b/src/test/ui/suggestions/for-c-in-str.rs deleted file mode 100644 index 011886e8073..00000000000 --- a/src/test/ui/suggestions/for-c-in-str.rs +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2018 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// E0277 should point exclusively at line 14, not the entire for loop span - -fn main() { - for c in "asdf" { - //~^ ERROR the trait bound `&str: std::iter::Iterator` is not satisfied - //~| NOTE `&str` is not an iterator - //~| HELP the trait `std::iter::Iterator` is not implemented for `&str` - //~| NOTE required by `std::iter::IntoIterator::into_iter` - println!(""); - } -} diff --git a/src/test/ui/suggestions/for-c-in-str.stderr b/src/test/ui/suggestions/for-c-in-str.stderr deleted file mode 100644 index b249df3b4ef..00000000000 --- a/src/test/ui/suggestions/for-c-in-str.stderr +++ /dev/null @@ -1,12 +0,0 @@ -error[E0277]: the trait bound `&str: std::iter::Iterator` is not satisfied - --> $DIR/for-c-in-str.rs:14:14 - | -LL | for c in "asdf" { - | ^^^^^^ `&str` is not an iterator; try calling `.chars()` or `.bytes()` - | - = help: the trait `std::iter::Iterator` is not implemented for `&str` - = note: required by `std::iter::IntoIterator::into_iter` - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/suggestions/issue-32354-suggest-import-rename.fixed b/src/test/ui/suggestions/issue-32354-suggest-import-rename.fixed deleted file mode 100644 index 251f7eb9a24..00000000000 --- a/src/test/ui/suggestions/issue-32354-suggest-import-rename.fixed +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2017 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// run-rustfix - -#![allow(unused_imports)] - -pub mod extension1 { - pub trait ConstructorExtension {} -} - -pub mod extension2 { - pub trait ConstructorExtension {} -} - -use extension1::ConstructorExtension; -use extension2::ConstructorExtension as OtherConstructorExtension; //~ ERROR is defined multiple times - -fn main() {} diff --git a/src/test/ui/suggestions/issue-32354-suggest-import-rename.rs b/src/test/ui/suggestions/issue-32354-suggest-import-rename.rs deleted file mode 100644 index 57cbeb47a1e..00000000000 --- a/src/test/ui/suggestions/issue-32354-suggest-import-rename.rs +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2017 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// run-rustfix - -#![allow(unused_imports)] - -pub mod extension1 { - pub trait ConstructorExtension {} -} - -pub mod extension2 { - pub trait ConstructorExtension {} -} - -use extension1::ConstructorExtension; -use extension2::ConstructorExtension; //~ ERROR is defined multiple times - -fn main() {} diff --git a/src/test/ui/suggestions/issue-32354-suggest-import-rename.stderr b/src/test/ui/suggestions/issue-32354-suggest-import-rename.stderr deleted file mode 100644 index f45a5f7dd61..00000000000 --- a/src/test/ui/suggestions/issue-32354-suggest-import-rename.stderr +++ /dev/null @@ -1,17 +0,0 @@ -error[E0252]: the name `ConstructorExtension` is defined multiple times - --> $DIR/issue-32354-suggest-import-rename.rs:24:5 - | -LL | use extension1::ConstructorExtension; - | -------------------------------- previous import of the trait `ConstructorExtension` here -LL | use extension2::ConstructorExtension; //~ ERROR is defined multiple times - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `ConstructorExtension` reimported here - | - = note: `ConstructorExtension` must be defined only once in the type namespace of this module -help: You can use `as` to change the binding name of the import - | -LL | use extension2::ConstructorExtension as OtherConstructorExtension; //~ ERROR is defined multiple times - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0252`. diff --git a/src/test/ui/suggestions/issue-43420-no-over-suggest.rs b/src/test/ui/suggestions/issue-43420-no-over-suggest.rs deleted file mode 100644 index 8c5bde45bae..00000000000 --- a/src/test/ui/suggestions/issue-43420-no-over-suggest.rs +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright 2017 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// check that we substitute type parameters before we suggest anything - otherwise -// we would suggest function such as `as_slice` for the `&[u16]`. - -fn foo(b: &[u16]) {} - -fn main() { - let a: Vec = Vec::new(); - foo(&a); //~ ERROR mismatched types -} diff --git a/src/test/ui/suggestions/issue-43420-no-over-suggest.stderr b/src/test/ui/suggestions/issue-43420-no-over-suggest.stderr deleted file mode 100644 index 80bbdd11289..00000000000 --- a/src/test/ui/suggestions/issue-43420-no-over-suggest.stderr +++ /dev/null @@ -1,12 +0,0 @@ -error[E0308]: mismatched types - --> $DIR/issue-43420-no-over-suggest.rs:18:9 - | -LL | foo(&a); //~ ERROR mismatched types - | ^^ expected slice, found struct `std::vec::Vec` - | - = note: expected type `&[u16]` - found type `&std::vec::Vec` - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/suggestions/issue-45562.fixed b/src/test/ui/suggestions/issue-45562.fixed deleted file mode 100644 index 7c01f0d1ee5..00000000000 --- a/src/test/ui/suggestions/issue-45562.fixed +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2018 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// run-rustfix - -#[no_mangle] pub static RAH: usize = 5; -//~^ ERROR const items should never be #[no_mangle] - -fn main() {} diff --git a/src/test/ui/suggestions/issue-45562.rs b/src/test/ui/suggestions/issue-45562.rs deleted file mode 100644 index c27d52fcdd3..00000000000 --- a/src/test/ui/suggestions/issue-45562.rs +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2018 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// run-rustfix - -#[no_mangle] pub const RAH: usize = 5; -//~^ ERROR const items should never be #[no_mangle] - -fn main() {} diff --git a/src/test/ui/suggestions/issue-45562.stderr b/src/test/ui/suggestions/issue-45562.stderr deleted file mode 100644 index d9e624cadc7..00000000000 --- a/src/test/ui/suggestions/issue-45562.stderr +++ /dev/null @@ -1,12 +0,0 @@ -error: const items should never be #[no_mangle] - --> $DIR/issue-45562.rs:13:14 - | -LL | #[no_mangle] pub const RAH: usize = 5; - | ---------^^^^^^^^^^^^^^^^ - | | - | help: try a static value: `pub static` - | - = note: #[deny(no_mangle_const_items)] on by default - -error: aborting due to previous error - diff --git a/src/test/ui/suggestions/issue-45799-bad-extern-crate-rename-suggestion-formatting.fixed b/src/test/ui/suggestions/issue-45799-bad-extern-crate-rename-suggestion-formatting.fixed deleted file mode 100644 index e3287030408..00000000000 --- a/src/test/ui/suggestions/issue-45799-bad-extern-crate-rename-suggestion-formatting.fixed +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2017 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// run-rustfix - -extern crate std as other_std; -fn main() {} -//~^^ ERROR the name `std` is defined multiple times [E0259] diff --git a/src/test/ui/suggestions/issue-45799-bad-extern-crate-rename-suggestion-formatting.rs b/src/test/ui/suggestions/issue-45799-bad-extern-crate-rename-suggestion-formatting.rs deleted file mode 100644 index f47ea474d51..00000000000 --- a/src/test/ui/suggestions/issue-45799-bad-extern-crate-rename-suggestion-formatting.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2017 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// run-rustfix - -extern crate std; -fn main() {} -//~^^ ERROR the name `std` is defined multiple times [E0259] diff --git a/src/test/ui/suggestions/issue-45799-bad-extern-crate-rename-suggestion-formatting.stderr b/src/test/ui/suggestions/issue-45799-bad-extern-crate-rename-suggestion-formatting.stderr deleted file mode 100644 index ecdfec2b3bf..00000000000 --- a/src/test/ui/suggestions/issue-45799-bad-extern-crate-rename-suggestion-formatting.stderr +++ /dev/null @@ -1,15 +0,0 @@ -error[E0259]: the name `std` is defined multiple times - --> $DIR/issue-45799-bad-extern-crate-rename-suggestion-formatting.rs:13:1 - | -LL | extern crate std; - | ^^^^^^^^^^^^^^^^^ `std` reimported here - | - = note: `std` must be defined only once in the type namespace of this module -help: You can use `as` to change the binding name of the import - | -LL | extern crate std as other_std; - | - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0259`. diff --git a/src/test/ui/suggestions/issue-46302.rs b/src/test/ui/suggestions/issue-46302.rs deleted file mode 100644 index 6ae6b549b07..00000000000 --- a/src/test/ui/suggestions/issue-46302.rs +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright 2017 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -fn foo() { - let s = "abc"; - let u: &str = if true { s[..2] } else { s }; - //~^ ERROR mismatched types -} - -fn main() { - foo(); -} diff --git a/src/test/ui/suggestions/issue-46302.stderr b/src/test/ui/suggestions/issue-46302.stderr deleted file mode 100644 index 8e399136fad..00000000000 --- a/src/test/ui/suggestions/issue-46302.stderr +++ /dev/null @@ -1,15 +0,0 @@ -error[E0308]: mismatched types - --> $DIR/issue-46302.rs:13:27 - | -LL | let u: &str = if true { s[..2] } else { s }; - | ^^^^^^ - | | - | expected &str, found str - | help: consider borrowing here: `&s[..2]` - | - = note: expected type `&str` - found type `str` - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/suggestions/issue-46756-consider-borrowing-cast-or-binexpr.fixed b/src/test/ui/suggestions/issue-46756-consider-borrowing-cast-or-binexpr.fixed deleted file mode 100644 index 77171cad6e7..00000000000 --- a/src/test/ui/suggestions/issue-46756-consider-borrowing-cast-or-binexpr.fixed +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2017 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// run-rustfix - -#![allow(unused)] - -fn light_flows_our_war_of_mocking_words(and_yet: &usize) -> usize { - and_yet + 1 -} - -fn main() { - let behold: isize = 2; - let with_tears: usize = 3; - light_flows_our_war_of_mocking_words(&(behold as usize)); - //~^ ERROR mismatched types [E0308] - light_flows_our_war_of_mocking_words(&(with_tears + 4)); - //~^ ERROR mismatched types [E0308] -} diff --git a/src/test/ui/suggestions/issue-46756-consider-borrowing-cast-or-binexpr.rs b/src/test/ui/suggestions/issue-46756-consider-borrowing-cast-or-binexpr.rs deleted file mode 100644 index e5ea9b5ed09..00000000000 --- a/src/test/ui/suggestions/issue-46756-consider-borrowing-cast-or-binexpr.rs +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2017 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// run-rustfix - -#![allow(unused)] - -fn light_flows_our_war_of_mocking_words(and_yet: &usize) -> usize { - and_yet + 1 -} - -fn main() { - let behold: isize = 2; - let with_tears: usize = 3; - light_flows_our_war_of_mocking_words(behold as usize); - //~^ ERROR mismatched types [E0308] - light_flows_our_war_of_mocking_words(with_tears + 4); - //~^ ERROR mismatched types [E0308] -} diff --git a/src/test/ui/suggestions/issue-46756-consider-borrowing-cast-or-binexpr.stderr b/src/test/ui/suggestions/issue-46756-consider-borrowing-cast-or-binexpr.stderr deleted file mode 100644 index 9c492751ca1..00000000000 --- a/src/test/ui/suggestions/issue-46756-consider-borrowing-cast-or-binexpr.stderr +++ /dev/null @@ -1,27 +0,0 @@ -error[E0308]: mismatched types - --> $DIR/issue-46756-consider-borrowing-cast-or-binexpr.rs:22:42 - | -LL | light_flows_our_war_of_mocking_words(behold as usize); - | ^^^^^^^^^^^^^^^ - | | - | expected &usize, found usize - | help: consider borrowing here: `&(behold as usize)` - | - = note: expected type `&usize` - found type `usize` - -error[E0308]: mismatched types - --> $DIR/issue-46756-consider-borrowing-cast-or-binexpr.rs:24:42 - | -LL | light_flows_our_war_of_mocking_words(with_tears + 4); - | ^^^^^^^^^^^^^^ - | | - | expected &usize, found usize - | help: consider borrowing here: `&(with_tears + 4)` - | - = note: expected type `&usize` - found type `usize` - -error: aborting due to 2 previous errors - -For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/suggestions/issue-48364.rs b/src/test/ui/suggestions/issue-48364.rs deleted file mode 100644 index 82cb722a656..00000000000 --- a/src/test/ui/suggestions/issue-48364.rs +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2018 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -fn foo() -> bool { - b"".starts_with(stringify!(foo)) - //~^ ERROR mismatched types -} - -fn main() {} diff --git a/src/test/ui/suggestions/issue-48364.stderr b/src/test/ui/suggestions/issue-48364.stderr deleted file mode 100644 index b420654a32d..00000000000 --- a/src/test/ui/suggestions/issue-48364.stderr +++ /dev/null @@ -1,12 +0,0 @@ -error[E0308]: mismatched types - --> $DIR/issue-48364.rs:12:21 - | -LL | b"".starts_with(stringify!(foo)) - | ^^^^^^^^^^^^^^^ expected slice, found str - | - = note: expected type `&[u8]` - found type `&'static str` - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/suggestions/issue-51244.nll.stderr b/src/test/ui/suggestions/issue-51244.nll.stderr deleted file mode 100644 index ce02ae2aec2..00000000000 --- a/src/test/ui/suggestions/issue-51244.nll.stderr +++ /dev/null @@ -1,11 +0,0 @@ -error[E0594]: cannot assign to `*my_ref` which is behind a `&` reference - --> $DIR/issue-51244.rs:13:5 - | -LL | let ref my_ref @ _ = 0; - | -------------- help: consider changing this to be a mutable reference: `ref mut my_ref @ _` -LL | *my_ref = 0; //~ ERROR cannot assign to immutable borrowed content `*my_ref` [E0594] - | ^^^^^^^^^^^ `my_ref` is a `&` reference, so the data it refers to cannot be written - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0594`. diff --git a/src/test/ui/suggestions/issue-51244.rs b/src/test/ui/suggestions/issue-51244.rs deleted file mode 100644 index 50a21184a98..00000000000 --- a/src/test/ui/suggestions/issue-51244.rs +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright 2018 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -fn main() { - let ref my_ref @ _ = 0; - *my_ref = 0; //~ ERROR cannot assign to immutable borrowed content `*my_ref` [E0594] -} diff --git a/src/test/ui/suggestions/issue-51244.stderr b/src/test/ui/suggestions/issue-51244.stderr deleted file mode 100644 index 997a74295e5..00000000000 --- a/src/test/ui/suggestions/issue-51244.stderr +++ /dev/null @@ -1,11 +0,0 @@ -error[E0594]: cannot assign to immutable borrowed content `*my_ref` - --> $DIR/issue-51244.rs:13:5 - | -LL | let ref my_ref @ _ = 0; - | -------------- help: use a mutable reference instead: `ref mut my_ref @ _` -LL | *my_ref = 0; //~ ERROR cannot assign to immutable borrowed content `*my_ref` [E0594] - | ^^^^^^^^^^^ cannot borrow as mutable - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0594`. diff --git a/src/test/ui/suggestions/issue-51515.rs b/src/test/ui/suggestions/issue-51515.rs deleted file mode 100644 index 3e0a3b757a3..00000000000 --- a/src/test/ui/suggestions/issue-51515.rs +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright 2018 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#![feature(nll)] - -fn main() { - let foo = &16; - //~^ HELP consider changing this to be a mutable reference - //~| SUGGESTION &mut 16 - *foo = 32; - //~^ ERROR cannot assign to `*foo` which is behind a `&` reference - let bar = foo; - //~^ HELP consider changing this to be a mutable reference - //~| SUGGESTION &mut i32 - *bar = 64; - //~^ ERROR cannot assign to `*bar` which is behind a `&` reference -} diff --git a/src/test/ui/suggestions/issue-51515.stderr b/src/test/ui/suggestions/issue-51515.stderr deleted file mode 100644 index 3e7349b5aca..00000000000 --- a/src/test/ui/suggestions/issue-51515.stderr +++ /dev/null @@ -1,21 +0,0 @@ -error[E0594]: cannot assign to `*foo` which is behind a `&` reference - --> $DIR/issue-51515.rs:17:5 - | -LL | let foo = &16; - | --- help: consider changing this to be a mutable reference: `&mut 16` -... -LL | *foo = 32; - | ^^^^^^^^^ `foo` is a `&` reference, so the data it refers to cannot be written - -error[E0594]: cannot assign to `*bar` which is behind a `&` reference - --> $DIR/issue-51515.rs:22:5 - | -LL | let bar = foo; - | --- help: consider changing this to be a mutable reference: `&mut i32` -... -LL | *bar = 64; - | ^^^^^^^^^ `bar` is a `&` reference, so the data it refers to cannot be written - -error: aborting due to 2 previous errors - -For more information about this error, try `rustc --explain E0594`. diff --git a/src/test/ui/suggestions/issue-52049.nll.stderr b/src/test/ui/suggestions/issue-52049.nll.stderr deleted file mode 100644 index 6f71f167611..00000000000 --- a/src/test/ui/suggestions/issue-52049.nll.stderr +++ /dev/null @@ -1,13 +0,0 @@ -error[E0597]: borrowed value does not live long enough - --> $DIR/issue-52049.rs:16:10 - | -LL | foo(&unpromotable(5u32)); - | ^^^^^^^^^^^^^^^^^^ temporary value does not live long enough -LL | } - | - temporary value only lives until here - | - = note: borrowed value must be valid for the static lifetime... - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0597`. diff --git a/src/test/ui/suggestions/issue-52049.rs b/src/test/ui/suggestions/issue-52049.rs deleted file mode 100644 index daff2258d36..00000000000 --- a/src/test/ui/suggestions/issue-52049.rs +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright 2018 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -fn foo(_: &'static u32) {} - -fn unpromotable(t: T) -> T { t } - -fn main() { - foo(&unpromotable(5u32)); -} -//~^^ ERROR borrowed value does not live long enough diff --git a/src/test/ui/suggestions/issue-52049.stderr b/src/test/ui/suggestions/issue-52049.stderr deleted file mode 100644 index e1e501023fc..00000000000 --- a/src/test/ui/suggestions/issue-52049.stderr +++ /dev/null @@ -1,13 +0,0 @@ -error[E0597]: borrowed value does not live long enough - --> $DIR/issue-52049.rs:16:10 - | -LL | foo(&unpromotable(5u32)); - | ^^^^^^^^^^^^^^^^^^ - temporary value only lives until here - | | - | temporary value does not live long enough - | - = note: borrowed value must be valid for the static lifetime... - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0597`. diff --git a/src/test/ui/suggestions/method-on-ambiguous-numeric-type.rs b/src/test/ui/suggestions/method-on-ambiguous-numeric-type.rs deleted file mode 100644 index 2b6e830ec59..00000000000 --- a/src/test/ui/suggestions/method-on-ambiguous-numeric-type.rs +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright 2018 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// aux-build:macro-in-other-crate.rs - -#[macro_use] extern crate macro_in_other_crate; - -macro_rules! local_mac { - ($ident:ident) => { let $ident = 42; } -} - -fn main() { - let x = 2.0.neg(); - //~^ ERROR can't call method `neg` on ambiguous numeric type `{float}` - - let y = 2.0; - let x = y.neg(); - //~^ ERROR can't call method `neg` on ambiguous numeric type `{float}` - println!("{:?}", x); - - for i in 0..100 { - println!("{}", i.pow(2)); - //~^ ERROR can't call method `pow` on ambiguous numeric type `{integer}` - } - - local_mac!(local_bar); - local_bar.pow(2); - //~^ ERROR can't call method `pow` on ambiguous numeric type `{integer}` -} - -fn qux() { - mac!(bar); - bar.pow(2); - //~^ ERROR can't call method `pow` on ambiguous numeric type `{integer}` -} diff --git a/src/test/ui/suggestions/method-on-ambiguous-numeric-type.stderr b/src/test/ui/suggestions/method-on-ambiguous-numeric-type.stderr deleted file mode 100644 index 796520e0ec7..00000000000 --- a/src/test/ui/suggestions/method-on-ambiguous-numeric-type.stderr +++ /dev/null @@ -1,51 +0,0 @@ -error[E0689]: can't call method `neg` on ambiguous numeric type `{float}` - --> $DIR/method-on-ambiguous-numeric-type.rs:20:17 - | -LL | let x = 2.0.neg(); - | ^^^ -help: you must specify a concrete type for this numeric value, like `f32` - | -LL | let x = 2.0_f32.neg(); - | ^^^^^^^ - -error[E0689]: can't call method `neg` on ambiguous numeric type `{float}` - --> $DIR/method-on-ambiguous-numeric-type.rs:24:15 - | -LL | let x = y.neg(); - | ^^^ -help: you must specify a type for this binding, like `f32` - | -LL | let y: f32 = 2.0; - | ^^^^^^ - -error[E0689]: can't call method `pow` on ambiguous numeric type `{integer}` - --> $DIR/method-on-ambiguous-numeric-type.rs:29:26 - | -LL | for i in 0..100 { - | - you must specify a type for this binding, like `i32` -LL | println!("{}", i.pow(2)); - | ^^^ - -error[E0689]: can't call method `pow` on ambiguous numeric type `{integer}` - --> $DIR/method-on-ambiguous-numeric-type.rs:34:15 - | -LL | local_bar.pow(2); - | ^^^ -help: you must specify a type for this binding, like `i32` - | -LL | ($ident:ident) => { let $ident: i32 = 42; } - | ^^^^^^^^^^^ - -error[E0689]: can't call method `pow` on ambiguous numeric type `{integer}` - --> $DIR/method-on-ambiguous-numeric-type.rs:40:9 - | -LL | mac!(bar); - | ---------- you must specify a type for this binding, like `i32` -LL | bar.pow(2); - | ^^^ - | - = 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: aborting due to 5 previous errors - -For more information about this error, try `rustc --explain E0689`. diff --git a/src/test/ui/suggestions/missing-comma-in-match.fixed b/src/test/ui/suggestions/missing-comma-in-match.fixed deleted file mode 100644 index 4832f35f42d..00000000000 --- a/src/test/ui/suggestions/missing-comma-in-match.fixed +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2018 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// run-rustfix - -fn main() { - match &Some(3) { - &None => 1, - &Some(2) => { 3 } - //~^ ERROR expected one of `,`, `.`, `?`, `}`, or an operator, found `=>` - //~| NOTE expected one of `,`, `.`, `?`, `}`, or an operator here - _ => 2 - }; -} diff --git a/src/test/ui/suggestions/missing-comma-in-match.rs b/src/test/ui/suggestions/missing-comma-in-match.rs deleted file mode 100644 index e39b20e77ea..00000000000 --- a/src/test/ui/suggestions/missing-comma-in-match.rs +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2018 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// run-rustfix - -fn main() { - match &Some(3) { - &None => 1 - &Some(2) => { 3 } - //~^ ERROR expected one of `,`, `.`, `?`, `}`, or an operator, found `=>` - //~| NOTE expected one of `,`, `.`, `?`, `}`, or an operator here - _ => 2 - }; -} diff --git a/src/test/ui/suggestions/missing-comma-in-match.stderr b/src/test/ui/suggestions/missing-comma-in-match.stderr deleted file mode 100644 index 77935934107..00000000000 --- a/src/test/ui/suggestions/missing-comma-in-match.stderr +++ /dev/null @@ -1,10 +0,0 @@ -error: expected one of `,`, `.`, `?`, `}`, or an operator, found `=>` - --> $DIR/missing-comma-in-match.rs:16:18 - | -LL | &None => 1 - | - help: missing a comma here to end this `match` arm -LL | &Some(2) => { 3 } - | ^^ expected one of `,`, `.`, `?`, `}`, or an operator here - -error: aborting due to previous error - diff --git a/src/test/ui/suggestions/numeric-cast-2.rs b/src/test/ui/suggestions/numeric-cast-2.rs deleted file mode 100644 index 2092b6bce37..00000000000 --- a/src/test/ui/suggestions/numeric-cast-2.rs +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2018 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -fn foo() -> i32 { - 4 -} -fn main() { - let x: u16 = foo(); - //~^ ERROR mismatched types - let y: i64 = x + x; - //~^ ERROR mismatched types - let z: i32 = x + x; - //~^ ERROR mismatched types -} diff --git a/src/test/ui/suggestions/numeric-cast-2.stderr b/src/test/ui/suggestions/numeric-cast-2.stderr deleted file mode 100644 index 3d485583717..00000000000 --- a/src/test/ui/suggestions/numeric-cast-2.stderr +++ /dev/null @@ -1,21 +0,0 @@ -error[E0308]: mismatched types - --> $DIR/numeric-cast-2.rs:15:18 - | -LL | let x: u16 = foo(); - | ^^^^^ expected u16, found i32 - -error[E0308]: mismatched types - --> $DIR/numeric-cast-2.rs:17:18 - | -LL | let y: i64 = x + x; - | ^^^^^ expected i64, found u16 - -error[E0308]: mismatched types - --> $DIR/numeric-cast-2.rs:19:18 - | -LL | let z: i32 = x + x; - | ^^^^^ expected i32, found u16 - -error: aborting due to 3 previous errors - -For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/suggestions/numeric-cast.rs b/src/test/ui/suggestions/numeric-cast.rs deleted file mode 100644 index 69bfdfa94b1..00000000000 --- a/src/test/ui/suggestions/numeric-cast.rs +++ /dev/null @@ -1,320 +0,0 @@ -// Copyright 2018 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - - -fn foo(_x: N) {} - -fn main() { - let x_usize: usize = 1; - let x_u64: u64 = 2; - let x_u32: u32 = 3; - let x_u16: u16 = 4; - let x_u8: u8 = 5; - let x_isize: isize = 6; - let x_i64: i64 = 7; - let x_i32: i32 = 8; - let x_i16: i16 = 9; - let x_i8: i8 = 10; - let x_f64: f64 = 11.0; - let x_f32: f32 = 12.0; - - foo::(x_usize); - foo::(x_u64); - //~^ ERROR mismatched types - foo::(x_u32); - //~^ ERROR mismatched types - foo::(x_u16); - //~^ ERROR mismatched types - foo::(x_u8); - //~^ ERROR mismatched types - foo::(x_isize); - //~^ ERROR mismatched types - foo::(x_i64); - //~^ ERROR mismatched types - foo::(x_i32); - //~^ ERROR mismatched types - foo::(x_i16); - //~^ ERROR mismatched types - foo::(x_i8); - //~^ ERROR mismatched types - foo::(x_f64); - //~^ ERROR mismatched types - foo::(x_f32); - //~^ ERROR mismatched types - - foo::(x_usize); - //~^ ERROR mismatched types - foo::(x_u64); - //~^ ERROR mismatched types - foo::(x_u32); - //~^ ERROR mismatched types - foo::(x_u16); - //~^ ERROR mismatched types - foo::(x_u8); - //~^ ERROR mismatched types - foo::(x_isize); - foo::(x_i64); - //~^ ERROR mismatched types - foo::(x_i32); - //~^ ERROR mismatched types - foo::(x_i16); - //~^ ERROR mismatched types - foo::(x_i8); - //~^ ERROR mismatched types - foo::(x_f64); - //~^ ERROR mismatched types - foo::(x_f32); - //~^ ERROR mismatched types - - foo::(x_usize); - //~^ ERROR mismatched types - foo::(x_u64); - foo::(x_u32); - //~^ ERROR mismatched types - foo::(x_u16); - //~^ ERROR mismatched types - foo::(x_u8); - //~^ ERROR mismatched types - foo::(x_isize); - //~^ ERROR mismatched types - foo::(x_i64); - //~^ ERROR mismatched types - foo::(x_i32); - //~^ ERROR mismatched types - foo::(x_i16); - //~^ ERROR mismatched types - foo::(x_i8); - //~^ ERROR mismatched types - foo::(x_f64); - //~^ ERROR mismatched types - foo::(x_f32); - //~^ ERROR mismatched types - - foo::(x_usize); - //~^ ERROR mismatched types - foo::(x_u64); - //~^ ERROR mismatched types - foo::(x_u32); - //~^ ERROR mismatched types - foo::(x_u16); - //~^ ERROR mismatched types - foo::(x_u8); - //~^ ERROR mismatched types - foo::(x_isize); - //~^ ERROR mismatched types - foo::(x_i64); - foo::(x_i32); - //~^ ERROR mismatched types - foo::(x_i16); - //~^ ERROR mismatched types - foo::(x_i8); - //~^ ERROR mismatched types - foo::(x_f64); - //~^ ERROR mismatched types - foo::(x_f32); - //~^ ERROR mismatched types - - foo::(x_usize); - //~^ ERROR mismatched types - foo::(x_u64); - //~^ ERROR mismatched types - foo::(x_u32); - foo::(x_u16); - //~^ ERROR mismatched types - foo::(x_u8); - //~^ ERROR mismatched types - foo::(x_isize); - //~^ ERROR mismatched types - foo::(x_i64); - //~^ ERROR mismatched types - foo::(x_i32); - //~^ ERROR mismatched types - foo::(x_i16); - //~^ ERROR mismatched types - foo::(x_i8); - //~^ ERROR mismatched types - foo::(x_f64); - //~^ ERROR mismatched types - foo::(x_f32); - //~^ ERROR mismatched types - - foo::(x_usize); - //~^ ERROR mismatched types - foo::(x_u64); - //~^ ERROR mismatched types - foo::(x_u32); - //~^ ERROR mismatched types - foo::(x_u16); - //~^ ERROR mismatched types - foo::(x_u8); - //~^ ERROR mismatched types - foo::(x_isize); - //~^ ERROR mismatched types - foo::(x_i64); - //~^ ERROR mismatched types - foo::(x_i32); - foo::(x_i16); - //~^ ERROR mismatched types - foo::(x_i8); - //~^ ERROR mismatched types - foo::(x_f64); - //~^ ERROR mismatched types - foo::(x_f32); - //~^ ERROR mismatched types - - foo::(x_usize); - //~^ ERROR mismatched types - foo::(x_u64); - //~^ ERROR mismatched types - foo::(x_u32); - //~^ ERROR mismatched types - foo::(x_u16); - foo::(x_u8); - //~^ ERROR mismatched types - foo::(x_isize); - //~^ ERROR mismatched types - foo::(x_i64); - //~^ ERROR mismatched types - foo::(x_i32); - //~^ ERROR mismatched types - foo::(x_i16); - //~^ ERROR mismatched types - foo::(x_i8); - //~^ ERROR mismatched types - foo::(x_f64); - //~^ ERROR mismatched types - foo::(x_f32); - //~^ ERROR mismatched types - - foo::(x_usize); - //~^ ERROR mismatched types - foo::(x_u64); - //~^ ERROR mismatched types - foo::(x_u32); - //~^ ERROR mismatched types - foo::(x_u16); - //~^ ERROR mismatched types - foo::(x_u8); - //~^ ERROR mismatched types - foo::(x_isize); - //~^ ERROR mismatched types - foo::(x_i64); - //~^ ERROR mismatched types - foo::(x_i32); - //~^ ERROR mismatched types - foo::(x_i16); - foo::(x_i8); - //~^ ERROR mismatched types - foo::(x_f64); - //~^ ERROR mismatched types - foo::(x_f32); - //~^ ERROR mismatched types - - foo::(x_usize); - //~^ ERROR mismatched types - foo::(x_u64); - //~^ ERROR mismatched types - foo::(x_u32); - //~^ ERROR mismatched types - foo::(x_u16); - //~^ ERROR mismatched types - foo::(x_u8); - foo::(x_isize); - //~^ ERROR mismatched types - foo::(x_i64); - //~^ ERROR mismatched types - foo::(x_i32); - //~^ ERROR mismatched types - foo::(x_i16); - //~^ ERROR mismatched types - foo::(x_i8); - //~^ ERROR mismatched types - foo::(x_f64); - //~^ ERROR mismatched types - foo::(x_f32); - //~^ ERROR mismatched types - - foo::(x_usize); - //~^ ERROR mismatched types - foo::(x_u64); - //~^ ERROR mismatched types - foo::(x_u32); - //~^ ERROR mismatched types - foo::(x_u16); - //~^ ERROR mismatched types - foo::(x_u8); - //~^ ERROR mismatched types - foo::(x_isize); - //~^ ERROR mismatched types - foo::(x_i64); - //~^ ERROR mismatched types - foo::(x_i32); - //~^ ERROR mismatched types - foo::(x_i16); - //~^ ERROR mismatched types - foo::(x_i8); - foo::(x_f64); - //~^ ERROR mismatched types - foo::(x_f32); - //~^ ERROR mismatched types - - foo::(x_usize); - //~^ ERROR mismatched types - foo::(x_u64); - //~^ ERROR mismatched types - foo::(x_u32); - //~^ ERROR mismatched types - foo::(x_u16); - //~^ ERROR mismatched types - foo::(x_u8); - //~^ ERROR mismatched types - foo::(x_isize); - //~^ ERROR mismatched types - foo::(x_i64); - //~^ ERROR mismatched types - foo::(x_i32); - //~^ ERROR mismatched types - foo::(x_i16); - //~^ ERROR mismatched types - foo::(x_i8); - //~^ ERROR mismatched types - foo::(x_f64); - foo::(x_f32); - //~^ ERROR mismatched types - - foo::(x_usize); - //~^ ERROR mismatched types - foo::(x_u64); - //~^ ERROR mismatched types - foo::(x_u32); - //~^ ERROR mismatched types - foo::(x_u16); - //~^ ERROR mismatched types - foo::(x_u8); - //~^ ERROR mismatched types - foo::(x_isize); - //~^ ERROR mismatched types - foo::(x_i64); - //~^ ERROR mismatched types - foo::(x_i32); - //~^ ERROR mismatched types - foo::(x_i16); - //~^ ERROR mismatched types - foo::(x_i8); - //~^ ERROR mismatched types - foo::(x_f64); - //~^ ERROR mismatched types - foo::(x_f32); - - foo::(x_u8 as u16); - //~^ ERROR mismatched types - foo::(-x_i8); - //~^ ERROR mismatched types -} diff --git a/src/test/ui/suggestions/numeric-cast.stderr b/src/test/ui/suggestions/numeric-cast.stderr deleted file mode 100644 index 4aac65ff4cb..00000000000 --- a/src/test/ui/suggestions/numeric-cast.stderr +++ /dev/null @@ -1,907 +0,0 @@ -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:29:18 - | -LL | foo::(x_u64); - | ^^^^^ expected usize, found u64 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:31:18 - | -LL | foo::(x_u32); - | ^^^^^ expected usize, found u32 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:33:18 - | -LL | foo::(x_u16); - | ^^^^^ expected usize, found u16 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:35:18 - | -LL | foo::(x_u8); - | ^^^^ expected usize, found u8 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:37:18 - | -LL | foo::(x_isize); - | ^^^^^^^ expected usize, found isize - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:39:18 - | -LL | foo::(x_i64); - | ^^^^^ expected usize, found i64 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:41:18 - | -LL | foo::(x_i32); - | ^^^^^ expected usize, found i32 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:43:18 - | -LL | foo::(x_i16); - | ^^^^^ expected usize, found i16 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:45:18 - | -LL | foo::(x_i8); - | ^^^^ expected usize, found i8 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:47:18 - | -LL | foo::(x_f64); - | ^^^^^ expected usize, found f64 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:49:18 - | -LL | foo::(x_f32); - | ^^^^^ expected usize, found f32 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:52:18 - | -LL | foo::(x_usize); - | ^^^^^^^ expected isize, found usize - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:54:18 - | -LL | foo::(x_u64); - | ^^^^^ expected isize, found u64 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:56:18 - | -LL | foo::(x_u32); - | ^^^^^ expected isize, found u32 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:58:18 - | -LL | foo::(x_u16); - | ^^^^^ expected isize, found u16 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:60:18 - | -LL | foo::(x_u8); - | ^^^^ expected isize, found u8 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:63:18 - | -LL | foo::(x_i64); - | ^^^^^ expected isize, found i64 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:65:18 - | -LL | foo::(x_i32); - | ^^^^^ expected isize, found i32 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:67:18 - | -LL | foo::(x_i16); - | ^^^^^ expected isize, found i16 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:69:18 - | -LL | foo::(x_i8); - | ^^^^ expected isize, found i8 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:71:18 - | -LL | foo::(x_f64); - | ^^^^^ expected isize, found f64 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:73:18 - | -LL | foo::(x_f32); - | ^^^^^ expected isize, found f32 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:76:16 - | -LL | foo::(x_usize); - | ^^^^^^^ expected u64, found usize - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:79:16 - | -LL | foo::(x_u32); - | ^^^^^ expected u64, found u32 -help: you can cast an `u32` to `u64`, which will zero-extend the source value - | -LL | foo::(x_u32.into()); - | ^^^^^^^^^^^^ - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:81:16 - | -LL | foo::(x_u16); - | ^^^^^ expected u64, found u16 -help: you can cast an `u16` to `u64`, which will zero-extend the source value - | -LL | foo::(x_u16.into()); - | ^^^^^^^^^^^^ - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:83:16 - | -LL | foo::(x_u8); - | ^^^^ expected u64, found u8 -help: you can cast an `u8` to `u64`, which will zero-extend the source value - | -LL | foo::(x_u8.into()); - | ^^^^^^^^^^^ - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:85:16 - | -LL | foo::(x_isize); - | ^^^^^^^ expected u64, found isize - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:87:16 - | -LL | foo::(x_i64); - | ^^^^^ expected u64, found i64 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:89:16 - | -LL | foo::(x_i32); - | ^^^^^ expected u64, found i32 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:91:16 - | -LL | foo::(x_i16); - | ^^^^^ expected u64, found i16 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:93:16 - | -LL | foo::(x_i8); - | ^^^^ expected u64, found i8 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:95:16 - | -LL | foo::(x_f64); - | ^^^^^ expected u64, found f64 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:97:16 - | -LL | foo::(x_f32); - | ^^^^^ expected u64, found f32 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:100:16 - | -LL | foo::(x_usize); - | ^^^^^^^ expected i64, found usize - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:102:16 - | -LL | foo::(x_u64); - | ^^^^^ expected i64, found u64 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:104:16 - | -LL | foo::(x_u32); - | ^^^^^ expected i64, found u32 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:106:16 - | -LL | foo::(x_u16); - | ^^^^^ expected i64, found u16 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:108:16 - | -LL | foo::(x_u8); - | ^^^^ expected i64, found u8 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:110:16 - | -LL | foo::(x_isize); - | ^^^^^^^ expected i64, found isize - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:113:16 - | -LL | foo::(x_i32); - | ^^^^^ expected i64, found i32 -help: you can cast an `i32` to `i64`, which will sign-extend the source value - | -LL | foo::(x_i32.into()); - | ^^^^^^^^^^^^ - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:115:16 - | -LL | foo::(x_i16); - | ^^^^^ expected i64, found i16 -help: you can cast an `i16` to `i64`, which will sign-extend the source value - | -LL | foo::(x_i16.into()); - | ^^^^^^^^^^^^ - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:117:16 - | -LL | foo::(x_i8); - | ^^^^ expected i64, found i8 -help: you can cast an `i8` to `i64`, which will sign-extend the source value - | -LL | foo::(x_i8.into()); - | ^^^^^^^^^^^ - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:119:16 - | -LL | foo::(x_f64); - | ^^^^^ expected i64, found f64 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:121:16 - | -LL | foo::(x_f32); - | ^^^^^ expected i64, found f32 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:124:16 - | -LL | foo::(x_usize); - | ^^^^^^^ expected u32, found usize - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:126:16 - | -LL | foo::(x_u64); - | ^^^^^ expected u32, found u64 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:129:16 - | -LL | foo::(x_u16); - | ^^^^^ expected u32, found u16 -help: you can cast an `u16` to `u32`, which will zero-extend the source value - | -LL | foo::(x_u16.into()); - | ^^^^^^^^^^^^ - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:131:16 - | -LL | foo::(x_u8); - | ^^^^ expected u32, found u8 -help: you can cast an `u8` to `u32`, which will zero-extend the source value - | -LL | foo::(x_u8.into()); - | ^^^^^^^^^^^ - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:133:16 - | -LL | foo::(x_isize); - | ^^^^^^^ expected u32, found isize - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:135:16 - | -LL | foo::(x_i64); - | ^^^^^ expected u32, found i64 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:137:16 - | -LL | foo::(x_i32); - | ^^^^^ expected u32, found i32 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:139:16 - | -LL | foo::(x_i16); - | ^^^^^ expected u32, found i16 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:141:16 - | -LL | foo::(x_i8); - | ^^^^ expected u32, found i8 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:143:16 - | -LL | foo::(x_f64); - | ^^^^^ expected u32, found f64 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:145:16 - | -LL | foo::(x_f32); - | ^^^^^ expected u32, found f32 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:148:16 - | -LL | foo::(x_usize); - | ^^^^^^^ expected i32, found usize - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:150:16 - | -LL | foo::(x_u64); - | ^^^^^ expected i32, found u64 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:152:16 - | -LL | foo::(x_u32); - | ^^^^^ expected i32, found u32 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:154:16 - | -LL | foo::(x_u16); - | ^^^^^ expected i32, found u16 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:156:16 - | -LL | foo::(x_u8); - | ^^^^ expected i32, found u8 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:158:16 - | -LL | foo::(x_isize); - | ^^^^^^^ expected i32, found isize - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:160:16 - | -LL | foo::(x_i64); - | ^^^^^ expected i32, found i64 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:163:16 - | -LL | foo::(x_i16); - | ^^^^^ expected i32, found i16 -help: you can cast an `i16` to `i32`, which will sign-extend the source value - | -LL | foo::(x_i16.into()); - | ^^^^^^^^^^^^ - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:165:16 - | -LL | foo::(x_i8); - | ^^^^ expected i32, found i8 -help: you can cast an `i8` to `i32`, which will sign-extend the source value - | -LL | foo::(x_i8.into()); - | ^^^^^^^^^^^ - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:167:16 - | -LL | foo::(x_f64); - | ^^^^^ expected i32, found f64 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:169:16 - | -LL | foo::(x_f32); - | ^^^^^ expected i32, found f32 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:172:16 - | -LL | foo::(x_usize); - | ^^^^^^^ expected u16, found usize - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:174:16 - | -LL | foo::(x_u64); - | ^^^^^ expected u16, found u64 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:176:16 - | -LL | foo::(x_u32); - | ^^^^^ expected u16, found u32 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:179:16 - | -LL | foo::(x_u8); - | ^^^^ expected u16, found u8 -help: you can cast an `u8` to `u16`, which will zero-extend the source value - | -LL | foo::(x_u8.into()); - | ^^^^^^^^^^^ - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:181:16 - | -LL | foo::(x_isize); - | ^^^^^^^ expected u16, found isize - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:183:16 - | -LL | foo::(x_i64); - | ^^^^^ expected u16, found i64 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:185:16 - | -LL | foo::(x_i32); - | ^^^^^ expected u16, found i32 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:187:16 - | -LL | foo::(x_i16); - | ^^^^^ expected u16, found i16 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:189:16 - | -LL | foo::(x_i8); - | ^^^^ expected u16, found i8 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:191:16 - | -LL | foo::(x_f64); - | ^^^^^ expected u16, found f64 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:193:16 - | -LL | foo::(x_f32); - | ^^^^^ expected u16, found f32 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:196:16 - | -LL | foo::(x_usize); - | ^^^^^^^ expected i16, found usize - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:198:16 - | -LL | foo::(x_u64); - | ^^^^^ expected i16, found u64 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:200:16 - | -LL | foo::(x_u32); - | ^^^^^ expected i16, found u32 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:202:16 - | -LL | foo::(x_u16); - | ^^^^^ expected i16, found u16 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:204:16 - | -LL | foo::(x_u8); - | ^^^^ expected i16, found u8 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:206:16 - | -LL | foo::(x_isize); - | ^^^^^^^ expected i16, found isize - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:208:16 - | -LL | foo::(x_i64); - | ^^^^^ expected i16, found i64 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:210:16 - | -LL | foo::(x_i32); - | ^^^^^ expected i16, found i32 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:213:16 - | -LL | foo::(x_i8); - | ^^^^ expected i16, found i8 -help: you can cast an `i8` to `i16`, which will sign-extend the source value - | -LL | foo::(x_i8.into()); - | ^^^^^^^^^^^ - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:215:16 - | -LL | foo::(x_f64); - | ^^^^^ expected i16, found f64 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:217:16 - | -LL | foo::(x_f32); - | ^^^^^ expected i16, found f32 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:220:15 - | -LL | foo::(x_usize); - | ^^^^^^^ expected u8, found usize - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:222:15 - | -LL | foo::(x_u64); - | ^^^^^ expected u8, found u64 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:224:15 - | -LL | foo::(x_u32); - | ^^^^^ expected u8, found u32 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:226:15 - | -LL | foo::(x_u16); - | ^^^^^ expected u8, found u16 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:229:15 - | -LL | foo::(x_isize); - | ^^^^^^^ expected u8, found isize - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:231:15 - | -LL | foo::(x_i64); - | ^^^^^ expected u8, found i64 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:233:15 - | -LL | foo::(x_i32); - | ^^^^^ expected u8, found i32 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:235:15 - | -LL | foo::(x_i16); - | ^^^^^ expected u8, found i16 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:237:15 - | -LL | foo::(x_i8); - | ^^^^ expected u8, found i8 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:239:15 - | -LL | foo::(x_f64); - | ^^^^^ expected u8, found f64 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:241:15 - | -LL | foo::(x_f32); - | ^^^^^ expected u8, found f32 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:244:15 - | -LL | foo::(x_usize); - | ^^^^^^^ expected i8, found usize - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:246:15 - | -LL | foo::(x_u64); - | ^^^^^ expected i8, found u64 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:248:15 - | -LL | foo::(x_u32); - | ^^^^^ expected i8, found u32 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:250:15 - | -LL | foo::(x_u16); - | ^^^^^ expected i8, found u16 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:252:15 - | -LL | foo::(x_u8); - | ^^^^ expected i8, found u8 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:254:15 - | -LL | foo::(x_isize); - | ^^^^^^^ expected i8, found isize - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:256:15 - | -LL | foo::(x_i64); - | ^^^^^ expected i8, found i64 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:258:15 - | -LL | foo::(x_i32); - | ^^^^^ expected i8, found i32 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:260:15 - | -LL | foo::(x_i16); - | ^^^^^ expected i8, found i16 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:263:15 - | -LL | foo::(x_f64); - | ^^^^^ expected i8, found f64 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:265:15 - | -LL | foo::(x_f32); - | ^^^^^ expected i8, found f32 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:268:16 - | -LL | foo::(x_usize); - | ^^^^^^^ expected f64, found usize - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:270:16 - | -LL | foo::(x_u64); - | ^^^^^ expected f64, found u64 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:272:16 - | -LL | foo::(x_u32); - | ^^^^^ expected f64, found u32 -help: you can cast an `u32` to `f64`, producing the floating point representation of the integer - | -LL | foo::(x_u32.into()); - | ^^^^^^^^^^^^ - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:274:16 - | -LL | foo::(x_u16); - | ^^^^^ expected f64, found u16 -help: you can cast an `u16` to `f64`, producing the floating point representation of the integer - | -LL | foo::(x_u16.into()); - | ^^^^^^^^^^^^ - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:276:16 - | -LL | foo::(x_u8); - | ^^^^ expected f64, found u8 -help: you can cast an `u8` to `f64`, producing the floating point representation of the integer - | -LL | foo::(x_u8.into()); - | ^^^^^^^^^^^ - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:278:16 - | -LL | foo::(x_isize); - | ^^^^^^^ expected f64, found isize - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:280:16 - | -LL | foo::(x_i64); - | ^^^^^ expected f64, found i64 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:282:16 - | -LL | foo::(x_i32); - | ^^^^^ expected f64, found i32 -help: you can cast an `i32` to `f64`, producing the floating point representation of the integer - | -LL | foo::(x_i32.into()); - | ^^^^^^^^^^^^ - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:284:16 - | -LL | foo::(x_i16); - | ^^^^^ expected f64, found i16 -help: you can cast an `i16` to `f64`, producing the floating point representation of the integer - | -LL | foo::(x_i16.into()); - | ^^^^^^^^^^^^ - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:286:16 - | -LL | foo::(x_i8); - | ^^^^ expected f64, found i8 -help: you can cast an `i8` to `f64`, producing the floating point representation of the integer - | -LL | foo::(x_i8.into()); - | ^^^^^^^^^^^ - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:289:16 - | -LL | foo::(x_f32); - | ^^^^^ expected f64, found f32 -help: you can cast an `f32` to `f64` in a lossless way - | -LL | foo::(x_f32.into()); - | ^^^^^^^^^^^^ - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:292:16 - | -LL | foo::(x_usize); - | ^^^^^^^ expected f32, found usize - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:294:16 - | -LL | foo::(x_u64); - | ^^^^^ expected f32, found u64 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:296:16 - | -LL | foo::(x_u32); - | ^^^^^ expected f32, found u32 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:298:16 - | -LL | foo::(x_u16); - | ^^^^^ expected f32, found u16 -help: you can cast an `u16` to `f32`, producing the floating point representation of the integer - | -LL | foo::(x_u16.into()); - | ^^^^^^^^^^^^ - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:300:16 - | -LL | foo::(x_u8); - | ^^^^ expected f32, found u8 -help: you can cast an `u8` to `f32`, producing the floating point representation of the integer - | -LL | foo::(x_u8.into()); - | ^^^^^^^^^^^ - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:302:16 - | -LL | foo::(x_isize); - | ^^^^^^^ expected f32, found isize - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:304:16 - | -LL | foo::(x_i64); - | ^^^^^ expected f32, found i64 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:306:16 - | -LL | foo::(x_i32); - | ^^^^^ expected f32, found i32 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:308:16 - | -LL | foo::(x_i16); - | ^^^^^ expected f32, found i16 -help: you can cast an `i16` to `f32`, producing the floating point representation of the integer - | -LL | foo::(x_i16.into()); - | ^^^^^^^^^^^^ - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:310:16 - | -LL | foo::(x_i8); - | ^^^^ expected f32, found i8 -help: you can cast an `i8` to `f32`, producing the floating point representation of the integer - | -LL | foo::(x_i8.into()); - | ^^^^^^^^^^^ - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:312:16 - | -LL | foo::(x_f64); - | ^^^^^ expected f32, found f64 - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:316:16 - | -LL | foo::(x_u8 as u16); - | ^^^^^^^^^^^ expected u32, found u16 -help: you can cast an `u16` to `u32`, which will zero-extend the source value - | -LL | foo::((x_u8 as u16).into()); - | ^^^^^^^^^^^^^^^^^^^^ - -error[E0308]: mismatched types - --> $DIR/numeric-cast.rs:318:16 - | -LL | foo::(-x_i8); - | ^^^^^ expected i32, found i8 -help: you can cast an `i8` to `i32`, which will sign-extend the source value - | -LL | foo::((-x_i8).into()); - | ^^^^^^^^^^^^^^ - -error: aborting due to 134 previous errors - -For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/suggestions/placement-syntax.rs b/src/test/ui/suggestions/placement-syntax.rs deleted file mode 100644 index 39252597a23..00000000000 --- a/src/test/ui/suggestions/placement-syntax.rs +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2018 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -fn main() { - let x = -5; - if x<-1 { - //~^ ERROR emplacement syntax is obsolete - println!("ok"); - } -} diff --git a/src/test/ui/suggestions/placement-syntax.stderr b/src/test/ui/suggestions/placement-syntax.stderr deleted file mode 100644 index 933ba96519c..00000000000 --- a/src/test/ui/suggestions/placement-syntax.stderr +++ /dev/null @@ -1,14 +0,0 @@ -error: emplacement syntax is obsolete (for now, anyway) - --> $DIR/placement-syntax.rs:13:8 - | -LL | if x<-1 { - | ^^^^ - | - = note: for more information, see -help: if you meant to write a comparison against a negative value, add a space in between `<` and `-` - | -LL | if x< -1 { - | ^^^ - -error: aborting due to previous error - diff --git a/src/test/ui/suggestions/pub-ident-fn-2.rs b/src/test/ui/suggestions/pub-ident-fn-2.rs deleted file mode 100644 index 44884bfcdfd..00000000000 --- a/src/test/ui/suggestions/pub-ident-fn-2.rs +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2017 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -pub foo(s: usize) { bar() } -//~^ ERROR missing `fn` for method definition - -fn main() { - foo(2); -} diff --git a/src/test/ui/suggestions/pub-ident-fn-2.stderr b/src/test/ui/suggestions/pub-ident-fn-2.stderr deleted file mode 100644 index bbbb3df8769..00000000000 --- a/src/test/ui/suggestions/pub-ident-fn-2.stderr +++ /dev/null @@ -1,12 +0,0 @@ -error: missing `fn` for method definition - --> $DIR/pub-ident-fn-2.rs:11:4 - | -LL | pub foo(s: usize) { bar() } - | ^ -help: add `fn` here to parse `foo` as a public method - | -LL | pub fn foo(s: usize) { bar() } - | ^^ - -error: aborting due to previous error - diff --git a/src/test/ui/suggestions/pub-ident-fn-or-struct-2.rs b/src/test/ui/suggestions/pub-ident-fn-or-struct-2.rs deleted file mode 100644 index 1ccadc8a40b..00000000000 --- a/src/test/ui/suggestions/pub-ident-fn-or-struct-2.rs +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright 2017 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -pub S(); -//~^ ERROR missing `fn` or `struct` for method or struct definition - -fn main() {} diff --git a/src/test/ui/suggestions/pub-ident-fn-or-struct-2.stderr b/src/test/ui/suggestions/pub-ident-fn-or-struct-2.stderr deleted file mode 100644 index e492a8c4756..00000000000 --- a/src/test/ui/suggestions/pub-ident-fn-or-struct-2.stderr +++ /dev/null @@ -1,8 +0,0 @@ -error: missing `fn` or `struct` for method or struct definition - --> $DIR/pub-ident-fn-or-struct-2.rs:11:4 - | -LL | pub S(); - | ---^- help: if you meant to call a macro, try: `S!` - -error: aborting due to previous error - diff --git a/src/test/ui/suggestions/pub-ident-fn-or-struct.rs b/src/test/ui/suggestions/pub-ident-fn-or-struct.rs deleted file mode 100644 index 0664918945b..00000000000 --- a/src/test/ui/suggestions/pub-ident-fn-or-struct.rs +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright 2017 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -pub S (foo) bar -//~^ ERROR missing `fn` or `struct` for method or struct definition - -fn main() {} diff --git a/src/test/ui/suggestions/pub-ident-fn-or-struct.stderr b/src/test/ui/suggestions/pub-ident-fn-or-struct.stderr deleted file mode 100644 index c1bff34cec3..00000000000 --- a/src/test/ui/suggestions/pub-ident-fn-or-struct.stderr +++ /dev/null @@ -1,8 +0,0 @@ -error: missing `fn` or `struct` for method or struct definition - --> $DIR/pub-ident-fn-or-struct.rs:11:4 - | -LL | pub S (foo) bar - | ---^- help: if you meant to call a macro, try: `S!` - -error: aborting due to previous error - diff --git a/src/test/ui/suggestions/pub-ident-fn.fixed b/src/test/ui/suggestions/pub-ident-fn.fixed deleted file mode 100644 index f2d0c6c3e1d..00000000000 --- a/src/test/ui/suggestions/pub-ident-fn.fixed +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright 2017 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// run-rustfix - -pub fn foo(_s: usize) -> bool { true } -//~^ ERROR missing `fn` for method definition - -fn main() { - foo(2); -} diff --git a/src/test/ui/suggestions/pub-ident-fn.rs b/src/test/ui/suggestions/pub-ident-fn.rs deleted file mode 100644 index 82c32f57eea..00000000000 --- a/src/test/ui/suggestions/pub-ident-fn.rs +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright 2017 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// run-rustfix - -pub foo(_s: usize) -> bool { true } -//~^ ERROR missing `fn` for method definition - -fn main() { - foo(2); -} diff --git a/src/test/ui/suggestions/pub-ident-fn.stderr b/src/test/ui/suggestions/pub-ident-fn.stderr deleted file mode 100644 index f7c96b8b9f4..00000000000 --- a/src/test/ui/suggestions/pub-ident-fn.stderr +++ /dev/null @@ -1,12 +0,0 @@ -error: missing `fn` for method definition - --> $DIR/pub-ident-fn.rs:13:4 - | -LL | pub foo(_s: usize) -> bool { true } - | ^^^ -help: add `fn` here to parse `foo` as a public method - | -LL | pub fn foo(_s: usize) -> bool { true } - | ^^ - -error: aborting due to previous error - diff --git a/src/test/ui/suggestions/pub-ident-struct.rs b/src/test/ui/suggestions/pub-ident-struct.rs deleted file mode 100644 index d08d498f87a..00000000000 --- a/src/test/ui/suggestions/pub-ident-struct.rs +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright 2017 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -pub S { -//~^ ERROR missing `struct` for struct definition -} -fn main() {} diff --git a/src/test/ui/suggestions/pub-ident-struct.stderr b/src/test/ui/suggestions/pub-ident-struct.stderr deleted file mode 100644 index cd53cea7212..00000000000 --- a/src/test/ui/suggestions/pub-ident-struct.stderr +++ /dev/null @@ -1,12 +0,0 @@ -error: missing `struct` for struct definition - --> $DIR/pub-ident-struct.rs:11:4 - | -LL | pub S { - | ^ -help: add `struct` here to parse `S` as a public struct - | -LL | pub struct S { - | ^^^^^^ - -error: aborting due to previous error - diff --git a/src/test/ui/suggestions/removing-extern-crate.fixed b/src/test/ui/suggestions/removing-extern-crate.fixed deleted file mode 100644 index 83b35cec809..00000000000 --- a/src/test/ui/suggestions/removing-extern-crate.fixed +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2018 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// compile-flags: --edition 2018 -// aux-build:removing-extern-crate.rs -// run-rustfix -// compile-pass - -#![warn(rust_2018_idioms)] -#![allow(unused_imports)] - - - - -mod another { - - -} - -fn main() {} diff --git a/src/test/ui/suggestions/removing-extern-crate.rs b/src/test/ui/suggestions/removing-extern-crate.rs deleted file mode 100644 index 29479086460..00000000000 --- a/src/test/ui/suggestions/removing-extern-crate.rs +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2018 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// compile-flags: --edition 2018 -// aux-build:removing-extern-crate.rs -// run-rustfix -// compile-pass - -#![warn(rust_2018_idioms)] -#![allow(unused_imports)] - -extern crate std as foo; -extern crate core; - -mod another { - extern crate std as foo; - extern crate std; -} - -fn main() {} diff --git a/src/test/ui/suggestions/removing-extern-crate.stderr b/src/test/ui/suggestions/removing-extern-crate.stderr deleted file mode 100644 index f2eed27a266..00000000000 --- a/src/test/ui/suggestions/removing-extern-crate.stderr +++ /dev/null @@ -1,31 +0,0 @@ -warning: unused extern crate - --> $DIR/removing-extern-crate.rs:19:1 - | -LL | extern crate std as foo; - | ^^^^^^^^^^^^^^^^^^^^^^^^ help: remove it - | -note: lint level defined here - --> $DIR/removing-extern-crate.rs:16:9 - | -LL | #![warn(rust_2018_idioms)] - | ^^^^^^^^^^^^^^^^ - = note: #[warn(unused_extern_crates)] implied by #[warn(rust_2018_idioms)] - -warning: unused extern crate - --> $DIR/removing-extern-crate.rs:20:1 - | -LL | extern crate core; - | ^^^^^^^^^^^^^^^^^^ help: remove it - -warning: unused extern crate - --> $DIR/removing-extern-crate.rs:23:5 - | -LL | extern crate std as foo; - | ^^^^^^^^^^^^^^^^^^^^^^^^ help: remove it - -warning: unused extern crate - --> $DIR/removing-extern-crate.rs:24:5 - | -LL | extern crate std; - | ^^^^^^^^^^^^^^^^^ help: remove it - diff --git a/src/test/ui/suggestions/repr.rs b/src/test/ui/suggestions/repr.rs deleted file mode 100644 index 312f60202c6..00000000000 --- a/src/test/ui/suggestions/repr.rs +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright 2018 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// compile-pass - -#[repr] -//^ WARN `repr` attribute must have a hint -struct _A {} - -#[repr = "B"] -//^ WARN `repr` attribute isn't configurable with a literal -struct _B {} - -#[repr = "C"] -//^ WARN `repr` attribute isn't configurable with a literal -struct _C {} - -#[repr(C)] -struct _D {} - -fn main() {} diff --git a/src/test/ui/suggestions/repr.stderr b/src/test/ui/suggestions/repr.stderr deleted file mode 100644 index 7a99d8c0448..00000000000 --- a/src/test/ui/suggestions/repr.stderr +++ /dev/null @@ -1,25 +0,0 @@ -warning: `repr` attribute must have a hint - --> $DIR/repr.rs:13:1 - | -LL | #[repr] - | ^^^^^^^ needs a hint - | - = note: #[warn(bad_repr)] on by default - = help: valid hints include `#[repr(C)]`, `#[repr(packed)]`, `#[repr(rust)]` and `#[repr(transparent)]` - = note: for more information, visit - -warning: `repr` attribute isn't configurable with a literal - --> $DIR/repr.rs:17:1 - | -LL | #[repr = "B"] - | ^^^^^^^^^^^^^ needs a hint - | - = help: valid hints include `#[repr(C)]`, `#[repr(packed)]`, `#[repr(rust)]` and `#[repr(transparent)]` - = note: for more information, visit - -warning: `repr` attribute isn't configurable with a literal - --> $DIR/repr.rs:21:1 - | -LL | #[repr = "C"] - | ^^^^^^^^^^^^^ help: give `repr` a hint: `#[repr(C)]` - diff --git a/src/test/ui/suggestions/return-type.rs b/src/test/ui/suggestions/return-type.rs deleted file mode 100644 index e63787949a4..00000000000 --- a/src/test/ui/suggestions/return-type.rs +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright 2017 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -struct S { - t: T, -} - -fn foo(x: T) -> S { - S { t: x } -} - -fn bar() { - foo(4 as usize) - //~^ ERROR mismatched types -} - -fn main() {} diff --git a/src/test/ui/suggestions/return-type.stderr b/src/test/ui/suggestions/return-type.stderr deleted file mode 100644 index 7d7653eee28..00000000000 --- a/src/test/ui/suggestions/return-type.stderr +++ /dev/null @@ -1,20 +0,0 @@ -error[E0308]: mismatched types - --> $DIR/return-type.rs:20:5 - | -LL | foo(4 as usize) - | ^^^^^^^^^^^^^^^ expected (), found struct `S` - | - = note: expected type `()` - found type `S` -help: try adding a semicolon - | -LL | foo(4 as usize); - | ^ -help: try adding a return type - | -LL | fn bar() -> S { - | ^^^^^^^^^^^ - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/suggestions/str-array-assignment.rs b/src/test/ui/suggestions/str-array-assignment.rs deleted file mode 100644 index 9d6cf5fe598..00000000000 --- a/src/test/ui/suggestions/str-array-assignment.rs +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2017 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -fn main() { - let s = "abc"; - let t = if true { s[..2] } else { s }; - //~^ ERROR if and else have incompatible types - let u: &str = if true { s[..2] } else { s }; - //~^ ERROR mismatched types - let v = s[..2]; - //~^ ERROR the size for values of type - let w: &str = s[..2]; - //~^ ERROR mismatched types -} diff --git a/src/test/ui/suggestions/str-array-assignment.stderr b/src/test/ui/suggestions/str-array-assignment.stderr deleted file mode 100644 index 7a774cab38e..00000000000 --- a/src/test/ui/suggestions/str-array-assignment.stderr +++ /dev/null @@ -1,49 +0,0 @@ -error[E0308]: if and else have incompatible types - --> $DIR/str-array-assignment.rs:13:11 - | -LL | let t = if true { s[..2] } else { s }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected str, found &str - | - = note: expected type `str` - found type `&str` - -error[E0308]: mismatched types - --> $DIR/str-array-assignment.rs:15:27 - | -LL | let u: &str = if true { s[..2] } else { s }; - | ^^^^^^ - | | - | expected &str, found str - | help: consider borrowing here: `&s[..2]` - | - = note: expected type `&str` - found type `str` - -error[E0277]: the size for values of type `str` cannot be known at compilation time - --> $DIR/str-array-assignment.rs:17:7 - | -LL | let v = s[..2]; - | ^ ------ help: consider borrowing here: `&s[..2]` - | | - | doesn't have a size known at compile-time - | - = help: the trait `std::marker::Sized` is not implemented for `str` - = note: to learn more, visit - = note: all local variables must have a statically known size - -error[E0308]: mismatched types - --> $DIR/str-array-assignment.rs:19:17 - | -LL | let w: &str = s[..2]; - | ^^^^^^ - | | - | expected &str, found str - | help: consider borrowing here: `&s[..2]` - | - = note: expected type `&str` - found type `str` - -error: aborting due to 4 previous errors - -Some errors occurred: E0277, E0308. -For more information about an error, try `rustc --explain E0277`. diff --git a/src/test/ui/suggestions/str-as-char.fixed b/src/test/ui/suggestions/str-as-char.fixed deleted file mode 100644 index c0dad38e436..00000000000 --- a/src/test/ui/suggestions/str-as-char.fixed +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2017 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// run-rustfix - -fn main() { - println!("●●"); - //~^ ERROR character literal may only contain one codepoint -} diff --git a/src/test/ui/suggestions/str-as-char.rs b/src/test/ui/suggestions/str-as-char.rs deleted file mode 100644 index b5a5df0af7f..00000000000 --- a/src/test/ui/suggestions/str-as-char.rs +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2017 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// run-rustfix - -fn main() { - println!('●●'); - //~^ ERROR character literal may only contain one codepoint -} diff --git a/src/test/ui/suggestions/str-as-char.stderr b/src/test/ui/suggestions/str-as-char.stderr deleted file mode 100644 index 60eb182adf1..00000000000 --- a/src/test/ui/suggestions/str-as-char.stderr +++ /dev/null @@ -1,12 +0,0 @@ -error: character literal may only contain one codepoint - --> $DIR/str-as-char.rs:14:14 - | -LL | println!('●●'); - | ^^^^ -help: if you meant to write a `str` literal, use double quotes - | -LL | println!("●●"); - | ^^^^ - -error: aborting due to previous error - diff --git a/src/test/ui/suggestions/suggest-labels.rs b/src/test/ui/suggestions/suggest-labels.rs deleted file mode 100644 index 9fb519c57ed..00000000000 --- a/src/test/ui/suggestions/suggest-labels.rs +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2017 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#[allow(unreachable_code, unused_labels)] -fn main() { - 'foo: loop { - break 'fo; //~ ERROR use of undeclared label - } - - 'bar: loop { - continue 'bor; //~ ERROR use of undeclared label - } - - 'longlabel: loop { - 'longlabel1: loop { - break 'longlable; //~ ERROR use of undeclared label - } - } -} diff --git a/src/test/ui/suggestions/suggest-labels.stderr b/src/test/ui/suggestions/suggest-labels.stderr deleted file mode 100644 index 671ff1a56db..00000000000 --- a/src/test/ui/suggestions/suggest-labels.stderr +++ /dev/null @@ -1,21 +0,0 @@ -error[E0426]: use of undeclared label `'fo` - --> $DIR/suggest-labels.rs:14:15 - | -LL | break 'fo; //~ ERROR use of undeclared label - | ^^^ did you mean `'foo`? - -error[E0426]: use of undeclared label `'bor` - --> $DIR/suggest-labels.rs:18:18 - | -LL | continue 'bor; //~ ERROR use of undeclared label - | ^^^^ did you mean `'bar`? - -error[E0426]: use of undeclared label `'longlable` - --> $DIR/suggest-labels.rs:23:19 - | -LL | break 'longlable; //~ ERROR use of undeclared label - | ^^^^^^^^^^ did you mean `'longlabel1`? - -error: aborting due to 3 previous errors - -For more information about this error, try `rustc --explain E0426`. diff --git a/src/test/ui/suggestions/suggest-methods.rs b/src/test/ui/suggestions/suggest-methods.rs deleted file mode 100644 index 49027deecc1..00000000000 --- a/src/test/ui/suggestions/suggest-methods.rs +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright 2017 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -struct Foo; - -impl Foo { - fn bar(self) {} - fn baz(&self, x: f64) {} -} - -trait FooT { - fn bag(&self); -} - -impl FooT for Foo { - fn bag(&self) {} -} - -fn main() { - let f = Foo; - f.bat(1.0); //~ ERROR no method named - - let s = "foo".to_string(); - let _ = s.is_emtpy(); //~ ERROR no method named - - // Generates a warning for `count_zeros()`. `count_ones()` is also a close - // match, but the former is closer. - let _ = 63u32.count_eos(); //~ ERROR no method named - - // Does not generate a warning - let _ = 63u32.count_o(); //~ ERROR no method named - -} diff --git a/src/test/ui/suggestions/suggest-methods.stderr b/src/test/ui/suggestions/suggest-methods.stderr deleted file mode 100644 index cb352361f33..00000000000 --- a/src/test/ui/suggestions/suggest-methods.stderr +++ /dev/null @@ -1,36 +0,0 @@ -error[E0599]: no method named `bat` found for type `Foo` in the current scope - --> $DIR/suggest-methods.rs:28:7 - | -LL | struct Foo; - | ----------- method `bat` not found for this -... -LL | f.bat(1.0); //~ ERROR no method named - | ^^^ - | - = help: did you mean `bar`? - -error[E0599]: no method named `is_emtpy` found for type `std::string::String` in the current scope - --> $DIR/suggest-methods.rs:31:15 - | -LL | let _ = s.is_emtpy(); //~ ERROR no method named - | ^^^^^^^^ - | - = help: did you mean `is_empty`? - -error[E0599]: no method named `count_eos` found for type `u32` in the current scope - --> $DIR/suggest-methods.rs:35:19 - | -LL | let _ = 63u32.count_eos(); //~ ERROR no method named - | ^^^^^^^^^ - | - = help: did you mean `count_zeros`? - -error[E0599]: no method named `count_o` found for type `u32` in the current scope - --> $DIR/suggest-methods.rs:38:19 - | -LL | let _ = 63u32.count_o(); //~ ERROR no method named - | ^^^^^^^ - -error: aborting due to 4 previous errors - -For more information about this error, try `rustc --explain E0599`. diff --git a/src/test/ui/suggestions/suggest-ref-mut.rs b/src/test/ui/suggestions/suggest-ref-mut.rs deleted file mode 100644 index 30b5371af1a..00000000000 --- a/src/test/ui/suggestions/suggest-ref-mut.rs +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright 2018 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#![feature(nll)] - -struct X(usize); - -impl X { - fn zap(&self) { - //~^ HELP - //~| SUGGESTION &mut self - self.0 = 32; - //~^ ERROR - } -} - -fn main() { - let ref foo = 16; - //~^ HELP - //~| SUGGESTION ref mut foo - *foo = 32; - //~^ ERROR - if let Some(ref bar) = Some(16) { - //~^ HELP - //~| SUGGESTION ref mut bar - *bar = 32; - //~^ ERROR - } - match 16 { - ref quo => { *quo = 32; }, - //~^ ERROR - //~| HELP - //~| SUGGESTION ref mut quo - } -} diff --git a/src/test/ui/suggestions/suggest-ref-mut.stderr b/src/test/ui/suggestions/suggest-ref-mut.stderr deleted file mode 100644 index 0b2b240ef53..00000000000 --- a/src/test/ui/suggestions/suggest-ref-mut.stderr +++ /dev/null @@ -1,38 +0,0 @@ -error[E0594]: cannot assign to `self.0` which is behind a `&` reference - --> $DIR/suggest-ref-mut.rs:19:9 - | -LL | fn zap(&self) { - | ----- help: consider changing this to be a mutable reference: `&mut self` -... -LL | self.0 = 32; - | ^^^^^^^^^^^ `self` is a `&` reference, so the data it refers to cannot be written - -error[E0594]: cannot assign to `*foo` which is behind a `&` reference - --> $DIR/suggest-ref-mut.rs:28:5 - | -LL | let ref foo = 16; - | ------- help: consider changing this to be a mutable reference: `ref mut foo` -... -LL | *foo = 32; - | ^^^^^^^^^ `foo` is a `&` reference, so the data it refers to cannot be written - -error[E0594]: cannot assign to `*bar` which is behind a `&` reference - --> $DIR/suggest-ref-mut.rs:33:9 - | -LL | if let Some(ref bar) = Some(16) { - | ------- help: consider changing this to be a mutable reference: `ref mut bar` -... -LL | *bar = 32; - | ^^^^^^^^^ `bar` is a `&` reference, so the data it refers to cannot be written - -error[E0594]: cannot assign to `*quo` which is behind a `&` reference - --> $DIR/suggest-ref-mut.rs:37:22 - | -LL | ref quo => { *quo = 32; }, - | ------- ^^^^^^^^^ `quo` is a `&` reference, so the data it refers to cannot be written - | | - | help: consider changing this to be a mutable reference: `ref mut quo` - -error: aborting due to 4 previous errors - -For more information about this error, try `rustc --explain E0594`. diff --git a/src/test/ui/suggestions/try-on-option.rs b/src/test/ui/suggestions/try-on-option.rs deleted file mode 100644 index 65ca23402d2..00000000000 --- a/src/test/ui/suggestions/try-on-option.rs +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright 2017 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#![feature(try_trait)] - -fn main() {} - -fn foo() -> Result { - let x: Option = None; - x?; //~ the trait bound - Ok(22) -} - -fn bar() -> u32 { - let x: Option = None; - x?; //~ the `?` operator - 22 -} diff --git a/src/test/ui/suggestions/try-on-option.stderr b/src/test/ui/suggestions/try-on-option.stderr deleted file mode 100644 index 265ee593bb7..00000000000 --- a/src/test/ui/suggestions/try-on-option.stderr +++ /dev/null @@ -1,20 +0,0 @@ -error[E0277]: the trait bound `(): std::convert::From` is not satisfied - --> $DIR/try-on-option.rs:17:5 - | -LL | x?; //~ the trait bound - | ^^ the trait `std::convert::From` is not implemented for `()` - | - = note: required by `std::convert::From::from` - -error[E0277]: the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `std::ops::Try`) - --> $DIR/try-on-option.rs:23:5 - | -LL | x?; //~ the `?` operator - | ^^ cannot use the `?` operator in a function that returns `u32` - | - = help: the trait `std::ops::Try` is not implemented for `u32` - = note: required by `std::ops::Try::from_error` - -error: aborting due to 2 previous errors - -For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/suggestions/try-operator-on-main.rs b/src/test/ui/suggestions/try-operator-on-main.rs deleted file mode 100644 index e52ef45c2ec..00000000000 --- a/src/test/ui/suggestions/try-operator-on-main.rs +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright 2017 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// ignore-cloudabi no std::fs support - -#![feature(try_trait)] - -use std::ops::Try; - -fn main() { - // error for a `Try` type on a non-`Try` fn - std::fs::File::open("foo")?; //~ ERROR the `?` operator can only - - // a non-`Try` type on a non-`Try` fn - ()?; //~ ERROR the `?` operator can only - - // an unrelated use of `Try` - try_trait_generic::<()>(); //~ ERROR the trait bound -} - - - -fn try_trait_generic() -> T { - // and a non-`Try` object on a `Try` fn. - ()?; //~ ERROR the `?` operator can only - - loop {} -} diff --git a/src/test/ui/suggestions/try-operator-on-main.stderr b/src/test/ui/suggestions/try-operator-on-main.stderr deleted file mode 100644 index 121ae14f999..00000000000 --- a/src/test/ui/suggestions/try-operator-on-main.stderr +++ /dev/null @@ -1,42 +0,0 @@ -error[E0277]: the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `std::ops::Try`) - --> $DIR/try-operator-on-main.rs:19:5 - | -LL | std::fs::File::open("foo")?; //~ ERROR the `?` operator can only - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot use the `?` operator in a function that returns `()` - | - = help: the trait `std::ops::Try` is not implemented for `()` - = note: required by `std::ops::Try::from_error` - -error[E0277]: the `?` operator can only be applied to values that implement `std::ops::Try` - --> $DIR/try-operator-on-main.rs:22:5 - | -LL | ()?; //~ ERROR the `?` operator can only - | ^^^ the `?` operator cannot be applied to type `()` - | - = help: the trait `std::ops::Try` is not implemented for `()` - = note: required by `std::ops::Try::into_result` - -error[E0277]: the trait bound `(): std::ops::Try` is not satisfied - --> $DIR/try-operator-on-main.rs:25:5 - | -LL | try_trait_generic::<()>(); //~ ERROR the trait bound - | ^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::ops::Try` is not implemented for `()` - | -note: required by `try_trait_generic` - --> $DIR/try-operator-on-main.rs:30:1 - | -LL | fn try_trait_generic() -> T { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error[E0277]: the `?` operator can only be applied to values that implement `std::ops::Try` - --> $DIR/try-operator-on-main.rs:32:5 - | -LL | ()?; //~ ERROR the `?` operator can only - | ^^^ the `?` operator cannot be applied to type `()` - | - = help: the trait `std::ops::Try` is not implemented for `()` - = note: required by `std::ops::Try::into_result` - -error: aborting due to 4 previous errors - -For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/suggestions/tuple-float-index.fixed b/src/test/ui/suggestions/tuple-float-index.fixed deleted file mode 100644 index 55bc2f77dad..00000000000 --- a/src/test/ui/suggestions/tuple-float-index.fixed +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// run-rustfix -// compile-flags: -Z parse-only - -fn main () { - ((1, (2, 3)).1).1; //~ ERROR unexpected token: `1.1` -} diff --git a/src/test/ui/suggestions/tuple-float-index.rs b/src/test/ui/suggestions/tuple-float-index.rs deleted file mode 100644 index d569ca4cb86..00000000000 --- a/src/test/ui/suggestions/tuple-float-index.rs +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// run-rustfix -// compile-flags: -Z parse-only - -fn main () { - (1, (2, 3)).1.1; //~ ERROR unexpected token: `1.1` -} diff --git a/src/test/ui/suggestions/tuple-float-index.stderr b/src/test/ui/suggestions/tuple-float-index.stderr deleted file mode 100644 index 15af0834f03..00000000000 --- a/src/test/ui/suggestions/tuple-float-index.stderr +++ /dev/null @@ -1,11 +0,0 @@ -error: unexpected token: `1.1` - --> $DIR/tuple-float-index.rs:15:17 - | -LL | (1, (2, 3)).1.1; //~ ERROR unexpected token: `1.1` - | ------------^^^ - | | | - | | unexpected token - | help: try parenthesizing the first index: `((1, (2, 3)).1).1` - -error: aborting due to previous error - diff --git a/src/test/ui/suggestions/type-ascription-instead-of-initializer.rs b/src/test/ui/suggestions/type-ascription-instead-of-initializer.rs deleted file mode 100644 index d80dad8fbd4..00000000000 --- a/src/test/ui/suggestions/type-ascription-instead-of-initializer.rs +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright 2017 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -fn main() { - let x: Vec::with_capacity(10, 20); //~ ERROR expected type, found `10` - //~^ ERROR this function takes 1 parameter -} diff --git a/src/test/ui/suggestions/type-ascription-instead-of-initializer.stderr b/src/test/ui/suggestions/type-ascription-instead-of-initializer.stderr deleted file mode 100644 index 3722d2a0e3f..00000000000 --- a/src/test/ui/suggestions/type-ascription-instead-of-initializer.stderr +++ /dev/null @@ -1,18 +0,0 @@ -error: expected type, found `10` - --> $DIR/type-ascription-instead-of-initializer.rs:12:31 - | -LL | let x: Vec::with_capacity(10, 20); //~ ERROR expected type, found `10` - | -- ^^ - | || - | |help: use `=` if you meant to assign - | while parsing the type for `x` - -error[E0061]: this function takes 1 parameter but 2 parameters were supplied - --> $DIR/type-ascription-instead-of-initializer.rs:12:12 - | -LL | let x: Vec::with_capacity(10, 20); //~ ERROR expected type, found `10` - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ expected 1 parameter - -error: aborting due to 2 previous errors - -For more information about this error, try `rustc --explain E0061`. diff --git a/src/test/ui/suggestions/type-ascription-instead-of-statement-end.rs b/src/test/ui/suggestions/type-ascription-instead-of-statement-end.rs deleted file mode 100644 index 01d773dd5e1..00000000000 --- a/src/test/ui/suggestions/type-ascription-instead-of-statement-end.rs +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright 2017 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#![feature(type_ascription)] - -fn main() { - println!("test"): - 0; //~ ERROR expected type, found `0` -} - -fn foo() { - println!("test"): 0; //~ ERROR expected type, found `0` -} diff --git a/src/test/ui/suggestions/type-ascription-instead-of-statement-end.stderr b/src/test/ui/suggestions/type-ascription-instead-of-statement-end.stderr deleted file mode 100644 index 314c9060d4f..00000000000 --- a/src/test/ui/suggestions/type-ascription-instead-of-statement-end.stderr +++ /dev/null @@ -1,16 +0,0 @@ -error: expected type, found `0` - --> $DIR/type-ascription-instead-of-statement-end.rs:15:5 - | -LL | println!("test"): - | - help: try using a semicolon: `;` -LL | 0; //~ ERROR expected type, found `0` - | ^ expecting a type here because of type ascription - -error: expected type, found `0` - --> $DIR/type-ascription-instead-of-statement-end.rs:19:23 - | -LL | println!("test"): 0; //~ ERROR expected type, found `0` - | ^ expecting a type here because of type ascription - -error: aborting due to 2 previous errors - diff --git a/src/test/ui/suggestions/type-ascription-with-fn-call.rs b/src/test/ui/suggestions/type-ascription-with-fn-call.rs deleted file mode 100644 index b2c25c37e8e..00000000000 --- a/src/test/ui/suggestions/type-ascription-with-fn-call.rs +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright 2017 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#![feature(type_ascription)] - -fn main() { - f() : - f(); //~ ERROR expected type, found function -} - -fn f() {} diff --git a/src/test/ui/suggestions/type-ascription-with-fn-call.stderr b/src/test/ui/suggestions/type-ascription-with-fn-call.stderr deleted file mode 100644 index 78df97139b6..00000000000 --- a/src/test/ui/suggestions/type-ascription-with-fn-call.stderr +++ /dev/null @@ -1,14 +0,0 @@ -error[E0573]: expected type, found function `f` - --> $DIR/type-ascription-with-fn-call.rs:15:5 - | -LL | f() : - | - help: did you mean to use `;` here instead? -LL | f(); //~ ERROR expected type, found function - | ^^^ - | | - | not a type - | expecting a type here because of type ascription - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0573`. diff --git a/src/test/ui/token/issue-41155.stderr b/src/test/ui/token/issue-41155.stderr index 84dbc7ffc2f..5c1aae29c2f 100644 --- a/src/test/ui/token/issue-41155.stderr +++ b/src/test/ui/token/issue-41155.stderr @@ -1,8 +1,8 @@ -error: expected one of `(`, `async`, `const`, `default`, `extern`, `fn`, `type`, or `unsafe`, found `}` +error: expected one of `(`, `async`, `const`, `default`, `existential`, `extern`, `fn`, `type`, or `unsafe`, found `}` --> $DIR/issue-41155.rs:13:1 | LL | pub - | - expected one of 8 possible tokens here + | - expected one of 9 possible tokens here LL | } //~ ERROR expected one of | ^ unexpected token diff --git a/src/test/ui/try-on-option.rs b/src/test/ui/try-on-option.rs new file mode 100644 index 00000000000..65ca23402d2 --- /dev/null +++ b/src/test/ui/try-on-option.rs @@ -0,0 +1,25 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![feature(try_trait)] + +fn main() {} + +fn foo() -> Result { + let x: Option = None; + x?; //~ the trait bound + Ok(22) +} + +fn bar() -> u32 { + let x: Option = None; + x?; //~ the `?` operator + 22 +} diff --git a/src/test/ui/try-on-option.stderr b/src/test/ui/try-on-option.stderr new file mode 100644 index 00000000000..265ee593bb7 --- /dev/null +++ b/src/test/ui/try-on-option.stderr @@ -0,0 +1,20 @@ +error[E0277]: the trait bound `(): std::convert::From` is not satisfied + --> $DIR/try-on-option.rs:17:5 + | +LL | x?; //~ the trait bound + | ^^ the trait `std::convert::From` is not implemented for `()` + | + = note: required by `std::convert::From::from` + +error[E0277]: the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `std::ops::Try`) + --> $DIR/try-on-option.rs:23:5 + | +LL | x?; //~ the `?` operator + | ^^ cannot use the `?` operator in a function that returns `u32` + | + = help: the trait `std::ops::Try` is not implemented for `u32` + = note: required by `std::ops::Try::from_error` + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/try-operator-on-main.rs b/src/test/ui/try-operator-on-main.rs new file mode 100644 index 00000000000..e52ef45c2ec --- /dev/null +++ b/src/test/ui/try-operator-on-main.rs @@ -0,0 +1,35 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// ignore-cloudabi no std::fs support + +#![feature(try_trait)] + +use std::ops::Try; + +fn main() { + // error for a `Try` type on a non-`Try` fn + std::fs::File::open("foo")?; //~ ERROR the `?` operator can only + + // a non-`Try` type on a non-`Try` fn + ()?; //~ ERROR the `?` operator can only + + // an unrelated use of `Try` + try_trait_generic::<()>(); //~ ERROR the trait bound +} + + + +fn try_trait_generic() -> T { + // and a non-`Try` object on a `Try` fn. + ()?; //~ ERROR the `?` operator can only + + loop {} +} diff --git a/src/test/ui/try-operator-on-main.stderr b/src/test/ui/try-operator-on-main.stderr new file mode 100644 index 00000000000..121ae14f999 --- /dev/null +++ b/src/test/ui/try-operator-on-main.stderr @@ -0,0 +1,42 @@ +error[E0277]: the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `std::ops::Try`) + --> $DIR/try-operator-on-main.rs:19:5 + | +LL | std::fs::File::open("foo")?; //~ ERROR the `?` operator can only + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot use the `?` operator in a function that returns `()` + | + = help: the trait `std::ops::Try` is not implemented for `()` + = note: required by `std::ops::Try::from_error` + +error[E0277]: the `?` operator can only be applied to values that implement `std::ops::Try` + --> $DIR/try-operator-on-main.rs:22:5 + | +LL | ()?; //~ ERROR the `?` operator can only + | ^^^ the `?` operator cannot be applied to type `()` + | + = help: the trait `std::ops::Try` is not implemented for `()` + = note: required by `std::ops::Try::into_result` + +error[E0277]: the trait bound `(): std::ops::Try` is not satisfied + --> $DIR/try-operator-on-main.rs:25:5 + | +LL | try_trait_generic::<()>(); //~ ERROR the trait bound + | ^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::ops::Try` is not implemented for `()` + | +note: required by `try_trait_generic` + --> $DIR/try-operator-on-main.rs:30:1 + | +LL | fn try_trait_generic() -> T { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error[E0277]: the `?` operator can only be applied to values that implement `std::ops::Try` + --> $DIR/try-operator-on-main.rs:32:5 + | +LL | ()?; //~ ERROR the `?` operator can only + | ^^^ the `?` operator cannot be applied to type `()` + | + = help: the trait `std::ops::Try` is not implemented for `()` + = note: required by `std::ops::Try::into_result` + +error: aborting due to 4 previous errors + +For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/tuple-float-index.fixed b/src/test/ui/tuple-float-index.fixed new file mode 100644 index 00000000000..55bc2f77dad --- /dev/null +++ b/src/test/ui/tuple-float-index.fixed @@ -0,0 +1,16 @@ +// Copyright 2012 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// run-rustfix +// compile-flags: -Z parse-only + +fn main () { + ((1, (2, 3)).1).1; //~ ERROR unexpected token: `1.1` +} diff --git a/src/test/ui/tuple-float-index.rs b/src/test/ui/tuple-float-index.rs new file mode 100644 index 00000000000..d569ca4cb86 --- /dev/null +++ b/src/test/ui/tuple-float-index.rs @@ -0,0 +1,16 @@ +// Copyright 2012 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// run-rustfix +// compile-flags: -Z parse-only + +fn main () { + (1, (2, 3)).1.1; //~ ERROR unexpected token: `1.1` +} diff --git a/src/test/ui/tuple-float-index.stderr b/src/test/ui/tuple-float-index.stderr new file mode 100644 index 00000000000..15af0834f03 --- /dev/null +++ b/src/test/ui/tuple-float-index.stderr @@ -0,0 +1,11 @@ +error: unexpected token: `1.1` + --> $DIR/tuple-float-index.rs:15:17 + | +LL | (1, (2, 3)).1.1; //~ ERROR unexpected token: `1.1` + | ------------^^^ + | | | + | | unexpected token + | help: try parenthesizing the first index: `((1, (2, 3)).1).1` + +error: aborting due to previous error + diff --git a/src/test/ui/type-ascription-instead-of-initializer.rs b/src/test/ui/type-ascription-instead-of-initializer.rs new file mode 100644 index 00000000000..d80dad8fbd4 --- /dev/null +++ b/src/test/ui/type-ascription-instead-of-initializer.rs @@ -0,0 +1,14 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn main() { + let x: Vec::with_capacity(10, 20); //~ ERROR expected type, found `10` + //~^ ERROR this function takes 1 parameter +} diff --git a/src/test/ui/type-ascription-instead-of-initializer.stderr b/src/test/ui/type-ascription-instead-of-initializer.stderr new file mode 100644 index 00000000000..3722d2a0e3f --- /dev/null +++ b/src/test/ui/type-ascription-instead-of-initializer.stderr @@ -0,0 +1,18 @@ +error: expected type, found `10` + --> $DIR/type-ascription-instead-of-initializer.rs:12:31 + | +LL | let x: Vec::with_capacity(10, 20); //~ ERROR expected type, found `10` + | -- ^^ + | || + | |help: use `=` if you meant to assign + | while parsing the type for `x` + +error[E0061]: this function takes 1 parameter but 2 parameters were supplied + --> $DIR/type-ascription-instead-of-initializer.rs:12:12 + | +LL | let x: Vec::with_capacity(10, 20); //~ ERROR expected type, found `10` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ expected 1 parameter + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0061`. diff --git a/src/test/ui/type-ascription-instead-of-statement-end.rs b/src/test/ui/type-ascription-instead-of-statement-end.rs new file mode 100644 index 00000000000..01d773dd5e1 --- /dev/null +++ b/src/test/ui/type-ascription-instead-of-statement-end.rs @@ -0,0 +1,20 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![feature(type_ascription)] + +fn main() { + println!("test"): + 0; //~ ERROR expected type, found `0` +} + +fn foo() { + println!("test"): 0; //~ ERROR expected type, found `0` +} diff --git a/src/test/ui/type-ascription-instead-of-statement-end.stderr b/src/test/ui/type-ascription-instead-of-statement-end.stderr new file mode 100644 index 00000000000..314c9060d4f --- /dev/null +++ b/src/test/ui/type-ascription-instead-of-statement-end.stderr @@ -0,0 +1,16 @@ +error: expected type, found `0` + --> $DIR/type-ascription-instead-of-statement-end.rs:15:5 + | +LL | println!("test"): + | - help: try using a semicolon: `;` +LL | 0; //~ ERROR expected type, found `0` + | ^ expecting a type here because of type ascription + +error: expected type, found `0` + --> $DIR/type-ascription-instead-of-statement-end.rs:19:23 + | +LL | println!("test"): 0; //~ ERROR expected type, found `0` + | ^ expecting a type here because of type ascription + +error: aborting due to 2 previous errors + diff --git a/src/test/ui/type-ascription-with-fn-call.rs b/src/test/ui/type-ascription-with-fn-call.rs new file mode 100644 index 00000000000..b2c25c37e8e --- /dev/null +++ b/src/test/ui/type-ascription-with-fn-call.rs @@ -0,0 +1,18 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![feature(type_ascription)] + +fn main() { + f() : + f(); //~ ERROR expected type, found function +} + +fn f() {} diff --git a/src/test/ui/type-ascription-with-fn-call.stderr b/src/test/ui/type-ascription-with-fn-call.stderr new file mode 100644 index 00000000000..78df97139b6 --- /dev/null +++ b/src/test/ui/type-ascription-with-fn-call.stderr @@ -0,0 +1,14 @@ +error[E0573]: expected type, found function `f` + --> $DIR/type-ascription-with-fn-call.rs:15:5 + | +LL | f() : + | - help: did you mean to use `;` here instead? +LL | f(); //~ ERROR expected type, found function + | ^^^ + | | + | not a type + | expecting a type here because of type ascription + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0573`.