-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #100676 - lcnr:implied-bounds-yay, r=nikomatsakis
implied bounds: explicitly state which types are assumed to be wf Adds a new query which maps each definition to the types which that definition assumes to be well formed. The intent is to make it easier to reason about implied bounds. This change should not influence the user-facing behavior of rustc. Notably, `borrowck` still only assumes that the function signature of associated functions is well formed while `wfcheck` assumes that the both the function signature and the impl trait ref is well formed. Not sure if that by itself can trigger UB or whether it's just annoying. As a next step, we can add `WellFormed` predicates to `predicates_of` of these items and can stop adding the wf bounds at each place which uses them. I also intend to move the computation from `assumed_wf_types` to `implied_bounds` into the `param_env` computation. This requires me to take a deeper look at `compare_predicate_entailment` which is currently somewhat weird wrt implied bounds so I am not touching this here. r? `@nikomatsakis`
- Loading branch information
Showing
24 changed files
with
321 additions
and
237 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,60 @@ | ||
use crate::rustc_middle::ty::DefIdTree; | ||
use rustc_hir::{def::DefKind, def_id::DefId}; | ||
use rustc_middle::ty::{self, Ty, TyCtxt}; | ||
|
||
pub fn provide(providers: &mut ty::query::Providers) { | ||
*providers = ty::query::Providers { assumed_wf_types, ..*providers }; | ||
} | ||
|
||
fn assumed_wf_types<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> &'tcx ty::List<Ty<'tcx>> { | ||
match tcx.def_kind(def_id) { | ||
DefKind::Fn => { | ||
let sig = tcx.fn_sig(def_id); | ||
let liberated_sig = tcx.liberate_late_bound_regions(def_id, sig); | ||
liberated_sig.inputs_and_output | ||
} | ||
DefKind::AssocFn => { | ||
let sig = tcx.fn_sig(def_id); | ||
let liberated_sig = tcx.liberate_late_bound_regions(def_id, sig); | ||
let mut assumed_wf_types: Vec<_> = | ||
tcx.assumed_wf_types(tcx.parent(def_id)).as_slice().into(); | ||
assumed_wf_types.extend(liberated_sig.inputs_and_output); | ||
tcx.intern_type_list(&assumed_wf_types) | ||
} | ||
DefKind::Impl => match tcx.impl_trait_ref(def_id) { | ||
Some(trait_ref) => { | ||
let types: Vec<_> = trait_ref.substs.types().collect(); | ||
tcx.intern_type_list(&types) | ||
} | ||
// Only the impl self type | ||
None => tcx.intern_type_list(&[tcx.type_of(def_id)]), | ||
}, | ||
DefKind::AssocConst | DefKind::AssocTy => tcx.assumed_wf_types(tcx.parent(def_id)), | ||
DefKind::Mod | ||
| DefKind::Struct | ||
| DefKind::Union | ||
| DefKind::Enum | ||
| DefKind::Variant | ||
| DefKind::Trait | ||
| DefKind::TyAlias | ||
| DefKind::ForeignTy | ||
| DefKind::TraitAlias | ||
| DefKind::TyParam | ||
| DefKind::Const | ||
| DefKind::ConstParam | ||
| DefKind::Static(_) | ||
| DefKind::Ctor(_, _) | ||
| DefKind::Macro(_) | ||
| DefKind::ExternCrate | ||
| DefKind::Use | ||
| DefKind::ForeignMod | ||
| DefKind::AnonConst | ||
| DefKind::InlineConst | ||
| DefKind::OpaqueTy | ||
| DefKind::Field | ||
| DefKind::LifetimeParam | ||
| DefKind::GlobalAsm | ||
| DefKind::Closure | ||
| DefKind::Generator => ty::List::empty(), | ||
} | ||
} |
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
Oops, something went wrong.