-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
lint incorrect implied bounds in wfcheck #109763
Closed
+450
−80
Closed
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
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
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 |
---|---|---|
|
@@ -3,26 +3,34 @@ use crate::traits::query::type_op::{self, TypeOp, TypeOpOutput}; | |
use crate::traits::query::NoSolution; | ||
use crate::traits::{ObligationCause, ObligationCtxt}; | ||
use rustc_data_structures::fx::FxIndexSet; | ||
use rustc_hir::def_id::LocalDefId; | ||
use rustc_infer::infer::resolve::OpportunisticRegionResolver; | ||
use rustc_middle::ty::{self, ParamEnv, Ty, TypeFolder, TypeVisitableExt}; | ||
use rustc_span::def_id::LocalDefId; | ||
use rustc_span::DUMMY_SP; | ||
|
||
pub use rustc_middle::traits::query::OutlivesBound; | ||
|
||
type BoundsCompat<'a, 'tcx: 'a> = impl Iterator<Item = OutlivesBound<'tcx>> + 'a; | ||
type Bounds<'a, 'tcx: 'a> = impl Iterator<Item = OutlivesBound<'tcx>> + 'a; | ||
pub trait InferCtxtExt<'a, 'tcx> { | ||
fn implied_outlives_bounds( | ||
fn implied_outlives_bounds_compat( | ||
&self, | ||
param_env: ty::ParamEnv<'tcx>, | ||
body_id: LocalDefId, | ||
ty: Ty<'tcx>, | ||
) -> Vec<OutlivesBound<'tcx>>; | ||
|
||
fn implied_bounds_tys( | ||
fn implied_bounds_tys_compat( | ||
&'a self, | ||
param_env: ty::ParamEnv<'tcx>, | ||
body_id: LocalDefId, | ||
tys: FxIndexSet<Ty<'tcx>>, | ||
) -> BoundsCompat<'a, 'tcx>; | ||
|
||
fn implied_bounds_tys( | ||
&'a self, | ||
param_env: ty::ParamEnv<'tcx>, | ||
tys: &'a FxIndexSet<Ty<'tcx>>, | ||
) -> Bounds<'a, 'tcx>; | ||
} | ||
|
||
|
@@ -47,7 +55,7 @@ impl<'a, 'tcx: 'a> InferCtxtExt<'a, 'tcx> for InferCtxt<'tcx> { | |
/// into the inference context with this body-id. | ||
/// - `ty`, the type that we are supposed to assume is WF. | ||
#[instrument(level = "debug", skip(self, param_env, body_id), ret)] | ||
fn implied_outlives_bounds( | ||
fn implied_outlives_bounds_compat( | ||
&self, | ||
param_env: ty::ParamEnv<'tcx>, | ||
body_id: LocalDefId, | ||
|
@@ -115,12 +123,33 @@ impl<'a, 'tcx: 'a> InferCtxtExt<'a, 'tcx> for InferCtxt<'tcx> { | |
output | ||
} | ||
|
||
fn implied_bounds_tys( | ||
fn implied_bounds_tys_compat( | ||
&'a self, | ||
param_env: ParamEnv<'tcx>, | ||
body_id: LocalDefId, | ||
tys: FxIndexSet<Ty<'tcx>>, | ||
) -> BoundsCompat<'a, 'tcx> { | ||
tys.into_iter() | ||
.flat_map(move |ty| self.implied_outlives_bounds_compat(param_env, body_id, ty)) | ||
} | ||
|
||
fn implied_bounds_tys( | ||
&'a self, | ||
param_env: ParamEnv<'tcx>, | ||
tys: &'a FxIndexSet<Ty<'tcx>>, | ||
) -> Bounds<'a, 'tcx> { | ||
tys.into_iter().flat_map(move |ty| self.implied_outlives_bounds(param_env, body_id, ty)) | ||
tys.iter() | ||
.flat_map(move |&ty| { | ||
let ty = self.resolve_vars_if_possible(ty); | ||
let ty = OpportunisticRegionResolver::new(self).fold_ty(ty); | ||
if ty.has_infer() { | ||
// Infer vars can appear only in invalid code. See #110161. | ||
self.tcx.sess.delay_span_bug(DUMMY_SP, "infer vars in implied bounds"); | ||
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. For the record, this line should be removed when/if this is rebased #115559 |
||
return &[] as &[OutlivesBound<'_>]; | ||
} | ||
|
||
self.tcx.implied_outlives_bounds(param_env.and(ty)).unwrap_or(&[]) | ||
}) | ||
.copied() | ||
} | ||
} |
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 |
---|---|---|
|
@@ -77,21 +77,20 @@ pub fn obligations<'tcx>( | |
|
||
/// Compute the predicates that are required for a type to be well-formed. | ||
/// | ||
/// This is only intended to be used in the new solver, since it does not | ||
/// take into account recursion depth or proper error-reporting spans. | ||
/// This is only intended to be used in implied bounds computation and in | ||
/// the new solver, since it does not take into account recursion depth or | ||
/// proper error-reporting spans. | ||
pub fn unnormalized_obligations<'tcx>( | ||
infcx: &InferCtxt<'tcx>, | ||
tcx: TyCtxt<'tcx>, | ||
param_env: ty::ParamEnv<'tcx>, | ||
arg: GenericArg<'tcx>, | ||
) -> Option<Vec<traits::PredicateObligation<'tcx>>> { | ||
) -> Vec<traits::PredicateObligation<'tcx>> { | ||
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 too can be moved into a separate commit or PR? |
||
if let ty::GenericArgKind::Lifetime(..) = arg.unpack() { | ||
return Some(vec![]); | ||
return vec![]; | ||
} | ||
|
||
debug_assert_eq!(arg, infcx.resolve_vars_if_possible(arg)); | ||
|
||
let mut wf = WfPredicates { | ||
tcx: infcx.tcx, | ||
tcx, | ||
param_env, | ||
body_id: CRATE_DEF_ID, | ||
span: DUMMY_SP, | ||
|
@@ -100,7 +99,7 @@ pub fn unnormalized_obligations<'tcx>( | |
item: None, | ||
}; | ||
wf.compute(arg); | ||
Some(wf.out) | ||
wf.out | ||
} | ||
|
||
/// Returns the obligations that make this trait reference | ||
|
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.
Given that it seems like most places still use this, it seems like it would make sense to keep this name the same, and name the new version v2 or something.