Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 7 pull requests #57918

Merged
merged 17 commits into from
Jan 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# `crate_visibility_modifier`

The tracking issue for this feature is: [#45388]
The tracking issue for this feature is: [#53120]

[#45388]: https://github.com/rust-lang/rust/issues/45388
[#53120]: https://github.com/rust-lang/rust/issues/53120

-----

Expand Down
1 change: 0 additions & 1 deletion src/libcore/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,6 @@ pub const fn needs_drop<T>() -> bool {
/// assert_eq!(0, x);
/// ```
#[inline]
#[rustc_deprecated(since = "2.0.0", reason = "use `mem::MaybeUninit::zeroed` instead")]
#[stable(feature = "rust1", since = "1.0.0")]
pub unsafe fn zeroed<T>() -> T {
#[cfg(not(stage0))]
Expand Down
1 change: 1 addition & 0 deletions src/libfmt_macros/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
test(attr(deny(warnings))))]

#![feature(nll)]
#![feature(rustc_private)]

pub use self::Piece::*;
pub use self::Position::*;
Expand Down
6 changes: 1 addition & 5 deletions src/librustc_resolve/build_reduced_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use syntax::ext::base::{MacroKind, SyntaxExtension};
use syntax::ext::base::Determinacy::Undetermined;
use syntax::ext::hygiene::Mark;
use syntax::ext::tt::macro_rules;
use syntax::feature_gate::{is_builtin_attr, emit_feature_err, GateIssue};
use syntax::feature_gate::is_builtin_attr;
use syntax::parse::token::{self, Token};
use syntax::std_inject::injected_crate_name;
use syntax::symbol::keywords;
Expand Down Expand Up @@ -356,10 +356,6 @@ impl<'a> Resolver<'a> {
.emit();
return;
} else if orig_name == Some(keywords::SelfLower.name()) {
if !self.session.features_untracked().extern_crate_self {
emit_feature_err(&self.session.parse_sess, "extern_crate_self", item.span,
GateIssue::Language, "`extern crate self` is unstable");
}
self.graph_root
} else {
let crate_id = self.crate_loader.process_extern_crate(item, &self.definitions);
Expand Down
91 changes: 45 additions & 46 deletions src/librustc_resolve/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5134,60 +5134,59 @@ impl<'a> Resolver<'a> {
);

// See https://github.com/rust-lang/rust/issues/32354
if old_binding.is_import() || new_binding.is_import() {
let binding = if new_binding.is_import() && !new_binding.span.is_dummy() {
new_binding
let directive = match (&new_binding.kind, &old_binding.kind) {
(NameBindingKind::Import { directive, .. }, _) if !new_binding.span.is_dummy() =>
Some((directive, new_binding.span)),
(_, NameBindingKind::Import { directive, .. }) if !old_binding.span.is_dummy() =>
Some((directive, old_binding.span)),
_ => None,
};
if let Some((directive, binding_span)) = directive {
let suggested_name = if name.as_str().chars().next().unwrap().is_uppercase() {
format!("Other{}", name)
} else {
old_binding
format!("other_{}", name)
};

let cm = self.session.source_map();
let rename_msg = "you can use `as` to change the binding name of the import";

if let (
Ok(snippet),
NameBindingKind::Import { directive, ..},
_dummy @ false,
) = (
cm.span_to_snippet(binding.span),
binding.kind.clone(),
binding.span.is_dummy(),
) {
let suggested_name = if name.as_str().chars().next().unwrap().is_uppercase() {
format!("Other{}", name)
} else {
format!("other_{}", name)
};
let mut suggestion = None;
match directive.subclass {
ImportDirectiveSubclass::SingleImport { type_ns_only: true, .. } =>
suggestion = Some(format!("self as {}", suggested_name)),
ImportDirectiveSubclass::SingleImport { source, .. } => {
if let Some(pos) = source.span.hi().0.checked_sub(binding_span.lo().0)
.map(|pos| pos as usize) {
if let Ok(snippet) = self.session.source_map()
.span_to_snippet(binding_span) {
if pos <= snippet.len() {
suggestion = Some(format!(
"{} as {}{}",
&snippet[..pos],
suggested_name,
if snippet.ends_with(";") { ";" } else { "" }
))
}
}
}
}
ImportDirectiveSubclass::ExternCrate { source, target, .. } =>
suggestion = Some(format!(
"extern crate {} as {};",
source.unwrap_or(target.name),
suggested_name,
)),
_ => unreachable!(),
}

let rename_msg = "you can use `as` to change the binding name of the import";
if let Some(suggestion) = suggestion {
err.span_suggestion_with_applicability(
binding.span,
&rename_msg,
match directive.subclass {
ImportDirectiveSubclass::SingleImport { type_ns_only: true, .. } =>
format!("self as {}", suggested_name),
ImportDirectiveSubclass::SingleImport { source, .. } =>
format!(
"{} as {}{}",
&snippet[..((source.span.hi().0 - binding.span.lo().0) as usize)],
suggested_name,
if snippet.ends_with(";") {
";"
} else {
""
}
),
ImportDirectiveSubclass::ExternCrate { source, target, .. } =>
format!(
"extern crate {} as {};",
source.unwrap_or(target.name),
suggested_name,
),
_ => unreachable!(),
},
binding_span,
rename_msg,
suggestion,
Applicability::MaybeIncorrect,
);
} else {
err.span_label(binding.span, rename_msg);
err.span_label(binding_span, rename_msg);
}
}

Expand Down
4 changes: 1 addition & 3 deletions src/libstd/sync/mutex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,9 +450,7 @@ impl<'a, T: ?Sized> Drop for MutexGuard<'a, T> {
#[stable(feature = "std_debug", since = "1.16.0")]
impl<'a, T: ?Sized + fmt::Debug> fmt::Debug for MutexGuard<'a, T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("MutexGuard")
.field("lock", &self.__lock)
.finish()
fmt::Debug::fmt(&**self, f)
}
}

Expand Down
5 changes: 2 additions & 3 deletions src/libsyntax/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -453,9 +453,6 @@ declare_features! (
// Adds `reason` and `expect` lint attributes.
(active, lint_reasons, "1.31.0", Some(54503), None),

// `extern crate self as foo;` puts local crate root into extern prelude under name `foo`.
(active, extern_crate_self, "1.31.0", Some(56409), None),

// Allows paths to enum variants on type aliases.
(active, type_alias_enum_variants, "1.31.0", Some(49683), None),

Expand Down Expand Up @@ -689,6 +686,8 @@ declare_features! (
(accepted, uniform_paths, "1.32.0", Some(53130), None),
// Allows `cfg(target_vendor = "...")`.
(accepted, cfg_target_vendor, "1.33.0", Some(29718), None),
// `extern crate self as foo;` puts local crate root into extern prelude under name `foo`.
(accepted, extern_crate_self, "1.34.0", Some(56409), None),
);

// If you change this, please modify `src/doc/unstable-book` as well. You must
Expand Down
2 changes: 1 addition & 1 deletion src/libtest/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#![feature(asm)]
#![cfg_attr(stage0, feature(cfg_target_vendor))]
#![feature(fnbox)]
#![cfg_attr(any(unix, target_os = "cloudabi"), feature(libc))]
#![cfg_attr(any(unix, target_os = "cloudabi"), feature(libc, rustc_private))]
#![feature(nll)]
#![feature(set_stdio)]
#![feature(panic_unwind)]
Expand Down
1 change: 1 addition & 0 deletions src/test/run-pass/simd/simd-intrinsic-generic-reduction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#![allow(non_camel_case_types)]

// ignore-emscripten
// ignore-aarch64 FIXME: https://github.com/rust-lang/rust/issues/54510

// Test that the simd_reduce_{op} intrinsics produce the correct results.

Expand Down
3 changes: 0 additions & 3 deletions src/test/ui/feature-gates/feature-gate-extern_crate_self.rs

This file was deleted.

11 changes: 0 additions & 11 deletions src/test/ui/feature-gates/feature-gate-extern_crate_self.stderr

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![feature(extern_crate_self)]

extern crate self; //~ ERROR `extern crate self;` requires renaming

#[macro_use] //~ ERROR `macro_use` is not supported on `extern crate self`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
error: `extern crate self;` requires renaming
--> $DIR/extern-crate-self-fail.rs:3:1
--> $DIR/extern-crate-self-fail.rs:1:1
|
LL | extern crate self; //~ ERROR `extern crate self;` requires renaming
| ^^^^^^^^^^^^^^^^^^ help: try: `extern crate self as name;`

error: `macro_use` is not supported on `extern crate self`
--> $DIR/extern-crate-self-fail.rs:5:1
--> $DIR/extern-crate-self-fail.rs:3:1
|
LL | #[macro_use] //~ ERROR `macro_use` is not supported on `extern crate self`
| ^^^^^^^^^^^^
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// run-pass

// Test that a macro can correctly expand the alias
// in an `extern crate self as ALIAS` item.

fn the_answer() -> usize { 42 }

macro_rules! alias_self {
($alias:ident) => { extern crate self as $alias; }
}

alias_self!(the_alias);

fn main() {
assert_eq!(the_alias::the_answer(), 42);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// compile-pass

// Test that `extern crate self;` is accepted
// syntactically as an item for use in a macro.

macro_rules! accept_item { ($x:item) => {} }

accept_item! {
extern crate self;
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// run-pass

// Test that a macro can correctly expand `self` in
// an `extern crate self as ALIAS` item.

fn the_answer() -> usize { 42 }

macro_rules! extern_something {
($alias:ident) => { extern crate $alias as the_alias; }
}

extern_something!(self);

fn main() {
assert_eq!(the_alias::the_answer(), 42);
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// compile-pass

#![feature(extern_crate_self)]

extern crate self as foo;

struct S;
Expand Down
17 changes: 17 additions & 0 deletions src/test/ui/issues/issue-56411.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
macro_rules! import {
( $($name:ident),* ) => {
$(
mod $name;
pub use self::$name;
//~^ ERROR the name `issue_56411_aux` is defined multiple times
//~| ERROR `issue_56411_aux` is private, and cannot be re-exported

)*
}
}

import!(issue_56411_aux);

fn main() {
println!("Hello, world!");
}
31 changes: 31 additions & 0 deletions src/test/ui/issues/issue-56411.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
error[E0255]: the name `issue_56411_aux` is defined multiple times
--> $DIR/issue-56411.rs:5:21
|
LL | mod $name;
| ---------- previous definition of the module `issue_56411_aux` here
LL | pub use self::$name;
| ^^^^^^^^^^^
| |
| `issue_56411_aux` reimported here
| you can use `as` to change the binding name of the import
...
LL | import!(issue_56411_aux);
| ------------------------- in this macro invocation
|
= note: `issue_56411_aux` must be defined only once in the type namespace of this module

error[E0365]: `issue_56411_aux` is private, and cannot be re-exported
--> $DIR/issue-56411.rs:5:21
|
LL | pub use self::$name;
| ^^^^^^^^^^^ re-export of private `issue_56411_aux`
...
LL | import!(issue_56411_aux);
| ------------------------- in this macro invocation
|
= note: consider declaring type or module `issue_56411_aux` with `pub`

error: aborting due to 2 previous errors

Some errors occurred: E0255, E0365.
For more information about an error, try `rustc --explain E0255`.
5 changes: 5 additions & 0 deletions src/test/ui/issues/issue_56411_aux.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// compile-pass

struct T {}

fn main() {}
6 changes: 3 additions & 3 deletions src/tools/linkchecker/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ impl FileEntry {
fn parse_ids(&mut self, file: &Path, contents: &str, errors: &mut bool) {
if self.ids.is_empty() {
with_attrs_in_source(contents, " id", |fragment, i, _| {
let frag = fragment.trim_left_matches("#").to_owned();
let frag = fragment.trim_start_matches("#").to_owned();
let encoded = small_url_encode(&frag);
if !self.ids.insert(frag) {
*errors = true;
Expand Down Expand Up @@ -343,7 +343,7 @@ fn with_attrs_in_source<F: FnMut(&str, usize, &str)>(contents: &str, attr: &str,
Some(i) => i,
None => continue,
};
if rest[..pos_equals].trim_left_matches(" ") != "" {
if rest[..pos_equals].trim_start_matches(" ") != "" {
continue;
}

Expand All @@ -355,7 +355,7 @@ fn with_attrs_in_source<F: FnMut(&str, usize, &str)>(contents: &str, attr: &str,
};
let quote_delim = rest.as_bytes()[pos_quote] as char;

if rest[..pos_quote].trim_left_matches(" ") != "" {
if rest[..pos_quote].trim_start_matches(" ") != "" {
continue;
}
let rest = &rest[pos_quote + 1..];
Expand Down