Skip to content

Commit 0325719

Browse files
committed
Auto merge of #149603 - matthiaskrgr:rollup-qvo8q9s, r=matthiaskrgr
Rollup of 9 pull requests Successful merges: - #147841 (Fix ICE when applying test macro to crate root) - #149501 (CTFE: avoid emitting a hard error on generic normalization failures) - #149517 (Implement blessing for tidy alphabetical check) - #149521 (Improve `io::Error::downcast`) - #149545 (fix the check for which expressions read never type) - #149549 (Regression test for system register `ttbr0_el2`) - #149579 (Motor OS: fix compile error) - #149595 (Tidying up `tests/ui/issues` tests [2/N]) - #149597 (Revert "implement and test `Iterator::{exactly_one, collect_array}`") r? `@ghost` `@rustbot` modify labels: rollup
2 parents 5325015 + cd923ac commit 0325719

File tree

62 files changed

+1293
-802
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+1293
-802
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5615,6 +5615,7 @@ dependencies = [
56155615
"semver",
56165616
"serde",
56175617
"similar",
5618+
"tempfile",
56185619
"termcolor",
56195620
"toml 0.7.8",
56205621
"walkdir",

compiler/rustc_builtin_macros/src/test.rs

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@ pub(crate) fn expand_test_case(
3434
check_builtin_macro_attribute(ecx, meta_item, sym::test_case);
3535
warn_on_duplicate_attribute(ecx, &anno_item, sym::test_case);
3636

37-
if !ecx.ecfg.should_test {
38-
return vec![];
39-
}
40-
4137
let sp = ecx.with_def_site_ctxt(attr_sp);
4238
let (mut item, is_stmt) = match anno_item {
4339
Annotatable::Item(item) => (item, false),
@@ -54,6 +50,10 @@ pub(crate) fn expand_test_case(
5450
}
5551
};
5652

53+
if !ecx.ecfg.should_test {
54+
return vec![];
55+
}
56+
5757
// `#[test_case]` is valid on functions, consts, and statics. Only modify
5858
// the item in those cases.
5959
match &mut item.kind {
@@ -113,29 +113,29 @@ pub(crate) fn expand_test_or_bench(
113113
item: Annotatable,
114114
is_bench: bool,
115115
) -> Vec<Annotatable> {
116-
// If we're not in test configuration, remove the annotated item
117-
if !cx.ecfg.should_test {
118-
return vec![];
119-
}
120-
121116
let (item, is_stmt) = match item {
122117
Annotatable::Item(i) => (i, false),
123118
Annotatable::Stmt(box ast::Stmt { kind: ast::StmtKind::Item(i), .. }) => (i, true),
124119
other => {
125-
not_testable_error(cx, attr_sp, None);
120+
not_testable_error(cx, is_bench, attr_sp, None);
126121
return vec![other];
127122
}
128123
};
129124

130125
let ast::ItemKind::Fn(fn_) = &item.kind else {
131-
not_testable_error(cx, attr_sp, Some(&item));
126+
not_testable_error(cx, is_bench, attr_sp, Some(&item));
132127
return if is_stmt {
133128
vec![Annotatable::Stmt(Box::new(cx.stmt_item(item.span, item)))]
134129
} else {
135130
vec![Annotatable::Item(item)]
136131
};
137132
};
138133

134+
// If we're not in test configuration, remove the annotated item
135+
if !cx.ecfg.should_test {
136+
return vec![];
137+
}
138+
139139
if let Some(attr) = attr::find_by_name(&item.attrs, sym::naked) {
140140
cx.dcx().emit_err(errors::NakedFunctionTestingAttribute {
141141
testing_span: attr_sp,
@@ -405,9 +405,10 @@ pub(crate) fn expand_test_or_bench(
405405
}
406406
}
407407

408-
fn not_testable_error(cx: &ExtCtxt<'_>, attr_sp: Span, item: Option<&ast::Item>) {
408+
fn not_testable_error(cx: &ExtCtxt<'_>, is_bench: bool, attr_sp: Span, item: Option<&ast::Item>) {
409409
let dcx = cx.dcx();
410-
let msg = "the `#[test]` attribute may only be used on a non-associated function";
410+
let name = if is_bench { "bench" } else { "test" };
411+
let msg = format!("the `#[{name}]` attribute may only be used on a free function");
411412
let level = match item.map(|i| &i.kind) {
412413
// These were a warning before #92959 and need to continue being that to avoid breaking
413414
// stable user code (#94508).
@@ -426,12 +427,16 @@ fn not_testable_error(cx: &ExtCtxt<'_>, attr_sp: Span, item: Option<&ast::Item>)
426427
),
427428
);
428429
}
429-
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")
430-
.with_span_suggestion(attr_sp,
430+
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"));
431+
432+
if !is_bench {
433+
err.with_span_suggestion(attr_sp,
431434
"replace with conditional compilation to make the item only exist when tests are being run",
432435
"#[cfg(test)]",
433-
Applicability::MaybeIncorrect)
434-
.emit();
436+
Applicability::MaybeIncorrect).emit();
437+
} else {
438+
err.emit();
439+
}
435440
}
436441

437442
fn get_location_info(cx: &ExtCtxt<'_>, fn_: &ast::Fn) -> (Symbol, usize, usize, usize, usize) {

compiler/rustc_codegen_ssa/src/back/metadata.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,7 @@ impl MetadataLoader for DefaultMetadataLoader {
8686
format!("failed to parse aix dylib '{}': {}", path.display(), e)
8787
})?;
8888

89-
// FIXME: rewrite in terms of `#![feature(exact_length_collection)]`. See: #149266
90-
match Itertools::exactly_one(archive.members()) {
89+
match archive.members().exactly_one() {
9190
Ok(lib) => {
9291
let lib = lib.map_err(|e| {
9392
format!("failed to parse aix dylib '{}': {}", path.display(), e)

compiler/rustc_const_eval/src/interpret/eval_context.rs

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ use rustc_middle::ty::layout::{
1111
self, FnAbiError, FnAbiOf, FnAbiOfHelpers, FnAbiRequest, LayoutError, LayoutOf,
1212
LayoutOfHelpers, TyAndLayout,
1313
};
14-
use rustc_middle::ty::{self, GenericArgsRef, Ty, TyCtxt, TypeFoldable, TypingEnv, Variance};
14+
use rustc_middle::ty::{
15+
self, GenericArgsRef, Ty, TyCtxt, TypeFoldable, TypeVisitableExt, TypingEnv, Variance,
16+
};
1517
use rustc_middle::{mir, span_bug};
1618
use rustc_span::Span;
1719
use rustc_target::callconv::FnAbi;
@@ -84,10 +86,31 @@ impl<'tcx, M: Machine<'tcx>> LayoutOfHelpers<'tcx> for InterpCx<'tcx, M> {
8486
#[inline]
8587
fn handle_layout_err(
8688
&self,
87-
err: LayoutError<'tcx>,
89+
mut err: LayoutError<'tcx>,
8890
_: Span,
8991
_: Ty<'tcx>,
9092
) -> InterpErrorKind<'tcx> {
93+
// FIXME(#149283): This is really hacky and is only used to hide type
94+
// system bugs. We use it as a temporary fix for #149081.
95+
//
96+
// While it's expected that we sometimes get ambiguity errors when
97+
// entering another generic environment while the current environment
98+
// itself is still generic, we should never fail to entirely prove
99+
// something.
100+
match err {
101+
LayoutError::NormalizationFailure(ty, _) => {
102+
if ty.has_non_region_param() {
103+
err = LayoutError::TooGeneric(ty);
104+
}
105+
}
106+
107+
LayoutError::Unknown(_)
108+
| LayoutError::SizeOverflow(_)
109+
| LayoutError::InvalidSimd { .. }
110+
| LayoutError::TooGeneric(_)
111+
| LayoutError::ReferencesError(_)
112+
| LayoutError::Cycle(_) => {}
113+
}
91114
err_inval!(Layout(err))
92115
}
93116
}
@@ -112,7 +135,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
112135
/// and allows wrapping the actual [LayoutOf::layout_of] with a tracing span.
113136
/// See [LayoutOf::layout_of] for the original documentation.
114137
#[inline(always)]
115-
pub fn layout_of(&self, ty: Ty<'tcx>) -> <Self as LayoutOfHelpers<'tcx>>::LayoutOfResult {
138+
pub fn layout_of(&self, ty: Ty<'tcx>) -> Result<TyAndLayout<'tcx>, InterpErrorKind<'tcx>> {
116139
let _trace = enter_trace_span!(M, layouting::layout_of, ty = ?ty.kind());
117140
LayoutOf::layout_of(self, ty)
118141
}

compiler/rustc_hir/src/hir.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1793,6 +1793,55 @@ impl<'hir> Pat<'hir> {
17931793
});
17941794
is_never_pattern
17951795
}
1796+
1797+
/// Whether this pattern constitutes a read of value of the scrutinee that
1798+
/// it is matching against. This is used to determine whether we should
1799+
/// perform `NeverToAny` coercions.
1800+
///
1801+
/// See [`expr_guaranteed_to_constitute_read_for_never`][m] for the nuances of
1802+
/// what happens when this returns true.
1803+
///
1804+
/// [m]: ../../rustc_middle/ty/struct.TyCtxt.html#method.expr_guaranteed_to_constitute_read_for_never
1805+
pub fn is_guaranteed_to_constitute_read_for_never(&self) -> bool {
1806+
match self.kind {
1807+
// Does not constitute a read.
1808+
PatKind::Wild => false,
1809+
1810+
// The guard cannot affect if we make a read or not (it runs after the inner pattern
1811+
// has matched), therefore it's irrelevant.
1812+
PatKind::Guard(pat, _) => pat.is_guaranteed_to_constitute_read_for_never(),
1813+
1814+
// This is unnecessarily restrictive when the pattern that doesn't
1815+
// constitute a read is unreachable.
1816+
//
1817+
// For example `match *never_ptr { value => {}, _ => {} }` or
1818+
// `match *never_ptr { _ if false => {}, value => {} }`.
1819+
//
1820+
// It is however fine to be restrictive here; only returning `true`
1821+
// can lead to unsoundness.
1822+
PatKind::Or(subpats) => {
1823+
subpats.iter().all(|pat| pat.is_guaranteed_to_constitute_read_for_never())
1824+
}
1825+
1826+
// Does constitute a read, since it is equivalent to a discriminant read.
1827+
PatKind::Never => true,
1828+
1829+
// All of these constitute a read, or match on something that isn't `!`,
1830+
// which would require a `NeverToAny` coercion.
1831+
PatKind::Missing
1832+
| PatKind::Binding(_, _, _, _)
1833+
| PatKind::Struct(_, _, _)
1834+
| PatKind::TupleStruct(_, _, _)
1835+
| PatKind::Tuple(_, _)
1836+
| PatKind::Box(_)
1837+
| PatKind::Ref(_, _, _)
1838+
| PatKind::Deref(_)
1839+
| PatKind::Expr(_)
1840+
| PatKind::Range(_, _, _)
1841+
| PatKind::Slice(_, _, _)
1842+
| PatKind::Err(_) => true,
1843+
}
1844+
}
17961845
}
17971846

17981847
/// A single field in a struct pattern.

compiler/rustc_hir_typeck/src/coercion.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1078,7 +1078,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10781078
self,
10791079
cause,
10801080
allow_two_phase,
1081-
self.expr_guaranteed_to_constitute_read_for_never(expr),
1081+
self.tcx.expr_guaranteed_to_constitute_read_for_never(expr),
10821082
);
10831083
let ok = self.commit_if_ok(|_| coerce.coerce(source, target))?;
10841084

0 commit comments

Comments
 (0)