Skip to content

Commit 38546ba

Browse files
committed
Add note when trying to use Self as a ctor
1 parent ce9ef37 commit 38546ba

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/librustc_resolve/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -898,7 +898,7 @@ impl<'a> LexicalScopeBinding<'a> {
898898
}
899899
}
900900

901-
#[derive(Clone)]
901+
#[derive(Clone, Debug)]
902902
enum PathResult<'a> {
903903
Module(Module<'a>),
904904
NonModule(PathResolution),
@@ -2742,6 +2742,10 @@ impl<'a> Resolver<'a> {
27422742
block));
27432743
return (err, candidates);
27442744
}
2745+
(Def::SelfTy(_, _), _) if ns == ValueNS && is_struct_like(def) => {
2746+
err.note("can't instantiate `Self`, you must use the implemented struct \
2747+
directly");
2748+
}
27452749
_ => {}
27462750
}
27472751
}

src/test/ui/resolve/tuple-struct-alias.stderr

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@ error[E0423]: expected function, found self type `Self`
33
|
44
16 | let s = Self(0, 1); //~ ERROR expected function
55
| ^^^^ not a function
6+
|
7+
= note: can't instantiate `Self`, you must use the implemented struct directly
68

79
error[E0532]: expected tuple struct/variant, found self type `Self`
810
--> $DIR/tuple-struct-alias.rs:18:13
911
|
1012
18 | Self(..) => {} //~ ERROR expected tuple struct/variant
1113
| ^^^^ not a tuple struct/variant
14+
|
15+
= note: can't instantiate `Self`, you must use the implemented struct directly
1216

1317
error[E0423]: expected function, found type alias `A`
1418
--> $DIR/tuple-struct-alias.rs:24:13

0 commit comments

Comments
 (0)