1
Fork 0
This commit is contained in:
bjorn3 2025-02-08 22:12:13 +00:00
parent 3183b44a1e
commit 1fcae03369
287 changed files with 5888 additions and 4608 deletions

View file

@ -567,10 +567,13 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
Some(rename) => source.ident.span.to(rename.span),
None => source.ident.span,
};
self.r.report_error(span, ResolutionError::SelfImportsOnlyAllowedWithin {
root: parent.is_none(),
span_with_rename,
});
self.r.report_error(
span,
ResolutionError::SelfImportsOnlyAllowedWithin {
root: parent.is_none(),
span_with_rename,
},
);
// Error recovery: replace `use foo::self;` with `use foo;`
if let Some(parent) = module_path.pop() {

View file

@ -95,11 +95,14 @@ impl<'a, 'ra, 'tcx> DefCollector<'a, 'ra, 'tcx> {
fn visit_macro_invoc(&mut self, id: NodeId) {
let id = id.placeholder_to_expn_id();
let old_parent = self.resolver.invocation_parents.insert(id, InvocationParent {
parent_def: self.parent_def,
impl_trait_context: self.impl_trait_context,
in_attr: self.in_attr,
});
let old_parent = self.resolver.invocation_parents.insert(
id,
InvocationParent {
parent_def: self.parent_def,
impl_trait_context: self.impl_trait_context,
in_attr: self.in_attr,
},
);
assert!(old_parent.is_none(), "parent `LocalDefId` is reset for an invocation");
}
}

View file

@ -990,14 +990,10 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
VisResolutionError::AncestorOnly(span) => {
self.dcx().create_err(errs::AncestorOnly(span))
}
VisResolutionError::FailedToResolve(span, label, suggestion) => {
self.into_struct_error(span, ResolutionError::FailedToResolve {
segment: None,
label,
suggestion,
module: None,
})
}
VisResolutionError::FailedToResolve(span, label, suggestion) => self.into_struct_error(
span,
ResolutionError::FailedToResolve { segment: None, label, suggestion, module: None },
),
VisResolutionError::ExpectedFound(span, path_str, res) => {
self.dcx().create_err(errs::ExpectedModuleFound { span, res, path_str })
}

View file

@ -1181,21 +1181,25 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
}
Some(_) => None,
};
(rib_ident.span, AttemptToUseNonConstantValueInConstant {
ident: original_rib_ident_def,
suggestion: "const",
current: "let",
type_span,
})
(
rib_ident.span,
AttemptToUseNonConstantValueInConstant {
ident: original_rib_ident_def,
suggestion: "const",
current: "let",
type_span,
},
)
}
Some((ident, kind)) => {
(span, AttemptToUseNonConstantValueInConstant {
Some((ident, kind)) => (
span,
AttemptToUseNonConstantValueInConstant {
ident,
suggestion: "let",
current: kind.as_str(),
type_span: None,
})
}
},
),
};
self.report_error(span, resolution_error);
}
@ -1203,10 +1207,13 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
}
RibKind::ConstParamTy => {
if let Some(span) = finalize {
self.report_error(span, ParamInTyOfConstParam {
name: rib_ident.name,
param_kind: None,
});
self.report_error(
span,
ParamInTyOfConstParam {
name: rib_ident.name,
param_kind: None,
},
);
}
return Res::Err;
}
@ -1287,10 +1294,13 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
}
RibKind::ConstParamTy => {
if let Some(span) = finalize {
self.report_error(span, ResolutionError::ParamInTyOfConstParam {
name: rib_ident.name,
param_kind: Some(errors::ParamKindInTyOfConstParam::Type),
});
self.report_error(
span,
ResolutionError::ParamInTyOfConstParam {
name: rib_ident.name,
param_kind: Some(errors::ParamKindInTyOfConstParam::Type),
},
);
}
return Res::Err;
}
@ -1353,10 +1363,13 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
}
RibKind::ConstParamTy => {
if let Some(span) = finalize {
self.report_error(span, ResolutionError::ParamInTyOfConstParam {
name: rib_ident.name,
param_kind: Some(errors::ParamKindInTyOfConstParam::Const),
});
self.report_error(
span,
ResolutionError::ParamInTyOfConstParam {
name: rib_ident.name,
param_kind: Some(errors::ParamKindInTyOfConstParam::Const),
},
);
}
return Res::Err;
}

View file

@ -914,12 +914,15 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
} => {
if no_ambiguity {
assert!(import.imported_module.get().is_none());
self.report_error(span, ResolutionError::FailedToResolve {
segment: Some(segment_name),
label,
suggestion,
module,
});
self.report_error(
span,
ResolutionError::FailedToResolve {
segment: Some(segment_name),
label,
suggestion,
module,
},
);
}
return None;
}

View file

@ -1823,9 +1823,11 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
&& Some(true) == self.diag_metadata.in_non_gat_assoc_type
&& let crate::ModuleKind::Def(DefKind::Trait, trait_id, _) = module.kind
{
if def_id_matches_path(self.r.tcx, trait_id, &[
"core", "iter", "traits", "iterator", "Iterator",
]) {
if def_id_matches_path(
self.r.tcx,
trait_id,
&["core", "iter", "traits", "iterator", "Iterator"],
) {
self.r.dcx().emit_err(errors::LendingIteratorReportError {
lifetime: lifetime.ident.span,
ty: ty.span,
@ -3425,11 +3427,14 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
match seen_trait_items.entry(id_in_trait) {
Entry::Occupied(entry) => {
self.report_error(span, ResolutionError::TraitImplDuplicate {
name: ident,
old_span: *entry.get(),
trait_item_span: binding.span,
});
self.report_error(
span,
ResolutionError::TraitImplDuplicate {
name: ident,
old_span: *entry.get(),
trait_item_span: binding.span,
},
);
return;
}
Entry::Vacant(entry) => {
@ -3460,13 +3465,16 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
}
};
let trait_path = path_names_to_string(path);
self.report_error(span, ResolutionError::TraitImplMismatch {
name: ident,
kind,
code,
trait_path,
trait_item_span: binding.span,
});
self.report_error(
span,
ResolutionError::TraitImplMismatch {
name: ident,
kind,
code,
trait_path,
trait_item_span: binding.span,
},
);
}
fn resolve_const_body(&mut self, expr: &'ast Expr, item: Option<(Ident, ConstantItemKind)>) {
@ -3845,10 +3853,13 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
.patterns_with_skipped_bindings
.entry(def_id)
.or_default()
.push((pat.span, match rest {
ast::PatFieldsRest::Recovered(guar) => Err(*guar),
_ => Ok(()),
}));
.push((
pat.span,
match rest {
ast::PatFieldsRest::Recovered(guar) => Err(*guar),
_ => Ok(()),
},
));
}
}
ast::PatFieldsRest::None => {}
@ -4485,12 +4496,15 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
segment_name,
error_implied_by_parse_error: _,
} => {
return Err(respan(span, ResolutionError::FailedToResolve {
segment: Some(segment_name),
label,
suggestion,
module,
}));
return Err(respan(
span,
ResolutionError::FailedToResolve {
segment: Some(segment_name),
label,
suggestion,
module,
},
));
}
PathResult::Module(..) | PathResult::Failed { .. } => return Ok(None),
PathResult::Indeterminate => bug!("indeterminate path result in resolve_qpath"),

View file

@ -1048,12 +1048,15 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
debug!("smart_resolve_path_fragment: E0424, source={:?}", source);
err.code(E0424);
err.span_label(span, match source {
PathSource::Pat => {
"`self` value is a keyword and may not be bound to variables or shadowed"
}
_ => "`self` value is a keyword only available in methods with a `self` parameter",
});
err.span_label(
span,
match source {
PathSource::Pat => {
"`self` value is a keyword and may not be bound to variables or shadowed"
}
_ => "`self` value is a keyword only available in methods with a `self` parameter",
},
);
let is_assoc_fn = self.self_type_is_available();
let self_from_macro = "a `self` parameter, but a macro invocation can only \
access identifiers it receives from parameters";
@ -2399,15 +2402,18 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
if module_def_id == def_id {
let path =
Path { span: name_binding.span, segments: path_segments, tokens: None };
result = Some((module, ImportSuggestion {
did: Some(def_id),
descr: "module",
path,
accessible: true,
doc_visible,
note: None,
via_import: false,
}));
result = Some((
module,
ImportSuggestion {
did: Some(def_id),
descr: "module",
path,
accessible: true,
doc_visible,
note: None,
via_import: false,
},
));
} else {
// add the module to the lookup
if seen_modules.insert(module_def_id) {

View file

@ -888,12 +888,15 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
None,
)
};
self.report_error(span, ResolutionError::FailedToResolve {
segment: path.last().map(|segment| segment.ident.name),
label,
suggestion,
module,
});
self.report_error(
span,
ResolutionError::FailedToResolve {
segment: path.last().map(|segment| segment.ident.name),
label,
suggestion,
module,
},
);
}
PathResult::Module(..) | PathResult::Indeterminate => unreachable!(),
}