From a772a6fc2ad9ab0872af238fe2e641dcf379a2cd Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Wed, 22 Feb 2023 21:19:42 +0000 Subject: [PATCH 1/3] Add ErrorGuaranteed to HIR TyKind::Err --- compiler/rustc_ast_lowering/src/item.rs | 30 ++++++++++--------- compiler/rustc_ast_lowering/src/lib.rs | 22 ++++++++------ compiler/rustc_errors/src/lib.rs | 16 +--------- compiler/rustc_hir/src/hir.rs | 6 ++-- compiler/rustc_hir/src/intravisit.rs | 2 +- .../rustc_hir_analysis/src/astconv/mod.rs | 2 +- compiler/rustc_hir_pretty/src/lib.rs | 2 +- compiler/rustc_span/src/lib.rs | 14 +++++++++ src/librustdoc/clean/mod.rs | 2 +- 9 files changed, 51 insertions(+), 45 deletions(-) diff --git a/compiler/rustc_ast_lowering/src/item.rs b/compiler/rustc_ast_lowering/src/item.rs index 4a0e005b8b902..ec57b66cd118f 100644 --- a/compiler/rustc_ast_lowering/src/item.rs +++ b/compiler/rustc_ast_lowering/src/item.rs @@ -284,7 +284,7 @@ impl<'hir> LoweringContext<'_, 'hir> { .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::TyAlias(box TyAlias { generics, where_clauses, ty: Some(ty), .. }) => { + ItemKind::TyAlias(box TyAlias { generics, where_clauses, ty, .. }) => { // We lower // // type Foo = impl Trait @@ -299,18 +299,16 @@ impl<'hir> LoweringContext<'_, 'hir> { &generics, id, &ImplTraitContext::Disallowed(ImplTraitPosition::Generic), - |this| this.lower_ty(ty, &ImplTraitContext::TypeAliasesOpaqueTy), - ); - hir::ItemKind::TyAlias(ty, generics) - } - ItemKind::TyAlias(box TyAlias { generics, where_clauses, ty: None, .. }) => { - let mut generics = generics.clone(); - add_ty_alias_where_clause(&mut generics, *where_clauses, true); - let (generics, ty) = self.lower_generics( - &generics, - id, - &ImplTraitContext::Disallowed(ImplTraitPosition::Generic), - |this| this.arena.alloc(this.ty(span, hir::TyKind::Err)), + |this| match ty { + None => { + let guar = this.tcx.sess.delay_span_bug( + span, + "expected to lower type alias type, but it was missing", + ); + this.arena.alloc(this.ty(span, hir::TyKind::Err(guar))) + } + Some(ty) => this.lower_ty(ty, &ImplTraitContext::TypeAliasesOpaqueTy), + }, ); hir::ItemKind::TyAlias(ty, generics) } @@ -847,7 +845,11 @@ impl<'hir> LoweringContext<'_, 'hir> { &ImplTraitContext::Disallowed(ImplTraitPosition::Generic), |this| match ty { 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) } Some(ty) => { diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index c5b144e68dc7e..5d78d914b6d7f 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -1082,11 +1082,12 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { hir::TypeBindingKind::Constraint { bounds } } DesugarKind::Error(position) => { - self.tcx.sess.emit_err(errors::MisplacedAssocTyBinding { + let guar = self.tcx.sess.emit_err(errors::MisplacedAssocTyBinding { span: constraint.span, 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() } } } @@ -1255,7 +1256,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { fn lower_ty_direct(&mut self, t: &Ty, itctx: &ImplTraitContext) -> hir::Ty<'hir> { let kind = match &t.kind { 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::Ptr(mt) => hir::TyKind::Ptr(self.lower_mt(mt, itctx)), TyKind::Ref(region, mt) => { @@ -1381,7 +1384,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { path } ImplTraitContext::FeatureGated(position, feature) => { - self.tcx + let guar = self + .tcx .sess .create_feature_err( MisplacedImplTrait { @@ -1391,24 +1395,24 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { *feature, ) .emit(); - hir::TyKind::Err + hir::TyKind::Err(guar) } ImplTraitContext::Disallowed(position) => { - self.tcx.sess.emit_err(MisplacedImplTrait { + let guar = self.tcx.sess.emit_err(MisplacedImplTrait { span: t.span, position: DiagnosticArgFromDisplay(position), }); - hir::TyKind::Err + hir::TyKind::Err(guar) } } } TyKind::MacCall(_) => panic!("`TyKind::MacCall` should have been expanded by now"), TyKind::CVarArgs => { - self.tcx.sess.delay_span_bug( + let guar = self.tcx.sess.delay_span_bug( t.span, "`TyKind::CVarArgs` should have been handled elsewhere", ); - hir::TyKind::Err + hir::TyKind::Err(guar) } }; diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index edec8cce92f97..18c824d8b4e66 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -42,7 +42,7 @@ pub use rustc_error_messages::{ pub use rustc_lint_defs::{pluralize, Applicability}; use rustc_macros::fluent_messages; use rustc_span::source_map::SourceMap; -use rustc_span::HashStableContext; +pub use rustc_span::ErrorGuaranteed; use rustc_span::{Loc, Span}; use std::borrow::Cow; @@ -1846,17 +1846,3 @@ pub enum TerminalUrl { Yes, 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(()) - } -} diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index 3f52f174cdf6d..db69f199aa72f 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -369,10 +369,10 @@ impl<'hir> GenericArgs<'hir> { pub fn has_err(&self) -> bool { self.args.iter().any(|arg| match arg { - GenericArg::Type(ty) => matches!(ty.kind, TyKind::Err), + GenericArg::Type(ty) => matches!(ty.kind, TyKind::Err(_)), _ => false, }) || 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, }) } @@ -2676,7 +2676,7 @@ pub enum TyKind<'hir> { /// specified. This can appear anywhere in a type. Infer, /// Placeholder for a type that has failed to be defined. - Err, + Err(rustc_span::ErrorGuaranteed), } #[derive(Debug, HashStable_Generic)] diff --git a/compiler/rustc_hir/src/intravisit.rs b/compiler/rustc_hir/src/intravisit.rs index f632babab0b24..bcd7e2e05cf9e 100644 --- a/compiler/rustc_hir/src/intravisit.rs +++ b/compiler/rustc_hir/src/intravisit.rs @@ -844,7 +844,7 @@ pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty<'v>) { visitor.visit_lifetime(lifetime); } TyKind::Typeof(ref expression) => visitor.visit_anon_const(expression), - TyKind::Infer | TyKind::Err => {} + TyKind::Infer | TyKind::Err(_) => {} } } diff --git a/compiler/rustc_hir_analysis/src/astconv/mod.rs b/compiler/rustc_hir_analysis/src/astconv/mod.rs index 43dd5b3621a6e..a15cf454df72f 100644 --- a/compiler/rustc_hir_analysis/src/astconv/mod.rs +++ b/compiler/rustc_hir_analysis/src/astconv/mod.rs @@ -3113,7 +3113,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { // handled specially and will not descend into this routine. 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); diff --git a/compiler/rustc_hir_pretty/src/lib.rs b/compiler/rustc_hir_pretty/src/lib.rs index 7dcf9d8299f14..89c2d11427332 100644 --- a/compiler/rustc_hir_pretty/src/lib.rs +++ b/compiler/rustc_hir_pretty/src/lib.rs @@ -358,7 +358,7 @@ impl<'a> State<'a> { self.print_anon_const(e); self.word(")"); } - hir::TyKind::Err => { + hir::TyKind::Err(_) => { self.popen(); self.word("/*ERROR*/"); self.pclose(); diff --git a/compiler/rustc_span/src/lib.rs b/compiler/rustc_span/src/lib.rs index e112100aa5fcd..873cd33f6a4f2 100644 --- a/compiler/rustc_span/src/lib.rs +++ b/compiler/rustc_span/src/lib.rs @@ -2149,3 +2149,17 @@ where 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(()) + } +} diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 648423e1289b9..0e8f0cfc5185d 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -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))), // 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, } } From c0e58c342092b40dcb1d6391e387b56f0edd2ef5 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Wed, 22 Feb 2023 22:40:06 +0000 Subject: [PATCH 2/3] Add ErrorGuaranteed to HIR ExprKind::Err --- compiler/rustc_ast_lowering/src/expr.rs | 19 +++++++++++-------- compiler/rustc_ast_lowering/src/format.rs | 19 ++++++++++++++++--- compiler/rustc_ast_lowering/src/item.rs | 9 +++++---- compiler/rustc_ast_lowering/src/pat.rs | 4 ++-- compiler/rustc_hir/src/hir.rs | 8 ++++---- compiler/rustc_hir/src/intravisit.rs | 2 +- compiler/rustc_hir_pretty/src/lib.rs | 2 +- compiler/rustc_hir_typeck/src/expr.rs | 2 +- .../rustc_hir_typeck/src/expr_use_visitor.rs | 2 +- .../drop_ranges/cfg_build.rs | 4 ++-- .../src/mem_categorization.rs | 2 +- compiler/rustc_mir_build/src/thir/cx/expr.rs | 2 +- compiler/rustc_passes/src/liveness.rs | 6 +++--- compiler/rustc_passes/src/naked_functions.rs | 2 +- 14 files changed, 50 insertions(+), 33 deletions(-) diff --git a/compiler/rustc_ast_lowering/src/expr.rs b/compiler/rustc_ast_lowering/src/expr.rs index dfe790b485123..d4fafe38638a4 100644 --- a/compiler/rustc_ast_lowering/src/expr.rs +++ b/compiler/rustc_ast_lowering/src/expr.rs @@ -88,8 +88,8 @@ impl<'hir> LoweringContext<'_, 'hir> { let kind = hir::ExprKind::Box(self.lower_expr(&inner)); return hir::Expr { hir_id, kind, span: self.lower_span(e.span) }; } else { - self.tcx.sess.emit_err(RustcBoxAttributeError { span: e.span }); - hir::ExprKind::Err + let guar = self.tcx.sess.emit_err(RustcBoxAttributeError { span: e.span }); + hir::ExprKind::Err(guar) } } else if let Some(legacy_args) = self.resolver.legacy_const_generic_args(f) { 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) } ExprKind::Underscore => { - self.tcx.sess.emit_err(UnderscoreExprLhsAssign { span: e.span }); - hir::ExprKind::Err + let guar = self.tcx.sess.emit_err(UnderscoreExprLhsAssign { span: e.span }); + hir::ExprKind::Err(guar) } ExprKind::Path(qself, path) => { let qpath = self.lower_qpath( @@ -299,8 +299,9 @@ impl<'hir> LoweringContext<'_, 'hir> { let rest = match &se.rest { StructRest::Base(e) => Some(self.lower_expr(e)), StructRest::Rest(sp) => { - self.tcx.sess.emit_err(BaseExpressionDoubleDot { span: *sp }); - Some(&*self.arena.alloc(self.expr_err(*sp))) + let guar = + self.tcx.sess.emit_err(BaseExpressionDoubleDot { span: *sp }); + Some(&*self.arena.alloc(self.expr_err(*sp, guar))) } 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::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::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) } else { // 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( span, diff --git a/compiler/rustc_ast_lowering/src/format.rs b/compiler/rustc_ast_lowering/src/format.rs index e7dd0b18a03b9..4095e225a8019 100644 --- a/compiler/rustc_ast_lowering/src/format.rs +++ b/compiler/rustc_ast_lowering/src/format.rs @@ -102,7 +102,12 @@ fn make_count<'hir>( let value = ctx.arena.alloc_from_iter([ctx.expr_usize(sp, i)]); ctx.expr_call_mut(sp, count_param, value) } 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), @@ -135,7 +140,10 @@ fn make_format_spec<'hir>( argmap.insert_full((arg_index, ArgumentType::Format(placeholder.format_trait))); 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 { ref width, @@ -294,7 +302,12 @@ fn expand_format_args<'hir>( )); make_argument(ctx, sp, arg, ty) } 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 diff --git a/compiler/rustc_ast_lowering/src/item.rs b/compiler/rustc_ast_lowering/src/item.rs index ec57b66cd118f..7325bce605592 100644 --- a/compiler/rustc_ast_lowering/src/item.rs +++ b/compiler/rustc_ast_lowering/src/item.rs @@ -7,6 +7,7 @@ use rustc_ast::ptr::P; use rustc_ast::visit::AssocCtxt; use rustc_ast::*; use rustc_data_structures::sorted_map::SortedMap; +use rustc_errors::ErrorGuaranteed; use rustc_hir as hir; use rustc_hir::def::{DefKind, Res}; use rustc_hir::def_id::{LocalDefId, CRATE_DEF_ID}; @@ -796,8 +797,8 @@ impl<'hir> LoweringContext<'_, 'hir> { } /// Construct `ExprKind::Err` for the given `span`. - pub(crate) fn expr_err(&mut self, span: Span) -> hir::Expr<'hir> { - self.expr(span, hir::ExprKind::Err) + pub(crate) fn expr_err(&mut self, span: Span, guar: ErrorGuaranteed) -> hir::Expr<'hir> { + self.expr(span, hir::ExprKind::Err(guar)) } fn lower_impl_item(&mut self, i: &AssocItem) -> &'hir hir::ImplItem<'hir> { @@ -975,7 +976,7 @@ impl<'hir> LoweringContext<'_, 'hir> { fn lower_block_expr_opt(&mut self, span: Span, block: Option<&Block>) -> hir::Expr<'hir> { match 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")), } } @@ -985,7 +986,7 @@ impl<'hir> LoweringContext<'_, 'hir> { &[], match 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")), }, ) }) diff --git a/compiler/rustc_ast_lowering/src/pat.rs b/compiler/rustc_ast_lowering/src/pat.rs index 06d885a45fb7d..2509b70563956 100644 --- a/compiler/rustc_ast_lowering/src/pat.rs +++ b/compiler/rustc_ast_lowering/src/pat.rs @@ -330,8 +330,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { ExprKind::Path(..) if allow_paths => {} ExprKind::Unary(UnOp::Neg, inner) if matches!(inner.kind, ExprKind::Lit(_)) => {} _ => { - self.tcx.sess.emit_err(ArbitraryExpressionInPattern { span: expr.span }); - return self.arena.alloc(self.expr_err(expr.span)); + let guar = self.tcx.sess.emit_err(ArbitraryExpressionInPattern { span: expr.span }); + return self.arena.alloc(self.expr_err(expr.span, guar)); } } self.lower_expr(expr) diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index db69f199aa72f..72e9f7c13437e 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -1688,7 +1688,7 @@ impl Expr<'_> { ExprKind::Struct(..) => ExprPrecedence::Struct, ExprKind::Repeat(..) => ExprPrecedence::Repeat, ExprKind::Yield(..) => ExprPrecedence::Yield, - ExprKind::Err => ExprPrecedence::Err, + ExprKind::Err(_) => ExprPrecedence::Err, } } @@ -1754,7 +1754,7 @@ impl Expr<'_> { | ExprKind::Yield(..) | ExprKind::Cast(..) | ExprKind::DropTemps(..) - | ExprKind::Err => false, + | ExprKind::Err(_) => false, } } @@ -1840,7 +1840,7 @@ impl Expr<'_> { | ExprKind::Binary(..) | ExprKind::Yield(..) | ExprKind::DropTemps(..) - | ExprKind::Err => true, + | ExprKind::Err(_) => true, } } @@ -2013,7 +2013,7 @@ pub enum ExprKind<'hir> { Yield(&'hir Expr<'hir>, YieldSource), /// 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. diff --git a/compiler/rustc_hir/src/intravisit.rs b/compiler/rustc_hir/src/intravisit.rs index bcd7e2e05cf9e..cc0f64017e426 100644 --- a/compiler/rustc_hir/src/intravisit.rs +++ b/compiler/rustc_hir/src/intravisit.rs @@ -790,7 +790,7 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr<'v>) ExprKind::Yield(ref subexpression, _) => { visitor.visit_expr(subexpression); } - ExprKind::Lit(_) | ExprKind::Err => {} + ExprKind::Lit(_) | ExprKind::Err(_) => {} } } diff --git a/compiler/rustc_hir_pretty/src/lib.rs b/compiler/rustc_hir_pretty/src/lib.rs index 89c2d11427332..c021fca713390 100644 --- a/compiler/rustc_hir_pretty/src/lib.rs +++ b/compiler/rustc_hir_pretty/src/lib.rs @@ -1559,7 +1559,7 @@ impl<'a> State<'a> { self.word_space("yield"); self.print_expr_maybe_paren(expr, parser::PREC_JUMP); } - hir::ExprKind::Err => { + hir::ExprKind::Err(_) => { self.popen(); self.word("/*ERROR*/"); self.pclose(); diff --git a/compiler/rustc_hir_typeck/src/expr.rs b/compiler/rustc_hir_typeck/src/expr.rs index d192d16e8df8b..7fc4ccb04ee0b 100644 --- a/compiler/rustc_hir_typeck/src/expr.rs +++ b/compiler/rustc_hir_typeck/src/expr.rs @@ -354,7 +354,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ExprKind::Field(base, field) => self.check_field(expr, &base, field, expected), ExprKind::Index(base, idx) => self.check_expr_index(base, idx, expr), 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), } } diff --git a/compiler/rustc_hir_typeck/src/expr_use_visitor.rs b/compiler/rustc_hir_typeck/src/expr_use_visitor.rs index c8cda0dc90c6d..b9a058d6bba2c 100644 --- a/compiler/rustc_hir_typeck/src/expr_use_visitor.rs +++ b/compiler/rustc_hir_typeck/src/expr_use_visitor.rs @@ -301,7 +301,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> { hir::ExprKind::Continue(..) | hir::ExprKind::Lit(..) | hir::ExprKind::ConstBlock(..) - | hir::ExprKind::Err => {} + | hir::ExprKind::Err(_) => {} hir::ExprKind::Loop(blk, ..) => { self.walk_block(blk); diff --git a/compiler/rustc_hir_typeck/src/generator_interior/drop_ranges/cfg_build.rs b/compiler/rustc_hir_typeck/src/generator_interior/drop_ranges/cfg_build.rs index adedb5b742884..7c0402b1c7fb8 100644 --- a/compiler/rustc_hir_typeck/src/generator_interior/drop_ranges/cfg_build.rs +++ b/compiler/rustc_hir_typeck/src/generator_interior/drop_ranges/cfg_build.rs @@ -219,7 +219,7 @@ impl<'a, 'tcx> DropRangeVisitor<'a, 'tcx> { | ExprKind::Struct(..) | ExprKind::Repeat(..) | ExprKind::Yield(..) - | ExprKind::Err => (), + | ExprKind::Err(_) => (), } } @@ -483,7 +483,7 @@ impl<'a, 'tcx> Visitor<'tcx> for DropRangeVisitor<'a, 'tcx> { | ExprKind::Closure { .. } | ExprKind::ConstBlock(..) | ExprKind::DropTemps(..) - | ExprKind::Err + | ExprKind::Err(_) | ExprKind::Field(..) | ExprKind::Index(..) | ExprKind::InlineAsm(..) diff --git a/compiler/rustc_hir_typeck/src/mem_categorization.rs b/compiler/rustc_hir_typeck/src/mem_categorization.rs index e50f5c77552dc..bcfc61bffb2c6 100644 --- a/compiler/rustc_hir_typeck/src/mem_categorization.rs +++ b/compiler/rustc_hir_typeck/src/mem_categorization.rs @@ -383,7 +383,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> { | hir::ExprKind::Repeat(..) | hir::ExprKind::InlineAsm(..) | 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)), } } diff --git a/compiler/rustc_mir_build/src/thir/cx/expr.rs b/compiler/rustc_mir_build/src/thir/cx/expr.rs index 3b11fc77d8982..ae203233bd568 100644 --- a/compiler/rustc_mir_build/src/thir/cx/expr.rs +++ b/compiler/rustc_mir_build/src/thir/cx/expr.rs @@ -758,7 +758,7 @@ impl<'tcx> Cx<'tcx> { 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::Err => unreachable!(), + hir::ExprKind::Err(_) => unreachable!(), }; Expr { temp_lifetime, ty: expr_ty, span: expr.span, kind } diff --git a/compiler/rustc_passes/src/liveness.rs b/compiler/rustc_passes/src/liveness.rs index 678f1815d012c..df5c8f53ec1c5 100644 --- a/compiler/rustc_passes/src/liveness.rs +++ b/compiler/rustc_passes/src/liveness.rs @@ -475,7 +475,7 @@ impl<'tcx> Visitor<'tcx> for IrMaps<'tcx> { | hir::ExprKind::InlineAsm(..) | hir::ExprKind::Box(..) | hir::ExprKind::Type(..) - | hir::ExprKind::Err + | hir::ExprKind::Err(_) | hir::ExprKind::Path(hir::QPath::TypeRelative(..)) | hir::ExprKind::Path(hir::QPath::LangItem(..)) => { intravisit::walk_expr(self, expr); @@ -1129,7 +1129,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { hir::ExprKind::Lit(..) | hir::ExprKind::ConstBlock(..) - | hir::ExprKind::Err + | hir::ExprKind::Err(_) | hir::ExprKind::Path(hir::QPath::TypeRelative(..)) | 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::Box(..) | hir::ExprKind::Type(..) - | hir::ExprKind::Err => {} + | hir::ExprKind::Err(_) => {} } } diff --git a/compiler/rustc_passes/src/naked_functions.rs b/compiler/rustc_passes/src/naked_functions.rs index acc54e7e11006..c5b5cf7f5a963 100644 --- a/compiler/rustc_passes/src/naked_functions.rs +++ b/compiler/rustc_passes/src/naked_functions.rs @@ -219,7 +219,7 @@ impl<'tcx> CheckInlineAssembly<'tcx> { hir::intravisit::walk_expr(self, expr); } - ExprKind::Err => { + ExprKind::Err(_) => { self.items.push((ItemKind::Err, span)); } } From 0f4a7d174e471814faecb94315675dbf00e5063a Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Thu, 23 Feb 2023 02:46:49 +0000 Subject: [PATCH 3/3] Make clippy happy --- src/tools/clippy/clippy_lints/src/dereference.rs | 4 ++-- src/tools/clippy/clippy_lints/src/loops/never_loop.rs | 2 +- .../clippy_lints/src/matches/significant_drop_in_scrutinee.rs | 2 +- src/tools/clippy/clippy_lints/src/utils/author.rs | 2 +- src/tools/clippy/clippy_utils/src/eager_or_lazy.rs | 2 +- src/tools/clippy/clippy_utils/src/hir_utils.rs | 4 ++-- src/tools/clippy/clippy_utils/src/sugg.rs | 2 +- src/tools/clippy/clippy_utils/src/visitors.rs | 2 +- 8 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/tools/clippy/clippy_lints/src/dereference.rs b/src/tools/clippy/clippy_lints/src/dereference.rs index ef46e23123b92..644604a2e3f84 100644 --- a/src/tools/clippy/clippy_lints/src/dereference.rs +++ b/src/tools/clippy/clippy_lints/src/dereference.rs @@ -1022,7 +1022,7 @@ fn binding_ty_auto_deref_stability<'tcx>( )) .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) }, }; @@ -1038,7 +1038,7 @@ fn ty_contains_infer(ty: &hir::Ty<'_>) -> bool { if self.0 || matches!( ty.kind, - TyKind::OpaqueDef(..) | TyKind::Infer | TyKind::Typeof(_) | TyKind::Err + TyKind::OpaqueDef(..) | TyKind::Infer | TyKind::Typeof(_) | TyKind::Err(_) ) { self.0 = true; diff --git a/src/tools/clippy/clippy_lints/src/loops/never_loop.rs b/src/tools/clippy/clippy_lints/src/loops/never_loop.rs index 14f161f510265..d7e000473124e 100644 --- a/src/tools/clippy/clippy_lints/src/loops/never_loop.rs +++ b/src/tools/clippy/clippy_lints/src/loops/never_loop.rs @@ -224,7 +224,7 @@ fn never_loop_expr(expr: &Expr<'_>, ignore_ids: &mut Vec, main_loop_id: H | ExprKind::Path(_) | ExprKind::ConstBlock(_) | ExprKind::Lit(_) - | ExprKind::Err => NeverLoopResult::Otherwise, + | ExprKind::Err(_) => NeverLoopResult::Otherwise, } } diff --git a/src/tools/clippy/clippy_lints/src/matches/significant_drop_in_scrutinee.rs b/src/tools/clippy/clippy_lints/src/matches/significant_drop_in_scrutinee.rs index f587c69f7302d..b33a247817292 100644 --- a/src/tools/clippy/clippy_lints/src/matches/significant_drop_in_scrutinee.rs +++ b/src/tools/clippy/clippy_lints/src/matches/significant_drop_in_scrutinee.rs @@ -341,7 +341,7 @@ impl<'a, 'tcx> Visitor<'tcx> for SigDropHelper<'a, 'tcx> { ExprKind::ConstBlock(_) | ExprKind::Continue(_) | ExprKind::DropTemps(_) | - ExprKind::Err | + ExprKind::Err(_) | ExprKind::InlineAsm(_) | ExprKind::Let(_) | ExprKind::Lit(_) | diff --git a/src/tools/clippy/clippy_lints/src/utils/author.rs b/src/tools/clippy/clippy_lints/src/utils/author.rs index bd7daf0773caf..c37e5bb6716e9 100644 --- a/src/tools/clippy/clippy_lints/src/utils/author.rs +++ b/src/tools/clippy/clippy_lints/src/utils/author.rs @@ -588,7 +588,7 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> { }, } }, - ExprKind::Err => kind!("Err"), + ExprKind::Err(_) => kind!("Err"), ExprKind::DropTemps(expr) => { bind!(self, expr); kind!("DropTemps({expr})"); diff --git a/src/tools/clippy/clippy_utils/src/eager_or_lazy.rs b/src/tools/clippy/clippy_utils/src/eager_or_lazy.rs index 6ff7728374f83..ee2f816f181ba 100644 --- a/src/tools/clippy/clippy_utils/src/eager_or_lazy.rs +++ b/src/tools/clippy/clippy_utils/src/eager_or_lazy.rs @@ -193,7 +193,7 @@ fn expr_eagerness<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> EagernessS | ExprKind::Ret(_) | ExprKind::InlineAsm(_) | ExprKind::Yield(..) - | ExprKind::Err => { + | ExprKind::Err(_) => { self.eagerness = ForceNoChange; return; }, diff --git a/src/tools/clippy/clippy_utils/src/hir_utils.rs b/src/tools/clippy/clippy_utils/src/hir_utils.rs index 2bbe1a19b625a..0603755f8a941 100644 --- a/src/tools/clippy/clippy_utils/src/hir_utils.rs +++ b/src/tools/clippy/clippy_utils/src/hir_utils.rs @@ -714,7 +714,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { } self.hash_pat(pat); }, - ExprKind::Err => {}, + ExprKind::Err(_) => {}, ExprKind::Lit(ref l) => { l.node.hash(&mut self.s); }, @@ -986,7 +986,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { TyKind::Typeof(anon_const) => { self.hash_body(anon_const.body); }, - TyKind::Err | TyKind::Infer | TyKind::Never => {}, + TyKind::Err(_) | TyKind::Infer | TyKind::Never => {}, } } diff --git a/src/tools/clippy/clippy_utils/src/sugg.rs b/src/tools/clippy/clippy_utils/src/sugg.rs index 78fb2e0eb7e68..11ca81cfe6c18 100644 --- a/src/tools/clippy/clippy_utils/src/sugg.rs +++ b/src/tools/clippy/clippy_utils/src/sugg.rs @@ -157,7 +157,7 @@ impl<'a> Sugg<'a> { | hir::ExprKind::Ret(..) | hir::ExprKind::Struct(..) | 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::Assign(lhs, rhs, _) => { Sugg::BinOp(AssocOp::Assign, get_snippet(lhs.span), get_snippet(rhs.span)) diff --git a/src/tools/clippy/clippy_utils/src/visitors.rs b/src/tools/clippy/clippy_utils/src/visitors.rs index 00073bcd82aff..d27a20bd4dfa7 100644 --- a/src/tools/clippy/clippy_utils/src/visitors.rs +++ b/src/tools/clippy/clippy_utils/src/visitors.rs @@ -665,7 +665,7 @@ pub fn for_each_unconsumed_temporary<'tcx, B>( | ExprKind::Path(_) | ExprKind::Continue(_) | ExprKind::InlineAsm(_) - | ExprKind::Err => (), + | ExprKind::Err(_) => (), } ControlFlow::Continue(()) }