-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Add #[rustc_dump_{predicates,item_bounds}]
#126686
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
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,43 @@ | ||
use rustc_hir::def::DefKind; | ||
use rustc_hir::def_id::CRATE_DEF_ID; | ||
use rustc_middle::ty::TyCtxt; | ||
use rustc_span::sym; | ||
|
||
pub(crate) fn opaque_hidden_types(tcx: TyCtxt<'_>) { | ||
if !tcx.has_attr(CRATE_DEF_ID, sym::rustc_hidden_type_of_opaques) { | ||
return; | ||
} | ||
|
||
for id in tcx.hir().items() { | ||
let DefKind::OpaqueTy = tcx.def_kind(id.owner_id) else { continue }; | ||
|
||
let ty = tcx.type_of(id.owner_id).instantiate_identity(); | ||
|
||
tcx.dcx().emit_err(crate::errors::TypeOf { span: tcx.def_span(id.owner_id), ty }); | ||
} | ||
} | ||
|
||
pub(crate) fn predicates_and_item_bounds(tcx: TyCtxt<'_>) { | ||
for id in tcx.hir_crate_items(()).owners() { | ||
if tcx.has_attr(id, sym::rustc_dump_predicates) { | ||
let preds = tcx.predicates_of(id).instantiate_identity(tcx).predicates; | ||
let span = tcx.def_span(id); | ||
|
||
let mut diag = tcx.dcx().struct_span_err(span, sym::rustc_dump_predicates.as_str()); | ||
for pred in preds { | ||
diag.note(format!("{pred:?}")); | ||
} | ||
diag.emit(); | ||
} | ||
if tcx.has_attr(id, sym::rustc_dump_item_bounds) { | ||
let bounds = tcx.item_bounds(id).instantiate_identity(); | ||
let span = tcx.def_span(id); | ||
|
||
let mut diag = tcx.dcx().struct_span_err(span, sym::rustc_dump_item_bounds.as_str()); | ||
for bound in bounds { | ||
diag.note(format!("{bound:?}")); | ||
} | ||
diag.emit(); | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use rustc_middle::bug; | ||
use rustc_middle::ty::{self, TyCtxt}; | ||
use rustc_span::sym; | ||
|
||
pub(crate) fn inferred_outlives(tcx: TyCtxt<'_>) { | ||
for id in tcx.hir().items() { | ||
if !tcx.has_attr(id.owner_id, sym::rustc_outlives) { | ||
continue; | ||
} | ||
|
||
let preds = tcx.inferred_outlives_of(id.owner_id); | ||
let mut preds: Vec<_> = preds | ||
.iter() | ||
.map(|(pred, _)| match pred.kind().skip_binder() { | ||
ty::ClauseKind::RegionOutlives(p) => p.to_string(), | ||
ty::ClauseKind::TypeOutlives(p) => p.to_string(), | ||
err => bug!("unexpected clause {:?}", err), | ||
}) | ||
.collect(); | ||
preds.sort(); | ||
|
||
let span = tcx.def_span(id.owner_id); | ||
let mut err = tcx.dcx().struct_span_err(span, sym::rustc_outlives.as_str()); | ||
for pred in preds { | ||
err.note(pred); | ||
} | ||
err.emit(); | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.
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,32 @@ | ||
use rustc_hir::def::DefKind; | ||
use rustc_hir::def_id::CRATE_DEF_ID; | ||
use rustc_middle::ty::TyCtxt; | ||
use rustc_span::symbol::sym; | ||
|
||
pub(crate) fn variances(tcx: TyCtxt<'_>) { | ||
if tcx.has_attr(CRATE_DEF_ID, sym::rustc_variance_of_opaques) { | ||
for id in tcx.hir().items() { | ||
let DefKind::OpaqueTy = tcx.def_kind(id.owner_id) else { continue }; | ||
|
||
let variances = tcx.variances_of(id.owner_id); | ||
|
||
tcx.dcx().emit_err(crate::errors::VariancesOf { | ||
span: tcx.def_span(id.owner_id), | ||
variances: format!("{variances:?}"), | ||
}); | ||
} | ||
} | ||
|
||
for id in tcx.hir().items() { | ||
if !tcx.has_attr(id.owner_id, sym::rustc_variance) { | ||
continue; | ||
} | ||
|
||
let variances = tcx.variances_of(id.owner_id); | ||
|
||
tcx.dcx().emit_err(crate::errors::VariancesOf { | ||
span: tcx.def_span(id.owner_id), | ||
variances: format!("{variances:?}"), | ||
}); | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.
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,20 @@ | ||
//@ normalize-stderr-test "DefId\(.+?\)" -> "DefId(..)" | ||
|
||
#![feature(rustc_attrs)] | ||
|
||
#[rustc_dump_predicates] | ||
trait Trait<T>: Iterator<Item: Copy> | ||
//~^ ERROR rustc_dump_predicates | ||
where | ||
String: From<T> | ||
{ | ||
#[rustc_dump_predicates] | ||
#[rustc_dump_item_bounds] | ||
type Assoc<P: Eq>: std::ops::Deref<Target = ()> | ||
//~^ ERROR rustc_dump_predicates | ||
//~| ERROR rustc_dump_item_bounds | ||
where | ||
Self::Assoc<()>: Copy; | ||
} | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
error: rustc_dump_predicates | ||
--> $DIR/dump-preds.rs:6:1 | ||
| | ||
LL | trait Trait<T>: Iterator<Item: Copy> | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: Binder { value: TraitPredicate(<Self as std::iter::Iterator>, polarity:Positive), bound_vars: [] } | ||
= note: Binder { value: TraitPredicate(<<Self as std::iter::Iterator>::Item as std::marker::Copy>, polarity:Positive), bound_vars: [] } | ||
= note: Binder { value: TraitPredicate(<T as std::marker::Sized>, polarity:Positive), bound_vars: [] } | ||
= note: Binder { value: TraitPredicate(<std::string::String as std::convert::From<T>>, polarity:Positive), bound_vars: [] } | ||
= note: Binder { value: TraitPredicate(<Self as Trait<T>>, polarity:Positive), bound_vars: [] } | ||
|
||
error: rustc_dump_predicates | ||
--> $DIR/dump-preds.rs:13:5 | ||
| | ||
LL | type Assoc<P: Eq>: std::ops::Deref<Target = ()> | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: Binder { value: TraitPredicate(<Self as std::iter::Iterator>, polarity:Positive), bound_vars: [] } | ||
= note: Binder { value: TraitPredicate(<<Self as std::iter::Iterator>::Item as std::marker::Copy>, polarity:Positive), bound_vars: [] } | ||
= note: Binder { value: TraitPredicate(<T as std::marker::Sized>, polarity:Positive), bound_vars: [] } | ||
= note: Binder { value: TraitPredicate(<std::string::String as std::convert::From<T>>, polarity:Positive), bound_vars: [] } | ||
= note: Binder { value: TraitPredicate(<Self as Trait<T>>, polarity:Positive), bound_vars: [] } | ||
= note: Binder { value: TraitPredicate(<P as std::marker::Sized>, polarity:Positive), bound_vars: [] } | ||
= note: Binder { value: TraitPredicate(<P as std::cmp::Eq>, polarity:Positive), bound_vars: [] } | ||
= note: Binder { value: TraitPredicate(<<Self as Trait<T>>::Assoc<()> as std::marker::Copy>, polarity:Positive), bound_vars: [] } | ||
|
||
error: rustc_dump_item_bounds | ||
--> $DIR/dump-preds.rs:13:5 | ||
| | ||
LL | type Assoc<P: Eq>: std::ops::Deref<Target = ()> | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: Binder { value: ProjectionPredicate(AliasTerm { args: [Alias(Projection, AliasTy { args: [Self/#0, T/#1, P/#2], def_id: DefId(..) })], def_id: DefId(..) }, Term::Ty(())), bound_vars: [] } | ||
= note: Binder { value: TraitPredicate(<<Self as Trait<T>>::Assoc<P> as std::ops::Deref>, polarity:Positive), bound_vars: [] } | ||
= note: Binder { value: TraitPredicate(<<Self as Trait<T>>::Assoc<P> as std::marker::Sized>, polarity:Positive), bound_vars: [] } | ||
|
||
error: aborting due to 3 previous errors | ||
|
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.
Instead of going through all owner items I could instead extend
CheckAttrVisitor::check_attributes
. That's how#[rustc_object_lifetime_default]
is impl'ed.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 don't think it really matters 🤷