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

Lines changed: 3 additions & 4 deletions
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

Lines changed: 7 additions & 0 deletions
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",
Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 5 additions & 5 deletions
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

Lines changed: 5 additions & 5 deletions
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>() {}

0 commit comments

Comments
 (0)