Skip to content
Open
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
9549166
add test
lcnr Dec 1, 2025
02d84c8
generic normalization errors to `TooGeneric`
lcnr Dec 1, 2025
7de190a
`io::Error::downcast`: avoid reallocation in case of failure
a1phyr Dec 1, 2025
46f4b5d
add a tidy test
WaffleLapkin Dec 1, 2025
3a0f23b
refactor tidy alphabetical lint
WaffleLapkin Aug 16, 2025
4fef9bd
implement tidy bless for alphabetical blocks
WaffleLapkin Aug 16, 2025
a93d661
bless tidy tests
WaffleLapkin Aug 16, 2025
3e811b3
drive-by: tidy: fixup style
WaffleLapkin Dec 1, 2025
dcc785d
bless tidy
WaffleLapkin Aug 18, 2025
7922479
Regression tests for system register `ttbr0_el2`
Jamesbarford Dec 2, 2025
62f7cf4
move `expr_guaranteed_to_constitute_read_for_never` and `pat_guarante…
WaffleLapkin Dec 2, 2025
784b283
add a test for nested type ascriptions of never type
WaffleLapkin Dec 2, 2025
c5f15bd
fix the check for which expressions read never type
WaffleLapkin Dec 2, 2025
ef27140
Move `tests/ui/{unreachable-code => reachable}`
WaffleLapkin Dec 2, 2025
537a8d7
Motor OS: fix compile error
lasiotus Dec 3, 2025
bf0970f
add one more test for type ascription of never
WaffleLapkin Dec 2, 2025
5e802dd
moved and deleted test
reddevilmidzy Dec 3, 2025
07b1dad
Added comment to
reddevilmidzy Dec 3, 2025
245096b
Added comment to
reddevilmidzy Dec 3, 2025
cc230fb
Added comment to `tests\ui\str\debug-print-basic-tuple.rs`
reddevilmidzy Dec 3, 2025
d1bc6e3
Merged `tests\ui\type-inference\type-inference-unconstrained-none.rs`
reddevilmidzy Dec 3, 2025
8b6431d
add tests for tidy alphabetical blessing
WaffleLapkin Dec 3, 2025
e4f02e4
fix guard patterns interaction with never type
WaffleLapkin Dec 3, 2025
eb03ea4
Revert "implement and test `Iterator::{exactly_one, collect_array}`"
jdonszelmann Dec 3, 2025
c340732
Revert "fixup warnings around the compiler"
jdonszelmann Dec 3, 2025
1864bf6
ICE when applying test to crate root
jdonszelmann Oct 18, 2025
9dd3cae
only discard items with `#[test]` on it when target is valid
jdonszelmann Oct 18, 2025
97d4d21
fixup name in diagnostics
jdonszelmann Oct 18, 2025
8f82478
address review comments
jdonszelmann Dec 3, 2025
3f4a7b4
Rollup merge of #147841 - jdonszelmann:test-macro-ice, r=wafflelapkin
matthiaskrgr Dec 3, 2025
c3eb9dc
Rollup merge of #149501 - lcnr:no-hard-error-on-norm-failure, r=lqd,o…
matthiaskrgr Dec 3, 2025
c0060ee
Rollup merge of #149517 - WaffleLapkin:alphabet-blessing, r=jdonszelmann
matthiaskrgr Dec 3, 2025
8afa628
Rollup merge of #149521 - a1phyr:improve_io_error, r=joboet
matthiaskrgr Dec 3, 2025
1e494d8
Rollup merge of #149545 - WaffleLapkin:type_ascribe2, r=jackh726
matthiaskrgr Dec 3, 2025
432c466
Rollup merge of #149549 - Jamesbarford:chore/regression-test-ttbr0_el…
matthiaskrgr Dec 3, 2025
220e887
Rollup merge of #149579 - moturus:fix-thread-new, r=joboet
matthiaskrgr Dec 3, 2025
d2403c6
Rollup merge of #149595 - reddevilmidzy:t9, r=Kivooeo
matthiaskrgr Dec 3, 2025
cd923ac
Rollup merge of #149597 - jdonszelmann:revert-iterator-exactly-one, r…
matthiaskrgr Dec 3, 2025
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 @@ -5615,6 +5615,7 @@ dependencies = [
"semver",
"serde",
"similar",
"tempfile",
"termcolor",
"toml 0.7.8",
"walkdir",
Expand Down
39 changes: 22 additions & 17 deletions compiler/rustc_builtin_macros/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ pub(crate) fn expand_test_case(
check_builtin_macro_attribute(ecx, meta_item, sym::test_case);
warn_on_duplicate_attribute(ecx, &anno_item, sym::test_case);

if !ecx.ecfg.should_test {
return vec![];
}

let sp = ecx.with_def_site_ctxt(attr_sp);
let (mut item, is_stmt) = match anno_item {
Annotatable::Item(item) => (item, false),
Expand All @@ -54,6 +50,10 @@ pub(crate) fn expand_test_case(
}
};

if !ecx.ecfg.should_test {
return vec![];
}

// `#[test_case]` is valid on functions, consts, and statics. Only modify
// the item in those cases.
match &mut item.kind {
Expand Down Expand Up @@ -113,29 +113,29 @@ pub(crate) fn expand_test_or_bench(
item: Annotatable,
is_bench: bool,
) -> Vec<Annotatable> {
// If we're not in test configuration, remove the annotated item
if !cx.ecfg.should_test {
return vec![];
}

let (item, is_stmt) = match item {
Annotatable::Item(i) => (i, false),
Annotatable::Stmt(box ast::Stmt { kind: ast::StmtKind::Item(i), .. }) => (i, true),
other => {
not_testable_error(cx, attr_sp, None);
not_testable_error(cx, is_bench, attr_sp, None);
return vec![other];
}
};

let ast::ItemKind::Fn(fn_) = &item.kind else {
not_testable_error(cx, attr_sp, Some(&item));
not_testable_error(cx, is_bench, attr_sp, Some(&item));
return if is_stmt {
vec![Annotatable::Stmt(Box::new(cx.stmt_item(item.span, item)))]
} else {
vec![Annotatable::Item(item)]
};
};

// If we're not in test configuration, remove the annotated item
if !cx.ecfg.should_test {
return vec![];
}

if let Some(attr) = attr::find_by_name(&item.attrs, sym::naked) {
cx.dcx().emit_err(errors::NakedFunctionTestingAttribute {
testing_span: attr_sp,
Expand Down Expand Up @@ -405,9 +405,10 @@ pub(crate) fn expand_test_or_bench(
}
}

fn not_testable_error(cx: &ExtCtxt<'_>, attr_sp: Span, item: Option<&ast::Item>) {
fn not_testable_error(cx: &ExtCtxt<'_>, is_bench: bool, attr_sp: Span, item: Option<&ast::Item>) {
let dcx = cx.dcx();
let msg = "the `#[test]` attribute may only be used on a non-associated function";
let name = if is_bench { "bench" } else { "test" };
let msg = format!("the `#[{name}]` attribute may only be used on a free function");
let level = match item.map(|i| &i.kind) {
// These were a warning before #92959 and need to continue being that to avoid breaking
// stable user code (#94508).
Expand All @@ -426,12 +427,16 @@ fn not_testable_error(cx: &ExtCtxt<'_>, attr_sp: Span, item: Option<&ast::Item>)
),
);
}
err.with_span_label(attr_sp, "the `#[test]` macro causes a function to be run as a test and has no effect on non-functions")
.with_span_suggestion(attr_sp,
err.span_label(attr_sp, format!("the `#[{name}]` macro causes a function to be run as a test and has no effect on non-functions"));

if !is_bench {
err.with_span_suggestion(attr_sp,
"replace with conditional compilation to make the item only exist when tests are being run",
"#[cfg(test)]",
Applicability::MaybeIncorrect)
.emit();
Applicability::MaybeIncorrect).emit();
} else {
err.emit();
}
}

fn get_location_info(cx: &ExtCtxt<'_>, fn_: &ast::Fn) -> (Symbol, usize, usize, usize, usize) {
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_codegen_ssa/src/back/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ impl MetadataLoader for DefaultMetadataLoader {
format!("failed to parse aix dylib '{}': {}", path.display(), e)
})?;

// FIXME: rewrite in terms of `#![feature(exact_length_collection)]`. See: #149266
match Itertools::exactly_one(archive.members()) {
match archive.members().exactly_one() {
Ok(lib) => {
let lib = lib.map_err(|e| {
format!("failed to parse aix dylib '{}': {}", path.display(), e)
Expand Down
29 changes: 26 additions & 3 deletions compiler/rustc_const_eval/src/interpret/eval_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ use rustc_middle::ty::layout::{
self, FnAbiError, FnAbiOf, FnAbiOfHelpers, FnAbiRequest, LayoutError, LayoutOf,
LayoutOfHelpers, TyAndLayout,
};
use rustc_middle::ty::{self, GenericArgsRef, Ty, TyCtxt, TypeFoldable, TypingEnv, Variance};
use rustc_middle::ty::{
self, GenericArgsRef, Ty, TyCtxt, TypeFoldable, TypeVisitableExt, TypingEnv, Variance,
};
use rustc_middle::{mir, span_bug};
use rustc_span::Span;
use rustc_target::callconv::FnAbi;
Expand Down Expand Up @@ -84,10 +86,31 @@ impl<'tcx, M: Machine<'tcx>> LayoutOfHelpers<'tcx> for InterpCx<'tcx, M> {
#[inline]
fn handle_layout_err(
&self,
err: LayoutError<'tcx>,
mut err: LayoutError<'tcx>,
_: Span,
_: Ty<'tcx>,
) -> InterpErrorKind<'tcx> {
// FIXME(#149283): This is really hacky and is only used to hide type
// system bugs. We use it as a temporary fix for #149081.
//
// While it's expected that we sometimes get ambiguity errors when
// entering another generic environment while the current environment
// itself is still generic, we should never fail to entirely prove
// something.
match err {
LayoutError::NormalizationFailure(ty, _) => {
if ty.has_non_region_param() {
err = LayoutError::TooGeneric(ty);
}
}

LayoutError::Unknown(_)
| LayoutError::SizeOverflow(_)
| LayoutError::InvalidSimd { .. }
| LayoutError::TooGeneric(_)
| LayoutError::ReferencesError(_)
| LayoutError::Cycle(_) => {}
}
err_inval!(Layout(err))
}
}
Expand All @@ -112,7 +135,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
/// and allows wrapping the actual [LayoutOf::layout_of] with a tracing span.
/// See [LayoutOf::layout_of] for the original documentation.
#[inline(always)]
pub fn layout_of(&self, ty: Ty<'tcx>) -> <Self as LayoutOfHelpers<'tcx>>::LayoutOfResult {
pub fn layout_of(&self, ty: Ty<'tcx>) -> Result<TyAndLayout<'tcx>, InterpErrorKind<'tcx>> {
let _trace = enter_trace_span!(M, layouting::layout_of, ty = ?ty.kind());
LayoutOf::layout_of(self, ty)
}
Expand Down
49 changes: 49 additions & 0 deletions compiler/rustc_hir/src/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1793,6 +1793,55 @@ impl<'hir> Pat<'hir> {
});
is_never_pattern
}

/// Whether this pattern constitutes a read of value of the scrutinee that
/// it is matching against. This is used to determine whether we should
/// perform `NeverToAny` coercions.
///
/// See [`expr_guaranteed_to_constitute_read_for_never`][m] for the nuances of
/// what happens when this returns true.
///
/// [m]: ../../rustc_middle/ty/struct.TyCtxt.html#method.expr_guaranteed_to_constitute_read_for_never
pub fn is_guaranteed_to_constitute_read_for_never(&self) -> bool {
match self.kind {
// Does not constitute a read.
PatKind::Wild => false,

// The guard cannot affect if we make a read or not (it runs after the inner pattern
// has matched), therefore it's irrelevant.
PatKind::Guard(pat, _) => pat.is_guaranteed_to_constitute_read_for_never(),

// This is unnecessarily restrictive when the pattern that doesn't
// constitute a read is unreachable.
//
// For example `match *never_ptr { value => {}, _ => {} }` or
// `match *never_ptr { _ if false => {}, value => {} }`.
//
// It is however fine to be restrictive here; only returning `true`
// can lead to unsoundness.
PatKind::Or(subpats) => {
subpats.iter().all(|pat| pat.is_guaranteed_to_constitute_read_for_never())
}

// Does constitute a read, since it is equivalent to a discriminant read.
PatKind::Never => true,

// All of these constitute a read, or match on something that isn't `!`,
// which would require a `NeverToAny` coercion.
PatKind::Missing
| PatKind::Binding(_, _, _, _)
| PatKind::Struct(_, _, _)
| PatKind::TupleStruct(_, _, _)
| PatKind::Tuple(_, _)
| PatKind::Box(_)
| PatKind::Ref(_, _, _)
| PatKind::Deref(_)
| PatKind::Expr(_)
| PatKind::Range(_, _, _)
| PatKind::Slice(_, _, _)
| PatKind::Err(_) => true,
}
}
}

/// A single field in a struct pattern.
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/coercion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1078,7 +1078,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
self,
cause,
allow_two_phase,
self.expr_guaranteed_to_constitute_read_for_never(expr),
self.tcx.expr_guaranteed_to_constitute_read_for_never(expr),
);
let ok = self.commit_if_ok(|_| coerce.coerce(source, target))?;

Expand Down
Loading
Loading