Skip to content

Commit

Permalink
Auto merge of #64483 - petrochenkov:expectattr2, r=Centril
Browse files Browse the repository at this point in the history
resolve: Tweak some "cannot find" wording for macros
  • Loading branch information
bors committed Sep 15, 2019
2 parents 117cdf3 + f7f8d65 commit 60895fd
Show file tree
Hide file tree
Showing 64 changed files with 169 additions and 163 deletions.
7 changes: 3 additions & 4 deletions src/librustc_resolve/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -774,9 +774,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);
let mut err = self.session.struct_span_err(ident.span, &msg);
self.unresolved_macro_suggestions(&mut err, kind, &parent_scope, ident);
err.emit();
Expand Down
7 changes: 7 additions & 0 deletions src/libsyntax_pos/hygiene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/attributes/obsolete-attr.rs
Original file line number Diff line number Diff line change
@@ -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() {}
4 changes: 2 additions & 2 deletions src/test/ui/attributes/obsolete-attr.stderr
Original file line number Diff line number Diff line change
@@ -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 {}
Expand Down
6 changes: 3 additions & 3 deletions src/test/ui/attributes/unknown-attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions src/test/ui/attributes/unknown-attr.stderr
Original file line number Diff line number Diff line change
@@ -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() {}
Expand Down
Original file line number Diff line number Diff line change
@@ -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() {}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down
10 changes: 5 additions & 5 deletions src/test/ui/conditional-compilation/cfg-generic-params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>();
Expand Down
10 changes: 5 additions & 5 deletions src/test/ui/conditional-compilation/cfg-generic-params.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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>() {}
Expand Down
6 changes: 3 additions & 3 deletions src/test/ui/custom_attribute.rs
Original file line number Diff line number Diff line change
@@ -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
}
6 changes: 3 additions & 3 deletions src/test/ui/custom_attribute.stderr
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/empty/empty-macro-use.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: cannot find macro `macro_two!` in this scope
error: cannot find macro `macro_two` in this scope
--> $DIR/empty-macro-use.rs:7:5
|
LL | macro_two!();
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/ext-nonexistent.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: cannot find macro `iamnotanextensionthatexists!` in this scope
error: cannot find macro `iamnotanextensionthatexists` in this scope
--> $DIR/ext-nonexistent.rs:2:13
|
LL | fn main() { iamnotanextensionthatexists!(""); }
Expand Down
26 changes: 13 additions & 13 deletions src/test/ui/feature-gates/feature-gate-custom_attribute.rs
Original file line number Diff line number Diff line change
@@ -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() {}
26 changes: 13 additions & 13 deletions src/test/ui/feature-gates/feature-gate-custom_attribute.stderr
Original file line number Diff line number Diff line change
@@ -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")]
Expand Down
Loading

0 comments on commit 60895fd

Please sign in to comment.