Mention what item is using an invalid Self
type
This commit is contained in:
parent
611e7b9cea
commit
018c319b21
@ -1914,6 +1914,8 @@ pub(crate) fn report_path_resolution_error(
|
||||
};
|
||||
}
|
||||
(msg, None)
|
||||
} else if ident.name == kw::SelfUpper {
|
||||
("`Self` is only available in impls, traits, and type definitions".to_string(), None)
|
||||
} else if ident.name.as_str().chars().next().map_or(false, |c| c.is_ascii_uppercase()) {
|
||||
// Check whether the name refers to an item in the value namespace.
|
||||
let binding = if let Some(ribs) = ribs {
|
||||
|
@ -332,6 +332,16 @@ struct BaseError<'a> {
|
||||
span,
|
||||
"`Self` is only available in impls, traits, and type definitions".to_string(),
|
||||
);
|
||||
if let Some(item_kind) = self.diagnostic_metadata.current_item {
|
||||
err.span_label(
|
||||
item_kind.ident.span,
|
||||
format!(
|
||||
"`Self` not allowed in {} {}",
|
||||
item_kind.kind.article(),
|
||||
item_kind.kind.descr()
|
||||
),
|
||||
);
|
||||
}
|
||||
return (err, Vec::new());
|
||||
}
|
||||
if is_self_value(path, ns) {
|
||||
@ -389,6 +399,15 @@ struct BaseError<'a> {
|
||||
);
|
||||
}
|
||||
}
|
||||
} else if let Some(item_kind) = self.diagnostic_metadata.current_item {
|
||||
err.span_label(
|
||||
item_kind.ident.span,
|
||||
format!(
|
||||
"`self` not allowed in {} {}",
|
||||
item_kind.kind.article(),
|
||||
item_kind.kind.descr()
|
||||
),
|
||||
);
|
||||
}
|
||||
return (err, Vec::new());
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
error[E0411]: cannot find type `Self` in this scope
|
||||
--> $DIR/E0411.rs:2:6
|
||||
|
|
||||
LL | fn main() {
|
||||
| ---- `Self` not allowed in a function
|
||||
LL | <Self>::foo;
|
||||
| ^^^^ `Self` is only available in impls, traits, and type definitions
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
fn bget(&self, index: [usize; Self::DIM]) -> bool {
|
||||
//~^ ERROR incorrect function inside `extern` block
|
||||
//~| ERROR `self` parameter is only allowed in associated functions
|
||||
//~| ERROR use of undeclared type `Self`
|
||||
//~| ERROR failed to resolve: `Self`
|
||||
type T<'a> = &'a str;
|
||||
}
|
||||
}
|
||||
|
@ -25,11 +25,11 @@ LL | fn bget(&self, index: [usize; Self::DIM]) -> bool {
|
||||
|
|
||||
= note: associated functions are those in `impl` or `trait` definitions
|
||||
|
||||
error[E0433]: failed to resolve: use of undeclared type `Self`
|
||||
error[E0433]: failed to resolve: `Self` is only available in impls, traits, and type definitions
|
||||
--> $DIR/issue-97194.rs:2:35
|
||||
|
|
||||
LL | fn bget(&self, index: [usize; Self::DIM]) -> bool {
|
||||
| ^^^^ use of undeclared type `Self`
|
||||
| ^^^^ `Self` is only available in impls, traits, and type definitions
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
|
@ -1,5 +1,30 @@
|
||||
// Also includes more Self usages per #93796
|
||||
|
||||
fn foo(_: Self) {
|
||||
//~^ ERROR cannot find type `Self`
|
||||
}
|
||||
|
||||
fn foo2() {
|
||||
let x: Self;
|
||||
//~^ ERROR cannot find type `Self`
|
||||
}
|
||||
|
||||
type Foo<T>
|
||||
where
|
||||
Self: Clone,
|
||||
//~^ ERROR cannot find type `Self`
|
||||
= Vec<T>;
|
||||
|
||||
const FOO: Self = 0;
|
||||
//~^ ERROR cannot find type `Self`
|
||||
|
||||
const FOO2: u32 = Self::bar();
|
||||
//~^ ERROR failed to resolve: `Self`
|
||||
|
||||
static FOO_S: Self = 0;
|
||||
//~^ ERROR cannot find type `Self`
|
||||
|
||||
static FOO_S2: u32 = Self::bar();
|
||||
//~^ ERROR failed to resolve: `Self`
|
||||
|
||||
fn main() {}
|
||||
|
@ -1,9 +1,57 @@
|
||||
error[E0433]: failed to resolve: `Self` is only available in impls, traits, and type definitions
|
||||
--> $DIR/issue-24968.rs:21:19
|
||||
|
|
||||
LL | const FOO2: u32 = Self::bar();
|
||||
| ^^^^ `Self` is only available in impls, traits, and type definitions
|
||||
|
||||
error[E0433]: failed to resolve: `Self` is only available in impls, traits, and type definitions
|
||||
--> $DIR/issue-24968.rs:27:22
|
||||
|
|
||||
LL | static FOO_S2: u32 = Self::bar();
|
||||
| ^^^^ `Self` is only available in impls, traits, and type definitions
|
||||
|
||||
error[E0411]: cannot find type `Self` in this scope
|
||||
--> $DIR/issue-24968.rs:1:11
|
||||
--> $DIR/issue-24968.rs:3:11
|
||||
|
|
||||
LL | fn foo(_: Self) {
|
||||
| ^^^^ `Self` is only available in impls, traits, and type definitions
|
||||
| --- ^^^^ `Self` is only available in impls, traits, and type definitions
|
||||
| |
|
||||
| `Self` not allowed in a function
|
||||
|
||||
error: aborting due to previous error
|
||||
error[E0411]: cannot find type `Self` in this scope
|
||||
--> $DIR/issue-24968.rs:8:12
|
||||
|
|
||||
LL | fn foo2() {
|
||||
| ---- `Self` not allowed in a function
|
||||
LL | let x: Self;
|
||||
| ^^^^ `Self` is only available in impls, traits, and type definitions
|
||||
|
||||
For more information about this error, try `rustc --explain E0411`.
|
||||
error[E0411]: cannot find type `Self` in this scope
|
||||
--> $DIR/issue-24968.rs:14:5
|
||||
|
|
||||
LL | type Foo<T>
|
||||
| --- `Self` not allowed in a type alias
|
||||
LL | where
|
||||
LL | Self: Clone,
|
||||
| ^^^^ `Self` is only available in impls, traits, and type definitions
|
||||
|
||||
error[E0411]: cannot find type `Self` in this scope
|
||||
--> $DIR/issue-24968.rs:18:12
|
||||
|
|
||||
LL | const FOO: Self = 0;
|
||||
| --- ^^^^ `Self` is only available in impls, traits, and type definitions
|
||||
| |
|
||||
| `Self` not allowed in a constant item
|
||||
|
||||
error[E0411]: cannot find type `Self` in this scope
|
||||
--> $DIR/issue-24968.rs:24:15
|
||||
|
|
||||
LL | static FOO_S: Self = 0;
|
||||
| ----- ^^^^ `Self` is only available in impls, traits, and type definitions
|
||||
| |
|
||||
| `Self` not allowed in a static item
|
||||
|
||||
error: aborting due to 7 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0411, E0433.
|
||||
For more information about an error, try `rustc --explain E0411`.
|
||||
|
@ -3,6 +3,6 @@ pub trait Trait {
|
||||
}
|
||||
|
||||
pub type Alias = dyn Trait<A = Self::A>;
|
||||
//~^ ERROR failed to resolve: use of undeclared type `Self` [E0433]
|
||||
//~^ ERROR failed to resolve: `Self`
|
||||
|
||||
fn main() {}
|
||||
|
@ -1,8 +1,8 @@
|
||||
error[E0433]: failed to resolve: use of undeclared type `Self`
|
||||
error[E0433]: failed to resolve: `Self` is only available in impls, traits, and type definitions
|
||||
--> $DIR/issue-62263-self-in-atb.rs:5:32
|
||||
|
|
||||
LL | pub type Alias = dyn Trait<A = Self::A>;
|
||||
| ^^^^ use of undeclared type `Self`
|
||||
| ^^^^ `Self` is only available in impls, traits, and type definitions
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
type Alias = Self::Target;
|
||||
//~^ ERROR failed to resolve: use of undeclared type `Self` [E0433]
|
||||
//~^ ERROR failed to resolve: `Self`
|
||||
|
||||
fn main() {}
|
||||
|
@ -1,8 +1,8 @@
|
||||
error[E0433]: failed to resolve: use of undeclared type `Self`
|
||||
error[E0433]: failed to resolve: `Self` is only available in impls, traits, and type definitions
|
||||
--> $DIR/issue-62305-self-assoc-ty.rs:1:14
|
||||
|
|
||||
LL | type Alias = Self::Target;
|
||||
| ^^^^ use of undeclared type `Self`
|
||||
| ^^^^ `Self` is only available in impls, traits, and type definitions
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
@ -2,9 +2,10 @@ error[E0411]: cannot find type `Self` in this scope
|
||||
--> $DIR/issue-62364-self-ty-arg.rs:5:29
|
||||
|
|
||||
LL | type Alias<'a> = Struct<&'a Self>;
|
||||
| - ^^^^ `Self` is only available in impls, traits, and type definitions
|
||||
| |
|
||||
| help: you might be missing a type parameter: `, Self`
|
||||
| ----- - ^^^^ `Self` is only available in impls, traits, and type definitions
|
||||
| | |
|
||||
| | help: you might be missing a type parameter: `, Self`
|
||||
| `Self` not allowed in a type alias
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
@ -4,7 +4,7 @@ impl S {
|
||||
fn f() {}
|
||||
fn g() {
|
||||
use Self::f; //~ ERROR unresolved import
|
||||
pub(in Self::f) struct Z; //~ ERROR use of undeclared type `Self`
|
||||
pub(in Self::f) struct Z; //~ ERROR failed to resolve: `Self`
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,14 +1,14 @@
|
||||
error[E0433]: failed to resolve: use of undeclared type `Self`
|
||||
error[E0433]: failed to resolve: `Self` is only available in impls, traits, and type definitions
|
||||
--> $DIR/use-self-type.rs:7:16
|
||||
|
|
||||
LL | pub(in Self::f) struct Z;
|
||||
| ^^^^ use of undeclared type `Self`
|
||||
| ^^^^ `Self` is only available in impls, traits, and type definitions
|
||||
|
||||
error[E0432]: unresolved import `Self`
|
||||
--> $DIR/use-self-type.rs:6:13
|
||||
|
|
||||
LL | use Self::f;
|
||||
| ^^^^ use of undeclared type `Self`
|
||||
| ^^^^ `Self` is only available in impls, traits, and type definitions
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user