Skip to content

Commit 5088611

Browse files
committed
Address review comments
Adjust a few fulldeps and pretty-printing tests Fix rebase
1 parent cb64672 commit 5088611

13 files changed

+60
-84
lines changed

src/librustc_resolve/macros.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,9 @@ impl<'a, 'crateloader: 'a> base::Resolver for Resolver<'a, 'crateloader> {
329329
self.report_proc_macro_stub(invoc.span());
330330
return Err(Determinacy::Determined);
331331
} else if let Def::NonMacroAttr(attr_kind) = def {
332+
// Note that not only attributes, but anything in macro namespace can result in a
333+
// `Def::NonMacroAttr` definition (e.g. `inline!()`), so we must report the error
334+
// below for these cases.
332335
let is_attr_invoc =
333336
if let InvocationKind::Attr { .. } = invoc.kind { true } else { false };
334337
let path = invoc.path().expect("no path for non-macro attr");
@@ -604,7 +607,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
604607
// 3. Builtin attributes (closed, controlled).
605608

606609
assert!(ns == TypeNS || ns == MacroNS);
607-
let force = force || record_used;
610+
assert!(force || !record_used); // `record_used` implies `force`
608611
ident = ident.modern();
609612

610613
// Names from inner scope that can't shadow names from outer scopes, e.g.
@@ -789,7 +792,10 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
789792

790793
let determinacy = Determinacy::determined(force);
791794
if determinacy == Determinacy::Determined && is_attr {
792-
// For attributes interpret determinate "no solution" as a custom attribute.
795+
// For single-segment attributes interpret determinate "no resolution" as a custom
796+
// attribute. (Lexical resolution implies the first segment and is_attr should imply
797+
// the last segment, so we are certainly working with a single-segment attribute here.)
798+
assert!(ns == MacroNS);
793799
let binding = (Def::NonMacroAttr(NonMacroAttrKind::Custom),
794800
ty::Visibility::Public, ident.span, Mark::root())
795801
.to_name_binding(self.arenas);

src/libsyntax/ext/expand.rs

+12-22
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,15 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
516516
}
517517

518518
fn expand_invoc(&mut self, invoc: Invocation, ext: &SyntaxExtension) -> Option<AstFragment> {
519+
if invoc.fragment_kind == AstFragmentKind::ForeignItems &&
520+
!self.cx.ecfg.macros_in_extern_enabled() {
521+
if let SyntaxExtension::NonMacroAttr { .. } = *ext {} else {
522+
emit_feature_err(&self.cx.parse_sess, "macros_in_extern",
523+
invoc.span(), GateIssue::Language,
524+
"macro invocations in `extern {}` blocks are experimental");
525+
}
526+
}
527+
519528
let result = match invoc.kind {
520529
InvocationKind::Bang { .. } => self.expand_bang_invoc(invoc, ext)?,
521530
InvocationKind::Attr { .. } => self.expand_attr_invoc(invoc, ext)?,
@@ -549,6 +558,8 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
549558
};
550559

551560
if let NonMacroAttr { mark_used: false } = *ext {} else {
561+
// Macro attrs are always used when expanded,
562+
// non-macro attrs are considered used when the field says so.
552563
attr::mark_used(&attr);
553564
}
554565
invoc.expansion_data.mark.set_expn_info(ExpnInfo {
@@ -1482,34 +1493,14 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> {
14821493
foreign_item: ast::ForeignItem) -> SmallVector<ast::ForeignItem> {
14831494
let (attr, traits, foreign_item) = self.classify_item(foreign_item);
14841495

1485-
let explain = if self.cx.ecfg.use_extern_macros_enabled() {
1486-
feature_gate::EXPLAIN_PROC_MACROS_IN_EXTERN
1487-
} else {
1488-
feature_gate::EXPLAIN_MACROS_IN_EXTERN
1489-
};
1490-
1491-
if attr.is_some() || !traits.is_empty() {
1492-
if !self.cx.ecfg.macros_in_extern_enabled() &&
1493-
!self.cx.ecfg.custom_attribute_enabled() {
1494-
if let Some(ref attr) = attr {
1495-
emit_feature_err(&self.cx.parse_sess, "macros_in_extern", attr.span,
1496-
GateIssue::Language, explain);
1497-
}
1498-
}
1499-
1496+
if attr.is_some() || !traits.is_empty() {
15001497
let item = Annotatable::ForeignItem(P(foreign_item));
15011498
return self.collect_attr(attr, traits, item, AstFragmentKind::ForeignItems)
15021499
.make_foreign_items();
15031500
}
15041501

15051502
if let ast::ForeignItemKind::Macro(mac) = foreign_item.node {
15061503
self.check_attributes(&foreign_item.attrs);
1507-
1508-
if !self.cx.ecfg.macros_in_extern_enabled() {
1509-
emit_feature_err(&self.cx.parse_sess, "macros_in_extern", foreign_item.span,
1510-
GateIssue::Language, explain);
1511-
}
1512-
15131504
return self.collect_bang(mac, foreign_item.span, AstFragmentKind::ForeignItems)
15141505
.make_foreign_items();
15151506
}
@@ -1671,7 +1662,6 @@ impl<'feat> ExpansionConfig<'feat> {
16711662
fn enable_custom_derive = custom_derive,
16721663
fn enable_format_args_nl = format_args_nl,
16731664
fn macros_in_extern_enabled = macros_in_extern,
1674-
fn custom_attribute_enabled = custom_attribute,
16751665
fn proc_macro_mod = proc_macro_mod,
16761666
fn proc_macro_gen = proc_macro_gen,
16771667
fn proc_macro_expr = proc_macro_expr,

src/libsyntax/feature_gate.rs

-8
Original file line numberDiff line numberDiff line change
@@ -1354,13 +1354,6 @@ pub const EXPLAIN_UNSIZED_TUPLE_COERCION: &'static str =
13541354
pub const EXPLAIN_MACRO_AT_MOST_ONCE_REP: &'static str =
13551355
"using the `?` macro Kleene operator for \"at most one\" repetition is unstable";
13561356

1357-
pub const EXPLAIN_MACROS_IN_EXTERN: &'static str =
1358-
"macro invocations in `extern {}` blocks are experimental.";
1359-
1360-
// mention proc-macros when enabled
1361-
pub const EXPLAIN_PROC_MACROS_IN_EXTERN: &'static str =
1362-
"macro and proc-macro invocations in `extern {}` blocks are experimental.";
1363-
13641357
struct PostExpansionVisitor<'a> {
13651358
context: &'a Context<'a>,
13661359
}
@@ -1969,7 +1962,6 @@ pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute],
19691962
).emit();
19701963
} else {
19711964
set(&mut features, mi.span);
1972-
feature_checker.collect(&features, mi.span);
19731965
features.declared_lang_features.push((name, mi.span, None));
19741966
}
19751967
continue

src/test/compile-fail-fulldeps/proc-macro/issue-41211.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
#![feature(use_extern_macros)]
1717
#![emit_unchanged]
18-
//~^ ERROR: cannot find attribute macro `emit_unchanged` in this scope
18+
//~^ ERROR attribute `emit_unchanged` is currently unknown to the compiler
1919
extern crate issue_41211;
2020
use issue_41211::emit_unchanged;
2121

src/test/compile-fail-fulldeps/proc-macro/macros-in-extern.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ fn main() {
2626
#[link(name = "rust_test_helpers", kind = "static")]
2727
extern {
2828
#[no_output]
29-
//~^ ERROR macro and proc-macro invocations in `extern {}` blocks are experimental.
29+
//~^ ERROR macro invocations in `extern {}` blocks are experimental
3030
fn some_definitely_unknown_symbol_which_should_be_removed();
3131

3232
#[nop_attr]
33-
//~^ ERROR macro and proc-macro invocations in `extern {}` blocks are experimental.
33+
//~^ ERROR macro invocations in `extern {}` blocks are experimental
3434
fn rust_get_test_int() -> isize;
3535

3636
emit_input!(fn rust_dbg_extern_identity_u32(arg: u32) -> u32;);
37-
//~^ ERROR macro and proc-macro invocations in `extern {}` blocks are experimental.
37+
//~^ ERROR macro invocations in `extern {}` blocks are experimental
3838
}

src/test/compile-fail/macros-in-extern.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ fn main() {
3434
#[link(name = "rust_test_helpers", kind = "static")]
3535
extern {
3636
returns_isize!(rust_get_test_int);
37-
//~^ ERROR macro invocations in `extern {}` blocks are experimental.
37+
//~^ ERROR macro invocations in `extern {}` blocks are experimental
3838
takes_u32_returns_u32!(rust_dbg_extern_identity_u32);
39-
//~^ ERROR macro invocations in `extern {}` blocks are experimental.
39+
//~^ ERROR macro invocations in `extern {}` blocks are experimental
4040
emits_nothing!();
41-
//~^ ERROR macro invocations in `extern {}` blocks are experimental.
41+
//~^ ERROR macro invocations in `extern {}` blocks are experimental
4242
}

src/test/pretty/attr-literals.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ fn main() {
1818
#[align = 8]
1919
fn f() { }
2020

21-
#[vec(1, 2, 3)]
21+
#[vector(1, 2, 3)]
2222
fn g() { }
2323
}

src/test/ui-fulldeps/resolve-error.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// aux-build:attr_proc_macro.rs
1414
// aux-build:bang_proc_macro.rs
1515

16-
#![feature(use_extern_macros)]
16+
#![feature(custom_attribute)]
1717

1818
#[macro_use]
1919
extern crate derive_foo;
@@ -37,12 +37,10 @@ macro_rules! attr_proc_mac {
3737
//~^ ERROR cannot find
3838
struct Foo;
3939

40-
#[attr_proc_macra]
41-
//~^ ERROR cannot find
40+
#[attr_proc_macra] // OK, interpreted as a custom attribute
4241
struct Bar;
4342

44-
#[FooWithLongNan]
45-
//~^ ERROR cannot find
43+
#[FooWithLongNan] // OK, interpreted as a custom attribute
4644
struct Asdf;
4745

4846
#[derive(Dlone)]

src/test/ui-fulldeps/resolve-error.stderr

+8-20
Original file line numberDiff line numberDiff line change
@@ -4,59 +4,47 @@ error: cannot find derive macro `FooWithLongNan` in this scope
44
LL | #[derive(FooWithLongNan)]
55
| ^^^^^^^^^^^^^^ help: try: `FooWithLongName`
66

7-
error: cannot find attribute macro `attr_proc_macra` in this scope
8-
--> $DIR/resolve-error.rs:40:3
9-
|
10-
LL | #[attr_proc_macra]
11-
| ^^^^^^^^^^^^^^^ help: try: `attr_proc_macro`
12-
13-
error: cannot find attribute macro `FooWithLongNan` in this scope
14-
--> $DIR/resolve-error.rs:44:3
15-
|
16-
LL | #[FooWithLongNan]
17-
| ^^^^^^^^^^^^^^
18-
197
error: cannot find derive macro `Dlone` in this scope
20-
--> $DIR/resolve-error.rs:48:10
8+
--> $DIR/resolve-error.rs:46:10
219
|
2210
LL | #[derive(Dlone)]
2311
| ^^^^^ help: try: `Clone`
2412

2513
error: cannot find derive macro `Dlona` in this scope
26-
--> $DIR/resolve-error.rs:52:10
14+
--> $DIR/resolve-error.rs:50:10
2715
|
2816
LL | #[derive(Dlona)]
2917
| ^^^^^ help: try: `Clona`
3018

3119
error: cannot find derive macro `attr_proc_macra` in this scope
32-
--> $DIR/resolve-error.rs:56:10
20+
--> $DIR/resolve-error.rs:54:10
3321
|
3422
LL | #[derive(attr_proc_macra)]
3523
| ^^^^^^^^^^^^^^^
3624

3725
error: cannot find macro `FooWithLongNama!` in this scope
38-
--> $DIR/resolve-error.rs:61:5
26+
--> $DIR/resolve-error.rs:59:5
3927
|
4028
LL | FooWithLongNama!();
4129
| ^^^^^^^^^^^^^^^ help: you could try the macro: `FooWithLongNam`
4230

4331
error: cannot find macro `attr_proc_macra!` in this scope
44-
--> $DIR/resolve-error.rs:64:5
32+
--> $DIR/resolve-error.rs:62:5
4533
|
4634
LL | attr_proc_macra!();
4735
| ^^^^^^^^^^^^^^^ help: you could try the macro: `attr_proc_mac`
4836

4937
error: cannot find macro `Dlona!` in this scope
50-
--> $DIR/resolve-error.rs:67:5
38+
--> $DIR/resolve-error.rs:65:5
5139
|
5240
LL | Dlona!();
5341
| ^^^^^
5442

5543
error: cannot find macro `bang_proc_macrp!` in this scope
56-
--> $DIR/resolve-error.rs:70:5
44+
--> $DIR/resolve-error.rs:68:5
5745
|
5846
LL | bang_proc_macrp!();
5947
| ^^^^^^^^^^^^^^^ help: you could try the macro: `bang_proc_macro`
6048

61-
error: aborting due to 10 previous errors
49+
error: aborting due to 8 previous errors
6250

Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -8,18 +8,11 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// aux-build:attr_proc_macro.rs
12-
// ignore-tidy-linelength
11+
// Unresolved multi-segment attributes are not treated as custom.
1312

14-
#![feature(custom_attribute)]
15-
//~^ ERROR Cannot use `#![feature(use_extern_macros)]` and `#![feature(custom_attribute)] at the same time
13+
#![feature(custom_attribute, proc_macro_path_invoc)]
1614

17-
extern crate attr_proc_macro;
18-
use attr_proc_macro::attr_proc_macro;
15+
mod existent {}
1916

20-
#[attr_proc_macro]
21-
fn foo() {}
22-
23-
fn main() {
24-
foo();
25-
}
17+
#[existent::nonexistent] //~ ERROR failed to resolve. Could not find `nonexistent` in `existent`
18+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0433]: failed to resolve. Could not find `nonexistent` in `existent`
2+
--> $DIR/custom-attribute-multisegment.rs:17:13
3+
|
4+
LL | #[existent::nonexistent] //~ ERROR failed to resolve. Could not find `nonexistent` in `existent`
5+
| ^^^^^^^^^^^ Could not find `nonexistent` in `existent`
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0433`.

src/test/ui/feature-gate-macros_in_extern.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ macro_rules! emits_nothing(
2727
#[link(name = "rust_test_helpers", kind = "static")]
2828
extern {
2929
returns_isize!(rust_get_test_int);
30-
//~^ ERROR macro invocations in `extern {}` blocks are experimental.
30+
//~^ ERROR macro invocations in `extern {}` blocks are experimental
3131
takes_u32_returns_u32!(rust_dbg_extern_identity_u32);
32-
//~^ ERROR macro invocations in `extern {}` blocks are experimental.
32+
//~^ ERROR macro invocations in `extern {}` blocks are experimental
3333
emits_nothing!();
34-
//~^ ERROR macro invocations in `extern {}` blocks are experimental.
34+
//~^ ERROR macro invocations in `extern {}` blocks are experimental
3535
}

src/test/ui/feature-gate-macros_in_extern.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
error[E0658]: macro and proc-macro invocations in `extern {}` blocks are experimental. (see issue #49476)
1+
error[E0658]: macro invocations in `extern {}` blocks are experimental (see issue #49476)
22
--> $DIR/feature-gate-macros_in_extern.rs:29:5
33
|
44
LL | returns_isize!(rust_get_test_int);
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
77
= help: add #![feature(macros_in_extern)] to the crate attributes to enable
88

9-
error[E0658]: macro and proc-macro invocations in `extern {}` blocks are experimental. (see issue #49476)
9+
error[E0658]: macro invocations in `extern {}` blocks are experimental (see issue #49476)
1010
--> $DIR/feature-gate-macros_in_extern.rs:31:5
1111
|
1212
LL | takes_u32_returns_u32!(rust_dbg_extern_identity_u32);
1313
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1414
|
1515
= help: add #![feature(macros_in_extern)] to the crate attributes to enable
1616

17-
error[E0658]: macro and proc-macro invocations in `extern {}` blocks are experimental. (see issue #49476)
17+
error[E0658]: macro invocations in `extern {}` blocks are experimental (see issue #49476)
1818
--> $DIR/feature-gate-macros_in_extern.rs:33:5
1919
|
2020
LL | emits_nothing!();

0 commit comments

Comments
 (0)