Skip to content
Permalink
Browse files

resolve: Tweak "cannot find" wording for attributes

  • Loading branch information...
petrochenkov committed Sep 15, 2019
1 parent 8bf776d commit 42a19dde82a55b65f18566d54dbbb033a22e08d9
Showing with 128 additions and 121 deletions.
  1. +3 −3 src/librustc_resolve/macros.rs
  2. +7 −0 src/libsyntax_pos/hygiene.rs
  3. +2 −2 src/test/ui/attributes/obsolete-attr.rs
  4. +2 −2 src/test/ui/attributes/obsolete-attr.stderr
  5. +3 −3 src/test/ui/attributes/unknown-attr.rs
  6. +3 −3 src/test/ui/attributes/unknown-attr.stderr
  7. +1 −1 src/test/ui/conditional-compilation/cfg-attr-unknown-attribute-macro-expansion.rs
  8. +1 −1 src/test/ui/conditional-compilation/cfg-attr-unknown-attribute-macro-expansion.stderr
  9. +5 −5 src/test/ui/conditional-compilation/cfg-generic-params.rs
  10. +5 −5 src/test/ui/conditional-compilation/cfg-generic-params.stderr
  11. +3 −3 src/test/ui/custom_attribute.rs
  12. +3 −3 src/test/ui/custom_attribute.stderr
  13. +13 −13 src/test/ui/feature-gates/feature-gate-custom_attribute.rs
  14. +13 −13 src/test/ui/feature-gates/feature-gate-custom_attribute.stderr
  15. +17 −17 src/test/ui/feature-gates/feature-gate-custom_attribute2.rs
  16. +17 −17 src/test/ui/feature-gates/feature-gate-custom_attribute2.stderr
  17. +1 −1 src/test/ui/feature-gates/feature-gate-rustc-attrs.rs
  18. +1 −1 src/test/ui/feature-gates/feature-gate-rustc-attrs.stderr
  19. +2 −2 src/test/ui/issues/issue-32655.rs
  20. +2 −2 src/test/ui/issues/issue-32655.stderr
  21. +1 −1 src/test/ui/issues/issue-49074.rs
  22. +1 −1 src/test/ui/issues/issue-49074.stderr
  23. +1 −1 src/test/ui/macros/macro-reexport-removed.rs
  24. +1 −1 src/test/ui/macros/macro-reexport-removed.stderr
  25. +1 −1 src/test/ui/proc-macro/derive-still-gated.rs
  26. +1 −1 src/test/ui/proc-macro/derive-still-gated.stderr
  27. +1 −1 src/test/ui/proc-macro/macro-namespace-reserved-2.rs
  28. +1 −1 src/test/ui/proc-macro/macro-namespace-reserved-2.stderr
  29. +1 −1 src/test/ui/proc-macro/proc-macro-attributes.rs
  30. +1 −1 src/test/ui/proc-macro/proc-macro-attributes.stderr
  31. +2 −2 src/test/ui/proc-macro/resolve-error.rs
  32. +2 −2 src/test/ui/proc-macro/resolve-error.stderr
  33. +1 −1 src/test/ui/reserved/reserved-attr-on-macro.rs
  34. +1 −1 src/test/ui/reserved/reserved-attr-on-macro.stderr
  35. +3 −3 src/test/ui/suggestions/attribute-typos.rs
  36. +3 −3 src/test/ui/suggestions/attribute-typos.stderr
  37. +1 −1 src/test/ui/tool-attributes/tool-attributes-misplaced-1.rs
  38. +1 −1 src/test/ui/tool-attributes/tool-attributes-misplaced-1.stderr
@@ -323,7 +323,7 @@ impl<'a> Resolver<'a> {
self.check_stability_and_deprecation(&ext, path);

Ok(if ext.macro_kind() != kind {
let expected = if kind == MacroKind::Attr { "attribute" } else { kind.descr() };
let expected = kind.descr_expected();
let msg = format!("expected {}, found {} `{}`", expected, res.descr(), path);
self.session.struct_span_err(path.span, &msg)
.span_label(path.span, format!("not {} {}", kind.article(), expected))
@@ -775,8 +775,8 @@ impl<'a> Resolver<'a> {
Err(..) => {
assert!(initial_binding.is_none());
let bang = if kind == MacroKind::Bang { "!" } else { "" };
let msg =
format!("cannot find {} `{}{}` in this scope", kind.descr(), ident, bang);
let expected = kind.descr_expected();
let msg = format!("cannot find {} `{}{}` in this scope", expected, ident, bang);
let mut err = self.session.struct_span_err(ident.span, &msg);
self.unresolved_macro_suggestions(&mut err, kind, &parent_scope, ident);
err.emit();
@@ -677,6 +677,13 @@ impl MacroKind {
}
}

pub fn descr_expected(self) -> &'static str {
match self {
MacroKind::Attr => "attribute",
_ => self.descr(),
}
}

pub fn article(self) -> &'static str {
match self {
MacroKind::Attr => "an",
@@ -1,9 +1,9 @@
// Obsolete attributes fall back to unstable custom attributes.

#[ab_isize="stdcall"] extern {}
//~^ ERROR cannot find attribute macro `ab_isize` in this scope
//~^ ERROR cannot find attribute `ab_isize` in this scope

#[fixed_stack_segment] fn f() {}
//~^ ERROR cannot find attribute macro `fixed_stack_segment` in this scope
//~^ ERROR cannot find attribute `fixed_stack_segment` in this scope

fn main() {}
@@ -1,10 +1,10 @@
error: cannot find attribute macro `fixed_stack_segment` in this scope
error: cannot find attribute `fixed_stack_segment` in this scope
--> $DIR/obsolete-attr.rs:6:3
|
LL | #[fixed_stack_segment] fn f() {}
| ^^^^^^^^^^^^^^^^^^^

error: cannot find attribute macro `ab_isize` in this scope
error: cannot find attribute `ab_isize` in this scope
--> $DIR/obsolete-attr.rs:3:3
|
LL | #[ab_isize="stdcall"] extern {}
@@ -3,10 +3,10 @@
#![feature(custom_inner_attributes)]

#![mutable_doc]
//~^ ERROR cannot find attribute macro `mutable_doc` in this scope
//~^ ERROR cannot find attribute `mutable_doc` in this scope

#[dance] mod a {}
//~^ ERROR cannot find attribute macro `dance` in this scope
//~^ ERROR cannot find attribute `dance` in this scope

#[dance] fn main() {}
//~^ ERROR cannot find attribute macro `dance` in this scope
//~^ ERROR cannot find attribute `dance` in this scope
@@ -1,16 +1,16 @@
error: cannot find attribute macro `mutable_doc` in this scope
error: cannot find attribute `mutable_doc` in this scope
--> $DIR/unknown-attr.rs:5:4
|
LL | #![mutable_doc]
| ^^^^^^^^^^^

error: cannot find attribute macro `dance` in this scope
error: cannot find attribute `dance` in this scope
--> $DIR/unknown-attr.rs:8:3
|
LL | #[dance] mod a {}
| ^^^^^

error: cannot find attribute macro `dance` in this scope
error: cannot find attribute `dance` in this scope
--> $DIR/unknown-attr.rs:11:3
|
LL | #[dance] fn main() {}
@@ -1,7 +1,7 @@
macro_rules! foo {
() => {
#[cfg_attr(all(), unknown)]
//~^ ERROR cannot find attribute macro `unknown` in this scope
//~^ ERROR cannot find attribute `unknown` in this scope
fn foo() {}
}
}
@@ -1,4 +1,4 @@
error: cannot find attribute macro `unknown` in this scope
error: cannot find attribute `unknown` in this scope
--> $DIR/cfg-attr-unknown-attribute-macro-expansion.rs:3:27
|
LL | #[cfg_attr(all(), unknown)]
@@ -17,22 +17,22 @@ struct WhereBad where for<#[cfg(no)] 'a, #[cfg(yes)] T> u8: Copy;

fn f_lt_no<#[cfg_attr(no, unknown)] 'a>() {} // OK
fn f_lt_yes<#[cfg_attr(yes, unknown)] 'a>() {}
//~^ ERROR cannot find attribute macro `unknown` in this scope
//~^ ERROR cannot find attribute `unknown` in this scope
fn f_ty_no<#[cfg_attr(no, unknown)] T>() {} // OK
fn f_ty_yes<#[cfg_attr(yes, unknown)] T>() {}
//~^ ERROR cannot find attribute macro `unknown` in this scope
//~^ ERROR cannot find attribute `unknown` in this scope

type FnNo = for<#[cfg_attr(no, unknown)] 'a> fn(); // OK
type FnYes = for<#[cfg_attr(yes, unknown)] 'a> fn();
//~^ ERROR cannot find attribute macro `unknown` in this scope
//~^ ERROR cannot find attribute `unknown` in this scope

type PolyNo = dyn for<#[cfg_attr(no, unknown)] 'a> Copy; // OK
type PolyYes = dyn for<#[cfg_attr(yes, unknown)] 'a> Copy;
//~^ ERROR cannot find attribute macro `unknown` in this scope
//~^ ERROR cannot find attribute `unknown` in this scope

struct WhereNo where for<#[cfg_attr(no, unknown)] 'a> u8: Copy; // OK
struct WhereYes where for<#[cfg_attr(yes, unknown)] 'a> u8: Copy;
//~^ ERROR cannot find attribute macro `unknown` in this scope
//~^ ERROR cannot find attribute `unknown` in this scope

fn main() {
f_lt::<'static>();
@@ -16,31 +16,31 @@ error: only lifetime parameters can be used in this context
LL | struct WhereBad where for<#[cfg(no)] 'a, #[cfg(yes)] T> u8: Copy;
| ^

error: cannot find attribute macro `unknown` in this scope
error: cannot find attribute `unknown` in this scope
--> $DIR/cfg-generic-params.rs:34:43
|
LL | struct WhereYes where for<#[cfg_attr(yes, unknown)] 'a> u8: Copy;
| ^^^^^^^

error: cannot find attribute macro `unknown` in this scope
error: cannot find attribute `unknown` in this scope
--> $DIR/cfg-generic-params.rs:30:40
|
LL | type PolyYes = dyn for<#[cfg_attr(yes, unknown)] 'a> Copy;
| ^^^^^^^

error: cannot find attribute macro `unknown` in this scope
error: cannot find attribute `unknown` in this scope
--> $DIR/cfg-generic-params.rs:26:34
|
LL | type FnYes = for<#[cfg_attr(yes, unknown)] 'a> fn();
| ^^^^^^^

error: cannot find attribute macro `unknown` in this scope
error: cannot find attribute `unknown` in this scope
--> $DIR/cfg-generic-params.rs:22:29
|
LL | fn f_ty_yes<#[cfg_attr(yes, unknown)] T>() {}
| ^^^^^^^

error: cannot find attribute macro `unknown` in this scope
error: cannot find attribute `unknown` in this scope
--> $DIR/cfg-generic-params.rs:19:29
|
LL | fn f_lt_yes<#[cfg_attr(yes, unknown)] 'a>() {}
@@ -1,9 +1,9 @@
#![feature(stmt_expr_attributes)]

#[foo] //~ ERROR cannot find attribute macro `foo` in this scope
#[foo] //~ ERROR cannot find attribute `foo` in this scope
fn main() {
#[foo] //~ ERROR cannot find attribute macro `foo` in this scope
#[foo] //~ ERROR cannot find attribute `foo` in this scope
let x = ();
#[foo] //~ ERROR cannot find attribute macro `foo` in this scope
#[foo] //~ ERROR cannot find attribute `foo` in this scope
x
}
@@ -1,16 +1,16 @@
error: cannot find attribute macro `foo` in this scope
error: cannot find attribute `foo` in this scope
--> $DIR/custom_attribute.rs:3:3
|
LL | #[foo]
| ^^^

error: cannot find attribute macro `foo` in this scope
error: cannot find attribute `foo` in this scope
--> $DIR/custom_attribute.rs:5:7
|
LL | #[foo]
| ^^^

error: cannot find attribute macro `foo` in this scope
error: cannot find attribute `foo` in this scope
--> $DIR/custom_attribute.rs:7:7
|
LL | #[foo]
@@ -1,18 +1,18 @@
// Check that literals in attributes parse just fine.

#[fake_attr] //~ ERROR cannot find attribute macro `fake_attr` in this scope
#[fake_attr(100)] //~ ERROR cannot find attribute macro `fake_attr` in this scope
#[fake_attr(1, 2, 3)] //~ ERROR cannot find attribute macro `fake_attr` in this scope
#[fake_attr("hello")] //~ ERROR cannot find attribute macro `fake_attr` in this scope
#[fake_attr(name = "hello")] //~ ERROR cannot find attribute macro `fake_attr` in this scope
#[fake_attr(1, "hi", key = 12, true, false)] //~ ERROR cannot find attribute macro `fake_attr` in th
#[fake_attr(key = "hello", val = 10)] //~ ERROR cannot find attribute macro `fake_attr` in this scop
#[fake_attr(key("hello"), val(10))] //~ ERROR cannot find attribute macro `fake_attr` in this scope
#[fake_attr(enabled = true, disabled = false)] //~ ERROR cannot find attribute macro `fake_attr` in
#[fake_attr(true)] //~ ERROR cannot find attribute macro `fake_attr` in this scope
#[fake_attr(pi = 3.14159)] //~ ERROR cannot find attribute macro `fake_attr` in this scope
#[fake_attr(b"hi")] //~ ERROR cannot find attribute macro `fake_attr` in this scope
#[fake_doc(r"doc")] //~ ERROR cannot find attribute macro `fake_doc` in this scope
#[fake_attr] //~ ERROR cannot find attribute `fake_attr` in this scope
#[fake_attr(100)] //~ ERROR cannot find attribute `fake_attr` in this scope
#[fake_attr(1, 2, 3)] //~ ERROR cannot find attribute `fake_attr` in this scope
#[fake_attr("hello")] //~ ERROR cannot find attribute `fake_attr` in this scope
#[fake_attr(name = "hello")] //~ ERROR cannot find attribute `fake_attr` in this scope
#[fake_attr(1, "hi", key = 12, true, false)] //~ ERROR cannot find attribute `fake_attr` in th
#[fake_attr(key = "hello", val = 10)] //~ ERROR cannot find attribute `fake_attr` in this scop
#[fake_attr(key("hello"), val(10))] //~ ERROR cannot find attribute `fake_attr` in this scope
#[fake_attr(enabled = true, disabled = false)] //~ ERROR cannot find attribute `fake_attr` in
#[fake_attr(true)] //~ ERROR cannot find attribute `fake_attr` in this scope
#[fake_attr(pi = 3.14159)] //~ ERROR cannot find attribute `fake_attr` in this scope
#[fake_attr(b"hi")] //~ ERROR cannot find attribute `fake_attr` in this scope
#[fake_doc(r"doc")] //~ ERROR cannot find attribute `fake_doc` in this scope
struct Q {}

fn main() {}
@@ -1,76 +1,76 @@
error: cannot find attribute macro `fake_attr` in this scope
error: cannot find attribute `fake_attr` in this scope
--> $DIR/feature-gate-custom_attribute.rs:3:3
|
LL | #[fake_attr]
| ^^^^^^^^^

error: cannot find attribute macro `fake_attr` in this scope
error: cannot find attribute `fake_attr` in this scope
--> $DIR/feature-gate-custom_attribute.rs:4:3
|
LL | #[fake_attr(100)]
| ^^^^^^^^^

error: cannot find attribute macro `fake_attr` in this scope
error: cannot find attribute `fake_attr` in this scope
--> $DIR/feature-gate-custom_attribute.rs:5:3
|
LL | #[fake_attr(1, 2, 3)]
| ^^^^^^^^^

error: cannot find attribute macro `fake_attr` in this scope
error: cannot find attribute `fake_attr` in this scope
--> $DIR/feature-gate-custom_attribute.rs:6:3
|
LL | #[fake_attr("hello")]
| ^^^^^^^^^

error: cannot find attribute macro `fake_attr` in this scope
error: cannot find attribute `fake_attr` in this scope
--> $DIR/feature-gate-custom_attribute.rs:7:3
|
LL | #[fake_attr(name = "hello")]
| ^^^^^^^^^

error: cannot find attribute macro `fake_attr` in this scope
error: cannot find attribute `fake_attr` in this scope
--> $DIR/feature-gate-custom_attribute.rs:8:3
|
LL | #[fake_attr(1, "hi", key = 12, true, false)]
| ^^^^^^^^^

error: cannot find attribute macro `fake_attr` in this scope
error: cannot find attribute `fake_attr` in this scope
--> $DIR/feature-gate-custom_attribute.rs:9:3
|
LL | #[fake_attr(key = "hello", val = 10)]
| ^^^^^^^^^

error: cannot find attribute macro `fake_attr` in this scope
error: cannot find attribute `fake_attr` in this scope
--> $DIR/feature-gate-custom_attribute.rs:10:3
|
LL | #[fake_attr(key("hello"), val(10))]
| ^^^^^^^^^

error: cannot find attribute macro `fake_attr` in this scope
error: cannot find attribute `fake_attr` in this scope
--> $DIR/feature-gate-custom_attribute.rs:11:3
|
LL | #[fake_attr(enabled = true, disabled = false)]
| ^^^^^^^^^

error: cannot find attribute macro `fake_attr` in this scope
error: cannot find attribute `fake_attr` in this scope
--> $DIR/feature-gate-custom_attribute.rs:12:3
|
LL | #[fake_attr(true)]
| ^^^^^^^^^

error: cannot find attribute macro `fake_attr` in this scope
error: cannot find attribute `fake_attr` in this scope
--> $DIR/feature-gate-custom_attribute.rs:13:3
|
LL | #[fake_attr(pi = 3.14159)]
| ^^^^^^^^^

error: cannot find attribute macro `fake_attr` in this scope
error: cannot find attribute `fake_attr` in this scope
--> $DIR/feature-gate-custom_attribute.rs:14:3
|
LL | #[fake_attr(b"hi")]
| ^^^^^^^^^

error: cannot find attribute macro `fake_doc` in this scope
error: cannot find attribute `fake_doc` in this scope
--> $DIR/feature-gate-custom_attribute.rs:15:3
|
LL | #[fake_doc(r"doc")]
@@ -4,54 +4,54 @@
// gate-test-custom_attribute

struct StLt<#[lt_struct] 'a>(&'a u32);
//~^ ERROR cannot find attribute macro `lt_struct` in this scope
//~^ ERROR cannot find attribute `lt_struct` in this scope
struct StTy<#[ty_struct] I>(I);
//~^ ERROR cannot find attribute macro `ty_struct` in this scope
//~^ ERROR cannot find attribute `ty_struct` in this scope

enum EnLt<#[lt_enum] 'b> { A(&'b u32), B }
//~^ ERROR cannot find attribute macro `lt_enum` in this scope
//~^ ERROR cannot find attribute `lt_enum` in this scope
enum EnTy<#[ty_enum] J> { A(J), B }
//~^ ERROR cannot find attribute macro `ty_enum` in this scope
//~^ ERROR cannot find attribute `ty_enum` in this scope

trait TrLt<#[lt_trait] 'c> { fn foo(&self, _: &'c [u32]) -> &'c u32; }
//~^ ERROR cannot find attribute macro `lt_trait` in this scope
//~^ ERROR cannot find attribute `lt_trait` in this scope
trait TrTy<#[ty_trait] K> { fn foo(&self, _: K); }
//~^ ERROR cannot find attribute macro `ty_trait` in this scope
//~^ ERROR cannot find attribute `ty_trait` in this scope

type TyLt<#[lt_type] 'd> = &'d u32;
//~^ ERROR cannot find attribute macro `lt_type` in this scope
//~^ ERROR cannot find attribute `lt_type` in this scope
type TyTy<#[ty_type] L> = (L, );
//~^ ERROR cannot find attribute macro `ty_type` in this scope
//~^ ERROR cannot find attribute `ty_type` in this scope

impl<#[lt_inherent] 'e> StLt<'e> { }
//~^ ERROR cannot find attribute macro `lt_inherent` in this scope
//~^ ERROR cannot find attribute `lt_inherent` in this scope
impl<#[ty_inherent] M> StTy<M> { }
//~^ ERROR cannot find attribute macro `ty_inherent` in this scope
//~^ ERROR cannot find attribute `ty_inherent` in this scope

impl<#[lt_impl_for] 'f> TrLt<'f> for StLt<'f> {
//~^ ERROR cannot find attribute macro `lt_impl_for` in this scope
//~^ ERROR cannot find attribute `lt_impl_for` in this scope
fn foo(&self, _: &'f [u32]) -> &'f u32 { loop { } }
}
impl<#[ty_impl_for] N> TrTy<N> for StTy<N> {
//~^ ERROR cannot find attribute macro `ty_impl_for` in this scope
//~^ ERROR cannot find attribute `ty_impl_for` in this scope
fn foo(&self, _: N) { }
}

fn f_lt<#[lt_fn] 'g>(_: &'g [u32]) -> &'g u32 { loop { } }
//~^ ERROR cannot find attribute macro `lt_fn` in this scope
//~^ ERROR cannot find attribute `lt_fn` in this scope
fn f_ty<#[ty_fn] O>(_: O) { }
//~^ ERROR cannot find attribute macro `ty_fn` in this scope
//~^ ERROR cannot find attribute `ty_fn` in this scope

impl<I> StTy<I> {
fn m_lt<#[lt_meth] 'h>(_: &'h [u32]) -> &'h u32 { loop { } }
//~^ ERROR cannot find attribute macro `lt_meth` in this scope
//~^ ERROR cannot find attribute `lt_meth` in this scope
fn m_ty<#[ty_meth] P>(_: P) { }
//~^ ERROR cannot find attribute macro `ty_meth` in this scope
//~^ ERROR cannot find attribute `ty_meth` in this scope
}

fn hof_lt<Q>(_: Q)
where Q: for <#[lt_hof] 'i> Fn(&'i [u32]) -> &'i u32
//~^ ERROR cannot find attribute macro `lt_hof` in this scope
//~^ ERROR cannot find attribute `lt_hof` in this scope
{
}

0 comments on commit 42a19dd

Please sign in to comment.
You can’t perform that action at this time.