Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions compiler/rustc_arena/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ impl<T> TypedArena<T> {
unsafe {
// Clear the last chunk, which is partially filled.
let mut chunks_borrow = self.chunks.borrow_mut();
if let Some(mut last_chunk) = chunks_borrow.last_mut() {
self.clear_last_chunk(&mut last_chunk);
if let Some(last_chunk) = chunks_borrow.last_mut() {
self.clear_last_chunk(last_chunk);
let len = chunks_borrow.len();
// If `T` is ZST, code below has no effect.
for mut chunk in chunks_borrow.drain(..len - 1) {
Expand Down Expand Up @@ -204,7 +204,7 @@ fn test_typed_arena_drop_on_clear() {
}

thread_local! {
static DROP_COUNTER: Cell<u32> = Cell::new(0)
static DROP_COUNTER: Cell<u32> = const { Cell::new(0) }
}

struct SmallDroppable;
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_fluent_macro/src/fluent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ pub(crate) fn fluent_messages(input: proc_macro::TokenStream) -> proc_macro::Tok
Level::Error,
format!("referenced message `{mref}` does not exist (in message `{name}`)"),
)
.help(&format!("you may have meant to use a variable reference (`{{${mref}}}`)"))
.help(format!("you may have meant to use a variable reference (`{{${mref}}}`)"))
.emit();
}
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_graphviz/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ impl<'a> Id<'a> {
/// it in the generated .dot file. They can also provide more
/// elaborate (and non-unique) label text that is used in the graphviz
/// rendered output.
///
/// The graph instance is responsible for providing the DOT compatible
/// identifiers for the nodes and (optionally) rendered labels for the nodes and
/// edges, as well as an identifier for the graph itself.
Expand Down
18 changes: 8 additions & 10 deletions compiler/rustc_graphviz/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ impl NodeLabels<&'static str> {
}

fn len(&self) -> usize {
match self {
&UnlabelledNodes(len) => len,
&AllNodesLabelled(ref lbls) => lbls.len(),
&SomeNodesLabelled(ref lbls) => lbls.len(),
match *self {
UnlabelledNodes(len) => len,
AllNodesLabelled(ref lbls) => lbls.len(),
SomeNodesLabelled(ref lbls) => lbls.len(),
}
}
}
Expand Down Expand Up @@ -394,17 +394,15 @@ fn left_aligned_text() {
#[test]
fn simple_id_construction() {
let id1 = Id::new("hello");
match id1 {
Ok(_) => {}
Err(..) => panic!("'hello' is not a valid value for id anymore"),
if id1.is_err() {
panic!("'hello' is not a valid value for id anymore");
}
}

#[test]
fn badly_formatted_id() {
let id2 = Id::new("Weird { struct : ure } !!!");
match id2 {
Ok(_) => panic!("graphviz id suddenly allows spaces, brackets and stuff"),
Err(..) => {}
if id2.is_ok() {
panic!("graphviz id suddenly allows spaces, brackets and stuff");
}
}
2 changes: 1 addition & 1 deletion compiler/rustc_hashes/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl FromStableHash for Hash64 {
type Hash = StableHasherHash;

#[inline]
fn from(StableHasherHash([_0, __1]): Self::Hash) -> Self {
fn from(StableHasherHash([_0, _]): Self::Hash) -> Self {
Self { inner: _0 }
}
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_llvm/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ fn main() {

// Include path contains host directory, replace it with target
if is_crossed && flag.starts_with("-I") {
cfg.flag(&flag.replace(&host, &target));
cfg.flag(flag.replace(&host, &target));
continue;
}

Expand Down
13 changes: 5 additions & 8 deletions compiler/rustc_log/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl LoggerConfig {

/// Initialize the logger with the given values for the filter, coloring, and other options env variables.
pub fn init_logger(cfg: LoggerConfig) -> Result<(), Error> {
init_logger_with_additional_layer(cfg, || Registry::default())
init_logger_with_additional_layer(cfg, Registry::default)
}

/// Trait alias for the complex return type of `build_subscriber` in
Expand Down Expand Up @@ -145,14 +145,11 @@ where
.with_thread_ids(verbose_thread_ids)
.with_thread_names(verbose_thread_ids);

match cfg.wraptree {
Ok(v) => match v.parse::<usize>() {
Ok(v) => {
layer = layer.with_wraparound(v);
}
if let Ok(v) = cfg.wraptree {
match v.parse::<usize>() {
Ok(v) => layer = layer.with_wraparound(v),
Err(_) => return Err(Error::InvalidWraptree(v)),
},
Err(_) => {} // no wraptree
}
}

let subscriber = build_subscriber().with(layer.with_filter(filter));
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_serialize/src/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ impl<S: Encoder> Encodable<S> for str {

impl<S: Encoder> Encodable<S> for String {
fn encode(&self, s: &mut S) {
s.emit_str(&self);
s.emit_str(self);
}
}

Expand Down Expand Up @@ -341,8 +341,8 @@ impl<D: Decoder, const N: usize> Decodable<D> for [u8; N] {
let len = d.read_usize();
assert!(len == N);
let mut v = [0u8; N];
for i in 0..len {
v[i] = Decodable::decode(d);
for i in v.iter_mut() {
*i = Decodable::decode(d);
}
v
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_thread_pool/src/broadcast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ where
registry.inject_broadcast(job_refs);

let current_thread_job_id = current_thread
.and_then(|worker| (registry.id() == worker.registry.id()).then(|| worker))
.and_then(|worker| (registry.id() == worker.registry.id()).then_some(worker))
.map(|worker| unsafe { jobs[worker.index()].as_job_ref() }.id());

// Wait for all jobs to complete, then collect the results, maybe propagating a panic.
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_thread_pool/src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,7 @@ impl WorkerThread {
latch: &L,
mut all_jobs_started: impl FnMut() -> bool,
mut is_job: impl FnMut(&JobRef) -> bool,
mut execute_job: impl FnMut(JobRef) -> (),
mut execute_job: impl FnMut(JobRef),
) {
let mut jobs = SmallVec::<[JobRef; 8]>::new();
let mut broadcast_jobs = SmallVec::<[JobRef; 8]>::new();
Expand Down Expand Up @@ -897,7 +897,7 @@ impl WorkerThread {
// The job might have injected local work, so go back to the outer loop.
continue 'outer;
} else {
self.registry.sleep.no_work_found(&mut idle_state, latch, &self, true)
self.registry.sleep.no_work_found(&mut idle_state, latch, self, true)
}
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_thread_pool/src/scope/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ fn the_final_countdown<'scope>(
let top_of_stack = 0;
let p = bottom_of_stack as *const i32 as usize;
let q = &top_of_stack as *const i32 as usize;
let diff = if p > q { p - q } else { q - p };
let diff = p.abs_diff(q);

let mut data = max.lock().unwrap();
*data = Ord::max(diff, *data);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_thread_pool/src/thread_pool/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ fn failed_thread_stack() {
// macOS and Windows weren't fazed, or at least didn't fail the way we want.
// They work with `isize::MAX`, but 32-bit platforms may feasibly allocate a
// 2GB stack, so it might not fail until the second thread.
let stack_size = ::std::isize::MAX as usize;
let stack_size = isize::MAX as usize;

let (start_count, start_handler) = count_handler();
let (exit_count, exit_handler) = count_handler();
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_thread_pool/src/worker_local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl<T> WorkerLocal<T> {
unsafe {
let worker_thread = WorkerThread::current();
if worker_thread.is_null()
|| &*(*worker_thread).registry as *const _ != &*self.registry as *const _
|| !std::ptr::eq(&*(*worker_thread).registry, &*self.registry)
{
panic!("WorkerLocal can only be used on the thread pool it was created on")
}
Expand All @@ -55,7 +55,7 @@ impl<T> WorkerLocal<T> {
impl<T> WorkerLocal<Vec<T>> {
/// Joins the elements of all the worker locals into one Vec
pub fn join(self) -> Vec<T> {
self.into_inner().into_iter().flat_map(|v| v).collect()
self.into_inner().into_iter().flatten().collect()
}
}

Expand Down
11 changes: 5 additions & 6 deletions compiler/rustc_type_ir_macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,11 @@ fn lift(mut ty: syn::Type) -> syn::Type {
struct ItoJ;
impl VisitMut for ItoJ {
fn visit_type_path_mut(&mut self, i: &mut syn::TypePath) {
if i.qself.is_none() {
if let Some(first) = i.path.segments.first_mut() {
if first.ident == "I" {
*first = parse_quote! { J };
}
}
if i.qself.is_none()
&& let Some(first) = i.path.segments.first_mut()
&& first.ident == "I"
{
*first = parse_quote! { J };
}
syn::visit_mut::visit_type_path_mut(self, i);
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_windows_rc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ fn write_resource_script_file(
.replace("@RUSTC_PRODUCTVERSION_QUAD@", &version.to_quad_string())
.replace("@RUSTC_PRODUCTVERSION_STR@", &descriptive_version);

fs::write(&rc_path, resource_script)
fs::write(rc_path, resource_script)
.unwrap_or_else(|_| panic!("failed to write resource file {}", rc_path.display()));
}

Expand Down
5 changes: 1 addition & 4 deletions library/proc_macro/src/bridge/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,7 @@ impl Symbol {

// Mimics the behavior of `Symbol::can_be_raw` from `rustc_span`
fn can_be_raw(string: &str) -> bool {
match string {
"_" | "super" | "self" | "Self" | "crate" | "$crate" => false,
_ => true,
}
!matches!(string, "_" | "super" | "self" | "Self" | "crate" | "$crate")
}
}

Expand Down
2 changes: 1 addition & 1 deletion library/proc_macro/src/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl MultiSpan for Vec<Span> {
}

#[unstable(feature = "proc_macro_diagnostic", issue = "54140")]
impl<'a> MultiSpan for &'a [Span] {
impl MultiSpan for &[Span] {
fn into_spans(self) -> Vec<Span> {
self.to_vec()
}
Expand Down
3 changes: 1 addition & 2 deletions library/proc_macro/src/escape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ pub(crate) fn escape_bytes(bytes: &[u8], opt: EscapeOptions) -> String {
escape_single_byte(byte, opt, &mut repr);
}
} else {
let mut chunks = bytes.utf8_chunks();
while let Some(chunk) = chunks.next() {
for chunk in bytes.utf8_chunks() {
for ch in chunk.valid().chars() {
escape_single_char(ch, opt, &mut repr);
}
Expand Down
2 changes: 1 addition & 1 deletion library/proc_macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ impl Span {
/// This path should not be embedded in the output of the macro; prefer `file()` instead.
#[stable(feature = "proc_macro_span_file", since = "1.88.0")]
pub fn local_file(&self) -> Option<PathBuf> {
self.0.local_file().map(|s| PathBuf::from(s))
self.0.local_file().map(PathBuf::from)
}

/// Creates a new span encompassing `self` and `other`.
Expand Down
10 changes: 5 additions & 5 deletions library/proc_macro/src/quote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,11 +378,11 @@ pub fn quote(stream: TokenStream) -> TokenStream {
"`$` must be followed by an ident or `$` or a repetition group in `quote!`"
),
}
} else if let TokenTree::Punct(ref tt) = tree {
if tt.as_char() == '$' {
after_dollar = true;
continue;
}
} else if let TokenTree::Punct(ref tt) = tree
&& tt.as_char() == '$'
{
after_dollar = true;
continue;
}

match tree {
Expand Down
2 changes: 1 addition & 1 deletion src/build_helper/src/npm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub fn install(src_root_path: &Path, out_dir: &Path, npm: &Path) -> Result<PathB
// disable a bunch of things we don't want.
// this makes tidy output less noisy, and also significantly improves runtime
// of repeated tidy invocations.
cmd.args(&["--audit=false", "--save=false", "--fund=false"]);
cmd.args(["--audit=false", "--save=false", "--fund=false"]);
cmd.current_dir(out_dir);
let exit_status = cmd.spawn()?.wait()?;
if !exit_status.success() {
Expand Down
7 changes: 2 additions & 5 deletions src/librustdoc/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,9 @@ fn main() {
let minified_path = std::path::PathBuf::from(format!("{out_dir}/{path}.min"));
if path.ends_with(".js") || path.ends_with(".css") {
let minified: String = if path.ends_with(".css") {
minifier::css::minify(str::from_utf8(&data_bytes).unwrap())
.unwrap()
.to_string()
.into()
minifier::css::minify(str::from_utf8(&data_bytes).unwrap()).unwrap().to_string()
} else {
minifier::js::minify(str::from_utf8(&data_bytes).unwrap()).to_string().into()
minifier::js::minify(str::from_utf8(&data_bytes).unwrap()).to_string()
};
std::fs::write(&minified_path, minified.as_bytes()).expect("write to out_dir");
} else {
Expand Down
8 changes: 4 additions & 4 deletions src/tools/build-manifest/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ impl Builder {
}

if let Some(path) = std::env::var_os("BUILD_MANIFEST_SHIPPED_FILES_PATH") {
self.write_shipped_files(&Path::new(&path));
self.write_shipped_files(Path::new(&path));
}

t!(self.checksums.store_cache());
Expand Down Expand Up @@ -435,7 +435,7 @@ impl Builder {
target: BTreeMap::new(),
};
for host in HOSTS {
if let Some(target) = self.target_host_combination(host, &manifest) {
if let Some(target) = self.target_host_combination(host, manifest) {
pkg.target.insert(host.to_string(), target);
} else {
pkg.target.insert(host.to_string(), Target::unavailable());
Expand Down Expand Up @@ -556,11 +556,11 @@ impl Builder {
}

let fallback = if pkg.use_docs_fallback() { DOCS_FALLBACK } else { &[] };
let version_info = self.versions.version(&pkg).expect("failed to load package version");
let version_info = self.versions.version(pkg).expect("failed to load package version");
let mut is_present = version_info.present;

// Never ship nightly-only components for other trains.
if self.versions.channel() != "nightly" && NIGHTLY_ONLY_COMPONENTS.contains(&pkg) {
if self.versions.channel() != "nightly" && NIGHTLY_ONLY_COMPONENTS.contains(pkg) {
is_present = false; // Pretend the component is entirely missing.
}

Expand Down
4 changes: 2 additions & 2 deletions src/tools/build-manifest/src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ pub(crate) struct Artifact {
impl Artifact {
pub(crate) fn add_file(&mut self, builder: &mut Builder, target: &str, path: &str) {
if let Some(path) = record_shipped_file(builder, builder.input.join(path)) {
self.target.entry(target.into()).or_insert_with(Vec::new).push(ArtifactFile {
self.target.entry(target.into()).or_default().push(ArtifactFile {
url: builder.url(&path),
hash_sha256: FileHash::Missing(path),
});
}
}

pub(crate) fn add_tarball(&mut self, builder: &mut Builder, target: &str, base_path: &str) {
let files = self.target.entry(target.into()).or_insert_with(Vec::new);
let files = self.target.entry(target.into()).or_default();
let base_path = builder.input.join(base_path);
for compression in &["gz", "xz"] {
if let Some(tarball) = tarball_variant(builder, &base_path, compression) {
Expand Down
Loading
Loading