Skip to content

Commit 4cd0ee9

Browse files
committed
Auto merge of #74388 - Manishearth:rollup-i7iueu8, r=Manishearth
Rollup of 7 pull requests Successful merges: - #73421 (Clarify effect of orphan rule changes on From/Into) - #74037 (Update reference to CONTRIBUTING.md) - #74203 (Enforce the static symbol order.) - #74295 (Add and fix BTreeMap comments) - #74352 (Use local links in the alloc docs.) - #74377 (Move libstd's default feature to libtest) - #74381 (Update docs for str::as_bytes_mut.) Failed merges: r? @ghost
2 parents e2e29de + a77813b commit 4cd0ee9

File tree

18 files changed

+217
-182
lines changed

18 files changed

+217
-182
lines changed

CONTRIBUTING.md

+7
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,12 @@ Thank you for your interest in contributing to Rust!
44

55
To get started, read the [Getting Started] guide in the [rustc-dev-guide].
66

7+
## Bug reports
8+
9+
Did a compiler error message tell you to come here? If you want to create an ICE report,
10+
refer to [this section][contributing-bug-reports] and [open an issue][issue template].
11+
712
[Getting Started]: https://rustc-dev-guide.rust-lang.org/getting-started.html
813
[rustc-dev-guide]: https://rustc-dev-guide.rust-lang.org/
14+
[contributing-bug-reports]: https://rustc-dev-guide.rust-lang.org/contributing.html#bug-reports
15+
[issue template]: https://github.com/rust-lang/rust/issues/new/choose

src/bootstrap/builder.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,8 @@ impl<'a> Builder<'a> {
773773
let my_out = match mode {
774774
// This is the intended out directory for compiler documentation.
775775
Mode::Rustc | Mode::ToolRustc | Mode::Codegen => self.compiler_doc_out(target),
776-
_ => self.crate_doc_out(target),
776+
Mode::Std => out_dir.join(target).join("doc"),
777+
_ => panic!("doc mode {:?} not expected", mode),
777778
};
778779
let rustdoc = self.rustdoc(compiler);
779780
self.clear_if_dirty(&my_out, &rustdoc);

src/bootstrap/doc.rs

+15-24
Original file line numberDiff line numberDiff line change
@@ -417,34 +417,16 @@ impl Step for Std {
417417
builder.ensure(compile::Std { compiler, target });
418418
let out_dir = builder.stage_out(compiler, Mode::Std).join(target).join("doc");
419419

420-
// Here what we're doing is creating a *symlink* (directory junction on
421-
// Windows) to the final output location. This is not done as an
422-
// optimization but rather for correctness. We've got three trees of
423-
// documentation, one for std, one for test, and one for rustc. It's then
424-
// our job to merge them all together.
425-
//
426-
// Unfortunately rustbuild doesn't know nearly as well how to merge doc
427-
// trees as rustdoc does itself, so instead of actually having three
428-
// separate trees we just have rustdoc output to the same location across
429-
// all of them.
430-
//
431-
// This way rustdoc generates output directly into the output, and rustdoc
432-
// will also directly handle merging.
433-
let my_out = builder.crate_doc_out(target);
434-
t!(symlink_dir_force(&builder.config, &my_out, &out_dir));
435420
t!(fs::copy(builder.src.join("src/doc/rust.css"), out.join("rust.css")));
436421

437422
let run_cargo_rustdoc_for = |package: &str| {
438423
let mut cargo =
439424
builder.cargo(compiler, Mode::Std, SourceType::InTree, target, "rustdoc");
440425
compile::std_cargo(builder, target, compiler.stage, &mut cargo);
441426

442-
cargo.arg("-p").arg(package);
443-
// Create all crate output directories first to make sure rustdoc uses
444-
// relative links.
445-
// FIXME: Cargo should probably do this itself.
446-
t!(fs::create_dir_all(out_dir.join(package)));
447427
cargo
428+
.arg("-p")
429+
.arg(package)
448430
.arg("--")
449431
.arg("--markdown-css")
450432
.arg("rust.css")
@@ -462,11 +444,17 @@ impl Step for Std {
462444
// folder structure, that would also build internal crates that we do
463445
// not want to show in documentation. These crates will later be visited
464446
// by the rustc step, so internal documentation will show them.
465-
let krates = ["alloc", "core", "std", "proc_macro", "test"];
447+
//
448+
// Note that the order here is important! The crates need to be
449+
// processed starting from the leaves, otherwise rustdoc will not
450+
// create correct links between crates because rustdoc depends on the
451+
// existence of the output directories to know if it should be a local
452+
// or remote link.
453+
let krates = ["core", "alloc", "std", "proc_macro", "test"];
466454
for krate in &krates {
467455
run_cargo_rustdoc_for(krate);
468456
}
469-
builder.cp_r(&my_out, &out);
457+
builder.cp_r(&out_dir, &out);
470458

471459
// Look for src/libstd, src/libcore etc in the `x.py doc` arguments and
472460
// open the corresponding rendered docs.
@@ -529,8 +517,11 @@ impl Step for Rustc {
529517
// Build rustc.
530518
builder.ensure(compile::Rustc { compiler, target });
531519

532-
// We do not symlink to the same shared folder that already contains std library
533-
// documentation from previous steps as we do not want to include that.
520+
// This uses a shared directory so that librustdoc documentation gets
521+
// correctly built and merged with the rustc documentation. This is
522+
// needed because rustdoc is built in a different directory from
523+
// rustc. rustdoc needs to be able to see everything, for example when
524+
// merging the search index, or generating local (relative) links.
534525
let out_dir = builder.stage_out(compiler, Mode::Rustc).join(target).join("doc");
535526
t!(symlink_dir_force(&builder.config, &out, &out_dir));
536527

src/bootstrap/lib.rs

-7
Original file line numberDiff line numberDiff line change
@@ -612,13 +612,6 @@ impl Build {
612612
INTERNER.intern_path(self.out.join(&*target).join("md-doc"))
613613
}
614614

615-
/// Output directory for all crate documentation for a target (temporary)
616-
///
617-
/// The artifacts here are then copied into `doc_out` above.
618-
fn crate_doc_out(&self, target: Interned<String>) -> PathBuf {
619-
self.out.join(&*target).join("crate-docs")
620-
}
621-
622615
/// Returns `true` if no custom `llvm-config` is set for the specified target.
623616
///
624617
/// If no custom `llvm-config` was specified then Rust's llvm will be used.

src/liballoc/collections/btree/map.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1697,6 +1697,8 @@ where
16971697
pred: F,
16981698
inner: DrainFilterInner<'a, K, V>,
16991699
}
1700+
/// Most of the implementation of DrainFilter, independent of the type
1701+
/// of the predicate, thus also serving for BTreeSet::DrainFilter.
17001702
pub(super) struct DrainFilterInner<'a, K: 'a, V: 'a> {
17011703
length: &'a mut usize,
17021704
cur_leaf_edge: Option<Handle<NodeRef<marker::Mut<'a>, K, V, marker::Leaf>, marker::Edge>>,

src/liballoc/collections/btree/navigate.rs

+14-12
Original file line numberDiff line numberDiff line change
@@ -161,15 +161,16 @@ impl<'a, K, V> Handle<NodeRef<marker::Mut<'a>, K, V, marker::Leaf>, marker::Edge
161161
impl<K, V> Handle<NodeRef<marker::Owned, K, V, marker::Leaf>, marker::Edge> {
162162
/// Moves the leaf edge handle to the next leaf edge and returns the key and value
163163
/// in between, while deallocating any node left behind.
164-
/// Unsafe for three reasons:
164+
/// Unsafe for two reasons:
165165
/// - The caller must ensure that the leaf edge is not the last one in the tree
166166
/// and is not a handle previously resulting from counterpart `next_back_unchecked`.
167-
/// - If the leaf edge is the last edge of a node, that node and possibly ancestors
167+
/// - Further use of the updated leaf edge handle is very dangerous. In particular,
168+
/// if the leaf edge is the last edge of a node, that node and possibly ancestors
168169
/// will be deallocated, while the reference to those nodes in the surviving ancestor
169-
/// is left dangling; thus further use of the leaf edge handle is dangerous.
170-
/// It is, however, safe to call this method again on the updated handle.
171-
/// if the two preconditions above hold.
172-
/// - Using the updated handle may well invalidate the returned references.
170+
/// is left dangling.
171+
/// The only safe way to proceed with the updated handle is to compare it, drop it,
172+
/// call this method again subject to both preconditions listed in the first point,
173+
/// or call counterpart `next_back_unchecked` subject to its preconditions.
173174
pub unsafe fn next_unchecked(&mut self) -> (K, V) {
174175
unsafe {
175176
replace(self, |leaf_edge| {
@@ -183,15 +184,16 @@ impl<K, V> Handle<NodeRef<marker::Owned, K, V, marker::Leaf>, marker::Edge> {
183184

184185
/// Moves the leaf edge handle to the previous leaf edge and returns the key
185186
/// and value in between, while deallocating any node left behind.
186-
/// Unsafe for three reasons:
187+
/// Unsafe for two reasons:
187188
/// - The caller must ensure that the leaf edge is not the first one in the tree
188189
/// and is not a handle previously resulting from counterpart `next_unchecked`.
189-
/// - If the lead edge is the first edge of a node, that node and possibly ancestors
190+
/// - Further use of the updated leaf edge handle is very dangerous. In particular,
191+
/// if the leaf edge is the first edge of a node, that node and possibly ancestors
190192
/// will be deallocated, while the reference to those nodes in the surviving ancestor
191-
/// is left dangling; thus further use of the leaf edge handle is dangerous.
192-
/// It is, however, safe to call this method again on the updated handle.
193-
/// if the two preconditions above hold.
194-
/// - Using the updated handle may well invalidate the returned references.
193+
/// is left dangling.
194+
/// The only safe way to proceed with the updated handle is to compare it, drop it,
195+
/// call this method again subject to both preconditions listed in the first point,
196+
/// or call counterpart `next_unchecked` subject to its preconditions.
195197
pub unsafe fn next_back_unchecked(&mut self) -> (K, V) {
196198
unsafe {
197199
replace(self, |leaf_edge| {

src/liballoc/collections/btree/node.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ struct InternalNode<K, V> {
9494
data: LeafNode<K, V>,
9595

9696
/// The pointers to the children of this node. `len + 1` of these are considered
97-
/// initialized and valid.
97+
/// initialized and valid. Although during the process of `into_iter` or `drop`,
98+
/// some pointers are dangling while others still need to be traversed.
9899
edges: [MaybeUninit<BoxedNode<K, V>>; 2 * B],
99100
}
100101

@@ -408,7 +409,7 @@ impl<K, V> NodeRef<marker::Owned, K, V, marker::LeafOrInternal> {
408409

409410
impl<'a, K, V, Type> NodeRef<marker::Mut<'a>, K, V, Type> {
410411
/// Unsafely asserts to the compiler some static information about whether this
411-
/// node is a `Leaf`.
412+
/// node is a `Leaf` or an `Internal`.
412413
unsafe fn cast_unchecked<NewType>(&mut self) -> NodeRef<marker::Mut<'_>, K, V, NewType> {
413414
NodeRef { height: self.height, node: self.node, root: self.root, _marker: PhantomData }
414415
}
@@ -515,7 +516,7 @@ impl<'a, K: 'a, V: 'a, Type> NodeRef<marker::Mut<'a>, K, V, Type> {
515516
}
516517

517518
impl<'a, K, V> NodeRef<marker::Mut<'a>, K, V, marker::Leaf> {
518-
/// Adds a key/value pair the end of the node.
519+
/// Adds a key/value pair to the end of the node.
519520
pub fn push(&mut self, key: K, val: V) {
520521
assert!(self.len() < CAPACITY);
521522

@@ -602,8 +603,10 @@ impl<'a, K, V> NodeRef<marker::Mut<'a>, K, V, marker::Internal> {
602603
}
603604

604605
impl<'a, K, V> NodeRef<marker::Mut<'a>, K, V, marker::LeafOrInternal> {
605-
/// Removes a key/value pair from the end of this node. If this is an internal node,
606-
/// also removes the edge that was to the right of that pair.
606+
/// Removes a key/value pair from the end of this node and returns the pair.
607+
/// If this is an internal node, also removes the edge that was to the right
608+
/// of that pair and returns the orphaned node that this edge owned with its
609+
/// parent erased.
607610
pub fn pop(&mut self) -> (K, V, Option<Root<K, V>>) {
608611
assert!(self.len() > 0);
609612

@@ -883,7 +886,7 @@ impl<'a, K, V> Handle<NodeRef<marker::Mut<'a>, K, V, marker::Internal>, marker::
883886
}
884887

885888
/// Unsafely asserts to the compiler some static information about whether the underlying
886-
/// node of this handle is a `Leaf`.
889+
/// node of this handle is a `Leaf` or an `Internal`.
887890
unsafe fn cast_unchecked<NewType>(
888891
&mut self,
889892
) -> Handle<NodeRef<marker::Mut<'_>, K, V, NewType>, marker::Edge> {

src/libcore/convert/mod.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@
1818
//! [`TryFrom<T>`][`TryFrom`] rather than [`Into<U>`][`Into`] or [`TryInto<U>`][`TryInto`],
1919
//! as [`From`] and [`TryFrom`] provide greater flexibility and offer
2020
//! equivalent [`Into`] or [`TryInto`] implementations for free, thanks to a
21-
//! blanket implementation in the standard library. Only implement [`Into`] or [`TryInto`]
22-
//! when a conversion to a type outside the current crate is required.
21+
//! blanket implementation in the standard library. When targeting a version prior to Rust 1.41, it
22+
//! may be necessary to implement [`Into`] or [`TryInto`] directly when converting to a type
23+
//! outside the current crate.
2324
//!
2425
//! # Generic Implementations
2526
//!
@@ -298,8 +299,10 @@ pub trait Into<T>: Sized {
298299
/// because implementing `From` automatically provides one with an implementation of [`Into`]
299300
/// thanks to the blanket implementation in the standard library.
300301
///
301-
/// Only implement [`Into`] if a conversion to a type outside the current crate is required.
302-
/// `From` cannot do these type of conversions because of Rust's orphaning rules.
302+
/// Only implement [`Into`] when targeting a version prior to Rust 1.41 and converting to a type
303+
/// outside the current crate.
304+
/// `From` was not able to do these types of conversions in earlier versions because of Rust's
305+
/// orphaning rules.
303306
/// See [`Into`] for more details.
304307
///
305308
/// Prefer using [`Into`] over using `From` when specifying trait bounds on a generic function.

src/libcore/str/mod.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -2374,11 +2374,14 @@ impl str {
23742374
unsafe { Slices { str: self }.slice }
23752375
}
23762376

2377-
/// Converts a mutable string slice to a mutable byte slice. To convert the
2378-
/// mutable byte slice back into a mutable string slice, use the
2379-
/// [`str::from_utf8_mut`] function.
2377+
/// Converts a mutable string slice to a mutable byte slice.
23802378
///
2381-
/// [`str::from_utf8_mut`]: ./str/fn.from_utf8_mut.html
2379+
/// # Safety
2380+
///
2381+
/// The caller must ensure that the content of the slice is valid UTF-8
2382+
/// before the borrow ends and the underlying `str` is used.
2383+
///
2384+
/// Use of a `str` whose contents are not valid UTF-8 is undefined behavior.
23822385
///
23832386
/// # Examples
23842387
///

src/librustc_driver/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ pub const EXIT_SUCCESS: i32 = 0;
6565
/// Exit status code used for compilation failures and invalid flags.
6666
pub const EXIT_FAILURE: i32 = 1;
6767

68-
const BUG_REPORT_URL: &str = "https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.\
69-
md#bug-reports";
68+
const BUG_REPORT_URL: &str = "https://github.com/rust-lang/rust/issues/new\
69+
?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md";
7070

7171
const ICE_REPORT_COMPILER_FLAGS: &[&str] = &["Z", "C", "crate-type"];
7272

src/librustc_macros/src/symbols.rs

+24-5
Original file line numberDiff line numberDiff line change
@@ -87,18 +87,29 @@ pub fn symbols(input: TokenStream) -> TokenStream {
8787
let mut prefill_stream = quote! {};
8888
let mut counter = 0u32;
8989
let mut keys = HashSet::<String>::new();
90+
let mut prev_key: Option<String> = None;
91+
let mut errors = Vec::<String>::new();
9092

91-
let mut check_dup = |str: &str| {
93+
let mut check_dup = |str: &str, errors: &mut Vec<String>| {
9294
if !keys.insert(str.to_string()) {
93-
panic!("Symbol `{}` is duplicated", str);
95+
errors.push(format!("Symbol `{}` is duplicated", str));
9496
}
9597
};
9698

99+
let mut check_order = |str: &str, errors: &mut Vec<String>| {
100+
if let Some(ref prev_str) = prev_key {
101+
if str < prev_str {
102+
errors.push(format!("Symbol `{}` must precede `{}`", str, prev_str));
103+
}
104+
}
105+
prev_key = Some(str.to_string());
106+
};
107+
97108
// Generate the listed keywords.
98109
for keyword in &input.keywords.0 {
99110
let name = &keyword.name;
100111
let value = &keyword.value;
101-
check_dup(&value.value());
112+
check_dup(&value.value(), &mut errors);
102113
prefill_stream.extend(quote! {
103114
#value,
104115
});
@@ -116,7 +127,8 @@ pub fn symbols(input: TokenStream) -> TokenStream {
116127
Some(value) => value.value(),
117128
None => name.to_string(),
118129
};
119-
check_dup(&value);
130+
check_dup(&value, &mut errors);
131+
check_order(&name.to_string(), &mut errors);
120132
prefill_stream.extend(quote! {
121133
#value,
122134
});
@@ -131,7 +143,7 @@ pub fn symbols(input: TokenStream) -> TokenStream {
131143
// Generate symbols for the strings "0", "1", ..., "9".
132144
for n in 0..10 {
133145
let n = n.to_string();
134-
check_dup(&n);
146+
check_dup(&n, &mut errors);
135147
prefill_stream.extend(quote! {
136148
#n,
137149
});
@@ -141,6 +153,13 @@ pub fn symbols(input: TokenStream) -> TokenStream {
141153
counter += 1;
142154
}
143155

156+
if !errors.is_empty() {
157+
for error in errors.into_iter() {
158+
eprintln!("error: {}", error)
159+
}
160+
panic!("errors in `Keywords` and/or `Symbols`");
161+
}
162+
144163
let tt = TokenStream::from(quote! {
145164
macro_rules! keywords {
146165
() => {

0 commit comments

Comments
 (0)