Skip to content

Commit 858e9f9

Browse files
Merge branch 'rust-lang:master' into issue-118859-fix
2 parents f5dde30 + 2fdd9ed commit 858e9f9

File tree

144 files changed

+2291
-870
lines changed

Some content is hidden

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

144 files changed

+2291
-870
lines changed

compiler/rustc_ast/src/ast.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,19 @@ impl Pat {
676676
});
677677
could_be_never_pattern
678678
}
679+
680+
/// Whether this contains a `!` pattern. This in particular means that a feature gate error will
681+
/// be raised if the feature is off. Used to avoid gating the feature twice.
682+
pub fn contains_never_pattern(&self) -> bool {
683+
let mut contains_never_pattern = false;
684+
self.walk(&mut |pat| {
685+
if matches!(pat.kind, PatKind::Never) {
686+
contains_never_pattern = true;
687+
}
688+
true
689+
});
690+
contains_never_pattern
691+
}
679692
}
680693

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

compiler/rustc_ast_lowering/src/expr.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -581,8 +581,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
581581
} else {
582582
// Either `body.is_none()` or `is_never_pattern` here.
583583
if !is_never_pattern {
584-
let suggestion = span.shrink_to_hi();
585-
self.tcx.sess.emit_err(MatchArmWithNoBody { span, suggestion });
584+
if self.tcx.features().never_patterns {
585+
// If the feature is off we already emitted the error after parsing.
586+
let suggestion = span.shrink_to_hi();
587+
self.tcx.sess.emit_err(MatchArmWithNoBody { span, suggestion });
588+
}
586589
} else if let Some(body) = &arm.body {
587590
self.tcx.sess.emit_err(NeverPatternWithBody { span: body.span });
588591
guard = None;

compiler/rustc_ast_passes/messages.ftl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,10 @@ ast_passes_item_underscore = `{$kind}` items in this context need a name
174174
ast_passes_keyword_lifetime =
175175
lifetimes cannot use keyword names
176176
177+
ast_passes_match_arm_with_no_body =
178+
`match` arm with no body
179+
.suggestion = add a body after the pattern
180+
177181
ast_passes_module_nonascii = trying to load file for module `{$name}` with non-ascii identifier name
178182
.help = consider using the `#[path]` attribute to specify filesystem path
179183

compiler/rustc_ast_passes/src/errors.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -758,3 +758,12 @@ pub struct AnonStructOrUnionNotAllowed {
758758
pub span: Span,
759759
pub struct_or_union: &'static str,
760760
}
761+
762+
#[derive(Diagnostic)]
763+
#[diag(ast_passes_match_arm_with_no_body)]
764+
pub struct MatchArmWithNoBody {
765+
#[primary_span]
766+
pub span: Span,
767+
#[suggestion(code = " => todo!(),", applicability = "has-placeholders")]
768+
pub suggestion: Span,
769+
}

compiler/rustc_ast_passes/src/feature_gate.rs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,34 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) {
554554
gate_all!(explicit_tail_calls, "`become` expression is experimental");
555555
gate_all!(generic_const_items, "generic const items are experimental");
556556
gate_all!(unnamed_fields, "unnamed fields are not yet fully implemented");
557-
gate_all!(never_patterns, "`!` patterns are experimental");
557+
558+
if !visitor.features.never_patterns {
559+
if let Some(spans) = spans.get(&sym::never_patterns) {
560+
for &span in spans {
561+
if span.allows_unstable(sym::never_patterns) {
562+
continue;
563+
}
564+
let sm = sess.source_map();
565+
// We gate two types of spans: the span of a `!` pattern, and the span of a
566+
// match arm without a body. For the latter we want to give the user a normal
567+
// error.
568+
if let Ok(snippet) = sm.span_to_snippet(span)
569+
&& snippet == "!"
570+
{
571+
feature_err(
572+
&sess.parse_sess,
573+
sym::never_patterns,
574+
span,
575+
"`!` patterns are experimental",
576+
)
577+
.emit();
578+
} else {
579+
let suggestion = span.shrink_to_hi();
580+
sess.emit_err(errors::MatchArmWithNoBody { span, suggestion });
581+
}
582+
}
583+
}
584+
}
558585

559586
if !visitor.features.negative_bounds {
560587
for &span in spans.get(&sym::negative_bounds).iter().copied().flatten() {

compiler/rustc_codegen_cranelift/build_system/tests.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,6 @@ const BASE_SYSROOT_SUITE: &[TestCase] = &[
7575
"example/arbitrary_self_types_pointers_and_wrappers.rs",
7676
&[],
7777
),
78-
TestCase::build_bin_and_run(
79-
"aot.issue_91827_extern_types",
80-
"example/issue-91827-extern-types.rs",
81-
&[],
82-
),
8378
TestCase::build_lib("build.alloc_system", "example/alloc_system.rs", "lib"),
8479
TestCase::build_bin_and_run("aot.alloc_example", "example/alloc_example.rs", &[]),
8580
TestCase::jit_bin("jit.std_example", "example/std_example.rs", ""),

compiler/rustc_codegen_cranelift/example/issue-91827-extern-types.rs

Lines changed: 0 additions & 55 deletions
This file was deleted.

compiler/rustc_codegen_llvm/src/back/lto.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -816,6 +816,9 @@ impl ThinLTOKeysMap {
816816
use std::io::Write;
817817
let file = File::create(path)?;
818818
let mut writer = io::BufWriter::new(file);
819+
// The entries are loaded back into a hash map in `load_from_file()`, so
820+
// the order in which we write them to file here does not matter.
821+
#[allow(rustc::potential_query_instability)]
819822
for (module, key) in &self.keys {
820823
writeln!(writer, "{module} {key}")?;
821824
}

compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ pub fn finalize(cx: &CodegenCx<'_, '_>) {
5858
return;
5959
}
6060

61+
// The entries of the map are only used to get a list of all files with
62+
// coverage info. In the end the list of files is passed into
63+
// `GlobalFileTable::new()` which internally do `.sort_unstable_by()`, so
64+
// the iteration order here does not matter.
65+
#[allow(rustc::potential_query_instability)]
6166
let function_coverage_entries = function_coverage_map
6267
.into_iter()
6368
.map(|(instance, function_coverage)| (instance, function_coverage.into_finished()))

compiler/rustc_codegen_llvm/src/intrinsic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1568,7 +1568,7 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
15681568

15691569
// Alignment of T, must be a constant integer value:
15701570
let alignment_ty = bx.type_i32();
1571-
let alignment = bx.const_i32(bx.align_of(values_ty).bytes() as i32);
1571+
let alignment = bx.const_i32(bx.align_of(values_elem).bytes() as i32);
15721572

15731573
// Truncate the mask vector to a vector of i1s:
15741574
let (mask, mask_ty) = {

0 commit comments

Comments
 (0)