Skip to content

Commit 19a33ed

Browse files
committed
Auto merge of #28060 - GuillaumeGomez:patch-3, r=Manishearth
Part of #24407 r? @Manishearth
2 parents ae75ef9 + ae0409b commit 19a33ed

File tree

2 files changed

+189
-9
lines changed

2 files changed

+189
-9
lines changed

src/librustc_resolve/diagnostics.rs

+51-3
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,55 @@ impl Bar {
397397
```
398398
"##,
399399

400+
E0411: r##"
401+
The `Self` keyword was used outside an impl or a trait. Erroneous
402+
code example:
403+
404+
```
405+
<Self>::foo; // error: use of `Self` outside of an impl or trait
406+
```
407+
408+
The `Self` keyword represents the current type, which explains why it
409+
can only be used inside an impl or a trait. It gives access to the
410+
associated items of a type:
411+
412+
```
413+
trait Foo {
414+
type Bar;
415+
}
416+
417+
trait Baz : Foo {
418+
fn bar() -> Self::Bar; // like this
419+
}
420+
```
421+
422+
However, be careful when two types has a common associated type:
423+
424+
```
425+
trait Foo {
426+
type Bar;
427+
}
428+
429+
trait Foo2 {
430+
type Bar;
431+
}
432+
433+
trait Baz : Foo + Foo2 {
434+
fn bar() -> Self::Bar;
435+
// error: ambiguous associated type `Bar` in bounds of `Self`
436+
}
437+
```
438+
439+
This problem can be solved by specifying from which trait we want
440+
to use the `Bar` type:
441+
442+
```
443+
trait Baz : Foo + Foo2 {
444+
fn bar() -> <Self as Foo>::Bar; // ok!
445+
}
446+
```
447+
"##,
448+
400449
E0412: r##"
401450
An undeclared type name was used. Example of erroneous codes:
402451
@@ -823,8 +872,8 @@ impl Foo for i32 {}
823872
}
824873

825874
register_diagnostics! {
826-
E0153, // called no where
827-
E0157, // called from no where
875+
// E0153, unused error code
876+
// E0157, unused error code
828877
E0254, // import conflicts with imported crate in this module
829878
E0257,
830879
E0258,
@@ -835,7 +884,6 @@ register_diagnostics! {
835884
E0409, // variable is bound with different mode in pattern # than in
836885
// pattern #1
837886
E0410, // variable from pattern is not bound in pattern 1
838-
E0411, // use of `Self` outside of an impl or trait
839887
E0414, // only irrefutable patterns allowed here
840888
E0418, // is not an enum variant, struct or const
841889
E0420, // is not an associated const

src/librustc_typeck/diagnostics.rs

+138-6
Original file line numberDiff line numberDiff line change
@@ -3020,6 +3020,144 @@ parameters. You can read more about it in the API documentation:
30203020
https://doc.rust-lang.org/std/marker/struct.PhantomData.html
30213021
"##,
30223022

3023+
E0439: r##"
3024+
The length of the platform-intrinsic function `simd_shuffle`
3025+
wasn't specified. Erroneous code example:
3026+
3027+
```
3028+
extern "platform-intrinsic" {
3029+
fn simd_shuffle<A,B>(a: A, b: A, c: [u32; 8]) -> B;
3030+
// error: invalid `simd_shuffle`, needs length: `simd_shuffle`
3031+
}
3032+
```
3033+
3034+
The `simd_shuffle` function needs the length of the array passed as
3035+
last parameter in its name. Example:
3036+
3037+
```
3038+
extern "platform-intrinsic" {
3039+
fn simd_shuffle8<A,B>(a: A, b: A, c: [u32; 8]) -> B;
3040+
}
3041+
```
3042+
"##,
3043+
3044+
E0440: r##"
3045+
A platform-specific intrinsic function has the wrong number of type
3046+
parameters. Erroneous code example:
3047+
3048+
```
3049+
#[repr(simd)]
3050+
struct f64x2(f64, f64);
3051+
3052+
extern "platform-intrinsic" {
3053+
fn x86_mm_movemask_pd<T>(x: f64x2) -> i32;
3054+
// error: platform-specific intrinsic has wrong number of type
3055+
// parameters
3056+
}
3057+
```
3058+
3059+
Please refer to the function declaration to see if it corresponds
3060+
with yours. Example:
3061+
3062+
```
3063+
#[repr(simd)]
3064+
struct f64x2(f64, f64);
3065+
3066+
extern "platform-intrinsic" {
3067+
fn x86_mm_movemask_pd(x: f64x2) -> i32;
3068+
}
3069+
```
3070+
"##,
3071+
3072+
E0441: r##"
3073+
An unknown platform-specific intrinsic function was used. Erroneous
3074+
code example:
3075+
3076+
```
3077+
#[repr(simd)]
3078+
struct i16x8(i16, i16, i16, i16, i16, i16, i16, i16);
3079+
3080+
extern "platform-intrinsic" {
3081+
fn x86_mm_adds_ep16(x: i16x8, y: i16x8) -> i16x8;
3082+
// error: unrecognized platform-specific intrinsic function
3083+
}
3084+
```
3085+
3086+
Please verify that the function name wasn't misspelled, and ensure
3087+
that it is declared in the rust source code (in the file
3088+
src/librustc_platform_intrinsics/x86.rs). Example:
3089+
3090+
```
3091+
#[repr(simd)]
3092+
struct i16x8(i16, i16, i16, i16, i16, i16, i16, i16);
3093+
3094+
extern "platform-intrinsic" {
3095+
fn x86_mm_adds_epi16(x: i16x8, y: i16x8) -> i16x8; // ok!
3096+
}
3097+
```
3098+
"##,
3099+
3100+
E0442: r##"
3101+
Intrinsic argument(s) and/or return value have the wrong type.
3102+
Erroneous code example:
3103+
3104+
```
3105+
#[repr(simd)]
3106+
struct i8x16(i8, i8, i8, i8, i8, i8, i8, i8,
3107+
i8, i8, i8, i8, i8, i8, i8, i8);
3108+
#[repr(simd)]
3109+
struct i32x4(i32, i32, i32, i32);
3110+
#[repr(simd)]
3111+
struct i64x2(i64, i64);
3112+
3113+
extern "platform-intrinsic" {
3114+
fn x86_mm_adds_epi16(x: i8x16, y: i32x4) -> i64x2;
3115+
// error: intrinsic arguments/return value have wrong type
3116+
}
3117+
```
3118+
3119+
To fix this error, please refer to the function declaration to give
3120+
it the awaited types. Example:
3121+
3122+
```
3123+
#[repr(simd)]
3124+
struct i16x8(i16, i16, i16, i16, i16, i16, i16, i16);
3125+
3126+
extern "platform-intrinsic" {
3127+
fn x86_mm_adds_epi16(x: i16x8, y: i16x8) -> i16x8; // ok!
3128+
}
3129+
```
3130+
"##,
3131+
3132+
E0443: r##"
3133+
Intrinsic argument(s) and/or return value have the wrong type.
3134+
Erroneous code example:
3135+
3136+
```
3137+
#[repr(simd)]
3138+
struct i16x8(i16, i16, i16, i16, i16, i16, i16, i16);
3139+
#[repr(simd)]
3140+
struct i64x8(i64, i64, i64, i64, i64, i64, i64, i64);
3141+
3142+
extern "platform-intrinsic" {
3143+
fn x86_mm_adds_epi16(x: i16x8, y: i16x8) -> i64x8;
3144+
// error: intrinsic argument/return value has wrong type
3145+
}
3146+
```
3147+
3148+
To fix this error, please refer to the function declaration to give
3149+
it the awaited types. Example:
3150+
3151+
```
3152+
#[repr(simd)]
3153+
struct i16x8(i16, i16, i16, i16, i16, i16, i16, i16);
3154+
3155+
extern "platform-intrinsic" {
3156+
fn x86_mm_adds_epi16(x: i16x8, y: i16x8) -> i16x8; // ok!
3157+
}
3158+
```
3159+
"##,
3160+
30233161
E0444: r##"
30243162
A platform-specific intrinsic function has wrong number of arguments.
30253163
Erroneous code example:
@@ -3128,10 +3266,4 @@ register_diagnostics! {
31283266
E0399, // trait items need to be implemented because the associated
31293267
// type `{}` was overridden
31303268
E0436, // functional record update requires a struct
3131-
E0439, // invalid `simd_shuffle`, needs length: `{}`
3132-
E0440, // platform-specific intrinsic has wrong number of type parameters
3133-
E0441, // unrecognized platform-specific intrinsic function
3134-
E0442, // intrinsic {} has wrong type: found {}, expected {}
3135-
E0443, // intrinsic {} has wrong type: found `{}`, expected `{}` which
3136-
// was used for this vector type previously in this signature
31373269
}

0 commit comments

Comments
 (0)