Special case 'generic param from outer item' message for Self
This commit is contained in:
parent
511bf6e1c7
commit
2cfc81766c
@ -114,8 +114,14 @@ resolve_forward_declared_generic_param =
|
||||
.label = defaulted generic parameters cannot be forward declared
|
||||
|
||||
resolve_generic_params_from_outer_item =
|
||||
can't use generic parameters from outer item
|
||||
.label = use of generic parameter from outer item
|
||||
can't use {$is_self ->
|
||||
[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
|
||||
.suggestion = try introducing a local generic parameter here
|
||||
|
||||
|
@ -568,12 +568,14 @@ pub(crate) fn into_struct_error(
|
||||
DefKind::Const => Some(errs::GenericParamsFromOuterItemStaticOrConst::Const),
|
||||
_ => None,
|
||||
};
|
||||
let is_self = matches!(outer_res, Res::SelfTyParam { .. } | Res::SelfTyAlias { .. });
|
||||
let mut err = errs::GenericParamsFromOuterItem {
|
||||
span,
|
||||
label: None,
|
||||
refer_to_type_directly: None,
|
||||
sugg: None,
|
||||
static_or_const,
|
||||
is_self,
|
||||
};
|
||||
|
||||
let sm = self.tcx.sess.source_map();
|
||||
|
@ -46,6 +46,7 @@ pub(crate) struct GenericParamsFromOuterItem {
|
||||
pub(crate) sugg: Option<GenericParamsFromOuterItemSugg>,
|
||||
#[subdiagnostic]
|
||||
pub(crate) static_or_const: Option<GenericParamsFromOuterItemStaticOrConst>,
|
||||
pub(crate) is_self: bool,
|
||||
}
|
||||
|
||||
#[derive(Subdiagnostic)]
|
||||
|
@ -20,7 +20,7 @@ LL | fn baz<U,
|
||||
LL | (y: T) {
|
||||
| ^ 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
|
||||
|
|
||||
LL | impl<T> Iterator for A<T> {
|
||||
@ -29,7 +29,7 @@ LL | impl<T> Iterator for A<T> {
|
||||
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
|
||||
|
||||
error[E0283]: type annotations needed
|
||||
|
@ -1,7 +1,7 @@
|
||||
trait Trait {
|
||||
fn outer(&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
|
||||
|
|
||||
LL | fn inner(_: &Self) {
|
||||
| ^^^^
|
||||
| |
|
||||
| use of generic parameter from outer item
|
||||
| use of `Self` from outer item
|
||||
| can't use `Self` here
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
@ -4,8 +4,8 @@ impl A {
|
||||
//~^ NOTE `Self` type implicitly declared here, by this `impl`
|
||||
fn banana(&mut self) {
|
||||
fn peach(this: &Self) {
|
||||
//~^ ERROR can't use generic parameters from outer item
|
||||
//~| NOTE use of generic parameter from outer item
|
||||
//~^ ERROR can't use `Self` from outer item
|
||||
//~| NOTE use of `Self` from outer item
|
||||
//~| 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
|
||||
|
|
||||
LL | impl A {
|
||||
@ -7,7 +7,7 @@ LL | impl A {
|
||||
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
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
Loading…
Reference in New Issue
Block a user