Skip to content

Commit d55f3e9

Browse files
committed
Auto merge of #68625 - JohnTitor:rollup-20pfcru, r=JohnTitor
Rollup of 8 pull requests Successful merges: - #68289 (Don't ICE on path-collision in dep-graph) - #68378 (Add BTreeMap::remove_entry) - #68553 (Fix run button positionning in case of scrolling) - #68556 (rustdoc: Fix re-exporting primitive types) - #68582 (Add E0727 long explanation) - #68592 (fix: typo in vec.rs) - #68619 (Fix a few spelling mistakes) - #68620 (Update links to WASI docs in time.rs module) Failed merges: r? @ghost
2 parents 3761dcd + c0df1be commit d55f3e9

File tree

16 files changed

+203
-41
lines changed

16 files changed

+203
-41
lines changed

src/liballoc/collections/btree/map.rs

+30-1
Original file line numberDiff line numberDiff line change
@@ -806,13 +806,42 @@ impl<K: Ord, V> BTreeMap<K, V> {
806806
/// ```
807807
#[stable(feature = "rust1", since = "1.0.0")]
808808
pub fn remove<Q: ?Sized>(&mut self, key: &Q) -> Option<V>
809+
where
810+
K: Borrow<Q>,
811+
Q: Ord,
812+
{
813+
self.remove_entry(key).map(|(_, v)| v)
814+
}
815+
816+
/// Removes a key from the map, returning the stored key and value if the key
817+
/// was previously in the map.
818+
///
819+
/// The key may be any borrowed form of the map's key type, but the ordering
820+
/// on the borrowed form *must* match the ordering on the key type.
821+
///
822+
/// # Examples
823+
///
824+
/// Basic usage:
825+
///
826+
/// ```
827+
/// #![feature(btreemap_remove_entry)]
828+
/// use std::collections::BTreeMap;
829+
///
830+
/// let mut map = BTreeMap::new();
831+
/// map.insert(1, "a");
832+
/// assert_eq!(map.remove_entry(&1), Some((1, "a")));
833+
/// assert_eq!(map.remove_entry(&1), None);
834+
/// ```
835+
#[unstable(feature = "btreemap_remove_entry", issue = "66714")]
836+
pub fn remove_entry<Q: ?Sized>(&mut self, key: &Q) -> Option<(K, V)>
809837
where
810838
K: Borrow<Q>,
811839
Q: Ord,
812840
{
813841
match search::search_tree(self.root.as_mut(), key) {
814842
Found(handle) => Some(
815-
OccupiedEntry { handle, length: &mut self.length, _marker: PhantomData }.remove(),
843+
OccupiedEntry { handle, length: &mut self.length, _marker: PhantomData }
844+
.remove_entry(),
816845
),
817846
GoDown(_) => None,
818847
}

src/liballoc/vec.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ use crate::raw_vec::RawVec;
176176
/// ```
177177
///
178178
/// In Rust, it's more common to pass slices as arguments rather than vectors
179-
/// when you just want to provide a read access. The same goes for [`String`] and
179+
/// when you just want to provide read access. The same goes for [`String`] and
180180
/// [`&str`].
181181
///
182182
/// # Capacity and reallocation

src/librustc/dep_graph/graph.rs

+30-9
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use rustc_data_structures::sharded::{self, Sharded};
66
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
77
use rustc_data_structures::sync::{AtomicU32, AtomicU64, Lock, Lrc, Ordering};
88
use rustc_errors::Diagnostic;
9+
use rustc_hir::def_id::DefId;
910
use rustc_index::vec::{Idx, IndexVec};
1011
use smallvec::SmallVec;
1112
use std::collections::hash_map::Entry;
@@ -677,18 +678,33 @@ impl DepGraph {
677678
} else {
678679
match dep_dep_node.kind {
679680
DepKind::Hir | DepKind::HirBody | DepKind::CrateMetadata => {
680-
if dep_dep_node.extract_def_id(tcx).is_none() {
681+
if let Some(def_id) = dep_dep_node.extract_def_id(tcx) {
682+
if def_id_corresponds_to_hir_dep_node(tcx, def_id) {
683+
// The `DefPath` has corresponding node,
684+
// and that node should have been marked
685+
// either red or green in `data.colors`.
686+
bug!(
687+
"DepNode {:?} should have been \
688+
pre-marked as red or green but wasn't.",
689+
dep_dep_node
690+
);
691+
} else {
692+
// This `DefPath` does not have a
693+
// corresponding `DepNode` (e.g. a
694+
// struct field), and the ` DefPath`
695+
// collided with the `DefPath` of a
696+
// proper item that existed in the
697+
// previous compilation session.
698+
//
699+
// Since the given `DefPath` does not
700+
// denote the item that previously
701+
// existed, we just fail to mark green.
702+
return None;
703+
}
704+
} else {
681705
// If the node does not exist anymore, we
682706
// just fail to mark green.
683707
return None;
684-
} else {
685-
// If the node does exist, it should have
686-
// been pre-allocated.
687-
bug!(
688-
"DepNode {:?} should have been \
689-
pre-allocated but wasn't.",
690-
dep_dep_node
691-
)
692708
}
693709
}
694710
_ => {
@@ -899,6 +915,11 @@ impl DepGraph {
899915
}
900916
}
901917

918+
fn def_id_corresponds_to_hir_dep_node(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
919+
let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap();
920+
def_id.index == hir_id.owner
921+
}
922+
902923
/// A "work product" is an intermediate result that we save into the
903924
/// incremental directory for later re-use. The primary example are
904925
/// the object files that we save for each partition at code

src/librustc/mir/traversal.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use super::*;
44

55
/// Preorder traversal of a graph.
66
///
7-
/// Preorder traversal is when each node is visited before an of it's
7+
/// Preorder traversal is when each node is visited before any of its
88
/// successors
99
///
1010
/// ```text
@@ -82,7 +82,7 @@ impl<'a, 'tcx> Iterator for Preorder<'a, 'tcx> {
8282

8383
/// Postorder traversal of a graph.
8484
///
85-
/// Postorder traversal is when each node is visited after all of it's
85+
/// Postorder traversal is when each node is visited after all of its
8686
/// successors, except when the successor is only reachable by a back-edge
8787
///
8888
///

src/librustc_error_codes/error_codes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,7 @@ E0718: include_str!("./error_codes/E0718.md"),
397397
E0720: include_str!("./error_codes/E0720.md"),
398398
E0723: include_str!("./error_codes/E0723.md"),
399399
E0725: include_str!("./error_codes/E0725.md"),
400+
E0727: include_str!("./error_codes/E0727.md"),
400401
E0728: include_str!("./error_codes/E0728.md"),
401402
E0729: include_str!("./error_codes/E0729.md"),
402403
E0730: include_str!("./error_codes/E0730.md"),
@@ -607,6 +608,5 @@ E0746: include_str!("./error_codes/E0746.md"),
607608
E0722, // Malformed `#[optimize]` attribute
608609
E0724, // `#[ffi_returns_twice]` is only allowed in foreign functions
609610
E0726, // non-explicit (not `'_`) elided lifetime in unsupported position
610-
E0727, // `async` generators are not yet supported
611611
E0739, // invalid track_caller application/syntax
612612
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
A `yield` clause was used in an `async` context.
2+
3+
Example of erroneous code:
4+
5+
```compile_fail
6+
#![feature(generators)]
7+
8+
let generator = || {
9+
async {
10+
yield;
11+
}
12+
};
13+
```
14+
15+
Here, the `yield` keyword is used in an `async` block,
16+
which is not yet supported.
17+
18+
To fix this error, you have to move `yield` out of the `async` block:
19+
20+
```
21+
#![feature(generators)]
22+
23+
let generator = || {
24+
yield;
25+
};
26+
```

src/librustdoc/clean/inline.rs

+33-4
Original file line numberDiff line numberDiff line change
@@ -445,12 +445,41 @@ fn build_module(cx: &DocContext<'_>, did: DefId, visited: &mut FxHashSet<DefId>)
445445
// two namespaces, so the target may be listed twice. Make sure we only
446446
// visit each node at most once.
447447
for &item in cx.tcx.item_children(did).iter() {
448-
let def_id = item.res.def_id();
449448
if item.vis == ty::Visibility::Public {
450-
if did == def_id || !visited.insert(def_id) {
451-
continue;
449+
if let Some(def_id) = item.res.mod_def_id() {
450+
if did == def_id || !visited.insert(def_id) {
451+
continue;
452+
}
452453
}
453-
if let Some(i) = try_inline(cx, item.res, item.ident.name, None, visited) {
454+
if let Res::PrimTy(p) = item.res {
455+
// Primitive types can't be inlined so generate an import instead.
456+
items.push(clean::Item {
457+
name: None,
458+
attrs: clean::Attributes::default(),
459+
source: clean::Span::empty(),
460+
def_id: cx.tcx.hir().local_def_id_from_node_id(ast::CRATE_NODE_ID),
461+
visibility: clean::Public,
462+
stability: None,
463+
deprecation: None,
464+
inner: clean::ImportItem(clean::Import::Simple(
465+
item.ident.to_string(),
466+
clean::ImportSource {
467+
path: clean::Path {
468+
global: false,
469+
res: item.res,
470+
segments: vec![clean::PathSegment {
471+
name: clean::PrimitiveType::from(p).as_str().to_string(),
472+
args: clean::GenericArgs::AngleBracketed {
473+
args: Vec::new(),
474+
bindings: Vec::new(),
475+
},
476+
}],
477+
},
478+
did: None,
479+
},
480+
)),
481+
});
482+
} else if let Some(i) = try_inline(cx, item.res, item.ident.name, None, visited) {
454483
items.extend(i)
455484
}
456485
}

src/librustdoc/clean/types.rs

+13
Original file line numberDiff line numberDiff line change
@@ -1290,6 +1290,19 @@ impl From<ast::FloatTy> for PrimitiveType {
12901290
}
12911291
}
12921292

1293+
impl From<hir::PrimTy> for PrimitiveType {
1294+
fn from(prim_ty: hir::PrimTy) -> PrimitiveType {
1295+
match prim_ty {
1296+
hir::PrimTy::Int(int_ty) => int_ty.into(),
1297+
hir::PrimTy::Uint(uint_ty) => uint_ty.into(),
1298+
hir::PrimTy::Float(float_ty) => float_ty.into(),
1299+
hir::PrimTy::Str => PrimitiveType::Str,
1300+
hir::PrimTy::Bool => PrimitiveType::Bool,
1301+
hir::PrimTy::Char => PrimitiveType::Char,
1302+
}
1303+
}
1304+
}
1305+
12931306
#[derive(Clone, PartialEq, Eq, Debug)]
12941307
pub enum Visibility {
12951308
Public,

src/librustdoc/clean/utils.rs

+1-8
Original file line numberDiff line numberDiff line change
@@ -570,14 +570,7 @@ pub fn resolve_type(cx: &DocContext<'_>, path: Path, id: hir::HirId) -> Type {
570570
}
571571

572572
let is_generic = match path.res {
573-
Res::PrimTy(p) => match p {
574-
hir::PrimTy::Str => return Primitive(PrimitiveType::Str),
575-
hir::PrimTy::Bool => return Primitive(PrimitiveType::Bool),
576-
hir::PrimTy::Char => return Primitive(PrimitiveType::Char),
577-
hir::PrimTy::Int(int_ty) => return Primitive(int_ty.into()),
578-
hir::PrimTy::Uint(uint_ty) => return Primitive(uint_ty.into()),
579-
hir::PrimTy::Float(float_ty) => return Primitive(float_ty.into()),
580-
},
573+
Res::PrimTy(p) => return Primitive(PrimitiveType::from(p)),
581574
Res::SelfTy(..) if path.segments.len() == 1 => {
582575
return Generic(kw::SelfUpper.to_string());
583576
}

src/librustdoc/html/format.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -1171,11 +1171,14 @@ impl clean::ImportSource {
11711171
display_fn(move |f| match self.did {
11721172
Some(did) => resolved_path(f, did, &self.path, true, false),
11731173
_ => {
1174-
for (i, seg) in self.path.segments.iter().enumerate() {
1175-
if i > 0 {
1176-
write!(f, "::")?
1177-
}
1178-
write!(f, "{}", seg.name)?;
1174+
for seg in &self.path.segments[..self.path.segments.len() - 1] {
1175+
write!(f, "{}::", seg.name)?;
1176+
}
1177+
let name = self.path.last_name();
1178+
if let hir::def::Res::PrimTy(p) = self.path.res {
1179+
primitive_link(f, PrimitiveType::from(p), name)?;
1180+
} else {
1181+
write!(f, "{}", name)?;
11791182
}
11801183
Ok(())
11811184
}

src/librustdoc/html/highlight.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use syntax::token::{self, Token};
2222
pub fn render_with_highlighting(
2323
src: &str,
2424
class: Option<&str>,
25-
extension: Option<&str>,
25+
playground_button: Option<&str>,
2626
tooltip: Option<(&str, &str)>,
2727
) -> String {
2828
debug!("highlighting: ================\n{}\n==============", src);
@@ -58,10 +58,7 @@ pub fn render_with_highlighting(
5858
Ok(highlighted_source) => {
5959
write_header(class, &mut out).unwrap();
6060
write!(out, "{}", highlighted_source).unwrap();
61-
if let Some(extension) = extension {
62-
write!(out, "{}", extension).unwrap();
63-
}
64-
write_footer(&mut out).unwrap();
61+
write_footer(&mut out, playground_button).unwrap();
6562
}
6663
Err(()) => {
6764
// If errors are encountered while trying to highlight, just emit
@@ -433,6 +430,6 @@ fn write_header(class: Option<&str>, out: &mut dyn Write) -> io::Result<()> {
433430
write!(out, "<div class=\"example-wrap\"><pre class=\"rust {}\">\n", class.unwrap_or(""))
434431
}
435432

436-
fn write_footer(out: &mut dyn Write) -> io::Result<()> {
437-
write!(out, "</pre></div>\n")
433+
fn write_footer(out: &mut dyn Write, playground_button: Option<&str>) -> io::Result<()> {
434+
write!(out, "</pre>{}</div>\n", if let Some(button) = playground_button { button } else { "" })
438435
}

src/librustdoc/html/static/rustdoc.css

+3-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ summary {
136136
outline: none;
137137
}
138138

139-
code, pre {
139+
code, pre, a.test-arrow {
140140
font-family: "Source Code Pro", monospace;
141141
}
142142
.docblock code, .docblock-short code {
@@ -305,6 +305,7 @@ nav.sub {
305305
.rustdoc:not(.source) .example-wrap {
306306
display: inline-flex;
307307
margin-bottom: 10px;
308+
position: relative;
308309
}
309310

310311
.example-wrap {
@@ -878,6 +879,7 @@ a.test-arrow {
878879
font-size: 130%;
879880
top: 5px;
880881
right: 5px;
882+
z-index: 1;
881883
}
882884
a.test-arrow:hover{
883885
text-decoration: none;

src/libstd/time.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ pub use core::time::Duration;
7676
/// [QueryPerformanceCounter]: https://docs.microsoft.com/en-us/windows/win32/api/profileapi/nf-profileapi-queryperformancecounter
7777
/// [`insecure_time` usercall]: https://edp.fortanix.com/docs/api/fortanix_sgx_abi/struct.Usercalls.html#method.insecure_time
7878
/// [timekeeping in SGX]: https://edp.fortanix.com/docs/concepts/rust-std/#codestdtimecode
79-
/// [__wasi_clock_time_get (Monotonic Clock)]: https://github.com/CraneStation/wasmtime/blob/master/docs/WASI-api.md#clock_time_get
79+
/// [__wasi_clock_time_get (Monotonic Clock)]: https://github.com/WebAssembly/WASI/blob/master/phases/snapshot/docs.md#clock_time_get
8080
/// [clock_gettime (Monotonic Clock)]: https://linux.die.net/man/3/clock_gettime
8181
/// [mach_absolute_time]: https://developer.apple.com/library/archive/documentation/Darwin/Conceptual/KernelProgramming/services/services.html
8282
/// [clock_time_get (Monotonic Clock)]: https://nuxi.nl/cloudabi/#clock_time_get
@@ -157,7 +157,7 @@ pub struct Instant(time::Instant);
157157
/// [timekeeping in SGX]: https://edp.fortanix.com/docs/concepts/rust-std/#codestdtimecode
158158
/// [gettimeofday]: http://man7.org/linux/man-pages/man2/gettimeofday.2.html
159159
/// [clock_gettime (Realtime Clock)]: https://linux.die.net/man/3/clock_gettime
160-
/// [__wasi_clock_time_get (Realtime Clock)]: https://github.com/CraneStation/wasmtime/blob/master/docs/WASI-api.md#clock_time_get
160+
/// [__wasi_clock_time_get (Realtime Clock)]: https://github.com/WebAssembly/WASI/blob/master/phases/snapshot/docs.md#clock_time_get
161161
/// [GetSystemTimeAsFileTime]: https://docs.microsoft.com/en-us/windows/win32/api/sysinfoapi/nf-sysinfoapi-getsystemtimeasfiletime
162162
///
163163
/// **Disclaimer:** These system calls might change over time.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// revisions: rpass1 rpass2
2+
3+
#[cfg(rpass1)]
4+
pub trait Something {
5+
fn foo();
6+
}
7+
8+
#[cfg(rpass2)]
9+
pub struct Something {
10+
pub foo: u8,
11+
}
12+
13+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// compile-flags: --emit metadata --crate-type lib --edition 2018
2+
3+
#![crate_name = "foo"]
4+
5+
pub mod bar {
6+
pub use bool;
7+
pub use char as my_char;
8+
}

0 commit comments

Comments
 (0)