begin crate-relative paths with `crate`

This commit is contained in:
Niko Matsakis 2018-02-11 09:28:47 -05:00
parent 1eab1b19a3
commit 0625d4c282
3 changed files with 30 additions and 10 deletions

View File

@ -319,14 +319,8 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
types: Vec<P<ast::Ty>>,
bindings: Vec<ast::TypeBinding> )
-> ast::Path {
use syntax::parse::token;
let last_identifier = idents.pop().unwrap();
let mut segments: Vec<ast::PathSegment> = 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.

View File

@ -733,9 +733,12 @@ fn mk_test_desc_and_fn_rec(cx: &TestCtxt, test: &Test) -> P<ast::Expr> {
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");

View File

@ -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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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() {
}