-
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
Enforce supertrait outlives obligations hold when confirming impl #124336
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -7,15 +7,17 @@ use std::fmt::{self, Display}; | |||||||
use std::ops::ControlFlow; | ||||||||
use std::{cmp, iter}; | ||||||||
|
||||||||
use hir::def::DefKind; | ||||||||
use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet}; | ||||||||
use rustc_data_structures::stack::ensure_sufficient_stack; | ||||||||
use rustc_errors::{Diag, EmissionGuarantee}; | ||||||||
use rustc_hir as hir; | ||||||||
use rustc_hir::def_id::DefId; | ||||||||
use rustc_hir::LangItem; | ||||||||
use rustc_infer::infer::relate::TypeRelation; | ||||||||
use rustc_infer::infer::BoundRegionConversionTime::HigherRankedType; | ||||||||
use rustc_infer::infer::{BoundRegionConversionTime, DefineOpaqueTypes}; | ||||||||
use rustc_infer::infer::BoundRegionConversionTime::{self, HigherRankedType}; | ||||||||
use rustc_infer::infer::DefineOpaqueTypes; | ||||||||
use rustc_infer::traits::util::elaborate; | ||||||||
use rustc_infer::traits::TraitObligation; | ||||||||
use rustc_middle::bug; | ||||||||
use rustc_middle::dep_graph::{dep_kinds, DepNodeIndex}; | ||||||||
|
@@ -2798,6 +2800,35 @@ impl<'tcx> SelectionContext<'_, 'tcx> { | |||||||
}); | ||||||||
} | ||||||||
|
||||||||
// Register any outlives obligations from the trait here, cc #124336. | ||||||||
if matches!(self.tcx().def_kind(def_id), DefKind::Impl { of_trait: true }) | ||||||||
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.
Suggested change
|
||||||||
&& let Some(header) = self.tcx().impl_trait_header(def_id) | ||||||||
{ | ||||||||
let trait_clause: ty::Clause<'tcx> = | ||||||||
header.trait_ref.instantiate(self.tcx(), args).upcast(self.tcx()); | ||||||||
for clause in elaborate(self.tcx(), [trait_clause]) { | ||||||||
if matches!( | ||||||||
clause.kind().skip_binder(), | ||||||||
ty::ClauseKind::TypeOutlives(..) | ty::ClauseKind::RegionOutlives(..) | ||||||||
) { | ||||||||
let clause = normalize_with_depth_to( | ||||||||
self, | ||||||||
param_env, | ||||||||
cause.clone(), | ||||||||
recursion_depth, | ||||||||
clause, | ||||||||
&mut obligations, | ||||||||
); | ||||||||
obligations.push(Obligation { | ||||||||
cause: cause.clone(), | ||||||||
recursion_depth, | ||||||||
param_env, | ||||||||
predicate: clause.as_predicate(), | ||||||||
}); | ||||||||
} | ||||||||
} | ||||||||
} | ||||||||
|
||||||||
obligations | ||||||||
} | ||||||||
} | ||||||||
|
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
pub trait Arbitrary: Sized + 'static {} | ||
|
||
impl<'a, A: Clone> Arbitrary for ::std::borrow::Cow<'a, A> {} //~ ERROR lifetime bound | ||
//~^ ERROR cannot infer an appropriate lifetime for lifetime parameter `'a` | ||
|
||
fn main() { | ||
} |
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
error[E0716]: temporary value dropped while borrowed | ||
--> $DIR/wf-in-where-clause-static.rs:18:18 | ||
| | ||
LL | let s = foo(&String::from("blah blah blah")); | ||
| -----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-- temporary value is freed at the end of this statement | ||
| | | | ||
| | creates a temporary value which is freed while still in use | ||
| argument requires that borrow lasts for `'static` | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0716`. |
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
error[E0716]: temporary value dropped while borrowed | ||
--> $DIR/wf-in-where-clause-static.rs:18:18 | ||
| | ||
LL | let s = foo(&String::from("blah blah blah")); | ||
| -----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-- temporary value is freed at the end of this statement | ||
| | | | ||
| | creates a temporary value which is freed while still in use | ||
| argument requires that borrow lasts for `'static` | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0716`. |
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.
please add a comment why we elaborate here:
dyn Any: Any
to have the same region constraints (to enable us to merge them), we also elaborate to get all outlives constraints hereThere 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.
Can do
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.
still relevant