-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Add note when inherent impl for a alias type defined outside of the crate #142415
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: master
Are you sure you want to change the base?
Conversation
tests/ui/incoherent-inherent-impls/insufficient-suggestion-issue-141679.stderr
Show resolved
Hide resolved
tests/ui/incoherent-inherent-impls/insufficient-suggestion-issue-141679.stderr
Outdated
Show resolved
Hide resolved
r? compiler |
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.
@rustbot ready
.note = define and implement a trait or new type instead | ||
.help = consider defining a trait and implementing it for the type or using a newtype wrapper like `struct MyType(ExternalType);` and implement it | ||
.note = For more details about orphan rules, see <https://doc.rust-lang.org/reference/items/implementations.html?highlight=orphan#orphan-rules> | ||
|
||
hir_analysis_inherent_ty_outside_new_alias_note = `{$ty_name}` does not define a new type, just alias of `{$alias_ty_name}` defined here |
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.
It seems difficult to apply structured suggestions here, because not only do we have to implement a new type, we also need to implement it with impl. Maybe we can use a clearer explanation:
help: consider defining a trait and implementing it for the type or using a newtype wrapper like `struct MyType(ExternalType);` and implement it.
Note: For more details about orphan rules, see <https://doc.rust-lang.org/reference/items/implementations.html?highlight=orphan#orphan-rules>
Signed-off-by: xizheyin <[email protected]>
do you not get TyKind::Alias when you use type_of on the impl? coherence is probably fine to use middle queries |
…rate Signed-off-by: xizheyin <[email protected]>
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.
I've tried using type_of
before, but I don't seem to be getting the information I'm looking for. When I try this code
let ty = self.tcx.type_of(impl_def_id).skip_binder();
if let ty::Adt(def, _) = ty.kind() {
let def_id = def.did();
let ty_name = self.tcx.def_path_str(def_id);
let alias_ty_name = self.tcx.type_of(def_id).skip_binder().to_string();
println!("ty_name: {:?}", ty_name);
println!("alias_ty_name: {:?}", alias_ty_name);
}
it prints:
ty_name: "Rc"
alias_ty_name: "Rc<T, A>"
It should be:
ty_name: "Function"
alias_ty_name: "Rc<Foo>"
Local variable ty
is a adt of type Rc
. Maybe the information we need only exists in HIR? Or am I using it wrong?
if let hir::TyKind::Path(rustc_hir::QPath::Resolved(_, path)) = | ||
self.tcx.hir_node_by_def_id(impl_def_id).expect_item().expect_impl().self_ty.kind | ||
&& let rustc_hir::def::Res::Def(DefKind::TyAlias, def_id) = path.res |
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.
I merged the two ifs.
r? compiler |
Fixes #141679
r? compiler