Skip to content

Commit

Permalink
Continue to borrowck even if there were previous errors
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Feb 1, 2024
1 parent dc618dc commit 6ff8054
Show file tree
Hide file tree
Showing 198 changed files with 3,174 additions and 477 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/lib.rs
Expand Up @@ -209,7 +209,7 @@ pub fn check_crate(tcx: TyCtxt<'_>) -> Result<(), ErrorGuaranteed> {

tcx.ensure().check_unused_traits(());

if let Some(reported) = tcx.dcx().has_errors() { Err(reported) } else { Ok(()) }
Ok(())
}

/// A quasi-deprecated helper used in rustdoc and clippy to get
Expand Down
8 changes: 6 additions & 2 deletions compiler/rustc_mir_build/src/build/mod.rs
Expand Up @@ -675,8 +675,12 @@ fn construct_error(tcx: TyCtxt<'_>, def_id: LocalDefId, guar: ErrorGuaranteed) -
))),
)
}
_ => {
span_bug!(span, "expected type of closure body to be a closure or coroutine");
ty::Error(_) => (vec![closure_ty, closure_ty], closure_ty, None),
kind => {
span_bug!(
span,
"expected type of closure body to be a closure or coroutine, got {kind:?}"
);
}
}
}
Expand Down
12 changes: 11 additions & 1 deletion compiler/rustc_mir_build/src/build/scope.rs
Expand Up @@ -655,7 +655,17 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
let drops = if destination.is_some() {
&mut self.scopes.breakable_scopes[break_index].break_drops
} else {
self.scopes.breakable_scopes[break_index].continue_drops.as_mut().unwrap()
let Some(drops) = self.scopes.breakable_scopes[break_index].continue_drops.as_mut()
else {
self.tcx.dcx().span_delayed_bug(
source_info.span,
"unlabelled `continue` within labelled block",
);
self.cfg.terminate(block, source_info, TerminatorKind::Unreachable);

return self.cfg.start_new_block().unit();
};
drops
};

let drop_idx = self.scopes.scopes[scope_index + 1..]
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_mir_transform/src/ffi_unwind_calls.rs
Expand Up @@ -58,6 +58,7 @@ fn has_ffi_unwind_calls(tcx: TyCtxt<'_>, local_def_id: LocalDefId) -> bool {
ty::FnDef(..) => body_ty.fn_sig(tcx).abi(),
ty::Closure(..) => Abi::RustCall,
ty::Coroutine(..) => Abi::Rust,
ty::Error(_) => return false,
_ => span_bug!(body.span, "unexpected body ty: {:?}", body_ty),
};
let body_can_unwind = layout::fn_can_unwind(tcx, Some(def_id), body_abi);
Expand Down
12 changes: 11 additions & 1 deletion compiler/rustc_parse/src/parser/expr.rs
Expand Up @@ -2911,12 +2911,22 @@ impl<'a> Parser<'a> {
Ok(arm) => arms.push(arm),
Err(e) => {
// Recover by skipping to the end of the block.
e.emit();
let guar = e.emit();
self.recover_stmt();
let span = lo.to(self.token.span);
if self.token == token::CloseDelim(Delimiter::Brace) {
self.bump();
}
// Always push at least one arm to make the match non-empty
arms.push(Arm {
attrs: Default::default(),
pat: self.mk_pat(span, ast::PatKind::Err(guar)),
guard: None,
body: Some(self.mk_expr_err(span)),
span,
id: DUMMY_NODE_ID,
is_placeholder: false,
});
return Ok(self.mk_expr_with_attrs(
span,
ExprKind::Match(scrutinee, arms),
Expand Down
10 changes: 6 additions & 4 deletions compiler/rustc_passes/src/liveness.rs
Expand Up @@ -123,6 +123,7 @@ enum LiveNodeKind {
VarDefNode(Span, HirId),
ClosureNode,
ExitNode,
ErrNode,
}

fn live_node_kind_to_string(lnk: LiveNodeKind, tcx: TyCtxt<'_>) -> String {
Expand All @@ -133,6 +134,7 @@ fn live_node_kind_to_string(lnk: LiveNodeKind, tcx: TyCtxt<'_>) -> String {
VarDefNode(s, _) => format!("Var def node [{}]", sm.span_to_diagnostic_string(s)),
ClosureNode => "Closure node".to_owned(),
ExitNode => "Exit node".to_owned(),
ErrNode => "Error node".to_owned(),
}
}

Expand Down Expand Up @@ -962,10 +964,10 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {

// Now that we know the label we're going to,
// look it up in the continue loop nodes table
self.cont_ln
.get(&sc)
.cloned()
.unwrap_or_else(|| span_bug!(expr.span, "continue to unknown label"))
self.cont_ln.get(&sc).cloned().unwrap_or_else(|| {
self.ir.tcx.dcx().span_delayed_bug(expr.span, "continue to unknown label");
self.ir.add_live_node(ErrNode)
})
}

hir::ExprKind::Assign(ref l, ref r, _) => {
Expand Down
3 changes: 3 additions & 0 deletions tests/incremental/const-generics/issue-62536.rs
@@ -1,4 +1,7 @@
// revisions:cfail1

#![allow(unused_variables)]

struct S<T, const N: usize>([T; N]);

fn f<T, const N: usize>(x: T) -> S<T, {N}> { panic!() }
Expand Down
@@ -1,6 +1,6 @@
// revisions: cfail
#![feature(generic_const_exprs)]
#![allow(incomplete_features, unused_braces)]
#![allow(incomplete_features, unused_braces, unused_variables)]

trait Delegates<T> {}

Expand Down
1 change: 1 addition & 0 deletions tests/incremental/struct_change_field_name.rs
Expand Up @@ -6,6 +6,7 @@
// [cfail2] compile-flags: -Z query-dep-graph -Z assert-incr-state=loaded

#![feature(rustc_attrs)]
#![allow(unused_variables)]

#[cfg(rpass1)]
pub struct X {
Expand Down
52 changes: 26 additions & 26 deletions tests/ui/asm/bad-template.aarch64.stderr
@@ -1,35 +1,35 @@
error: invalid reference to argument at index 0
--> $DIR/bad-template.rs:27:15
--> $DIR/bad-template.rs:30:15
|
LL | asm!("{}");
| ^^ from here
|
= note: no arguments were given

error: invalid reference to argument at index 1
--> $DIR/bad-template.rs:29:15
--> $DIR/bad-template.rs:32:15
|
LL | asm!("{1}", in(reg) foo);
| ^^^ from here
|
= note: there is 1 argument

error: argument never used
--> $DIR/bad-template.rs:29:21
--> $DIR/bad-template.rs:32:21
|
LL | asm!("{1}", in(reg) foo);
| ^^^^^^^^^^^ argument never used
|
= help: if this argument is intentionally unused, consider using it in an asm comment: `"/* {0} */"`

error: there is no argument named `a`
--> $DIR/bad-template.rs:32:16
--> $DIR/bad-template.rs:35:16
|
LL | asm!("{a}");
| ^

error: invalid reference to argument at index 0
--> $DIR/bad-template.rs:34:15
--> $DIR/bad-template.rs:37:15
|
LL | asm!("{}", a = in(reg) foo);
| ^^ --------------- named argument
Expand All @@ -38,37 +38,37 @@ LL | asm!("{}", a = in(reg) foo);
|
= note: no positional arguments were given
note: named arguments cannot be referenced by position
--> $DIR/bad-template.rs:34:20
--> $DIR/bad-template.rs:37:20
|
LL | asm!("{}", a = in(reg) foo);
| ^^^^^^^^^^^^^^^

error: named argument never used
--> $DIR/bad-template.rs:34:20
--> $DIR/bad-template.rs:37:20
|
LL | asm!("{}", a = in(reg) foo);
| ^^^^^^^^^^^^^^^ named argument never used
|
= help: if this argument is intentionally unused, consider using it in an asm comment: `"/* {a} */"`

error: invalid reference to argument at index 1
--> $DIR/bad-template.rs:37:15
--> $DIR/bad-template.rs:40:15
|
LL | asm!("{1}", a = in(reg) foo);
| ^^^ from here
|
= note: no positional arguments were given

error: named argument never used
--> $DIR/bad-template.rs:37:21
--> $DIR/bad-template.rs:40:21
|
LL | asm!("{1}", a = in(reg) foo);
| ^^^^^^^^^^^^^^^ named argument never used
|
= help: if this argument is intentionally unused, consider using it in an asm comment: `"/* {a} */"`

error: invalid reference to argument at index 0
--> $DIR/bad-template.rs:44:15
--> $DIR/bad-template.rs:47:15
|
LL | asm!("{}", in("x0") foo);
| ^^ ------------ explicit register argument
Expand All @@ -77,24 +77,24 @@ LL | asm!("{}", in("x0") foo);
|
= note: no positional arguments were given
note: explicit register arguments cannot be used in the asm template
--> $DIR/bad-template.rs:44:20
--> $DIR/bad-template.rs:47:20
|
LL | asm!("{}", in("x0") foo);
| ^^^^^^^^^^^^
help: use the register name directly in the assembly code
--> $DIR/bad-template.rs:44:20
--> $DIR/bad-template.rs:47:20
|
LL | asm!("{}", in("x0") foo);
| ^^^^^^^^^^^^

error: asm template modifier must be a single character
--> $DIR/bad-template.rs:46:17
--> $DIR/bad-template.rs:49:17
|
LL | asm!("{:foo}", in(reg) foo);
| ^^^

error: multiple unused asm arguments
--> $DIR/bad-template.rs:49:18
--> $DIR/bad-template.rs:52:18
|
LL | asm!("", in(reg) 0, in(reg) 1);
| ^^^^^^^^^ ^^^^^^^^^ argument never used
Expand All @@ -104,37 +104,37 @@ LL | asm!("", in(reg) 0, in(reg) 1);
= help: if these arguments are intentionally unused, consider using them in an asm comment: `"/* {0} {1} */"`

error: invalid reference to argument at index 0
--> $DIR/bad-template.rs:55:14
--> $DIR/bad-template.rs:58:14
|
LL | global_asm!("{}");
| ^^ from here
|
= note: no arguments were given

error: invalid reference to argument at index 1
--> $DIR/bad-template.rs:57:14
--> $DIR/bad-template.rs:60:14
|
LL | global_asm!("{1}", const FOO);
| ^^^ from here
|
= note: there is 1 argument

error: argument never used
--> $DIR/bad-template.rs:57:20
--> $DIR/bad-template.rs:60:20
|
LL | global_asm!("{1}", const FOO);
| ^^^^^^^^^ argument never used
|
= help: if this argument is intentionally unused, consider using it in an asm comment: `"/* {0} */"`

error: there is no argument named `a`
--> $DIR/bad-template.rs:60:15
--> $DIR/bad-template.rs:63:15
|
LL | global_asm!("{a}");
| ^

error: invalid reference to argument at index 0
--> $DIR/bad-template.rs:62:14
--> $DIR/bad-template.rs:65:14
|
LL | global_asm!("{}", a = const FOO);
| ^^ ------------- named argument
Expand All @@ -143,43 +143,43 @@ LL | global_asm!("{}", a = const FOO);
|
= note: no positional arguments were given
note: named arguments cannot be referenced by position
--> $DIR/bad-template.rs:62:19
--> $DIR/bad-template.rs:65:19
|
LL | global_asm!("{}", a = const FOO);
| ^^^^^^^^^^^^^

error: named argument never used
--> $DIR/bad-template.rs:62:19
--> $DIR/bad-template.rs:65:19
|
LL | global_asm!("{}", a = const FOO);
| ^^^^^^^^^^^^^ named argument never used
|
= help: if this argument is intentionally unused, consider using it in an asm comment: `"/* {a} */"`

error: invalid reference to argument at index 1
--> $DIR/bad-template.rs:65:14
--> $DIR/bad-template.rs:68:14
|
LL | global_asm!("{1}", a = const FOO);
| ^^^ from here
|
= note: no positional arguments were given

error: named argument never used
--> $DIR/bad-template.rs:65:20
--> $DIR/bad-template.rs:68:20
|
LL | global_asm!("{1}", a = const FOO);
| ^^^^^^^^^^^^^ named argument never used
|
= help: if this argument is intentionally unused, consider using it in an asm comment: `"/* {a} */"`

error: asm template modifier must be a single character
--> $DIR/bad-template.rs:68:16
--> $DIR/bad-template.rs:71:16
|
LL | global_asm!("{:foo}", const FOO);
| ^^^

error: multiple unused asm arguments
--> $DIR/bad-template.rs:70:17
--> $DIR/bad-template.rs:73:17
|
LL | global_asm!("", const FOO, const FOO);
| ^^^^^^^^^ ^^^^^^^^^ argument never used
Expand All @@ -189,7 +189,7 @@ LL | global_asm!("", const FOO, const FOO);
= help: if these arguments are intentionally unused, consider using them in an asm comment: `"/* {0} {1} */"`

warning: formatting may not be suitable for sub-register argument
--> $DIR/bad-template.rs:46:15
--> $DIR/bad-template.rs:49:15
|
LL | asm!("{:foo}", in(reg) foo);
| ^^^^^^ --- for this argument
Expand Down
3 changes: 3 additions & 0 deletions tests/ui/asm/bad-template.rs
Expand Up @@ -21,6 +21,9 @@ macro_rules! global_asm {
#[lang = "sized"]
trait Sized {}

#[lang = "copy"]
trait Copy {}

fn main() {
let mut foo = 0;
unsafe {
Expand Down

0 comments on commit 6ff8054

Please sign in to comment.