Skip to content

Commit 5f8c17d

Browse files
committed
Auto merge of rust-lang#124916 - matthiaskrgr:rollup-vmpmt4u, r=matthiaskrgr
Rollup of 4 pull requests Successful merges: - rust-lang#124777 (Fix Error Messages for `break` Inside Coroutines) - rust-lang#124837 (Migrate `run-make/rustdoc-map-file` to rmake) - rust-lang#124875 (Fix more ICEs in `diagnostic::on_unimplemented`) - rust-lang#124908 (Handle field projections like slice indexing in invalid_reference_casting) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 37dc766 + 48b1e1a commit 5f8c17d

18 files changed

+417
-117
lines changed

compiler/rustc_lint/src/reference_casting.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,8 @@ fn is_cast_to_bigger_memory_layout<'tcx>(
202202

203203
// if the current expr looks like this `&mut expr[index]` then just looking
204204
// at `expr[index]` won't give us the underlying allocation, so we just skip it
205-
if let ExprKind::Index(..) = e_alloc.kind {
205+
// the same logic applies field access like `&mut expr.field`
206+
if let ExprKind::Index(..) | ExprKind::Field(..) = e_alloc.kind {
206207
return None;
207208
}
208209

compiler/rustc_passes/messages.ftl

+5-5
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,16 @@ passes_attr_only_in_functions =
5252
passes_both_ffi_const_and_pure =
5353
`#[ffi_const]` function cannot be `#[ffi_pure]`
5454
55-
passes_break_inside_async_block =
56-
`{$name}` inside of an `async` block
57-
.label = cannot `{$name}` inside of an `async` block
58-
.async_block_label = enclosing `async` block
59-
6055
passes_break_inside_closure =
6156
`{$name}` inside of a closure
6257
.label = cannot `{$name}` inside of a closure
6358
.closure_label = enclosing closure
6459
60+
passes_break_inside_coroutine =
61+
`{$name}` inside `{$kind}` {$source}
62+
.label = cannot `{$name}` inside `{$kind}` {$source}
63+
.coroutine_label = enclosing `{$kind}` {$source}
64+
6565
passes_break_non_loop =
6666
`break` with value from a `{$kind}` loop
6767
.label = can only break with a value inside `loop` or breakable block

compiler/rustc_passes/src/errors.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -1086,14 +1086,16 @@ pub struct BreakInsideClosure<'a> {
10861086
}
10871087

10881088
#[derive(Diagnostic)]
1089-
#[diag(passes_break_inside_async_block, code = E0267)]
1090-
pub struct BreakInsideAsyncBlock<'a> {
1089+
#[diag(passes_break_inside_coroutine, code = E0267)]
1090+
pub struct BreakInsideCoroutine<'a> {
10911091
#[primary_span]
10921092
#[label]
10931093
pub span: Span,
1094-
#[label(passes_async_block_label)]
1095-
pub closure_span: Span,
1094+
#[label(passes_coroutine_label)]
1095+
pub coroutine_span: Span,
10961096
pub name: &'a str,
1097+
pub kind: &'a str,
1098+
pub source: &'a str,
10971099
}
10981100

10991101
#[derive(Diagnostic)]

compiler/rustc_passes/src/loops.rs

+23-9
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_span::hygiene::DesugaringKind;
1313
use rustc_span::{BytePos, Span};
1414

1515
use crate::errors::{
16-
BreakInsideAsyncBlock, BreakInsideClosure, BreakNonLoop, ContinueLabeledBlock, OutsideLoop,
16+
BreakInsideClosure, BreakInsideCoroutine, BreakNonLoop, ContinueLabeledBlock, OutsideLoop,
1717
OutsideLoopSuggestion, UnlabeledCfInWhileCondition, UnlabeledInLabeledBlock,
1818
};
1919

@@ -23,7 +23,7 @@ enum Context {
2323
Fn,
2424
Loop(hir::LoopSource),
2525
Closure(Span),
26-
AsyncClosure(Span),
26+
Coroutine { coroutine_span: Span, kind: hir::CoroutineDesugaring, source: hir::CoroutineSource },
2727
UnlabeledBlock(Span),
2828
LabeledBlock,
2929
Constant,
@@ -89,12 +89,10 @@ impl<'a, 'hir> Visitor<'hir> for CheckLoopVisitor<'a, 'hir> {
8989
hir::ExprKind::Closure(&hir::Closure {
9090
ref fn_decl, body, fn_decl_span, kind, ..
9191
}) => {
92-
// FIXME(coroutines): This doesn't handle coroutines correctly
9392
let cx = match kind {
94-
hir::ClosureKind::Coroutine(hir::CoroutineKind::Desugared(
95-
hir::CoroutineDesugaring::Async,
96-
hir::CoroutineSource::Block,
97-
)) => AsyncClosure(fn_decl_span),
93+
hir::ClosureKind::Coroutine(hir::CoroutineKind::Desugared(kind, source)) => {
94+
Coroutine { coroutine_span: fn_decl_span, kind, source }
95+
}
9896
_ => Closure(fn_decl_span),
9997
};
10098
self.visit_fn_decl(fn_decl);
@@ -227,8 +225,24 @@ impl<'a, 'hir> CheckLoopVisitor<'a, 'hir> {
227225
Closure(closure_span) => {
228226
self.sess.dcx().emit_err(BreakInsideClosure { span, closure_span, name });
229227
}
230-
AsyncClosure(closure_span) => {
231-
self.sess.dcx().emit_err(BreakInsideAsyncBlock { span, closure_span, name });
228+
Coroutine { coroutine_span, kind, source } => {
229+
let kind = match kind {
230+
hir::CoroutineDesugaring::Async => "async",
231+
hir::CoroutineDesugaring::Gen => "gen",
232+
hir::CoroutineDesugaring::AsyncGen => "async gen",
233+
};
234+
let source = match source {
235+
hir::CoroutineSource::Block => "block",
236+
hir::CoroutineSource::Closure => "closure",
237+
hir::CoroutineSource::Fn => "function",
238+
};
239+
self.sess.dcx().emit_err(BreakInsideCoroutine {
240+
span,
241+
coroutine_span,
242+
name,
243+
kind,
244+
source,
245+
});
232246
}
233247
UnlabeledBlock(block_span) if is_break && block_span.eq_ctxt(break_span) => {
234248
let suggestion = Some(OutsideLoopSuggestion { block_span, break_span });

compiler/rustc_trait_selection/src/traits/error_reporting/on_unimplemented.rs

+69-51
Original file line numberDiff line numberDiff line change
@@ -350,12 +350,14 @@ impl IgnoredDiagnosticOption {
350350
option_name: &'static str,
351351
) {
352352
if let (Some(new_item), Some(old_item)) = (new, old) {
353-
tcx.emit_node_span_lint(
354-
UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES,
355-
tcx.local_def_id_to_hir_id(item_def_id.expect_local()),
356-
new_item,
357-
IgnoredDiagnosticOption { span: new_item, prev_span: old_item, option_name },
358-
);
353+
if let Some(item_def_id) = item_def_id.as_local() {
354+
tcx.emit_node_span_lint(
355+
UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES,
356+
tcx.local_def_id_to_hir_id(item_def_id),
357+
new_item,
358+
IgnoredDiagnosticOption { span: new_item, prev_span: old_item, option_name },
359+
);
360+
}
359361
}
360362
}
361363
}
@@ -639,30 +641,38 @@ impl<'tcx> OnUnimplementedDirective {
639641
AttrArgs::Eq(span, AttrArgsEq::Hir(expr)) => span.to(expr.span),
640642
};
641643

642-
tcx.emit_node_span_lint(
643-
UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES,
644-
tcx.local_def_id_to_hir_id(item_def_id.expect_local()),
645-
report_span,
646-
MalformedOnUnimplementedAttrLint::new(report_span),
647-
);
644+
if let Some(item_def_id) = item_def_id.as_local() {
645+
tcx.emit_node_span_lint(
646+
UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES,
647+
tcx.local_def_id_to_hir_id(item_def_id),
648+
report_span,
649+
MalformedOnUnimplementedAttrLint::new(report_span),
650+
);
651+
}
648652
Ok(None)
649653
}
650654
} else if is_diagnostic_namespace_variant {
651655
match &attr.kind {
652656
AttrKind::Normal(p) if !matches!(p.item.args, AttrArgs::Empty) => {
653-
tcx.emit_node_span_lint(
654-
UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES,
655-
tcx.local_def_id_to_hir_id(item_def_id.expect_local()),
656-
attr.span,
657-
MalformedOnUnimplementedAttrLint::new(attr.span),
658-
);
657+
if let Some(item_def_id) = item_def_id.as_local() {
658+
tcx.emit_node_span_lint(
659+
UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES,
660+
tcx.local_def_id_to_hir_id(item_def_id),
661+
attr.span,
662+
MalformedOnUnimplementedAttrLint::new(attr.span),
663+
);
664+
}
665+
}
666+
_ => {
667+
if let Some(item_def_id) = item_def_id.as_local() {
668+
tcx.emit_node_span_lint(
669+
UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES,
670+
tcx.local_def_id_to_hir_id(item_def_id),
671+
attr.span,
672+
MissingOptionsForOnUnimplementedAttr,
673+
)
674+
}
659675
}
660-
_ => tcx.emit_node_span_lint(
661-
UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES,
662-
tcx.local_def_id_to_hir_id(item_def_id.expect_local()),
663-
attr.span,
664-
MissingOptionsForOnUnimplementedAttr,
665-
),
666676
};
667677

668678
Ok(None)
@@ -791,12 +801,14 @@ impl<'tcx> OnUnimplementedFormatString {
791801
|| format_spec.precision_span.is_some()
792802
|| format_spec.fill_span.is_some())
793803
{
794-
tcx.emit_node_span_lint(
795-
UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES,
796-
tcx.local_def_id_to_hir_id(item_def_id.expect_local()),
797-
self.span,
798-
InvalidFormatSpecifier,
799-
);
804+
if let Some(item_def_id) = item_def_id.as_local() {
805+
tcx.emit_node_span_lint(
806+
UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES,
807+
tcx.local_def_id_to_hir_id(item_def_id),
808+
self.span,
809+
InvalidFormatSpecifier,
810+
);
811+
}
800812
}
801813
match a.position {
802814
Position::ArgumentNamed(s) => {
@@ -812,15 +824,17 @@ impl<'tcx> OnUnimplementedFormatString {
812824
s if generics.params.iter().any(|param| param.name == s) => (),
813825
s => {
814826
if self.is_diagnostic_namespace_variant {
815-
tcx.emit_node_span_lint(
816-
UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES,
817-
tcx.local_def_id_to_hir_id(item_def_id.expect_local()),
818-
self.span,
819-
UnknownFormatParameterForOnUnimplementedAttr {
820-
argument_name: s,
821-
trait_name,
822-
},
823-
);
827+
if let Some(item_def_id) = item_def_id.as_local() {
828+
tcx.emit_node_span_lint(
829+
UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES,
830+
tcx.local_def_id_to_hir_id(item_def_id),
831+
self.span,
832+
UnknownFormatParameterForOnUnimplementedAttr {
833+
argument_name: s,
834+
trait_name,
835+
},
836+
);
837+
}
824838
} else {
825839
result = Err(struct_span_code_err!(
826840
tcx.dcx(),
@@ -842,12 +856,14 @@ impl<'tcx> OnUnimplementedFormatString {
842856
// `{:1}` and `{}` are not to be used
843857
Position::ArgumentIs(..) | Position::ArgumentImplicitlyIs(_) => {
844858
if self.is_diagnostic_namespace_variant {
845-
tcx.emit_node_span_lint(
846-
UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES,
847-
tcx.local_def_id_to_hir_id(item_def_id.expect_local()),
848-
self.span,
849-
DisallowedPositionalArgument,
850-
);
859+
if let Some(item_def_id) = item_def_id.as_local() {
860+
tcx.emit_node_span_lint(
861+
UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES,
862+
tcx.local_def_id_to_hir_id(item_def_id),
863+
self.span,
864+
DisallowedPositionalArgument,
865+
);
866+
}
851867
} else {
852868
let reported = struct_span_code_err!(
853869
tcx.dcx(),
@@ -870,12 +886,14 @@ impl<'tcx> OnUnimplementedFormatString {
870886
// so that users are aware that something is not correct
871887
for e in parser.errors {
872888
if self.is_diagnostic_namespace_variant {
873-
tcx.emit_node_span_lint(
874-
UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES,
875-
tcx.local_def_id_to_hir_id(item_def_id.expect_local()),
876-
self.span,
877-
WrappedParserError { description: e.description, label: e.label },
878-
);
889+
if let Some(item_def_id) = item_def_id.as_local() {
890+
tcx.emit_node_span_lint(
891+
UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES,
892+
tcx.local_def_id_to_hir_id(item_def_id),
893+
self.span,
894+
WrappedParserError { description: e.description, label: e.label },
895+
);
896+
}
879897
} else {
880898
let reported =
881899
struct_span_code_err!(tcx.dcx(), self.span, E0231, "{}", e.description,).emit();

src/tools/tidy/src/allowed_run_make_makefiles.txt

-1
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,6 @@ run-make/rlib-format-packed-bundled-libs/Makefile
245245
run-make/rmeta-preferred/Makefile
246246
run-make/rustc-macro-dep-files/Makefile
247247
run-make/rustdoc-io-error/Makefile
248-
run-make/rustdoc-map-file/Makefile
249248
run-make/rustdoc-output-path/Makefile
250249
run-make/rustdoc-scrape-examples-invalid-expr/Makefile
251250
run-make/rustdoc-scrape-examples-macros/Makefile

tests/run-make/rustdoc-map-file/Makefile

-5
This file was deleted.
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
use run_make_support::{rustdoc, tmp_dir};
2+
use std::process::Command;
3+
4+
fn main() {
5+
let out_dir = tmp_dir().join("out");
6+
rustdoc()
7+
.input("foo.rs")
8+
.arg("-Zunstable-options")
9+
.arg("--generate-redirect-map")
10+
.output(&out_dir)
11+
.run();
12+
// FIXME (GuillaumeGomez): Port the python script to Rust as well.
13+
let python = std::env::var("PYTHON").unwrap_or("python".into());
14+
assert!(Command::new(python).arg("validate_json.py").arg(&out_dir).status().unwrap().success());
15+
}

tests/ui/async-await/async-block-control-flow-static-semantics.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ async fn return_targets_async_block_not_async_fn() -> u8 {
2929

3030
fn no_break_in_async_block() {
3131
async {
32-
break 0u8; //~ ERROR `break` inside of an `async` block
32+
break 0u8; //~ ERROR `break` inside `async` block
3333
};
3434
}
3535

3636
fn no_break_in_async_block_even_with_outer_loop() {
3737
loop {
3838
async {
39-
break 0u8; //~ ERROR `break` inside of an `async` block
39+
break 0u8; //~ ERROR `break` inside `async` block
4040
};
4141
}
4242
}

tests/ui/async-await/async-block-control-flow-static-semantics.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
error[E0267]: `break` inside of an `async` block
1+
error[E0267]: `break` inside `async` block
22
--> $DIR/async-block-control-flow-static-semantics.rs:32:9
33
|
44
LL | / async {
55
LL | | break 0u8;
6-
| | ^^^^^^^^^ cannot `break` inside of an `async` block
6+
| | ^^^^^^^^^ cannot `break` inside `async` block
77
LL | | };
88
| |_____- enclosing `async` block
99

10-
error[E0267]: `break` inside of an `async` block
10+
error[E0267]: `break` inside `async` block
1111
--> $DIR/async-block-control-flow-static-semantics.rs:39:13
1212
|
1313
LL | / async {
1414
LL | | break 0u8;
15-
| | ^^^^^^^^^ cannot `break` inside of an `async` block
15+
| | ^^^^^^^^^ cannot `break` inside `async` block
1616
LL | | };
1717
| |_________- enclosing `async` block
1818

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//@ edition: 2024
2+
//@ compile-flags: -Z unstable-options
3+
4+
#![feature(gen_blocks)]
5+
#![feature(async_closure)]
6+
7+
async fn async_fn() {
8+
break; //~ ERROR `break` inside `async` function
9+
}
10+
11+
gen fn gen_fn() {
12+
break; //~ ERROR `break` inside `gen` function
13+
}
14+
15+
async gen fn async_gen_fn() {
16+
break; //~ ERROR `break` inside `async gen` function
17+
}
18+
19+
fn main() {
20+
let _ = async { break; }; //~ ERROR `break` inside `async` block
21+
let _ = async || { break; }; //~ ERROR `break` inside `async` closure
22+
23+
let _ = gen { break; }; //~ ERROR `break` inside `gen` block
24+
25+
let _ = async gen { break; }; //~ ERROR `break` inside `async gen` block
26+
}

0 commit comments

Comments
 (0)