Skip to content

Commit 60895fd

Browse files
committed
Auto merge of #64483 - petrochenkov:expectattr2, r=Centril
resolve: Tweak some "cannot find" wording for macros
2 parents 117cdf3 + f7f8d65 commit 60895fd

File tree

64 files changed

+169
-163
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+169
-163
lines changed

src/librustc_resolve/macros.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ impl<'a> Resolver<'a> {
323323
self.check_stability_and_deprecation(&ext, path);
324324

325325
Ok(if ext.macro_kind() != kind {
326-
let expected = if kind == MacroKind::Attr { "attribute" } else { kind.descr() };
326+
let expected = kind.descr_expected();
327327
let msg = format!("expected {}, found {} `{}`", expected, res.descr(), path);
328328
self.session.struct_span_err(path.span, &msg)
329329
.span_label(path.span, format!("not {} {}", kind.article(), expected))
@@ -774,9 +774,8 @@ impl<'a> Resolver<'a> {
774774
}
775775
Err(..) => {
776776
assert!(initial_binding.is_none());
777-
let bang = if kind == MacroKind::Bang { "!" } else { "" };
778-
let msg =
779-
format!("cannot find {} `{}{}` in this scope", kind.descr(), ident, bang);
777+
let expected = kind.descr_expected();
778+
let msg = format!("cannot find {} `{}` in this scope", expected, ident);
780779
let mut err = self.session.struct_span_err(ident.span, &msg);
781780
self.unresolved_macro_suggestions(&mut err, kind, &parent_scope, ident);
782781
err.emit();

src/libsyntax_pos/hygiene.rs

+7
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,13 @@ impl MacroKind {
677677
}
678678
}
679679

680+
pub fn descr_expected(self) -> &'static str {
681+
match self {
682+
MacroKind::Attr => "attribute",
683+
_ => self.descr(),
684+
}
685+
}
686+
680687
pub fn article(self) -> &'static str {
681688
match self {
682689
MacroKind::Attr => "an",
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// Obsolete attributes fall back to unstable custom attributes.
22

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

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

99
fn main() {}

src/test/ui/attributes/obsolete-attr.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
error: cannot find attribute macro `fixed_stack_segment` in this scope
1+
error: cannot find attribute `fixed_stack_segment` in this scope
22
--> $DIR/obsolete-attr.rs:6:3
33
|
44
LL | #[fixed_stack_segment] fn f() {}
55
| ^^^^^^^^^^^^^^^^^^^
66

7-
error: cannot find attribute macro `ab_isize` in this scope
7+
error: cannot find attribute `ab_isize` in this scope
88
--> $DIR/obsolete-attr.rs:3:3
99
|
1010
LL | #[ab_isize="stdcall"] extern {}

src/test/ui/attributes/unknown-attr.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
#![feature(custom_inner_attributes)]
44

55
#![mutable_doc]
6-
//~^ ERROR cannot find attribute macro `mutable_doc` in this scope
6+
//~^ ERROR cannot find attribute `mutable_doc` in this scope
77

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

1111
#[dance] fn main() {}
12-
//~^ ERROR cannot find attribute macro `dance` in this scope
12+
//~^ ERROR cannot find attribute `dance` in this scope

src/test/ui/attributes/unknown-attr.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
error: cannot find attribute macro `mutable_doc` in this scope
1+
error: cannot find attribute `mutable_doc` in this scope
22
--> $DIR/unknown-attr.rs:5:4
33
|
44
LL | #![mutable_doc]
55
| ^^^^^^^^^^^
66

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

13-
error: cannot find attribute macro `dance` in this scope
13+
error: cannot find attribute `dance` in this scope
1414
--> $DIR/unknown-attr.rs:11:3
1515
|
1616
LL | #[dance] fn main() {}

src/test/ui/conditional-compilation/cfg-attr-unknown-attribute-macro-expansion.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
macro_rules! foo {
22
() => {
33
#[cfg_attr(all(), unknown)]
4-
//~^ ERROR cannot find attribute macro `unknown` in this scope
4+
//~^ ERROR cannot find attribute `unknown` in this scope
55
fn foo() {}
66
}
77
}

src/test/ui/conditional-compilation/cfg-attr-unknown-attribute-macro-expansion.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: cannot find attribute macro `unknown` in this scope
1+
error: cannot find attribute `unknown` in this scope
22
--> $DIR/cfg-attr-unknown-attribute-macro-expansion.rs:3:27
33
|
44
LL | #[cfg_attr(all(), unknown)]

src/test/ui/conditional-compilation/cfg-generic-params.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,22 @@ struct WhereBad where for<#[cfg(no)] 'a, #[cfg(yes)] T> u8: Copy;
1717

1818
fn f_lt_no<#[cfg_attr(no, unknown)] 'a>() {} // OK
1919
fn f_lt_yes<#[cfg_attr(yes, unknown)] 'a>() {}
20-
//~^ ERROR cannot find attribute macro `unknown` in this scope
20+
//~^ ERROR cannot find attribute `unknown` in this scope
2121
fn f_ty_no<#[cfg_attr(no, unknown)] T>() {} // OK
2222
fn f_ty_yes<#[cfg_attr(yes, unknown)] T>() {}
23-
//~^ ERROR cannot find attribute macro `unknown` in this scope
23+
//~^ ERROR cannot find attribute `unknown` in this scope
2424

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

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

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

3737
fn main() {
3838
f_lt::<'static>();

src/test/ui/conditional-compilation/cfg-generic-params.stderr

+5-5
Original file line numberDiff line numberDiff line change
@@ -16,31 +16,31 @@ error: only lifetime parameters can be used in this context
1616
LL | struct WhereBad where for<#[cfg(no)] 'a, #[cfg(yes)] T> u8: Copy;
1717
| ^
1818

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

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

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

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

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

src/test/ui/custom_attribute.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#![feature(stmt_expr_attributes)]
22

3-
#[foo] //~ ERROR cannot find attribute macro `foo` in this scope
3+
#[foo] //~ ERROR cannot find attribute `foo` in this scope
44
fn main() {
5-
#[foo] //~ ERROR cannot find attribute macro `foo` in this scope
5+
#[foo] //~ ERROR cannot find attribute `foo` in this scope
66
let x = ();
7-
#[foo] //~ ERROR cannot find attribute macro `foo` in this scope
7+
#[foo] //~ ERROR cannot find attribute `foo` in this scope
88
x
99
}

src/test/ui/custom_attribute.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
error: cannot find attribute macro `foo` in this scope
1+
error: cannot find attribute `foo` in this scope
22
--> $DIR/custom_attribute.rs:3:3
33
|
44
LL | #[foo]
55
| ^^^
66

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

13-
error: cannot find attribute macro `foo` in this scope
13+
error: cannot find attribute `foo` in this scope
1414
--> $DIR/custom_attribute.rs:7:7
1515
|
1616
LL | #[foo]

src/test/ui/empty/empty-macro-use.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: cannot find macro `macro_two!` in this scope
1+
error: cannot find macro `macro_two` in this scope
22
--> $DIR/empty-macro-use.rs:7:5
33
|
44
LL | macro_two!();

src/test/ui/ext-nonexistent.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: cannot find macro `iamnotanextensionthatexists!` in this scope
1+
error: cannot find macro `iamnotanextensionthatexists` in this scope
22
--> $DIR/ext-nonexistent.rs:2:13
33
|
44
LL | fn main() { iamnotanextensionthatexists!(""); }
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
// Check that literals in attributes parse just fine.
22

3-
#[fake_attr] //~ ERROR cannot find attribute macro `fake_attr` in this scope
4-
#[fake_attr(100)] //~ ERROR cannot find attribute macro `fake_attr` in this scope
5-
#[fake_attr(1, 2, 3)] //~ ERROR cannot find attribute macro `fake_attr` in this scope
6-
#[fake_attr("hello")] //~ ERROR cannot find attribute macro `fake_attr` in this scope
7-
#[fake_attr(name = "hello")] //~ ERROR cannot find attribute macro `fake_attr` in this scope
8-
#[fake_attr(1, "hi", key = 12, true, false)] //~ ERROR cannot find attribute macro `fake_attr` in th
9-
#[fake_attr(key = "hello", val = 10)] //~ ERROR cannot find attribute macro `fake_attr` in this scop
10-
#[fake_attr(key("hello"), val(10))] //~ ERROR cannot find attribute macro `fake_attr` in this scope
11-
#[fake_attr(enabled = true, disabled = false)] //~ ERROR cannot find attribute macro `fake_attr` in
12-
#[fake_attr(true)] //~ ERROR cannot find attribute macro `fake_attr` in this scope
13-
#[fake_attr(pi = 3.14159)] //~ ERROR cannot find attribute macro `fake_attr` in this scope
14-
#[fake_attr(b"hi")] //~ ERROR cannot find attribute macro `fake_attr` in this scope
15-
#[fake_doc(r"doc")] //~ ERROR cannot find attribute macro `fake_doc` in this scope
3+
#[fake_attr] //~ ERROR cannot find attribute `fake_attr` in this scope
4+
#[fake_attr(100)] //~ ERROR cannot find attribute `fake_attr` in this scope
5+
#[fake_attr(1, 2, 3)] //~ ERROR cannot find attribute `fake_attr` in this scope
6+
#[fake_attr("hello")] //~ ERROR cannot find attribute `fake_attr` in this scope
7+
#[fake_attr(name = "hello")] //~ ERROR cannot find attribute `fake_attr` in this scope
8+
#[fake_attr(1, "hi", key = 12, true, false)] //~ ERROR cannot find attribute `fake_attr` in th
9+
#[fake_attr(key = "hello", val = 10)] //~ ERROR cannot find attribute `fake_attr` in this scop
10+
#[fake_attr(key("hello"), val(10))] //~ ERROR cannot find attribute `fake_attr` in this scope
11+
#[fake_attr(enabled = true, disabled = false)] //~ ERROR cannot find attribute `fake_attr` in
12+
#[fake_attr(true)] //~ ERROR cannot find attribute `fake_attr` in this scope
13+
#[fake_attr(pi = 3.14159)] //~ ERROR cannot find attribute `fake_attr` in this scope
14+
#[fake_attr(b"hi")] //~ ERROR cannot find attribute `fake_attr` in this scope
15+
#[fake_doc(r"doc")] //~ ERROR cannot find attribute `fake_doc` in this scope
1616
struct Q {}
1717

1818
fn main() {}

src/test/ui/feature-gates/feature-gate-custom_attribute.stderr

+13-13
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,76 @@
1-
error: cannot find attribute macro `fake_attr` in this scope
1+
error: cannot find attribute `fake_attr` in this scope
22
--> $DIR/feature-gate-custom_attribute.rs:3:3
33
|
44
LL | #[fake_attr]
55
| ^^^^^^^^^
66

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

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

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

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

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

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

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

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

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

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

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

73-
error: cannot find attribute macro `fake_doc` in this scope
73+
error: cannot find attribute `fake_doc` in this scope
7474
--> $DIR/feature-gate-custom_attribute.rs:15:3
7575
|
7676
LL | #[fake_doc(r"doc")]

0 commit comments

Comments
 (0)