Skip to content

Commit 4b40bc8

Browse files
committed
auto merge of #20365 : nick29581/rust/mod, r=huonw
Part of #20361 and #20362
2 parents 71b46b1 + dc53461 commit 4b40bc8

File tree

227 files changed

+383
-365
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

227 files changed

+383
-365
lines changed

src/librustc/lint/builtin.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ impl LintPass for BoxPointers {
551551
declare_lint! {
552552
RAW_POINTER_DERIVING,
553553
Warn,
554-
"uses of #[deriving] with raw pointers are rarely correct"
554+
"uses of #[derive] with raw pointers are rarely correct"
555555
}
556556

557557
struct RawPtrDerivingVisitor<'a, 'tcx: 'a> {
@@ -560,7 +560,7 @@ struct RawPtrDerivingVisitor<'a, 'tcx: 'a> {
560560

561561
impl<'a, 'tcx, 'v> Visitor<'v> for RawPtrDerivingVisitor<'a, 'tcx> {
562562
fn visit_ty(&mut self, ty: &ast::Ty) {
563-
static MSG: &'static str = "use of `#[deriving]` with a raw pointer";
563+
static MSG: &'static str = "use of `#[derive]` with a raw pointer";
564564
if let ast::TyPtr(..) = ty.node {
565565
self.cx.span_lint(RAW_POINTER_DERIVING, ty.span, MSG);
566566
}

src/librustc_resolve/build_reduced_graph.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -681,9 +681,10 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
681681
ViewPathSimple(binding, ref full_path, id) => {
682682
let source_name =
683683
full_path.segments.last().unwrap().identifier.name;
684-
if token::get_name(source_name).get() == "mod" {
684+
if token::get_name(source_name).get() == "mod" ||
685+
token::get_name(source_name).get() == "self" {
685686
self.resolve_error(view_path.span,
686-
"`mod` imports are only allowed within a { } list");
687+
"`self` imports are only allowed within a { } list");
687688
}
688689

689690
let subclass = SingleImport(binding.name,
@@ -704,10 +705,10 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
704705
}).collect::<Vec<Span>>();
705706
if mod_spans.len() > 1 {
706707
self.resolve_error(mod_spans[0],
707-
"`mod` import can only appear once in the list");
708+
"`self` import can only appear once in the list");
708709
for other_span in mod_spans.iter().skip(1) {
709710
self.session.span_note(*other_span,
710-
"another `mod` import appears here");
711+
"another `self` import appears here");
711712
}
712713
}
713714

@@ -720,7 +721,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
720721
Some(name) => *name,
721722
None => {
722723
self.resolve_error(source_item.span,
723-
"`mod` import can only appear in an import list \
724+
"`self` import can only appear in an import list \
724725
with a non-empty prefix");
725726
continue;
726727
}

src/librustc_resolve/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -971,6 +971,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
971971
}
972972
}
973973

974+
974975
// Import resolution
975976
//
976977
// This is a fixed-point algorithm. We resolve imports until our efforts

src/libsyntax/ext/base.rs

+2
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,8 @@ fn initial_syntax_expander_table(ecfg: &expand::ExpansionConfig) -> SyntaxEnv {
390390
syntax_expanders.insert(intern("log_syntax"),
391391
builtin_normal_expander(
392392
ext::log_syntax::expand_syntax_ext));
393+
syntax_expanders.insert(intern("derive"),
394+
Decorator(box ext::deriving::expand_meta_derive));
393395
syntax_expanders.insert(intern("deriving"),
394396
Decorator(box ext::deriving::expand_meta_deriving));
395397

src/libsyntax/ext/deriving/generic/mod.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// except according to those terms.
1010

1111
//! Some code that abstracts away much of the boilerplate of writing
12-
//! `deriving` instances for traits. Among other things it manages getting
12+
//! `derive` instances for traits. Among other things it manages getting
1313
//! access to the fields of the 4 different sorts of structs and enum
1414
//! variants, as well as creating the method and impl ast instances.
1515
//!
@@ -26,7 +26,7 @@
2626
//! moment. (`TraitDef.additional_bounds`)
2727
//!
2828
//! Unsupported: FIXME #6257: calling methods on reference fields,
29-
//! e.g. deriving Eq/Ord/Clone don't work on `struct A(&int)`,
29+
//! e.g. derive Eq/Ord/Clone don't work on `struct A(&int)`,
3030
//! because of how the auto-dereferencing happens.
3131
//!
3232
//! The most important thing for implementers is the `Substructure` and
@@ -209,7 +209,7 @@ use self::ty::{LifetimeBounds, Path, Ptr, PtrTy, Self, Ty};
209209
pub mod ty;
210210

211211
pub struct TraitDef<'a> {
212-
/// The span for the current #[deriving(Foo)] header.
212+
/// The span for the current #[derive(Foo)] header.
213213
pub span: Span,
214214

215215
pub attributes: Vec<ast::Attribute>,
@@ -354,7 +354,7 @@ impl<'a> TraitDef<'a> {
354354
generics)
355355
}
356356
_ => {
357-
cx.span_err(mitem.span, "`deriving` may only be applied to structs and enums");
357+
cx.span_err(mitem.span, "`derive` may only be applied to structs and enums");
358358
return;
359359
}
360360
};
@@ -718,7 +718,7 @@ impl<'a> MethodDef<'a> {
718718
}
719719

720720
/// ```
721-
/// #[deriving(PartialEq)]
721+
/// #[derive(PartialEq)]
722722
/// struct A { x: int, y: int }
723723
///
724724
/// // equivalent to:
@@ -782,7 +782,7 @@ impl<'a> MethodDef<'a> {
782782
} else {
783783
cx.span_bug(trait_.span,
784784
"no self arguments to non-static method in generic \
785-
`deriving`")
785+
`derive`")
786786
};
787787

788788
// body of the inner most destructuring match
@@ -822,7 +822,7 @@ impl<'a> MethodDef<'a> {
822822
}
823823

824824
/// ```
825-
/// #[deriving(PartialEq)]
825+
/// #[derive(PartialEq)]
826826
/// enum A {
827827
/// A1,
828828
/// A2(int)
@@ -1185,7 +1185,7 @@ impl<'a> TraitDef<'a> {
11851185
cx: &mut ExtCtxt,
11861186
mut to_set: Span) -> Span {
11871187
let trait_name = match self.path.path.last() {
1188-
None => cx.span_bug(self.span, "trait with empty path in generic `deriving`"),
1188+
None => cx.span_bug(self.span, "trait with empty path in generic `derive`"),
11891189
Some(name) => *name
11901190
};
11911191
to_set.expn_id = cx.codemap().record_expansion(codemap::ExpnInfo {
@@ -1215,7 +1215,7 @@ impl<'a> TraitDef<'a> {
12151215
match (just_spans.is_empty(), named_idents.is_empty()) {
12161216
(false, false) => cx.span_bug(self.span,
12171217
"a struct with named and unnamed \
1218-
fields in generic `deriving`"),
1218+
fields in generic `derive`"),
12191219
// named fields
12201220
(_, false) => Named(named_idents),
12211221
// tuple structs (includes empty structs)
@@ -1263,7 +1263,7 @@ impl<'a> TraitDef<'a> {
12631263
None
12641264
}
12651265
_ => {
1266-
cx.span_bug(sp, "a struct with named and unnamed fields in `deriving`");
1266+
cx.span_bug(sp, "a struct with named and unnamed fields in `derive`");
12671267
}
12681268
};
12691269
let ident = cx.ident_of(format!("{}_{}", prefix, i)[]);
@@ -1371,7 +1371,7 @@ pub fn cs_fold<F>(use_foldl: bool,
13711371
enum_nonmatch_f(cx, trait_span, (all_args[], tuple),
13721372
substructure.nonself_args),
13731373
StaticEnum(..) | StaticStruct(..) => {
1374-
cx.span_bug(trait_span, "static function in `deriving`")
1374+
cx.span_bug(trait_span, "static function in `derive`")
13751375
}
13761376
}
13771377
}
@@ -1411,7 +1411,7 @@ pub fn cs_same_method<F>(f: F,
14111411
enum_nonmatch_f(cx, trait_span, (all_self_args[], tuple),
14121412
substructure.nonself_args),
14131413
StaticEnum(..) | StaticStruct(..) => {
1414-
cx.span_bug(trait_span, "static function in `deriving`")
1414+
cx.span_bug(trait_span, "static function in `derive`")
14151415
}
14161416
}
14171417
}

src/libsyntax/ext/deriving/mod.rs

+20-10
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
//! The compiler code necessary to implement the `#[deriving]` extensions.
11+
//! The compiler code necessary to implement the `#[derive]` extensions.
1212
//!
1313
//! FIXME (#2810): hygiene. Search for "__" strings (in other files too). We also assume "extra" is
1414
//! the standard library, and "std" is the core library.
@@ -45,16 +45,26 @@ pub fn expand_meta_deriving(cx: &mut ExtCtxt,
4545
_span: Span,
4646
mitem: &MetaItem,
4747
item: &Item,
48-
mut push: Box<FnMut(P<Item>)>) {
48+
push: Box<FnMut(P<Item>)>) {
49+
cx.span_warn(mitem.span, "`deriving` is deprecated; use `derive`");
50+
51+
expand_meta_derive(cx, _span, mitem, item, push)
52+
}
53+
54+
pub fn expand_meta_derive(cx: &mut ExtCtxt,
55+
_span: Span,
56+
mitem: &MetaItem,
57+
item: &Item,
58+
mut push: Box<FnMut(P<Item>)>) {
4959
match mitem.node {
5060
MetaNameValue(_, ref l) => {
51-
cx.span_err(l.span, "unexpected value in `deriving`");
61+
cx.span_err(l.span, "unexpected value in `derive`");
5262
}
5363
MetaWord(_) => {
54-
cx.span_warn(mitem.span, "empty trait list in `deriving`");
64+
cx.span_warn(mitem.span, "empty trait list in `derive`");
5565
}
5666
MetaList(_, ref titems) if titems.len() == 0 => {
57-
cx.span_warn(mitem.span, "empty trait list in `deriving`");
67+
cx.span_warn(mitem.span, "empty trait list in `derive`");
5868
}
5969
MetaList(_, ref titems) => {
6070
for titem in titems.iter().rev() {
@@ -78,15 +88,15 @@ pub fn expand_meta_deriving(cx: &mut ExtCtxt,
7888
}
7989
"Encodable" => {
8090
cx.span_warn(titem.span,
81-
"deriving(Encodable) is deprecated \
82-
in favor of deriving(RustcEncodable)");
91+
"derive(Encodable) is deprecated \
92+
in favor of derive(RustcEncodable)");
8393

8494
expand!(encodable::expand_deriving_encodable)
8595
}
8696
"Decodable" => {
8797
cx.span_warn(titem.span,
88-
"deriving(Decodable) is deprecated \
89-
in favor of deriving(RustcDecodable)");
98+
"derive(Decodable) is deprecated \
99+
in favor of derive(RustcDecodable)");
90100

91101
expand!(decodable::expand_deriving_decodable)
92102
}
@@ -111,7 +121,7 @@ pub fn expand_meta_deriving(cx: &mut ExtCtxt,
111121

112122
ref tname => {
113123
cx.span_err(titem.span,
114-
format!("unknown `deriving` \
124+
format!("unknown `derive` \
115125
trait: `{}`",
116126
*tname)[]);
117127
}

src/libsyntax/parse/parser.rs

+4
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,10 @@ impl<'a> Parser<'a> {
546546
pub fn parse_path_list_item(&mut self) -> ast::PathListItem {
547547
let lo = self.span.lo;
548548
let node = if self.eat_keyword(keywords::Mod) {
549+
let span = self.last_span;
550+
self.span_warn(span, "deprecated syntax; use the `self` keyword now");
551+
ast::PathListMod { id: ast::DUMMY_NODE_ID }
552+
} else if self.eat_keyword(keywords::Self) {
549553
ast::PathListMod { id: ast::DUMMY_NODE_ID }
550554
} else {
551555
let ident = self.parse_ident();

src/libsyntax/print/pprust.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2540,7 +2540,7 @@ impl<'a> State<'a> {
25402540
s.print_ident(name)
25412541
},
25422542
ast::PathListMod { .. } => {
2543-
word(&mut s.s, "mod")
2543+
word(&mut s.s, "self")
25442544
}
25452545
}
25462546
}));

src/test/auxiliary/trait_inheritance_overloading_xc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use std::cmp::PartialEq;
1313
pub trait MyNum : Add<Self,Self> + Sub<Self,Self> + Mul<Self,Self> + PartialEq + Clone {
1414
}
1515

16-
#[deriving(Clone, Show)]
16+
#[derive(Clone, Show)]
1717
pub struct MyInt {
1818
pub val: int
1919
}

src/test/bench/shootout-k-nucleotide.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ static OCCURRENCES: [&'static str;5] = [
6060

6161
// Code implementation
6262

63-
#[deriving(PartialEq, PartialOrd, Ord, Eq)]
63+
#[derive(PartialEq, PartialOrd, Ord, Eq)]
6464
struct Code(u64);
6565

6666
impl Copy for Code {}

src/test/bench/task-perf-alloc-unwind.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use std::os;
1414
use std::task;
1515
use std::time::Duration;
1616

17-
#[deriving(Clone)]
17+
#[derive(Clone)]
1818
enum List<T> {
1919
Nil, Cons(T, Box<List<T>>)
2020
}

src/test/compile-fail/associated-types-issue-20346.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#![feature(associated_types)]
1515
#![no_implicit_prelude]
1616

17-
use std::option::Option::{None, Some, mod};
17+
use std::option::Option::{self, None, Some};
1818
use std::vec::Vec;
1919

2020
trait Iterator {

src/test/compile-fail/attr-before-eof.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#[deriving(Show)] //~ERROR expected item after attributes
11+
#[derive(Show)] //~ERROR expected item after attributes

src/test/compile-fail/borrowck-init-in-fru.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#[deriving(Clone)]
11+
#[derive(Clone)]
1212
struct point {
1313
x: int,
1414
y: int,

src/test/compile-fail/borrowck-loan-in-overloaded-op.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// except according to those terms.
1010

1111

12-
#[deriving(Clone)]
12+
#[derive(Clone)]
1313
struct foo(Box<uint>);
1414

1515
impl Add<foo, foo> for foo {

src/test/compile-fail/borrowck-loan-rcvr-overloaded-op.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#[deriving(Copy)]
11+
#[derive(Copy)]
1212
struct Point {
1313
x: int,
1414
y: int,

src/test/compile-fail/borrowck-move-out-of-vec-tail.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
// Test that we do not permit moves from &[] matched by a vec pattern.
1212

13-
#[deriving(Clone, Show)]
13+
#[derive(Clone, Show)]
1414
struct Foo {
1515
string: String
1616
}

src/test/compile-fail/coherence-blanket-conflicts-with-specific-multidispatch.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ impl<T> MyTrait<T> for T { //~ ERROR E0119
2424
}
2525
}
2626

27-
#[deriving(Clone)]
27+
#[derive(Clone)]
2828
struct MyType {
2929
dummy: uint
3030
}

src/test/compile-fail/copy-a-resource.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#[deriving(Show)]
11+
#[derive(Show)]
1212
struct foo {
1313
i: int,
1414
}

src/test/compile-fail/deriving-bounds.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#[deriving(Copy(Bad))]
11+
#[derive(Copy(Bad))]
1212
//~^ ERROR unexpected value in deriving, expected a trait
1313
struct Test;
1414

15-
#[deriving(Sync)]
15+
#[derive(Sync)]
1616
//~^ ERROR Sync is an unsafe trait and it should be implemented explicitly
1717
struct Test1;
1818

src/test/compile-fail/deriving-meta-unknown-trait.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#[deriving(Eqr)] //~ ERROR unknown `deriving` trait: `Eqr`
11+
#[derive(Eqr)] //~ ERROR unknown `derive` trait: `Eqr`
1212
struct Foo;
1313

1414
pub fn main() {}

0 commit comments

Comments
 (0)