use rustc_hir::def_id::DefId;
use rustc_hir::lang_items::LangItem;
use rustc_hir::{Item, ItemKind, Node};
+use rustc_middle::dep_graph::DepContext;
use rustc_middle::ty::error::TypeError;
use rustc_middle::ty::{
self,
}
fn path_crate(self, cnum: CrateNum) -> Result<Self::Path, Self::Error> {
- Ok(vec![self.tcx.original_crate_name(cnum).to_string()])
+ Ok(vec![self.tcx.crate_name(cnum).to_string()])
}
fn path_qualified(
self,
match (&terr, expected == found) {
(TypeError::Sorts(values), extra) => {
let sort_string = |ty: Ty<'tcx>| match (extra, ty.kind()) {
- (true, ty::Opaque(def_id, _)) => format!(
- " (opaque type at {})",
- self.tcx
+ (true, ty::Opaque(def_id, _)) => {
+ let pos = self
+ .tcx
.sess
.source_map()
- .mk_substr_filename(self.tcx.def_span(*def_id)),
- ),
+ .lookup_char_pos(self.tcx.def_span(*def_id).lo());
+ format!(
+ " (opaque type at <{}:{}:{}>)",
+ pos.file.name.prefer_local(),
+ pos.line,
+ pos.col.to_usize() + 1,
+ )
+ }
(true, _) => format!(" ({})", ty.sort_string(self.tcx)),
(false, _) => "".to_string(),
};
struct_span_err!(self.tcx.sess, span, E0580, "{}", failure_str)
}
FailureCode::Error0308(failure_str) => {
- struct_span_err!(self.tcx.sess, span, E0308, "{}", failure_str)
+ let mut err = struct_span_err!(self.tcx.sess, span, E0308, "{}", failure_str);
+ if let ValuePairs::Types(ty::error::ExpectedFound { expected, found }) =
+ trace.values
+ {
+ // If a tuple of length one was expected and the found expression has
+ // parentheses around it, perhaps the user meant to write `(expr,)` to
+ // build a tuple (issue #86100)
+ match (expected.kind(), found.kind()) {
+ (ty::Tuple(_), ty::Tuple(_)) => {}
+ (ty::Tuple(_), _) if expected.tuple_fields().count() == 1 => {
+ if let Ok(code) = self.tcx.sess().source_map().span_to_snippet(span) {
+ if let Some(code) =
+ code.strip_prefix('(').and_then(|s| s.strip_suffix(')'))
+ {
+ err.span_suggestion(
+ span,
+ "use a trailing comma to create a tuple with one element",
+ format!("({},)", code),
+ Applicability::MaybeIncorrect,
+ );
+ }
+ }
+ }
+ _ => {}
+ }
+ }
+ err
}
FailureCode::Error0644(failure_str) => {
struct_span_err!(self.tcx.sess, span, E0644, "{}", failure_str)
self.tcx.associated_item(def_id).ident
),
infer::EarlyBoundRegion(_, name) => format!(" for lifetime parameter `{}`", name),
- infer::BoundRegionInCoherence(name) => {
- format!(" for lifetime parameter `{}` in coherence check", name)
- }
infer::UpvarRegion(ref upvar_id, _) => {
let var_name = self.tcx.hir().name(upvar_id.var_path.hir_id);
format!(" for capture of `{}` by closure", var_name)