forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#126686 - fmease:dump-preds-n-item-bounds, r…
…=compiler-errors Add `#[rustc_dump_{predicates,item_bounds}]` Conflicts with rust-lang#126668. As discussed r? compiler-errors CC `@fee1-dead`
- Loading branch information
Showing
17 changed files
with
187 additions
and
104 deletions.
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: "(dump_preds|core)\[[0-9a-f]+\]" -> "$1[HASH]" | ||
|
||
#![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(0:5 ~ dump_preds[HASH]::Trait::Assoc) })], def_id: DefId(2:3422 ~ core[HASH]::ops::deref::Deref::Target) }, 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 | ||
|