Skip to content

Commit ad1eaff

Browse files
committed
Auto merge of rust-lang#88143 - GuillaumeGomez:rollup-sgh318f, r=GuillaumeGomez
Rollup of 10 pull requests Successful merges: - rust-lang#87818 (Fix anchors display in rustdoc) - rust-lang#87983 (Use more accurate spans when proposing adding lifetime to item) - rust-lang#88012 (Change WASI's `RawFd` from `u32` to `c_int` (`i32`).) - rust-lang#88031 (Make `BuildHasher` object safe) - rust-lang#88036 (Fix dead code warning when inline const is used in pattern) - rust-lang#88082 (Take into account jobs number for rustdoc GUI tests) - rust-lang#88109 (Fix environment variable getter docs) - rust-lang#88111 (Add background-color on clickable definitions in source code) - rust-lang#88129 (Fix dataflow graphviz bug, make dataflow graphviz modules public) - rust-lang#88136 (Move private_unused.rs test to impl-trait) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 6d30039 + 9bbb57c commit ad1eaff

File tree

37 files changed

+303
-108
lines changed

37 files changed

+303
-108
lines changed

compiler/rustc_mir/src/dataflow/framework/fmt.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub trait DebugWithContext<C>: Eq + fmt::Debug {
3333
}
3434

3535
write!(f, "\u{001f}-")?;
36-
self.fmt_with(ctxt, f)
36+
old.fmt_with(ctxt, f)
3737
}
3838
}
3939

compiler/rustc_mir/src/dataflow/framework/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ mod cursor;
4242
mod direction;
4343
mod engine;
4444
pub mod fmt;
45-
mod graphviz;
45+
pub mod graphviz;
4646
pub mod lattice;
4747
mod visitor;
4848

compiler/rustc_mir/src/dataflow/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustc_span::symbol::{sym, Symbol};
55

66
pub(crate) use self::drop_flag_effects::*;
77
pub use self::framework::{
8-
fmt, lattice, visit_results, Analysis, AnalysisDomain, Backward, BorrowckFlowState,
8+
fmt, graphviz, lattice, visit_results, Analysis, AnalysisDomain, Backward, BorrowckFlowState,
99
BorrowckResults, Engine, Forward, GenKill, GenKillAnalysis, JoinSemiLattice, Results,
1010
ResultsCursor, ResultsRefCursor, ResultsVisitor, SwitchIntEdgeEffects,
1111
};

compiler/rustc_mir/src/util/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ pub use self::alignment::is_disaligned;
1818
pub use self::find_self_call::find_self_call;
1919
pub use self::generic_graph::graphviz_safe_def_name;
2020
pub use self::graphviz::write_mir_graphviz;
21-
pub use self::pretty::{dump_enabled, dump_mir, write_mir_pretty, PassWhere};
21+
pub use self::pretty::{dump_enabled, dump_mir, write_mir_fn, write_mir_pretty, PassWhere};

compiler/rustc_passes/src/dead.rs

+7
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use rustc_middle::middle::privacy;
1515
use rustc_middle::ty::{self, DefIdTree, TyCtxt};
1616
use rustc_session::lint;
1717
use rustc_span::symbol::{sym, Symbol};
18+
use std::mem;
1819

1920
// Any local node that may call something in its body block should be
2021
// explored. For example, if it's a live Node::Item that is a
@@ -395,8 +396,14 @@ impl<'tcx> Visitor<'tcx> for MarkSymbolVisitor<'tcx> {
395396
}
396397

397398
fn visit_anon_const(&mut self, c: &'tcx hir::AnonConst) {
399+
// When inline const blocks are used in pattern position, paths
400+
// referenced by it should be considered as used.
401+
let in_pat = mem::replace(&mut self.in_pat, false);
402+
398403
self.live_symbols.insert(self.tcx.hir().local_def_id(c.hir_id));
399404
intravisit::walk_anon_const(self, c);
405+
406+
self.in_pat = in_pat;
400407
}
401408
}
402409

compiler/rustc_resolve/src/late/diagnostics.rs

+76-10
Original file line numberDiff line numberDiff line change
@@ -2073,20 +2073,85 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
20732073
continue;
20742074
}
20752075
});
2076+
2077+
struct Lifetime(Span, String);
2078+
impl Lifetime {
2079+
fn is_unnamed(&self) -> bool {
2080+
self.1.starts_with('&') && !self.1.starts_with("&'")
2081+
}
2082+
fn is_underscore(&self) -> bool {
2083+
self.1.starts_with("&'_ ")
2084+
}
2085+
fn is_named(&self) -> bool {
2086+
self.1.starts_with("&'")
2087+
}
2088+
fn suggestion(&self, sugg: String) -> Option<(Span, String)> {
2089+
Some(
2090+
match (
2091+
self.is_unnamed(),
2092+
self.is_underscore(),
2093+
self.is_named(),
2094+
sugg.starts_with("&"),
2095+
) {
2096+
(true, _, _, false) => (self.span_unnamed_borrow(), sugg),
2097+
(true, _, _, true) => {
2098+
(self.span_unnamed_borrow(), sugg[1..].to_string())
2099+
}
2100+
(_, true, _, false) => {
2101+
(self.span_underscore_borrow(), sugg.trim().to_string())
2102+
}
2103+
(_, true, _, true) => {
2104+
(self.span_underscore_borrow(), sugg[1..].trim().to_string())
2105+
}
2106+
(_, _, true, false) => {
2107+
(self.span_named_borrow(), sugg.trim().to_string())
2108+
}
2109+
(_, _, true, true) => {
2110+
(self.span_named_borrow(), sugg[1..].trim().to_string())
2111+
}
2112+
_ => return None,
2113+
},
2114+
)
2115+
}
2116+
fn span_unnamed_borrow(&self) -> Span {
2117+
let lo = self.0.lo() + BytePos(1);
2118+
self.0.with_lo(lo).with_hi(lo)
2119+
}
2120+
fn span_named_borrow(&self) -> Span {
2121+
let lo = self.0.lo() + BytePos(1);
2122+
self.0.with_lo(lo)
2123+
}
2124+
fn span_underscore_borrow(&self) -> Span {
2125+
let lo = self.0.lo() + BytePos(1);
2126+
let hi = lo + BytePos(2);
2127+
self.0.with_lo(lo).with_hi(hi)
2128+
}
2129+
}
2130+
20762131
for param in params {
20772132
if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(param.span) {
2078-
if snippet.starts_with('&') && !snippet.starts_with("&'") {
2079-
introduce_suggestion
2080-
.push((param.span, format!("&'a {}", &snippet[1..])));
2081-
} else if let Some(stripped) = snippet.strip_prefix("&'_ ") {
2082-
introduce_suggestion.push((param.span, format!("&'a {}", &stripped)));
2133+
if let Some((span, sugg)) =
2134+
Lifetime(param.span, snippet).suggestion("'a ".to_string())
2135+
{
2136+
introduce_suggestion.push((span, sugg));
20832137
}
20842138
}
20852139
}
2086-
for ((span, _), sugg) in spans_with_counts.iter().copied().zip(suggs.iter()) {
2087-
if let Some(sugg) = sugg {
2088-
introduce_suggestion.push((span, sugg.to_string()));
2089-
}
2140+
for (span, sugg) in spans_with_counts.iter().copied().zip(suggs.iter()).filter_map(
2141+
|((span, _), sugg)| match &sugg {
2142+
Some(sugg) => Some((span, sugg.to_string())),
2143+
_ => None,
2144+
},
2145+
) {
2146+
let (span, sugg) = self
2147+
.tcx
2148+
.sess
2149+
.source_map()
2150+
.span_to_snippet(span)
2151+
.ok()
2152+
.and_then(|snippet| Lifetime(span, snippet).suggestion(sugg.clone()))
2153+
.unwrap_or((span, sugg));
2154+
introduce_suggestion.push((span, sugg.to_string()));
20902155
}
20912156
err.multipart_suggestion_with_style(
20922157
&msg,
@@ -2159,7 +2224,8 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
21592224
for ((span, _), snippet) in spans_with_counts.iter().copied().zip(snippets.iter()) {
21602225
match snippet.as_deref() {
21612226
Some("") => spans_suggs.push((span, "'lifetime, ".to_string())),
2162-
Some("&") => spans_suggs.push((span, "&'lifetime ".to_string())),
2227+
Some("&") => spans_suggs
2228+
.push((span.with_lo(span.lo() + BytePos(1)), "'lifetime ".to_string())),
21632229
_ => {}
21642230
}
21652231
}

library/core/src/hash/mod.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,10 @@ pub trait BuildHasher {
520520
/// );
521521
/// ```
522522
#[unstable(feature = "build_hasher_simple_hash_one", issue = "86161")]
523-
fn hash_one<T: Hash>(&self, x: T) -> u64 {
523+
fn hash_one<T: Hash>(&self, x: T) -> u64
524+
where
525+
Self: Sized,
526+
{
524527
let mut hasher = self.build_hasher();
525528
x.hash(&mut hasher);
526529
hasher.finish()

library/core/tests/hash/mod.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
mod sip;
22

33
use std::default::Default;
4-
use std::hash::{Hash, Hasher};
4+
use std::hash::{BuildHasher, Hash, Hasher};
55
use std::rc::Rc;
66

77
struct MyHasher {
@@ -139,3 +139,10 @@ fn test_indirect_hasher() {
139139
}
140140
assert_eq!(hasher.hash, 5);
141141
}
142+
143+
#[test]
144+
fn test_build_hasher_object_safe() {
145+
use std::collections::hash_map::{DefaultHasher, RandomState};
146+
147+
let _: &dyn BuildHasher<Hasher = DefaultHasher> = &RandomState::new();
148+
}

library/std/src/env.rs

+14-5
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,13 @@ impl fmt::Debug for VarsOs {
185185
///
186186
/// # Errors
187187
///
188-
/// Returns `[None]` if the environment variable isn't set.
189-
/// Returns `[None]` if the environment variable is not valid Unicode. If this is not
190-
/// desired, consider using [`var_os`].
188+
/// This function will return an error if the environment variable isn't set.
189+
///
190+
/// This function may return an error if the environment variable's name contains
191+
/// the equal sign character (`=`) or the NUL character.
192+
///
193+
/// This function will return an error if the environment variable's value is
194+
/// not valid Unicode. If this is not desired, consider using [`var_os`].
191195
///
192196
/// # Examples
193197
///
@@ -221,8 +225,13 @@ fn _var(key: &OsStr) -> Result<String, VarError> {
221225
///
222226
/// # Errors
223227
///
224-
/// Returns `[None]` if the variable isn't set.
225-
/// May return `[None]` if the variable value contains the NUL character.
228+
/// This function returns an error if the environment variable isn't set.
229+
///
230+
/// This function may return an error if the environment variable's name contains
231+
/// the equal sign character (`=`) or the NUL character.
232+
///
233+
/// This function may return an error if the environment variable's value contains
234+
/// the NUL character.
226235
///
227236
/// # Examples
228237
///

library/std/src/os/wasi/io.rs

+14-7
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,18 @@
66
use crate::fs;
77
use crate::io;
88
use crate::net;
9+
use crate::os::raw;
910
use crate::sys;
1011
use crate::sys_common::{AsInner, FromInner, IntoInner};
1112

1213
/// Raw file descriptors.
13-
pub type RawFd = u32;
14+
///
15+
/// This has type `c_int` to ease compatibility with code that also compiles on
16+
/// Unix configurations, however unlike Unix and POSIX, in WASI negative file
17+
/// descriptors are valid. Only `-1` is reserved for indicating errors. Code
18+
/// intending to be portable across Unix platforms and WASI should avoid
19+
/// assuming that negative file descriptors are invalid.
20+
pub type RawFd = raw::c_int;
1421

1522
/// A trait to extract the raw WASI file descriptor from an underlying
1623
/// object.
@@ -161,41 +168,41 @@ impl IntoRawFd for fs::File {
161168
impl AsRawFd for io::Stdin {
162169
#[inline]
163170
fn as_raw_fd(&self) -> RawFd {
164-
libc::STDIN_FILENO as RawFd
171+
libc::STDIN_FILENO
165172
}
166173
}
167174

168175
impl AsRawFd for io::Stdout {
169176
#[inline]
170177
fn as_raw_fd(&self) -> RawFd {
171-
libc::STDOUT_FILENO as RawFd
178+
libc::STDOUT_FILENO
172179
}
173180
}
174181

175182
impl AsRawFd for io::Stderr {
176183
#[inline]
177184
fn as_raw_fd(&self) -> RawFd {
178-
libc::STDERR_FILENO as RawFd
185+
libc::STDERR_FILENO
179186
}
180187
}
181188

182189
impl<'a> AsRawFd for io::StdinLock<'a> {
183190
#[inline]
184191
fn as_raw_fd(&self) -> RawFd {
185-
libc::STDIN_FILENO as RawFd
192+
libc::STDIN_FILENO
186193
}
187194
}
188195

189196
impl<'a> AsRawFd for io::StdoutLock<'a> {
190197
#[inline]
191198
fn as_raw_fd(&self) -> RawFd {
192-
libc::STDOUT_FILENO as RawFd
199+
libc::STDOUT_FILENO
193200
}
194201
}
195202

196203
impl<'a> AsRawFd for io::StderrLock<'a> {
197204
#[inline]
198205
fn as_raw_fd(&self) -> RawFd {
199-
libc::STDERR_FILENO as RawFd
206+
libc::STDERR_FILENO
200207
}
201208
}

0 commit comments

Comments
 (0)