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 7 pull requests #85163

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
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: 1 addition & 0 deletions compiler/rustc_middle/src/ty/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ macro_rules! define_callbacks {
}

pub trait QueryEngine<'tcx>: rustc_data_structures::sync::Sync {
#[cfg(parallel_compiler)]
unsafe fn deadlock(&'tcx self, tcx: TyCtxt<'tcx>, registry: &rustc_rayon_core::Registry);

fn encode_query_results(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use rustc_middle::mir::{Mutability, Place, PlaceRef, ProjectionElem};
use rustc_middle::ty::{self, Ty, TyCtxt};
use rustc_middle::{
hir::place::PlaceBase,
mir::{self, ClearCrossCrate, Local, LocalDecl, LocalInfo, Location},
mir::{self, ClearCrossCrate, Local, LocalDecl, LocalInfo, LocalKind, Location},
};
use rustc_span::source_map::DesugaringKind;
use rustc_span::symbol::{kw, Symbol};
Expand Down Expand Up @@ -424,15 +424,28 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {

match label {
Some((true, err_help_span, suggested_code)) => {
err.span_suggestion(
err_help_span,
&format!(
"consider changing this to be a mutable {}",
pointer_desc
),
suggested_code,
Applicability::MachineApplicable,
);
let (is_trait_sig, local_trait) = self.is_error_in_trait(local);
if !is_trait_sig {
err.span_suggestion(
err_help_span,
&format!(
"consider changing this to be a mutable {}",
pointer_desc
),
suggested_code,
Applicability::MachineApplicable,
);
} else if let Some(x) = local_trait {
err.span_suggestion(
x,
&format!(
"consider changing that to be a mutable {}",
pointer_desc
),
suggested_code,
Applicability::MachineApplicable,
);
}
}
Some((false, err_label_span, message)) => {
err.span_label(err_label_span, &message);
Expand Down Expand Up @@ -502,6 +515,69 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {

err.buffer(&mut self.errors_buffer);
}

/// User cannot make signature of a trait mutable without changing the
/// trait. So we find if this error belongs to a trait and if so we move
/// suggestion to the trait or disable it if it is out of scope of this crate
fn is_error_in_trait(&self, local: Local) -> (bool, Option<Span>) {
if self.body.local_kind(local) != LocalKind::Arg {
return (false, None);
}
let hir_map = self.infcx.tcx.hir();
let my_def = self.body.source.def_id();
let my_hir = hir_map.local_def_id_to_hir_id(my_def.as_local().unwrap());
let td = if let Some(a) = self.infcx.tcx.impl_of_method(my_def).and_then(|x| {
self.infcx.tcx.trait_id_of_impl(x)
}) {
a
} else {
return (false, None);
};
(true, td.as_local().and_then(|tld| {
let h = hir_map.local_def_id_to_hir_id(tld);
match hir_map.find(h) {
Some(Node::Item(hir::Item {
kind: hir::ItemKind::Trait(
_, _, _, _,
items
),
..
})) => {
let mut f_in_trait_opt = None;
for hir::TraitItemRef { id: fi, kind: k, .. } in *items {
let hi = fi.hir_id();
if !matches!(k, hir::AssocItemKind::Fn { .. }) {
continue;
}
if hir_map.name(hi) != hir_map.name(my_hir) {
continue;
}
f_in_trait_opt = Some(hi);
break;
}
f_in_trait_opt.and_then(|f_in_trait| {
match hir_map.find(f_in_trait) {
Some(Node::TraitItem(hir::TraitItem {
kind: hir::TraitItemKind::Fn(hir::FnSig {
decl: hir::FnDecl {
inputs,
..
},
..
}, _),
..
})) => {
let hir::Ty { span, .. } = inputs[local.index() - 1];
Some(span)
},
_ => None,
}
})
}
_ => None
}
}))
}

// point to span of upvar making closure call require mutable borrow
fn show_mutating_upvar(
Expand Down
10 changes: 4 additions & 6 deletions compiler/rustc_query_impl/src/plumbing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -550,12 +550,10 @@ macro_rules! define_queries_struct {
}

impl QueryEngine<'tcx> for Queries<'tcx> {
unsafe fn deadlock(&'tcx self, _tcx: TyCtxt<'tcx>, _registry: &rustc_rayon_core::Registry) {
#[cfg(parallel_compiler)]
{
let tcx = QueryCtxt { tcx: _tcx, queries: self };
rustc_query_system::query::deadlock(tcx, _registry)
}
#[cfg(parallel_compiler)]
unsafe fn deadlock(&'tcx self, tcx: TyCtxt<'tcx>, registry: &rustc_rayon_core::Registry) {
let tcx = QueryCtxt { tcx, queries: self };
rustc_query_system::query::deadlock(tcx, registry)
}

fn encode_query_results(
Expand Down
20 changes: 13 additions & 7 deletions compiler/rustc_query_system/src/query/plumbing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -605,13 +605,19 @@ fn incremental_verify_ich<CTX, K, V: Debug>(

let old_hash = tcx.dep_graph().prev_fingerprint_of(dep_node);

assert_eq!(
Some(new_hash),
old_hash,
"found unstable fingerprints for {:?}: {:?}",
dep_node,
result
);
if Some(new_hash) != old_hash {
let run_cmd = if let Some(crate_name) = &tcx.sess().opts.crate_name {
format!("`cargo clean -p {}` or `cargo clean`", crate_name)
} else {
"`cargo clean`".to_string()
};
tcx.sess().struct_err(&format!("internal compiler error: encountered incremental compilation error with {:?}", dep_node))
.help(&format!("This is a known issue with the compiler. Run {} to allow your project to compile", run_cmd))
.note(&format!("Please follow the instructions below to create a bug report with the provided information"))
.note(&format!("See <https://github.com/rust-lang/rust/issues/84970> for more information"))
.emit();
panic!("Found unstable fingerprints for {:?}: {:?}", dep_node, result);
}
}

fn force_query_with_job<C, CTX>(
Expand Down
Loading