Skip to content

Instantly share code, notes, and snippets.

View jyn514's full-sized avatar

jyn jyn514

View GitHub Profile
@jyn514
jyn514 / borrow-checker-faqs.md
Created March 14, 2021 05:59
tips and tricks for dealing with the borrow-checker

(I plan to publish this as a blog post once a few people have looked at it and caught the obvious typos.)

I got lots of positive feedback about the FAQ section in my Rust 2020 blog post, so I'm trying that format again for another topic that's been requested a lot: How to fix common borrow-checker issues. This isn't meant to explain how or why the borrow checker works the way it does (see The Nomicon or Two Beautiful Rust Programs for that), just how to work around some of its current limitations.

rustc src/main.rs -Ztreat-err-as-bug=3
thread 'rustc' panicked at 'called `Result::unwrap()` on an `Err` value: failed while formatting fluent string `borrowck_returned_lifetime_short`:
the fluent string has an argument `category_desc` that was not found.
help: no arguments are available
the fluent string has an argument `free_region_name` that was not found.
help: no arguments are available
the fluent string has an argument `outlived_fr_name` that was not found.
help: no arguments are available
', compiler/rustc_errors/src/emitter.rs:2397:77
stack backtrace:
diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs
index 5bc4d164265..211d45e022e 100644
--- a/src/tools/compiletest/src/runtest.rs
+++ b/src/tools/compiletest/src/runtest.rs
@@ -1939,6 +1939,17 @@ fn make_compile_args(
// Use a single thread for efficiency and a deterministic error message order
rustc.arg("-Zthreads=1");
+ // Hide libstd sources from ui tests to make sure we generate the stderr
+ // output that users will see.
@jyn514
jyn514 / time-passes.txt
Last active May 24, 2023 22:34
MAGIC_EXTRA_RUSTFLAGS=-Ztime-passes x check rustc_middle
Checking stage0 compiler artifacts {rustc_middle} (x86_64-unknown-linux-gnu)
Checking rustc_middle v0.0.0 (/home/jyn/src/rust/compiler/rustc_middle)
time: 0.635; rss: 51MB -> 310MB ( +259MB) expand_crate
time: 0.635; rss: 51MB -> 310MB ( +259MB) macro_expand_crate
time: 0.018; rss: 310MB -> 310MB ( +0MB) AST_validation
time: 0.127; rss: 312MB -> 346MB ( +33MB) late_resolve_crate
time: 0.011; rss: 346MB -> 346MB ( +0MB) resolve_check_unused
time: 0.021; rss: 346MB -> 346MB ( +0MB) resolve_postprocess
time: 0.173; rss: 310MB -> 346MB ( +35MB) resolve_crate
time: 0.011; rss: 346MB -> 346MB ( +0MB) complete_gated_feature_checking
@jyn514
jyn514 / git redesign.md
Last active April 27, 2023 04:28
vague scribbles about how to make git easier to use

Git redesign

  • all repos start with a blank initial commit, no more "does not have any commits yet" errors

  • git commit foo should just work for new files, no more making people run git add first lol

  • no fucking perl scripts lmfao

    • better perf
    • git on windows is less horrifically cursed
#!/usr/bin/env python3
import re
import sys
def sizeof_fmt(num, suffix="B"):
for unit in ["", "Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "Zi"]:
if abs(num) < 1024.0:
return f"{num:3.1f}{unit}{suffix}"
num /= 1024.0
return f"{num:.1f}Yi{suffix}"
#!/usr/bin/env bash
set -x
error() {
echo "$@" >&2
}
usage() {
error "usage: $0 <src> <dest>"
@jyn514
jyn514 / setup.log
Created January 11, 2023 17:07
first time setup
PS C:\Users\Joshua Nelson\src\rust2> git worktree add ../rust5
Preparing worktree (new branch 'rust5')
Updating files: 100% (38772/38772), done.
HEAD is now at e4330295d9b Give a more helpful error for "trimmed_def_paths construted"
PS C:\Users\Joshua Nelson\src\rust2> cd ../rust5
PS C:\Users\Joshua Nelson\src\rust5> ./x.ps1 build --dry-run
downloading https://static.rust-lang.org/dist/2022-11-01/rust-std-beta-x86_64-pc-windows-msvc.tar.xz
#################################################################################################################### 100.0%
extracting C:\Users\Joshua Nelson\src\rust5\build\cache\2022-11-01\rust-std-beta-x86_64-pc-windows-msvc.tar.xz
downloading https://static.rust-lang.org/dist/2022-11-01/rustc-beta-x86_64-pc-windows-msvc.tar.xz
@jyn514
jyn514 / all_warnings.txt
Last active January 3, 2023 16:17
All warnings clippy emits on rust-lang/rust
This file has been truncated, but you can view the full file.
Building rustbuild
Finished dev [unoptimized] target(s) in 0.04s
Building stage0 library artifacts (aarch64-unknown-linux-gnu -> aarch64-unknown-linux-gnu)
Finished release [optimized] target(s) in 38.39s
Copying stage0 library from stage0 (aarch64-unknown-linux-gnu -> aarch64-unknown-linux-gnu / aarch64-unknown-linux-gnu)
Building stage0 compiler artifacts (aarch64-unknown-linux-gnu -> aarch64-unknown-linux-gnu)
Finished release [optimized] target(s) in 2m 46s
Copying stage0 rustc from stage0 (aarch64-unknown-linux-gnu -> aarch64-unknown-linux-gnu / aarch64-unknown-linux-gnu)
Assembling stage1 compiler (aarch64-unknown-linux-gnu)
Building stage0 tool clippy-driver (aarch64-unknown-linux-gnu)
This file has been truncated, but you can view the full file.
[
{"name":"std::thread::LocalKey::<T>::try_with","instantiation_count":3214,"size_estimate":58,"total_estimate":186412},
{"name":"hashbrown::raw::RawTable::<T, A>::reserve_rehash","instantiation_count":277,"size_estimate":402,"total_estimate":111354},
{"name":"rustc_query_system::query::plumbing::try_load_from_disk_and_cache_in_memory","instantiation_count":228,"size_estimate":449,"total_estimate":102372},
{"name":"rustc_query_system::dep_graph::DepGraph::<K>::with_task_impl","instantiation_count":228,"size_estimate":391,"total_estimate":89148},
{"name":"rustc_query_system::query::plumbing::execute_job","instantiation_count":228,"size_estimate":376,"total_estimate":85728},
{"name":"rustc_middle::ty::tls::with_context_opt","instantiation_count":1599,"size_estimate":53,"total_estimate":84747},
{"name":"plumbing::force_from_dep_node","instantiation_count":285,"size_estimate":296,"total_estimate":84360},
{"name":"std::ptr::const_ptr::<impl *const T>::is_aligned_to","instantiation_count":1722,"size_estimate":46,"t