diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs
index 2e6de96d65a6..57978ca9c80a 100644
--- a/src/libsyntax/ext/build.rs
+++ b/src/libsyntax/ext/build.rs
@@ -319,14 +319,8 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
types: Vec
>,
bindings: Vec )
-> ast::Path {
- use syntax::parse::token;
-
let last_identifier = idents.pop().unwrap();
let mut segments: Vec = Vec::new();
- if global &&
- !idents.first().map_or(false, |&ident| token::Ident(ident).is_path_segment_keyword()) {
- segments.push(ast::PathSegment::crate_root(span));
- }
segments.extend(idents.into_iter().map(|i| ast::PathSegment::from_ident(i, span)));
let parameters = if !lifetimes.is_empty() || !types.is_empty() || !bindings.is_empty() {
@@ -335,7 +329,9 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
None
};
segments.push(ast::PathSegment { identifier: last_identifier, span, parameters });
- ast::Path { span, segments }
+ let path = ast::Path { span, segments };
+
+ if global { path.default_to_global() } else { path }
}
/// Constructs a qualified path.
diff --git a/src/libsyntax/test.rs b/src/libsyntax/test.rs
index 094de6868a50..6cbb7ab393fa 100644
--- a/src/libsyntax/test.rs
+++ b/src/libsyntax/test.rs
@@ -733,9 +733,12 @@ fn mk_test_desc_and_fn_rec(cx: &TestCtxt, test: &Test) -> P {
field("should_panic", fail_expr),
field("allow_fail", allow_fail_expr)]);
-
- let mut visible_path = match cx.toplevel_reexport {
- Some(id) => vec![id],
+ let mut visible_path = vec![];
+ if cx.features.extern_absolute_paths {
+ visible_path.push(keywords::Crate.ident());
+ }
+ match cx.toplevel_reexport {
+ Some(id) => visible_path.push(id),
None => {
let diag = cx.span_diagnostic;
diag.bug("expected to find top-level re-export name, but found None");
diff --git a/src/test/run-pass/rfc-2126-extern-absolute-paths/test.rs b/src/test/run-pass/rfc-2126-extern-absolute-paths/test.rs
new file mode 100644
index 000000000000..796f652d6b57
--- /dev/null
+++ b/src/test/run-pass/rfc-2126-extern-absolute-paths/test.rs
@@ -0,0 +1,21 @@
+// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 or the MIT license
+// , at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// Check that `#[test]` works with extern-absolute-paths enabled.
+//
+// Regression test for #47075.
+
+// compile-flags: --test
+
+#![feature(extern_absolute_paths)]
+
+#[test]
+fn test() {
+}