Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion compiler/rustc_resolve/src/build_reduced_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -898,7 +898,7 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
}

// These items live in both the type and value namespaces.
ItemKind::Struct(ident, _, ref vdata) => {
ItemKind::Struct(ident, ref generics, ref vdata) => {
self.build_reduced_graph_for_struct_variant(
vdata.fields(),
ident,
Expand Down Expand Up @@ -947,6 +947,7 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
.struct_constructors
.insert(local_def_id, (ctor_res, ctor_vis.to_def_id(), ret_fields));
}
self.r.struct_generics.insert(local_def_id, generics.clone());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's see if we can struct_generics store references. That should keep mem usage to a minimum.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted.

}

ItemKind::Union(ident, _, ref vdata) => {
Expand Down
14 changes: 14 additions & 0 deletions compiler/rustc_resolve/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -882,6 +882,20 @@ pub(crate) struct UnexpectedResChangeTyToConstParamSugg {
pub applicability: Applicability,
}

#[derive(Subdiagnostic)]
#[suggestion(
"you might have meant to introduce a const parameter on the `{$item_name}`",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"you might have meant to introduce a const parameter on the `{$item_name}`",
"you might have meant to introduce a const parameter on `{$item_name}`",

code = "{snippet}",
applicability = "machine-applicable",
style = "verbose"
)]
pub(crate) struct UnexpectedMissingConstParameter {
#[primary_span]
pub span: Span,
pub snippet: String,
pub item_name: String,
}

#[derive(Subdiagnostic)]
#[multipart_suggestion(
"you might have meant to write a const parameter here",
Expand Down
27 changes: 18 additions & 9 deletions compiler/rustc_resolve/src/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4426,7 +4426,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
let Finalize { node_id, path_span, .. } = finalize;
let report_errors = |this: &mut Self, res: Option<Res>| {
if this.should_report_errs() {
let (err, candidates) = this.smart_resolve_report_errors(
let (mut err, candidates) = this.smart_resolve_report_errors(
path,
None,
path_span,
Expand All @@ -4437,7 +4437,8 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {

let def_id = this.parent_scope.module.nearest_parent_mod();
let instead = res.is_some();
let suggestion = if let Some((start, end)) = this.diag_metadata.in_range
let (suggestion, const_err) = if let Some((start, end)) =
this.diag_metadata.in_range
&& path[0].ident.span.lo() == end.span.lo()
&& !matches!(start.kind, ExprKind::Lit(_))
{
Expand All @@ -4449,22 +4450,30 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
span = span.with_lo(span.lo() + BytePos(1));
sugg = "";
}
Some((
span,
"you might have meant to write `.` instead of `..`",
sugg.to_string(),
Applicability::MaybeIncorrect,
))
(
Some((
span,
"you might have meant to write `.` instead of `..`",
sugg.to_string(),
Applicability::MaybeIncorrect,
)),
None,
)
} else if res.is_none()
&& let PathSource::Type
| PathSource::Expr(_)
| PathSource::PreciseCapturingArg(..) = source
{
this.suggest_adding_generic_parameter(path, source)
} else {
None
(None, None)
};

if let Some(const_err) = const_err {
err.cancel();
err = const_err;
}
Comment on lines +4472 to +4475
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is currently inactive, right? const_err isn't None anywhere right now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const_err is actually always None except in the case of where we add the error we just introduce see it here -> https://github.com/rust-lang/rust/pull/152913/changes#diff-2c81e6d8048a31a3ce43f30181aaa037e0ad0076e7aee67792ca993f28c75ac3R3440-R3441

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is to prevent the type error from showing up.


let ue = UseError {
err,
candidates,
Expand Down
Loading
Loading