From 19e6f06818d07c729bbc3522cbb73b66493a03f5 Mon Sep 17 00:00:00 2001 From: CensoredUsername Date: Sun, 21 Aug 2016 18:57:43 +0200 Subject: [PATCH 1/9] Make the return type of AstBuilder.stmt_let_typed match the return type of other AstBuilder.stmt* functions --- src/libsyntax/ext/build.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index b81d95a6998c3..08bedd794f6a0 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -96,7 +96,7 @@ pub trait AstBuilder { ident: ast::Ident, typ: P, ex: P) - -> P; + -> ast::Stmt; fn stmt_let_type_only(&self, span: Span, ty: P) -> ast::Stmt; fn stmt_item(&self, sp: Span, item: P) -> ast::Stmt; @@ -556,7 +556,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { ident: ast::Ident, typ: P, ex: P) - -> P { + -> ast::Stmt { let pat = if mutbl { let binding_mode = ast::BindingMode::ByValue(ast::Mutability::Mutable); self.pat_ident_binding_mode(sp, ident, binding_mode) @@ -571,11 +571,11 @@ impl<'a> AstBuilder for ExtCtxt<'a> { span: sp, attrs: ast::ThinVec::new(), }); - P(ast::Stmt { + ast::Stmt { id: ast::DUMMY_NODE_ID, node: ast::StmtKind::Local(local), span: sp, - }) + } } // Generate `let _: Type;`, usually used for type assertions. From 4c37ad660714ab65d20226c743f686cf6174abc7 Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Tue, 17 May 2016 18:51:45 +0200 Subject: [PATCH 2/9] Add attribute support to generic lifetime and type parameters. I am using `ThinAttributes` rather than a vector for attributes attached to generics, since I expect almost all lifetime and types parameters to not carry any attributes. --- src/libsyntax/ast.rs | 2 + src/libsyntax/ext/build.rs | 6 +++ src/libsyntax/feature_gate.rs | 21 ++++++++++ src/libsyntax/fold.rs | 12 +++++- src/libsyntax/parse/parser.rs | 47 ++++++++++++++++++----- src/libsyntax/visit.rs | 2 + src/libsyntax_ext/deriving/generic/mod.rs | 2 +- src/libsyntax_ext/deriving/generic/ty.rs | 7 ++-- 8 files changed, 85 insertions(+), 14 deletions(-) diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index c18b36161dfcf..c5765f159a9cf 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -121,6 +121,7 @@ impl fmt::Debug for Lifetime { /// A lifetime definition, e.g. `'a: 'b+'c+'d` #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] pub struct LifetimeDef { + pub attrs: ThinVec, pub lifetime: Lifetime, pub bounds: Vec } @@ -370,6 +371,7 @@ pub type TyParamBounds = P<[TyParamBound]>; #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] pub struct TyParam { + pub attrs: ThinVec, pub ident: Ident, pub id: NodeId, pub bounds: TyParamBounds, diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index b81d95a6998c3..b822599e941f1 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -73,6 +73,7 @@ pub trait AstBuilder { fn typaram(&self, span: Span, id: ast::Ident, + attrs: Vec, bounds: ast::TyParamBounds, default: Option>) -> ast::TyParam; @@ -83,6 +84,7 @@ pub trait AstBuilder { fn lifetime_def(&self, span: Span, name: ast::Name, + attrs: Vec, bounds: Vec) -> ast::LifetimeDef; @@ -452,11 +454,13 @@ impl<'a> AstBuilder for ExtCtxt<'a> { fn typaram(&self, span: Span, id: ast::Ident, + attrs: Vec, bounds: ast::TyParamBounds, default: Option>) -> ast::TyParam { ast::TyParam { ident: id, id: ast::DUMMY_NODE_ID, + attrs: attrs.into(), bounds: bounds, default: default, span: span @@ -503,9 +507,11 @@ impl<'a> AstBuilder for ExtCtxt<'a> { fn lifetime_def(&self, span: Span, name: ast::Name, + attrs: Vec, bounds: Vec) -> ast::LifetimeDef { ast::LifetimeDef { + attrs: attrs.into(), lifetime: self.lifetime(span, name), bounds: bounds } diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index 27b97a0ad665b..67372351b44d9 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -302,6 +302,9 @@ declare_features! ( // Used to identify the `compiler_builtins` crate // rustc internal (active, compiler_builtins, "1.13.0", None), + + // Allows attributes on lifetime/type formal parameters in generics (RFC 1327) + (active, generic_param_attrs, "1.11.0", Some(34761)), ); declare_features! ( @@ -1208,6 +1211,24 @@ impl<'a> Visitor for PostExpansionVisitor<'a> { visit::walk_vis(self, vis) } + + fn visit_generics(&mut self, g: &ast::Generics) { + for t in &g.ty_params { + if !t.attrs.is_empty() { + gate_feature_post!(&self, generic_param_attrs, t.attrs[0].span, + "attributes on type parameter bindings are experimental"); + } + } + visit::walk_generics(self, g) + } + + fn visit_lifetime_def(&mut self, lifetime_def: &ast::LifetimeDef) { + if !lifetime_def.attrs.is_empty() { + gate_feature_post!(&self, generic_param_attrs, lifetime_def.attrs[0].span, + "attributes on lifetime bindings are experimental"); + } + visit::walk_lifetime_def(self, lifetime_def) + } } pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute]) -> Features { diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index 36f273e1dbc29..e28c67602c532 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -662,8 +662,13 @@ pub fn noop_fold_ty_param_bound(tpb: TyParamBound, fld: &mut T) } pub fn noop_fold_ty_param(tp: TyParam, fld: &mut T) -> TyParam { - let TyParam {id, ident, bounds, default, span} = tp; + let TyParam {attrs, id, ident, bounds, default, span} = tp; + let attrs: Vec<_> = attrs.into(); TyParam { + attrs: attrs.into_iter() + .flat_map(|x| fld.fold_attribute(x).into_iter()) + .collect::>() + .into(), id: fld.new_id(id), ident: ident, bounds: fld.fold_bounds(bounds), @@ -687,7 +692,12 @@ pub fn noop_fold_lifetime(l: Lifetime, fld: &mut T) -> Lifetime { pub fn noop_fold_lifetime_def(l: LifetimeDef, fld: &mut T) -> LifetimeDef { + let attrs: Vec<_> = l.attrs.into(); LifetimeDef { + attrs: attrs.into_iter() + .flat_map(|x| fld.fold_attribute(x).into_iter()) + .collect::>() + .into(), lifetime: fld.fold_lifetime(l.lifetime), bounds: fld.fold_lifetimes(l.bounds), } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 23085fadc5e60..fe5ff5c47b248 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -1184,7 +1184,7 @@ impl<'a> Parser<'a> { let lo = self.span.lo; let (name, node) = if self.eat_keyword(keywords::Type) { - let TyParam {ident, bounds, default, ..} = self.parse_ty_param()?; + let TyParam {ident, bounds, default, ..} = self.parse_ty_param(vec![])?; self.expect(&token::Semi)?; (ident, TraitItemKind::Type(bounds, default)) } else if self.is_const_item() { @@ -1923,10 +1923,22 @@ impl<'a> Parser<'a> { /// Parses `lifetime_defs = [ lifetime_defs { ',' lifetime_defs } ]` where `lifetime_def = /// lifetime [':' lifetimes]` - pub fn parse_lifetime_defs(&mut self) -> PResult<'a, Vec> { - + /// + /// If `followed_by_ty_params` is None, then we are in a context + /// where only lifetime parameters are allowed, and thus we should + /// error if we encounter attributes after the bound lifetimes. + /// + /// If `followed_by_ty_params` is Some(r), then there may be type + /// parameter bindings after the lifetimes, so we should pass + /// along the parsed attributes to be attached to the first such + /// type parmeter. + pub fn parse_lifetime_defs(&mut self, + followed_by_ty_params: Option<&mut Vec>) + -> PResult<'a, Vec> + { let mut res = Vec::new(); loop { + let attrs = self.parse_outer_attributes()?; match self.token { token::Lifetime(_) => { let lifetime = self.parse_lifetime()?; @@ -1936,11 +1948,20 @@ impl<'a> Parser<'a> { } else { Vec::new() }; - res.push(ast::LifetimeDef { lifetime: lifetime, + res.push(ast::LifetimeDef { attrs: attrs.into(), + lifetime: lifetime, bounds: bounds }); } _ => { + if let Some(recv) = followed_by_ty_params { + assert!(recv.is_empty()); + *recv = attrs; + } else { + let msg = "encountered trailing attributes after lifetime parameters"; + return Err(self.fatal(msg)); + } + debug!("parse_lifetime_defs ret {:?}", res); return Ok(res); } } @@ -4238,7 +4259,7 @@ impl<'a> Parser<'a> { } /// Matches typaram = IDENT (`?` unbound)? optbounds ( EQ ty )? - fn parse_ty_param(&mut self) -> PResult<'a, TyParam> { + fn parse_ty_param(&mut self, preceding_attrs: Vec) -> PResult<'a, TyParam> { let span = self.span; let ident = self.parse_ident()?; @@ -4252,6 +4273,7 @@ impl<'a> Parser<'a> { }; Ok(TyParam { + attrs: preceding_attrs.into(), ident: ident, id: ast::DUMMY_NODE_ID, bounds: bounds, @@ -4272,11 +4294,18 @@ impl<'a> Parser<'a> { let span_lo = self.span.lo; if self.eat(&token::Lt) { - let lifetime_defs = self.parse_lifetime_defs()?; + let mut attrs = vec![]; + let lifetime_defs = self.parse_lifetime_defs(Some(&mut attrs))?; let mut seen_default = false; + let mut post_lifetime_attrs = Some(attrs); let ty_params = self.parse_seq_to_gt(Some(token::Comma), |p| { p.forbid_lifetime()?; - let ty_param = p.parse_ty_param()?; + let attrs = match post_lifetime_attrs.as_mut() { + None => p.parse_outer_attributes()?, + Some(attrs) => mem::replace(attrs, vec![]), + }; + post_lifetime_attrs = None; + let ty_param = p.parse_ty_param(attrs)?; if ty_param.default.is_some() { seen_default = true; } else if seen_default { @@ -4433,7 +4462,7 @@ impl<'a> Parser<'a> { let bound_lifetimes = if self.eat_keyword(keywords::For) { // Higher ranked constraint. self.expect(&token::Lt)?; - let lifetime_defs = self.parse_lifetime_defs()?; + let lifetime_defs = self.parse_lifetime_defs(None)?; self.expect_gt()?; lifetime_defs } else { @@ -5006,7 +5035,7 @@ impl<'a> Parser<'a> { fn parse_late_bound_lifetime_defs(&mut self) -> PResult<'a, Vec> { if self.eat_keyword(keywords::For) { self.expect(&token::Lt)?; - let lifetime_defs = self.parse_lifetime_defs()?; + let lifetime_defs = self.parse_lifetime_defs(None)?; self.expect_gt()?; Ok(lifetime_defs) } else { diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index 57b06c40878fe..70864c3a6e674 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -201,6 +201,7 @@ pub fn walk_lifetime(visitor: &mut V, lifetime: &Lifetime) { pub fn walk_lifetime_def(visitor: &mut V, lifetime_def: &LifetimeDef) { visitor.visit_lifetime(&lifetime_def.lifetime); walk_list!(visitor, visit_lifetime, &lifetime_def.bounds); + walk_list!(visitor, visit_attribute, &*lifetime_def.attrs); } pub fn walk_poly_trait_ref(visitor: &mut V, trait_ref: &PolyTraitRef, _: &TraitBoundModifier) @@ -474,6 +475,7 @@ pub fn walk_generics(visitor: &mut V, generics: &Generics) { visitor.visit_ident(param.span, param.ident); walk_list!(visitor, visit_ty_param_bound, ¶m.bounds); walk_list!(visitor, visit_ty, ¶m.default); + walk_list!(visitor, visit_attribute, &*param.attrs); } walk_list!(visitor, visit_lifetime_def, &generics.lifetimes); for predicate in &generics.where_clause.predicates { diff --git a/src/libsyntax_ext/deriving/generic/mod.rs b/src/libsyntax_ext/deriving/generic/mod.rs index e307925a6ed83..bc47d8f4e6137 100644 --- a/src/libsyntax_ext/deriving/generic/mod.rs +++ b/src/libsyntax_ext/deriving/generic/mod.rs @@ -536,7 +536,7 @@ impl<'a> TraitDef<'a> { bounds.push((*declared_bound).clone()); } - cx.typaram(self.span, ty_param.ident, P::from_vec(bounds), None) + cx.typaram(self.span, ty_param.ident, vec![], P::from_vec(bounds), None) })); // and similarly for where clauses diff --git a/src/libsyntax_ext/deriving/generic/ty.rs b/src/libsyntax_ext/deriving/generic/ty.rs index 210878b7c9f0e..4749d082bc0ec 100644 --- a/src/libsyntax_ext/deriving/generic/ty.rs +++ b/src/libsyntax_ext/deriving/generic/ty.rs @@ -194,6 +194,7 @@ impl<'a> Ty<'a> { fn mk_ty_param(cx: &ExtCtxt, span: Span, name: &str, + attrs: &[ast::Attribute], bounds: &[Path], self_ident: Ident, self_generics: &Generics) @@ -204,7 +205,7 @@ fn mk_ty_param(cx: &ExtCtxt, cx.typarambound(path) }) .collect(); - cx.typaram(span, cx.ident_of(name), bounds, None) + cx.typaram(span, cx.ident_of(name), attrs.to_owned(), bounds, None) } fn mk_generics(lifetimes: Vec, ty_params: Vec, span: Span) @@ -246,7 +247,7 @@ impl<'a> LifetimeBounds<'a> { let bounds = bounds.iter() .map(|b| cx.lifetime(span, cx.ident_of(*b).name)) .collect(); - cx.lifetime_def(span, cx.ident_of(*lt).name, bounds) + cx.lifetime_def(span, cx.ident_of(*lt).name, vec![], bounds) }) .collect(); let ty_params = self.bounds @@ -254,7 +255,7 @@ impl<'a> LifetimeBounds<'a> { .map(|t| { match *t { (ref name, ref bounds) => { - mk_ty_param(cx, span, *name, bounds, self_ty, self_generics) + mk_ty_param(cx, span, *name, &[], bounds, self_ty, self_generics) } } }) From c242fc3ea3f64f2225e3ba9dd85545bb1d72a578 Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Mon, 11 Jul 2016 16:52:37 +0200 Subject: [PATCH 3/9] Generic unit tests for attributes on lifetime/type formals in generics list. --- .../attr-on-generic-formals-are-visited.rs | 75 ++++++++++++++++++ ...attr-on-generic-formals-wo-feature-gate.rs | 76 +++++++++++++++++++ src/test/run-pass/attr-on-generic-formals.rs | 60 +++++++++++++++ 3 files changed, 211 insertions(+) create mode 100644 src/test/compile-fail/attr-on-generic-formals-are-visited.rs create mode 100644 src/test/compile-fail/attr-on-generic-formals-wo-feature-gate.rs create mode 100644 src/test/run-pass/attr-on-generic-formals.rs diff --git a/src/test/compile-fail/attr-on-generic-formals-are-visited.rs b/src/test/compile-fail/attr-on-generic-formals-are-visited.rs new file mode 100644 index 0000000000000..c902cfdd756df --- /dev/null +++ b/src/test/compile-fail/attr-on-generic-formals-are-visited.rs @@ -0,0 +1,75 @@ +// 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. + +// This test ensures that attributes on formals in generic parameter +// lists are included when we are checking for unstable attributes. +// +// Note that feature(generic_param_attrs) *is* enabled here. We are +// checking feature-gating of the attributes themselves, not the +// capability to parse such attributes in that context. + +#![feature(generic_param_attrs)] +#![allow(dead_code)] + +struct StLt<#[lt_struct] 'a>(&'a u32); +//~^ ERROR The attribute `lt_struct` is currently unknown to the compiler +struct StTy<#[ty_struct] I>(I); +//~^ ERROR The attribute `ty_struct` is currently unknown to the compiler + +enum EnLt<#[lt_enum] 'b> { A(&'b u32), B } +//~^ ERROR The attribute `lt_enum` is currently unknown to the compiler +enum EnTy<#[ty_enum] J> { A(J), B } +//~^ ERROR The attribute `ty_enum` is currently unknown to the compiler + +trait TrLt<#[lt_trait] 'c> { fn foo(&self, _: &'c [u32]) -> &'c u32; } +//~^ ERROR The attribute `lt_trait` is currently unknown to the compiler +trait TrTy<#[ty_trait] K> { fn foo(&self, _: K); } +//~^ ERROR The attribute `ty_trait` is currently unknown to the compiler + +type TyLt<#[lt_type] 'd> = &'d u32; +//~^ ERROR The attribute `lt_type` is currently unknown to the compiler +type TyTy<#[ty_type] L> = (L, ); +//~^ ERROR The attribute `ty_type` is currently unknown to the compiler + +impl<#[lt_inherent] 'e> StLt<'e> { } +//~^ ERROR The attribute `lt_inherent` is currently unknown to the compiler +impl<#[ty_inherent] M> StTy { } +//~^ ERROR The attribute `ty_inherent` is currently unknown to the compiler + +impl<#[lt_impl_for] 'f> TrLt<'f> for StLt<'f> { + //~^ ERROR The attribute `lt_impl_for` is currently unknown to the compiler + fn foo(&self, _: &'f [u32]) -> &'f u32 { loop { } } +} +impl<#[ty_impl_for] N> TrTy for StTy { + //~^ ERROR The attribute `ty_impl_for` is currently unknown to the compiler + fn foo(&self, _: N) { } +} + +fn f_lt<#[lt_fn] 'g>(_: &'g [u32]) -> &'g u32 { loop { } } +//~^ ERROR The attribute `lt_fn` is currently unknown to the compiler +fn f_ty<#[ty_fn] O>(_: O) { } +//~^ ERROR The attribute `ty_fn` is currently unknown to the compiler + +impl StTy { + fn m_lt<#[lt_meth] 'h>(_: &'h [u32]) -> &'h u32 { loop { } } + //~^ ERROR The attribute `lt_meth` is currently unknown to the compiler + fn m_ty<#[ty_meth] P>(_: P) { } + //~^ ERROR The attribute `ty_meth` is currently unknown to the compiler +} + +fn hof_lt(_: Q) + where Q: for <#[lt_hof] 'i> Fn(&'i [u32]) -> &'i u32 + //~^ ERROR The attribute `lt_hof` is currently unknown to the compiler +{ +} + +fn main() { + +} diff --git a/src/test/compile-fail/attr-on-generic-formals-wo-feature-gate.rs b/src/test/compile-fail/attr-on-generic-formals-wo-feature-gate.rs new file mode 100644 index 0000000000000..944802f450a6d --- /dev/null +++ b/src/test/compile-fail/attr-on-generic-formals-wo-feature-gate.rs @@ -0,0 +1,76 @@ +// 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. + +// This test ensures that attributes on formals in generic parameter +// lists are rejected if feature(generic_param_attrs) is not enabled. +// +// (We are prefixing all tested features with `rustc_`, to ensure that +// the attributes themselves won't be rejected by the compiler when +// using `rustc_attrs` feature. There is a separate compile-fail/ test +// ensuring that the attribute feature-gating works in this context.) + +#![feature(rustc_attrs)] +#![allow(dead_code)] + +struct StLt<#[rustc_lt_struct] 'a>(&'a u32); +//~^ ERROR attributes on lifetime bindings are experimental (see issue #34761) +struct StTy<#[rustc_ty_struct] I>(I); +//~^ ERROR attributes on type parameter bindings are experimental (see issue #34761) + +enum EnLt<#[rustc_lt_enum] 'b> { A(&'b u32), B } +//~^ ERROR attributes on lifetime bindings are experimental (see issue #34761) +enum EnTy<#[rustc_ty_enum] J> { A(J), B } +//~^ ERROR attributes on type parameter bindings are experimental (see issue #34761) + +trait TrLt<#[rustc_lt_trait] 'c> { fn foo(&self, _: &'c [u32]) -> &'c u32; } +//~^ ERROR attributes on lifetime bindings are experimental (see issue #34761) +trait TrTy<#[rustc_ty_trait] K> { fn foo(&self, _: K); } +//~^ ERROR attributes on type parameter bindings are experimental (see issue #34761) + +type TyLt<#[rustc_lt_type] 'd> = &'d u32; +//~^ ERROR attributes on lifetime bindings are experimental (see issue #34761) +type TyTy<#[rustc_ty_type] L> = (L, ); +//~^ ERROR attributes on type parameter bindings are experimental (see issue #34761) + +impl<#[rustc_lt_inherent] 'e> StLt<'e> { } +//~^ ERROR attributes on lifetime bindings are experimental (see issue #34761) +impl<#[rustc_ty_inherent] M> StTy { } +//~^ ERROR attributes on type parameter bindings are experimental (see issue #34761) + +impl<#[rustc_lt_impl_for] 'f> TrLt<'f> for StLt<'f> { + //~^ ERROR attributes on lifetime bindings are experimental (see issue #34761) + fn foo(&self, _: &'f [u32]) -> &'f u32 { loop { } } +} +impl<#[rustc_ty_impl_for] N> TrTy for StTy { + //~^ ERROR attributes on type parameter bindings are experimental (see issue #34761) + fn foo(&self, _: N) { } +} + +fn f_lt<#[rustc_lt_fn] 'g>(_: &'g [u32]) -> &'g u32 { loop { } } +//~^ ERROR attributes on lifetime bindings are experimental (see issue #34761) +fn f_ty<#[rustc_ty_fn] O>(_: O) { } +//~^ ERROR attributes on type parameter bindings are experimental (see issue #34761) + +impl StTy { + fn m_lt<#[rustc_lt_meth] 'h>(_: &'h [u32]) -> &'h u32 { loop { } } + //~^ ERROR attributes on lifetime bindings are experimental (see issue #34761) + fn m_ty<#[rustc_ty_meth] P>(_: P) { } + //~^ ERROR attributes on type parameter bindings are experimental (see issue #34761) +} + +fn hof_lt(_: Q) + where Q: for <#[rustc_lt_hof] 'i> Fn(&'i [u32]) -> &'i u32 + //~^ ERROR attributes on lifetime bindings are experimental (see issue #34761) +{ +} + +fn main() { + +} diff --git a/src/test/run-pass/attr-on-generic-formals.rs b/src/test/run-pass/attr-on-generic-formals.rs new file mode 100644 index 0000000000000..5985284d8496b --- /dev/null +++ b/src/test/run-pass/attr-on-generic-formals.rs @@ -0,0 +1,60 @@ +// 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. + +// This test ensures we can attach attributes to the formals in all +// places where generic parameter lists occur, assuming appropriate +// feature gates are enabled. +// +// (We are prefixing all tested features with `rustc_`, to ensure that +// the attributes themselves won't be rejected by the compiler when +// using `rustc_attrs` feature. There is a separate compile-fail/ test +// ensuring that the attribute feature-gating works in this context.) + +#![feature(generic_param_attrs, rustc_attrs)] +#![allow(dead_code)] + +struct StLt<#[rustc_lt_struct] 'a>(&'a u32); +struct StTy<#[rustc_ty_struct] I>(I); + +enum EnLt<#[rustc_lt_enum] 'b> { A(&'b u32), B } +enum EnTy<#[rustc_ty_enum] J> { A(J), B } + +trait TrLt<#[rustc_lt_trait] 'c> { fn foo(&self, _: &'c [u32]) -> &'c u32; } +trait TrTy<#[rustc_ty_trait] K> { fn foo(&self, _: K); } + +type TyLt<#[rustc_lt_type] 'd> = &'d u32; +type TyTy<#[rustc_ty_type] L> = (L, ); + +impl<#[rustc_lt_inherent] 'e> StLt<'e> { } +impl<#[rustc_ty_inherent] M> StTy { } + +impl<#[rustc_lt_impl_for] 'f> TrLt<'f> for StLt<'f> { + fn foo(&self, _: &'f [u32]) -> &'f u32 { loop { } } +} +impl<#[rustc_ty_impl_for] N> TrTy for StTy { + fn foo(&self, _: N) { } +} + +fn f_lt<#[rustc_lt_fn] 'g>(_: &'g [u32]) -> &'g u32 { loop { } } +fn f_ty<#[rustc_ty_fn] O>(_: O) { } + +impl StTy { + fn m_lt<#[rustc_lt_meth] 'h>(_: &'h [u32]) -> &'h u32 { loop { } } + fn m_ty<#[rustc_ty_meth] P>(_: P) { } +} + +fn hof_lt(_: Q) + where Q: for <#[rustc_lt_hof] 'i> Fn(&'i [u32]) -> &'i u32 +{ +} + +fn main() { + +} From 3a9b7be10b8e32d014008f9fde276cd032aa4e4a Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Mon, 11 Jul 2016 18:29:45 +0200 Subject: [PATCH 4/9] Added tests and fixed corner case for trailing attributes with no attached binding in generics. --- src/libsyntax/parse/parser.rs | 17 +++++++++++- .../attrs-with-no-formal-in-generics-1.rs | 26 +++++++++++++++++++ .../attrs-with-no-formal-in-generics-2.rs | 26 +++++++++++++++++++ .../attrs-with-no-formal-in-generics-3.rs | 26 +++++++++++++++++++ 4 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 src/test/compile-fail/attrs-with-no-formal-in-generics-1.rs create mode 100644 src/test/compile-fail/attrs-with-no-formal-in-generics-2.rs create mode 100644 src/test/compile-fail/attrs-with-no-formal-in-generics-3.rs diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index fe5ff5c47b248..3c561780085b8 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -1958,7 +1958,7 @@ impl<'a> Parser<'a> { assert!(recv.is_empty()); *recv = attrs; } else { - let msg = "encountered trailing attributes after lifetime parameters"; + let msg = "trailing attribute after lifetime parameters"; return Err(self.fatal(msg)); } debug!("parse_lifetime_defs ret {:?}", res); @@ -4294,12 +4294,21 @@ impl<'a> Parser<'a> { let span_lo = self.span.lo; if self.eat(&token::Lt) { + // Upon encountering attribute in generics list, we do not + // know if it is attached to lifetime or to type param. + // + // Solution: 1. eagerly parse attributes in tandem with + // lifetime defs, 2. store last set of parsed (and unused) + // attributes in `attrs`, and 3. pass in those attributes + // when parsing formal type param after lifetime defs. let mut attrs = vec![]; let lifetime_defs = self.parse_lifetime_defs(Some(&mut attrs))?; let mut seen_default = false; let mut post_lifetime_attrs = Some(attrs); let ty_params = self.parse_seq_to_gt(Some(token::Comma), |p| { p.forbid_lifetime()?; + // Move out of `post_lifetime_attrs` if present. O/w + // not first type param: parse attributes anew. let attrs = match post_lifetime_attrs.as_mut() { None => p.parse_outer_attributes()?, Some(attrs) => mem::replace(attrs, vec![]), @@ -4315,6 +4324,12 @@ impl<'a> Parser<'a> { } Ok(ty_param) })?; + if let Some(attrs) = post_lifetime_attrs { + if !attrs.is_empty() { + self.span_err(attrs[0].span, + "trailing attribute after lifetime parameters"); + } + } Ok(ast::Generics { lifetimes: lifetime_defs, ty_params: ty_params, diff --git a/src/test/compile-fail/attrs-with-no-formal-in-generics-1.rs b/src/test/compile-fail/attrs-with-no-formal-in-generics-1.rs new file mode 100644 index 0000000000000..53e287cda208a --- /dev/null +++ b/src/test/compile-fail/attrs-with-no-formal-in-generics-1.rs @@ -0,0 +1,26 @@ +// 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. + +// This test checks variations on `<#[attr] 'a, #[oops]>`, where +// `#[oops]` is left dangling (that is, it is unattached, with no +// formal binding following it). + +#![feature(generic_param_attrs, rustc_attrs)] +#![allow(dead_code)] + +struct RefIntPair<'a, 'b>(&'a u32, &'b u32); + +impl<#[rustc_1] 'a, 'b, #[oops]> RefIntPair<'a, 'b> { + //~^ ERROR trailing attribute after lifetime parameters +} + +fn main() { + +} diff --git a/src/test/compile-fail/attrs-with-no-formal-in-generics-2.rs b/src/test/compile-fail/attrs-with-no-formal-in-generics-2.rs new file mode 100644 index 0000000000000..a38a7bfb93785 --- /dev/null +++ b/src/test/compile-fail/attrs-with-no-formal-in-generics-2.rs @@ -0,0 +1,26 @@ +// 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. + +// This test checks variations on `<#[attr] 'a, #[oops]>`, where +// `#[oops]` is left dangling (that is, it is unattached, with no +// formal binding following it). + +#![feature(generic_param_attrs, rustc_attrs)] +#![allow(dead_code)] + +struct RefAny<'a, T>(&'a T); + +impl<#[rustc_1] 'a, #[rustc_2] T, #[oops]> RefAny<'a, T> { + //~^ ERROR expected identifier, found `>` +} + +fn main() { + +} diff --git a/src/test/compile-fail/attrs-with-no-formal-in-generics-3.rs b/src/test/compile-fail/attrs-with-no-formal-in-generics-3.rs new file mode 100644 index 0000000000000..e7d5b94d24226 --- /dev/null +++ b/src/test/compile-fail/attrs-with-no-formal-in-generics-3.rs @@ -0,0 +1,26 @@ +// 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. + +// This test checks variations on `<#[attr] 'a, #[oops]>`, where +// `#[oops]` is left dangling (that is, it is unattached, with no +// formal binding following it). + +struct RefIntPair<'a, 'b>(&'a u32, &'b u32); + +fn hof_lt(_: Q) + where Q: for <#[rustc_1] 'a, 'b, #[oops]> Fn(RefIntPair<'a,'b>) -> &'b u32 + //~^ ERROR trailing attribute after lifetime parameters +{ + +} + +fn main() { + +} From 69c3d0add4a35d0a643cbdec2d91fc28808618b0 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Tue, 20 Sep 2016 02:21:48 +0200 Subject: [PATCH 5/9] Remove unused `TypeError` variants These weren't flagged by the lint because they were still technically created somewhere... if you created them before, somehow. --- src/librustc/ty/error.rs | 27 --------------------------- src/librustc/ty/structural_impls.rs | 7 ------- 2 files changed, 34 deletions(-) diff --git a/src/librustc/ty/error.rs b/src/librustc/ty/error.rs index 001f47af68c3b..9b345c2d02329 100644 --- a/src/librustc/ty/error.rs +++ b/src/librustc/ty/error.rs @@ -33,13 +33,8 @@ pub enum TypeError<'tcx> { UnsafetyMismatch(ExpectedFound), AbiMismatch(ExpectedFound), Mutability, - BoxMutability, - PtrMutability, - RefMutability, - VecMutability, TupleSize(ExpectedFound), FixedArraySize(ExpectedFound), - TyParamSize(ExpectedFound), ArgCount, RegionsDoesNotOutlive(&'tcx Region, &'tcx Region), RegionsNotSame(&'tcx Region, &'tcx Region), @@ -47,14 +42,12 @@ pub enum TypeError<'tcx> { RegionsInsufficientlyPolymorphic(BoundRegion, &'tcx Region), RegionsOverlyPolymorphic(BoundRegion, &'tcx Region), Sorts(ExpectedFound>), - IntegerAsChar, IntMismatch(ExpectedFound), FloatMismatch(ExpectedFound), Traits(ExpectedFound), BuiltinBoundsMismatch(ExpectedFound), VariadicMismatch(ExpectedFound), CyclicTy, - ConvergenceMismatch(ExpectedFound), ProjectionNameMismatched(ExpectedFound), ProjectionBoundsLength(ExpectedFound), TyParamDefaultMismatch(ExpectedFound>) @@ -99,18 +92,6 @@ impl<'tcx> fmt::Display for TypeError<'tcx> { values.found) } Mutability => write!(f, "types differ in mutability"), - BoxMutability => { - write!(f, "boxed types differ in mutability") - } - VecMutability => write!(f, "vectors differ in mutability"), - PtrMutability => write!(f, "pointers differ in mutability"), - RefMutability => write!(f, "references differ in mutability"), - TyParamSize(values) => { - write!(f, "expected a type with {} type params, \ - found one with {} type params", - values.expected, - values.found) - } FixedArraySize(values) => { write!(f, "expected an array with a fixed size of {} elements, \ found one with {} elements", @@ -167,9 +148,6 @@ impl<'tcx> fmt::Display for TypeError<'tcx> { values.found) } } - IntegerAsChar => { - write!(f, "expected an integral type, found `char`") - } IntMismatch(ref values) => { write!(f, "expected `{:?}`, found `{:?}`", values.expected, @@ -185,11 +163,6 @@ impl<'tcx> fmt::Display for TypeError<'tcx> { if values.expected { "variadic" } else { "non-variadic" }, if values.found { "variadic" } else { "non-variadic" }) } - ConvergenceMismatch(ref values) => { - write!(f, "expected {} fn, found {} function", - if values.expected { "converging" } else { "diverging" }, - if values.found { "converging" } else { "diverging" }) - } ProjectionNameMismatched(ref values) => { write!(f, "expected {}, found {}", values.expected, diff --git a/src/librustc/ty/structural_impls.rs b/src/librustc/ty/structural_impls.rs index 5a87ea1473d98..abd5cb51f39ba 100644 --- a/src/librustc/ty/structural_impls.rs +++ b/src/librustc/ty/structural_impls.rs @@ -296,13 +296,8 @@ impl<'a, 'tcx> Lift<'tcx> for ty::error::TypeError<'a> { UnsafetyMismatch(x) => UnsafetyMismatch(x), AbiMismatch(x) => AbiMismatch(x), Mutability => Mutability, - BoxMutability => BoxMutability, - PtrMutability => PtrMutability, - RefMutability => RefMutability, - VecMutability => VecMutability, TupleSize(x) => TupleSize(x), FixedArraySize(x) => FixedArraySize(x), - TyParamSize(x) => TyParamSize(x), ArgCount => ArgCount, RegionsDoesNotOutlive(a, b) => { return tcx.lift(&(a, b)).map(|(a, b)| RegionsDoesNotOutlive(a, b)) @@ -319,14 +314,12 @@ impl<'a, 'tcx> Lift<'tcx> for ty::error::TypeError<'a> { RegionsOverlyPolymorphic(a, b) => { return tcx.lift(&b).map(|b| RegionsOverlyPolymorphic(a, b)) } - IntegerAsChar => IntegerAsChar, IntMismatch(x) => IntMismatch(x), FloatMismatch(x) => FloatMismatch(x), Traits(x) => Traits(x), BuiltinBoundsMismatch(x) => BuiltinBoundsMismatch(x), VariadicMismatch(x) => VariadicMismatch(x), CyclicTy => CyclicTy, - ConvergenceMismatch(x) => ConvergenceMismatch(x), ProjectionNameMismatched(x) => ProjectionNameMismatched(x), ProjectionBoundsLength(x) => ProjectionBoundsLength(x), From cf0b7bdd0c2920fcf77da6608d4829945a110b7e Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Tue, 20 Sep 2016 02:14:46 +0200 Subject: [PATCH 6/9] Call arrays "arrays" instead of "vecs" internally --- src/librustc/cfg/construct.rs | 4 ++-- src/librustc/hir/intravisit.rs | 8 ++++---- src/librustc/hir/lowering.rs | 8 ++++---- src/librustc/hir/map/def_collector.rs | 2 +- src/librustc/hir/mod.rs | 14 +++++++------- src/librustc/hir/pat_util.rs | 2 +- src/librustc/hir/print.rs | 8 ++++---- src/librustc/infer/error_reporting.rs | 10 +++++----- src/librustc/middle/expr_use_visitor.rs | 2 +- src/librustc/middle/liveness.rs | 6 +++--- src/librustc/middle/mem_categorization.rs | 4 ++-- src/librustc/middle/region.rs | 4 ++-- src/librustc/mir/repr.rs | 12 +++++------- src/librustc/mir/tcx.rs | 2 +- src/librustc/mir/visit.rs | 2 +- src/librustc/ty/fast_reject.rs | 4 ++-- src/librustc/ty/mod.rs | 2 +- src/librustc_const_eval/check_match.rs | 10 +++++----- src/librustc_const_eval/eval.rs | 8 ++++---- .../calculate_svh/svh_visitor.rs | 4 ++-- src/librustc_mir/build/expr/as_rvalue.rs | 2 +- src/librustc_mir/hair/cx/expr.rs | 2 +- src/librustc_mir/hair/cx/pattern.rs | 2 +- src/librustc_mir/mir_map.rs | 2 +- src/librustc_passes/consts.rs | 2 +- src/librustc_trans/mir/constant.rs | 2 +- src/librustc_typeck/astconv.rs | 4 ++-- src/librustc_typeck/check/_match.rs | 2 +- src/librustc_typeck/check/mod.rs | 8 ++++---- src/librustc_typeck/check/writeback.rs | 2 +- src/librustdoc/clean/mod.rs | 6 +++--- 31 files changed, 74 insertions(+), 76 deletions(-) diff --git a/src/librustc/cfg/construct.rs b/src/librustc/cfg/construct.rs index 25a73226473b7..50d4cbc982e97 100644 --- a/src/librustc/cfg/construct.rs +++ b/src/librustc/cfg/construct.rs @@ -126,7 +126,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> { self.add_ast_node(pat.id, &[pats_exit]) } - PatKind::Vec(ref pre, ref vec, ref post) => { + PatKind::Slice(ref pre, ref vec, ref post) => { let pre_exit = self.pats_all(pre.iter(), pred); let vec_exit = self.pats_all(vec.iter(), pre_exit); let post_exit = self.pats_all(post.iter(), vec_exit); @@ -298,7 +298,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> { self.add_unreachable_node() } - hir::ExprVec(ref elems) => { + hir::ExprArray(ref elems) => { self.straightline(expr, pred, elems.iter().map(|e| &**e)) } diff --git a/src/librustc/hir/intravisit.rs b/src/librustc/hir/intravisit.rs index 726e4e53e231c..b1771f52da2c6 100644 --- a/src/librustc/hir/intravisit.rs +++ b/src/librustc/hir/intravisit.rs @@ -394,7 +394,7 @@ pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty) { visitor.visit_id(typ.id); match typ.node { - TyVec(ref ty) => { + TySlice(ref ty) => { visitor.visit_ty(ty) } TyPtr(ref mutable_type) => { @@ -422,7 +422,7 @@ pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty) { visitor.visit_ty(ty); walk_list!(visitor, visit_ty_param_bound, bounds); } - TyFixedLengthVec(ref ty, ref expression) => { + TyArray(ref ty, ref expression) => { visitor.visit_ty(ty); visitor.visit_expr(expression) } @@ -520,7 +520,7 @@ pub fn walk_pat<'v, V: Visitor<'v>>(visitor: &mut V, pattern: &'v Pat) { visitor.visit_expr(upper_bound) } PatKind::Wild => (), - PatKind::Vec(ref prepatterns, ref slice_pattern, ref postpatterns) => { + PatKind::Slice(ref prepatterns, ref slice_pattern, ref postpatterns) => { walk_list!(visitor, visit_pat, prepatterns); walk_list!(visitor, visit_pat, slice_pattern); walk_list!(visitor, visit_pat, postpatterns); @@ -749,7 +749,7 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) { ExprBox(ref subexpression) => { visitor.visit_expr(subexpression) } - ExprVec(ref subexpressions) => { + ExprArray(ref subexpressions) => { walk_list!(visitor, visit_expr, subexpressions); } ExprRepeat(ref element, ref count) => { diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index 29dedeeeb03e6..30a34e8a53b1a 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -227,7 +227,7 @@ impl<'a> LoweringContext<'a> { id: t.id, node: match t.node { Infer | ImplicitSelf => hir::TyInfer, - Vec(ref ty) => hir::TyVec(self.lower_ty(ty)), + Vec(ref ty) => hir::TySlice(self.lower_ty(ty)), Ptr(ref mt) => hir::TyPtr(self.lower_mt(mt)), Rptr(ref region, ref mt) => { hir::TyRptr(self.lower_opt_lifetime(region), self.lower_mt(mt)) @@ -258,7 +258,7 @@ impl<'a> LoweringContext<'a> { hir::TyObjectSum(self.lower_ty(ty), self.lower_bounds(bounds)) } FixedLengthVec(ref ty, ref e) => { - hir::TyFixedLengthVec(self.lower_ty(ty), self.lower_expr(e)) + hir::TyArray(self.lower_ty(ty), self.lower_expr(e)) } Typeof(ref expr) => { hir::TyTypeof(self.lower_expr(expr)) @@ -892,7 +892,7 @@ impl<'a> LoweringContext<'a> { hir::PatKind::Range(self.lower_expr(e1), self.lower_expr(e2)) } PatKind::Vec(ref before, ref slice, ref after) => { - hir::PatKind::Vec(before.iter().map(|x| self.lower_pat(x)).collect(), + hir::PatKind::Slice(before.iter().map(|x| self.lower_pat(x)).collect(), slice.as_ref().map(|x| self.lower_pat(x)), after.iter().map(|x| self.lower_pat(x)).collect()) } @@ -1031,7 +1031,7 @@ impl<'a> LoweringContext<'a> { } ExprKind::Vec(ref exprs) => { - hir::ExprVec(exprs.iter().map(|x| self.lower_expr(x)).collect()) + hir::ExprArray(exprs.iter().map(|x| self.lower_expr(x)).collect()) } ExprKind::Repeat(ref expr, ref count) => { let expr = self.lower_expr(expr); diff --git a/src/librustc/hir/map/def_collector.rs b/src/librustc/hir/map/def_collector.rs index c0f38061a0d6d..8959c8153296a 100644 --- a/src/librustc/hir/map/def_collector.rs +++ b/src/librustc/hir/map/def_collector.rs @@ -448,7 +448,7 @@ impl<'ast> intravisit::Visitor<'ast> for DefCollector<'ast> { } fn visit_ty(&mut self, ty: &'ast hir::Ty) { - if let hir::TyFixedLengthVec(_, ref length) = ty.node { + if let hir::TyArray(_, ref length) = ty.node { self.visit_hir_const_integer(length); } if let hir::TyImplTrait(..) = ty.node { diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index 0cfdbae1a50b0..f64b0e9c7342c 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -478,7 +478,7 @@ impl Pat { PatKind::Box(ref s) | PatKind::Ref(ref s, _) => { s.walk_(it) } - PatKind::Vec(ref before, ref slice, ref after) => { + PatKind::Slice(ref before, ref slice, ref after) => { before.iter().all(|p| p.walk_(it)) && slice.iter().all(|p| p.walk_(it)) && after.iter().all(|p| p.walk_(it)) @@ -554,8 +554,8 @@ pub enum PatKind { /// A range pattern, e.g. `1...2` Range(P, P), /// `[a, b, ..i, y, z]` is represented as: - /// `PatKind::Vec(box [a, b], Some(i), box [y, z])` - Vec(HirVec>, Option>, HirVec>), + /// `PatKind::Slice(box [a, b], Some(i), box [y, z])` + Slice(HirVec>, Option>, HirVec>), } #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)] @@ -826,7 +826,7 @@ pub enum Expr_ { /// A `box x` expression. ExprBox(P), /// An array (`[a, b, c, d]`) - ExprVec(HirVec>), + ExprArray(HirVec>), /// A function call /// /// The first field resolves to the function itself (usually an `ExprPath`), @@ -1080,10 +1080,10 @@ pub struct BareFnTy { #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] /// The different kinds of types recognized by the compiler pub enum Ty_ { - /// A variable length array (`[T]`) - TyVec(P), + /// A variable length slice (`[T]`) + TySlice(P), /// A fixed length array (`[T; n]`) - TyFixedLengthVec(P, P), + TyArray(P, P), /// A raw pointer (`*const T` or `*mut T`) TyPtr(MutTy), /// A reference (`&'a T` or `&'a mut T`) diff --git a/src/librustc/hir/pat_util.rs b/src/librustc/hir/pat_util.rs index dec41fdfc3b50..505d126db7f4f 100644 --- a/src/librustc/hir/pat_util.rs +++ b/src/librustc/hir/pat_util.rs @@ -62,7 +62,7 @@ pub fn pat_is_refutable(dm: &DefMap, pat: &hir::Pat) -> bool { _ => false } } - PatKind::Vec(..) => true, + PatKind::Slice(..) => true, _ => false } } diff --git a/src/librustc/hir/print.rs b/src/librustc/hir/print.rs index eebc8fa9e5d5d..90b92beb7a7fb 100644 --- a/src/librustc/hir/print.rs +++ b/src/librustc/hir/print.rs @@ -486,7 +486,7 @@ impl<'a> State<'a> { self.maybe_print_comment(ty.span.lo)?; self.ibox(0)?; match ty.node { - hir::TyVec(ref ty) => { + hir::TySlice(ref ty) => { word(&mut self.s, "[")?; self.print_type(&ty)?; word(&mut self.s, "]")?; @@ -543,7 +543,7 @@ impl<'a> State<'a> { hir::TyImplTrait(ref bounds) => { self.print_bounds("impl ", &bounds[..])?; } - hir::TyFixedLengthVec(ref ty, ref v) => { + hir::TyArray(ref ty, ref v) => { word(&mut self.s, "[")?; self.print_type(&ty)?; word(&mut self.s, "; ")?; @@ -1319,7 +1319,7 @@ impl<'a> State<'a> { self.word_space("box")?; self.print_expr(expr)?; } - hir::ExprVec(ref exprs) => { + hir::ExprArray(ref exprs) => { self.print_expr_vec(&exprs[..])?; } hir::ExprRepeat(ref element, ref count) => { @@ -1829,7 +1829,7 @@ impl<'a> State<'a> { word(&mut self.s, "...")?; self.print_expr(&end)?; } - PatKind::Vec(ref before, ref slice, ref after) => { + PatKind::Slice(ref before, ref slice, ref after) => { word(&mut self.s, "[")?; self.commasep(Inconsistent, &before[..], |s, p| s.print_pat(&p))?; if let Some(ref p) = *slice { diff --git a/src/librustc/infer/error_reporting.rs b/src/librustc/infer/error_reporting.rs index 2792968d427aa..3f216d6916851 100644 --- a/src/librustc/infer/error_reporting.rs +++ b/src/librustc/infer/error_reporting.rs @@ -1433,8 +1433,8 @@ impl<'a, 'gcx, 'tcx> Rebuilder<'a, 'gcx, 'tcx> { hir::TyPtr(ref mut_ty) => { ty_queue.push(&mut_ty.ty); } - hir::TyVec(ref ty) | - hir::TyFixedLengthVec(ref ty, _) => { + hir::TySlice(ref ty) | + hir::TyArray(ref ty, _) => { ty_queue.push(&ty); } hir::TyTup(ref tys) => ty_queue.extend(tys.iter().map(|ty| &**ty)), @@ -1469,9 +1469,9 @@ impl<'a, 'gcx, 'tcx> Rebuilder<'a, 'gcx, 'tcx> { ty: build_to(mut_ty.ty, to), }) } - hir::TyVec(ty) => hir::TyVec(build_to(ty, to)), - hir::TyFixedLengthVec(ty, e) => { - hir::TyFixedLengthVec(build_to(ty, to), e) + hir::TySlice(ty) => hir::TySlice(build_to(ty, to)), + hir::TyArray(ty, e) => { + hir::TyArray(build_to(ty, to), e) } hir::TyTup(tys) => { hir::TyTup(tys.into_iter().map(|ty| build_to(ty, to)).collect()) diff --git a/src/librustc/middle/expr_use_visitor.rs b/src/librustc/middle/expr_use_visitor.rs index 5b5c3da8f05b2..d7392338d5ed9 100644 --- a/src/librustc/middle/expr_use_visitor.rs +++ b/src/librustc/middle/expr_use_visitor.rs @@ -442,7 +442,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> { } } - hir::ExprVec(ref exprs) => { + hir::ExprArray(ref exprs) => { self.consume_exprs(exprs); } diff --git a/src/librustc/middle/liveness.rs b/src/librustc/middle/liveness.rs index db9dd82d492d3..79396b9ca4dab 100644 --- a/src/librustc/middle/liveness.rs +++ b/src/librustc/middle/liveness.rs @@ -490,7 +490,7 @@ fn visit_expr(ir: &mut IrMaps, expr: &Expr) { // otherwise, live nodes are not required: hir::ExprIndex(..) | hir::ExprField(..) | hir::ExprTupField(..) | - hir::ExprVec(..) | hir::ExprCall(..) | hir::ExprMethodCall(..) | + hir::ExprArray(..) | hir::ExprCall(..) | hir::ExprMethodCall(..) | hir::ExprTup(..) | hir::ExprBinary(..) | hir::ExprAddrOf(..) | hir::ExprCast(..) | hir::ExprUnary(..) | hir::ExprBreak(_) | hir::ExprAgain(_) | hir::ExprLit(_) | hir::ExprRet(..) | @@ -1095,7 +1095,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { // Uninteresting cases: just propagate in rev exec order - hir::ExprVec(ref exprs) => { + hir::ExprArray(ref exprs) => { self.propagate_through_exprs(&exprs[..], succ) } @@ -1436,7 +1436,7 @@ fn check_expr(this: &mut Liveness, expr: &Expr) { hir::ExprCall(..) | hir::ExprMethodCall(..) | hir::ExprIf(..) | hir::ExprMatch(..) | hir::ExprWhile(..) | hir::ExprLoop(..) | hir::ExprIndex(..) | hir::ExprField(..) | hir::ExprTupField(..) | - hir::ExprVec(..) | hir::ExprTup(..) | hir::ExprBinary(..) | + hir::ExprArray(..) | hir::ExprTup(..) | hir::ExprBinary(..) | hir::ExprCast(..) | hir::ExprUnary(..) | hir::ExprRet(..) | hir::ExprBreak(..) | hir::ExprAgain(..) | hir::ExprLit(_) | hir::ExprBlock(..) | hir::ExprAddrOf(..) | diff --git a/src/librustc/middle/mem_categorization.rs b/src/librustc/middle/mem_categorization.rs index 340a5ac8f87b7..c50e668a41794 100644 --- a/src/librustc/middle/mem_categorization.rs +++ b/src/librustc/middle/mem_categorization.rs @@ -503,7 +503,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> { hir::ExprClosure(..) | hir::ExprRet(..) | hir::ExprUnary(..) | hir::ExprMethodCall(..) | hir::ExprCast(..) | - hir::ExprVec(..) | hir::ExprTup(..) | hir::ExprIf(..) | + hir::ExprArray(..) | hir::ExprTup(..) | hir::ExprIf(..) | hir::ExprBinary(..) | hir::ExprWhile(..) | hir::ExprBlock(..) | hir::ExprLoop(..) | hir::ExprMatch(..) | hir::ExprLit(..) | hir::ExprBreak(..) | @@ -1155,7 +1155,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> { self.cat_pattern_(subcmt, &subpat, op)?; } - PatKind::Vec(ref before, ref slice, ref after) => { + PatKind::Slice(ref before, ref slice, ref after) => { let context = InteriorOffsetKind::Pattern; let elt_cmt = self.cat_index(pat, cmt, context)?; for before_pat in before { diff --git a/src/librustc/middle/region.rs b/src/librustc/middle/region.rs index 33110c61e8f8b..90b6cbad3d9ae 100644 --- a/src/librustc/middle/region.rs +++ b/src/librustc/middle/region.rs @@ -961,7 +961,7 @@ fn resolve_local(visitor: &mut RegionResolutionVisitor, local: &hir::Local) { field_pats.iter().any(|fp| is_binding_pat(&fp.node.pat)) } - PatKind::Vec(ref pats1, ref pats2, ref pats3) => { + PatKind::Slice(ref pats1, ref pats2, ref pats3) => { pats1.iter().any(|p| is_binding_pat(&p)) || pats2.iter().any(|p| is_binding_pat(&p)) || pats3.iter().any(|p| is_binding_pat(&p)) @@ -1012,7 +1012,7 @@ fn resolve_local(visitor: &mut RegionResolutionVisitor, local: &hir::Local) { visitor, &field.expr, blk_id); } } - hir::ExprVec(ref subexprs) | + hir::ExprArray(ref subexprs) | hir::ExprTup(ref subexprs) => { for subexpr in subexprs { record_rvalue_scope_if_borrow_expr( diff --git a/src/librustc/mir/repr.rs b/src/librustc/mir/repr.rs index 70b0b810c6c48..997d67506528d 100644 --- a/src/librustc/mir/repr.rs +++ b/src/librustc/mir/repr.rs @@ -1016,7 +1016,7 @@ pub enum CastKind { #[derive(Clone, Debug, PartialEq, Eq, RustcEncodable, RustcDecodable)] pub enum AggregateKind<'tcx> { - Vec, + Array, Tuple, /// The second field is variant number (discriminant), it's equal to 0 /// for struct and union expressions. The fourth field is active field @@ -1107,8 +1107,6 @@ impl<'tcx> Debug for Rvalue<'tcx> { } Aggregate(ref kind, ref lvs) => { - use self::AggregateKind::*; - fn fmt_tuple(fmt: &mut Formatter, lvs: &[Operand]) -> fmt::Result { let mut tuple_fmt = fmt.debug_tuple(""); for lv in lvs { @@ -1118,9 +1116,9 @@ impl<'tcx> Debug for Rvalue<'tcx> { } match *kind { - Vec => write!(fmt, "{:?}", lvs), + AggregateKind::Array => write!(fmt, "{:?}", lvs), - Tuple => { + AggregateKind::Tuple => { match lvs.len() { 0 => write!(fmt, "()"), 1 => write!(fmt, "({:?},)", lvs[0]), @@ -1128,7 +1126,7 @@ impl<'tcx> Debug for Rvalue<'tcx> { } } - Adt(adt_def, variant, substs, _) => { + AggregateKind::Adt(adt_def, variant, substs, _) => { let variant_def = &adt_def.variants[variant]; ppaux::parameterized(fmt, substs, variant_def.did, @@ -1147,7 +1145,7 @@ impl<'tcx> Debug for Rvalue<'tcx> { } } - Closure(def_id, _) => ty::tls::with(|tcx| { + AggregateKind::Closure(def_id, _) => ty::tls::with(|tcx| { if let Some(node_id) = tcx.map.as_local_node_id(def_id) { let name = format!("[closure@{:?}]", tcx.map.span(node_id)); let mut struct_fmt = fmt.debug_struct(&name); diff --git a/src/librustc/mir/tcx.rs b/src/librustc/mir/tcx.rs index 74ad6c602f6cd..41b2c49072751 100644 --- a/src/librustc/mir/tcx.rs +++ b/src/librustc/mir/tcx.rs @@ -175,7 +175,7 @@ impl<'tcx> Rvalue<'tcx> { } &Rvalue::Aggregate(ref ak, ref ops) => { match *ak { - AggregateKind::Vec => { + AggregateKind::Array => { if let Some(operand) = ops.get(0) { let ty = operand.ty(mir, tcx); Some(tcx.mk_array(ty, ops.len())) diff --git a/src/librustc/mir/visit.rs b/src/librustc/mir/visit.rs index 2c58d35973e73..eb098ef107ec3 100644 --- a/src/librustc/mir/visit.rs +++ b/src/librustc/mir/visit.rs @@ -531,7 +531,7 @@ macro_rules! make_mir_visitor { Rvalue::Aggregate(ref $($mutability)* kind, ref $($mutability)* operands) => { match *kind { - AggregateKind::Vec => { + AggregateKind::Array => { } AggregateKind::Tuple => { } diff --git a/src/librustc/ty/fast_reject.rs b/src/librustc/ty/fast_reject.rs index ee1544d2d996d..befc9533c387b 100644 --- a/src/librustc/ty/fast_reject.rs +++ b/src/librustc/ty/fast_reject.rs @@ -24,7 +24,7 @@ pub enum SimplifiedType { FloatSimplifiedType(ast::FloatTy), AdtSimplifiedType(DefId), StrSimplifiedType, - VecSimplifiedType, + ArraySimplifiedType, PtrSimplifiedType, NeverSimplifiedType, TupleSimplifiedType(usize), @@ -57,7 +57,7 @@ pub fn simplify_type<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>, ty::TyFloat(float_type) => Some(FloatSimplifiedType(float_type)), ty::TyAdt(def, _) => Some(AdtSimplifiedType(def.did)), ty::TyStr => Some(StrSimplifiedType), - ty::TyArray(..) | ty::TySlice(_) => Some(VecSimplifiedType), + ty::TyArray(..) | ty::TySlice(_) => Some(ArraySimplifiedType), ty::TyRawPtr(_) => Some(PtrSimplifiedType), ty::TyTrait(ref trait_info) => { Some(TraitSimplifiedType(trait_info.principal.def_id())) diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index 717b8923a1635..cc13299d43475 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -2228,7 +2228,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { hir::ExprClosure(..) | hir::ExprBlock(..) | hir::ExprRepeat(..) | - hir::ExprVec(..) | + hir::ExprArray(..) | hir::ExprBreak(..) | hir::ExprAgain(..) | hir::ExprRet(..) | diff --git a/src/librustc_const_eval/check_match.rs b/src/librustc_const_eval/check_match.rs index eb74936d8c905..4a6f12e8ba342 100644 --- a/src/librustc_const_eval/check_match.rs +++ b/src/librustc_const_eval/check_match.rs @@ -610,14 +610,14 @@ fn construct_witness<'a,'tcx>(cx: &MatchCheckCtxt<'a,'tcx>, ctor: &Constructor, ty::TySlice(_) => match ctor { &Slice(n) => { assert_eq!(pats_len, n); - PatKind::Vec(pats.collect(), None, hir::HirVec::new()) + PatKind::Slice(pats.collect(), None, hir::HirVec::new()) }, _ => unreachable!() }, ty::TyArray(_, len) => { assert_eq!(pats_len, len); - PatKind::Vec(pats.collect(), None, hir::HirVec::new()) + PatKind::Slice(pats.collect(), None, hir::HirVec::new()) } _ => { @@ -713,7 +713,7 @@ fn is_useful<'a, 'tcx>(cx: &MatchCheckCtxt<'a, 'tcx>, }; let max_slice_length = rows.iter().filter_map(|row| match row[0].0.node { - PatKind::Vec(ref before, _, ref after) => Some(before.len() + after.len()), + PatKind::Slice(ref before, _, ref after) => Some(before.len() + after.len()), _ => None }).max().map_or(0, |v| v + 1); @@ -812,7 +812,7 @@ fn pat_constructors(cx: &MatchCheckCtxt, p: &Pat, vec![ConstantValue(eval_const_expr(cx.tcx, &expr))], PatKind::Range(ref lo, ref hi) => vec![ConstantRange(eval_const_expr(cx.tcx, &lo), eval_const_expr(cx.tcx, &hi))], - PatKind::Vec(ref before, ref slice, ref after) => + PatKind::Slice(ref before, ref slice, ref after) => match left_ty.sty { ty::TyArray(..) => vec![Single], ty::TySlice(_) if slice.is_some() => { @@ -1001,7 +1001,7 @@ pub fn specialize<'a, 'b, 'tcx>( } } - PatKind::Vec(ref before, ref slice, ref after) => { + PatKind::Slice(ref before, ref slice, ref after) => { let pat_len = before.len() + after.len(); match *constructor { Single => { diff --git a/src/librustc_const_eval/eval.rs b/src/librustc_const_eval/eval.rs index 4ae3c7d37db8d..3bf936dc9960c 100644 --- a/src/librustc_const_eval/eval.rs +++ b/src/librustc_const_eval/eval.rs @@ -317,11 +317,11 @@ pub fn const_expr_to_pat<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, PatKind::Struct(path.clone(), field_pats, false) } - hir::ExprVec(ref exprs) => { + hir::ExprArray(ref exprs) => { let pats = exprs.iter() .map(|expr| const_expr_to_pat(tcx, &expr, pat_id, span)) .collect::>()?; - PatKind::Vec(pats, None, hir::HirVec::new()) + PatKind::Slice(pats, None, hir::HirVec::new()) } hir::ExprPath(_, ref path) => { @@ -898,7 +898,7 @@ pub fn eval_const_expr_partial<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, Array(_, n) if idx >= n => { signal!(e, IndexOutOfBounds { len: n, index: idx }) } - Array(v, n) => if let hir::ExprVec(ref v) = tcx.map.expect_expr(v).node { + Array(v, n) => if let hir::ExprArray(ref v) = tcx.map.expect_expr(v).node { assert_eq!(n as usize as u64, n); eval_const_expr_partial(tcx, &v[idx as usize], ty_hint, fn_args)? } else { @@ -925,7 +925,7 @@ pub fn eval_const_expr_partial<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, _ => signal!(e, IndexedNonVec), } } - hir::ExprVec(ref v) => Array(e.id, v.len() as u64), + hir::ExprArray(ref v) => Array(e.id, v.len() as u64), hir::ExprRepeat(_, ref n) => { let len_hint = ty_hint.checked_or(tcx.types.usize); Repeat( diff --git a/src/librustc_incremental/calculate_svh/svh_visitor.rs b/src/librustc_incremental/calculate_svh/svh_visitor.rs index 55fe5fc1e349a..d0ae83a9826c2 100644 --- a/src/librustc_incremental/calculate_svh/svh_visitor.rs +++ b/src/librustc_incremental/calculate_svh/svh_visitor.rs @@ -207,7 +207,7 @@ enum SawExprComponent<'a> { SawExprAgain(Option), SawExprBox, - SawExprVec, + SawExprArray, SawExprCall, SawExprMethodCall, SawExprTup, @@ -235,7 +235,7 @@ enum SawExprComponent<'a> { fn saw_expr<'a>(node: &'a Expr_) -> SawExprComponent<'a> { match *node { ExprBox(..) => SawExprBox, - ExprVec(..) => SawExprVec, + ExprArray(..) => SawExprArray, ExprCall(..) => SawExprCall, ExprMethodCall(..) => SawExprMethodCall, ExprTup(..) => SawExprTup, diff --git a/src/librustc_mir/build/expr/as_rvalue.rs b/src/librustc_mir/build/expr/as_rvalue.rs index a40571c5d8597..2123235ddc1d8 100644 --- a/src/librustc_mir/build/expr/as_rvalue.rs +++ b/src/librustc_mir/build/expr/as_rvalue.rs @@ -160,7 +160,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { .map(|f| unpack!(block = this.as_operand(block, f))) .collect(); - block.and(Rvalue::Aggregate(AggregateKind::Vec, fields)) + block.and(Rvalue::Aggregate(AggregateKind::Array, fields)) } ExprKind::Tuple { fields } => { // see (*) above // first process the set of fields diff --git a/src/librustc_mir/hair/cx/expr.rs b/src/librustc_mir/hair/cx/expr.rs index 6283ff2187ab8..2840538ae5b4f 100644 --- a/src/librustc_mir/hair/cx/expr.rs +++ b/src/librustc_mir/hair/cx/expr.rs @@ -613,7 +613,7 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>, value: value.to_ref(), value_extents: cx.tcx.region_maps.node_extent(value.id) }, - hir::ExprVec(ref fields) => + hir::ExprArray(ref fields) => ExprKind::Vec { fields: fields.to_ref() }, hir::ExprTup(ref fields) => ExprKind::Tuple { fields: fields.to_ref() }, diff --git a/src/librustc_mir/hair/cx/pattern.rs b/src/librustc_mir/hair/cx/pattern.rs index 7b8446b184fb3..8751b1dc03aab 100644 --- a/src/librustc_mir/hair/cx/pattern.rs +++ b/src/librustc_mir/hair/cx/pattern.rs @@ -113,7 +113,7 @@ impl<'patcx, 'cx, 'gcx, 'tcx> PatCx<'patcx, 'cx, 'gcx, 'tcx> { PatternKind::Deref { subpattern: self.to_pattern(subpattern) } } - PatKind::Vec(ref prefix, ref slice, ref suffix) => { + PatKind::Slice(ref prefix, ref slice, ref suffix) => { let ty = self.cx.tcx.node_id_to_type(pat.id); match ty.sty { ty::TyRef(_, mt) => diff --git a/src/librustc_mir/mir_map.rs b/src/librustc_mir/mir_map.rs index 5e92a057da382..2dcefcc12f6e5 100644 --- a/src/librustc_mir/mir_map.rs +++ b/src/librustc_mir/mir_map.rs @@ -202,7 +202,7 @@ impl<'a, 'tcx> Visitor<'tcx> for BuildMir<'a, 'tcx> { // Array lengths, i.e. [T; constant]. fn visit_ty(&mut self, ty: &'tcx hir::Ty) { - if let hir::TyFixedLengthVec(_, ref length) = ty.node { + if let hir::TyArray(_, ref length) = ty.node { self.build_const_integer(length); } intravisit::walk_ty(self, ty); diff --git a/src/librustc_passes/consts.rs b/src/librustc_passes/consts.rs index f919e42b6bd7d..1b86c84a05702 100644 --- a/src/librustc_passes/consts.rs +++ b/src/librustc_passes/consts.rs @@ -602,7 +602,7 @@ fn check_expr<'a, 'tcx>(v: &mut CheckCrateVisitor<'a, 'tcx>, e: &hir::Expr, node hir::ExprIndex(..) | hir::ExprField(..) | hir::ExprTupField(..) | - hir::ExprVec(_) | + hir::ExprArray(_) | hir::ExprType(..) | hir::ExprTup(..) => {} diff --git a/src/librustc_trans/mir/constant.rs b/src/librustc_trans/mir/constant.rs index b74d56ce368a9..e97d40102af64 100644 --- a/src/librustc_trans/mir/constant.rs +++ b/src/librustc_trans/mir/constant.rs @@ -572,7 +572,7 @@ impl<'a, 'tcx> MirConstContext<'a, 'tcx> { } match *kind { - mir::AggregateKind::Vec => { + mir::AggregateKind::Array => { self.const_array(dest_ty, &fields) } mir::AggregateKind::Adt(..) | diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index f5e289c33028e..2f6fe8d77d214 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -1623,7 +1623,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o { } let result_ty = match ast_ty.node { - hir::TyVec(ref ty) => { + hir::TySlice(ref ty) => { tcx.mk_slice(self.ast_ty_to_ty(rscope, &ty)) } hir::TyObjectSum(ref ty, ref bounds) => { @@ -1758,7 +1758,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o { ty } - hir::TyFixedLengthVec(ref ty, ref e) => { + hir::TyArray(ref ty, ref e) => { if let Ok(length) = eval_length(tcx.global_tcx(), &e, "array length") { tcx.mk_array(self.ast_ty_to_ty(rscope, &ty), length) } else { diff --git a/src/librustc_typeck/check/_match.rs b/src/librustc_typeck/check/_match.rs index de7ca479b0b66..da9c88a65186c 100644 --- a/src/librustc_typeck/check/_match.rs +++ b/src/librustc_typeck/check/_match.rs @@ -227,7 +227,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { tcx.types.err } } - PatKind::Vec(ref before, ref slice, ref after) => { + PatKind::Slice(ref before, ref slice, ref after) => { let expected_ty = self.structurally_resolved_type(pat.span, expected); let (inner_ty, slice_ty) = match expected_ty.sty { ty::TyArray(inner_ty, size) => { diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index ee00cb2f5a3e4..2ac2dab999bb0 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -450,7 +450,7 @@ impl<'a, 'tcx> Visitor<'tcx> for CheckItemTypesVisitor<'a, 'tcx> { fn visit_ty(&mut self, t: &'tcx hir::Ty) { match t.node { - hir::TyFixedLengthVec(_, ref expr) => { + hir::TyArray(_, ref expr) => { check_const_with_type(self.ccx, &expr, self.ccx.tcx.types.usize, expr.id); } _ => {} @@ -626,7 +626,7 @@ impl<'a, 'gcx, 'tcx> Visitor<'gcx> for GatherLocalsVisitor<'a, 'gcx, 'tcx> { // need to record the type for that node fn visit_ty(&mut self, t: &'gcx hir::Ty) { match t.node { - hir::TyFixedLengthVec(ref ty, ref count_expr) => { + hir::TyArray(ref ty, ref count_expr) => { self.visit_ty(&ty); self.fcx.check_expr_with_hint(&count_expr, self.fcx.tcx.types.usize); } @@ -3590,7 +3590,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { self.check_method_call(expr, name, &args[..], &tps[..], expected, lvalue_pref) } hir::ExprCast(ref e, ref t) => { - if let hir::TyFixedLengthVec(_, ref count_expr) = t.node { + if let hir::TyArray(_, ref count_expr) = t.node { self.check_expr_with_hint(&count_expr, tcx.types.usize); } @@ -3623,7 +3623,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { self.check_expr_eq_type(&e, typ); typ } - hir::ExprVec(ref args) => { + hir::ExprArray(ref args) => { let uty = expected.to_option(self).and_then(|uty| { match uty.sty { ty::TyArray(ty, _) | ty::TySlice(ty) => Some(ty), diff --git a/src/librustc_typeck/check/writeback.rs b/src/librustc_typeck/check/writeback.rs index 0b70d904c2654..8685f703a599c 100644 --- a/src/librustc_typeck/check/writeback.rs +++ b/src/librustc_typeck/check/writeback.rs @@ -247,7 +247,7 @@ impl<'cx, 'gcx, 'tcx, 'v> Visitor<'v> for WritebackCx<'cx, 'gcx, 'tcx> { fn visit_ty(&mut self, t: &hir::Ty) { match t.node { - hir::TyFixedLengthVec(ref ty, ref count_expr) => { + hir::TyArray(ref ty, ref count_expr) => { self.visit_ty(&ty); write_ty_to_tcx(self.fcx.ccx, count_expr.id, self.tcx().types.usize); } diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 0ae059509bd10..af482a940bc14 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1646,8 +1646,8 @@ impl Clean for hir::Ty { TyRptr(ref l, ref m) => BorrowedRef {lifetime: l.clean(cx), mutability: m.mutbl.clean(cx), type_: box m.ty.clean(cx)}, - TyVec(ref ty) => Vector(box ty.clean(cx)), - TyFixedLengthVec(ref ty, ref e) => { + TySlice(ref ty) => Vector(box ty.clean(cx)), + TyArray(ref ty, ref e) => { let n = if let Some(tcx) = cx.tcx_opt() { use rustc_const_math::{ConstInt, ConstUsize}; use rustc_const_eval::eval_const_expr; @@ -2699,7 +2699,7 @@ fn name_from_pat(p: &hir::Pat) -> String { }, PatKind::Range(..) => panic!("tried to get argument name from PatKind::Range, \ which is not allowed in function arguments"), - PatKind::Vec(ref begin, ref mid, ref end) => { + PatKind::Slice(ref begin, ref mid, ref end) => { let begin = begin.iter().map(|p| name_from_pat(&**p)); let mid = mid.as_ref().map(|p| format!("..{}", name_from_pat(&**p))).into_iter(); let end = end.iter().map(|p| name_from_pat(&**p)); From 48e5199de366ed2945d1103f0b6c8aa542604ebb Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Tue, 20 Sep 2016 16:54:24 +0200 Subject: [PATCH 7/9] libsyntax: clearer names for some AST parts This applies the HIR changes from the previous commits to the AST, and is thus a syntax-[breaking-change] Renames `PatKind::Vec` to `PatKind::Slice`, since these are called slice patterns, not vec patterns. Renames `TyKind::Vec`, which represents the type `[T]`, to `TyKind::Slice`. Renames `TyKind::FixedLengthVec` to `TyKind::Array`. --- src/librustc/hir/lowering.rs | 33 +++++++++++++-------------- src/librustc/hir/map/def_collector.rs | 2 +- src/libsyntax/ast.rs | 12 +++++----- src/libsyntax/diagnostics/plugin.rs | 2 +- src/libsyntax/feature_gate.rs | 4 ++-- src/libsyntax/fold.rs | 10 ++++---- src/libsyntax/parse/parser.rs | 6 ++--- src/libsyntax/print/pprust.rs | 6 ++--- src/libsyntax/test.rs | 2 +- src/libsyntax/visit.rs | 6 ++--- src/libsyntax_ext/format.rs | 2 +- 11 files changed, 42 insertions(+), 43 deletions(-) diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index 30a34e8a53b1a..a4f47d6990394 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -222,17 +222,16 @@ impl<'a> LoweringContext<'a> { } fn lower_ty(&mut self, t: &Ty) -> P { - use syntax::ast::TyKind::*; P(hir::Ty { id: t.id, node: match t.node { - Infer | ImplicitSelf => hir::TyInfer, - Vec(ref ty) => hir::TySlice(self.lower_ty(ty)), - Ptr(ref mt) => hir::TyPtr(self.lower_mt(mt)), - Rptr(ref region, ref mt) => { + TyKind::Infer | TyKind::ImplicitSelf => hir::TyInfer, + TyKind::Slice(ref ty) => hir::TySlice(self.lower_ty(ty)), + TyKind::Ptr(ref mt) => hir::TyPtr(self.lower_mt(mt)), + TyKind::Rptr(ref region, ref mt) => { hir::TyRptr(self.lower_opt_lifetime(region), self.lower_mt(mt)) } - BareFn(ref f) => { + TyKind::BareFn(ref f) => { hir::TyBareFn(P(hir::BareFnTy { lifetimes: self.lower_lifetime_defs(&f.lifetimes), unsafety: self.lower_unsafety(f.unsafety), @@ -240,12 +239,12 @@ impl<'a> LoweringContext<'a> { decl: self.lower_fn_decl(&f.decl), })) } - Never => hir::TyNever, - Tup(ref tys) => hir::TyTup(tys.iter().map(|ty| self.lower_ty(ty)).collect()), - Paren(ref ty) => { + TyKind::Never => hir::TyNever, + TyKind::Tup(ref tys) => hir::TyTup(tys.iter().map(|ty| self.lower_ty(ty)).collect()), + TyKind::Paren(ref ty) => { return self.lower_ty(ty); } - Path(ref qself, ref path) => { + TyKind::Path(ref qself, ref path) => { let qself = qself.as_ref().map(|&QSelf { ref ty, position }| { hir::QSelf { ty: self.lower_ty(ty), @@ -254,22 +253,22 @@ impl<'a> LoweringContext<'a> { }); hir::TyPath(qself, self.lower_path(path)) } - ObjectSum(ref ty, ref bounds) => { + TyKind::ObjectSum(ref ty, ref bounds) => { hir::TyObjectSum(self.lower_ty(ty), self.lower_bounds(bounds)) } - FixedLengthVec(ref ty, ref e) => { + TyKind::Array(ref ty, ref e) => { hir::TyArray(self.lower_ty(ty), self.lower_expr(e)) } - Typeof(ref expr) => { + TyKind::Typeof(ref expr) => { hir::TyTypeof(self.lower_expr(expr)) } - PolyTraitRef(ref bounds) => { + TyKind::PolyTraitRef(ref bounds) => { hir::TyPolyTraitRef(self.lower_bounds(bounds)) } - ImplTrait(ref bounds) => { + TyKind::ImplTrait(ref bounds) => { hir::TyImplTrait(self.lower_bounds(bounds)) } - Mac(_) => panic!("TyMac should have been expanded by now."), + TyKind::Mac(_) => panic!("TyMac should have been expanded by now."), }, span: t.span, }) @@ -891,7 +890,7 @@ impl<'a> LoweringContext<'a> { PatKind::Range(ref e1, ref e2) => { hir::PatKind::Range(self.lower_expr(e1), self.lower_expr(e2)) } - PatKind::Vec(ref before, ref slice, ref after) => { + PatKind::Slice(ref before, ref slice, ref after) => { hir::PatKind::Slice(before.iter().map(|x| self.lower_pat(x)).collect(), slice.as_ref().map(|x| self.lower_pat(x)), after.iter().map(|x| self.lower_pat(x)).collect()) diff --git a/src/librustc/hir/map/def_collector.rs b/src/librustc/hir/map/def_collector.rs index 8959c8153296a..49d889ff08dec 100644 --- a/src/librustc/hir/map/def_collector.rs +++ b/src/librustc/hir/map/def_collector.rs @@ -286,7 +286,7 @@ impl<'a> visit::Visitor for DefCollector<'a> { fn visit_ty(&mut self, ty: &Ty) { match ty.node { TyKind::Mac(..) => return self.visit_macro_invoc(ty.id, false), - TyKind::FixedLengthVec(_, ref length) => self.visit_ast_const_integer(length), + TyKind::Array(_, ref length) => self.visit_ast_const_integer(length), TyKind::ImplTrait(..) => { self.create_def(ty.id, DefPathData::ImplTrait); } diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index c18b36161dfcf..9364cec8dddaf 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -593,7 +593,7 @@ impl Pat { PatKind::Box(ref s) | PatKind::Ref(ref s, _) => { s.walk(it) } - PatKind::Vec(ref before, ref slice, ref after) => { + PatKind::Slice(ref before, ref slice, ref after) => { before.iter().all(|p| p.walk(it)) && slice.iter().all(|p| p.walk(it)) && after.iter().all(|p| p.walk(it)) @@ -669,8 +669,8 @@ pub enum PatKind { /// A range pattern, e.g. `1...2` Range(P, P), /// `[a, b, ..i, y, z]` is represented as: - /// `PatKind::Vec(box [a, b], Some(i), box [y, z])` - Vec(Vec>, Option>, Vec>), + /// `PatKind::Slice(box [a, b], Some(i), box [y, z])` + Slice(Vec>, Option>, Vec>), /// A macro pattern; pre-expansion Mac(Mac), } @@ -1431,10 +1431,10 @@ pub struct BareFnTy { /// The different kinds of types recognized by the compiler #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] pub enum TyKind { - /// A variable-length array (`[T]`) - Vec(P), + /// A variable-length slice (`[T]`) + Slice(P), /// A fixed length array (`[T; n]`) - FixedLengthVec(P, P), + Array(P, P), /// A raw pointer (`*const T` or `*mut T`) Ptr(MutTy), /// A reference (`&'a T` or `&'a mut T`) diff --git a/src/libsyntax/diagnostics/plugin.rs b/src/libsyntax/diagnostics/plugin.rs index 4e50299e836b3..81c8e0bdb8262 100644 --- a/src/libsyntax/diagnostics/plugin.rs +++ b/src/libsyntax/diagnostics/plugin.rs @@ -215,7 +215,7 @@ pub fn expand_build_diagnostic_array<'cx>(ecx: &'cx mut ExtCtxt, let ty = ecx.ty( span, - ast::TyKind::FixedLengthVec( + ast::TyKind::Array( ecx.ty( span, ast::TyKind::Tup(vec![ty_str.clone(), ty_str]) diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index b687e4f92be73..88835fc868aba 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -1082,14 +1082,14 @@ impl<'a> Visitor for PostExpansionVisitor<'a> { fn visit_pat(&mut self, pattern: &ast::Pat) { match pattern.node { - PatKind::Vec(_, Some(_), ref last) if !last.is_empty() => { + PatKind::Slice(_, Some(_), ref last) if !last.is_empty() => { gate_feature_post!(&self, advanced_slice_patterns, pattern.span, "multiple-element slice matches anywhere \ but at the end of a slice (e.g. \ `[0, ..xs, 0]`) are experimental") } - PatKind::Vec(..) => { + PatKind::Slice(..) => { gate_feature_post!(&self, slice_patterns, pattern.span, "slice pattern syntax is experimental"); diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index 36f273e1dbc29..05adfc430563b 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -356,7 +356,7 @@ pub fn noop_fold_ty(t: P, fld: &mut T) -> P { id: fld.new_id(id), node: match node { TyKind::Infer | TyKind::ImplicitSelf => node, - TyKind::Vec(ty) => TyKind::Vec(fld.fold_ty(ty)), + TyKind::Slice(ty) => TyKind::Slice(fld.fold_ty(ty)), TyKind::Ptr(mt) => TyKind::Ptr(fld.fold_mt(mt)), TyKind::Rptr(region, mt) => { TyKind::Rptr(fld.fold_opt_lifetime(region), fld.fold_mt(mt)) @@ -385,8 +385,8 @@ pub fn noop_fold_ty(t: P, fld: &mut T) -> P { TyKind::ObjectSum(fld.fold_ty(ty), fld.fold_bounds(bounds)) } - TyKind::FixedLengthVec(ty, e) => { - TyKind::FixedLengthVec(fld.fold_ty(ty), fld.fold_expr(e)) + TyKind::Array(ty, e) => { + TyKind::Array(fld.fold_ty(ty), fld.fold_expr(e)) } TyKind::Typeof(expr) => { TyKind::Typeof(fld.fold_expr(expr)) @@ -1092,8 +1092,8 @@ pub fn noop_fold_pat(p: P, folder: &mut T) -> P { PatKind::Range(e1, e2) => { PatKind::Range(folder.fold_expr(e1), folder.fold_expr(e2)) }, - PatKind::Vec(before, slice, after) => { - PatKind::Vec(before.move_map(|x| folder.fold_pat(x)), + PatKind::Slice(before, slice, after) => { + PatKind::Slice(before.move_map(|x| folder.fold_pat(x)), slice.map(|x| folder.fold_pat(x)), after.move_map(|x| folder.fold_pat(x))) } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index d5ed1d157e47a..de7baf04b54e2 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -1386,8 +1386,8 @@ impl<'a> Parser<'a> { // Parse the `; e` in `[ i32; e ]` // where `e` is a const expression let t = match self.maybe_parse_fixed_length_of_vec()? { - None => TyKind::Vec(t), - Some(suffix) => TyKind::FixedLengthVec(t, suffix) + None => TyKind::Slice(t), + Some(suffix) => TyKind::Array(t, suffix) }; self.expect(&token::CloseDelim(token::Bracket))?; t @@ -3587,7 +3587,7 @@ impl<'a> Parser<'a> { self.bump(); let (before, slice, after) = self.parse_pat_vec_elements()?; self.expect(&token::CloseDelim(token::Bracket))?; - pat = PatKind::Vec(before, slice, after); + pat = PatKind::Slice(before, slice, after); } // At this point, token != _, &, &&, (, [ _ => if self.eat_keyword(keywords::Mut) { diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 8563d27908db6..3c106970232cd 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -972,7 +972,7 @@ impl<'a> State<'a> { try!(self.maybe_print_comment(ty.span.lo)); try!(self.ibox(0)); match ty.node { - ast::TyKind::Vec(ref ty) => { + ast::TyKind::Slice(ref ty) => { try!(word(&mut self.s, "[")); try!(self.print_type(&ty)); try!(word(&mut self.s, "]")); @@ -1039,7 +1039,7 @@ impl<'a> State<'a> { ast::TyKind::ImplTrait(ref bounds) => { try!(self.print_bounds("impl ", &bounds[..])); } - ast::TyKind::FixedLengthVec(ref ty, ref v) => { + ast::TyKind::Array(ref ty, ref v) => { try!(word(&mut self.s, "[")); try!(self.print_type(&ty)); try!(word(&mut self.s, "; ")); @@ -2573,7 +2573,7 @@ impl<'a> State<'a> { try!(word(&mut self.s, "...")); try!(self.print_expr(&end)); } - PatKind::Vec(ref before, ref slice, ref after) => { + PatKind::Slice(ref before, ref slice, ref after) => { try!(word(&mut self.s, "[")); try!(self.commasep(Inconsistent, &before[..], diff --git a/src/libsyntax/test.rs b/src/libsyntax/test.rs index e4510520a55a4..2bc5447cccc2f 100644 --- a/src/libsyntax/test.rs +++ b/src/libsyntax/test.rs @@ -564,7 +564,7 @@ fn mk_tests(cx: &TestCtxt) -> P { let static_lt = ecx.lifetime(sp, keywords::StaticLifetime.name()); // &'static [self::test::TestDescAndFn] let static_type = ecx.ty_rptr(sp, - ecx.ty(sp, ast::TyKind::Vec(struct_type)), + ecx.ty(sp, ast::TyKind::Slice(struct_type)), Some(static_lt), ast::Mutability::Immutable); // static TESTS: $static_type = &[...]; diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index 57b06c40878fe..49f3a729f1673 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -313,7 +313,7 @@ pub fn walk_variant(visitor: &mut V, variant: &Variant, generics: &Generics, pub fn walk_ty(visitor: &mut V, typ: &Ty) { match typ.node { - TyKind::Vec(ref ty) | TyKind::Paren(ref ty) => { + TyKind::Slice(ref ty) | TyKind::Paren(ref ty) => { visitor.visit_ty(ty) } TyKind::Ptr(ref mutable_type) => { @@ -341,7 +341,7 @@ pub fn walk_ty(visitor: &mut V, typ: &Ty) { visitor.visit_ty(ty); walk_list!(visitor, visit_ty_param_bound, bounds); } - TyKind::FixedLengthVec(ref ty, ref expression) => { + TyKind::Array(ref ty, ref expression) => { visitor.visit_ty(ty); visitor.visit_expr(expression) } @@ -434,7 +434,7 @@ pub fn walk_pat(visitor: &mut V, pattern: &Pat) { visitor.visit_expr(upper_bound) } PatKind::Wild => (), - PatKind::Vec(ref prepatterns, ref slice_pattern, ref postpatterns) => { + PatKind::Slice(ref prepatterns, ref slice_pattern, ref postpatterns) => { walk_list!(visitor, visit_pat, prepatterns); walk_list!(visitor, visit_pat, slice_pattern); walk_list!(visitor, visit_pat, postpatterns); diff --git a/src/libsyntax_ext/format.rs b/src/libsyntax_ext/format.rs index 892ebcfa76129..de78f859f0f61 100644 --- a/src/libsyntax_ext/format.rs +++ b/src/libsyntax_ext/format.rs @@ -506,7 +506,7 @@ impl<'a, 'b> Context<'a, 'b> { -> P { let sp = piece_ty.span; let ty = ecx.ty_rptr(sp, - ecx.ty(sp, ast::TyKind::Vec(piece_ty)), + ecx.ty(sp, ast::TyKind::Slice(piece_ty)), Some(ecx.lifetime(sp, keywords::StaticLifetime.name())), ast::Mutability::Immutable); let slice = ecx.expr_vec_slice(sp, pieces); From e59756ee929a8831d2c943e5dd2d658fceb6df95 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Tue, 20 Sep 2016 20:18:35 +0200 Subject: [PATCH 8/9] Fix tidy --- src/librustc/hir/lowering.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index a4f47d6990394..dace486b277db 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -240,7 +240,9 @@ impl<'a> LoweringContext<'a> { })) } TyKind::Never => hir::TyNever, - TyKind::Tup(ref tys) => hir::TyTup(tys.iter().map(|ty| self.lower_ty(ty)).collect()), + TyKind::Tup(ref tys) => { + hir::TyTup(tys.iter().map(|ty| self.lower_ty(ty)).collect()) + } TyKind::Paren(ref ty) => { return self.lower_ty(ty); } From bc2b28387c7373d183d2eec6798521dcc4d51643 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Thu, 22 Sep 2016 12:35:55 +0200 Subject: [PATCH 9/9] Fix rebase fallout --- src/librustc_const_eval/check_match.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/librustc_const_eval/check_match.rs b/src/librustc_const_eval/check_match.rs index 4a6f12e8ba342..5178ef65cf6a4 100644 --- a/src/librustc_const_eval/check_match.rs +++ b/src/librustc_const_eval/check_match.rs @@ -536,10 +536,10 @@ impl<'a, 'tcx> StaticInliner<'a, 'tcx> { } PatKind::Box(inner) => PatKind::Box(self.fold_pat(inner)), PatKind::Ref(inner, mutbl) => PatKind::Ref(self.fold_pat(inner), mutbl), - PatKind::Vec(before, slice, after) => { - PatKind::Vec(before.move_map(|x| self.fold_pat(x)), - slice.map(|x| self.fold_pat(x)), - after.move_map(|x| self.fold_pat(x))) + PatKind::Slice(before, slice, after) => { + PatKind::Slice(before.move_map(|x| self.fold_pat(x)), + slice.map(|x| self.fold_pat(x)), + after.move_map(|x| self.fold_pat(x))) } PatKind::Wild | PatKind::Lit(_) |