Rip it out

My type ascription
Oh rip it out
Ah
If you think we live too much then
You can sacrifice diagnostics
Don't mix your garbage
Into my syntax
So many weird hacks keep diagnostics alive
Yet I don't even step outside
So many bad diagnostics keep tyasc alive
Yet tyasc doesn't even bother to survive!
This commit is contained in:
Nilstrieb 2022-11-16 21:46:06 +01:00 committed by yukang
parent 2034b6d23c
commit c63b6a437e
97 changed files with 951 additions and 954 deletions

View file

@ -777,6 +777,10 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
.sess
.create_err(errs::SelfImportOnlyInImportListWithNonEmptyPrefix { span }),
ResolutionError::FailedToResolve { label, suggestion } => {
if label.len() > 0 {
//panic!("debug now");
}
let mut err =
struct_span_err!(self.tcx.sess, span, E0433, "failed to resolve: {}", &label);
err.span_label(span, label);

View file

@ -1345,7 +1345,13 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
ribs: Option<&PerNS<Vec<Rib<'a>>>>,
ignore_binding: Option<&'a NameBinding<'a>>,
) -> PathResult<'a> {
debug!("resolve_path(path={:?}, opt_ns={:?}, finalize={:?})", path, opt_ns, finalize);
debug!(
"resolve_path(path={:?}, opt_ns={:?}, finalize={:?}) path_len: {}",
path,
opt_ns,
finalize,
path.len()
);
let mut module = None;
let mut allow_super = true;

View file

@ -1264,14 +1264,15 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
opt_ns: Option<Namespace>, // `None` indicates a module path in import
finalize: Option<Finalize>,
) -> PathResult<'a> {
self.r.resolve_path_with_ribs(
let res = self.r.resolve_path_with_ribs(
path,
opt_ns,
&self.parent_scope,
finalize,
Some(&self.ribs),
None,
)
);
res
}
// AST resolution
@ -3488,10 +3489,6 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
//
// Similar thing, for types, happens in `report_errors` above.
let report_errors_for_call = |this: &mut Self, parent_err: Spanned<ResolutionError<'a>>| {
if !source.is_call() {
return Some(parent_err);
}
// Before we start looking for candidates, we have to get our hands
// on the type user is trying to perform invocation on; basically:
// we're transforming `HashMap::new` into just `HashMap`.
@ -3721,6 +3718,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
}
/// Handles paths that may refer to associated items.
#[instrument(level = "debug", skip(self))]
fn resolve_qpath(
&mut self,
qself: &Option<P<QSelf>>,
@ -3728,11 +3726,6 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
ns: Namespace,
finalize: Finalize,
) -> Result<Option<PartialRes>, Spanned<ResolutionError<'a>>> {
debug!(
"resolve_qpath(qself={:?}, path={:?}, ns={:?}, finalize={:?})",
qself, path, ns, finalize,
);
if let Some(qself) = qself {
if qself.position == 0 {
// This is a case like `<T>::B`, where there is no

View file

@ -305,6 +305,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
/// Handles error reporting for `smart_resolve_path_fragment` function.
/// Creates base error and amends it with one short label and possibly some longer helps/notes.
#[instrument(level = "debug", skip(self))]
pub(crate) fn smart_resolve_report_errors(
&mut self,
path: &[Segment],
@ -350,7 +351,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
return (err, candidates);
}
if !self.type_ascription_suggestion(&mut err, base_error.span) {
if !self.suggest_missing_let(&mut err, base_error.span) {
let mut fallback =
self.suggest_trait_and_bounds(&mut err, source, res, span, &base_error);
@ -1823,7 +1824,8 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
start.to(sm.next_point(start))
}
fn type_ascription_suggestion(&self, err: &mut Diagnostic, base_span: Span) -> bool {
#[instrument(level = "debug", skip(self, err))]
fn suggest_missing_let(&self, err: &mut Diagnostic, base_span: Span) -> bool {
let sm = self.r.tcx.sess.source_map();
let base_snippet = sm.span_to_snippet(base_span);
if let Some(&sp) = self.diagnostic_metadata.current_type_ascription.last() {
@ -1878,12 +1880,6 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
}
}
}
if show_label {
err.span_label(
base_span,
"expecting a type here because of type ascription",
);
}
return show_label;
}
}