Skip to content

Rollup of 9 pull requests #120534

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

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
7bdf705
Avoid ICE when is_val_statically_known is not of a supported type
Teapot4195 Jan 30, 2024
a97ff2a
Add additional test cases for is_val_statically_known
Teapot4195 Jan 30, 2024
8ebd47e
Mark "unused binding" suggestion as maybe incorrect
estebank Jan 29, 2024
15b4734
Remove unused `Constructor: PartialEq` impl
Nadrieril Jan 30, 2024
40402cb
Manual `Debug` impls are not needed since `TypeCx: Debug`
Nadrieril Jan 31, 2024
ee2cddd
It is correct to lower `!` to `_`.
Nadrieril Jan 31, 2024
7ea4dbb
Store SHOULD_CAPTURE as AtomicU8
GnomedDev Jan 31, 2024
8eb48b4
Update data layouts in custom target tests for LLVM 18
nikic Jan 31, 2024
8d31a53
Be less confident when `dyn` suggestion is not checked for object safety
trevyn Jan 20, 2024
f7531f1
Remove has_errors check that has no effect
oli-obk Jan 31, 2024
a6b1e43
Remove a has_errors check that only hides errors after unrelated item…
oli-obk Jan 31, 2024
28f250d
Remove a has_errors check that does not prevent follow up error noise
oli-obk Jan 31, 2024
d31905c
Remove a has_errors check that doesn't actually prevent noisy follow …
oli-obk Jan 31, 2024
647a453
Correct paths for hexagon-unknown-none-elf platform doc
androm3da Jan 31, 2024
6090c3c
Rollup merge of #120470 - estebank:issue-54196, r=compiler-errors
matthiaskrgr Jan 31, 2024
ea3f64a
Rollup merge of #120484 - Teapot4195:issue-120480-fix, r=compiler-errors
matthiaskrgr Jan 31, 2024
c4da12a
Rollup merge of #120516 - Nadrieril:cleanup-impls, r=compiler-errors
matthiaskrgr Jan 31, 2024
08c7f26
Rollup merge of #120517 - Nadrieril:lower-never-as-wildcard, r=compil…
matthiaskrgr Jan 31, 2024
ab0b57c
Rollup merge of #120528 - GnomedDev:atomicu8-backtrace-style, r=cuviper
matthiaskrgr Jan 31, 2024
f12c1c2
Rollup merge of #120529 - nikic:llvm-18-datalayout-fixes, r=cuviper
matthiaskrgr Jan 31, 2024
958d6f8
Rollup merge of #120530 - trevyn:issue-116434, r=compiler-errors
matthiaskrgr Jan 31, 2024
ae02de9
Rollup merge of #120531 - oli-obk:track_errors7, r=estebank
matthiaskrgr Jan 31, 2024
7d87d59
Rollup merge of #120533 - androm3da:bcain/update_hex_docs, r=wesleywiser
matthiaskrgr Jan 31, 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: 1 addition & 0 deletions compiler/rustc_codegen_llvm/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,7 @@ impl<'ll> CodegenCx<'ll, '_> {
ifn!("llvm.is.constant.isize", fn(t_isize) -> i1);
ifn!("llvm.is.constant.f32", fn(t_f32) -> i1);
ifn!("llvm.is.constant.f64", fn(t_f64) -> i1);
ifn!("llvm.is.constant.ptr", fn(ptr) -> i1);

ifn!("llvm.expect.i1", fn(i1, i1) -> i1);
ifn!("llvm.eh.typeid.for", fn(ptr) -> t_i32);
Expand Down
16 changes: 12 additions & 4 deletions compiler/rustc_codegen_llvm/src/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,18 @@ impl<'ll, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'_, 'll, 'tcx> {
sym::likely => {
self.call_intrinsic("llvm.expect.i1", &[args[0].immediate(), self.const_bool(true)])
}
sym::is_val_statically_known => self.call_intrinsic(
&format!("llvm.is.constant.{:?}", args[0].layout.immediate_llvm_type(self.cx)),
&[args[0].immediate()],
),
sym::is_val_statically_known => {
let intrinsic_type = args[0].layout.immediate_llvm_type(self.cx);
match self.type_kind(intrinsic_type) {
TypeKind::Pointer | TypeKind::Integer | TypeKind::Float | TypeKind::Double => {
self.call_intrinsic(
&format!("llvm.is.constant.{:?}", intrinsic_type),
&[args[0].immediate()],
)
}
_ => self.const_bool(false),
}
}
sym::unlikely => self
.call_intrinsic("llvm.expect.i1", &[args[0].immediate(), self.const_bool(false)]),
kw::Try => {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir_analysis/src/astconv/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,9 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
tcx.node_span_lint(BARE_TRAIT_OBJECTS, self_ty.hir_id, self_ty.span, msg, |lint| {
if self_ty.span.can_be_used_for_suggestions() {
lint.multipart_suggestion_verbose(
"use `dyn`",
"if this is an object-safe trait, use `dyn`",
sugg,
Applicability::MachineApplicable,
Applicability::MaybeIncorrect,
);
}
self.maybe_lint_blanket_trait_impl(self_ty, lint);
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_passes/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1739,7 +1739,7 @@ pub struct UnusedVariableTryPrefix {

#[derive(Subdiagnostic)]
pub enum UnusedVariableSugg {
#[multipart_suggestion(passes_suggestion, applicability = "machine-applicable")]
#[multipart_suggestion(passes_suggestion, applicability = "maybe-incorrect")]
TryPrefixSugg {
#[suggestion_part(code = "_{name}")]
spans: Vec<Span>,
Expand Down Expand Up @@ -1778,7 +1778,7 @@ pub struct UnusedVarTryIgnore {
}

#[derive(Subdiagnostic)]
#[multipart_suggestion(passes_suggestion, applicability = "machine-applicable")]
#[multipart_suggestion(passes_suggestion, applicability = "maybe-incorrect")]
pub struct UnusedVarTryIgnoreSugg {
#[suggestion_part(code = "{name}: _")]
pub shorthands: Vec<Span>,
Expand Down
70 changes: 1 addition & 69 deletions compiler/rustc_pattern_analysis/src/constructor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@
use std::cmp::{self, max, min, Ordering};
use std::fmt;
use std::iter::once;
use std::mem;

use smallvec::SmallVec;

Expand Down Expand Up @@ -648,6 +647,7 @@ impl OpaqueId {
/// `specialize_constructor` returns the list of fields corresponding to a pattern, given a
/// constructor. `Constructor::apply` reconstructs the pattern from a pair of `Constructor` and
/// `Fields`.
#[derive(Debug)]
pub enum Constructor<Cx: TypeCx> {
/// Tuples and structs.
Struct,
Expand Down Expand Up @@ -717,74 +717,6 @@ impl<Cx: TypeCx> Clone for Constructor<Cx> {
}
}

impl<Cx: TypeCx> fmt::Debug for Constructor<Cx> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Constructor::Struct => f.debug_tuple("Struct").finish(),
Constructor::Variant(idx) => f.debug_tuple("Variant").field(idx).finish(),
Constructor::Ref => f.debug_tuple("Ref").finish(),
Constructor::Slice(slice) => f.debug_tuple("Slice").field(slice).finish(),
Constructor::UnionField => f.debug_tuple("UnionField").finish(),
Constructor::Bool(b) => f.debug_tuple("Bool").field(b).finish(),
Constructor::IntRange(range) => f.debug_tuple("IntRange").field(range).finish(),
Constructor::F32Range(lo, hi, end) => {
f.debug_tuple("F32Range").field(lo).field(hi).field(end).finish()
}
Constructor::F64Range(lo, hi, end) => {
f.debug_tuple("F64Range").field(lo).field(hi).field(end).finish()
}
Constructor::Str(value) => f.debug_tuple("Str").field(value).finish(),
Constructor::Opaque(inner) => f.debug_tuple("Opaque").field(inner).finish(),
Constructor::Or => f.debug_tuple("Or").finish(),
Constructor::Wildcard => f.debug_tuple("Wildcard").finish(),
Constructor::NonExhaustive => f.debug_tuple("NonExhaustive").finish(),
Constructor::Hidden => f.debug_tuple("Hidden").finish(),
Constructor::Missing => f.debug_tuple("Missing").finish(),
}
}
}

impl<Cx: TypeCx> PartialEq for Constructor<Cx> {
fn eq(&self, other: &Self) -> bool {
(mem::discriminant(self) == mem::discriminant(other))
&& match (self, other) {
(Constructor::Struct, Constructor::Struct) => true,
(Constructor::Variant(self_variant), Constructor::Variant(other_variant)) => {
self_variant == other_variant
}
(Constructor::Ref, Constructor::Ref) => true,
(Constructor::Slice(self_slice), Constructor::Slice(other_slice)) => {
self_slice == other_slice
}
(Constructor::UnionField, Constructor::UnionField) => true,
(Constructor::Bool(self_b), Constructor::Bool(other_b)) => self_b == other_b,
(Constructor::IntRange(self_range), Constructor::IntRange(other_range)) => {
self_range == other_range
}
(
Constructor::F32Range(self_lo, self_hi, self_end),
Constructor::F32Range(other_lo, other_hi, other_end),
) => self_lo == other_lo && self_hi == other_hi && self_end == other_end,
(
Constructor::F64Range(self_lo, self_hi, self_end),
Constructor::F64Range(other_lo, other_hi, other_end),
) => self_lo == other_lo && self_hi == other_hi && self_end == other_end,
(Constructor::Str(self_value), Constructor::Str(other_value)) => {
self_value == other_value
}
(Constructor::Opaque(self_inner), Constructor::Opaque(other_inner)) => {
self_inner == other_inner
}
(Constructor::Or, Constructor::Or) => true,
(Constructor::Wildcard, Constructor::Wildcard) => true,
(Constructor::NonExhaustive, Constructor::NonExhaustive) => true,
(Constructor::Hidden, Constructor::Hidden) => true,
(Constructor::Missing, Constructor::Missing) => true,
_ => unreachable!(),
}
}
}

impl<Cx: TypeCx> Constructor<Cx> {
pub(crate) fn is_non_exhaustive(&self) -> bool {
matches!(self, NonExhaustive)
Expand Down
11 changes: 1 addition & 10 deletions compiler/rustc_pattern_analysis/src/pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ impl<'p, Cx: TypeCx> fmt::Debug for PatOrWild<'p, Cx> {

/// Same idea as `DeconstructedPat`, except this is a fictitious pattern built up for diagnostics
/// purposes. As such they don't use interning and can be cloned.
#[derive(Debug)]
pub struct WitnessPat<Cx: TypeCx> {
ctor: Constructor<Cx>,
pub(crate) fields: Vec<WitnessPat<Cx>>,
Expand All @@ -309,16 +310,6 @@ impl<Cx: TypeCx> Clone for WitnessPat<Cx> {
}
}

impl<Cx: TypeCx> fmt::Debug for WitnessPat<Cx> {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt.debug_struct("WitnessPat")
.field("ctor", &self.ctor)
.field("fields", &self.fields)
.field("ty", &self.ty)
.finish()
}
}

impl<Cx: TypeCx> WitnessPat<Cx> {
pub(crate) fn new(ctor: Constructor<Cx>, fields: Vec<Self>, ty: Cx::Ty) -> Self {
Self { ctor, fields, ty }
Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_pattern_analysis/src/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -675,8 +675,9 @@ impl<'p, 'tcx> RustcMatchCheckCtxt<'p, 'tcx> {
cx.pattern_arena.alloc_from_iter(pats.into_iter().map(|p| self.lower_pat(p)))
}
PatKind::Never => {
// FIXME(never_patterns): handle `!` in exhaustiveness. This is a sane default
// in the meantime.
// A never pattern matches all the values of its type (namely none). Moreover it
// must be compatible with other constructors, since we can use `!` on a type like
// `Result<!, !>` which has other constructors. Hence we lower it as a wildcard.
ctor = Wildcard;
fields = &[];
}
Expand Down
14 changes: 2 additions & 12 deletions compiler/rustc_pattern_analysis/src/usefulness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1207,6 +1207,7 @@ impl<'p, Cx: TypeCx> fmt::Debug for Matrix<'p, Cx> {
/// The final `Pair(Some(_), true)` is then the resulting witness.
///
/// See the top of the file for more detailed explanations and examples.
#[derive(Debug)]
struct WitnessStack<Cx: TypeCx>(Vec<WitnessPat<Cx>>);

impl<Cx: TypeCx> Clone for WitnessStack<Cx> {
Expand All @@ -1215,12 +1216,6 @@ impl<Cx: TypeCx> Clone for WitnessStack<Cx> {
}
}

impl<Cx: TypeCx> fmt::Debug for WitnessStack<Cx> {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt.debug_tuple("WitnessStack").field(&self.0).finish()
}
}

impl<Cx: TypeCx> WitnessStack<Cx> {
/// Asserts that the witness contains a single pattern, and returns it.
fn single_pattern(self) -> WitnessPat<Cx> {
Expand Down Expand Up @@ -1265,6 +1260,7 @@ impl<Cx: TypeCx> WitnessStack<Cx> {
///
/// Just as the `Matrix` starts with a single column, by the end of the algorithm, this has a single
/// column, which contains the patterns that are missing for the match to be exhaustive.
#[derive(Debug)]
struct WitnessMatrix<Cx: TypeCx>(Vec<WitnessStack<Cx>>);

impl<Cx: TypeCx> Clone for WitnessMatrix<Cx> {
Expand All @@ -1273,12 +1269,6 @@ impl<Cx: TypeCx> Clone for WitnessMatrix<Cx> {
}
}

impl<Cx: TypeCx> fmt::Debug for WitnessMatrix<Cx> {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt.debug_tuple("WitnessMatrix").field(&self.0).finish()
}
}

impl<Cx: TypeCx> WitnessMatrix<Cx> {
/// New matrix with no witnesses.
fn empty() -> Self {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -448,8 +448,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
// FIXME(effects)
let predicate_is_const = false;

if let Some(guar) = self.dcx().has_errors()
&& trait_predicate.references_error()
if let Err(guar) = trait_predicate.error_reported()
{
return guar;
}
Expand Down Expand Up @@ -2625,9 +2624,6 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
if let Some(e) = self.tainted_by_errors() {
return e;
}
if let Some(e) = self.dcx().has_errors() {
return e;
}

self.emit_inference_failure_err(
obligation.cause.body_id,
Expand All @@ -2645,10 +2641,6 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
if let Some(e) = self.tainted_by_errors() {
return e;
}
if let Some(e) = self.dcx().has_errors() {
// no need to overload user in such cases
return e;
}
let SubtypePredicate { a_is_expected: _, a, b } = data;
// both must be type variables, or the other would've been instantiated
assert!(a.is_ty_var() && b.is_ty_var());
Expand Down Expand Up @@ -2728,10 +2720,6 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
if let Some(e) = self.tainted_by_errors() {
return e;
}
if let Some(e) = self.dcx().has_errors() {
// no need to overload user in such cases
return e;
}
struct_span_code_err!(
self.dcx(),
span,
Expand Down
12 changes: 6 additions & 6 deletions library/std/src/panic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use crate::any::Any;
use crate::collections;
use crate::panicking;
use crate::sync::atomic::{AtomicUsize, Ordering};
use crate::sync::atomic::{AtomicU8, Ordering};
use crate::sync::{Mutex, RwLock};
use crate::thread::Result;

Expand Down Expand Up @@ -228,15 +228,15 @@ impl BacktraceStyle {
if cfg!(feature = "backtrace") { Some(BacktraceStyle::Full) } else { None }
}

fn as_usize(self) -> usize {
fn as_u8(self) -> u8 {
match self {
BacktraceStyle::Short => 1,
BacktraceStyle::Full => 2,
BacktraceStyle::Off => 3,
}
}

fn from_usize(s: usize) -> Option<Self> {
fn from_u8(s: u8) -> Option<Self> {
Some(match s {
0 => return None,
1 => BacktraceStyle::Short,
Expand All @@ -251,7 +251,7 @@ impl BacktraceStyle {
// that backtrace.
//
// Internally stores equivalent of an Option<BacktraceStyle>.
static SHOULD_CAPTURE: AtomicUsize = AtomicUsize::new(0);
static SHOULD_CAPTURE: AtomicU8 = AtomicU8::new(0);

/// Configure whether the default panic hook will capture and display a
/// backtrace.
Expand All @@ -264,7 +264,7 @@ pub fn set_backtrace_style(style: BacktraceStyle) {
// If the `backtrace` feature of this crate isn't enabled, skip setting.
return;
}
SHOULD_CAPTURE.store(style.as_usize(), Ordering::Release);
SHOULD_CAPTURE.store(style.as_u8(), Ordering::Release);
}

/// Checks whether the standard library's panic hook will capture and print a
Expand Down Expand Up @@ -296,7 +296,7 @@ pub fn get_backtrace_style() -> Option<BacktraceStyle> {
// to optimize away callers.
return None;
}
if let Some(style) = BacktraceStyle::from_usize(SHOULD_CAPTURE.load(Ordering::Acquire)) {
if let Some(style) = BacktraceStyle::from_u8(SHOULD_CAPTURE.load(Ordering::Acquire)) {
return Some(style);
}

Expand Down
17 changes: 9 additions & 8 deletions src/doc/rustc/src/platform-support/hexagon-unknown-none-elf.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ q6_arch=v65
g0_lib_path=${sdk_libs}/${q6_arch}/G0
pic_lib_path=${sdk_libs}/${q6_arch}/G0/pic

cargo build --target=hexagon-unknown-none-elf -Zbuild-std
build_cfg=release
cargo build --target=hexagon-unknown-none-elf -Zbuild-std --release

# Builds an executable against "hexagon standalone OS" suitable for emulation:
${cc} --target=hexagon-unknown-none-elf -o testit \
Expand All @@ -142,12 +143,12 @@ ${cc} --target=hexagon-unknown-none-elf -o testit \
-L${sdk_libs}/${q6_arch}/ \
-L${sdk_libs}/ \
testit.c \
target/hexagon-unknown-none-elf/debug/libmin_ex_lib_lin.rlib \
target/hexagon-unknown-none-elf/debug/deps/libcore-*.rlib \
target/hexagon-unknown-none-elf/debug/deps/libcompiler_builtins-*.rlib \
target/hexagon-unknown-none-elf/${build_cfg}/libdemo1_hexagon.rlib \
target/hexagon-unknown-none-elf/${build_cfg}/deps/libcore-*.rlib \
target/hexagon-unknown-none-elf/${build_cfg}/deps/libcompiler_builtins-*.rlib \
-Wl,--start-group \
-Wl,--defsym,_SDA_BASE_=0,--defsym,__sbss_start=0,--defsym,__sbss_end=0 \
-lstandalone \
${g0_lib_path}/libstandalone.a \
${g0_lib_path}/libc.a \
-lgcc \
-lc_eh \
Expand Down Expand Up @@ -248,9 +249,9 @@ ${cc} --target=hexagon-unknown-none-elf -o testit.so \
-Wl,--wrap=memalign \
-m${q6_arch} \
testit.c \
target/hexagon-unknown-none-elf/debug/libmin_ex_lib_lin.rlib \
target/hexagon-unknown-none-elf/debug/deps/libcore-*.rlib \
target/hexagon-unknown-none-elf/debug/deps/libcompiler_builtins-*.rlib \
target/hexagon-unknown-none-elf/${build_cfg}/libdemo2_hexagon.rlib \
target/hexagon-unknown-none-elf/${build_cfg}/deps/libcore-*.rlib \
target/hexagon-unknown-none-elf/${build_cfg}/deps/libcompiler_builtins-*.rlib \
-Wl,-soname=testit \
${pic_lib_path}/libc.so

Expand Down
Loading