Rollup merge of #111020 - cjgillot:validate-self-ctor, r=petrochenkov
Validate resolution for SelfCtor too. Fixes https://github.com/rust-lang/rust/issues/89868 r? `@petrochenkov`
This commit is contained in:
commit
1187ce7213
@ -550,7 +550,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||||||
|
|
||||||
let sm = self.tcx.sess.source_map();
|
let sm = self.tcx.sess.source_map();
|
||||||
let def_id = match outer_res {
|
let def_id = match outer_res {
|
||||||
Res::SelfTyParam { .. } => {
|
Res::SelfTyParam { .. } | Res::SelfCtor(_) => {
|
||||||
err.span_label(span, "can't use `Self` here");
|
err.span_label(span, "can't use `Self` here");
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
@ -1171,7 +1171,10 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||||||
return Res::Err;
|
return Res::Err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Res::Def(DefKind::TyParam, _) | Res::SelfTyParam { .. } | Res::SelfTyAlias { .. } => {
|
Res::Def(DefKind::TyParam, _)
|
||||||
|
| Res::SelfTyParam { .. }
|
||||||
|
| Res::SelfTyAlias { .. }
|
||||||
|
| Res::SelfCtor(_) => {
|
||||||
for rib in ribs {
|
for rib in ribs {
|
||||||
let has_generic_params: HasGenericParams = match rib.kind {
|
let has_generic_params: HasGenericParams = match rib.kind {
|
||||||
NormalRibKind
|
NormalRibKind
|
||||||
|
17
tests/ui/self/self-ctor-inner-const.rs
Normal file
17
tests/ui/self/self-ctor-inner-const.rs
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
// Verify that we ban usage of `Self` as constructor from inner items.
|
||||||
|
|
||||||
|
struct S0<T>(T);
|
||||||
|
|
||||||
|
impl<T> S0<T> {
|
||||||
|
fn foo() {
|
||||||
|
const C: S0<u8> = Self(0);
|
||||||
|
//~^ ERROR can't use generic parameters from outer function
|
||||||
|
fn bar() -> Self {
|
||||||
|
//~^ ERROR can't use generic parameters from outer function
|
||||||
|
Self(0)
|
||||||
|
//~^ ERROR can't use generic parameters from outer function
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
33
tests/ui/self/self-ctor-inner-const.stderr
Normal file
33
tests/ui/self/self-ctor-inner-const.stderr
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
error[E0401]: can't use generic parameters from outer function
|
||||||
|
--> $DIR/self-ctor-inner-const.rs:7:27
|
||||||
|
|
|
||||||
|
LL | const C: S0<u8> = Self(0);
|
||||||
|
| ^^^^
|
||||||
|
| |
|
||||||
|
| use of generic parameter from outer function
|
||||||
|
| can't use `Self` here
|
||||||
|
|
||||||
|
error[E0401]: can't use generic parameters from outer function
|
||||||
|
--> $DIR/self-ctor-inner-const.rs:9:21
|
||||||
|
|
|
||||||
|
LL | impl<T> S0<T> {
|
||||||
|
| ---- `Self` type implicitly declared here, by this `impl`
|
||||||
|
...
|
||||||
|
LL | fn bar() -> Self {
|
||||||
|
| ^^^^
|
||||||
|
| |
|
||||||
|
| use of generic parameter from outer function
|
||||||
|
| use a type here instead
|
||||||
|
|
||||||
|
error[E0401]: can't use generic parameters from outer function
|
||||||
|
--> $DIR/self-ctor-inner-const.rs:11:13
|
||||||
|
|
|
||||||
|
LL | Self(0)
|
||||||
|
| ^^^^
|
||||||
|
| |
|
||||||
|
| use of generic parameter from outer function
|
||||||
|
| can't use `Self` here
|
||||||
|
|
||||||
|
error: aborting due to 3 previous errors
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0401`.
|
Loading…
x
Reference in New Issue
Block a user