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 9 pull requests #134293

Closed
wants to merge 28 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
8200c1e
rustdoc-search: fix mismatched path when parent re-exported twice
notriddle Dec 12, 2024
7880aba
crashes: more tests v2
matthiaskrgr Dec 12, 2024
65a54a7
Tweak multispan rendering
estebank Dec 11, 2024
49a22a4
Filter empty lines, comments and delimiters from previous to last mul…
estebank Dec 11, 2024
4c6d793
Only dist `llvm-objcopy` if llvm tools are enabled
cuviper Dec 13, 2024
65a609b
validate `--skip` and `--exclude` paths
onur-ozkan Dec 12, 2024
ead78fd
Remove jobserver from Session
bjorn3 Dec 12, 2024
981f625
Remove registered_lints field from Session
bjorn3 Dec 12, 2024
ea9e8c1
Explain why an untranslatable_diagnostic occurs
bjorn3 Dec 12, 2024
3198496
Make dependency_formats an FxIndexMap rather than a list of tuples
bjorn3 Dec 12, 2024
af530c4
Use a more precise span in placeholder_type_error_diag
krtab Dec 13, 2024
e17ca31
rustc_borrowck: Make suggest_ampmut() return type match its use
Enselic Dec 13, 2024
d7fa8ee
Add regression test for issue 127562
Enselic Dec 13, 2024
2d2c6f2
rustc_borrowck: Stop suggesting the invalid syntax `&mut raw const`
Enselic Dec 13, 2024
f6cb227
rustc_borrowck: Convert suggest_ampmut() 4-tuple to struct for readab…
Enselic Dec 13, 2024
98318c5
rustdoc-search: update test with now-shorter function path
notriddle Dec 13, 2024
ad82d9f
Fix miri tests
estebank Dec 12, 2024
9f1044e
Account for `///` when rendering multiline spans
estebank Dec 13, 2024
af3721e
Document the symbol Visibility enum
bjorn3 Dec 13, 2024
d2c3dd3
Rollup merge of #134181 - estebank:trim-render, r=oli-obk
matthiaskrgr Dec 14, 2024
9a66fb2
Rollup merge of #134209 - onur-ozkan:check-skip-paths, r=jieyouxu
matthiaskrgr Dec 14, 2024
f19a47a
Rollup merge of #134231 - notriddle:notriddle/mismatched-path, r=Guil…
matthiaskrgr Dec 14, 2024
b52dd88
Rollup merge of #134236 - matthiaskrgr:tests12122024, r=compiler-errors
matthiaskrgr Dec 14, 2024
1a8c4be
Rollup merge of #134240 - cuviper:dist-llvm-tools, r=jieyouxu
matthiaskrgr Dec 14, 2024
0d4f176
Rollup merge of #134244 - Enselic:no-mut-hint-for-raw-ref, r=jieyouxu
matthiaskrgr Dec 14, 2024
832018e
Rollup merge of #134251 - bjorn3:various_cleanups2, r=oli-obk
matthiaskrgr Dec 14, 2024
e3011bd
Rollup merge of #134256 - krtab:suggestion_overlapping, r=petrochenkov
matthiaskrgr Dec 14, 2024
bf8af73
Rollup merge of #134261 - bjorn3:document_symbol_visibility, r=lqd
matthiaskrgr Dec 14, 2024
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
1 change: 0 additions & 1 deletion Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3507,7 +3507,6 @@ dependencies = [
"cc",
"either",
"itertools",
"jobserver",
"libc",
"object 0.36.5",
"pathdiff",
Expand Down
69 changes: 53 additions & 16 deletions compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1100,12 +1100,12 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
}
let decl_span = local_decl.source_info.span;

let label = match *local_decl.local_info() {
let amp_mut_sugg = match *local_decl.local_info() {
LocalInfo::User(mir::BindingForm::ImplicitSelf(_)) => {
let suggestion = suggest_ampmut_self(self.infcx.tcx, decl_span);
let additional =
local_trait.map(|span| (span, suggest_ampmut_self(self.infcx.tcx, span)));
Some((true, decl_span, suggestion, additional))
Some(AmpMutSugg { has_sugg: true, span: decl_span, suggestion, additional })
}

LocalInfo::User(mir::BindingForm::Var(mir::VarBindingForm {
Expand Down Expand Up @@ -1150,7 +1150,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
None
}
None => {
let (has_sugg, decl_span, sugg) = if name != kw::SelfLower {
if name != kw::SelfLower {
suggest_ampmut(
self.infcx.tcx,
local_decl.ty,
Expand All @@ -1165,7 +1165,12 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
..
})) => {
let sugg = suggest_ampmut_self(self.infcx.tcx, decl_span);
(true, decl_span, sugg)
Some(AmpMutSugg {
has_sugg: true,
span: decl_span,
suggestion: sugg,
additional: None,
})
}
// explicit self (eg `self: &'a Self`)
_ => suggest_ampmut(
Expand All @@ -1176,8 +1181,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
opt_ty_info,
),
}
};
Some((has_sugg, decl_span, sugg, None))
}
}
}
}
Expand All @@ -1187,15 +1191,24 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
..
})) => {
let pattern_span: Span = local_decl.source_info.span;
suggest_ref_mut(self.infcx.tcx, pattern_span)
.map(|span| (true, span, "mut ".to_owned(), None))
suggest_ref_mut(self.infcx.tcx, pattern_span).map(|span| AmpMutSugg {
has_sugg: true,
span,
suggestion: "mut ".to_owned(),
additional: None,
})
}

_ => unreachable!(),
};

match label {
Some((true, err_help_span, suggested_code, additional)) => {
match amp_mut_sugg {
Some(AmpMutSugg {
has_sugg: true,
span: err_help_span,
suggestion: suggested_code,
additional,
}) => {
let mut sugg = vec![(err_help_span, suggested_code)];
if let Some(s) = additional {
sugg.push(s);
Expand All @@ -1217,7 +1230,9 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
);
}
}
Some((false, err_label_span, message, _)) => {
Some(AmpMutSugg {
has_sugg: false, span: err_label_span, suggestion: message, ..
}) => {
let def_id = self.body.source.def_id();
let hir_id = if let Some(local_def_id) = def_id.as_local()
&& let Some(body) = self.infcx.tcx.hir().maybe_body_owned_by(local_def_id)
Expand Down Expand Up @@ -1422,6 +1437,13 @@ fn suggest_ampmut_self<'tcx>(tcx: TyCtxt<'tcx>, span: Span) -> String {
}
}

struct AmpMutSugg {
has_sugg: bool,
span: Span,
suggestion: String,
additional: Option<(Span, String)>,
}

// When we want to suggest a user change a local variable to be a `&mut`, there
// are three potential "obvious" things to highlight:
//
Expand All @@ -1443,7 +1465,7 @@ fn suggest_ampmut<'tcx>(
decl_span: Span,
opt_assignment_rhs_span: Option<Span>,
opt_ty_info: Option<Span>,
) -> (bool, Span, String) {
) -> Option<AmpMutSugg> {
// if there is a RHS and it starts with a `&` from it, then check if it is
// mutable, and if not, put suggest putting `mut ` to make it mutable.
// we don't have to worry about lifetime annotations here because they are
Expand All @@ -1456,6 +1478,11 @@ fn suggest_ampmut<'tcx>(
&& let Ok(src) = tcx.sess.source_map().span_to_snippet(assignment_rhs_span)
&& let Some(stripped) = src.strip_prefix('&')
{
let is_raw_ref = stripped.trim_start().starts_with("raw ");
// We don't support raw refs yet
if is_raw_ref {
return None;
}
let is_mut = if let Some(rest) = stripped.trim_start().strip_prefix("mut") {
match rest.chars().next() {
// e.g. `&mut x`
Expand All @@ -1479,7 +1506,12 @@ fn suggest_ampmut<'tcx>(

// FIXME(Ezrashaw): returning is bad because we still might want to
// update the annotated type, see #106857.
return (true, span, "mut ".to_owned());
return Some(AmpMutSugg {
has_sugg: true,
span,
suggestion: "mut ".to_owned(),
additional: None,
});
}
}

Expand All @@ -1504,18 +1536,23 @@ fn suggest_ampmut<'tcx>(
&& let Some(ws_pos) = src.find(char::is_whitespace)
{
let span = span.with_lo(span.lo() + BytePos(ws_pos as u32)).shrink_to_lo();
(true, span, " mut".to_owned())
Some(AmpMutSugg { has_sugg: true, span, suggestion: " mut".to_owned(), additional: None })
// if there is already a binding, we modify it to be `mut`
} else if binding_exists {
// shrink the span to just after the `&` in `&variable`
let span = span.with_lo(span.lo() + BytePos(1)).shrink_to_lo();
(true, span, "mut ".to_owned())
Some(AmpMutSugg { has_sugg: true, span, suggestion: "mut ".to_owned(), additional: None })
} else {
// otherwise, suggest that the user annotates the binding; we provide the
// type of the local.
let ty = decl_ty.builtin_deref(true).unwrap();

(false, span, format!("{}mut {}", if decl_ty.is_ref() { "&" } else { "*" }, ty))
Some(AmpMutSugg {
has_sugg: false,
span,
suggestion: format!("{}mut {}", if decl_ty.is_ref() { "&" } else { "*" }, ty),
additional: None,
})
}
}

Expand Down
10 changes: 4 additions & 6 deletions compiler/rustc_codegen_cranelift/src/concurrency_limiter.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use std::sync::{Arc, Condvar, Mutex};

use jobserver::HelperThread;
use rustc_data_structures::jobserver::{self, HelperThread};
use rustc_errors::DiagCtxtHandle;
use rustc_session::Session;

// FIXME don't panic when a worker thread panics

Expand All @@ -14,14 +13,13 @@ pub(super) struct ConcurrencyLimiter {
}

impl ConcurrencyLimiter {
pub(super) fn new(sess: &Session, pending_jobs: usize) -> Self {
pub(super) fn new(pending_jobs: usize) -> Self {
let state = Arc::new(Mutex::new(state::ConcurrencyLimiterState::new(pending_jobs)));
let available_token_condvar = Arc::new(Condvar::new());

let state_helper = state.clone();
let available_token_condvar_helper = available_token_condvar.clone();
let helper_thread = sess
.jobserver
let helper_thread = jobserver::client()
.clone()
.into_helper_thread(move |token| {
let mut state = state_helper.lock().unwrap();
Expand Down Expand Up @@ -113,7 +111,7 @@ impl Drop for ConcurrencyLimiterToken {
}

mod state {
use jobserver::Acquired;
use rustc_data_structures::jobserver::Acquired;

#[derive(Debug)]
pub(super) struct ConcurrencyLimiterState {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_codegen_cranelift/src/driver/aot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ pub(crate) fn run_aot(
metadata_module: None,
metadata,
crate_info: CrateInfo::new(tcx, target_cpu),
concurrency_limiter: ConcurrencyLimiter::new(tcx.sess, 0),
concurrency_limiter: ConcurrencyLimiter::new(0),
});
};

Expand Down Expand Up @@ -711,7 +711,7 @@ pub(crate) fn run_aot(
CguReuse::PreLto | CguReuse::PostLto => false,
});

let concurrency_limiter = IntoDynSyncSend(ConcurrencyLimiter::new(tcx.sess, todo_cgus.len()));
let concurrency_limiter = IntoDynSyncSend(ConcurrencyLimiter::new(todo_cgus.len()));

let modules = tcx.sess.time("codegen mono items", || {
let mut modules: Vec<_> = par_map(todo_cgus, |(_, cgu)| {
Expand Down
7 changes: 1 addition & 6 deletions compiler/rustc_codegen_cranelift/src/driver/jit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,12 +287,7 @@ fn dep_symbol_lookup_fn(

let mut dylib_paths = Vec::new();

let data = &crate_info
.dependency_formats
.iter()
.find(|(crate_type, _data)| *crate_type == rustc_session::config::CrateType::Executable)
.unwrap()
.1;
let data = &crate_info.dependency_formats[&rustc_session::config::CrateType::Executable].1;
// `used_crates` is in reverse postorder in terms of dependencies. Reverse the order here to
// get a postorder which ensures that all dependencies of a dylib are loaded before the dylib
// itself. This helps the dynamic linker to find dylibs not in the regular dynamic library
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_codegen_cranelift/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#![warn(unused_lifetimes)]
// tidy-alphabetical-end

extern crate jobserver;
#[macro_use]
extern crate rustc_middle;
extern crate rustc_abi;
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_codegen_ssa/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ bitflags = "2.4.1"
cc = "1.1.23"
either = "1.5.0"
itertools = "0.12"
jobserver = "0.1.28"
pathdiff = "0.2.0"
regex = "1.4"
rustc_abi = { path = "../rustc_abi" }
Expand Down
34 changes: 13 additions & 21 deletions compiler/rustc_codegen_ssa/src/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,13 @@ pub fn each_linked_rlib(
) -> Result<(), errors::LinkRlibError> {
let crates = info.used_crates.iter();

let fmts = if crate_type.is_none() {
let fmts = if let Some(crate_type) = crate_type {
let Some(fmts) = info.dependency_formats.get(&crate_type) else {
return Err(errors::LinkRlibError::MissingFormat);
};

fmts
} else {
for combination in info.dependency_formats.iter().combinations(2) {
let (ty1, list1) = &combination[0];
let (ty2, list2) = &combination[1];
Expand All @@ -252,18 +258,7 @@ pub fn each_linked_rlib(
if info.dependency_formats.is_empty() {
return Err(errors::LinkRlibError::MissingFormat);
}
&info.dependency_formats[0].1
} else {
let fmts = info
.dependency_formats
.iter()
.find_map(|&(ty, ref list)| if Some(ty) == crate_type { Some(list) } else { None });

let Some(fmts) = fmts else {
return Err(errors::LinkRlibError::MissingFormat);
};

fmts
info.dependency_formats.first().unwrap().1
};

for &cnum in crates {
Expand Down Expand Up @@ -624,8 +619,7 @@ fn link_staticlib(
let fmts = codegen_results
.crate_info
.dependency_formats
.iter()
.find_map(|&(ty, ref list)| if ty == CrateType::Staticlib { Some(list) } else { None })
.get(&CrateType::Staticlib)
.expect("no dependency formats for staticlib");

let mut all_rust_dylibs = vec![];
Expand Down Expand Up @@ -2355,11 +2349,10 @@ fn linker_with_args(
// they are used within inlined functions or instantiated generic functions. We do this *after*
// handling the raw-dylib symbols in the current crate to make sure that those are chosen first
// by the linker.
let (_, dependency_linkage) = codegen_results
let dependency_linkage = codegen_results
.crate_info
.dependency_formats
.iter()
.find(|(ty, _)| *ty == crate_type)
.get(&crate_type)
.expect("failed to find crate type in dependency format list");

// We sort the libraries below
Expand Down Expand Up @@ -2738,11 +2731,10 @@ fn add_upstream_rust_crates(
// Linking to a rlib involves just passing it to the linker (the linker
// will slurp up the object files inside), and linking to a dynamic library
// involves just passing the right -l flag.
let (_, data) = codegen_results
let data = codegen_results
.crate_info
.dependency_formats
.iter()
.find(|(ty, _)| *ty == crate_type)
.get(&crate_type)
.expect("failed to find crate type in dependency format list");

if sess.target.is_like_aix {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_ssa/src/back/linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1749,7 +1749,7 @@ fn for_each_exported_symbols_include_dep<'tcx>(
}

let formats = tcx.dependency_formats(());
let deps = formats.iter().find_map(|(t, list)| (*t == crate_type).then_some(list)).unwrap();
let deps = &formats[&crate_type];

for (index, dep_format) in deps.iter().enumerate() {
let cnum = CrateNum::new(index + 1);
Expand Down
7 changes: 2 additions & 5 deletions compiler/rustc_codegen_ssa/src/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ use std::sync::Arc;
use std::sync::mpsc::{Receiver, Sender, channel};
use std::{fs, io, mem, str, thread};

use jobserver::{Acquired, Client};
use rustc_ast::attr;
use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
use rustc_data_structures::jobserver::{self, Acquired};
use rustc_data_structures::memmap::Mmap;
use rustc_data_structures::profiling::{SelfProfilerRef, VerboseTimingGuard};
use rustc_errors::emitter::Emitter;
Expand Down Expand Up @@ -456,7 +456,6 @@ pub(crate) fn start_async_codegen<B: ExtraBackendMethods>(
metadata_module: Option<CompiledModule>,
) -> OngoingCodegen<B> {
let (coordinator_send, coordinator_receive) = channel();
let sess = tcx.sess;

let crate_attrs = tcx.hir().attrs(rustc_hir::CRATE_HIR_ID);
let no_builtins = attr::contains_name(crate_attrs, sym::no_builtins);
Expand All @@ -477,7 +476,6 @@ pub(crate) fn start_async_codegen<B: ExtraBackendMethods>(
shared_emitter,
codegen_worker_send,
coordinator_receive,
sess.jobserver.clone(),
Arc::new(regular_config),
Arc::new(metadata_config),
Arc::new(allocator_config),
Expand Down Expand Up @@ -1093,7 +1091,6 @@ fn start_executing_work<B: ExtraBackendMethods>(
shared_emitter: SharedEmitter,
codegen_worker_send: Sender<CguMessage>,
coordinator_receive: Receiver<Box<dyn Any + Send>>,
jobserver: Client,
regular_config: Arc<ModuleConfig>,
metadata_config: Arc<ModuleConfig>,
allocator_config: Arc<ModuleConfig>,
Expand Down Expand Up @@ -1145,7 +1142,7 @@ fn start_executing_work<B: ExtraBackendMethods>(
// get tokens on `coordinator_receive` which will
// get managed in the main loop below.
let coordinator_send2 = coordinator_send.clone();
let helper = jobserver
let helper = jobserver::client()
.into_helper_thread(move |token| {
drop(coordinator_send2.send(Box::new(Message::Token::<B>(token))));
})
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_data_structures/src/jobserver.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::sync::{LazyLock, OnceLock};

pub use jobserver_crate::Client;
pub use jobserver_crate::{Acquired, Client, HelperThread};
use jobserver_crate::{FromEnv, FromEnvErrorKind};

// We can only call `from_env_ext` once per process
Expand Down
Loading
Loading