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 12 pull requests #98663

Closed
wants to merge 38 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
6ef2033
Fix FFI-unwind unsoundness with mixed panic mode
nbdd0121 May 18, 2022
77fd0cc
Handle panic runtime specially
nbdd0121 May 19, 2022
bc5afd9
Ensure ffi_unwind_calls lint is gated behind c_unwind
nbdd0121 May 19, 2022
1750a2f
Add tests for mixed panic mode restriction and lints
nbdd0121 May 20, 2022
9e6c044
Use is_fn_like instead of matching on DefKind
nbdd0121 May 23, 2022
14d155a
Rename `panic_strategy` query to `required_panic_strategy`
nbdd0121 Jun 8, 2022
ce774e3
Add a explanation about required panic strategy computation
nbdd0121 Jun 8, 2022
42eeb58
Implement support for DWARF version 5.
pcwalton Jun 20, 2022
8fb6c54
Fix cross compiling on macOS
topjohnwu Jun 21, 2022
b6e28b5
Allow dynamically linking against libLLVM on macOS
topjohnwu Jun 24, 2022
7180afb
Set CLANG_TABLEGEN when cross compiling clang
topjohnwu Jun 25, 2022
3b117c4
library: fix uefi va_list type definition
dlrobertson Jun 26, 2022
6e32a16
fix box with custom allocator in miri
beepster4096 Jun 26, 2022
d317988
validate box's allocator
beepster4096 Jun 27, 2022
1fca246
Ensure that `static_crt` is set in the bootstrapper whenever using `c…
dpaoliello Jun 23, 2022
af0c1fe
fix data race in thread::scope
RalfJung Jun 25, 2022
9f9c311
Validate all fields of box instead of validating allocator specifically
beepster4096 Jun 28, 2022
49e6b79
Fix test for non-prefer-dynamic target
nbdd0121 Jun 28, 2022
b292d94
Triagebot: Fix mentions word wrapping.
ehuss Jun 28, 2022
9039265
fix silly mistake
beepster4096 Jun 28, 2022
98af1bf
Migrate some rustc_borrowck diagnostics to SessionDiagnostic
compiler-errors Jun 23, 2022
cec6988
rustdoc: fix help menu popover toggling
notriddle Jun 28, 2022
cb8a738
rustdoc: fix keyboard shortcuts bug in settings menu
notriddle Jun 28, 2022
f5f42a8
rustdoc: make keyboard commands work when checkboxes are selected
notriddle Jun 28, 2022
ccea908
rustdoc: add assertion for missing popover div
notriddle Jun 29, 2022
1e40200
Erase regions in new abstract consts
JulianKnodt Jun 25, 2022
053eab7
Rollup merge of #97235 - nbdd0121:unwind, r=Amanieu
GuillaumeGomez Jun 29, 2022
9156e22
Rollup merge of #98328 - topjohnwu:fix_cross, r=jyn514
GuillaumeGomez Jun 29, 2022
60ff324
Rollup merge of #98350 - pcwalton:dwarf5, r=michaelwoerister
GuillaumeGomez Jun 29, 2022
c085775
Rollup merge of #98415 - compiler-errors:rustc-borrowck-session-diagn…
GuillaumeGomez Jun 29, 2022
744059c
Rollup merge of #98418 - topjohnwu:macos-dylib, r=jyn514
GuillaumeGomez Jun 29, 2022
b79e0a8
Rollup merge of #98434 - dpaoliello:staticcrt, r=jyn514
GuillaumeGomez Jun 29, 2022
c2aa7fd
Rollup merge of #98499 - JulianKnodt:erase_lifetime, r=lcnr
GuillaumeGomez Jun 29, 2022
590c1ab
Rollup merge of #98503 - RalfJung:scope-race, r=m-ou-se
GuillaumeGomez Jun 29, 2022
389616f
Rollup merge of #98516 - dlrobertson:uefi_va_list, r=joshtriplett
GuillaumeGomez Jun 29, 2022
a6c819c
Rollup merge of #98554 - DrMeepster:box_unsizing_is_not_special, r=Ra…
GuillaumeGomez Jun 29, 2022
29c2559
Rollup merge of #98636 - ehuss:mentions-wrapping, r=Mark-Simulacrum
GuillaumeGomez Jun 29, 2022
4161ea0
Rollup merge of #98646 - notriddle:notriddle/main.js, r=GuillaumeGomez
GuillaumeGomez Jun 29, 2022
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 @@ -3595,6 +3595,7 @@ dependencies = [
"rustc_index",
"rustc_infer",
"rustc_lexer",
"rustc_macros",
"rustc_middle",
"rustc_mir_dataflow",
"rustc_serialize",
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_borrowck/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ rustc_hir = { path = "../rustc_hir" }
rustc_index = { path = "../rustc_index" }
rustc_infer = { path = "../rustc_infer" }
rustc_lexer = { path = "../rustc_lexer" }
rustc_macros = { path = "../rustc_macros" }
rustc_middle = { path = "../rustc_middle" }
rustc_const_eval = { path = "../rustc_const_eval" }
rustc_mir_dataflow = { path = "../rustc_mir_dataflow" }
Expand Down
27 changes: 18 additions & 9 deletions compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ use std::fmt;
use std::rc::Rc;

use crate::region_infer::values::RegionElement;
use crate::session_diagnostics::HigherRankedErrorCause;
use crate::session_diagnostics::HigherRankedLifetimeError;
use crate::session_diagnostics::HigherRankedSubtypeError;
use crate::MirBorrowckCtxt;

#[derive(Clone)]
Expand Down Expand Up @@ -69,7 +72,7 @@ impl<'tcx> UniverseInfo<'tcx> {
// up in the existing UI tests. Consider investigating this
// some more.
mbcx.buffer_error(
mbcx.infcx.tcx.sess.struct_span_err(cause.span, "higher-ranked subtype error"),
mbcx.infcx.tcx.sess.create_err(HigherRankedSubtypeError { span: cause.span }),
);
}
}
Expand Down Expand Up @@ -216,9 +219,12 @@ impl<'tcx> TypeOpInfo<'tcx> for PredicateQuery<'tcx> {
tcx: TyCtxt<'tcx>,
span: Span,
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
let mut err = tcx.sess.struct_span_err(span, "higher-ranked lifetime error");
err.note(&format!("could not prove {}", self.canonical_query.value.value.predicate));
err
tcx.sess.create_err(HigherRankedLifetimeError {
cause: Some(HigherRankedErrorCause::CouldNotProve {
predicate: self.canonical_query.value.value.predicate.to_string(),
}),
span,
})
}

fn base_universe(&self) -> ty::UniverseIndex {
Expand Down Expand Up @@ -263,9 +269,12 @@ where
tcx: TyCtxt<'tcx>,
span: Span,
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
let mut err = tcx.sess.struct_span_err(span, "higher-ranked lifetime error");
err.note(&format!("could not normalize `{}`", self.canonical_query.value.value.value));
err
tcx.sess.create_err(HigherRankedLifetimeError {
cause: Some(HigherRankedErrorCause::CouldNotNormalize {
value: self.canonical_query.value.value.value.to_string(),
}),
span,
})
}

fn base_universe(&self) -> ty::UniverseIndex {
Expand Down Expand Up @@ -326,7 +335,7 @@ impl<'tcx> TypeOpInfo<'tcx> for AscribeUserTypeQuery<'tcx> {
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
// FIXME: This error message isn't great, but it doesn't show up in the existing UI tests,
// and is only the fallback when the nice error fails. Consider improving this some more.
tcx.sess.struct_span_err(span, "higher-ranked lifetime error")
tcx.sess.create_err(HigherRankedLifetimeError { cause: None, span })
}

fn base_universe(&self) -> ty::UniverseIndex {
Expand Down Expand Up @@ -366,7 +375,7 @@ impl<'tcx> TypeOpInfo<'tcx> for crate::type_check::InstantiateOpaqueType<'tcx> {
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
// FIXME: This error message isn't great, but it doesn't show up in the existing UI tests,
// and is only the fallback when the nice error fails. Consider improving this some more.
tcx.sess.struct_span_err(span, "higher-ranked lifetime error for opaque type!")
tcx.sess.create_err(HigherRankedLifetimeError { cause: None, span })
}

fn base_universe(&self) -> ty::UniverseIndex {
Expand Down
9 changes: 6 additions & 3 deletions compiler/rustc_borrowck/src/diagnostics/region_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use rustc_span::symbol::Ident;
use rustc_span::Span;

use crate::borrowck_errors;
use crate::session_diagnostics::GenericDoesNotLiveLongEnough;

use super::{OutlivesSuggestionBuilder, RegionName};
use crate::region_infer::BlameConstraint;
Expand Down Expand Up @@ -196,9 +197,11 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
// to report it; we could probably handle it by
// iterating over the universal regions and reporting
// an error that multiple bounds are required.
self.buffer_error(self.infcx.tcx.sess.struct_span_err(
type_test_span,
&format!("`{}` does not live long enough", type_test.generic_kind),
self.buffer_error(self.infcx.tcx.sess.create_err(
GenericDoesNotLiveLongEnough {
kind: type_test.generic_kind.to_string(),
span: type_test_span,
},
));
}
}
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_borrowck/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ mod places_conflict;
mod prefixes;
mod region_infer;
mod renumber;
mod session_diagnostics;
mod type_check;
mod universal_regions;
mod used_muts;
Expand Down
44 changes: 44 additions & 0 deletions compiler/rustc_borrowck/src/session_diagnostics.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
use rustc_macros::{SessionDiagnostic, SessionSubdiagnostic};
use rustc_middle::ty::Ty;
use rustc_span::Span;

#[derive(SessionDiagnostic)]
#[error(borrowck::move_unsized, code = "E0161")]
pub(crate) struct MoveUnsized<'tcx> {
pub ty: Ty<'tcx>,
#[primary_span]
#[label]
pub span: Span,
}

#[derive(SessionDiagnostic)]
#[error(borrowck::higher_ranked_lifetime_error)]
pub(crate) struct HigherRankedLifetimeError {
#[subdiagnostic]
pub cause: Option<HigherRankedErrorCause>,
#[primary_span]
pub span: Span,
}

#[derive(SessionSubdiagnostic)]
pub(crate) enum HigherRankedErrorCause {
#[note(borrowck::could_not_prove)]
CouldNotProve { predicate: String },
#[note(borrowck::could_not_normalize)]
CouldNotNormalize { value: String },
}

#[derive(SessionDiagnostic)]
#[error(borrowck::higher_ranked_subtype_error)]
pub(crate) struct HigherRankedSubtypeError {
#[primary_span]
pub span: Span,
}

#[derive(SessionDiagnostic)]
#[error(borrowck::generic_does_not_live_long_enough)]
pub(crate) struct GenericDoesNotLiveLongEnough {
pub kind: String,
#[primary_span]
pub span: Span,
}
13 changes: 2 additions & 11 deletions compiler/rustc_borrowck/src/type_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use hir::OpaqueTyOrigin;
use rustc_data_structures::frozen::Frozen;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::vec_map::VecMap;
use rustc_errors::struct_span_err;
use rustc_hir as hir;
use rustc_hir::def::DefKind;
use rustc_hir::def_id::LocalDefId;
Expand Down Expand Up @@ -48,6 +47,7 @@ use rustc_mir_dataflow::impls::MaybeInitializedPlaces;
use rustc_mir_dataflow::move_paths::MoveData;
use rustc_mir_dataflow::ResultsCursor;

use crate::session_diagnostics::MoveUnsized;
use crate::{
borrow_set::BorrowSet,
constraints::{OutlivesConstraint, OutlivesConstraintSet},
Expand Down Expand Up @@ -1780,19 +1780,10 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
// slot or local, so to find all unsized rvalues it is enough
// to check all temps, return slots and locals.
if self.reported_errors.replace((ty, span)).is_none() {
let mut diag = struct_span_err!(
self.tcx().sess,
span,
E0161,
"cannot move a value of type {0}: the size of {0} \
cannot be statically determined",
ty
);

// While this is located in `nll::typeck` this error is not
// an NLL error, it's a required check to prevent creation
// of unsized rvalues in a call expression.
diag.emit();
self.tcx().sess.emit_err(MoveUnsized { ty, span });
}
}
}
Expand Down
16 changes: 8 additions & 8 deletions compiler/rustc_codegen_llvm/src/debuginfo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,14 @@ impl<'ll, 'tcx> CodegenUnitDebugContext<'ll, 'tcx> {
// for macOS to understand. For more info see #11352
// This can be overridden using --llvm-opts -dwarf-version,N.
// Android has the same issue (#22398)
if let Some(version) = sess.target.dwarf_version {
llvm::LLVMRustAddModuleFlag(
self.llmod,
llvm::LLVMModFlagBehavior::Warning,
"Dwarf Version\0".as_ptr().cast(),
version,
)
}
let dwarf_version =
sess.opts.debugging_opts.dwarf_version.unwrap_or(sess.target.default_dwarf_version);
llvm::LLVMRustAddModuleFlag(
self.llmod,
llvm::LLVMModFlagBehavior::Warning,
"Dwarf Version\0".as_ptr().cast(),
dwarf_version,
);

// Indicate that we want CodeView debug information on MSVC
if sess.target.is_like_msvc {
Expand Down
16 changes: 0 additions & 16 deletions compiler/rustc_const_eval/src/interpret/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,22 +366,6 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
}
(&ty::Adt(def_a, _), &ty::Adt(def_b, _)) => {
assert_eq!(def_a, def_b);
if def_a.is_box() || def_b.is_box() {
if !def_a.is_box() || !def_b.is_box() {
span_bug!(
self.cur_span(),
"invalid unsizing between {:?} -> {:?}",
src.layout.ty,
cast_ty.ty
);
}
return self.unsize_into_ptr(
src,
dest,
src.layout.ty.boxed_ty(),
cast_ty.ty.boxed_ty(),
);
}

// unsizing of generic struct with pointer fields
// Example: `Arc<T>` -> `Arc<Trait>`
Expand Down
8 changes: 7 additions & 1 deletion compiler/rustc_const_eval/src/interpret/validity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,13 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
Ok(true)
}
ty::Adt(def, ..) if def.is_box() => {
self.check_safe_pointer(value, "box")?;
let unique = self.ecx.operand_field(value, 0)?;
let nonnull = self.ecx.operand_field(&unique, 0)?;
let ptr = self.ecx.operand_field(&nonnull, 0)?;
self.check_safe_pointer(&ptr, "box")?;

// Check other fields of Box
self.walk_value(value)?;
Ok(true)
}
ty::FnPtr(_sig) => {
Expand Down
18 changes: 18 additions & 0 deletions compiler/rustc_error_messages/locales/en-US/borrowck.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
borrowck-move-unsized =
cannot move a value of type `{$ty}`
.label = the size of `{$ty}` cannot be statically determined

borrowck-higher-ranked-lifetime-error =
higher-ranked lifetime error

borrowck-could-not-prove =
could not prove `{$predicate}`

borrowck-could-not-normalize =
could not normalize `{$value}`

borrowck-higher-ranked-subtype-error =
higher-ranked subtype error

generic-does-not-live-long-enough =
`{$kind}` does not live long enough
1 change: 1 addition & 0 deletions compiler/rustc_error_messages/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ fluent_messages! {
privacy => "../locales/en-US/privacy.ftl",
typeck => "../locales/en-US/typeck.ftl",
builtin_macros => "../locales/en-US/builtin_macros.ftl",
borrowck => "../locales/en-US/borrowck.ftl",
}

pub use fluent_generated::{self as fluent, DEFAULT_LOCALE_RESOURCES};
Expand Down
14 changes: 12 additions & 2 deletions compiler/rustc_errors/src/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,19 @@ pub trait Emitter {
let message = bundle.get_message(&identifier).expect("missing diagnostic in fluent bundle");
let value = match attr {
Some(attr) => {
message.get_attribute(attr).expect("missing attribute in fluent message").value()
if let Some(attr) = message.get_attribute(attr) {
attr.value()
} else {
panic!("missing attribute `{attr}` in fluent message `{identifier}`")
}
}
None => {
if let Some(value) = message.value() {
value
} else {
panic!("missing value in fluent message `{identifier}`")
}
}
None => message.value().expect("missing value in fluent message"),
};

let mut err = vec![];
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_interface/src/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -972,6 +972,7 @@ fn analysis(tcx: TyCtxt<'_>, (): ()) -> Result<()> {
if !tcx.sess.opts.debugging_opts.thir_unsafeck {
rustc_mir_transform::check_unsafety::check_unsafety(tcx, def_id);
}
tcx.ensure().has_ffi_unwind_calls(def_id);

if tcx.hir().body_const_context(def_id).is_some() {
tcx.ensure()
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_interface/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,7 @@ fn test_debugging_options_tracking_hash() {
tracked!(dep_info_omit_d_target, true);
tracked!(drop_tracking, true);
tracked!(dual_proc_macros, true);
tracked!(dwarf_version, Some(5));
tracked!(fewer_names, Some(true));
tracked!(force_unstable_if_unmarked, true);
tracked!(fuel, Some(("abc".to_string(), 99)));
Expand Down
40 changes: 40 additions & 0 deletions compiler/rustc_lint_defs/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3231,6 +3231,7 @@ declare_lint_pass! {
UNEXPECTED_CFGS,
DEPRECATED_WHERE_CLAUSE_LOCATION,
TEST_UNSTABLE_LINT,
FFI_UNWIND_CALLS,
]
}

Expand Down Expand Up @@ -3896,3 +3897,42 @@ declare_lint! {
"this unstable lint is only for testing",
@feature_gate = sym::test_unstable_lint;
}

declare_lint! {
/// The `ffi_unwind_calls` lint detects calls to foreign functions or function pointers with
/// `C-unwind` or other FFI-unwind ABIs.
///
/// ### Example
///
/// ```rust,ignore (need FFI)
/// #![feature(ffi_unwind_calls)]
/// #![feature(c_unwind)]
///
/// # mod impl {
/// # #[no_mangle]
/// # pub fn "C-unwind" fn foo() {}
/// # }
///
/// extern "C-unwind" {
/// fn foo();
/// }
///
/// fn bar() {
/// unsafe { foo(); }
/// let ptr: unsafe extern "C-unwind" fn() = foo;
/// unsafe { ptr(); }
/// }
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// For crates containing such calls, if they are compiled with `-C panic=unwind` then the
/// produced library cannot be linked with crates compiled with `-C panic=abort`. For crates
/// that desire this ability it is therefore necessary to avoid such calls.
pub FFI_UNWIND_CALLS,
Allow,
"call to foreign functions or function pointers with FFI-unwind ABI",
@feature_gate = sym::c_unwind;
}
2 changes: 1 addition & 1 deletion compiler/rustc_metadata/src/creader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ impl<'a> CrateLoader<'a> {
if !data.is_panic_runtime() {
self.sess.err(&format!("the crate `{}` is not a panic runtime", name));
}
if data.panic_strategy() != desired_strategy {
if data.required_panic_strategy() != Some(desired_strategy) {
self.sess.err(&format!(
"the crate `{}` does not have the panic \
strategy `{}`",
Expand Down
Loading