Skip to content

Commit 0625d4c

Browse files
committed
begin crate-relative paths with crate
1 parent 1eab1b1 commit 0625d4c

File tree

3 files changed

+30
-10
lines changed

3 files changed

+30
-10
lines changed

src/libsyntax/ext/build.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -319,14 +319,8 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
319319
types: Vec<P<ast::Ty>>,
320320
bindings: Vec<ast::TypeBinding> )
321321
-> ast::Path {
322-
use syntax::parse::token;
323-
324322
let last_identifier = idents.pop().unwrap();
325323
let mut segments: Vec<ast::PathSegment> = Vec::new();
326-
if global &&
327-
!idents.first().map_or(false, |&ident| token::Ident(ident).is_path_segment_keyword()) {
328-
segments.push(ast::PathSegment::crate_root(span));
329-
}
330324

331325
segments.extend(idents.into_iter().map(|i| ast::PathSegment::from_ident(i, span)));
332326
let parameters = if !lifetimes.is_empty() || !types.is_empty() || !bindings.is_empty() {
@@ -335,7 +329,9 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
335329
None
336330
};
337331
segments.push(ast::PathSegment { identifier: last_identifier, span, parameters });
338-
ast::Path { span, segments }
332+
let path = ast::Path { span, segments };
333+
334+
if global { path.default_to_global() } else { path }
339335
}
340336

341337
/// Constructs a qualified path.

src/libsyntax/test.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -733,9 +733,12 @@ fn mk_test_desc_and_fn_rec(cx: &TestCtxt, test: &Test) -> P<ast::Expr> {
733733
field("should_panic", fail_expr),
734734
field("allow_fail", allow_fail_expr)]);
735735

736-
737-
let mut visible_path = match cx.toplevel_reexport {
738-
Some(id) => vec![id],
736+
let mut visible_path = vec![];
737+
if cx.features.extern_absolute_paths {
738+
visible_path.push(keywords::Crate.ident());
739+
}
740+
match cx.toplevel_reexport {
741+
Some(id) => visible_path.push(id),
739742
None => {
740743
let diag = cx.span_diagnostic;
741744
diag.bug("expected to find top-level re-export name, but found None");
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Check that `#[test]` works with extern-absolute-paths enabled.
12+
//
13+
// Regression test for #47075.
14+
15+
// compile-flags: --test
16+
17+
#![feature(extern_absolute_paths)]
18+
19+
#[test]
20+
fn test() {
21+
}

0 commit comments

Comments
 (0)