From 76b3523ac07539af2508b401567c32c9f6113dc7 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Thu, 17 Mar 2016 00:43:36 +0530 Subject: [PATCH 1/2] Re-add double underscores in derive (fixes #32292) --- src/libsyntax_ext/deriving/cmp/ord.rs | 8 +-- src/libsyntax_ext/deriving/cmp/partial_ord.rs | 8 +-- src/libsyntax_ext/deriving/generic/mod.rs | 70 +++++++++---------- 3 files changed, 43 insertions(+), 43 deletions(-) diff --git a/src/libsyntax_ext/deriving/cmp/ord.rs b/src/libsyntax_ext/deriving/cmp/ord.rs index a7e156c5f6820..74706c470872a 100644 --- a/src/libsyntax_ext/deriving/cmp/ord.rs +++ b/src/libsyntax_ext/deriving/cmp/ord.rs @@ -64,7 +64,7 @@ pub fn ordering_collapsed(cx: &mut ExtCtxt, pub fn cs_cmp(cx: &mut ExtCtxt, span: Span, substr: &Substructure) -> P { - let test_id = cx.ident_of("cmp"); + let test_id = cx.ident_of("__cmp"); let equals_path = cx.path_global(span, cx.std_path(&["cmp", "Ordering", "Equal"])); @@ -79,9 +79,9 @@ pub fn cs_cmp(cx: &mut ExtCtxt, span: Span, ::std::cmp::Ordering::Equal => { ... } - cmp => cmp + __cmp => __cmp }, - cmp => cmp + __cmp => __cmp } */ cs_fold( @@ -91,7 +91,7 @@ pub fn cs_cmp(cx: &mut ExtCtxt, span: Span, |cx, span, old, self_f, other_fs| { // match new { // ::std::cmp::Ordering::Equal => old, - // cmp => cmp + // __cmp => __cmp // } let new = { diff --git a/src/libsyntax_ext/deriving/cmp/partial_ord.rs b/src/libsyntax_ext/deriving/cmp/partial_ord.rs index b3864a6c2e79e..c864ce0db5142 100644 --- a/src/libsyntax_ext/deriving/cmp/partial_ord.rs +++ b/src/libsyntax_ext/deriving/cmp/partial_ord.rs @@ -107,7 +107,7 @@ pub fn some_ordering_collapsed(cx: &mut ExtCtxt, pub fn cs_partial_cmp(cx: &mut ExtCtxt, span: Span, substr: &Substructure) -> P { - let test_id = cx.ident_of("cmp"); + let test_id = cx.ident_of("__cmp"); let ordering = cx.path_global(span, cx.std_path(&["cmp", "Ordering", "Equal"])); let ordering_expr = cx.expr_path(ordering.clone()); @@ -124,9 +124,9 @@ pub fn cs_partial_cmp(cx: &mut ExtCtxt, span: Span, ::std::option::Option::Some(::std::cmp::Ordering::Equal) => { ... } - cmp => cmp + __cmp => __cmp }, - cmp => cmp + __cmp => __cmp } */ cs_fold( @@ -136,7 +136,7 @@ pub fn cs_partial_cmp(cx: &mut ExtCtxt, span: Span, |cx, span, old, self_f, other_fs| { // match new { // Some(::std::cmp::Ordering::Equal) => old, - // cmp => cmp + // __cmp => __cmp // } let new = { diff --git a/src/libsyntax_ext/deriving/generic/mod.rs b/src/libsyntax_ext/deriving/generic/mod.rs index 58c84e6879598..ef7f455632c73 100644 --- a/src/libsyntax_ext/deriving/generic/mod.rs +++ b/src/libsyntax_ext/deriving/generic/mod.rs @@ -156,14 +156,14 @@ //! //! ```{.text} //! EnumNonMatchingCollapsed( -//! vec![, ], +//! vec![, ], //! &[, ], -//! &[, ]) +//! &[, ]) //! ``` //! //! It is the same for when the arguments are flipped to `C1 {x}` and //! `C0(a)`; the only difference is what the values of the identifiers -//! and will +//! and will //! be in the generated code. //! //! `EnumNonMatchingCollapsed` deliberately provides far less information @@ -843,7 +843,7 @@ impl<'a> MethodDef<'a> { for (i, ty) in self.args.iter().enumerate() { let ast_ty = ty.to_ty(cx, trait_.span, type_ident, generics); - let ident = cx.ident_of(&format!("arg_{}", i)); + let ident = cx.ident_of(&format!("__arg_{}", i)); arg_tys.push((ident, ast_ty)); let arg_expr = cx.expr_ident(trait_.span, ident); @@ -929,12 +929,12 @@ impl<'a> MethodDef<'a> { /// /// // equivalent to: /// impl PartialEq for A { - /// fn eq(&self, arg_1: &A) -> bool { + /// fn eq(&self, __arg_1: &A) -> bool { /// match *self { - /// A {x: ref self_0_0, y: ref self_0_1} => { - /// match *arg_1 { - /// A {x: ref self_1_0, y: ref self_1_1} => { - /// self_0_0.eq(self_1_0) && self_0_1.eq(self_1_1) + /// A {x: ref __self_0_0, y: ref __self_0_1} => { + /// match *__arg_1 { + /// A {x: ref __self_1_0, y: ref __self_1_1} => { + /// __self_0_0.eq(__self_1_0) && __self_0_1.eq(__self_1_1) /// } /// } /// } @@ -960,7 +960,7 @@ impl<'a> MethodDef<'a> { trait_.create_struct_pattern(cx, struct_path, struct_def, - &format!("self_{}", + &format!("__self_{}", i), ast::Mutability::Immutable); patterns.push(pat); @@ -1038,14 +1038,14 @@ impl<'a> MethodDef<'a> { /// // is equivalent to /// /// impl PartialEq for A { - /// fn eq(&self, arg_1: &A) -> ::bool { - /// match (&*self, &*arg_1) { + /// fn eq(&self, __arg_1: &A) -> ::bool { + /// match (&*self, &*__arg_1) { /// (&A1, &A1) => true, /// (&A2(ref self_0), - /// &A2(ref arg_1_0)) => (*self_0).eq(&(*arg_1_0)), + /// &A2(ref __arg_1_0)) => (*self_0).eq(&(*__arg_1_0)), /// _ => { - /// let self_vi = match *self { A1(..) => 0, A2(..) => 1 }; - /// let arg_1_vi = match *arg_1 { A1(..) => 0, A2(..) => 1 }; + /// let __self_vi = match *self { A1(..) => 0, A2(..) => 1 }; + /// let __arg_1_vi = match *__arg_1 { A1(..) => 0, A2(..) => 1 }; /// false /// } /// } @@ -1053,10 +1053,10 @@ impl<'a> MethodDef<'a> { /// } /// ``` /// - /// (Of course `self_vi` and `arg_1_vi` are unused for + /// (Of course `__self_vi` and `__arg_1_vi` are unused for /// `PartialEq`, and those subcomputations will hopefully be removed - /// as their results are unused. The point of `self_vi` and - /// `arg_1_vi` is for `PartialOrd`; see #15503.) + /// as their results are unused. The point of `__self_vi` and + /// `__arg_1_vi` is for `PartialOrd`; see #15503.) fn expand_enum_method_body<'b>(&self, cx: &mut ExtCtxt, trait_: &TraitDef<'b>, @@ -1087,14 +1087,14 @@ impl<'a> MethodDef<'a> { /// for each of the self-args, carried in precomputed variables. /// ```{.text} - /// let self0_vi = unsafe { + /// let __self0_vi = unsafe { /// std::intrinsics::discriminant_value(&self) } as i32; - /// let self1_vi = unsafe { + /// let __self1_vi = unsafe { /// std::intrinsics::discriminant_value(&arg1) } as i32; - /// let self2_vi = unsafe { + /// let __self2_vi = unsafe { /// std::intrinsics::discriminant_value(&arg2) } as i32; /// - /// if self0_vi == self1_vi && self0_vi == self2_vi && ... { + /// if __self0_vi == __self1_vi && __self0_vi == __self2_vi && ... { /// match (...) { /// (Variant1, Variant1, ...) => Body1 /// (Variant2, Variant2, ...) => Body2, @@ -1122,9 +1122,9 @@ impl<'a> MethodDef<'a> { let self_arg_names = self_args.iter().enumerate() .map(|(arg_count, _self_arg)| { if arg_count == 0 { - "self".to_string() + "__self".to_string() } else { - format!("arg_{}", arg_count) + format!("__arg_{}", arg_count) } }) .collect::>(); @@ -1261,17 +1261,17 @@ impl<'a> MethodDef<'a> { // with three Self args, builds three statements: // // ``` - // let self0_vi = unsafe { + // let __self0_vi = unsafe { // std::intrinsics::discriminant_value(&self) } as i32; - // let self1_vi = unsafe { + // let __self1_vi = unsafe { // std::intrinsics::discriminant_value(&arg1) } as i32; - // let self2_vi = unsafe { + // let __self2_vi = unsafe { // std::intrinsics::discriminant_value(&arg2) } as i32; // ``` let mut index_let_stmts: Vec = Vec::new(); //We also build an expression which checks whether all discriminants are equal - // discriminant_test = self0_vi == self1_vi && self0_vi == self2_vi && ... + // discriminant_test = __self0_vi == __self1_vi && __self0_vi == __self2_vi && ... let mut discriminant_test = cx.expr_bool(sp, true); let target_type_name = @@ -1321,7 +1321,7 @@ impl<'a> MethodDef<'a> { // down to desired l-values, but we cannot actually deref // them when they are fed as r-values into a tuple // expression; here add a layer of borrowing, turning - // `(*self, *arg_0, ...)` into `(&*self, &*arg_0, ...)`. + // `(*self, *__arg_0, ...)` into `(&*self, &*__arg_0, ...)`. let borrowed_self_args = self_args.move_map(|self_arg| cx.expr_addr_of(sp, self_arg)); let match_arg = cx.expr(sp, ast::ExprKind::Tup(borrowed_self_args)); @@ -1335,7 +1335,7 @@ impl<'a> MethodDef<'a> { // } // } // else { - // + // // } let all_match = cx.expr_match(sp, match_arg, match_arms); let arm_expr = cx.expr_if(sp, discriminant_test, all_match, Some(arm_expr)); @@ -1359,8 +1359,8 @@ impl<'a> MethodDef<'a> { // error-prone, since the catch-all as defined above would // generate code like this: // - // _ => { let self0 = match *self { }; - // let self1 = match *arg_0 { }; + // _ => { let __self0 = match *self { }; + // let __self1 = match *__arg_0 { }; // } // // Which is yields bindings for variables which type @@ -1399,7 +1399,7 @@ impl<'a> MethodDef<'a> { // down to desired l-values, but we cannot actually deref // them when they are fed as r-values into a tuple // expression; here add a layer of borrowing, turning - // `(*self, *arg_0, ...)` into `(&*self, &*arg_0, ...)`. + // `(*self, *__arg_0, ...)` into `(&*self, &*__arg_0, ...)`. let borrowed_self_args = self_args.move_map(|self_arg| cx.expr_addr_of(sp, self_arg)); let match_arg = cx.expr(sp, ast::ExprKind::Tup(borrowed_self_args)); cx.expr_match(sp, match_arg, match_arms) @@ -1613,8 +1613,8 @@ pub fn cs_fold(use_foldl: bool, /// process the collected results. i.e. /// /// ```ignore -/// f(cx, span, vec![self_1.method(arg_1_1, arg_2_1), -/// self_2.method(arg_1_2, arg_2_2)]) +/// f(cx, span, vec![self_1.method(__arg_1_1, __arg_2_1), +/// self_2.method(__arg_1_2, __arg_2_2)]) /// ``` #[inline] pub fn cs_same_method(f: F, From 52e064c39d1c20bb84aad72178a76c79c0c9b4c8 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Thu, 17 Mar 2016 01:23:02 +0530 Subject: [PATCH 2/2] Add test for silenced unused params in derive --- src/test/run-pass/issue-32292.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/test/run-pass/issue-32292.rs diff --git a/src/test/run-pass/issue-32292.rs b/src/test/run-pass/issue-32292.rs new file mode 100644 index 0000000000000..3995caa32bf17 --- /dev/null +++ b/src/test/run-pass/issue-32292.rs @@ -0,0 +1,18 @@ +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![deny(warnings)] + +#[derive(Hash, Ord, PartialOrd, Eq, PartialEq, Debug, Clone, Copy)] +struct Foo; + +fn main() { + let _ = Foo; +} \ No newline at end of file