diff options
Diffstat (limited to 'compiler/rustc_middle/src')
| -rw-r--r-- | compiler/rustc_middle/src/hir/map/mod.rs | 4 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/thir.rs | 7 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/traits/select.rs | 4 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/ty/_match.rs | 4 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/ty/error.rs | 14 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/ty/mod.rs | 6 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/ty/print/pretty.rs | 18 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/ty/relate.rs | 2 |
8 files changed, 47 insertions, 12 deletions
diff --git a/compiler/rustc_middle/src/hir/map/mod.rs b/compiler/rustc_middle/src/hir/map/mod.rs index 883554f959c..48bae7a2d4e 100644 --- a/compiler/rustc_middle/src/hir/map/mod.rs +++ b/compiler/rustc_middle/src/hir/map/mod.rs @@ -485,7 +485,9 @@ impl<'hir> Map<'hir> { BodyOwnerKind::Static(mt) => ConstContext::Static(mt), BodyOwnerKind::Fn if self.tcx.is_constructor(def_id.to_def_id()) => return None, - BodyOwnerKind::Fn if self.tcx.is_const_fn_raw(def_id.to_def_id()) => { + BodyOwnerKind::Fn | BodyOwnerKind::Closure + if self.tcx.is_const_fn_raw(def_id.to_def_id()) => + { ConstContext::ConstFn } BodyOwnerKind::Fn if self.tcx.is_const_default_method(def_id.to_def_id()) => { diff --git a/compiler/rustc_middle/src/thir.rs b/compiler/rustc_middle/src/thir.rs index ac903010c8d..5f320708c84 100644 --- a/compiler/rustc_middle/src/thir.rs +++ b/compiler/rustc_middle/src/thir.rs @@ -9,6 +9,7 @@ //! [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/thir.html use rustc_ast::{InlineAsmOptions, InlineAsmTemplatePiece}; +use rustc_errors::{DiagnosticArgValue, IntoDiagnosticArg}; use rustc_hir as hir; use rustc_hir::def_id::DefId; use rustc_hir::RangeEnd; @@ -575,6 +576,12 @@ impl<'tcx> Pat<'tcx> { } } +impl<'tcx> IntoDiagnosticArg for Pat<'tcx> { + fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> { + format!("{}", self).into_diagnostic_arg() + } +} + #[derive(Clone, Debug, HashStable)] pub struct Ascription<'tcx> { pub annotation: CanonicalUserTypeAnnotation<'tcx>, diff --git a/compiler/rustc_middle/src/traits/select.rs b/compiler/rustc_middle/src/traits/select.rs index ec69864c951..1cc9fd526b4 100644 --- a/compiler/rustc_middle/src/traits/select.rs +++ b/compiler/rustc_middle/src/traits/select.rs @@ -131,7 +131,9 @@ pub enum SelectionCandidate<'tcx> { /// Implementation of a `Fn`-family trait by one of the anonymous types /// generated for an `||` expression. - ClosureCandidate, + ClosureCandidate { + is_const: bool, + }, /// Implementation of a `Generator` trait by one of the anonymous types /// generated for a generator. diff --git a/compiler/rustc_middle/src/ty/_match.rs b/compiler/rustc_middle/src/ty/_match.rs index cd147d7e558..b9c5a4e0d0d 100644 --- a/compiler/rustc_middle/src/ty/_match.rs +++ b/compiler/rustc_middle/src/ty/_match.rs @@ -89,7 +89,9 @@ impl<'tcx> TypeRelation<'tcx> for Match<'tcx> { Err(TypeError::Sorts(relate::expected_found(self, a, b))) } - (&ty::Error(_), _) | (_, &ty::Error(_)) => Ok(self.tcx().ty_error()), + (&ty::Error(guar), _) | (_, &ty::Error(guar)) => { + Ok(self.tcx().ty_error_with_guaranteed(guar)) + } _ => relate::super_relate_tys(self, a, b), } diff --git a/compiler/rustc_middle/src/ty/error.rs b/compiler/rustc_middle/src/ty/error.rs index 50554cf9a82..5d394f71f0d 100644 --- a/compiler/rustc_middle/src/ty/error.rs +++ b/compiler/rustc_middle/src/ty/error.rs @@ -2,10 +2,10 @@ use crate::traits::{ObligationCause, ObligationCauseCode}; use crate::ty::diagnostics::suggest_constraining_type_param; use crate::ty::print::{with_forced_trimmed_paths, FmtPrinter, Printer}; use crate::ty::{self, BoundRegionKind, Region, Ty, TyCtxt}; -use hir::def::DefKind; use rustc_errors::Applicability::{MachineApplicable, MaybeIncorrect}; use rustc_errors::{pluralize, Diagnostic, MultiSpan}; use rustc_hir as hir; +use rustc_hir::def::{CtorOf, DefKind}; use rustc_hir::def_id::DefId; use rustc_span::symbol::{sym, Symbol}; use rustc_span::{BytePos, Span}; @@ -319,7 +319,11 @@ impl<'tcx> Ty<'tcx> { .into() } } - ty::FnDef(..) => "fn item".into(), + ty::FnDef(def_id, ..) => match tcx.def_kind(def_id) { + DefKind::Ctor(CtorOf::Struct, _) => "struct constructor".into(), + DefKind::Ctor(CtorOf::Variant, _) => "enum constructor".into(), + _ => "fn item".into(), + }, ty::FnPtr(_) => "fn pointer".into(), ty::Dynamic(ref inner, ..) if let Some(principal) = inner.principal() => { format!("trait object `dyn {}`", tcx.def_path_str(principal.def_id())).into() @@ -366,7 +370,11 @@ impl<'tcx> Ty<'tcx> { _ => "reference", } .into(), - ty::FnDef(..) => "fn item".into(), + ty::FnDef(def_id, ..) => match tcx.def_kind(def_id) { + DefKind::Ctor(CtorOf::Struct, _) => "struct constructor".into(), + DefKind::Ctor(CtorOf::Variant, _) => "enum constructor".into(), + _ => "fn item".into(), + }, ty::FnPtr(_) => "fn pointer".into(), ty::Dynamic(..) => "trait object".into(), ty::Closure(..) => "closure".into(), diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index fa571d480b6..993e95b3514 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -2465,8 +2465,10 @@ impl<'tcx> TyCtxt<'tcx> { #[inline] pub fn is_const_fn_raw(self, def_id: DefId) -> bool { - matches!(self.def_kind(def_id), DefKind::Fn | DefKind::AssocFn | DefKind::Ctor(..)) - && self.constness(def_id) == hir::Constness::Const + matches!( + self.def_kind(def_id), + DefKind::Fn | DefKind::AssocFn | DefKind::Ctor(..) | DefKind::Closure + ) && self.constness(def_id) == hir::Constness::Const } #[inline] diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index c49e75d68ad..a91e8de5f21 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -283,6 +283,8 @@ pub trait PrettyPrinter<'tcx>: /// This is typically the case for all non-`'_` regions. fn should_print_region(&self, region: ty::Region<'tcx>) -> bool; + fn reset_type_limit(&mut self) {} + // Defaults (should not be overridden): /// If possible, this returns a global path resolving to `def_id` that is visible @@ -1981,6 +1983,10 @@ impl<'tcx> PrettyPrinter<'tcx> for FmtPrinter<'_, 'tcx> { self.0.ty_infer_name_resolver.as_ref().and_then(|func| func(id)) } + fn reset_type_limit(&mut self) { + self.printed_type_count = 0; + } + fn const_infer_name(&self, id: ty::ConstVid<'tcx>) -> Option<Symbol> { self.0.const_infer_name_resolver.as_ref().and_then(|func| func(id)) } @@ -2722,11 +2728,15 @@ define_print_and_forward_display! { } ty::SubtypePredicate<'tcx> { - p!(print(self.a), " <: ", print(self.b)) + p!(print(self.a), " <: "); + cx.reset_type_limit(); + p!(print(self.b)) } ty::CoercePredicate<'tcx> { - p!(print(self.a), " -> ", print(self.b)) + p!(print(self.a), " -> "); + cx.reset_type_limit(); + p!(print(self.b)) } ty::TraitPredicate<'tcx> { @@ -2738,7 +2748,9 @@ define_print_and_forward_display! { } ty::ProjectionPredicate<'tcx> { - p!(print(self.projection_ty), " == ", print(self.term)) + p!(print(self.projection_ty), " == "); + cx.reset_type_limit(); + p!(print(self.term)) } ty::Term<'tcx> { diff --git a/compiler/rustc_middle/src/ty/relate.rs b/compiler/rustc_middle/src/ty/relate.rs index 4d34ca3d66b..65fd8d9753d 100644 --- a/compiler/rustc_middle/src/ty/relate.rs +++ b/compiler/rustc_middle/src/ty/relate.rs @@ -414,7 +414,7 @@ pub fn super_relate_tys<'tcx, R: TypeRelation<'tcx>>( bug!("bound types encountered in super_relate_tys") } - (&ty::Error(_), _) | (_, &ty::Error(_)) => Ok(tcx.ty_error()), + (&ty::Error(guar), _) | (_, &ty::Error(guar)) => Ok(tcx.ty_error_with_guaranteed(guar)), (&ty::Never, _) | (&ty::Char, _) |
