-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
Restore const PartialEq
#118661
Restore const PartialEq
#118661
Changes from 1 commit
f635cd2
e03c18b
2f457d9
d1f4bc5
d464dd0
de8f4ac
c4c3555
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 |
---|---|---|
|
@@ -214,7 +214,8 @@ pub fn implements_trait<'tcx>( | |
trait_id: DefId, | ||
args: &[GenericArg<'tcx>], | ||
) -> bool { | ||
implements_trait_with_env_from_iter(cx.tcx, cx.param_env, ty, trait_id, args.iter().map(|&x| Some(x))) | ||
let callee_id = cx.enclosing_body.map(|body| cx.tcx.hir().body_owner(body).owner.to_def_id()); | ||
implements_trait_with_env_from_iter(cx.tcx, cx.param_env, ty, trait_id, callee_id, args.iter().map(|&x| Some(x))) | ||
} | ||
|
||
/// Same as `implements_trait` but allows using a `ParamEnv` different from the lint context. | ||
|
@@ -223,9 +224,10 @@ pub fn implements_trait_with_env<'tcx>( | |
param_env: ParamEnv<'tcx>, | ||
ty: Ty<'tcx>, | ||
trait_id: DefId, | ||
callee_id: DefId, | ||
args: &[GenericArg<'tcx>], | ||
) -> bool { | ||
implements_trait_with_env_from_iter(tcx, param_env, ty, trait_id, args.iter().map(|&x| Some(x))) | ||
implements_trait_with_env_from_iter(tcx, param_env, ty, trait_id, Some(callee_id), args.iter().map(|&x| Some(x))) | ||
} | ||
|
||
/// Same as `implements_trait_from_env` but takes the arguments as an iterator. | ||
|
@@ -234,6 +236,7 @@ pub fn implements_trait_with_env_from_iter<'tcx>( | |
param_env: ParamEnv<'tcx>, | ||
ty: Ty<'tcx>, | ||
trait_id: DefId, | ||
callee_id: Option<DefId>, | ||
args: impl IntoIterator<Item = impl Into<Option<GenericArg<'tcx>>>>, | ||
) -> bool { | ||
// Clippy shouldn't have infer types | ||
|
@@ -245,20 +248,29 @@ pub fn implements_trait_with_env_from_iter<'tcx>( | |
} | ||
|
||
let infcx = tcx.infer_ctxt().build(); | ||
let args = args.into_iter().map(|arg| { | ||
arg.into().unwrap_or_else(|| { | ||
let orig = TypeVariableOrigin { | ||
kind: TypeVariableOriginKind::MiscVariable, | ||
span: DUMMY_SP, | ||
}; | ||
infcx.next_ty_var(orig).into() | ||
}) | ||
}).collect::<Vec<_>>(); | ||
|
||
// If an effect arg was not specified, we need to specify it. | ||
let effect_arg = if tcx.generics_of(trait_id).host_effect_index.is_some_and(|x| args.get(x - 1).is_none()) { | ||
Some(GenericArg::from(callee_id.map(|def_id| tcx.expected_host_effect_param_for_body(def_id)).unwrap_or(tcx.consts.true_))) | ||
} else { | ||
None | ||
}; | ||
Comment on lines
+251
to
+266
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. I think this is simplified by 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. I don't think that works. There are times where the caller of this function has already specified the host param themselves (they're modifying an existing 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. Oh, ok. |
||
|
||
let trait_ref = TraitRef::new( | ||
tcx, | ||
trait_id, | ||
Some(GenericArg::from(ty)) | ||
.into_iter() | ||
.chain(args.into_iter().map(|arg| { | ||
arg.into().unwrap_or_else(|| { | ||
let orig = TypeVariableOrigin { | ||
kind: TypeVariableOriginKind::MiscVariable, | ||
span: DUMMY_SP, | ||
}; | ||
infcx.next_ty_var(orig).into() | ||
}) | ||
})), | ||
.chain(args).chain(effect_arg), | ||
); | ||
|
||
debug_assert_matches!( | ||
|
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.
@fee1-dead (cc: @compiler-errors) I am having difficulty understanding what this additional required
callee_id
parameter is/does.A comment elsewhere in this PR suggests it is an "effect arg". Moreover, I found this doc comment for
with_opt_host_effect_param
:rust/compiler/rustc_middle/src/ty/util.rs
Line 860 in d73bd3f
But I can't find any documentation (e.g., in the Rustc Dev Guide) on what an "effect arg/param" is, or why/when it is needed.
Could you please point me to something that could help me better understand? Thank you.
This comment was marked as off-topic.
Sorry, something went wrong.
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 hidden the last comment since it could be wrong. I will take a look maybe tomorrow.