Skip to content

Commit

Permalink
Auto merge of #69822 - Centril:rollup-360ca2j, r=Centril
Browse files Browse the repository at this point in the history
Rollup of 8 pull requests

Successful merges:

 - #69422 (Remove use of `unwrap()` from save-analysis)
 - #69548 (Turn trailing tokens in `assert!()` into hard errors)
 - #69561 (Clean up unstable book)
 - #69599 (check_binding_alt_eq_ty: improve precision wrt. `if let`)
 - #69641 (Update books)
 - #69776 (Fix & test leak of some BTreeMap nodes on panic during `into_iter`)
 - #69805 (resolve: Modernize some naming)
 - #69810 (test(bindings_after_at): add dynamic drop tests for bindings_after_at)

Failed merges:

r? @ghost
  • Loading branch information
bors committed Mar 8, 2020
2 parents f943349 + 49c82d1 commit 1d5241c
Show file tree
Hide file tree
Showing 44 changed files with 462 additions and 455 deletions.
2 changes: 1 addition & 1 deletion src/doc/embedded-book
2 changes: 1 addition & 1 deletion src/doc/nomicon
2 changes: 1 addition & 1 deletion src/doc/rust-by-example
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

The tracking issue for this feature is: [#49147]

[#44109]: https://github.com/rust-lang/rust/issues/49147
[#49147]: https://github.com/rust-lang/rust/issues/49147

------------------------

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# `impl_trait_in_bindings`

The tracking issue for this feature is: [#34511]
The tracking issue for this feature is: [#63065]

[#34511]: https://github.com/rust-lang/rust/issues/34511
[#63065]: https://github.com/rust-lang/rust/issues/63065

------------------------

Expand Down
5 changes: 5 additions & 0 deletions src/doc/unstable-book/src/language-features/link-cfg.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# `link_cfg`

This feature is internal to the Rust compiler and is not intended for general use.

------------------------
2 changes: 1 addition & 1 deletion src/doc/unstable-book/src/language-features/trait-alias.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

The tracking issue for this feature is: [#41517]

[#41417]: https://github.com/rust-lang/rust/issues/41517
[#41517]: https://github.com/rust-lang/rust/issues/41517

------------------------

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

The tracking issue for this feature is [#60405]

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

----

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# `tidy_test_never_used_anywhere_else`

This feature is internal to the Rust compiler and is not intended for general use.

------------------------
11 changes: 10 additions & 1 deletion src/liballoc/collections/btree/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1477,6 +1477,14 @@ impl<K, V> Drop for IntoIter<K, V> {
// Continue the same loop we perform below. This only runs when unwinding, so we
// don't have to care about panics this time (they'll abort).
while let Some(_) = self.0.next() {}

// No need to avoid the shared root, because the tree was definitely not empty.
unsafe {
let mut node = ptr::read(&self.0.front).into_node().forget_type();
while let Some(parent) = node.deallocate_and_ascend() {
node = parent.into_node().forget_type();
}
}
}
}

Expand All @@ -1491,7 +1499,8 @@ impl<K, V> Drop for IntoIter<K, V> {
if node.is_shared_root() {
return;
}

// Most of the nodes have been deallocated while traversing
// but one pile from a leaf up to the root is left standing.
while let Some(parent) = node.deallocate_and_ascend() {
node = parent.into_node().forget_type();
}
Expand Down
26 changes: 25 additions & 1 deletion src/liballoc/tests/btree/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1021,7 +1021,7 @@ fn test_split_off_large_random_sorted() {
}

#[test]
fn test_into_iter_drop_leak() {
fn test_into_iter_drop_leak_1() {
static DROPS: AtomicU32 = AtomicU32::new(0);

struct D;
Expand All @@ -1045,3 +1045,27 @@ fn test_into_iter_drop_leak() {

assert_eq!(DROPS.load(Ordering::SeqCst), 5);
}

#[test]
fn test_into_iter_drop_leak_2() {
let size = 12; // to obtain tree with 2 levels (having edges to leaf nodes)
static DROPS: AtomicU32 = AtomicU32::new(0);
static PANIC_POINT: AtomicU32 = AtomicU32::new(0);

struct D;
impl Drop for D {
fn drop(&mut self) {
if DROPS.fetch_add(1, Ordering::SeqCst) == PANIC_POINT.load(Ordering::SeqCst) {
panic!("panic in `drop`");
}
}
}

for panic_point in vec![0, 1, size - 2, size - 1] {
DROPS.store(0, Ordering::SeqCst);
PANIC_POINT.store(panic_point, Ordering::SeqCst);
let map: BTreeMap<_, _> = (0..size).map(|i| (i, D)).collect();
catch_unwind(move || drop(map.into_iter())).ok();
assert_eq!(DROPS.load(Ordering::SeqCst), size);
}
}
12 changes: 4 additions & 8 deletions src/librustc_builtin_macros/assert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,15 @@ fn parse_assert<'a>(
// my_function();
// );
//
// Warn about semicolon and suggest removing it. Eventually, this should be turned into an
// error.
// Emit an error about semicolon and suggest removing it.
if parser.token == token::Semi {
let mut err = cx.struct_span_warn(sp, "macro requires an expression as an argument");
let mut err = cx.struct_span_err(sp, "macro requires an expression as an argument");
err.span_suggestion(
parser.token.span,
"try removing semicolon",
String::new(),
Applicability::MaybeIncorrect,
);
err.note("this is going to be an error in the future");
err.emit();

parser.bump();
Expand All @@ -101,19 +99,17 @@ fn parse_assert<'a>(
//
// assert!(true "error message");
//
// Parse this as an actual message, and suggest inserting a comma. Eventually, this should be
// turned into an error.
// Emit an error and suggest inserting a comma.
let custom_message =
if let token::Literal(token::Lit { kind: token::Str, .. }) = parser.token.kind {
let mut err = cx.struct_span_warn(parser.token.span, "unexpected string literal");
let mut err = cx.struct_span_err(parser.token.span, "unexpected string literal");
let comma_span = parser.prev_token.span.shrink_to_hi();
err.span_suggestion_short(
comma_span,
"try adding a comma",
", ".to_string(),
Applicability::MaybeIncorrect,
);
err.note("this is going to be an error in the future");
err.emit();

parse_custom_message(&mut parser)
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_feature/active.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ declare_features! (

// no-tracking-issue-start

/// Allows using `rustc_*` attributes (RFC 572).
(active, rustc_attrs, "1.0.0", None, None),

/// Allows using compiler's own crates.
(active, rustc_private, "1.0.0", Some(27812), None),

Expand Down Expand Up @@ -128,9 +131,6 @@ declare_features! (
/// Allows using `#[link_name="llvm.*"]`.
(active, link_llvm_intrinsics, "1.0.0", Some(29602), None),

/// Allows using `rustc_*` attributes (RFC 572).
(active, rustc_attrs, "1.0.0", Some(29642), None),

/// Allows using the `box $expr` syntax.
(active, box_syntax, "1.0.0", Some(49733), None),

Expand Down
77 changes: 32 additions & 45 deletions src/librustc_resolve/build_reduced_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
//! Imports are also considered items and placed into modules here, but not resolved yet.

use crate::def_collector::collect_definitions;
use crate::imports::ImportDirective;
use crate::imports::ImportDirectiveSubclass::{self, GlobImport, SingleImport};
use crate::imports::{Import, ImportKind};
use crate::macros::{LegacyBinding, LegacyScope};
use crate::Namespace::{self, MacroNS, TypeNS, ValueNS};
use crate::{CrateLint, Determinacy, PathResult, ResolutionError, VisResolutionError};
Expand Down Expand Up @@ -308,11 +307,11 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
})
}

// Add an import directive to the current module.
fn add_import_directive(
// Add an import to the current module.
fn add_import(
&mut self,
module_path: Vec<Segment>,
subclass: ImportDirectiveSubclass<'a>,
kind: ImportKind<'a>,
span: Span,
id: NodeId,
item: &ast::Item,
Expand All @@ -321,11 +320,11 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
vis: ty::Visibility,
) {
let current_module = self.parent_scope.module;
let directive = self.r.arenas.alloc_import_directive(ImportDirective {
let import = self.r.arenas.alloc_import(Import {
kind,
parent_scope: self.parent_scope,
module_path,
imported_module: Cell::new(None),
subclass,
span,
id,
use_span: item.span,
Expand All @@ -337,25 +336,25 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
used: Cell::new(false),
});

debug!("add_import_directive({:?})", directive);
debug!("add_import({:?})", import);

self.r.indeterminate_imports.push(directive);
match directive.subclass {
self.r.indeterminate_imports.push(import);
match import.kind {
// Don't add unresolved underscore imports to modules
SingleImport { target: Ident { name: kw::Underscore, .. }, .. } => {}
SingleImport { target, type_ns_only, .. } => {
ImportKind::Single { target: Ident { name: kw::Underscore, .. }, .. } => {}
ImportKind::Single { target, type_ns_only, .. } => {
self.r.per_ns(|this, ns| {
if !type_ns_only || ns == TypeNS {
let key = this.new_key(target, ns);
let mut resolution = this.resolution(current_module, key).borrow_mut();
resolution.add_single_import(directive);
resolution.add_single_import(import);
}
});
}
// We don't add prelude imports to the globs since they only affect lexical scopes,
// which are not relevant to import resolution.
GlobImport { is_prelude: true, .. } => {}
GlobImport { .. } => current_module.globs.borrow_mut().push(directive),
ImportKind::Glob { is_prelude: true, .. } => {}
ImportKind::Glob { .. } => current_module.globs.borrow_mut().push(import),
_ => unreachable!(),
}
}
Expand Down Expand Up @@ -480,7 +479,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
);
}

let subclass = SingleImport {
let kind = ImportKind::Single {
source: source.ident,
target: ident,
source_bindings: PerNS {
Expand All @@ -496,9 +495,9 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
type_ns_only,
nested,
};
self.add_import_directive(
self.add_import(
module_path,
subclass,
kind,
use_tree.span,
id,
item,
Expand All @@ -508,20 +507,11 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
);
}
ast::UseTreeKind::Glob => {
let subclass = GlobImport {
let kind = ImportKind::Glob {
is_prelude: attr::contains_name(&item.attrs, sym::prelude_import),
max_vis: Cell::new(ty::Visibility::Invisible),
};
self.add_import_directive(
prefix,
subclass,
use_tree.span,
id,
item,
root_span,
item.id,
vis,
);
self.add_import(prefix, kind, use_tree.span, id, item, root_span, item.id, vis);
}
ast::UseTreeKind::Nested(ref items) => {
// Ensure there is at most one `self` in the list
Expand Down Expand Up @@ -637,15 +627,12 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
let used = self.process_legacy_macro_imports(item, module);
let binding =
(module, ty::Visibility::Public, sp, expansion).to_name_binding(self.r.arenas);
let directive = self.r.arenas.alloc_import_directive(ImportDirective {
let import = self.r.arenas.alloc_import(Import {
kind: ImportKind::ExternCrate { source: orig_name, target: ident },
root_id: item.id,
id: item.id,
parent_scope: self.parent_scope,
imported_module: Cell::new(Some(ModuleOrUniformRoot::Module(module))),
subclass: ImportDirectiveSubclass::ExternCrate {
source: orig_name,
target: ident,
},
has_attributes: !item.attrs.is_empty(),
use_span_with_attributes: item.span_with_attributes(),
use_span: item.span,
Expand All @@ -655,8 +642,8 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
vis: Cell::new(vis),
used: Cell::new(used),
});
self.r.potentially_unused_imports.push(directive);
let imported_binding = self.r.import(binding, directive);
self.r.potentially_unused_imports.push(import);
let imported_binding = self.r.import(binding, import);
if ptr::eq(parent, self.r.graph_root) {
if let Some(entry) = self.r.extern_prelude.get(&ident.modern()) {
if expansion != ExpnId::root()
Expand Down Expand Up @@ -992,13 +979,13 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
}
}

let macro_use_directive = |this: &Self, span| {
this.r.arenas.alloc_import_directive(ImportDirective {
let macro_use_import = |this: &Self, span| {
this.r.arenas.alloc_import(Import {
kind: ImportKind::MacroUse,
root_id: item.id,
id: item.id,
parent_scope: this.parent_scope,
imported_module: Cell::new(Some(ModuleOrUniformRoot::Module(module))),
subclass: ImportDirectiveSubclass::MacroUse,
use_span_with_attributes: item.span_with_attributes(),
has_attributes: !item.attrs.is_empty(),
use_span: item.span,
Expand All @@ -1012,11 +999,11 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {

let allow_shadowing = self.parent_scope.expansion == ExpnId::root();
if let Some(span) = import_all {
let directive = macro_use_directive(self, span);
self.r.potentially_unused_imports.push(directive);
let import = macro_use_import(self, span);
self.r.potentially_unused_imports.push(import);
module.for_each_child(self, |this, ident, ns, binding| {
if ns == MacroNS {
let imported_binding = this.r.import(binding, directive);
let imported_binding = this.r.import(binding, import);
this.legacy_import_macro(ident.name, imported_binding, span, allow_shadowing);
}
});
Expand All @@ -1031,9 +1018,9 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
ident.span,
);
if let Ok(binding) = result {
let directive = macro_use_directive(self, ident.span);
self.r.potentially_unused_imports.push(directive);
let imported_binding = self.r.import(binding, directive);
let import = macro_use_import(self, ident.span);
self.r.potentially_unused_imports.push(import);
let imported_binding = self.r.import(binding, import);
self.legacy_import_macro(
ident.name,
imported_binding,
Expand Down
Loading

0 comments on commit 1d5241c

Please sign in to comment.