-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Label struct/enum constructor
instead of fn item
, mention that it should be called on type mismatch
#106524
Merged
Merged
Label struct/enum constructor
instead of fn item
, mention that it should be called on type mismatch
#106524
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,10 +2,10 @@ use crate::traits::{ObligationCause, ObligationCauseCode}; | |
use crate::ty::diagnostics::suggest_constraining_type_param; | ||
use crate::ty::print::{with_forced_trimmed_paths, FmtPrinter, Printer}; | ||
use crate::ty::{self, BoundRegionKind, Region, Ty, TyCtxt}; | ||
use hir::def::DefKind; | ||
use rustc_errors::Applicability::{MachineApplicable, MaybeIncorrect}; | ||
use rustc_errors::{pluralize, Diagnostic, MultiSpan}; | ||
use rustc_hir as hir; | ||
use rustc_hir::def::{CtorOf, DefKind}; | ||
use rustc_hir::def_id::DefId; | ||
use rustc_span::symbol::{sym, Symbol}; | ||
use rustc_span::{BytePos, Span}; | ||
|
@@ -319,7 +319,11 @@ impl<'tcx> Ty<'tcx> { | |
.into() | ||
} | ||
} | ||
ty::FnDef(..) => "fn item".into(), | ||
ty::FnDef(def_id, ..) => match tcx.def_kind(def_id) { | ||
DefKind::Ctor(CtorOf::Struct, _) => "struct constructor".into(), | ||
DefKind::Ctor(CtorOf::Variant, _) => "enum constructor".into(), | ||
_ => "fn item".into(), | ||
}, | ||
ty::FnPtr(_) => "fn pointer".into(), | ||
ty::Dynamic(ref inner, ..) if let Some(principal) = inner.principal() => { | ||
format!("trait object `dyn {}`", tcx.def_path_str(principal.def_id())).into() | ||
|
@@ -366,7 +370,11 @@ impl<'tcx> Ty<'tcx> { | |
_ => "reference", | ||
} | ||
.into(), | ||
ty::FnDef(..) => "fn item".into(), | ||
ty::FnDef(def_id, ..) => match tcx.def_kind(def_id) { | ||
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. Likewise. |
||
DefKind::Ctor(CtorOf::Struct, _) => "struct constructor".into(), | ||
DefKind::Ctor(CtorOf::Variant, _) => "enum constructor".into(), | ||
_ => "fn item".into(), | ||
}, | ||
ty::FnPtr(_) => "fn pointer".into(), | ||
ty::Dynamic(..) => "trait object".into(), | ||
ty::Closure(..) => "closure".into(), | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use the existing
descr
method? The output is a bit different, but also more uniform with other diags.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly because descr is pretty verbose here.. I didn't like how it sounded for these ctor DefKinds, but I don't have a particularly strong opinion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, also, I'm not really a fan of renaming functions from "fn item" to their descr "function".