Skip to content

Commit

Permalink
auto merge of #20365 : nick29581/rust/mod, r=huonw
Browse files Browse the repository at this point in the history
Part of #20361 and #20362
  • Loading branch information
bors committed Jan 2, 2015
2 parents 71b46b1 + dc53461 commit 4b40bc8
Show file tree
Hide file tree
Showing 227 changed files with 383 additions and 365 deletions.
4 changes: 2 additions & 2 deletions src/librustc/lint/builtin.rs
Expand Up @@ -551,7 +551,7 @@ impl LintPass for BoxPointers {
declare_lint! {
RAW_POINTER_DERIVING,
Warn,
"uses of #[deriving] with raw pointers are rarely correct"
"uses of #[derive] with raw pointers are rarely correct"
}

struct RawPtrDerivingVisitor<'a, 'tcx: 'a> {
Expand All @@ -560,7 +560,7 @@ struct RawPtrDerivingVisitor<'a, 'tcx: 'a> {

impl<'a, 'tcx, 'v> Visitor<'v> for RawPtrDerivingVisitor<'a, 'tcx> {
fn visit_ty(&mut self, ty: &ast::Ty) {
static MSG: &'static str = "use of `#[deriving]` with a raw pointer";
static MSG: &'static str = "use of `#[derive]` with a raw pointer";
if let ast::TyPtr(..) = ty.node {
self.cx.span_lint(RAW_POINTER_DERIVING, ty.span, MSG);
}
Expand Down
11 changes: 6 additions & 5 deletions src/librustc_resolve/build_reduced_graph.rs
Expand Up @@ -681,9 +681,10 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
ViewPathSimple(binding, ref full_path, id) => {
let source_name =
full_path.segments.last().unwrap().identifier.name;
if token::get_name(source_name).get() == "mod" {
if token::get_name(source_name).get() == "mod" ||
token::get_name(source_name).get() == "self" {
self.resolve_error(view_path.span,
"`mod` imports are only allowed within a { } list");
"`self` imports are only allowed within a { } list");
}

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

Expand All @@ -720,7 +721,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
Some(name) => *name,
None => {
self.resolve_error(source_item.span,
"`mod` import can only appear in an import list \
"`self` import can only appear in an import list \
with a non-empty prefix");
continue;
}
Expand Down
1 change: 1 addition & 0 deletions src/librustc_resolve/lib.rs
Expand Up @@ -971,6 +971,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
}
}


// Import resolution
//
// This is a fixed-point algorithm. We resolve imports until our efforts
Expand Down
2 changes: 2 additions & 0 deletions src/libsyntax/ext/base.rs
Expand Up @@ -390,6 +390,8 @@ fn initial_syntax_expander_table(ecfg: &expand::ExpansionConfig) -> SyntaxEnv {
syntax_expanders.insert(intern("log_syntax"),
builtin_normal_expander(
ext::log_syntax::expand_syntax_ext));
syntax_expanders.insert(intern("derive"),
Decorator(box ext::deriving::expand_meta_derive));
syntax_expanders.insert(intern("deriving"),
Decorator(box ext::deriving::expand_meta_deriving));

Expand Down
24 changes: 12 additions & 12 deletions src/libsyntax/ext/deriving/generic/mod.rs
Expand Up @@ -9,7 +9,7 @@
// except according to those terms.

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

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

pub attributes: Vec<ast::Attribute>,
Expand Down Expand Up @@ -354,7 +354,7 @@ impl<'a> TraitDef<'a> {
generics)
}
_ => {
cx.span_err(mitem.span, "`deriving` may only be applied to structs and enums");
cx.span_err(mitem.span, "`derive` may only be applied to structs and enums");
return;
}
};
Expand Down Expand Up @@ -718,7 +718,7 @@ impl<'a> MethodDef<'a> {
}

/// ```
/// #[deriving(PartialEq)]
/// #[derive(PartialEq)]
/// struct A { x: int, y: int }
///
/// // equivalent to:
Expand Down Expand Up @@ -782,7 +782,7 @@ impl<'a> MethodDef<'a> {
} else {
cx.span_bug(trait_.span,
"no self arguments to non-static method in generic \
`deriving`")
`derive`")
};

// body of the inner most destructuring match
Expand Down Expand Up @@ -822,7 +822,7 @@ impl<'a> MethodDef<'a> {
}

/// ```
/// #[deriving(PartialEq)]
/// #[derive(PartialEq)]
/// enum A {
/// A1,
/// A2(int)
Expand Down Expand Up @@ -1185,7 +1185,7 @@ impl<'a> TraitDef<'a> {
cx: &mut ExtCtxt,
mut to_set: Span) -> Span {
let trait_name = match self.path.path.last() {
None => cx.span_bug(self.span, "trait with empty path in generic `deriving`"),
None => cx.span_bug(self.span, "trait with empty path in generic `derive`"),
Some(name) => *name
};
to_set.expn_id = cx.codemap().record_expansion(codemap::ExpnInfo {
Expand Down Expand Up @@ -1215,7 +1215,7 @@ impl<'a> TraitDef<'a> {
match (just_spans.is_empty(), named_idents.is_empty()) {
(false, false) => cx.span_bug(self.span,
"a struct with named and unnamed \
fields in generic `deriving`"),
fields in generic `derive`"),
// named fields
(_, false) => Named(named_idents),
// tuple structs (includes empty structs)
Expand Down Expand Up @@ -1263,7 +1263,7 @@ impl<'a> TraitDef<'a> {
None
}
_ => {
cx.span_bug(sp, "a struct with named and unnamed fields in `deriving`");
cx.span_bug(sp, "a struct with named and unnamed fields in `derive`");
}
};
let ident = cx.ident_of(format!("{}_{}", prefix, i)[]);
Expand Down Expand Up @@ -1371,7 +1371,7 @@ pub fn cs_fold<F>(use_foldl: bool,
enum_nonmatch_f(cx, trait_span, (all_args[], tuple),
substructure.nonself_args),
StaticEnum(..) | StaticStruct(..) => {
cx.span_bug(trait_span, "static function in `deriving`")
cx.span_bug(trait_span, "static function in `derive`")
}
}
}
Expand Down Expand Up @@ -1411,7 +1411,7 @@ pub fn cs_same_method<F>(f: F,
enum_nonmatch_f(cx, trait_span, (all_self_args[], tuple),
substructure.nonself_args),
StaticEnum(..) | StaticStruct(..) => {
cx.span_bug(trait_span, "static function in `deriving`")
cx.span_bug(trait_span, "static function in `derive`")
}
}
}
Expand Down
30 changes: 20 additions & 10 deletions src/libsyntax/ext/deriving/mod.rs
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

//! The compiler code necessary to implement the `#[deriving]` extensions.
//! The compiler code necessary to implement the `#[derive]` extensions.
//!
//! FIXME (#2810): hygiene. Search for "__" strings (in other files too). We also assume "extra" is
//! the standard library, and "std" is the core library.
Expand Down Expand Up @@ -45,16 +45,26 @@ pub fn expand_meta_deriving(cx: &mut ExtCtxt,
_span: Span,
mitem: &MetaItem,
item: &Item,
mut push: Box<FnMut(P<Item>)>) {
push: Box<FnMut(P<Item>)>) {
cx.span_warn(mitem.span, "`deriving` is deprecated; use `derive`");

expand_meta_derive(cx, _span, mitem, item, push)
}

pub fn expand_meta_derive(cx: &mut ExtCtxt,
_span: Span,
mitem: &MetaItem,
item: &Item,
mut push: Box<FnMut(P<Item>)>) {
match mitem.node {
MetaNameValue(_, ref l) => {
cx.span_err(l.span, "unexpected value in `deriving`");
cx.span_err(l.span, "unexpected value in `derive`");
}
MetaWord(_) => {
cx.span_warn(mitem.span, "empty trait list in `deriving`");
cx.span_warn(mitem.span, "empty trait list in `derive`");
}
MetaList(_, ref titems) if titems.len() == 0 => {
cx.span_warn(mitem.span, "empty trait list in `deriving`");
cx.span_warn(mitem.span, "empty trait list in `derive`");
}
MetaList(_, ref titems) => {
for titem in titems.iter().rev() {
Expand All @@ -78,15 +88,15 @@ pub fn expand_meta_deriving(cx: &mut ExtCtxt,
}
"Encodable" => {
cx.span_warn(titem.span,
"deriving(Encodable) is deprecated \
in favor of deriving(RustcEncodable)");
"derive(Encodable) is deprecated \
in favor of derive(RustcEncodable)");

expand!(encodable::expand_deriving_encodable)
}
"Decodable" => {
cx.span_warn(titem.span,
"deriving(Decodable) is deprecated \
in favor of deriving(RustcDecodable)");
"derive(Decodable) is deprecated \
in favor of derive(RustcDecodable)");

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

ref tname => {
cx.span_err(titem.span,
format!("unknown `deriving` \
format!("unknown `derive` \
trait: `{}`",
*tname)[]);
}
Expand Down
4 changes: 4 additions & 0 deletions src/libsyntax/parse/parser.rs
Expand Up @@ -546,6 +546,10 @@ impl<'a> Parser<'a> {
pub fn parse_path_list_item(&mut self) -> ast::PathListItem {
let lo = self.span.lo;
let node = if self.eat_keyword(keywords::Mod) {
let span = self.last_span;
self.span_warn(span, "deprecated syntax; use the `self` keyword now");
ast::PathListMod { id: ast::DUMMY_NODE_ID }
} else if self.eat_keyword(keywords::Self) {
ast::PathListMod { id: ast::DUMMY_NODE_ID }
} else {
let ident = self.parse_ident();
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/print/pprust.rs
Expand Up @@ -2540,7 +2540,7 @@ impl<'a> State<'a> {
s.print_ident(name)
},
ast::PathListMod { .. } => {
word(&mut s.s, "mod")
word(&mut s.s, "self")
}
}
}));
Expand Down
2 changes: 1 addition & 1 deletion src/test/auxiliary/trait_inheritance_overloading_xc.rs
Expand Up @@ -13,7 +13,7 @@ use std::cmp::PartialEq;
pub trait MyNum : Add<Self,Self> + Sub<Self,Self> + Mul<Self,Self> + PartialEq + Clone {
}

#[deriving(Clone, Show)]
#[derive(Clone, Show)]
pub struct MyInt {
pub val: int
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/bench/shootout-k-nucleotide.rs
Expand Up @@ -60,7 +60,7 @@ static OCCURRENCES: [&'static str;5] = [

// Code implementation

#[deriving(PartialEq, PartialOrd, Ord, Eq)]
#[derive(PartialEq, PartialOrd, Ord, Eq)]
struct Code(u64);

impl Copy for Code {}
Expand Down
2 changes: 1 addition & 1 deletion src/test/bench/task-perf-alloc-unwind.rs
Expand Up @@ -14,7 +14,7 @@ use std::os;
use std::task;
use std::time::Duration;

#[deriving(Clone)]
#[derive(Clone)]
enum List<T> {
Nil, Cons(T, Box<List<T>>)
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/associated-types-issue-20346.rs
Expand Up @@ -14,7 +14,7 @@
#![feature(associated_types)]
#![no_implicit_prelude]

use std::option::Option::{None, Some, mod};
use std::option::Option::{self, None, Some};
use std::vec::Vec;

trait Iterator {
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/attr-before-eof.rs
Expand Up @@ -8,4 +8,4 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#[deriving(Show)] //~ERROR expected item after attributes
#[derive(Show)] //~ERROR expected item after attributes
2 changes: 1 addition & 1 deletion src/test/compile-fail/borrowck-init-in-fru.rs
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#[deriving(Clone)]
#[derive(Clone)]
struct point {
x: int,
y: int,
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/borrowck-loan-in-overloaded-op.rs
Expand Up @@ -9,7 +9,7 @@
// except according to those terms.


#[deriving(Clone)]
#[derive(Clone)]
struct foo(Box<uint>);

impl Add<foo, foo> for foo {
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/borrowck-loan-rcvr-overloaded-op.rs
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#[deriving(Copy)]
#[derive(Copy)]
struct Point {
x: int,
y: int,
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/borrowck-move-out-of-vec-tail.rs
Expand Up @@ -10,7 +10,7 @@

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

#[deriving(Clone, Show)]
#[derive(Clone, Show)]
struct Foo {
string: String
}
Expand Down
Expand Up @@ -24,7 +24,7 @@ impl<T> MyTrait<T> for T { //~ ERROR E0119
}
}

#[deriving(Clone)]
#[derive(Clone)]
struct MyType {
dummy: uint
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/copy-a-resource.rs
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#[deriving(Show)]
#[derive(Show)]
struct foo {
i: int,
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/compile-fail/deriving-bounds.rs
Expand Up @@ -8,11 +8,11 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#[deriving(Copy(Bad))]
#[derive(Copy(Bad))]
//~^ ERROR unexpected value in deriving, expected a trait
struct Test;

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

Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/deriving-meta-unknown-trait.rs
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#[deriving(Eqr)] //~ ERROR unknown `deriving` trait: `Eqr`
#[derive(Eqr)] //~ ERROR unknown `derive` trait: `Eqr`
struct Foo;

pub fn main() {}

0 comments on commit 4b40bc8

Please sign in to comment.