Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use UFCS in the expansion of #[deriving(Clone)] #18578

Merged
merged 6 commits into from
Nov 4, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/libcore/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,6 @@

#![stable]

use clone::Clone;
use cmp::PartialEq;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't these imports still be needed for stage0?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These imports get flagged by the #[deny(unused_imports] lint on stage1. But the compiler bootstraps fine after I removed them (I did make clean before trying a new make). So... yeah I'm not sure why this actually works.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may have to tag these with #[cfg(stage0)] to get past both stage0 and stage1+

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant that this passes all the stages as it is.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting... well let's see what bors says!

use std::fmt::Show;
use slice;
Expand Down
1 change: 0 additions & 1 deletion src/libcore/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
use mem;
use char;
use char::Char;
use clone::Clone;
use cmp;
use cmp::{PartialEq, Eq};
use default::Default;
Expand Down
1 change: 0 additions & 1 deletion src/libstd/collections/hash/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
//
// ignore-lexer-test FIXME #15883

use clone::Clone;
use cmp::{Eq, Equiv, PartialEq};
use core::kinds::Sized;
use default::Default;
Expand Down
1 change: 0 additions & 1 deletion src/libstd/io/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ use rt::rtio;
use c_str::CString;
use collections::HashMap;
use hash::Hash;
use clone::Clone;
#[cfg(windows)]
use std::hash::sip::SipState;

Expand Down
14 changes: 11 additions & 3 deletions src/libsyntax/ext/deriving/clone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,19 @@ fn cs_clone(
name: &str,
cx: &mut ExtCtxt, trait_span: Span,
substr: &Substructure) -> P<Expr> {
let clone_ident = substr.method_ident;
let ctor_ident;
let all_fields;
let subcall = |field: &FieldInfo|
cx.expr_method_call(field.span, field.self_.clone(), clone_ident, Vec::new());
let fn_path = vec![
cx.ident_of("std"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't this break deriving when using #[no_std]? It seems like this should be core.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most crates (those that don't use #[no_std]) don't link to the core crate, hence ::core::clone::Clone yields "error: failed to resolve. Maybe a missing extern crate core?".

Users of #[no_std] can use this work around to access this syntax extension.

cx.ident_of("clone"),
cx.ident_of("Clone"),
cx.ident_of("clone"),
];
let subcall = |field: &FieldInfo| {
let args = vec![cx.expr_addr_of(field.span, field.self_.clone())];

cx.expr_call_global(field.span, fn_path.clone(), args)
};

match *substr.fields {
Struct(ref af) => {
Expand Down
1 change: 0 additions & 1 deletion src/libunicode/u_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
* methods provided by the UnicodeChar trait.
*/

use core::clone::Clone;
use core::cmp;
use core::slice::ImmutableSlice;
use core::iter::{Filter, AdditiveIterator, Iterator, DoubleEndedIterator};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ struct E {
}
#[deriving(Clone)]
struct C {
x: NoCloneOrEq //~ ERROR does not implement any method in scope named `clone`
x: NoCloneOrEq
//~^ ERROR the trait `core::clone::Clone` is not implemented for the type `NoCloneOrEq`
}


Expand Down
16 changes: 16 additions & 0 deletions src/test/run-pass/issue-15689-2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2014 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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#[deriving(Clone)]
enum Test<'a> {
Slice(&'a int)
}

fn main() {}