From 38546ba9fa5678755c03721efe83425911812ccd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Mon, 1 Jan 2018 21:21:11 -0800 Subject: [PATCH] Add note when trying to use `Self` as a ctor --- src/librustc_resolve/lib.rs | 6 +++++- src/test/ui/resolve/tuple-struct-alias.stderr | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index e21f619d6c3..d64c3832935 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -898,7 +898,7 @@ impl<'a> LexicalScopeBinding<'a> { } } -#[derive(Clone)] +#[derive(Clone, Debug)] enum PathResult<'a> { Module(Module<'a>), NonModule(PathResolution), @@ -2742,6 +2742,10 @@ impl<'a> Resolver<'a> { block)); return (err, candidates); } + (Def::SelfTy(_, _), _) if ns == ValueNS && is_struct_like(def) => { + err.note("can't instantiate `Self`, you must use the implemented struct \ + directly"); + } _ => {} } } diff --git a/src/test/ui/resolve/tuple-struct-alias.stderr b/src/test/ui/resolve/tuple-struct-alias.stderr index 3b89c87b36f..b5122e04a13 100644 --- a/src/test/ui/resolve/tuple-struct-alias.stderr +++ b/src/test/ui/resolve/tuple-struct-alias.stderr @@ -3,12 +3,16 @@ error[E0423]: expected function, found self type `Self` | 16 | let s = Self(0, 1); //~ ERROR expected function | ^^^^ not a function + | + = note: can't instantiate `Self`, you must use the implemented struct directly error[E0532]: expected tuple struct/variant, found self type `Self` --> $DIR/tuple-struct-alias.rs:18:13 | 18 | Self(..) => {} //~ ERROR expected tuple struct/variant | ^^^^ not a tuple struct/variant + | + = note: can't instantiate `Self`, you must use the implemented struct directly error[E0423]: expected function, found type alias `A` --> $DIR/tuple-struct-alias.rs:24:13