-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
librustc: Make Copy
opt-in.
#17864
librustc: Make Copy
opt-in.
#17864
Conversation
It'd be nice to allow |
Exciting! Can't wait to review. One nit. You write:
But in fact there is another backwards incompatible part, concerning whether |
|
As long as the |
@thestinger, is it mentioned anywhere that we don't want |
cc @flaper87 |
@@ -476,6 +481,114 @@ impl<'a, 'tcx> CoherenceChecker<'a, 'tcx> { | |||
} | |||
} | |||
} | |||
|
|||
/// Ensures that implementations of the built-in trait `Copy` are legal. | |||
fn check_implementations_of_copy(&self) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this method be made more generic in order to cover also other built-in traits?
In my last PR I had a visitor that would run the checks below for each implementation of a built-in trait.
I like the implementation of this PR better but there's probably something we can rescue from the old one since for other built-in traits we'll need the same checks on fields and variants.
7cc1145
to
a3c7530
Compare
r+ modulo bare fns and the nit about just calling through to |
c0689c7
to
eac462d
Compare
Has there been a discussion about keeping the old |
Every case where a type had |
@mitsuhiko I'm not sure I understand how |
I think there needs to be a lint to determine when a type is able to implement |
@sfackler |
(To add to that: figuring out if something is a Pod type or not is something that is very useful. C++ for instance comes with an |
@mitsuhiko the semantics of |
I understand that, but why not have an always implemented |
@thestinger "It's too hard to change right now" was explicitly not considered a valid reason to not make this change. |
That said I'm adding the lint right now, for public types without any type parameters. |
051aa46
to
a9fd710
Compare
r? @nikomatsakis (lint added per @thestinger's suggestion) |
r+ here are comments (from IRC):
|
looks like this needs a rebase |
@pcwalton r+ but needs rebase |
This change makes the compiler no longer infer whether types (structures and enumerations) implement the `Copy` trait (and thus are implicitly copyable). Rather, you must implement `Copy` yourself via `impl Copy for MyType {}`. A new warning has been added, `missing_copy_implementations`, to warn you if a non-generic public type has been added that could have implemented `Copy` but didn't. This breaks code like: #[deriving(Show)] struct Point2D { x: int, y: int, } fn main() { let mypoint = Point2D { x: 1, y: 1, }; let otherpoint = mypoint; println!("{}{}", mypoint, otherpoint); } Change this code to: #[deriving(Show)] struct Point2D { x: int, y: int, } impl Copy for Point2D {} fn main() { let mypoint = Point2D { x: 1, y: 1, }; let otherpoint = mypoint; println!("{}{}", mypoint, otherpoint); } This is the backwards-incompatible part of rust-lang#13231. Part of RFC rust-lang#3. [breaking-change]
Closing in favor of #19566 |
fix: Build and run build scripts in lsif command
This change makes the compiler no longer infer whether types (structures
and enumerations) implement the
Copy
trait (and thus are implicitlycopyable). Rather, you must implement
Copy
yourself viaimpl Copy for MyType {}
.This breaks code like:
Change this code to:
This is the backwards-incompatible part of #13231.
Part of RFC #3.
[breaking-change]
r? @nikomatsakis