Skip to content

Commit 890acd8

Browse files
committed
---
yaml --- r: 233659 b: refs/heads/beta c: 63ba780 h: refs/heads/master i: 233657: 74021d6 233655: ad2571a v: v3
1 parent 023c233 commit 890acd8

File tree

6 files changed

+209
-14
lines changed

6 files changed

+209
-14
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ refs/tags/0.9: 36870b185fc5f5486636d4515f0e22677493f225
2323
refs/tags/0.10: ac33f2b15782272ae348dbd7b14b8257b2148b5a
2424
refs/tags/0.11.0: e1247cb1d0d681be034adb4b558b5a0c0d5720f9
2525
refs/tags/0.12.0: f0c419429ef30723ceaf6b42f9b5a2aeb5d2e2d1
26-
refs/heads/beta: 274dae9a4ce210c95a11eaf98eed12eccac3913a
26+
refs/heads/beta: 63ba780fd7ab506bfd0f92d34a39172b412cfbe1
2727
refs/tags/1.0.0-alpha: e42bd6d93a1d3433c486200587f8f9e12590a4d7
2828
refs/heads/tmp: 370fe2786109360f7c35b8ba552b83b773dd71d6
2929
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f

branches/beta/src/librustc_data_structures/transitive_relation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ impl<T:Debug+PartialEq> TransitiveRelation<T> {
110110
/// (there are corresponding tests below, btw). In each case,
111111
/// the query is `postdom_upper_bound(a, b)`:
112112
///
113-
/// ```
113+
/// ```text
114114
/// // returns Some(x), which is also LUB
115115
/// a -> a1 -> x
116116
/// ^

branches/beta/src/librustc_trans/trans/base.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -917,10 +917,14 @@ pub fn call_lifetime_start(cx: Block, ptr: ValueRef) {
917917
let _icx = push_ctxt("lifetime_start");
918918
let ccx = cx.ccx();
919919

920-
let llsize = C_u64(ccx, machine::llsize_of_alloc(ccx, val_ty(ptr).element_type()));
920+
let size = machine::llsize_of_alloc(ccx, val_ty(ptr).element_type());
921+
if size == 0 {
922+
return;
923+
}
924+
921925
let ptr = PointerCast(cx, ptr, Type::i8p(ccx));
922926
let lifetime_start = ccx.get_intrinsic(&"llvm.lifetime.start");
923-
Call(cx, lifetime_start, &[llsize, ptr], None, DebugLoc::None);
927+
Call(cx, lifetime_start, &[C_u64(ccx, size), ptr], None, DebugLoc::None);
924928
}
925929

926930
pub fn call_lifetime_end(cx: Block, ptr: ValueRef) {
@@ -931,10 +935,14 @@ pub fn call_lifetime_end(cx: Block, ptr: ValueRef) {
931935
let _icx = push_ctxt("lifetime_end");
932936
let ccx = cx.ccx();
933937

934-
let llsize = C_u64(ccx, machine::llsize_of_alloc(ccx, val_ty(ptr).element_type()));
938+
let size = machine::llsize_of_alloc(ccx, val_ty(ptr).element_type());
939+
if size == 0 {
940+
return;
941+
}
942+
935943
let ptr = PointerCast(cx, ptr, Type::i8p(ccx));
936944
let lifetime_end = ccx.get_intrinsic(&"llvm.lifetime.end");
937-
Call(cx, lifetime_end, &[llsize, ptr], None, DebugLoc::None);
945+
Call(cx, lifetime_end, &[C_u64(ccx, size), ptr], None, DebugLoc::None);
938946
}
939947

940948
pub fn call_memcpy(cx: Block, dst: ValueRef, src: ValueRef, n_bytes: ValueRef, align: u32) {
@@ -956,6 +964,11 @@ pub fn memcpy_ty<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
956964
t: Ty<'tcx>) {
957965
let _icx = push_ctxt("memcpy_ty");
958966
let ccx = bcx.ccx();
967+
968+
if type_is_zero_size(ccx, t) {
969+
return;
970+
}
971+
959972
if t.is_structural() {
960973
let llty = type_of::type_of(ccx, t);
961974
let llsz = llsize_of(ccx, llty);

branches/beta/src/librustc_typeck/coherence/orphan.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ impl<'cx, 'tcx> OrphanChecker<'cx, 'tcx> {
5050
span_err!(self.tcx.sess, span, E0390,
5151
"only a single inherent implementation marked with `#[lang = \"{}\"]` \
5252
is allowed for the `{}` primitive", lang, ty);
53+
span_help!(self.tcx.sess, span,
54+
"consider using a trait to implement these methods");
5355
}
5456
}
5557
}

branches/beta/src/librustc_typeck/diagnostics.rs

Lines changed: 183 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2400,6 +2400,132 @@ for types as needed by the compiler, and it is currently disallowed to
24002400
explicitly implement it for a type.
24012401
"##,
24022402

2403+
E0323: r##"
2404+
An associated const was implemented when another trait item was expected.
2405+
Erroneous code example:
2406+
2407+
```
2408+
trait Foo {
2409+
type N;
2410+
}
2411+
2412+
struct Bar;
2413+
2414+
impl Foo for Bar {
2415+
const N : u32 = 0;
2416+
// error: item `N` is an associated const, which doesn't match its
2417+
// trait `<Bar as Foo>`
2418+
}
2419+
```
2420+
2421+
Please verify that the associated const wasn't misspelled and the correct trait
2422+
was implemented. Example:
2423+
2424+
```
2425+
struct Bar;
2426+
2427+
trait Foo {
2428+
type N;
2429+
}
2430+
2431+
impl Foo for Bar {
2432+
type N = u32; // ok!
2433+
}
2434+
2435+
// or:
2436+
trait Foo {
2437+
const N : u32;
2438+
}
2439+
2440+
impl Foo for Bar {
2441+
const N : u32 = 0; // ok!
2442+
}
2443+
```
2444+
"##,
2445+
2446+
E0324: r##"
2447+
A method was implemented when another trait item was expected. Erroneous
2448+
code example:
2449+
2450+
```
2451+
struct Bar;
2452+
2453+
trait Foo {
2454+
const N : u32;
2455+
2456+
fn M();
2457+
}
2458+
2459+
impl Foo for Bar {
2460+
fn N() {}
2461+
// error: item `N` is an associated method, which doesn't match its
2462+
// trait `<Bar as Foo>`
2463+
}
2464+
```
2465+
2466+
To fix this error, please verify that the method name wasn't misspelled and
2467+
verify that you are indeed implementing the correct trait items. Example:
2468+
2469+
```
2470+
struct Bar;
2471+
2472+
trait Foo {
2473+
const N : u32;
2474+
2475+
fn M();
2476+
}
2477+
2478+
impl Foo for Bar {
2479+
const N : u32 = 0;
2480+
2481+
fn M() {} // ok!
2482+
}
2483+
```
2484+
"##,
2485+
2486+
E0325: r##"
2487+
An associated type was implemented when another trait item was expected.
2488+
Erroneous code example:
2489+
2490+
```
2491+
struct Bar;
2492+
2493+
trait Foo {
2494+
const N : u32;
2495+
}
2496+
2497+
impl Foo for Bar {
2498+
type N = u32;
2499+
// error: item `N` is an associated type, which doesn't match its
2500+
// trait `<Bar as Foo>`
2501+
}
2502+
```
2503+
2504+
Please verify that the associated type name wasn't misspelled and your
2505+
implementation corresponds to the trait definition. Example:
2506+
2507+
```
2508+
struct Bar;
2509+
2510+
trait Foo {
2511+
type N;
2512+
}
2513+
2514+
impl Foo for Bar {
2515+
type N = u32; // ok!
2516+
}
2517+
2518+
//or:
2519+
trait Foo {
2520+
const N : u32;
2521+
}
2522+
2523+
impl Foo for Bar {
2524+
const N : u32 = 0; // ok!
2525+
}
2526+
```
2527+
"##,
2528+
24032529
E0326: r##"
24042530
The types of any associated constants in a trait implementation must match the
24052531
types in the trait definition. This error indicates that there was a mismatch.
@@ -2566,6 +2692,31 @@ to change this.
25662692
[RFC 953]: https://github.com/rust-lang/rfcs/pull/953
25672693
"##,
25682694

2695+
E0369: r##"
2696+
A binary operation was attempted on a type which doesn't support it.
2697+
Erroneous code example:
2698+
2699+
```
2700+
let x = 12f32; // error: binary operation `<<` cannot be applied to
2701+
// type `f32`
2702+
2703+
x << 2;
2704+
```
2705+
2706+
To fix this error, please check that this type implements this binary
2707+
operation. Example:
2708+
2709+
```
2710+
let x = 12u32; // the `u32` type does implement it:
2711+
// https://doc.rust-lang.org/stable/std/ops/trait.Shl.html
2712+
2713+
x << 2; // ok!
2714+
```
2715+
2716+
It is also possible to overload most operators for your own type by
2717+
implementing traits from `std::ops`.
2718+
"##,
2719+
25692720
E0371: r##"
25702721
When `Trait2` is a subtrait of `Trait1` (for example, when `Trait2` has a
25712722
definition like `trait Trait2: Trait1 { ... }`), it is not allowed to implement
@@ -2607,6 +2758,37 @@ For more information see the [opt-in builtin traits RFC](https://github.com/rust
26072758
-lang/rfcs/blob/master/text/0019-opt-in-builtin-traits.md).
26082759
"##,
26092760

2761+
E0390: r##"
2762+
You tried to implement methods for a primitive type. Erroneous code example:
2763+
2764+
```
2765+
struct Foo {
2766+
x: i32
2767+
}
2768+
2769+
impl *mut Foo {}
2770+
// error: only a single inherent implementation marked with
2771+
// `#[lang = "mut_ptr"]` is allowed for the `*mut T` primitive
2772+
```
2773+
2774+
This isn't allowed, but using a trait to implement a method is a good solution.
2775+
Example:
2776+
2777+
```
2778+
struct Foo {
2779+
x: i32
2780+
}
2781+
2782+
trait Bar {
2783+
fn bar();
2784+
}
2785+
2786+
impl Bar for *mut Foo {
2787+
fn bar() {} // ok!
2788+
}
2789+
```
2790+
"##,
2791+
26102792
E0391: r##"
26112793
This error indicates that some types or traits depend on each other
26122794
and therefore cannot be constructed.
@@ -2691,7 +2873,7 @@ register_diagnostics! {
26912873
E0085,
26922874
E0086,
26932875
E0090,
2694-
E0103,
2876+
E0103, // @GuillaumeGomez: I was unable to get this error, try your best!
26952877
E0104,
26962878
E0118,
26972879
E0122,
@@ -2750,12 +2932,8 @@ register_diagnostics! {
27502932
E0319, // trait impls for defaulted traits allowed just for structs/enums
27512933
E0320, // recursive overflow during dropck
27522934
E0321, // extended coherence rules for defaulted traits violated
2753-
E0323, // implemented an associated const when another trait item expected
2754-
E0324, // implemented a method when another trait item expected
2755-
E0325, // implemented an associated type when another trait item expected
27562935
E0328, // cannot implement Unsize explicitly
27572936
E0329, // associated const depends on type parameter or Self.
2758-
E0369, // binary operation `<op>` cannot be applied to types
27592937
E0370, // discriminant overflow
27602938
E0374, // the trait `CoerceUnsized` may only be implemented for a coercion
27612939
// between structures with one field being coerced, none found
@@ -2766,8 +2944,6 @@ register_diagnostics! {
27662944
// between structures
27672945
E0377, // the trait `CoerceUnsized` may only be implemented for a coercion
27682946
// between structures with the same definition
2769-
E0390, // only a single inherent implementation marked with
2770-
// `#[lang = \"{}\"]` is allowed for the `{}` primitive
27712947
E0393, // the type parameter `{}` must be explicitly specified in an object
27722948
// type because its default value `{}` references the type `Self`"
27732949
E0399, // trait items need to be implemented because the associated

branches/beta/src/libstd/num/f64.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,11 @@ impl f64 {
454454
#[stable(feature = "rust1", since = "1.0.0")]
455455
#[inline]
456456
pub fn sqrt(self) -> f64 {
457-
unsafe { intrinsics::sqrtf64(self) }
457+
if self < 0.0 {
458+
NAN
459+
} else {
460+
unsafe { intrinsics::sqrtf64(self) }
461+
}
458462
}
459463

460464
/// Returns `e^(self)`, (the exponential function).

0 commit comments

Comments
 (0)