-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #111020 - cjgillot:validate-self-ctor, r=petrochenkov
Validate resolution for SelfCtor too. Fixes #89868 r? `@petrochenkov`
- Loading branch information
Showing
4 changed files
with
55 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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`. |