From 8e82c21bf3479d338fcb8f378095daa8e698de1e Mon Sep 17 00:00:00 2001 From: Xuefeng Wu Date: Mon, 4 May 2015 19:27:02 +0800 Subject: [PATCH 1/5] more friend error message for in fn arg --- src/librustc_resolve/lib.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 38ab0a8c5ed0d..6f8e70dad2e39 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -2361,8 +2361,18 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { "type name" }; - let msg = format!("use of undeclared {} `{}`", kind, - path_names_to_string(path, 0)); + let self_type_name = special_idents::type_self.name; + let is_invalid_self_type_name = + path.segments.len() > 0 && + maybe_qself.is_none() && + path.segments[0].identifier.name == self_type_name; + let msg = if is_invalid_self_type_name { + "expected type name, found keyword `Self`".to_string() + } else { + format!("use of undeclared {} `{}`", + kind, path_names_to_string(path, 0)) + }; + self.resolve_error(ty.span, &msg[..]); } } From 1e39d9b95dfd6d0f8cd4883c62f812532d15c403 Mon Sep 17 00:00:00 2001 From: XuefengWu Date: Sun, 10 May 2015 17:09:56 +0800 Subject: [PATCH 2/5] change Self type error message --- src/librustc_resolve/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 6f8e70dad2e39..7347b59dd4cf6 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -2367,7 +2367,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { maybe_qself.is_none() && path.segments[0].identifier.name == self_type_name; let msg = if is_invalid_self_type_name { - "expected type name, found keyword `Self`".to_string() + "use of Self outside of an impl".to_string() } else { format!("use of undeclared {} `{}`", kind, path_names_to_string(path, 0)) From 5cf6b025719f808b39bce33708cc96c287c37cb6 Mon Sep 17 00:00:00 2001 From: Xuefeng Wu Date: Sat, 16 May 2015 15:36:17 +0800 Subject: [PATCH 3/5] fix typo for copyright year and trait capitalise --- src/librustc_resolve/lib.rs | 2 +- src/test/compile-fail/issue-24968.rs | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 src/test/compile-fail/issue-24968.rs diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 7347b59dd4cf6..b5dd2f2909325 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -2367,7 +2367,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { maybe_qself.is_none() && path.segments[0].identifier.name == self_type_name; let msg = if is_invalid_self_type_name { - "use of Self outside of an impl".to_string() + "use of `Self` outside of an impl or trait".to_string() } else { format!("use of undeclared {} `{}`", kind, path_names_to_string(path, 0)) diff --git a/src/test/compile-fail/issue-24968.rs b/src/test/compile-fail/issue-24968.rs new file mode 100644 index 0000000000000..1bef74012f063 --- /dev/null +++ b/src/test/compile-fail/issue-24968.rs @@ -0,0 +1,15 @@ +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn foo(_: Self) { + //~^ ERROR use of `Self` outside of an impl or Trait +} + +fn main() {} From 574a8cd8cc65f9a32051d475cfe1ac6be28a1cdd Mon Sep 17 00:00:00 2001 From: Xuefeng Wu Date: Sat, 16 May 2015 17:37:11 +0800 Subject: [PATCH 4/5] fix trait capitalise typo in test file --- src/test/compile-fail/issue-24968.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/compile-fail/issue-24968.rs b/src/test/compile-fail/issue-24968.rs index 1bef74012f063..f51b77b0ee539 100644 --- a/src/test/compile-fail/issue-24968.rs +++ b/src/test/compile-fail/issue-24968.rs @@ -9,7 +9,7 @@ // except according to those terms. fn foo(_: Self) { - //~^ ERROR use of `Self` outside of an impl or Trait + //~^ ERROR use of `Self` outside of an impl or trait } fn main() {} From 7fe60c16362a0c07c1305d9b4ee9ba1288482138 Mon Sep 17 00:00:00 2001 From: Xuefeng Wu Date: Sat, 16 May 2015 21:39:48 +0800 Subject: [PATCH 5/5] fix error message in test --- src/test/compile-fail/issue-12796.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/compile-fail/issue-12796.rs b/src/test/compile-fail/issue-12796.rs index ce3c8c52b0e47..2249741cdaac5 100644 --- a/src/test/compile-fail/issue-12796.rs +++ b/src/test/compile-fail/issue-12796.rs @@ -12,7 +12,7 @@ trait Trait { fn outer(self) { fn inner(_: Self) { //~^ ERROR can't use type parameters from outer function - //~^^ ERROR use of undeclared type name `Self` + //~^^ ERROR use of `Self` outside of an impl or trait } } }