Rollup merge of #20998 - estsauver:20984, r=steveklabnik
There are a large number of places that incorrectly refer to deriving in comments, instead of derives. If someone could look at src/etc/generate-deriving-span-tests.py, I'm not sure how those tests were passing before/if they were.
This commit is contained in:
commit
1d8b917811
@ -2451,7 +2451,7 @@ There are three different types of inline attributes:
|
|||||||
* `#[inline(always)]` asks the compiler to always perform an inline expansion.
|
* `#[inline(always)]` asks the compiler to always perform an inline expansion.
|
||||||
* `#[inline(never)]` asks the compiler to never perform an inline expansion.
|
* `#[inline(never)]` asks the compiler to never perform an inline expansion.
|
||||||
|
|
||||||
### Derive
|
### `derive`
|
||||||
|
|
||||||
The `derive` attribute allows certain traits to be automatically implemented
|
The `derive` attribute allows certain traits to be automatically implemented
|
||||||
for data structures. For example, the following will create an `impl` for the
|
for data structures. For example, the following will create an `impl` for the
|
||||||
|
@ -12,8 +12,8 @@
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
This script creates a pile of compile-fail tests check that all the
|
This script creates a pile of compile-fail tests check that all the
|
||||||
derivings have spans that point to the fields, rather than the
|
derives have spans that point to the fields, rather than the
|
||||||
#[deriving(...)] line.
|
#[derive(...)] line.
|
||||||
|
|
||||||
sample usage: src/etc/generate-deriving-span-tests.py
|
sample usage: src/etc/generate-deriving-span-tests.py
|
||||||
"""
|
"""
|
||||||
@ -46,7 +46,7 @@ fn main() {{}}
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
ENUM_STRING = """
|
ENUM_STRING = """
|
||||||
#[deriving({traits})]
|
#[derive({traits})]
|
||||||
enum Enum {{
|
enum Enum {{
|
||||||
A(
|
A(
|
||||||
Error {errors}
|
Error {errors}
|
||||||
@ -54,7 +54,7 @@ enum Enum {{
|
|||||||
}}
|
}}
|
||||||
"""
|
"""
|
||||||
ENUM_STRUCT_VARIANT_STRING = """
|
ENUM_STRUCT_VARIANT_STRING = """
|
||||||
#[deriving({traits})]
|
#[derive({traits})]
|
||||||
enum Enum {{
|
enum Enum {{
|
||||||
A {{
|
A {{
|
||||||
x: Error {errors}
|
x: Error {errors}
|
||||||
@ -62,13 +62,13 @@ enum Enum {{
|
|||||||
}}
|
}}
|
||||||
"""
|
"""
|
||||||
STRUCT_STRING = """
|
STRUCT_STRING = """
|
||||||
#[deriving({traits})]
|
#[derive({traits})]
|
||||||
struct Struct {{
|
struct Struct {{
|
||||||
x: Error {errors}
|
x: Error {errors}
|
||||||
}}
|
}}
|
||||||
"""
|
"""
|
||||||
STRUCT_TUPLE_STRING = """
|
STRUCT_TUPLE_STRING = """
|
||||||
#[deriving({traits})]
|
#[derive({traits})]
|
||||||
struct Struct(
|
struct Struct(
|
||||||
Error {errors}
|
Error {errors}
|
||||||
);
|
);
|
||||||
@ -80,14 +80,14 @@ def create_test_case(type, trait, super_traits, number_of_errors):
|
|||||||
string = [ENUM_STRING, ENUM_STRUCT_VARIANT_STRING, STRUCT_STRING, STRUCT_TUPLE_STRING][type]
|
string = [ENUM_STRING, ENUM_STRUCT_VARIANT_STRING, STRUCT_STRING, STRUCT_TUPLE_STRING][type]
|
||||||
all_traits = ','.join([trait] + super_traits)
|
all_traits = ','.join([trait] + super_traits)
|
||||||
super_traits = ','.join(super_traits)
|
super_traits = ','.join(super_traits)
|
||||||
error_deriving = '#[deriving(%s)]' % super_traits if super_traits else ''
|
error_deriving = '#[derive(%s)]' % super_traits if super_traits else ''
|
||||||
|
|
||||||
errors = '\n'.join('//~%s ERROR' % ('^' * n) for n in range(error_count))
|
errors = '\n'.join('//~%s ERROR' % ('^' * n) for n in range(error_count))
|
||||||
code = string.format(traits = all_traits, errors = errors)
|
code = string.format(traits = all_traits, errors = errors)
|
||||||
return TEMPLATE.format(year = YEAR, error_deriving=error_deriving, code = code)
|
return TEMPLATE.format(year = YEAR, error_deriving=error_deriving, code = code)
|
||||||
|
|
||||||
def write_file(name, string):
|
def write_file(name, string):
|
||||||
test_file = os.path.join(TEST_DIR, 'deriving-span-%s.rs' % name)
|
test_file = os.path.join(TEST_DIR, 'derives-span-%s.rs' % name)
|
||||||
|
|
||||||
# set write permission if file exists, so it can be changed
|
# set write permission if file exists, so it can be changed
|
||||||
if os.path.exists(test_file):
|
if os.path.exists(test_file):
|
||||||
|
@ -392,7 +392,7 @@ def emit_grapheme_module(f, grapheme_table, grapheme_cats):
|
|||||||
use core::slice;
|
use core::slice;
|
||||||
|
|
||||||
#[allow(non_camel_case_types)]
|
#[allow(non_camel_case_types)]
|
||||||
#[deriving(Clone)]
|
#[derive(Clone)]
|
||||||
pub enum GraphemeCat {
|
pub enum GraphemeCat {
|
||||||
""")
|
""")
|
||||||
for cat in grapheme_cats + ["Any"]:
|
for cat in grapheme_cats + ["Any"]:
|
||||||
|
@ -102,10 +102,10 @@ pub fn fixme_14344_be_sure_to_link_to_collections() {}
|
|||||||
mod std {
|
mod std {
|
||||||
pub use core::fmt; // necessary for panic!()
|
pub use core::fmt; // necessary for panic!()
|
||||||
pub use core::option; // necessary for panic!()
|
pub use core::option; // necessary for panic!()
|
||||||
pub use core::clone; // deriving(Clone)
|
pub use core::clone; // derive(Clone)
|
||||||
pub use core::cmp; // deriving(Eq, Ord, etc.)
|
pub use core::cmp; // derive(Eq, Ord, etc.)
|
||||||
pub use core::marker; // deriving(Copy)
|
pub use core::marker; // derive(Copy)
|
||||||
pub use core::hash; // deriving(Hash)
|
pub use core::hash; // derive(Hash)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -156,7 +156,7 @@ mod svh_visitor {
|
|||||||
StrictVersionHashVisitor { st: st }
|
StrictVersionHashVisitor { st: st }
|
||||||
}
|
}
|
||||||
|
|
||||||
// To off-load the bulk of the hash-computation on deriving(Hash),
|
// To off-load the bulk of the hash-computation on #[derive(Hash)],
|
||||||
// we define a set of enums corresponding to the content that our
|
// we define a set of enums corresponding to the content that our
|
||||||
// crate visitor will encounter as it traverses the ast.
|
// crate visitor will encounter as it traverses the ast.
|
||||||
//
|
//
|
||||||
|
@ -221,7 +221,7 @@
|
|||||||
//! - `fmt::Show` implementations should be implemented for **all** public types.
|
//! - `fmt::Show` implementations should be implemented for **all** public types.
|
||||||
//! Output will typically represent the internal state as faithfully as possible.
|
//! Output will typically represent the internal state as faithfully as possible.
|
||||||
//! The purpose of the `Show` trait is to facilitate debugging Rust code. In
|
//! The purpose of the `Show` trait is to facilitate debugging Rust code. In
|
||||||
//! most cases, using `#[deriving(Show)]` is sufficient and recommended.
|
//! most cases, using `#[derive(Show)]` is sufficient and recommended.
|
||||||
//!
|
//!
|
||||||
//! Some examples of the output from both traits:
|
//! Some examples of the output from both traits:
|
||||||
//!
|
//!
|
||||||
|
@ -80,11 +80,11 @@ fn cs_clone(
|
|||||||
EnumNonMatchingCollapsed (..) => {
|
EnumNonMatchingCollapsed (..) => {
|
||||||
cx.span_bug(trait_span,
|
cx.span_bug(trait_span,
|
||||||
&format!("non-matching enum variants in \
|
&format!("non-matching enum variants in \
|
||||||
`deriving({})`", name)[])
|
`derive({})`", name)[])
|
||||||
}
|
}
|
||||||
StaticEnum(..) | StaticStruct(..) => {
|
StaticEnum(..) | StaticStruct(..) => {
|
||||||
cx.span_bug(trait_span,
|
cx.span_bug(trait_span,
|
||||||
&format!("static method in `deriving({})`", name)[])
|
&format!("static method in `derive({})`", name)[])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,7 +101,7 @@ fn cs_clone(
|
|||||||
None => {
|
None => {
|
||||||
cx.span_bug(trait_span,
|
cx.span_bug(trait_span,
|
||||||
&format!("unnamed field in normal struct in \
|
&format!("unnamed field in normal struct in \
|
||||||
`deriving({})`", name)[])
|
`derive({})`", name)[])
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
cx.field_imm(field.span, ident, subcall(field))
|
cx.field_imm(field.span, ident, subcall(field))
|
||||||
|
@ -32,7 +32,7 @@ pub fn expand_deriving_eq<F>(cx: &mut ExtCtxt,
|
|||||||
|cx, span, subexpr, self_f, other_fs| {
|
|cx, span, subexpr, self_f, other_fs| {
|
||||||
let other_f = match other_fs {
|
let other_f = match other_fs {
|
||||||
[ref o_f] => o_f,
|
[ref o_f] => o_f,
|
||||||
_ => cx.span_bug(span, "not exactly 2 arguments in `deriving(PartialEq)`")
|
_ => cx.span_bug(span, "not exactly 2 arguments in `derive(PartialEq)`")
|
||||||
};
|
};
|
||||||
|
|
||||||
let eq = cx.expr_binary(span, ast::BiEq, self_f, other_f.clone());
|
let eq = cx.expr_binary(span, ast::BiEq, self_f, other_f.clone());
|
||||||
@ -49,7 +49,7 @@ pub fn expand_deriving_eq<F>(cx: &mut ExtCtxt,
|
|||||||
|cx, span, subexpr, self_f, other_fs| {
|
|cx, span, subexpr, self_f, other_fs| {
|
||||||
let other_f = match other_fs {
|
let other_f = match other_fs {
|
||||||
[ref o_f] => o_f,
|
[ref o_f] => o_f,
|
||||||
_ => cx.span_bug(span, "not exactly 2 arguments in `deriving(PartialEq)`")
|
_ => cx.span_bug(span, "not exactly 2 arguments in `derive(PartialEq)`")
|
||||||
};
|
};
|
||||||
|
|
||||||
let eq = cx.expr_binary(span, ast::BiNe, self_f, other_f.clone());
|
let eq = cx.expr_binary(span, ast::BiNe, self_f, other_f.clone());
|
||||||
|
@ -152,7 +152,7 @@ pub fn cs_partial_cmp(cx: &mut ExtCtxt, span: Span,
|
|||||||
let new = {
|
let new = {
|
||||||
let other_f = match other_fs {
|
let other_f = match other_fs {
|
||||||
[ref o_f] => o_f,
|
[ref o_f] => o_f,
|
||||||
_ => cx.span_bug(span, "not exactly 2 arguments in `deriving(PartialOrd)`"),
|
_ => cx.span_bug(span, "not exactly 2 arguments in `derive(PartialOrd)`"),
|
||||||
};
|
};
|
||||||
|
|
||||||
let args = vec![
|
let args = vec![
|
||||||
@ -176,7 +176,7 @@ pub fn cs_partial_cmp(cx: &mut ExtCtxt, span: Span,
|
|||||||
equals_expr.clone(),
|
equals_expr.clone(),
|
||||||
box |cx, span, (self_args, tag_tuple), _non_self_args| {
|
box |cx, span, (self_args, tag_tuple), _non_self_args| {
|
||||||
if self_args.len() != 2 {
|
if self_args.len() != 2 {
|
||||||
cx.span_bug(span, "not exactly 2 arguments in `deriving(PartialOrd)`")
|
cx.span_bug(span, "not exactly 2 arguments in `derive(PartialOrd)`")
|
||||||
} else {
|
} else {
|
||||||
some_ordering_collapsed(cx, span, PartialCmpOp, tag_tuple)
|
some_ordering_collapsed(cx, span, PartialCmpOp, tag_tuple)
|
||||||
}
|
}
|
||||||
@ -210,7 +210,7 @@ fn cs_op(less: bool, equal: bool, cx: &mut ExtCtxt,
|
|||||||
*/
|
*/
|
||||||
let other_f = match other_fs {
|
let other_f = match other_fs {
|
||||||
[ref o_f] => o_f,
|
[ref o_f] => o_f,
|
||||||
_ => cx.span_bug(span, "not exactly 2 arguments in `deriving(PartialOrd)`")
|
_ => cx.span_bug(span, "not exactly 2 arguments in `derive(PartialOrd)`")
|
||||||
};
|
};
|
||||||
|
|
||||||
let cmp = cx.expr_binary(span, op, self_f.clone(), other_f.clone());
|
let cmp = cx.expr_binary(span, op, self_f.clone(), other_f.clone());
|
||||||
@ -224,7 +224,7 @@ fn cs_op(less: bool, equal: bool, cx: &mut ExtCtxt,
|
|||||||
cx.expr_bool(span, equal),
|
cx.expr_bool(span, equal),
|
||||||
box |cx, span, (self_args, tag_tuple), _non_self_args| {
|
box |cx, span, (self_args, tag_tuple), _non_self_args| {
|
||||||
if self_args.len() != 2 {
|
if self_args.len() != 2 {
|
||||||
cx.span_bug(span, "not exactly 2 arguments in `deriving(PartialOrd)`")
|
cx.span_bug(span, "not exactly 2 arguments in `derive(PartialOrd)`")
|
||||||
} else {
|
} else {
|
||||||
let op = match (less, equal) {
|
let op = match (less, equal) {
|
||||||
(true, true) => LeOp, (true, false) => LtOp,
|
(true, true) => LeOp, (true, false) => LtOp,
|
||||||
|
@ -32,7 +32,7 @@ pub fn expand_deriving_totaleq<F>(cx: &mut ExtCtxt,
|
|||||||
let block = cx.block(span, stmts, None);
|
let block = cx.block(span, stmts, None);
|
||||||
cx.expr_block(block)
|
cx.expr_block(block)
|
||||||
},
|
},
|
||||||
box |cx, sp, _, _| cx.span_bug(sp, "non matching enums in deriving(Eq)?"),
|
box |cx, sp, _, _| cx.span_bug(sp, "non matching enums in derive(Eq)?"),
|
||||||
cx,
|
cx,
|
||||||
span,
|
span,
|
||||||
substr)
|
substr)
|
||||||
|
@ -108,7 +108,7 @@ pub fn cs_cmp(cx: &mut ExtCtxt, span: Span,
|
|||||||
let new = {
|
let new = {
|
||||||
let other_f = match other_fs {
|
let other_f = match other_fs {
|
||||||
[ref o_f] => o_f,
|
[ref o_f] => o_f,
|
||||||
_ => cx.span_bug(span, "not exactly 2 arguments in `deriving(PartialOrd)`"),
|
_ => cx.span_bug(span, "not exactly 2 arguments in `derive(PartialOrd)`"),
|
||||||
};
|
};
|
||||||
|
|
||||||
let args = vec![
|
let args = vec![
|
||||||
@ -132,7 +132,7 @@ pub fn cs_cmp(cx: &mut ExtCtxt, span: Span,
|
|||||||
cx.expr_path(equals_path.clone()),
|
cx.expr_path(equals_path.clone()),
|
||||||
box |cx, span, (self_args, tag_tuple), _non_self_args| {
|
box |cx, span, (self_args, tag_tuple), _non_self_args| {
|
||||||
if self_args.len() != 2 {
|
if self_args.len() != 2 {
|
||||||
cx.span_bug(span, "not exactly 2 arguments in `deriving(Ord)`")
|
cx.span_bug(span, "not exactly 2 arguments in `derives(Ord)`")
|
||||||
} else {
|
} else {
|
||||||
ordering_collapsed(cx, span, tag_tuple)
|
ordering_collapsed(cx, span, tag_tuple)
|
||||||
}
|
}
|
||||||
|
@ -173,7 +173,7 @@ fn decodable_substructure(cx: &mut ExtCtxt, trait_span: Span,
|
|||||||
cx.lambda_expr_1(trait_span, result, blkarg)
|
cx.lambda_expr_1(trait_span, result, blkarg)
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
_ => cx.bug("expected StaticEnum or StaticStruct in deriving(Decodable)")
|
_ => cx.bug("expected StaticEnum or StaticStruct in derive(Decodable)")
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,6 +81,6 @@ fn default_substructure(cx: &mut ExtCtxt, trait_span: Span, substr: &Substructur
|
|||||||
// let compilation continue
|
// let compilation continue
|
||||||
cx.expr_uint(trait_span, 0)
|
cx.expr_uint(trait_span, 0)
|
||||||
}
|
}
|
||||||
_ => cx.span_bug(trait_span, "Non-static method in `deriving(Default)`")
|
_ => cx.span_bug(trait_span, "Non-static method in `derive(Default)`")
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -276,6 +276,6 @@ fn encodable_substructure(cx: &mut ExtCtxt, trait_span: Span,
|
|||||||
cx.expr_block(cx.block(trait_span, vec!(me), Some(ret)))
|
cx.expr_block(cx.block(trait_span, vec!(me), Some(ret)))
|
||||||
}
|
}
|
||||||
|
|
||||||
_ => cx.bug("expected Struct or EnumMatching in deriving(Encodable)")
|
_ => cx.bug("expected Struct or EnumMatching in derive(Encodable)")
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -1191,7 +1191,7 @@ impl<'a> TraitDef<'a> {
|
|||||||
to_set.expn_id = cx.codemap().record_expansion(codemap::ExpnInfo {
|
to_set.expn_id = cx.codemap().record_expansion(codemap::ExpnInfo {
|
||||||
call_site: to_set,
|
call_site: to_set,
|
||||||
callee: codemap::NameAndSpan {
|
callee: codemap::NameAndSpan {
|
||||||
name: format!("deriving({})", trait_name),
|
name: format!("derive({})", trait_name),
|
||||||
format: codemap::MacroAttribute,
|
format: codemap::MacroAttribute,
|
||||||
span: Some(self.span)
|
span: Some(self.span)
|
||||||
}
|
}
|
||||||
|
@ -182,8 +182,8 @@ impl<'a> Ty<'a> {
|
|||||||
Literal(ref p) => {
|
Literal(ref p) => {
|
||||||
p.to_path(cx, span, self_ty, self_generics)
|
p.to_path(cx, span, self_ty, self_generics)
|
||||||
}
|
}
|
||||||
Ptr(..) => { cx.span_bug(span, "pointer in a path in generic `deriving`") }
|
Ptr(..) => { cx.span_bug(span, "pointer in a path in generic `derive`") }
|
||||||
Tuple(..) => { cx.span_bug(span, "tuple in a path in generic `deriving`") }
|
Tuple(..) => { cx.span_bug(span, "tuple in a path in generic `derive`") }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -74,7 +74,7 @@ pub fn expand_deriving_from_primitive<F>(cx: &mut ExtCtxt,
|
|||||||
fn cs_from(name: &str, cx: &mut ExtCtxt, trait_span: Span, substr: &Substructure) -> P<Expr> {
|
fn cs_from(name: &str, cx: &mut ExtCtxt, trait_span: Span, substr: &Substructure) -> P<Expr> {
|
||||||
let n = match substr.nonself_args {
|
let n = match substr.nonself_args {
|
||||||
[ref n] => n,
|
[ref n] => n,
|
||||||
_ => cx.span_bug(trait_span, "incorrect number of arguments in `deriving(FromPrimitive)`")
|
_ => cx.span_bug(trait_span, "incorrect number of arguments in `derive(FromPrimitive)`")
|
||||||
};
|
};
|
||||||
|
|
||||||
match *substr.fields {
|
match *substr.fields {
|
||||||
@ -144,6 +144,6 @@ fn cs_from(name: &str, cx: &mut ExtCtxt, trait_span: Span, substr: &Substructure
|
|||||||
|
|
||||||
cx.expr_match(trait_span, n.clone(), arms)
|
cx.expr_match(trait_span, n.clone(), arms)
|
||||||
}
|
}
|
||||||
_ => cx.span_bug(trait_span, "expected StaticEnum in deriving(FromPrimitive)")
|
_ => cx.span_bug(trait_span, "expected StaticEnum in derive(FromPrimitive)")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -57,7 +57,7 @@ pub fn expand_deriving_rand<F>(cx: &mut ExtCtxt,
|
|||||||
fn rand_substructure(cx: &mut ExtCtxt, trait_span: Span, substr: &Substructure) -> P<Expr> {
|
fn rand_substructure(cx: &mut ExtCtxt, trait_span: Span, substr: &Substructure) -> P<Expr> {
|
||||||
let rng = match substr.nonself_args {
|
let rng = match substr.nonself_args {
|
||||||
[ref rng] => rng,
|
[ref rng] => rng,
|
||||||
_ => cx.bug("Incorrect number of arguments to `rand` in `deriving(Rand)`")
|
_ => cx.bug("Incorrect number of arguments to `rand` in `derive(Rand)`")
|
||||||
};
|
};
|
||||||
let rand_ident = vec!(
|
let rand_ident = vec!(
|
||||||
cx.ident_of("std"),
|
cx.ident_of("std"),
|
||||||
@ -131,7 +131,7 @@ fn rand_substructure(cx: &mut ExtCtxt, trait_span: Span, substr: &Substructure)
|
|||||||
let block = cx.block(trait_span, vec!( let_statement ), Some(match_expr));
|
let block = cx.block(trait_span, vec!( let_statement ), Some(match_expr));
|
||||||
cx.expr_block(block)
|
cx.expr_block(block)
|
||||||
}
|
}
|
||||||
_ => cx.bug("Non-static method in `deriving(Rand)`")
|
_ => cx.bug("Non-static method in `derive(Rand)`")
|
||||||
};
|
};
|
||||||
|
|
||||||
fn rand_thing<F>(cx: &mut ExtCtxt,
|
fn rand_thing<F>(cx: &mut ExtCtxt,
|
||||||
|
Loading…
Reference in New Issue
Block a user