-
-
Notifications
You must be signed in to change notification settings - Fork 14.6k
rustc_resolve: improve const generic errors #152913
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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, | ||
|
|
@@ -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()); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's see if we can
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Noted. |
||
| } | ||
|
|
||
| ItemKind::Union(ident, _, ref vdata) => { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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, | ||
|
|
@@ -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(_)) | ||
| { | ||
|
|
@@ -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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is currently inactive, right?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.