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 #106822

Merged
merged 26 commits into from
Jan 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
2538c0c
fix `SyncSender` spinning behavior
ibraheemdev Jan 11, 2023
f8276c9
add `SyncSender::send_timeout` test
ibraheemdev Jan 11, 2023
4e2a356
Add log-backtrace option to show backtraces along with logging
yukiomoto Jan 11, 2023
12ddf77
When suggesting writing a fully qualified path probe for appropriate …
estebank Jan 8, 2023
147c9bf
review comments
estebank Jan 8, 2023
c6f322b
review comments: account for generics
estebank Jan 8, 2023
8917e99
rework and document backoff behavior of `sync::mpsc`
ibraheemdev Jan 12, 2023
c825459
Provide help on closures capturing self causing borrow checker errors
chenyukang Jan 7, 2023
eafbca9
take care when there is no args in method call
chenyukang Jan 7, 2023
5457140
Bump IMPLIED_BOUNDS_ENTAILMENT to Deny + ReportNow
compiler-errors Jan 4, 2023
eaa7cc8
Add logic to make IMPLIED_BOUNDS_ENTAILMENT easier to understand
compiler-errors Jan 12, 2023
95ef76b
Normalize test output more thoroughly
Mark-Simulacrum Jan 13, 2023
138a1d2
riscv: Fix ELF header flags
FawazTirmizi Jan 9, 2023
549ece7
Warn when using panic-strategy abort for proc-macro crates
Veykril Jan 10, 2023
4aca7be
Remove redundant session field
oli-obk Dec 8, 2022
3bc2970
Improve linker-flavor detection
jschwe Jan 5, 2023
96bb02f
Rollup merge of #104645 - yukiomoto:log-backtrace-option, r=oli-obk
matthiaskrgr Jan 13, 2023
1dc43b2
Rollup merge of #106465 - compiler-errors:bump-IMPLIED_BOUNDS_ENTAILM…
matthiaskrgr Jan 13, 2023
f9dde54
Rollup merge of #106489 - jschwe:fix_linker_detection, r=petrochenkov
matthiaskrgr Jan 13, 2023
c6e3a47
Rollup merge of #106585 - estebank:issue-46585, r=compiler-errors
matthiaskrgr Jan 13, 2023
57b371a
Rollup merge of #106641 - chenyukang:yukang/fix-105761-segguest-this,…
matthiaskrgr Jan 13, 2023
e4d0104
Rollup merge of #106678 - Veykril:proc-macro-panic-abort, r=eholk
matthiaskrgr Jan 13, 2023
720137b
Rollup merge of #106701 - ibraheemdev:sync-sender-spin, r=Amanieu
matthiaskrgr Jan 13, 2023
e0f6840
Rollup merge of #106793 - Mark-Simulacrum:normalize-test, r=compiler-…
matthiaskrgr Jan 13, 2023
278e02a
Rollup merge of #106797 - FawazTirmizi:dev/issues/104284, r=bjorn3
matthiaskrgr Jan 13, 2023
f709382
Rollup merge of #106813 - oli-obk:sess_cleanup, r=GuillaumeGomez,petr…
matthiaskrgr Jan 13, 2023
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 Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4273,6 +4273,7 @@ version = "0.0.0"
dependencies = [
"rustc_span",
"tracing",
"tracing-core",
"tracing-subscriber",
"tracing-tree",
]
Expand Down
148 changes: 144 additions & 4 deletions compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use rustc_errors::{
struct_span_err, Applicability, Diagnostic, DiagnosticBuilder, ErrorGuaranteed, MultiSpan,
};
use rustc_hir as hir;
use rustc_hir::def::Res;
use rustc_hir::intravisit::{walk_block, walk_expr, Visitor};
use rustc_hir::{AsyncGeneratorKind, GeneratorKind, LangItem};
use rustc_infer::infer::TyCtxtInferExt;
Expand All @@ -20,7 +21,7 @@ use rustc_middle::ty::{self, suggest_constraining_type_params, PredicateKind, Ty
use rustc_mir_dataflow::move_paths::{InitKind, MoveOutIndex, MovePathIndex};
use rustc_span::def_id::LocalDefId;
use rustc_span::hygiene::DesugaringKind;
use rustc_span::symbol::sym;
use rustc_span::symbol::{kw, sym};
use rustc_span::{BytePos, Span, Symbol};
use rustc_trait_selection::infer::InferCtxtExt;

Expand All @@ -29,6 +30,7 @@ use crate::borrowck_errors;

use crate::diagnostics::conflict_errors::StorageDeadOrDrop::LocalStorageDead;
use crate::diagnostics::find_all_local_uses;
use crate::diagnostics::mutability_errors::mut_borrow_of_mutable_ref;
use crate::{
borrow_set::BorrowData, diagnostics::Instance, prefixes::IsPrefixOf,
InitializationRequiringAction, MirBorrowckCtxt, PrefixSet, WriteKind,
Expand Down Expand Up @@ -356,7 +358,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
if let Some(hir::Node::Item(hir::Item {
kind: hir::ItemKind::Fn(_, _, body_id),
..
})) = hir.find(hir.local_def_id_to_hir_id(self.mir_def_id()))
})) = hir.find(self.mir_hir_id())
&& let Some(hir::Node::Expr(expr)) = hir.find(body_id.hir_id)
{
let place = &self.move_data.move_paths[mpi].place;
Expand Down Expand Up @@ -948,7 +950,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
}
(BorrowKind::Mut { .. }, BorrowKind::Shared) => {
first_borrow_desc = "immutable ";
self.cannot_reborrow_already_borrowed(
let mut err = self.cannot_reborrow_already_borrowed(
span,
&desc_place,
&msg_place,
Expand All @@ -958,7 +960,13 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
"immutable",
&msg_borrow,
None,
)
);
self.suggest_binding_for_closure_capture_self(
&mut err,
issued_borrow.borrowed_place,
&issued_spans,
);
err
}

(BorrowKind::Mut { .. }, BorrowKind::Mut { .. }) => {
Expand Down Expand Up @@ -1240,6 +1248,138 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
}
}

fn suggest_binding_for_closure_capture_self(
&self,
err: &mut Diagnostic,
borrowed_place: Place<'tcx>,
issued_spans: &UseSpans<'tcx>,
) {
let UseSpans::ClosureUse { capture_kind_span, .. } = issued_spans else { return };
let hir = self.infcx.tcx.hir();

// check whether the borrowed place is capturing `self` by mut reference
let local = borrowed_place.local;
let Some(_) = self
.body
.local_decls
.get(local)
.map(|l| mut_borrow_of_mutable_ref(l, self.local_names[local])) else { return };

struct ExpressionFinder<'hir> {
capture_span: Span,
closure_change_spans: Vec<Span>,
closure_arg_span: Option<Span>,
in_closure: bool,
suggest_arg: String,
hir: rustc_middle::hir::map::Map<'hir>,
closure_local_id: Option<hir::HirId>,
closure_call_changes: Vec<(Span, String)>,
}
impl<'hir> Visitor<'hir> for ExpressionFinder<'hir> {
fn visit_expr(&mut self, e: &'hir hir::Expr<'hir>) {
if e.span.contains(self.capture_span) {
if let hir::ExprKind::Closure(&hir::Closure {
movability: None,
body,
fn_arg_span,
fn_decl: hir::FnDecl{ inputs, .. },
..
}) = e.kind &&
let Some(hir::Node::Expr(body )) = self.hir.find(body.hir_id) {
self.suggest_arg = "this: &Self".to_string();
if inputs.len() > 0 {
self.suggest_arg.push_str(", ");
}
self.in_closure = true;
self.closure_arg_span = fn_arg_span;
self.visit_expr(body);
self.in_closure = false;
}
}
if let hir::Expr { kind: hir::ExprKind::Path(path), .. } = e {
if let hir::QPath::Resolved(_, hir::Path { segments: [seg], ..}) = path &&
seg.ident.name == kw::SelfLower && self.in_closure {
self.closure_change_spans.push(e.span);
}
}
hir::intravisit::walk_expr(self, e);
}

fn visit_local(&mut self, local: &'hir hir::Local<'hir>) {
if let hir::Pat { kind: hir::PatKind::Binding(_, hir_id, _ident, _), .. } = local.pat &&
let Some(init) = local.init
{
if let hir::Expr { kind: hir::ExprKind::Closure(&hir::Closure {
movability: None,
..
}), .. } = init &&
init.span.contains(self.capture_span) {
self.closure_local_id = Some(*hir_id);
}
}
hir::intravisit::walk_local(self, local);
}

fn visit_stmt(&mut self, s: &'hir hir::Stmt<'hir>) {
if let hir::StmtKind::Semi(e) = s.kind &&
let hir::ExprKind::Call(hir::Expr { kind: hir::ExprKind::Path(path), ..}, args) = e.kind &&
let hir::QPath::Resolved(_, hir::Path { segments: [seg], ..}) = path &&
let Res::Local(hir_id) = seg.res &&
Some(hir_id) == self.closure_local_id {
let (span, arg_str) = if args.len() > 0 {
(args[0].span.shrink_to_lo(), "self, ".to_string())
} else {
let span = e.span.trim_start(seg.ident.span).unwrap_or(e.span);
(span, "(self)".to_string())
};
self.closure_call_changes.push((span, arg_str));
}
hir::intravisit::walk_stmt(self, s);
}
}

if let Some(hir::Node::ImplItem(
hir::ImplItem { kind: hir::ImplItemKind::Fn(_fn_sig, body_id), .. }
)) = hir.find(self.mir_hir_id()) &&
let Some(hir::Node::Expr(expr)) = hir.find(body_id.hir_id) {
let mut finder = ExpressionFinder {
capture_span: *capture_kind_span,
closure_change_spans: vec![],
closure_arg_span: None,
in_closure: false,
suggest_arg: String::new(),
closure_local_id: None,
closure_call_changes: vec![],
hir,
};
finder.visit_expr(expr);

if finder.closure_change_spans.is_empty() || finder.closure_call_changes.is_empty() {
return;
}

let mut sugg = vec![];
let sm = self.infcx.tcx.sess.source_map();

if let Some(span) = finder.closure_arg_span {
sugg.push((sm.next_point(span.shrink_to_lo()).shrink_to_hi(), finder.suggest_arg));
}
for span in finder.closure_change_spans {
sugg.push((span, "this".to_string()));
}

for (span, suggest) in finder.closure_call_changes {
sugg.push((span, suggest));
}

err.multipart_suggestion_verbose(
"try explicitly pass `&Self` into the Closure as an argument",
sugg,
Applicability::MachineApplicable,
);
}
}

/// Returns the description of the root place for a conflicting borrow and the full
/// descriptions of the places that caused the conflict.
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1094,7 +1094,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
}
}

fn mut_borrow_of_mutable_ref(local_decl: &LocalDecl<'_>, local_name: Option<Symbol>) -> bool {
pub fn mut_borrow_of_mutable_ref(local_decl: &LocalDecl<'_>, local_name: Option<Symbol>) -> bool {
debug!("local_info: {:?}, ty.kind(): {:?}", local_decl.local_info, local_decl.ty.kind());

match local_decl.local_info.as_deref() {
Expand Down
11 changes: 10 additions & 1 deletion compiler/rustc_codegen_ssa/src/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1231,12 +1231,21 @@ pub fn linker_and_flavor(sess: &Session) -> (PathBuf, LinkerFlavor) {
sess.emit_fatal(errors::LinkerFileStem);
});

// Remove any version postfix.
let stem = stem
.rsplit_once('-')
.and_then(|(lhs, rhs)| rhs.chars().all(char::is_numeric).then_some(lhs))
.unwrap_or(stem);

// GCC can have an optional target prefix.
let flavor = if stem == "emcc" {
LinkerFlavor::EmCc
} else if stem == "gcc"
|| stem.ends_with("-gcc")
|| stem == "g++"
|| stem.ends_with("-g++")
|| stem == "clang"
|| stem.ends_with("-clang")
|| stem == "clang++"
{
LinkerFlavor::from_cli(LinkerFlavorCli::Gcc, &sess.target)
} else if stem == "wasm-ld" || stem.ends_with("-wasm-ld") {
Expand Down
22 changes: 17 additions & 5 deletions compiler/rustc_codegen_ssa/src/back/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,23 @@ pub(crate) fn create_object_file(sess: &Session) -> Option<write::Object<'static
};
e_flags
}
Architecture::Riscv64 if sess.target.options.features.contains("+d") => {
// copied from `riscv64-linux-gnu-gcc foo.c -c`, note though
// that the `+d` target feature represents whether the double
// float abi is enabled.
let e_flags = elf::EF_RISCV_RVC | elf::EF_RISCV_FLOAT_ABI_DOUBLE;
Architecture::Riscv32 | Architecture::Riscv64 => {
// Source: https://github.com/riscv-non-isa/riscv-elf-psabi-doc/blob/079772828bd10933d34121117a222b4cc0ee2200/riscv-elf.adoc
let mut e_flags: u32 = 0x0;
let features = &sess.target.options.features;
// Check if compressed is enabled
if features.contains("+c") {
e_flags |= elf::EF_RISCV_RVC;
}

// Select the appropriate floating-point ABI
if features.contains("+d") {
e_flags |= elf::EF_RISCV_FLOAT_ABI_DOUBLE;
} else if features.contains("+f") {
e_flags |= elf::EF_RISCV_FLOAT_ABI_SINGLE;
} else {
e_flags |= elf::EF_RISCV_FLOAT_ABI_SOFT;
}
e_flags
}
_ => 0,
Expand Down
14 changes: 12 additions & 2 deletions compiler/rustc_driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,10 @@ fn run_compiler(
registry: diagnostics_registry(),
};

if !tracing::dispatcher::has_been_set() {
init_rustc_env_logger_with_backtrace_option(&config.opts.unstable_opts.log_backtrace);
}

match make_input(config.opts.error_format, &matches.free) {
Err(reported) => return Err(reported),
Ok(Some((input, input_file_path))) => {
Expand Down Expand Up @@ -1300,7 +1304,14 @@ pub fn install_ice_hook() {
/// This allows tools to enable rust logging without having to magically match rustc's
/// tracing crate version.
pub fn init_rustc_env_logger() {
if let Err(error) = rustc_log::init_rustc_env_logger() {
init_rustc_env_logger_with_backtrace_option(&None);
}

/// This allows tools to enable rust logging without having to magically match rustc's
/// tracing crate version. In contrast to `init_rustc_env_logger` it allows you to
/// choose a target module you wish to show backtraces along with its logging.
pub fn init_rustc_env_logger_with_backtrace_option(backtrace_target: &Option<String>) {
if let Err(error) = rustc_log::init_rustc_env_logger_with_backtrace_option(backtrace_target) {
early_error(ErrorOutputType::default(), &error.to_string());
}
}
Expand Down Expand Up @@ -1366,7 +1377,6 @@ mod signal_handler {
pub fn main() -> ! {
let start_time = Instant::now();
let start_rss = get_resident_set_size();
init_rustc_env_logger();
signal_handler::install();
let mut callbacks = TimePassesCallbacks::default();
install_ice_hook();
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_error_messages/locales/en-US/interface.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,6 @@ interface_rustc_error_unexpected_annotation =

interface_failed_writing_file =
failed to write file {$path}: {$error}"

interface_proc_macro_crate_panic_abort =
building proc macro crate with `panic=abort` may crash the compiler should the proc-macro panic
Loading