Rollup merge of #108379 - compiler-errors:hir-error-guaranteed, r=cjgillot
Add `ErrorGuaranteed` to `hir::{Expr,Ty}Kind::Err` variants First step in making the `Err` variants of `ExprKind` and `TyKind` require an `ErrorGuaranteed` during parsing. Making the corresponding AST versions require `ErrorGuaranteed` is a bit harder, whereas it was pretty easy to do this for HIR, so let's do that first. The only weird thing about this PR is that `ErrorGuaranteed` is moved to `rustc_span`. This is *certainly* not the right place to put it, but `rustc_hir` cannot depend on `rustc_error` because the latter already depends on the former. Should I just pull out some of the error machinery from `rustc_error` into an even more minimal crate that `rustc_hir` can depend on? Advice would be appreciated.
This commit is contained in:
commit
19b8685b06
27 changed files with 111 additions and 88 deletions
|
@ -88,8 +88,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||||
let kind = hir::ExprKind::Box(self.lower_expr(&inner));
|
let kind = hir::ExprKind::Box(self.lower_expr(&inner));
|
||||||
return hir::Expr { hir_id, kind, span: self.lower_span(e.span) };
|
return hir::Expr { hir_id, kind, span: self.lower_span(e.span) };
|
||||||
} else {
|
} else {
|
||||||
self.tcx.sess.emit_err(RustcBoxAttributeError { span: e.span });
|
let guar = self.tcx.sess.emit_err(RustcBoxAttributeError { span: e.span });
|
||||||
hir::ExprKind::Err
|
hir::ExprKind::Err(guar)
|
||||||
}
|
}
|
||||||
} else if let Some(legacy_args) = self.resolver.legacy_const_generic_args(f) {
|
} else if let Some(legacy_args) = self.resolver.legacy_const_generic_args(f) {
|
||||||
self.lower_legacy_const_generics((**f).clone(), args.clone(), &legacy_args)
|
self.lower_legacy_const_generics((**f).clone(), args.clone(), &legacy_args)
|
||||||
|
@ -266,8 +266,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||||
self.lower_expr_range(e.span, e1.as_deref(), e2.as_deref(), *lims)
|
self.lower_expr_range(e.span, e1.as_deref(), e2.as_deref(), *lims)
|
||||||
}
|
}
|
||||||
ExprKind::Underscore => {
|
ExprKind::Underscore => {
|
||||||
self.tcx.sess.emit_err(UnderscoreExprLhsAssign { span: e.span });
|
let guar = self.tcx.sess.emit_err(UnderscoreExprLhsAssign { span: e.span });
|
||||||
hir::ExprKind::Err
|
hir::ExprKind::Err(guar)
|
||||||
}
|
}
|
||||||
ExprKind::Path(qself, path) => {
|
ExprKind::Path(qself, path) => {
|
||||||
let qpath = self.lower_qpath(
|
let qpath = self.lower_qpath(
|
||||||
|
@ -299,8 +299,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||||
let rest = match &se.rest {
|
let rest = match &se.rest {
|
||||||
StructRest::Base(e) => Some(self.lower_expr(e)),
|
StructRest::Base(e) => Some(self.lower_expr(e)),
|
||||||
StructRest::Rest(sp) => {
|
StructRest::Rest(sp) => {
|
||||||
self.tcx.sess.emit_err(BaseExpressionDoubleDot { span: *sp });
|
let guar =
|
||||||
Some(&*self.arena.alloc(self.expr_err(*sp)))
|
self.tcx.sess.emit_err(BaseExpressionDoubleDot { span: *sp });
|
||||||
|
Some(&*self.arena.alloc(self.expr_err(*sp, guar)))
|
||||||
}
|
}
|
||||||
StructRest::None => None,
|
StructRest::None => None,
|
||||||
};
|
};
|
||||||
|
@ -318,7 +319,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
ExprKind::Yield(opt_expr) => self.lower_expr_yield(e.span, opt_expr.as_deref()),
|
ExprKind::Yield(opt_expr) => self.lower_expr_yield(e.span, opt_expr.as_deref()),
|
||||||
ExprKind::Err => hir::ExprKind::Err,
|
ExprKind::Err => hir::ExprKind::Err(
|
||||||
|
self.tcx.sess.delay_span_bug(e.span, "lowered ExprKind::Err"),
|
||||||
|
),
|
||||||
ExprKind::Try(sub_expr) => self.lower_expr_try(e.span, sub_expr),
|
ExprKind::Try(sub_expr) => self.lower_expr_try(e.span, sub_expr),
|
||||||
|
|
||||||
ExprKind::Paren(_) | ExprKind::ForLoop(..) => unreachable!("already handled"),
|
ExprKind::Paren(_) | ExprKind::ForLoop(..) => unreachable!("already handled"),
|
||||||
|
@ -761,7 +764,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||||
self.expr_ident_mut(span, task_context_ident, task_context_hid)
|
self.expr_ident_mut(span, task_context_ident, task_context_hid)
|
||||||
} else {
|
} else {
|
||||||
// Use of `await` outside of an async context, we cannot use `task_context` here.
|
// Use of `await` outside of an async context, we cannot use `task_context` here.
|
||||||
self.expr_err(span)
|
self.expr_err(span, self.tcx.sess.delay_span_bug(span, "no task_context hir id"))
|
||||||
};
|
};
|
||||||
let new_unchecked = self.expr_call_lang_item_fn_mut(
|
let new_unchecked = self.expr_call_lang_item_fn_mut(
|
||||||
span,
|
span,
|
||||||
|
|
|
@ -102,7 +102,12 @@ fn make_count<'hir>(
|
||||||
let value = ctx.arena.alloc_from_iter([ctx.expr_usize(sp, i)]);
|
let value = ctx.arena.alloc_from_iter([ctx.expr_usize(sp, i)]);
|
||||||
ctx.expr_call_mut(sp, count_param, value)
|
ctx.expr_call_mut(sp, count_param, value)
|
||||||
} else {
|
} else {
|
||||||
ctx.expr(sp, hir::ExprKind::Err)
|
ctx.expr(
|
||||||
|
sp,
|
||||||
|
hir::ExprKind::Err(
|
||||||
|
ctx.tcx.sess.delay_span_bug(sp, "lowered bad format_args count"),
|
||||||
|
),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None => ctx.expr_lang_item_type_relative(sp, hir::LangItem::FormatCount, sym::Implied),
|
None => ctx.expr_lang_item_type_relative(sp, hir::LangItem::FormatCount, sym::Implied),
|
||||||
|
@ -135,7 +140,10 @@ fn make_format_spec<'hir>(
|
||||||
argmap.insert_full((arg_index, ArgumentType::Format(placeholder.format_trait)));
|
argmap.insert_full((arg_index, ArgumentType::Format(placeholder.format_trait)));
|
||||||
ctx.expr_usize(sp, i)
|
ctx.expr_usize(sp, i)
|
||||||
}
|
}
|
||||||
Err(_) => ctx.expr(sp, hir::ExprKind::Err),
|
Err(_) => ctx.expr(
|
||||||
|
sp,
|
||||||
|
hir::ExprKind::Err(ctx.tcx.sess.delay_span_bug(sp, "lowered bad format_args count")),
|
||||||
|
),
|
||||||
};
|
};
|
||||||
let &FormatOptions {
|
let &FormatOptions {
|
||||||
ref width,
|
ref width,
|
||||||
|
@ -294,7 +302,12 @@ fn expand_format_args<'hir>(
|
||||||
));
|
));
|
||||||
make_argument(ctx, sp, arg, ty)
|
make_argument(ctx, sp, arg, ty)
|
||||||
} else {
|
} else {
|
||||||
ctx.expr(macsp, hir::ExprKind::Err)
|
ctx.expr(
|
||||||
|
macsp,
|
||||||
|
hir::ExprKind::Err(
|
||||||
|
ctx.tcx.sess.delay_span_bug(macsp, format!("no arg at {arg_index}")),
|
||||||
|
),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
let elements: Vec<_> = arguments
|
let elements: Vec<_> = arguments
|
||||||
|
|
|
@ -7,6 +7,7 @@ use rustc_ast::ptr::P;
|
||||||
use rustc_ast::visit::AssocCtxt;
|
use rustc_ast::visit::AssocCtxt;
|
||||||
use rustc_ast::*;
|
use rustc_ast::*;
|
||||||
use rustc_data_structures::sorted_map::SortedMap;
|
use rustc_data_structures::sorted_map::SortedMap;
|
||||||
|
use rustc_errors::ErrorGuaranteed;
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def::{DefKind, Res};
|
use rustc_hir::def::{DefKind, Res};
|
||||||
use rustc_hir::def_id::{LocalDefId, CRATE_DEF_ID};
|
use rustc_hir::def_id::{LocalDefId, CRATE_DEF_ID};
|
||||||
|
@ -284,7 +285,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||||
.alloc_from_iter(fm.items.iter().map(|x| self.lower_foreign_item_ref(x))),
|
.alloc_from_iter(fm.items.iter().map(|x| self.lower_foreign_item_ref(x))),
|
||||||
},
|
},
|
||||||
ItemKind::GlobalAsm(asm) => hir::ItemKind::GlobalAsm(self.lower_inline_asm(span, asm)),
|
ItemKind::GlobalAsm(asm) => hir::ItemKind::GlobalAsm(self.lower_inline_asm(span, asm)),
|
||||||
ItemKind::TyAlias(box TyAlias { generics, where_clauses, ty: Some(ty), .. }) => {
|
ItemKind::TyAlias(box TyAlias { generics, where_clauses, ty, .. }) => {
|
||||||
// We lower
|
// We lower
|
||||||
//
|
//
|
||||||
// type Foo = impl Trait
|
// type Foo = impl Trait
|
||||||
|
@ -299,18 +300,16 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||||
&generics,
|
&generics,
|
||||||
id,
|
id,
|
||||||
&ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
|
&ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
|
||||||
|this| this.lower_ty(ty, &ImplTraitContext::TypeAliasesOpaqueTy),
|
|this| match ty {
|
||||||
);
|
None => {
|
||||||
hir::ItemKind::TyAlias(ty, generics)
|
let guar = this.tcx.sess.delay_span_bug(
|
||||||
}
|
span,
|
||||||
ItemKind::TyAlias(box TyAlias { generics, where_clauses, ty: None, .. }) => {
|
"expected to lower type alias type, but it was missing",
|
||||||
let mut generics = generics.clone();
|
);
|
||||||
add_ty_alias_where_clause(&mut generics, *where_clauses, true);
|
this.arena.alloc(this.ty(span, hir::TyKind::Err(guar)))
|
||||||
let (generics, ty) = self.lower_generics(
|
}
|
||||||
&generics,
|
Some(ty) => this.lower_ty(ty, &ImplTraitContext::TypeAliasesOpaqueTy),
|
||||||
id,
|
},
|
||||||
&ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
|
|
||||||
|this| this.arena.alloc(this.ty(span, hir::TyKind::Err)),
|
|
||||||
);
|
);
|
||||||
hir::ItemKind::TyAlias(ty, generics)
|
hir::ItemKind::TyAlias(ty, generics)
|
||||||
}
|
}
|
||||||
|
@ -798,8 +797,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Construct `ExprKind::Err` for the given `span`.
|
/// Construct `ExprKind::Err` for the given `span`.
|
||||||
pub(crate) fn expr_err(&mut self, span: Span) -> hir::Expr<'hir> {
|
pub(crate) fn expr_err(&mut self, span: Span, guar: ErrorGuaranteed) -> hir::Expr<'hir> {
|
||||||
self.expr(span, hir::ExprKind::Err)
|
self.expr(span, hir::ExprKind::Err(guar))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn lower_impl_item(&mut self, i: &AssocItem) -> &'hir hir::ImplItem<'hir> {
|
fn lower_impl_item(&mut self, i: &AssocItem) -> &'hir hir::ImplItem<'hir> {
|
||||||
|
@ -847,7 +846,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||||
&ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
|
&ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
|
||||||
|this| match ty {
|
|this| match ty {
|
||||||
None => {
|
None => {
|
||||||
let ty = this.arena.alloc(this.ty(i.span, hir::TyKind::Err));
|
let guar = this.tcx.sess.delay_span_bug(
|
||||||
|
i.span,
|
||||||
|
"expected to lower associated type, but it was missing",
|
||||||
|
);
|
||||||
|
let ty = this.arena.alloc(this.ty(i.span, hir::TyKind::Err(guar)));
|
||||||
hir::ImplItemKind::Type(ty)
|
hir::ImplItemKind::Type(ty)
|
||||||
}
|
}
|
||||||
Some(ty) => {
|
Some(ty) => {
|
||||||
|
@ -973,7 +976,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||||
fn lower_block_expr_opt(&mut self, span: Span, block: Option<&Block>) -> hir::Expr<'hir> {
|
fn lower_block_expr_opt(&mut self, span: Span, block: Option<&Block>) -> hir::Expr<'hir> {
|
||||||
match block {
|
match block {
|
||||||
Some(block) => self.lower_block_expr(block),
|
Some(block) => self.lower_block_expr(block),
|
||||||
None => self.expr_err(span),
|
None => self.expr_err(span, self.tcx.sess.delay_span_bug(span, "no block")),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -983,7 +986,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||||
&[],
|
&[],
|
||||||
match expr {
|
match expr {
|
||||||
Some(expr) => this.lower_expr_mut(expr),
|
Some(expr) => this.lower_expr_mut(expr),
|
||||||
None => this.expr_err(span),
|
None => this.expr_err(span, this.tcx.sess.delay_span_bug(span, "no block")),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
|
@ -1082,11 +1082,12 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
hir::TypeBindingKind::Constraint { bounds }
|
hir::TypeBindingKind::Constraint { bounds }
|
||||||
}
|
}
|
||||||
DesugarKind::Error(position) => {
|
DesugarKind::Error(position) => {
|
||||||
self.tcx.sess.emit_err(errors::MisplacedAssocTyBinding {
|
let guar = self.tcx.sess.emit_err(errors::MisplacedAssocTyBinding {
|
||||||
span: constraint.span,
|
span: constraint.span,
|
||||||
position: DiagnosticArgFromDisplay(position),
|
position: DiagnosticArgFromDisplay(position),
|
||||||
});
|
});
|
||||||
let err_ty = &*self.arena.alloc(self.ty(constraint.span, hir::TyKind::Err));
|
let err_ty =
|
||||||
|
&*self.arena.alloc(self.ty(constraint.span, hir::TyKind::Err(guar)));
|
||||||
hir::TypeBindingKind::Equality { term: err_ty.into() }
|
hir::TypeBindingKind::Equality { term: err_ty.into() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1255,7 +1256,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
fn lower_ty_direct(&mut self, t: &Ty, itctx: &ImplTraitContext) -> hir::Ty<'hir> {
|
fn lower_ty_direct(&mut self, t: &Ty, itctx: &ImplTraitContext) -> hir::Ty<'hir> {
|
||||||
let kind = match &t.kind {
|
let kind = match &t.kind {
|
||||||
TyKind::Infer => hir::TyKind::Infer,
|
TyKind::Infer => hir::TyKind::Infer,
|
||||||
TyKind::Err => hir::TyKind::Err,
|
TyKind::Err => {
|
||||||
|
hir::TyKind::Err(self.tcx.sess.delay_span_bug(t.span, "TyKind::Err lowered"))
|
||||||
|
}
|
||||||
TyKind::Slice(ty) => hir::TyKind::Slice(self.lower_ty(ty, itctx)),
|
TyKind::Slice(ty) => hir::TyKind::Slice(self.lower_ty(ty, itctx)),
|
||||||
TyKind::Ptr(mt) => hir::TyKind::Ptr(self.lower_mt(mt, itctx)),
|
TyKind::Ptr(mt) => hir::TyKind::Ptr(self.lower_mt(mt, itctx)),
|
||||||
TyKind::Ref(region, mt) => {
|
TyKind::Ref(region, mt) => {
|
||||||
|
@ -1381,7 +1384,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
path
|
path
|
||||||
}
|
}
|
||||||
ImplTraitContext::FeatureGated(position, feature) => {
|
ImplTraitContext::FeatureGated(position, feature) => {
|
||||||
self.tcx
|
let guar = self
|
||||||
|
.tcx
|
||||||
.sess
|
.sess
|
||||||
.create_feature_err(
|
.create_feature_err(
|
||||||
MisplacedImplTrait {
|
MisplacedImplTrait {
|
||||||
|
@ -1391,24 +1395,24 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
*feature,
|
*feature,
|
||||||
)
|
)
|
||||||
.emit();
|
.emit();
|
||||||
hir::TyKind::Err
|
hir::TyKind::Err(guar)
|
||||||
}
|
}
|
||||||
ImplTraitContext::Disallowed(position) => {
|
ImplTraitContext::Disallowed(position) => {
|
||||||
self.tcx.sess.emit_err(MisplacedImplTrait {
|
let guar = self.tcx.sess.emit_err(MisplacedImplTrait {
|
||||||
span: t.span,
|
span: t.span,
|
||||||
position: DiagnosticArgFromDisplay(position),
|
position: DiagnosticArgFromDisplay(position),
|
||||||
});
|
});
|
||||||
hir::TyKind::Err
|
hir::TyKind::Err(guar)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
TyKind::MacCall(_) => panic!("`TyKind::MacCall` should have been expanded by now"),
|
TyKind::MacCall(_) => panic!("`TyKind::MacCall` should have been expanded by now"),
|
||||||
TyKind::CVarArgs => {
|
TyKind::CVarArgs => {
|
||||||
self.tcx.sess.delay_span_bug(
|
let guar = self.tcx.sess.delay_span_bug(
|
||||||
t.span,
|
t.span,
|
||||||
"`TyKind::CVarArgs` should have been handled elsewhere",
|
"`TyKind::CVarArgs` should have been handled elsewhere",
|
||||||
);
|
);
|
||||||
hir::TyKind::Err
|
hir::TyKind::Err(guar)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -330,8 +330,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
ExprKind::Path(..) if allow_paths => {}
|
ExprKind::Path(..) if allow_paths => {}
|
||||||
ExprKind::Unary(UnOp::Neg, inner) if matches!(inner.kind, ExprKind::Lit(_)) => {}
|
ExprKind::Unary(UnOp::Neg, inner) if matches!(inner.kind, ExprKind::Lit(_)) => {}
|
||||||
_ => {
|
_ => {
|
||||||
self.tcx.sess.emit_err(ArbitraryExpressionInPattern { span: expr.span });
|
let guar = self.tcx.sess.emit_err(ArbitraryExpressionInPattern { span: expr.span });
|
||||||
return self.arena.alloc(self.expr_err(expr.span));
|
return self.arena.alloc(self.expr_err(expr.span, guar));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.lower_expr(expr)
|
self.lower_expr(expr)
|
||||||
|
|
|
@ -42,7 +42,7 @@ pub use rustc_error_messages::{
|
||||||
pub use rustc_lint_defs::{pluralize, Applicability};
|
pub use rustc_lint_defs::{pluralize, Applicability};
|
||||||
use rustc_macros::fluent_messages;
|
use rustc_macros::fluent_messages;
|
||||||
use rustc_span::source_map::SourceMap;
|
use rustc_span::source_map::SourceMap;
|
||||||
use rustc_span::HashStableContext;
|
pub use rustc_span::ErrorGuaranteed;
|
||||||
use rustc_span::{Loc, Span};
|
use rustc_span::{Loc, Span};
|
||||||
|
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
@ -1846,17 +1846,3 @@ pub enum TerminalUrl {
|
||||||
Yes,
|
Yes,
|
||||||
Auto,
|
Auto,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Useful type to use with `Result<>` indicate that an error has already
|
|
||||||
/// been reported to the user, so no need to continue checking.
|
|
||||||
#[derive(Clone, Copy, Debug, Encodable, Decodable, Hash, PartialEq, Eq, PartialOrd, Ord)]
|
|
||||||
#[derive(HashStable_Generic)]
|
|
||||||
pub struct ErrorGuaranteed(());
|
|
||||||
|
|
||||||
impl ErrorGuaranteed {
|
|
||||||
/// To be used only if you really know what you are doing... ideally, we would find a way to
|
|
||||||
/// eliminate all calls to this method.
|
|
||||||
pub fn unchecked_claim_error_was_emitted() -> Self {
|
|
||||||
ErrorGuaranteed(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -369,10 +369,10 @@ impl<'hir> GenericArgs<'hir> {
|
||||||
|
|
||||||
pub fn has_err(&self) -> bool {
|
pub fn has_err(&self) -> bool {
|
||||||
self.args.iter().any(|arg| match arg {
|
self.args.iter().any(|arg| match arg {
|
||||||
GenericArg::Type(ty) => matches!(ty.kind, TyKind::Err),
|
GenericArg::Type(ty) => matches!(ty.kind, TyKind::Err(_)),
|
||||||
_ => false,
|
_ => false,
|
||||||
}) || self.bindings.iter().any(|arg| match arg.kind {
|
}) || self.bindings.iter().any(|arg| match arg.kind {
|
||||||
TypeBindingKind::Equality { term: Term::Ty(ty) } => matches!(ty.kind, TyKind::Err),
|
TypeBindingKind::Equality { term: Term::Ty(ty) } => matches!(ty.kind, TyKind::Err(_)),
|
||||||
_ => false,
|
_ => false,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -1688,7 +1688,7 @@ impl Expr<'_> {
|
||||||
ExprKind::Struct(..) => ExprPrecedence::Struct,
|
ExprKind::Struct(..) => ExprPrecedence::Struct,
|
||||||
ExprKind::Repeat(..) => ExprPrecedence::Repeat,
|
ExprKind::Repeat(..) => ExprPrecedence::Repeat,
|
||||||
ExprKind::Yield(..) => ExprPrecedence::Yield,
|
ExprKind::Yield(..) => ExprPrecedence::Yield,
|
||||||
ExprKind::Err => ExprPrecedence::Err,
|
ExprKind::Err(_) => ExprPrecedence::Err,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1754,7 +1754,7 @@ impl Expr<'_> {
|
||||||
| ExprKind::Yield(..)
|
| ExprKind::Yield(..)
|
||||||
| ExprKind::Cast(..)
|
| ExprKind::Cast(..)
|
||||||
| ExprKind::DropTemps(..)
|
| ExprKind::DropTemps(..)
|
||||||
| ExprKind::Err => false,
|
| ExprKind::Err(_) => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1840,7 +1840,7 @@ impl Expr<'_> {
|
||||||
| ExprKind::Binary(..)
|
| ExprKind::Binary(..)
|
||||||
| ExprKind::Yield(..)
|
| ExprKind::Yield(..)
|
||||||
| ExprKind::DropTemps(..)
|
| ExprKind::DropTemps(..)
|
||||||
| ExprKind::Err => true,
|
| ExprKind::Err(_) => true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2013,7 +2013,7 @@ pub enum ExprKind<'hir> {
|
||||||
Yield(&'hir Expr<'hir>, YieldSource),
|
Yield(&'hir Expr<'hir>, YieldSource),
|
||||||
|
|
||||||
/// A placeholder for an expression that wasn't syntactically well formed in some way.
|
/// A placeholder for an expression that wasn't syntactically well formed in some way.
|
||||||
Err,
|
Err(rustc_span::ErrorGuaranteed),
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Represents an optionally `Self`-qualified value/type path or associated extension.
|
/// Represents an optionally `Self`-qualified value/type path or associated extension.
|
||||||
|
@ -2676,7 +2676,7 @@ pub enum TyKind<'hir> {
|
||||||
/// specified. This can appear anywhere in a type.
|
/// specified. This can appear anywhere in a type.
|
||||||
Infer,
|
Infer,
|
||||||
/// Placeholder for a type that has failed to be defined.
|
/// Placeholder for a type that has failed to be defined.
|
||||||
Err,
|
Err(rustc_span::ErrorGuaranteed),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, HashStable_Generic)]
|
#[derive(Debug, HashStable_Generic)]
|
||||||
|
|
|
@ -790,7 +790,7 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr<'v>)
|
||||||
ExprKind::Yield(ref subexpression, _) => {
|
ExprKind::Yield(ref subexpression, _) => {
|
||||||
visitor.visit_expr(subexpression);
|
visitor.visit_expr(subexpression);
|
||||||
}
|
}
|
||||||
ExprKind::Lit(_) | ExprKind::Err => {}
|
ExprKind::Lit(_) | ExprKind::Err(_) => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -844,7 +844,7 @@ pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty<'v>) {
|
||||||
visitor.visit_lifetime(lifetime);
|
visitor.visit_lifetime(lifetime);
|
||||||
}
|
}
|
||||||
TyKind::Typeof(ref expression) => visitor.visit_anon_const(expression),
|
TyKind::Typeof(ref expression) => visitor.visit_anon_const(expression),
|
||||||
TyKind::Infer | TyKind::Err => {}
|
TyKind::Infer | TyKind::Err(_) => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3113,7 +3113,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||||
// handled specially and will not descend into this routine.
|
// handled specially and will not descend into this routine.
|
||||||
self.ty_infer(None, ast_ty.span)
|
self.ty_infer(None, ast_ty.span)
|
||||||
}
|
}
|
||||||
hir::TyKind::Err => tcx.ty_error_misc(),
|
hir::TyKind::Err(guar) => tcx.ty_error(*guar),
|
||||||
};
|
};
|
||||||
|
|
||||||
self.record_ty(ast_ty.hir_id, result_ty, ast_ty.span);
|
self.record_ty(ast_ty.hir_id, result_ty, ast_ty.span);
|
||||||
|
|
|
@ -358,7 +358,7 @@ impl<'a> State<'a> {
|
||||||
self.print_anon_const(e);
|
self.print_anon_const(e);
|
||||||
self.word(")");
|
self.word(")");
|
||||||
}
|
}
|
||||||
hir::TyKind::Err => {
|
hir::TyKind::Err(_) => {
|
||||||
self.popen();
|
self.popen();
|
||||||
self.word("/*ERROR*/");
|
self.word("/*ERROR*/");
|
||||||
self.pclose();
|
self.pclose();
|
||||||
|
@ -1559,7 +1559,7 @@ impl<'a> State<'a> {
|
||||||
self.word_space("yield");
|
self.word_space("yield");
|
||||||
self.print_expr_maybe_paren(expr, parser::PREC_JUMP);
|
self.print_expr_maybe_paren(expr, parser::PREC_JUMP);
|
||||||
}
|
}
|
||||||
hir::ExprKind::Err => {
|
hir::ExprKind::Err(_) => {
|
||||||
self.popen();
|
self.popen();
|
||||||
self.word("/*ERROR*/");
|
self.word("/*ERROR*/");
|
||||||
self.pclose();
|
self.pclose();
|
||||||
|
|
|
@ -354,7 +354,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
ExprKind::Field(base, field) => self.check_field(expr, &base, field, expected),
|
ExprKind::Field(base, field) => self.check_field(expr, &base, field, expected),
|
||||||
ExprKind::Index(base, idx) => self.check_expr_index(base, idx, expr),
|
ExprKind::Index(base, idx) => self.check_expr_index(base, idx, expr),
|
||||||
ExprKind::Yield(value, ref src) => self.check_expr_yield(value, expr, src),
|
ExprKind::Yield(value, ref src) => self.check_expr_yield(value, expr, src),
|
||||||
hir::ExprKind::Err => tcx.ty_error_misc(),
|
hir::ExprKind::Err(guar) => tcx.ty_error(guar),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -301,7 +301,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
|
||||||
hir::ExprKind::Continue(..)
|
hir::ExprKind::Continue(..)
|
||||||
| hir::ExprKind::Lit(..)
|
| hir::ExprKind::Lit(..)
|
||||||
| hir::ExprKind::ConstBlock(..)
|
| hir::ExprKind::ConstBlock(..)
|
||||||
| hir::ExprKind::Err => {}
|
| hir::ExprKind::Err(_) => {}
|
||||||
|
|
||||||
hir::ExprKind::Loop(blk, ..) => {
|
hir::ExprKind::Loop(blk, ..) => {
|
||||||
self.walk_block(blk);
|
self.walk_block(blk);
|
||||||
|
|
|
@ -219,7 +219,7 @@ impl<'a, 'tcx> DropRangeVisitor<'a, 'tcx> {
|
||||||
| ExprKind::Struct(..)
|
| ExprKind::Struct(..)
|
||||||
| ExprKind::Repeat(..)
|
| ExprKind::Repeat(..)
|
||||||
| ExprKind::Yield(..)
|
| ExprKind::Yield(..)
|
||||||
| ExprKind::Err => (),
|
| ExprKind::Err(_) => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -483,7 +483,7 @@ impl<'a, 'tcx> Visitor<'tcx> for DropRangeVisitor<'a, 'tcx> {
|
||||||
| ExprKind::Closure { .. }
|
| ExprKind::Closure { .. }
|
||||||
| ExprKind::ConstBlock(..)
|
| ExprKind::ConstBlock(..)
|
||||||
| ExprKind::DropTemps(..)
|
| ExprKind::DropTemps(..)
|
||||||
| ExprKind::Err
|
| ExprKind::Err(_)
|
||||||
| ExprKind::Field(..)
|
| ExprKind::Field(..)
|
||||||
| ExprKind::Index(..)
|
| ExprKind::Index(..)
|
||||||
| ExprKind::InlineAsm(..)
|
| ExprKind::InlineAsm(..)
|
||||||
|
|
|
@ -383,7 +383,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
|
||||||
| hir::ExprKind::Repeat(..)
|
| hir::ExprKind::Repeat(..)
|
||||||
| hir::ExprKind::InlineAsm(..)
|
| hir::ExprKind::InlineAsm(..)
|
||||||
| hir::ExprKind::Box(..)
|
| hir::ExprKind::Box(..)
|
||||||
| hir::ExprKind::Err => Ok(self.cat_rvalue(expr.hir_id, expr.span, expr_ty)),
|
| hir::ExprKind::Err(_) => Ok(self.cat_rvalue(expr.hir_id, expr.span, expr_ty)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -758,7 +758,7 @@ impl<'tcx> Cx<'tcx> {
|
||||||
hir::ExprKind::Tup(ref fields) => ExprKind::Tuple { fields: self.mirror_exprs(fields) },
|
hir::ExprKind::Tup(ref fields) => ExprKind::Tuple { fields: self.mirror_exprs(fields) },
|
||||||
|
|
||||||
hir::ExprKind::Yield(ref v, _) => ExprKind::Yield { value: self.mirror_expr(v) },
|
hir::ExprKind::Yield(ref v, _) => ExprKind::Yield { value: self.mirror_expr(v) },
|
||||||
hir::ExprKind::Err => unreachable!(),
|
hir::ExprKind::Err(_) => unreachable!(),
|
||||||
};
|
};
|
||||||
|
|
||||||
Expr { temp_lifetime, ty: expr_ty, span: expr.span, kind }
|
Expr { temp_lifetime, ty: expr_ty, span: expr.span, kind }
|
||||||
|
|
|
@ -475,7 +475,7 @@ impl<'tcx> Visitor<'tcx> for IrMaps<'tcx> {
|
||||||
| hir::ExprKind::InlineAsm(..)
|
| hir::ExprKind::InlineAsm(..)
|
||||||
| hir::ExprKind::Box(..)
|
| hir::ExprKind::Box(..)
|
||||||
| hir::ExprKind::Type(..)
|
| hir::ExprKind::Type(..)
|
||||||
| hir::ExprKind::Err
|
| hir::ExprKind::Err(_)
|
||||||
| hir::ExprKind::Path(hir::QPath::TypeRelative(..))
|
| hir::ExprKind::Path(hir::QPath::TypeRelative(..))
|
||||||
| hir::ExprKind::Path(hir::QPath::LangItem(..)) => {
|
| hir::ExprKind::Path(hir::QPath::LangItem(..)) => {
|
||||||
intravisit::walk_expr(self, expr);
|
intravisit::walk_expr(self, expr);
|
||||||
|
@ -1129,7 +1129,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
|
||||||
|
|
||||||
hir::ExprKind::Lit(..)
|
hir::ExprKind::Lit(..)
|
||||||
| hir::ExprKind::ConstBlock(..)
|
| hir::ExprKind::ConstBlock(..)
|
||||||
| hir::ExprKind::Err
|
| hir::ExprKind::Err(_)
|
||||||
| hir::ExprKind::Path(hir::QPath::TypeRelative(..))
|
| hir::ExprKind::Path(hir::QPath::TypeRelative(..))
|
||||||
| hir::ExprKind::Path(hir::QPath::LangItem(..)) => succ,
|
| hir::ExprKind::Path(hir::QPath::LangItem(..)) => succ,
|
||||||
|
|
||||||
|
@ -1427,7 +1427,7 @@ fn check_expr<'tcx>(this: &mut Liveness<'_, 'tcx>, expr: &'tcx Expr<'tcx>) {
|
||||||
| hir::ExprKind::Yield(..)
|
| hir::ExprKind::Yield(..)
|
||||||
| hir::ExprKind::Box(..)
|
| hir::ExprKind::Box(..)
|
||||||
| hir::ExprKind::Type(..)
|
| hir::ExprKind::Type(..)
|
||||||
| hir::ExprKind::Err => {}
|
| hir::ExprKind::Err(_) => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -219,7 +219,7 @@ impl<'tcx> CheckInlineAssembly<'tcx> {
|
||||||
hir::intravisit::walk_expr(self, expr);
|
hir::intravisit::walk_expr(self, expr);
|
||||||
}
|
}
|
||||||
|
|
||||||
ExprKind::Err => {
|
ExprKind::Err(_) => {
|
||||||
self.items.push((ItemKind::Err, span));
|
self.items.push((ItemKind::Err, span));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2149,3 +2149,17 @@ where
|
||||||
Hash::hash(&len, hasher);
|
Hash::hash(&len, hasher);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Useful type to use with `Result<>` indicate that an error has already
|
||||||
|
/// been reported to the user, so no need to continue checking.
|
||||||
|
#[derive(Clone, Copy, Debug, Encodable, Decodable, Hash, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
|
#[derive(HashStable_Generic)]
|
||||||
|
pub struct ErrorGuaranteed(());
|
||||||
|
|
||||||
|
impl ErrorGuaranteed {
|
||||||
|
/// To be used only if you really know what you are doing... ideally, we would find a way to
|
||||||
|
/// eliminate all calls to this method.
|
||||||
|
pub fn unchecked_claim_error_was_emitted() -> Self {
|
||||||
|
ErrorGuaranteed(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1661,7 +1661,7 @@ pub(crate) fn clean_ty<'tcx>(ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> T
|
||||||
}
|
}
|
||||||
TyKind::BareFn(barefn) => BareFunction(Box::new(clean_bare_fn_ty(barefn, cx))),
|
TyKind::BareFn(barefn) => BareFunction(Box::new(clean_bare_fn_ty(barefn, cx))),
|
||||||
// Rustdoc handles `TyKind::Err`s by turning them into `Type::Infer`s.
|
// Rustdoc handles `TyKind::Err`s by turning them into `Type::Infer`s.
|
||||||
TyKind::Infer | TyKind::Err | TyKind::Typeof(..) => Infer,
|
TyKind::Infer | TyKind::Err(_) | TyKind::Typeof(..) => Infer,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1022,7 +1022,7 @@ fn binding_ty_auto_deref_stability<'tcx>(
|
||||||
))
|
))
|
||||||
.is_sized(cx.tcx, cx.param_env.without_caller_bounds()),
|
.is_sized(cx.tcx, cx.param_env.without_caller_bounds()),
|
||||||
),
|
),
|
||||||
TyKind::OpaqueDef(..) | TyKind::Infer | TyKind::Typeof(..) | TyKind::TraitObject(..) | TyKind::Err => {
|
TyKind::OpaqueDef(..) | TyKind::Infer | TyKind::Typeof(..) | TyKind::TraitObject(..) | TyKind::Err(_) => {
|
||||||
Position::ReborrowStable(precedence)
|
Position::ReborrowStable(precedence)
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -1038,7 +1038,7 @@ fn ty_contains_infer(ty: &hir::Ty<'_>) -> bool {
|
||||||
if self.0
|
if self.0
|
||||||
|| matches!(
|
|| matches!(
|
||||||
ty.kind,
|
ty.kind,
|
||||||
TyKind::OpaqueDef(..) | TyKind::Infer | TyKind::Typeof(_) | TyKind::Err
|
TyKind::OpaqueDef(..) | TyKind::Infer | TyKind::Typeof(_) | TyKind::Err(_)
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
self.0 = true;
|
self.0 = true;
|
||||||
|
|
|
@ -224,7 +224,7 @@ fn never_loop_expr(expr: &Expr<'_>, ignore_ids: &mut Vec<HirId>, main_loop_id: H
|
||||||
| ExprKind::Path(_)
|
| ExprKind::Path(_)
|
||||||
| ExprKind::ConstBlock(_)
|
| ExprKind::ConstBlock(_)
|
||||||
| ExprKind::Lit(_)
|
| ExprKind::Lit(_)
|
||||||
| ExprKind::Err => NeverLoopResult::Otherwise,
|
| ExprKind::Err(_) => NeverLoopResult::Otherwise,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -341,7 +341,7 @@ impl<'a, 'tcx> Visitor<'tcx> for SigDropHelper<'a, 'tcx> {
|
||||||
ExprKind::ConstBlock(_) |
|
ExprKind::ConstBlock(_) |
|
||||||
ExprKind::Continue(_) |
|
ExprKind::Continue(_) |
|
||||||
ExprKind::DropTemps(_) |
|
ExprKind::DropTemps(_) |
|
||||||
ExprKind::Err |
|
ExprKind::Err(_) |
|
||||||
ExprKind::InlineAsm(_) |
|
ExprKind::InlineAsm(_) |
|
||||||
ExprKind::Let(_) |
|
ExprKind::Let(_) |
|
||||||
ExprKind::Lit(_) |
|
ExprKind::Lit(_) |
|
||||||
|
|
|
@ -588,7 +588,7 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
ExprKind::Err => kind!("Err"),
|
ExprKind::Err(_) => kind!("Err"),
|
||||||
ExprKind::DropTemps(expr) => {
|
ExprKind::DropTemps(expr) => {
|
||||||
bind!(self, expr);
|
bind!(self, expr);
|
||||||
kind!("DropTemps({expr})");
|
kind!("DropTemps({expr})");
|
||||||
|
|
|
@ -193,7 +193,7 @@ fn expr_eagerness<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> EagernessS
|
||||||
| ExprKind::Ret(_)
|
| ExprKind::Ret(_)
|
||||||
| ExprKind::InlineAsm(_)
|
| ExprKind::InlineAsm(_)
|
||||||
| ExprKind::Yield(..)
|
| ExprKind::Yield(..)
|
||||||
| ExprKind::Err => {
|
| ExprKind::Err(_) => {
|
||||||
self.eagerness = ForceNoChange;
|
self.eagerness = ForceNoChange;
|
||||||
return;
|
return;
|
||||||
},
|
},
|
||||||
|
|
|
@ -714,7 +714,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
self.hash_pat(pat);
|
self.hash_pat(pat);
|
||||||
},
|
},
|
||||||
ExprKind::Err => {},
|
ExprKind::Err(_) => {},
|
||||||
ExprKind::Lit(ref l) => {
|
ExprKind::Lit(ref l) => {
|
||||||
l.node.hash(&mut self.s);
|
l.node.hash(&mut self.s);
|
||||||
},
|
},
|
||||||
|
@ -986,7 +986,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
|
||||||
TyKind::Typeof(anon_const) => {
|
TyKind::Typeof(anon_const) => {
|
||||||
self.hash_body(anon_const.body);
|
self.hash_body(anon_const.body);
|
||||||
},
|
},
|
||||||
TyKind::Err | TyKind::Infer | TyKind::Never => {},
|
TyKind::Err(_) | TyKind::Infer | TyKind::Never => {},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -157,7 +157,7 @@ impl<'a> Sugg<'a> {
|
||||||
| hir::ExprKind::Ret(..)
|
| hir::ExprKind::Ret(..)
|
||||||
| hir::ExprKind::Struct(..)
|
| hir::ExprKind::Struct(..)
|
||||||
| hir::ExprKind::Tup(..)
|
| hir::ExprKind::Tup(..)
|
||||||
| hir::ExprKind::Err => Sugg::NonParen(get_snippet(expr.span)),
|
| hir::ExprKind::Err(_) => Sugg::NonParen(get_snippet(expr.span)),
|
||||||
hir::ExprKind::DropTemps(inner) => Self::hir_from_snippet(inner, get_snippet),
|
hir::ExprKind::DropTemps(inner) => Self::hir_from_snippet(inner, get_snippet),
|
||||||
hir::ExprKind::Assign(lhs, rhs, _) => {
|
hir::ExprKind::Assign(lhs, rhs, _) => {
|
||||||
Sugg::BinOp(AssocOp::Assign, get_snippet(lhs.span), get_snippet(rhs.span))
|
Sugg::BinOp(AssocOp::Assign, get_snippet(lhs.span), get_snippet(rhs.span))
|
||||||
|
|
|
@ -665,7 +665,7 @@ pub fn for_each_unconsumed_temporary<'tcx, B>(
|
||||||
| ExprKind::Path(_)
|
| ExprKind::Path(_)
|
||||||
| ExprKind::Continue(_)
|
| ExprKind::Continue(_)
|
||||||
| ExprKind::InlineAsm(_)
|
| ExprKind::InlineAsm(_)
|
||||||
| ExprKind::Err => (),
|
| ExprKind::Err(_) => (),
|
||||||
}
|
}
|
||||||
ControlFlow::Continue(())
|
ControlFlow::Continue(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue