Skip to content

Commit 1d5241c

Browse files
committed
Auto merge of #69822 - Centril:rollup-360ca2j, r=Centril
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
2 parents f943349 + 49c82d1 commit 1d5241c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+462
-455
lines changed

src/doc/unstable-book/src/language-features/const-in-array-repeat-expressions.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

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

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

77
------------------------
88

src/doc/unstable-book/src/language-features/impl-trait-in-bindings.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# `impl_trait_in_bindings`
22

3-
The tracking issue for this feature is: [#34511]
3+
The tracking issue for this feature is: [#63065]
44

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

77
------------------------
88

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# `link_cfg`
2+
3+
This feature is internal to the Rust compiler and is not intended for general use.
4+
5+
------------------------

src/doc/unstable-book/src/language-features/trait-alias.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

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

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

77
------------------------
88

src/doc/unstable-book/src/language-features/transparent-unions.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
The tracking issue for this feature is [#60405]
44

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

77
----
88

src/doc/unstable-book/src/library-features/read-initializer.md

-7
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# `tidy_test_never_used_anywhere_else`
2+
3+
This feature is internal to the Rust compiler and is not intended for general use.
4+
5+
------------------------

src/liballoc/collections/btree/map.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -1477,6 +1477,14 @@ impl<K, V> Drop for IntoIter<K, V> {
14771477
// Continue the same loop we perform below. This only runs when unwinding, so we
14781478
// don't have to care about panics this time (they'll abort).
14791479
while let Some(_) = self.0.next() {}
1480+
1481+
// No need to avoid the shared root, because the tree was definitely not empty.
1482+
unsafe {
1483+
let mut node = ptr::read(&self.0.front).into_node().forget_type();
1484+
while let Some(parent) = node.deallocate_and_ascend() {
1485+
node = parent.into_node().forget_type();
1486+
}
1487+
}
14801488
}
14811489
}
14821490

@@ -1491,7 +1499,8 @@ impl<K, V> Drop for IntoIter<K, V> {
14911499
if node.is_shared_root() {
14921500
return;
14931501
}
1494-
1502+
// Most of the nodes have been deallocated while traversing
1503+
// but one pile from a leaf up to the root is left standing.
14951504
while let Some(parent) = node.deallocate_and_ascend() {
14961505
node = parent.into_node().forget_type();
14971506
}

src/liballoc/tests/btree/map.rs

+25-1
Original file line numberDiff line numberDiff line change
@@ -1021,7 +1021,7 @@ fn test_split_off_large_random_sorted() {
10211021
}
10221022

10231023
#[test]
1024-
fn test_into_iter_drop_leak() {
1024+
fn test_into_iter_drop_leak_1() {
10251025
static DROPS: AtomicU32 = AtomicU32::new(0);
10261026

10271027
struct D;
@@ -1045,3 +1045,27 @@ fn test_into_iter_drop_leak() {
10451045

10461046
assert_eq!(DROPS.load(Ordering::SeqCst), 5);
10471047
}
1048+
1049+
#[test]
1050+
fn test_into_iter_drop_leak_2() {
1051+
let size = 12; // to obtain tree with 2 levels (having edges to leaf nodes)
1052+
static DROPS: AtomicU32 = AtomicU32::new(0);
1053+
static PANIC_POINT: AtomicU32 = AtomicU32::new(0);
1054+
1055+
struct D;
1056+
impl Drop for D {
1057+
fn drop(&mut self) {
1058+
if DROPS.fetch_add(1, Ordering::SeqCst) == PANIC_POINT.load(Ordering::SeqCst) {
1059+
panic!("panic in `drop`");
1060+
}
1061+
}
1062+
}
1063+
1064+
for panic_point in vec![0, 1, size - 2, size - 1] {
1065+
DROPS.store(0, Ordering::SeqCst);
1066+
PANIC_POINT.store(panic_point, Ordering::SeqCst);
1067+
let map: BTreeMap<_, _> = (0..size).map(|i| (i, D)).collect();
1068+
catch_unwind(move || drop(map.into_iter())).ok();
1069+
assert_eq!(DROPS.load(Ordering::SeqCst), size);
1070+
}
1071+
}

src/librustc_builtin_macros/assert.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -80,17 +80,15 @@ fn parse_assert<'a>(
8080
// my_function();
8181
// );
8282
//
83-
// Warn about semicolon and suggest removing it. Eventually, this should be turned into an
84-
// error.
83+
// Emit an error about semicolon and suggest removing it.
8584
if parser.token == token::Semi {
86-
let mut err = cx.struct_span_warn(sp, "macro requires an expression as an argument");
85+
let mut err = cx.struct_span_err(sp, "macro requires an expression as an argument");
8786
err.span_suggestion(
8887
parser.token.span,
8988
"try removing semicolon",
9089
String::new(),
9190
Applicability::MaybeIncorrect,
9291
);
93-
err.note("this is going to be an error in the future");
9492
err.emit();
9593

9694
parser.bump();
@@ -101,19 +99,17 @@ fn parse_assert<'a>(
10199
//
102100
// assert!(true "error message");
103101
//
104-
// Parse this as an actual message, and suggest inserting a comma. Eventually, this should be
105-
// turned into an error.
102+
// Emit an error and suggest inserting a comma.
106103
let custom_message =
107104
if let token::Literal(token::Lit { kind: token::Str, .. }) = parser.token.kind {
108-
let mut err = cx.struct_span_warn(parser.token.span, "unexpected string literal");
105+
let mut err = cx.struct_span_err(parser.token.span, "unexpected string literal");
109106
let comma_span = parser.prev_token.span.shrink_to_hi();
110107
err.span_suggestion_short(
111108
comma_span,
112109
"try adding a comma",
113110
", ".to_string(),
114111
Applicability::MaybeIncorrect,
115112
);
116-
err.note("this is going to be an error in the future");
117113
err.emit();
118114

119115
parse_custom_message(&mut parser)

src/librustc_feature/active.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ declare_features! (
9999

100100
// no-tracking-issue-start
101101

102+
/// Allows using `rustc_*` attributes (RFC 572).
103+
(active, rustc_attrs, "1.0.0", None, None),
104+
102105
/// Allows using compiler's own crates.
103106
(active, rustc_private, "1.0.0", Some(27812), None),
104107

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

131-
/// Allows using `rustc_*` attributes (RFC 572).
132-
(active, rustc_attrs, "1.0.0", Some(29642), None),
133-
134134
/// Allows using the `box $expr` syntax.
135135
(active, box_syntax, "1.0.0", Some(49733), None),
136136

src/librustc_resolve/build_reduced_graph.rs

+32-45
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
//! Imports are also considered items and placed into modules here, but not resolved yet.
77
88
use crate::def_collector::collect_definitions;
9-
use crate::imports::ImportDirective;
10-
use crate::imports::ImportDirectiveSubclass::{self, GlobImport, SingleImport};
9+
use crate::imports::{Import, ImportKind};
1110
use crate::macros::{LegacyBinding, LegacyScope};
1211
use crate::Namespace::{self, MacroNS, TypeNS, ValueNS};
1312
use crate::{CrateLint, Determinacy, PathResult, ResolutionError, VisResolutionError};
@@ -308,11 +307,11 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
308307
})
309308
}
310309

311-
// Add an import directive to the current module.
312-
fn add_import_directive(
310+
// Add an import to the current module.
311+
fn add_import(
313312
&mut self,
314313
module_path: Vec<Segment>,
315-
subclass: ImportDirectiveSubclass<'a>,
314+
kind: ImportKind<'a>,
316315
span: Span,
317316
id: NodeId,
318317
item: &ast::Item,
@@ -321,11 +320,11 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
321320
vis: ty::Visibility,
322321
) {
323322
let current_module = self.parent_scope.module;
324-
let directive = self.r.arenas.alloc_import_directive(ImportDirective {
323+
let import = self.r.arenas.alloc_import(Import {
324+
kind,
325325
parent_scope: self.parent_scope,
326326
module_path,
327327
imported_module: Cell::new(None),
328-
subclass,
329328
span,
330329
id,
331330
use_span: item.span,
@@ -337,25 +336,25 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
337336
used: Cell::new(false),
338337
});
339338

340-
debug!("add_import_directive({:?})", directive);
339+
debug!("add_import({:?})", import);
341340

342-
self.r.indeterminate_imports.push(directive);
343-
match directive.subclass {
341+
self.r.indeterminate_imports.push(import);
342+
match import.kind {
344343
// Don't add unresolved underscore imports to modules
345-
SingleImport { target: Ident { name: kw::Underscore, .. }, .. } => {}
346-
SingleImport { target, type_ns_only, .. } => {
344+
ImportKind::Single { target: Ident { name: kw::Underscore, .. }, .. } => {}
345+
ImportKind::Single { target, type_ns_only, .. } => {
347346
self.r.per_ns(|this, ns| {
348347
if !type_ns_only || ns == TypeNS {
349348
let key = this.new_key(target, ns);
350349
let mut resolution = this.resolution(current_module, key).borrow_mut();
351-
resolution.add_single_import(directive);
350+
resolution.add_single_import(import);
352351
}
353352
});
354353
}
355354
// We don't add prelude imports to the globs since they only affect lexical scopes,
356355
// which are not relevant to import resolution.
357-
GlobImport { is_prelude: true, .. } => {}
358-
GlobImport { .. } => current_module.globs.borrow_mut().push(directive),
356+
ImportKind::Glob { is_prelude: true, .. } => {}
357+
ImportKind::Glob { .. } => current_module.globs.borrow_mut().push(import),
359358
_ => unreachable!(),
360359
}
361360
}
@@ -480,7 +479,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
480479
);
481480
}
482481

483-
let subclass = SingleImport {
482+
let kind = ImportKind::Single {
484483
source: source.ident,
485484
target: ident,
486485
source_bindings: PerNS {
@@ -496,9 +495,9 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
496495
type_ns_only,
497496
nested,
498497
};
499-
self.add_import_directive(
498+
self.add_import(
500499
module_path,
501-
subclass,
500+
kind,
502501
use_tree.span,
503502
id,
504503
item,
@@ -508,20 +507,11 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
508507
);
509508
}
510509
ast::UseTreeKind::Glob => {
511-
let subclass = GlobImport {
510+
let kind = ImportKind::Glob {
512511
is_prelude: attr::contains_name(&item.attrs, sym::prelude_import),
513512
max_vis: Cell::new(ty::Visibility::Invisible),
514513
};
515-
self.add_import_directive(
516-
prefix,
517-
subclass,
518-
use_tree.span,
519-
id,
520-
item,
521-
root_span,
522-
item.id,
523-
vis,
524-
);
514+
self.add_import(prefix, kind, use_tree.span, id, item, root_span, item.id, vis);
525515
}
526516
ast::UseTreeKind::Nested(ref items) => {
527517
// Ensure there is at most one `self` in the list
@@ -637,15 +627,12 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
637627
let used = self.process_legacy_macro_imports(item, module);
638628
let binding =
639629
(module, ty::Visibility::Public, sp, expansion).to_name_binding(self.r.arenas);
640-
let directive = self.r.arenas.alloc_import_directive(ImportDirective {
630+
let import = self.r.arenas.alloc_import(Import {
631+
kind: ImportKind::ExternCrate { source: orig_name, target: ident },
641632
root_id: item.id,
642633
id: item.id,
643634
parent_scope: self.parent_scope,
644635
imported_module: Cell::new(Some(ModuleOrUniformRoot::Module(module))),
645-
subclass: ImportDirectiveSubclass::ExternCrate {
646-
source: orig_name,
647-
target: ident,
648-
},
649636
has_attributes: !item.attrs.is_empty(),
650637
use_span_with_attributes: item.span_with_attributes(),
651638
use_span: item.span,
@@ -655,8 +642,8 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
655642
vis: Cell::new(vis),
656643
used: Cell::new(used),
657644
});
658-
self.r.potentially_unused_imports.push(directive);
659-
let imported_binding = self.r.import(binding, directive);
645+
self.r.potentially_unused_imports.push(import);
646+
let imported_binding = self.r.import(binding, import);
660647
if ptr::eq(parent, self.r.graph_root) {
661648
if let Some(entry) = self.r.extern_prelude.get(&ident.modern()) {
662649
if expansion != ExpnId::root()
@@ -992,13 +979,13 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
992979
}
993980
}
994981

995-
let macro_use_directive = |this: &Self, span| {
996-
this.r.arenas.alloc_import_directive(ImportDirective {
982+
let macro_use_import = |this: &Self, span| {
983+
this.r.arenas.alloc_import(Import {
984+
kind: ImportKind::MacroUse,
997985
root_id: item.id,
998986
id: item.id,
999987
parent_scope: this.parent_scope,
1000988
imported_module: Cell::new(Some(ModuleOrUniformRoot::Module(module))),
1001-
subclass: ImportDirectiveSubclass::MacroUse,
1002989
use_span_with_attributes: item.span_with_attributes(),
1003990
has_attributes: !item.attrs.is_empty(),
1004991
use_span: item.span,
@@ -1012,11 +999,11 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
1012999

10131000
let allow_shadowing = self.parent_scope.expansion == ExpnId::root();
10141001
if let Some(span) = import_all {
1015-
let directive = macro_use_directive(self, span);
1016-
self.r.potentially_unused_imports.push(directive);
1002+
let import = macro_use_import(self, span);
1003+
self.r.potentially_unused_imports.push(import);
10171004
module.for_each_child(self, |this, ident, ns, binding| {
10181005
if ns == MacroNS {
1019-
let imported_binding = this.r.import(binding, directive);
1006+
let imported_binding = this.r.import(binding, import);
10201007
this.legacy_import_macro(ident.name, imported_binding, span, allow_shadowing);
10211008
}
10221009
});
@@ -1031,9 +1018,9 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
10311018
ident.span,
10321019
);
10331020
if let Ok(binding) = result {
1034-
let directive = macro_use_directive(self, ident.span);
1035-
self.r.potentially_unused_imports.push(directive);
1036-
let imported_binding = self.r.import(binding, directive);
1021+
let import = macro_use_import(self, ident.span);
1022+
self.r.potentially_unused_imports.push(import);
1023+
let imported_binding = self.r.import(binding, import);
10371024
self.legacy_import_macro(
10381025
ident.name,
10391026
imported_binding,

0 commit comments

Comments
 (0)