Skip to content

Commit 13c8e76

Browse files
author
Jonathan Turner
authored
Rollup merge of rust-lang#36787 - jseyfried:fix_test_harness_reexport_errors, r=nrc
Avoid re-export errors in the generated test harness Fixes rust-lang#36768. r? @nrc
2 parents 45fd062 + 28393be commit 13c8e76

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

src/librustc_resolve/resolve_imports.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -683,9 +683,8 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
683683
};
684684

685685
match (value_result, type_result) {
686-
// With `#![feature(item_like_imports)]`, all namespaces
687-
// must be re-exported with extra visibility for an error to occur.
688-
(Ok(value_binding), Ok(type_binding)) if self.new_import_semantics => {
686+
// All namespaces must be re-exported with extra visibility for an error to occur.
687+
(Ok(value_binding), Ok(type_binding)) => {
689688
let vis = directive.vis.get();
690689
if !value_binding.pseudo_vis().is_at_least(vis, self) &&
691690
!type_binding.pseudo_vis().is_at_least(vis, self) {

src/libsyntax/test.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use std::iter;
1919
use std::slice;
2020
use std::mem;
2121
use std::vec;
22-
use attr;
22+
use attr::{self, HasAttrs};
2323
use syntax_pos::{self, DUMMY_SP, NO_EXPANSION, Span, FileMap, BytePos};
2424
use std::rc::Rc;
2525

@@ -226,12 +226,20 @@ fn mk_reexport_mod(cx: &mut TestCtxt, parent: ast::NodeId, tests: Vec<ast::Ident
226226
tested_submods: Vec<(ast::Ident, ast::Ident)>) -> (P<ast::Item>, ast::Ident) {
227227
let super_ = token::str_to_ident("super");
228228

229+
// Generate imports with `#[allow(private_in_public)]` to work around issue #36768.
230+
let allow_private_in_public = cx.ext_cx.attribute(DUMMY_SP, cx.ext_cx.meta_list(
231+
DUMMY_SP,
232+
InternedString::new("allow"),
233+
vec![cx.ext_cx.meta_list_item_word(DUMMY_SP, InternedString::new("private_in_public"))],
234+
));
229235
let items = tests.into_iter().map(|r| {
230236
cx.ext_cx.item_use_simple(DUMMY_SP, ast::Visibility::Public,
231237
cx.ext_cx.path(DUMMY_SP, vec![super_, r]))
238+
.map_attrs(|_| vec![allow_private_in_public.clone()])
232239
}).chain(tested_submods.into_iter().map(|(r, sym)| {
233240
let path = cx.ext_cx.path(DUMMY_SP, vec![super_, r, sym]);
234241
cx.ext_cx.item_use_simple_(DUMMY_SP, ast::Visibility::Public, r, path)
242+
.map_attrs(|_| vec![allow_private_in_public.clone()])
235243
})).collect();
236244

237245
let reexport_mod = ast::Mod {

src/test/run-pass/issue-36768.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2016 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+
// compile-flags:--test
12+
#![deny(private_in_public)]
13+
14+
#[test] fn foo() {}
15+
mod foo {}
16+
17+
#[test] fn core() {}
18+
extern crate core;

0 commit comments

Comments
 (0)