Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 10 pull requests #88143

Merged
merged 25 commits into from Aug 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
35de5c9
Change WASI's `RawFd` from `u32` to `c_int` (`i32`).
sunfishcode Aug 13, 2021
481b282
make `BuildHasher` object safe
ibraheemdev Aug 14, 2021
2969aec
Fix dead code warning when inline const is used in pattern
nbdd0121 Aug 14, 2021
58f988f
move object safety test to library/core
ibraheemdev Aug 15, 2021
e62ecdc
Add a dead code test for using anon const in pattern
nbdd0121 Aug 14, 2021
9c21da6
Take into account jobs number for rustdoc gui tests
GuillaumeGomez Aug 16, 2021
fdf0913
Fix environment variable getter docs
inquisitivecrystal Aug 17, 2021
7ce7fe7
Add background-color on clickable definitions in source code
GuillaumeGomez Aug 17, 2021
907ce72
Expose graphviz modules
willcrichton Aug 17, 2021
0ce96bd
Fix bug in fmt_diff_with
willcrichton Aug 18, 2021
14add46
Use more accurate spans when proposing adding lifetime to item
estebank Aug 12, 2021
dc24f02
Fix anchors display in rustdoc
GuillaumeGomez Aug 6, 2021
12a776b
review comment: reduce duplication
estebank Aug 18, 2021
dcb97b6
Move private_unused.rs test to impl-trait
spastorino Aug 18, 2021
9349046
review comment: use newtype to deduplicate logic
estebank Aug 18, 2021
e89c7d0
Rollup merge of #87818 - GuillaumeGomez:anchors-display-rustdoc, r=ca…
GuillaumeGomez Aug 18, 2021
7449c6e
Rollup merge of #87983 - estebank:smaller-lt-spans, r=oli-obk
GuillaumeGomez Aug 18, 2021
627bc60
Rollup merge of #88012 - sunfishcode:sunfishcode/wasi-raw-fd-c-int, r…
GuillaumeGomez Aug 18, 2021
9b7c771
Rollup merge of #88031 - ibraheemdev:build-hasher-object-safe, r=m-ou-se
GuillaumeGomez Aug 18, 2021
016f691
Rollup merge of #88036 - nbdd0121:const3, r=petrochenkov
GuillaumeGomez Aug 18, 2021
fe025a7
Rollup merge of #88082 - GuillaumeGomez:rustdoc-gui-jobs-opt, r=dns2utf8
GuillaumeGomez Aug 18, 2021
fbaa4a2
Rollup merge of #88109 - inquisitivecrystal:env-docs, r=m-ou-se
GuillaumeGomez Aug 18, 2021
75c6a91
Rollup merge of #88111 - GuillaumeGomez:background-color-jump-to-def,…
GuillaumeGomez Aug 18, 2021
e2271cd
Rollup merge of #88129 - willcrichton:expose-graphviz-modules, r=ecst…
GuillaumeGomez Aug 18, 2021
9bbb57c
Rollup merge of #88136 - spastorino:fix-test-directory, r=oli-obk
GuillaumeGomez Aug 18, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_mir/src/dataflow/framework/fmt.rs
Expand Up @@ -33,7 +33,7 @@ pub trait DebugWithContext<C>: Eq + fmt::Debug {
}

write!(f, "\u{001f}-")?;
self.fmt_with(ctxt, f)
old.fmt_with(ctxt, f)
}
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir/src/dataflow/framework/mod.rs
Expand Up @@ -42,7 +42,7 @@ mod cursor;
mod direction;
mod engine;
pub mod fmt;
mod graphviz;
pub mod graphviz;
pub mod lattice;
mod visitor;

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir/src/dataflow/mod.rs
Expand Up @@ -5,7 +5,7 @@ use rustc_span::symbol::{sym, Symbol};

pub(crate) use self::drop_flag_effects::*;
pub use self::framework::{
fmt, lattice, visit_results, Analysis, AnalysisDomain, Backward, BorrowckFlowState,
fmt, graphviz, lattice, visit_results, Analysis, AnalysisDomain, Backward, BorrowckFlowState,
BorrowckResults, Engine, Forward, GenKill, GenKillAnalysis, JoinSemiLattice, Results,
ResultsCursor, ResultsRefCursor, ResultsVisitor, SwitchIntEdgeEffects,
};
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir/src/util/mod.rs
Expand Up @@ -18,4 +18,4 @@ pub use self::alignment::is_disaligned;
pub use self::find_self_call::find_self_call;
pub use self::generic_graph::graphviz_safe_def_name;
pub use self::graphviz::write_mir_graphviz;
pub use self::pretty::{dump_enabled, dump_mir, write_mir_pretty, PassWhere};
pub use self::pretty::{dump_enabled, dump_mir, write_mir_fn, write_mir_pretty, PassWhere};
7 changes: 7 additions & 0 deletions compiler/rustc_passes/src/dead.rs
Expand Up @@ -15,6 +15,7 @@ use rustc_middle::middle::privacy;
use rustc_middle::ty::{self, DefIdTree, TyCtxt};
use rustc_session::lint;
use rustc_span::symbol::{sym, Symbol};
use std::mem;

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

fn visit_anon_const(&mut self, c: &'tcx hir::AnonConst) {
// When inline const blocks are used in pattern position, paths
// referenced by it should be considered as used.
let in_pat = mem::replace(&mut self.in_pat, false);

self.live_symbols.insert(self.tcx.hir().local_def_id(c.hir_id));
intravisit::walk_anon_const(self, c);

self.in_pat = in_pat;
}
}

Expand Down
86 changes: 76 additions & 10 deletions compiler/rustc_resolve/src/late/diagnostics.rs
Expand Up @@ -2073,20 +2073,85 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
continue;
}
});

struct Lifetime(Span, String);
impl Lifetime {
fn is_unnamed(&self) -> bool {
self.1.starts_with('&') && !self.1.starts_with("&'")
}
fn is_underscore(&self) -> bool {
self.1.starts_with("&'_ ")
}
fn is_named(&self) -> bool {
self.1.starts_with("&'")
}
fn suggestion(&self, sugg: String) -> Option<(Span, String)> {
Some(
match (
self.is_unnamed(),
self.is_underscore(),
self.is_named(),
sugg.starts_with("&"),
) {
(true, _, _, false) => (self.span_unnamed_borrow(), sugg),
(true, _, _, true) => {
(self.span_unnamed_borrow(), sugg[1..].to_string())
}
(_, true, _, false) => {
(self.span_underscore_borrow(), sugg.trim().to_string())
}
(_, true, _, true) => {
(self.span_underscore_borrow(), sugg[1..].trim().to_string())
}
(_, _, true, false) => {
(self.span_named_borrow(), sugg.trim().to_string())
}
(_, _, true, true) => {
(self.span_named_borrow(), sugg[1..].trim().to_string())
}
_ => return None,
},
)
}
fn span_unnamed_borrow(&self) -> Span {
let lo = self.0.lo() + BytePos(1);
self.0.with_lo(lo).with_hi(lo)
}
fn span_named_borrow(&self) -> Span {
let lo = self.0.lo() + BytePos(1);
self.0.with_lo(lo)
}
fn span_underscore_borrow(&self) -> Span {
let lo = self.0.lo() + BytePos(1);
let hi = lo + BytePos(2);
self.0.with_lo(lo).with_hi(hi)
}
}

for param in params {
if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(param.span) {
if snippet.starts_with('&') && !snippet.starts_with("&'") {
introduce_suggestion
.push((param.span, format!("&'a {}", &snippet[1..])));
} else if let Some(stripped) = snippet.strip_prefix("&'_ ") {
introduce_suggestion.push((param.span, format!("&'a {}", &stripped)));
if let Some((span, sugg)) =
Lifetime(param.span, snippet).suggestion("'a ".to_string())
{
introduce_suggestion.push((span, sugg));
}
}
}
for ((span, _), sugg) in spans_with_counts.iter().copied().zip(suggs.iter()) {
if let Some(sugg) = sugg {
introduce_suggestion.push((span, sugg.to_string()));
}
for (span, sugg) in spans_with_counts.iter().copied().zip(suggs.iter()).filter_map(
|((span, _), sugg)| match &sugg {
Some(sugg) => Some((span, sugg.to_string())),
_ => None,
},
) {
let (span, sugg) = self
.tcx
.sess
.source_map()
.span_to_snippet(span)
.ok()
.and_then(|snippet| Lifetime(span, snippet).suggestion(sugg.clone()))
.unwrap_or((span, sugg));
introduce_suggestion.push((span, sugg.to_string()));
}
err.multipart_suggestion_with_style(
&msg,
Expand Down Expand Up @@ -2159,7 +2224,8 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
for ((span, _), snippet) in spans_with_counts.iter().copied().zip(snippets.iter()) {
match snippet.as_deref() {
Some("") => spans_suggs.push((span, "'lifetime, ".to_string())),
Some("&") => spans_suggs.push((span, "&'lifetime ".to_string())),
Some("&") => spans_suggs
.push((span.with_lo(span.lo() + BytePos(1)), "'lifetime ".to_string())),
_ => {}
}
}
Expand Down
5 changes: 4 additions & 1 deletion library/core/src/hash/mod.rs
Expand Up @@ -520,7 +520,10 @@ pub trait BuildHasher {
/// );
/// ```
#[unstable(feature = "build_hasher_simple_hash_one", issue = "86161")]
fn hash_one<T: Hash>(&self, x: T) -> u64 {
fn hash_one<T: Hash>(&self, x: T) -> u64
where
Self: Sized,
{
let mut hasher = self.build_hasher();
x.hash(&mut hasher);
hasher.finish()
Expand Down
9 changes: 8 additions & 1 deletion library/core/tests/hash/mod.rs
@@ -1,7 +1,7 @@
mod sip;

use std::default::Default;
use std::hash::{Hash, Hasher};
use std::hash::{BuildHasher, Hash, Hasher};
use std::rc::Rc;

struct MyHasher {
Expand Down Expand Up @@ -139,3 +139,10 @@ fn test_indirect_hasher() {
}
assert_eq!(hasher.hash, 5);
}

#[test]
fn test_build_hasher_object_safe() {
use std::collections::hash_map::{DefaultHasher, RandomState};

let _: &dyn BuildHasher<Hasher = DefaultHasher> = &RandomState::new();
}
19 changes: 14 additions & 5 deletions library/std/src/env.rs
Expand Up @@ -185,9 +185,13 @@ impl fmt::Debug for VarsOs {
///
/// # Errors
///
/// Returns `[None]` if the environment variable isn't set.
/// Returns `[None]` if the environment variable is not valid Unicode. If this is not
/// desired, consider using [`var_os`].
/// This function will return an error if the environment variable isn't set.
///
/// This function may return an error if the environment variable's name contains
/// the equal sign character (`=`) or the NUL character.
///
/// This function will return an error if the environment variable's value is
/// not valid Unicode. If this is not desired, consider using [`var_os`].
///
/// # Examples
///
Expand Down Expand Up @@ -221,8 +225,13 @@ fn _var(key: &OsStr) -> Result<String, VarError> {
///
/// # Errors
///
/// Returns `[None]` if the variable isn't set.
/// May return `[None]` if the variable value contains the NUL character.
/// This function returns an error if the environment variable isn't set.
///
/// This function may return an error if the environment variable's name contains
/// the equal sign character (`=`) or the NUL character.
///
/// This function may return an error if the environment variable's value contains
/// the NUL character.
///
/// # Examples
///
Expand Down
21 changes: 14 additions & 7 deletions library/std/src/os/wasi/io.rs
Expand Up @@ -6,11 +6,18 @@
use crate::fs;
use crate::io;
use crate::net;
use crate::os::raw;
use crate::sys;
use crate::sys_common::{AsInner, FromInner, IntoInner};

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

/// A trait to extract the raw WASI file descriptor from an underlying
/// object.
Expand Down Expand Up @@ -161,41 +168,41 @@ impl IntoRawFd for fs::File {
impl AsRawFd for io::Stdin {
#[inline]
fn as_raw_fd(&self) -> RawFd {
libc::STDIN_FILENO as RawFd
libc::STDIN_FILENO
}
}

impl AsRawFd for io::Stdout {
#[inline]
fn as_raw_fd(&self) -> RawFd {
libc::STDOUT_FILENO as RawFd
libc::STDOUT_FILENO
}
}

impl AsRawFd for io::Stderr {
#[inline]
fn as_raw_fd(&self) -> RawFd {
libc::STDERR_FILENO as RawFd
libc::STDERR_FILENO
}
}

impl<'a> AsRawFd for io::StdinLock<'a> {
#[inline]
fn as_raw_fd(&self) -> RawFd {
libc::STDIN_FILENO as RawFd
libc::STDIN_FILENO
}
}

impl<'a> AsRawFd for io::StdoutLock<'a> {
#[inline]
fn as_raw_fd(&self) -> RawFd {
libc::STDOUT_FILENO as RawFd
libc::STDOUT_FILENO
}
}

impl<'a> AsRawFd for io::StderrLock<'a> {
#[inline]
fn as_raw_fd(&self) -> RawFd {
libc::STDERR_FILENO as RawFd
libc::STDERR_FILENO
}
}