Special case 'generic param from outer item' message for Self
This commit is contained in:
parent
511bf6e1c7
commit
2cfc81766c
8 changed files with 20 additions and 11 deletions
|
@ -114,8 +114,14 @@ resolve_forward_declared_generic_param =
|
||||||
.label = defaulted generic parameters cannot be forward declared
|
.label = defaulted generic parameters cannot be forward declared
|
||||||
|
|
||||||
resolve_generic_params_from_outer_item =
|
resolve_generic_params_from_outer_item =
|
||||||
can't use generic parameters from outer item
|
can't use {$is_self ->
|
||||||
.label = use of generic parameter from outer item
|
[true] `Self`
|
||||||
|
*[false] generic parameters
|
||||||
|
} from outer item
|
||||||
|
.label = use of {$is_self ->
|
||||||
|
[true] `Self`
|
||||||
|
*[false] generic parameter
|
||||||
|
} from outer item
|
||||||
.refer_to_type_directly = refer to the type directly here instead
|
.refer_to_type_directly = refer to the type directly here instead
|
||||||
.suggestion = try introducing a local generic parameter here
|
.suggestion = try introducing a local generic parameter here
|
||||||
|
|
||||||
|
|
|
@ -568,12 +568,14 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
DefKind::Const => Some(errs::GenericParamsFromOuterItemStaticOrConst::Const),
|
DefKind::Const => Some(errs::GenericParamsFromOuterItemStaticOrConst::Const),
|
||||||
_ => None,
|
_ => None,
|
||||||
};
|
};
|
||||||
|
let is_self = matches!(outer_res, Res::SelfTyParam { .. } | Res::SelfTyAlias { .. });
|
||||||
let mut err = errs::GenericParamsFromOuterItem {
|
let mut err = errs::GenericParamsFromOuterItem {
|
||||||
span,
|
span,
|
||||||
label: None,
|
label: None,
|
||||||
refer_to_type_directly: None,
|
refer_to_type_directly: None,
|
||||||
sugg: None,
|
sugg: None,
|
||||||
static_or_const,
|
static_or_const,
|
||||||
|
is_self,
|
||||||
};
|
};
|
||||||
|
|
||||||
let sm = self.tcx.sess.source_map();
|
let sm = self.tcx.sess.source_map();
|
||||||
|
|
|
@ -46,6 +46,7 @@ pub(crate) struct GenericParamsFromOuterItem {
|
||||||
pub(crate) sugg: Option<GenericParamsFromOuterItemSugg>,
|
pub(crate) sugg: Option<GenericParamsFromOuterItemSugg>,
|
||||||
#[subdiagnostic]
|
#[subdiagnostic]
|
||||||
pub(crate) static_or_const: Option<GenericParamsFromOuterItemStaticOrConst>,
|
pub(crate) static_or_const: Option<GenericParamsFromOuterItemStaticOrConst>,
|
||||||
|
pub(crate) is_self: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Subdiagnostic)]
|
#[derive(Subdiagnostic)]
|
||||||
|
|
|
@ -20,7 +20,7 @@ LL | fn baz<U,
|
||||||
LL | (y: T) {
|
LL | (y: T) {
|
||||||
| ^ use of generic parameter from outer item
|
| ^ use of generic parameter from outer item
|
||||||
|
|
||||||
error[E0401]: can't use generic parameters from outer item
|
error[E0401]: can't use `Self` from outer item
|
||||||
--> $DIR/E0401.rs:24:25
|
--> $DIR/E0401.rs:24:25
|
||||||
|
|
|
|
||||||
LL | impl<T> Iterator for A<T> {
|
LL | impl<T> Iterator for A<T> {
|
||||||
|
@ -29,7 +29,7 @@ LL | impl<T> Iterator for A<T> {
|
||||||
LL | fn helper(sel: &Self) -> u8 {
|
LL | fn helper(sel: &Self) -> u8 {
|
||||||
| ^^^^
|
| ^^^^
|
||||||
| |
|
| |
|
||||||
| use of generic parameter from outer item
|
| use of `Self` from outer item
|
||||||
| refer to the type directly here instead
|
| refer to the type directly here instead
|
||||||
|
|
||||||
error[E0283]: type annotations needed
|
error[E0283]: type annotations needed
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
trait Trait {
|
trait Trait {
|
||||||
fn outer(&self) {
|
fn outer(&self) {
|
||||||
fn inner(_: &Self) {
|
fn inner(_: &Self) {
|
||||||
//~^ ERROR can't use generic parameters from outer item
|
//~^ ERROR can't use `Self` from outer item
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
error[E0401]: can't use generic parameters from outer item
|
error[E0401]: can't use `Self` from outer item
|
||||||
--> $DIR/issue-12796.rs:3:22
|
--> $DIR/issue-12796.rs:3:22
|
||||||
|
|
|
|
||||||
LL | fn inner(_: &Self) {
|
LL | fn inner(_: &Self) {
|
||||||
| ^^^^
|
| ^^^^
|
||||||
| |
|
| |
|
||||||
| use of generic parameter from outer item
|
| use of `Self` from outer item
|
||||||
| can't use `Self` here
|
| can't use `Self` here
|
||||||
|
|
||||||
error: aborting due to 1 previous error
|
error: aborting due to 1 previous error
|
||||||
|
|
|
@ -4,8 +4,8 @@ impl A {
|
||||||
//~^ NOTE `Self` type implicitly declared here, by this `impl`
|
//~^ NOTE `Self` type implicitly declared here, by this `impl`
|
||||||
fn banana(&mut self) {
|
fn banana(&mut self) {
|
||||||
fn peach(this: &Self) {
|
fn peach(this: &Self) {
|
||||||
//~^ ERROR can't use generic parameters from outer item
|
//~^ ERROR can't use `Self` from outer item
|
||||||
//~| NOTE use of generic parameter from outer item
|
//~| NOTE use of `Self` from outer item
|
||||||
//~| NOTE refer to the type directly here instead
|
//~| NOTE refer to the type directly here instead
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
error[E0401]: can't use generic parameters from outer item
|
error[E0401]: can't use `Self` from outer item
|
||||||
--> $DIR/use-self-in-inner-fn.rs:6:25
|
--> $DIR/use-self-in-inner-fn.rs:6:25
|
||||||
|
|
|
|
||||||
LL | impl A {
|
LL | impl A {
|
||||||
|
@ -7,7 +7,7 @@ LL | impl A {
|
||||||
LL | fn peach(this: &Self) {
|
LL | fn peach(this: &Self) {
|
||||||
| ^^^^
|
| ^^^^
|
||||||
| |
|
| |
|
||||||
| use of generic parameter from outer item
|
| use of `Self` from outer item
|
||||||
| refer to the type directly here instead
|
| refer to the type directly here instead
|
||||||
|
|
||||||
error: aborting due to 1 previous error
|
error: aborting due to 1 previous error
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue