From 91d6c60bed2c5d574ca524ab4812f731118cd22d Mon Sep 17 00:00:00 2001 From: Erick Tryzelaar Date: Fri, 30 Aug 2013 15:06:11 -0700 Subject: [PATCH 1/3] fix various warnings --- src/libstd/fmt/parse.rs | 1 - src/libstd/ptr.rs | 1 + src/libsyntax/parse/mod.rs | 2 +- src/test/bench/shootout-pfib.rs | 1 - src/test/run-pass/const-cross-crate-extern.rs | 5 +---- src/test/run-pass/const-extern-function.rs | 6 ++---- .../run-pass/extern-compare-with-return-type.rs | 2 +- src/test/run-pass/extern-take-value.rs | 14 +++++--------- src/test/run-pass/issue-5917.rs | 2 -- src/test/run-pass/monad.rs | 2 -- src/test/run-pass/reflect-visit-data.rs | 1 - src/test/run-pass/static-impl.rs | 2 -- src/test/run-pass/trait-generic.rs | 2 -- 13 files changed, 11 insertions(+), 30 deletions(-) diff --git a/src/libstd/fmt/parse.rs b/src/libstd/fmt/parse.rs index 6448896a489..4bfa6b5afce 100644 --- a/src/libstd/fmt/parse.rs +++ b/src/libstd/fmt/parse.rs @@ -595,7 +595,6 @@ impl<'self> Parser<'self> { mod tests { use super::*; use prelude::*; - use realstd::fmt::{String}; fn same(fmt: &'static str, p: ~[Piece<'static>]) { let mut parser = Parser::new(fmt); diff --git a/src/libstd/ptr.rs b/src/libstd/ptr.rs index 02469527b7a..38d8a244895 100644 --- a/src/libstd/ptr.rs +++ b/src/libstd/ptr.rs @@ -12,6 +12,7 @@ use cast; use clone::Clone; +#[cfg(not(test))] use cmp::Equiv; use iterator::{range, Iterator}; use option::{Option, Some, None}; diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index 81113f24329..61dcc6c1947 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -340,7 +340,7 @@ mod test { use parse::token::{str_to_ident}; use util::parser_testing::{string_to_tts_and_sess, string_to_parser}; use util::parser_testing::{string_to_expr, string_to_item}; - use util::parser_testing::{string_to_stmt, strs_to_idents}; + use util::parser_testing::string_to_stmt; // map a string to tts, return the tt without its parsesess fn string_to_tts_only(source_str : @str) -> ~[ast::token_tree] { diff --git a/src/test/bench/shootout-pfib.rs b/src/test/bench/shootout-pfib.rs index b2491e305b2..7029ca2a492 100644 --- a/src/test/bench/shootout-pfib.rs +++ b/src/test/bench/shootout-pfib.rs @@ -28,7 +28,6 @@ use std::io; use std::os; use std::result::{Ok, Err}; use std::task; -use std::u64; use std::uint; fn fib(n: int) -> int { diff --git a/src/test/run-pass/const-cross-crate-extern.rs b/src/test/run-pass/const-cross-crate-extern.rs index eb7ae3d6fec..5ded736ab9b 100644 --- a/src/test/run-pass/const-cross-crate-extern.rs +++ b/src/test/run-pass/const-cross-crate-extern.rs @@ -13,11 +13,8 @@ extern mod cci_const; use cci_const::bar; -use std::cast::transmute; static foo: extern "C" fn() = bar; pub fn main() { - unsafe { - assert_eq!(foo, bar); - } + assert_eq!(foo, bar); } diff --git a/src/test/run-pass/const-extern-function.rs b/src/test/run-pass/const-extern-function.rs index e07af4b0383..501a87955da 100644 --- a/src/test/run-pass/const-extern-function.rs +++ b/src/test/run-pass/const-extern-function.rs @@ -18,8 +18,6 @@ struct S { } pub fn main() { - unsafe { - assert_eq!(foopy, f); - assert_eq!(f, s.f); - } + assert_eq!(foopy, f); + assert_eq!(f, s.f); } diff --git a/src/test/run-pass/extern-compare-with-return-type.rs b/src/test/run-pass/extern-compare-with-return-type.rs index 41bf4a10b5d..5406fa283e7 100644 --- a/src/test/run-pass/extern-compare-with-return-type.rs +++ b/src/test/run-pass/extern-compare-with-return-type.rs @@ -15,7 +15,7 @@ extern fn voidret2() {} extern fn uintret() -> uint { 22 } -extern fn uintvoidret(x: uint) {} +extern fn uintvoidret(_x: uint) {} extern fn uintuintuintuintret(x: uint, y: uint, z: uint) -> uint { x+y+z } diff --git a/src/test/run-pass/extern-take-value.rs b/src/test/run-pass/extern-take-value.rs index e636f511da8..b883fbd6f6a 100644 --- a/src/test/run-pass/extern-take-value.rs +++ b/src/test/run-pass/extern-take-value.rs @@ -8,8 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use std::cast::transmute; - extern fn f() { } @@ -17,12 +15,10 @@ extern fn g() { } pub fn main() { - unsafe { - let a: extern "C" fn() = f; - let b: extern "C" fn() = f; - let c: extern "C" fn() = g; + let a: extern "C" fn() = f; + let b: extern "C" fn() = f; + let c: extern "C" fn() = g; - assert_eq!(a, b); - assert!(a != c); - } + assert_eq!(a, b); + assert!(a != c); } diff --git a/src/test/run-pass/issue-5917.rs b/src/test/run-pass/issue-5917.rs index 3e588bb53d2..326e92d3b70 100644 --- a/src/test/run-pass/issue-5917.rs +++ b/src/test/run-pass/issue-5917.rs @@ -8,8 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use std::io; - struct T (&'static [int]); static t : T = T (&'static [5, 4, 3]); fn main () { diff --git a/src/test/run-pass/monad.rs b/src/test/run-pass/monad.rs index 7dc859e559e..8baf15c8493 100644 --- a/src/test/run-pass/monad.rs +++ b/src/test/run-pass/monad.rs @@ -10,8 +10,6 @@ // xfail-fast -use std::int; - trait vec_monad { fn bind(&self, f: &fn(&A) -> ~[B]) -> ~[B]; } diff --git a/src/test/run-pass/reflect-visit-data.rs b/src/test/run-pass/reflect-visit-data.rs index efa3286e94a..1c77a6b2fb9 100644 --- a/src/test/run-pass/reflect-visit-data.rs +++ b/src/test/run-pass/reflect-visit-data.rs @@ -10,7 +10,6 @@ // xfail-fast -use std::int; use std::libc::c_void; use std::ptr; use std::sys; diff --git a/src/test/run-pass/static-impl.rs b/src/test/run-pass/static-impl.rs index 520b3583195..651b3342d58 100644 --- a/src/test/run-pass/static-impl.rs +++ b/src/test/run-pass/static-impl.rs @@ -10,8 +10,6 @@ // xfail-fast -use std::uint; - pub trait plus { fn plus(&self) -> int; } diff --git a/src/test/run-pass/trait-generic.rs b/src/test/run-pass/trait-generic.rs index 6916db28e11..f448bcb4ab5 100644 --- a/src/test/run-pass/trait-generic.rs +++ b/src/test/run-pass/trait-generic.rs @@ -10,8 +10,6 @@ // xfail-fast -use std::int; - trait to_str { fn to_string(&self) -> ~str; } From 66e3a4c50efe21e2e62fcf845184c6f1c8044c97 Mon Sep 17 00:00:00 2001 From: Erick Tryzelaar Date: Sat, 17 Aug 2013 11:09:52 -0700 Subject: [PATCH 2/3] rustc: capitalize types in rscope.rs --- src/librustc/middle/typeck/astconv.rs | 38 ++++++++++++------------- src/librustc/middle/typeck/check/mod.rs | 4 +-- src/librustc/middle/typeck/collect.rs | 22 +++++++------- src/librustc/middle/typeck/rscope.rs | 38 ++++++++++++------------- 4 files changed, 51 insertions(+), 51 deletions(-) diff --git a/src/librustc/middle/typeck/astconv.rs b/src/librustc/middle/typeck/astconv.rs index 6ebcf4facc1..18cc5e65a8b 100644 --- a/src/librustc/middle/typeck/astconv.rs +++ b/src/librustc/middle/typeck/astconv.rs @@ -11,7 +11,7 @@ /*! * Conversion from AST representation of types to the ty.rs * representation. The main routine here is `ast_ty_to_ty()`: each use - * is parameterized by an instance of `AstConv` and a `region_scope`. + * is parameterized by an instance of `AstConv` and a `RegionScope`. * * The parameterization of `ast_ty_to_ty()` is because it behaves * somewhat differently during the collect and check phases, @@ -23,12 +23,12 @@ * In the check phase, when the @FnCtxt is used as the `AstConv`, * `get_item_ty()` just looks up the item type in `tcx.tcache`. * - * The `region_scope` trait controls how region references are + * The `RegionScope` trait controls how region references are * handled. It has two methods which are used to resolve anonymous * region references (e.g., `&T`) and named region references (e.g., * `&a.T`). There are numerous region scopes that can be used, but most - * commonly you want either `empty_rscope`, which permits only the static - * region, or `type_rscope`, which permits the self region if the type in + * commonly you want either `EmptyRscope`, which permits only the static + * region, or `TypeRscope`, which permits the self region if the type in * question is parameterized by a region. * * Unlike the `AstConv` trait, the region scope can change as we descend @@ -58,7 +58,7 @@ use middle::ty::{substs}; use middle::ty::{ty_param_substs_and_ty}; use middle::ty; use middle::typeck::rscope::in_binding_rscope; -use middle::typeck::rscope::{region_scope, RegionError}; +use middle::typeck::rscope::{RegionScope, RegionError}; use middle::typeck::rscope::RegionParamNames; use middle::typeck::lookup_def_tcx; @@ -104,7 +104,7 @@ pub fn get_region_reporting_err( } } -pub fn ast_region_to_region( +pub fn ast_region_to_region( this: &AC, rscope: &RS, default_span: span, @@ -129,7 +129,7 @@ pub fn ast_region_to_region( get_region_reporting_err(this.tcx(), span, opt_lifetime, res) } -fn ast_path_substs( +fn ast_path_substs( this: &AC, rscope: &RS, def_id: ast::def_id, @@ -200,7 +200,7 @@ fn ast_path_substs( } pub fn ast_path_to_substs_and_ty( + RS:RegionScope + Clone + 'static>( this: &AC, rscope: &RS, did: ast::def_id, @@ -217,7 +217,7 @@ pub fn ast_path_to_substs_and_ty( +pub fn ast_path_to_trait_ref( this: &AC, rscope: &RS, trait_def_id: ast::def_id, @@ -240,7 +240,7 @@ pub fn ast_path_to_trait_ref( return trait_ref; } -pub fn ast_path_to_ty( +pub fn ast_path_to_ty( this: &AC, rscope: &RS, did: ast::def_id, @@ -262,10 +262,10 @@ pub static NO_TPS: uint = 2; // Parses the programmer's textual representation of a type into our // internal notion of a type. `getter` is a function that returns the type // corresponding to a definition ID: -pub fn ast_ty_to_ty( +pub fn ast_ty_to_ty( this: &AC, rscope: &RS, ast_ty: &ast::Ty) -> ty::t { - fn ast_mt_to_mt( + fn ast_mt_to_mt( this: &AC, rscope: &RS, mt: &ast::mt) -> ty::mt { ty::mt {ty: ast_ty_to_ty(this, rscope, mt.ty), mutbl: mt.mutbl} @@ -274,7 +274,7 @@ pub fn ast_ty_to_ty( // Handle @, ~, and & being able to mean estrs and evecs. // If a_seq_ty is a str or a vec, make it an estr/evec. // Also handle first-class trait types. - fn mk_pointer( + fn mk_pointer( this: &AC, rscope: &RS, a_seq_ty: &ast::mt, @@ -540,7 +540,7 @@ pub fn ast_ty_to_ty( } pub fn ty_of_arg( + RS:RegionScope + Clone + 'static>( this: &AC, rscope: &RS, a: &ast::arg, @@ -588,7 +588,7 @@ struct SelfInfo { explicit_self: ast::explicit_self } -pub fn ty_of_method( +pub fn ty_of_method( this: &AC, rscope: &RS, purity: ast::purity, @@ -606,7 +606,7 @@ pub fn ty_of_method( (a.unwrap(), b) } -pub fn ty_of_bare_fn( +pub fn ty_of_bare_fn( this: &AC, rscope: &RS, purity: ast::purity, @@ -619,7 +619,7 @@ pub fn ty_of_bare_fn( b } -fn ty_of_method_or_bare_fn( +fn ty_of_method_or_bare_fn( this: &AC, rscope: &RS, purity: ast::purity, @@ -657,7 +657,7 @@ fn ty_of_method_or_bare_fn( output: output_ty} }); - fn transform_self_ty( + fn transform_self_ty( this: &AC, rscope: &RS, self_info: &SelfInfo) -> Option @@ -690,7 +690,7 @@ fn ty_of_method_or_bare_fn( } } -pub fn ty_of_closure( +pub fn ty_of_closure( this: &AC, rscope: &RS, sigil: ast::Sigil, diff --git a/src/librustc/middle/typeck/check/mod.rs b/src/librustc/middle/typeck/check/mod.rs index 0b27a581a2a..3016d40729b 100644 --- a/src/librustc/middle/typeck/check/mod.rs +++ b/src/librustc/middle/typeck/check/mod.rs @@ -101,7 +101,7 @@ use middle::typeck::infer::{resolve_type, force_tvar}; use middle::typeck::infer; use middle::typeck::rscope::bound_self_region; use middle::typeck::rscope::{RegionError}; -use middle::typeck::rscope::region_scope; +use middle::typeck::rscope::RegionScope; use middle::typeck::{isr_alist, lookup_def_ccx}; use middle::typeck::no_params; use middle::typeck::{require_same_types, method_map, vtable_map}; @@ -705,7 +705,7 @@ impl FnCtxt { } } -impl region_scope for FnCtxt { +impl RegionScope for FnCtxt { fn anon_region(&self, span: span) -> Result { result::Ok(self.infcx().next_region_var(infer::MiscVariable(span))) } diff --git a/src/librustc/middle/typeck/collect.rs b/src/librustc/middle/typeck/collect.rs index 63317d4ca5c..71a9a041fb5 100644 --- a/src/librustc/middle/typeck/collect.rs +++ b/src/librustc/middle/typeck/collect.rs @@ -97,7 +97,7 @@ pub fn collect_item_types(ccx: @mut CrateCtxt, crate: &ast::Crate) { } pub trait ToTy { - fn to_ty( + fn to_ty( &self, rs: &RS, ast_ty: &ast::Ty) @@ -105,7 +105,7 @@ pub trait ToTy { } impl ToTy for CrateCtxt { - fn to_ty( + fn to_ty( &self, rs: &RS, ast_ty: &ast::Ty) @@ -163,7 +163,7 @@ pub fn get_enum_variant_types(ccx: &CrateCtxt, let result_ty; match variant.node.kind { ast::tuple_variant_kind(ref args) if args.len() > 0 => { - let rs = type_rscope(region_parameterization); + let rs = TypeRscope(region_parameterization); let input_tys = args.map(|va| ccx.to_ty(&rs, &va.ty)); result_ty = Some(ty::mk_ctor_fn(tcx, input_tys, enum_ty)); } @@ -724,7 +724,7 @@ pub fn convert_field(ccx: &CrateCtxt, generics: &ast::Generics) { let region_parameterization = RegionParameterization::from_variance_and_generics(rp, generics); - let tt = ccx.to_ty(&type_rscope(region_parameterization), &v.node.ty); + let tt = ccx.to_ty(&TypeRscope(region_parameterization), &v.node.ty); write_ty_to_tcx(ccx.tcx, v.node.id, tt); /* add the field to the tcache */ ccx.tcx.tcache.insert(local_def(v.node.id), @@ -863,7 +863,7 @@ pub fn convert(ccx: &CrateCtxt, it: &ast::item) { let i_ty_generics = ty_generics(ccx, rp, generics, 0); let region_parameterization = RegionParameterization::from_variance_and_generics(rp, generics); - let selfty = ccx.to_ty(&type_rscope(region_parameterization), selfty); + let selfty = ccx.to_ty(&TypeRscope(region_parameterization), selfty); write_ty_to_tcx(tcx, it.id, selfty); tcx.tcache.insert(local_def(it.id), ty_param_bounds_and_ty { @@ -1024,7 +1024,7 @@ pub fn instantiate_trait_ref(ccx: &CrateCtxt, let rp = RegionParameterization::from_variance_and_generics(rp, generics); - let rscope = type_rscope(rp); + let rscope = TypeRscope(rp); match lookup_def_tcx(ccx.tcx, ast_trait_ref.path.span, ast_trait_ref.ref_id) { ast::def_trait(trait_did) => { @@ -1099,7 +1099,7 @@ pub fn ty_of_item(ccx: &CrateCtxt, it: &ast::item) let rp = tcx.region_paramd_items.find(&it.id).map_move(|x| *x); match it.node { ast::item_static(ref t, _, _) => { - let typ = ccx.to_ty(&empty_rscope, t); + let typ = ccx.to_ty(&EmptyRscope, t); let tpt = no_params(typ); tcx.tcache.insert(local_def(it.id), tpt); return tpt; @@ -1108,7 +1108,7 @@ pub fn ty_of_item(ccx: &CrateCtxt, it: &ast::item) assert!(rp.is_none()); let ty_generics = ty_generics(ccx, None, generics, 0); let tofd = astconv::ty_of_bare_fn(ccx, - &empty_rscope, + &EmptyRscope, purity, abi, &generics.lifetimes, @@ -1137,7 +1137,7 @@ pub fn ty_of_item(ccx: &CrateCtxt, it: &ast::item) let region_parameterization = RegionParameterization::from_variance_and_generics(rp, generics); let tpt = { - let ty = ccx.to_ty(&type_rscope(region_parameterization), t); + let ty = ccx.to_ty(&TypeRscope(region_parameterization), t); ty_param_bounds_and_ty { generics: ty_generics(ccx, rp, generics, 0), ty: ty @@ -1197,7 +1197,7 @@ pub fn ty_of_foreign_item(ccx: &CrateCtxt, type_param_defs: @~[], region_param: None, }, - ty: ast_ty_to_ty(ccx, &empty_rscope, t) + ty: ast_ty_to_ty(ccx, &EmptyRscope, t) } } } @@ -1282,7 +1282,7 @@ pub fn ty_of_foreign_fn_decl(ccx: &CrateCtxt, -> ty::ty_param_bounds_and_ty { let ty_generics = ty_generics(ccx, None, ast_generics, 0); let region_param_names = RegionParamNames::from_generics(ast_generics); - let rb = in_binding_rscope(&empty_rscope, region_param_names); + let rb = in_binding_rscope(&EmptyRscope, region_param_names); let input_tys = decl.inputs.map(|a| ty_of_arg(ccx, &rb, a, None) ); let output_ty = ast_ty_to_ty(ccx, &rb, &decl.output); diff --git a/src/librustc/middle/typeck/rscope.rs b/src/librustc/middle/typeck/rscope.rs index c9e2b8dd37b..a93ff9c5fd0 100644 --- a/src/librustc/middle/typeck/rscope.rs +++ b/src/librustc/middle/typeck/rscope.rs @@ -24,7 +24,7 @@ pub struct RegionError { replacement: ty::Region } -pub trait region_scope { +pub trait RegionScope { fn anon_region(&self, span: span) -> Result; fn self_region(&self, span: span) -> Result; fn named_region(&self, span: span, id: ast::ident) @@ -32,8 +32,8 @@ pub trait region_scope { } #[deriving(Clone)] -pub enum empty_rscope { empty_rscope } -impl region_scope for empty_rscope { +pub struct EmptyRscope; +impl RegionScope for EmptyRscope { fn anon_region(&self, _span: span) -> Result { result::Err(RegionError { msg: ~"only 'static is allowed here", @@ -175,7 +175,7 @@ impl MethodRscope { } } -impl region_scope for MethodRscope { +impl RegionScope for MethodRscope { fn anon_region(&self, _span: span) -> Result { result::Err(RegionError { msg: ~"anonymous lifetimes are not permitted here", @@ -202,7 +202,7 @@ impl region_scope for MethodRscope { if !self.region_param_names.has_ident(id) { return RegionParamNames::undeclared_name(None); } - do empty_rscope.named_region(span, id).chain_err |_e| { + do EmptyRscope.named_region(span, id).chain_err |_e| { result::Err(RegionError { msg: ~"lifetime is not in scope", replacement: ty::re_bound(ty::br_self) @@ -212,9 +212,9 @@ impl region_scope for MethodRscope { } #[deriving(Clone)] -pub struct type_rscope(Option); +pub struct TypeRscope(Option); -impl type_rscope { +impl TypeRscope { fn replacement(&self) -> ty::Region { if self.is_some() { ty::re_bound(ty::br_self) @@ -223,7 +223,7 @@ impl type_rscope { } } } -impl region_scope for type_rscope { +impl RegionScope for TypeRscope { fn anon_region(&self, _span: span) -> Result { result::Err(RegionError { msg: ~"anonymous lifetimes are not permitted here", @@ -251,7 +251,7 @@ impl region_scope for type_rscope { } fn named_region(&self, span: span, id: ast::ident) -> Result { - do empty_rscope.named_region(span, id).chain_err |_e| { + do EmptyRscope.named_region(span, id).chain_err |_e| { result::Err(RegionError { msg: ~"only 'self is allowed as part of a type declaration", replacement: self.replacement() @@ -268,15 +268,15 @@ pub fn bound_self_region(rp: Option) } } -pub struct binding_rscope { - base: @region_scope, +pub struct BindingRscope { + base: @RegionScope, anon_bindings: @mut uint, region_param_names: RegionParamNames, } -impl Clone for binding_rscope { - fn clone(&self) -> binding_rscope { - binding_rscope { +impl Clone for BindingRscope { + fn clone(&self) -> BindingRscope { + BindingRscope { base: self.base, anon_bindings: self.anon_bindings, region_param_names: self.region_param_names.clone(), @@ -284,20 +284,20 @@ impl Clone for binding_rscope { } } -pub fn in_binding_rscope( +pub fn in_binding_rscope( this: &RS, region_param_names: RegionParamNames) - -> binding_rscope { + -> BindingRscope { let base = @(*this).clone(); - let base = base as @region_scope; - binding_rscope { + let base = base as @RegionScope; + BindingRscope { base: base, anon_bindings: @mut 0, region_param_names: region_param_names, } } -impl region_scope for binding_rscope { +impl RegionScope for BindingRscope { fn anon_region(&self, _span: span) -> Result { let idx = *self.anon_bindings; *self.anon_bindings += 1; From 9730ed9b027f17441faa90fce26350991a76b1d5 Mon Sep 17 00:00:00 2001 From: Erick Tryzelaar Date: Fri, 30 Aug 2013 15:04:20 -0700 Subject: [PATCH 3/3] std: Add a fixme for when we add Trait::::static_method() --- src/libstd/num/num.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/libstd/num/num.rs b/src/libstd/num/num.rs index 3cb110d8464..ac8f0022b95 100644 --- a/src/libstd/num/num.rs +++ b/src/libstd/num/num.rs @@ -285,6 +285,7 @@ pub trait Primitive: Num + Div + Rem { // FIXME (#5527): These should be associated constants + // FIXME (#8888): Removing `unused_self` requires #8888 to be fixed. fn bits(unused_self: Option) -> uint; fn bytes(unused_self: Option) -> uint; } @@ -327,6 +328,7 @@ pub trait Float: Real fn is_normal(&self) -> bool; fn classify(&self) -> FPCategory; + // FIXME (#8888): Removing `unused_self` requires #8888 to be fixed. fn mantissa_digits(unused_self: Option) -> uint; fn digits(unused_self: Option) -> uint; fn epsilon() -> Self;