mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-29 12:36:35 +03:00
+11
@@ -4343,6 +4343,7 @@ dependencies = [
|
||||
"rustc_hir_pretty",
|
||||
"rustc_index",
|
||||
"rustc_macros",
|
||||
"rustc_next_trait_solver",
|
||||
"rustc_query_system",
|
||||
"rustc_serialize",
|
||||
"rustc_session",
|
||||
@@ -4451,7 +4452,13 @@ dependencies = [
|
||||
name = "rustc_next_trait_solver"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"derivative",
|
||||
"rustc_ast_ir",
|
||||
"rustc_data_structures",
|
||||
"rustc_macros",
|
||||
"rustc_serialize",
|
||||
"rustc_type_ir",
|
||||
"rustc_type_ir_macros",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -4752,6 +4759,7 @@ name = "rustc_trait_selection"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"bitflags 2.5.0",
|
||||
"derivative",
|
||||
"itertools 0.12.1",
|
||||
"rustc_ast",
|
||||
"rustc_ast_ir",
|
||||
@@ -4767,10 +4775,13 @@ dependencies = [
|
||||
"rustc_next_trait_solver",
|
||||
"rustc_parse_format",
|
||||
"rustc_query_system",
|
||||
"rustc_serialize",
|
||||
"rustc_session",
|
||||
"rustc_span",
|
||||
"rustc_target",
|
||||
"rustc_transmute",
|
||||
"rustc_type_ir",
|
||||
"rustc_type_ir_macros",
|
||||
"smallvec",
|
||||
"tracing",
|
||||
]
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
use std::cmp;
|
||||
use std::fmt::{self, Write};
|
||||
use std::iter;
|
||||
use std::num::NonZero;
|
||||
use std::ops::Bound;
|
||||
use std::ops::Deref;
|
||||
|
||||
@@ -11,8 +10,8 @@
|
||||
|
||||
use crate::{
|
||||
Abi, AbiAndPrefAlign, Align, FieldsShape, IndexSlice, IndexVec, Integer, LayoutS, Niche,
|
||||
Primitive, ReprOptions, Scalar, Size, StructKind, TagEncoding, TargetDataLayout, Variants,
|
||||
WrappingRange,
|
||||
NonZeroUsize, Primitive, ReprOptions, Scalar, Size, StructKind, TagEncoding, TargetDataLayout,
|
||||
Variants, WrappingRange,
|
||||
};
|
||||
|
||||
// A variant is absent if it's uninhabited and only has ZST fields.
|
||||
@@ -328,7 +327,7 @@ fn layout_of_union<
|
||||
|
||||
Some(LayoutS {
|
||||
variants: Variants::Single { index: VariantIdx::new(0) },
|
||||
fields: FieldsShape::Union(NonZero::new(only_variant.len())?),
|
||||
fields: FieldsShape::Union(NonZeroUsize::new(only_variant.len())?),
|
||||
abi,
|
||||
largest_niche: None,
|
||||
align,
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#![cfg_attr(feature = "nightly", feature(rustdoc_internals))]
|
||||
|
||||
use std::fmt;
|
||||
use std::num::{NonZero, ParseIntError};
|
||||
use std::num::{NonZeroUsize, ParseIntError};
|
||||
use std::ops::{Add, AddAssign, Mul, RangeInclusive, Sub};
|
||||
use std::str::FromStr;
|
||||
|
||||
@@ -1175,7 +1175,7 @@ pub enum FieldsShape<FieldIdx: Idx> {
|
||||
Primitive,
|
||||
|
||||
/// All fields start at no offset. The `usize` is the field count.
|
||||
Union(NonZero<usize>),
|
||||
Union(NonZeroUsize),
|
||||
|
||||
/// Array/vector-like placement, with all fields of identical types.
|
||||
Array { stride: Size, count: u64 },
|
||||
|
||||
@@ -2105,7 +2105,7 @@ pub fn peel_refs(&self) -> &Self {
|
||||
|
||||
#[derive(Clone, Encodable, Decodable, Debug)]
|
||||
pub struct BareFnTy {
|
||||
pub unsafety: Unsafe,
|
||||
pub safety: Safety,
|
||||
pub ext: Extern,
|
||||
pub generic_params: ThinVec<GenericParam>,
|
||||
pub decl: P<FnDecl>,
|
||||
@@ -2484,11 +2484,15 @@ pub enum IsAuto {
|
||||
No,
|
||||
}
|
||||
|
||||
/// Safety of items.
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Hash, Encodable, Decodable, Debug)]
|
||||
#[derive(HashStable_Generic)]
|
||||
pub enum Unsafe {
|
||||
Yes(Span),
|
||||
No,
|
||||
pub enum Safety {
|
||||
/// `unsafe` an item is explicitly marked as `unsafe`.
|
||||
Unsafe(Span),
|
||||
/// Default means no value was provided, it will take a default value given the context in
|
||||
/// which is used.
|
||||
Default,
|
||||
}
|
||||
|
||||
/// Describes what kind of coroutine markers, if any, a function has.
|
||||
@@ -2692,7 +2696,7 @@ pub struct ModSpans {
|
||||
pub struct ForeignMod {
|
||||
/// `unsafe` keyword accepted syntactically for macro DSLs, but not
|
||||
/// semantically by Rust.
|
||||
pub unsafety: Unsafe,
|
||||
pub safety: Safety,
|
||||
pub abi: Option<StrLit>,
|
||||
pub items: ThinVec<P<ForeignItem>>,
|
||||
}
|
||||
@@ -3011,8 +3015,8 @@ pub fn from_abi(abi: Option<StrLit>, span: Span) -> Extern {
|
||||
/// included in this struct (e.g., `async unsafe fn` or `const extern "C" fn`).
|
||||
#[derive(Clone, Copy, Encodable, Decodable, Debug)]
|
||||
pub struct FnHeader {
|
||||
/// The `unsafe` keyword, if any
|
||||
pub unsafety: Unsafe,
|
||||
/// Whether this is `unsafe`, or has a default safety
|
||||
pub safety: Safety,
|
||||
/// Whether this is `async`, `gen`, or nothing.
|
||||
pub coroutine_kind: Option<CoroutineKind>,
|
||||
/// The `const` keyword, if any
|
||||
@@ -3024,8 +3028,8 @@ pub struct FnHeader {
|
||||
impl FnHeader {
|
||||
/// Does this function header have any qualifiers or is it empty?
|
||||
pub fn has_qualifiers(&self) -> bool {
|
||||
let Self { unsafety, coroutine_kind, constness, ext } = self;
|
||||
matches!(unsafety, Unsafe::Yes(_))
|
||||
let Self { safety, coroutine_kind, constness, ext } = self;
|
||||
matches!(safety, Safety::Unsafe(_))
|
||||
|| coroutine_kind.is_some()
|
||||
|| matches!(constness, Const::Yes(_))
|
||||
|| !matches!(ext, Extern::None)
|
||||
@@ -3035,7 +3039,7 @@ pub fn has_qualifiers(&self) -> bool {
|
||||
impl Default for FnHeader {
|
||||
fn default() -> FnHeader {
|
||||
FnHeader {
|
||||
unsafety: Unsafe::No,
|
||||
safety: Safety::Default,
|
||||
coroutine_kind: None,
|
||||
constness: Const::No,
|
||||
ext: Extern::None,
|
||||
@@ -3045,7 +3049,7 @@ fn default() -> FnHeader {
|
||||
|
||||
#[derive(Clone, Encodable, Decodable, Debug)]
|
||||
pub struct Trait {
|
||||
pub unsafety: Unsafe,
|
||||
pub safety: Safety,
|
||||
pub is_auto: IsAuto,
|
||||
pub generics: Generics,
|
||||
pub bounds: GenericBounds,
|
||||
@@ -3101,7 +3105,7 @@ pub struct TyAlias {
|
||||
#[derive(Clone, Encodable, Decodable, Debug)]
|
||||
pub struct Impl {
|
||||
pub defaultness: Defaultness,
|
||||
pub unsafety: Unsafe,
|
||||
pub safety: Safety,
|
||||
pub generics: Generics,
|
||||
pub constness: Const,
|
||||
pub polarity: ImplPolarity,
|
||||
@@ -3209,7 +3213,7 @@ pub enum ItemKind {
|
||||
/// E.g., `mod foo;` or `mod foo { .. }`.
|
||||
/// `unsafe` keyword on modules is accepted syntactically for macro DSLs, but not
|
||||
/// semantically by Rust.
|
||||
Mod(Unsafe, ModKind),
|
||||
Mod(Safety, ModKind),
|
||||
/// An external module (`extern`).
|
||||
///
|
||||
/// E.g., `extern {}` or `extern "C" {}`.
|
||||
|
||||
@@ -499,8 +499,8 @@ pub fn noop_visit_ty<T: MutVisitor>(ty: &mut P<Ty>, vis: &mut T) {
|
||||
vis.visit_mt(mt);
|
||||
}
|
||||
TyKind::BareFn(bft) => {
|
||||
let BareFnTy { unsafety, ext: _, generic_params, decl, decl_span } = bft.deref_mut();
|
||||
visit_unsafety(unsafety, vis);
|
||||
let BareFnTy { safety, ext: _, generic_params, decl, decl_span } = bft.deref_mut();
|
||||
visit_safety(safety, vis);
|
||||
generic_params.flat_map_in_place(|param| vis.flat_map_generic_param(param));
|
||||
vis.visit_fn_decl(decl);
|
||||
vis.visit_span(decl_span);
|
||||
@@ -543,8 +543,8 @@ pub fn noop_visit_ty<T: MutVisitor>(ty: &mut P<Ty>, vis: &mut T) {
|
||||
}
|
||||
|
||||
fn noop_visit_foreign_mod<T: MutVisitor>(foreign_mod: &mut ForeignMod, vis: &mut T) {
|
||||
let ForeignMod { unsafety, abi: _, items } = foreign_mod;
|
||||
visit_unsafety(unsafety, vis);
|
||||
let ForeignMod { safety, abi: _, items } = foreign_mod;
|
||||
visit_safety(safety, vis);
|
||||
items.flat_map_in_place(|item| vis.flat_map_foreign_item(item));
|
||||
}
|
||||
|
||||
@@ -859,10 +859,10 @@ fn visit_defaultness<T: MutVisitor>(defaultness: &mut Defaultness, vis: &mut T)
|
||||
}
|
||||
|
||||
// No `noop_` prefix because there isn't a corresponding method in `MutVisitor`.
|
||||
fn visit_unsafety<T: MutVisitor>(unsafety: &mut Unsafe, vis: &mut T) {
|
||||
match unsafety {
|
||||
Unsafe::Yes(span) => vis.visit_span(span),
|
||||
Unsafe::No => {}
|
||||
fn visit_safety<T: MutVisitor>(safety: &mut Safety, vis: &mut T) {
|
||||
match safety {
|
||||
Safety::Unsafe(span) => vis.visit_span(span),
|
||||
Safety::Default => {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1092,8 +1092,8 @@ fn noop_visit(&mut self, vis: &mut impl MutVisitor) {
|
||||
vis.visit_generics(generics);
|
||||
visit_opt(body, |body| vis.visit_block(body));
|
||||
}
|
||||
ItemKind::Mod(unsafety, mod_kind) => {
|
||||
visit_unsafety(unsafety, vis);
|
||||
ItemKind::Mod(safety, mod_kind) => {
|
||||
visit_safety(safety, vis);
|
||||
match mod_kind {
|
||||
ModKind::Loaded(items, _inline, ModSpans { inner_span, inject_use_span }) => {
|
||||
vis.visit_span(inner_span);
|
||||
@@ -1130,7 +1130,7 @@ fn noop_visit(&mut self, vis: &mut impl MutVisitor) {
|
||||
}
|
||||
ItemKind::Impl(box Impl {
|
||||
defaultness,
|
||||
unsafety,
|
||||
safety,
|
||||
generics,
|
||||
constness,
|
||||
polarity,
|
||||
@@ -1139,7 +1139,7 @@ fn noop_visit(&mut self, vis: &mut impl MutVisitor) {
|
||||
items,
|
||||
}) => {
|
||||
visit_defaultness(defaultness, vis);
|
||||
visit_unsafety(unsafety, vis);
|
||||
visit_safety(safety, vis);
|
||||
vis.visit_generics(generics);
|
||||
visit_constness(constness, vis);
|
||||
visit_polarity(polarity, vis);
|
||||
@@ -1147,8 +1147,8 @@ fn noop_visit(&mut self, vis: &mut impl MutVisitor) {
|
||||
vis.visit_ty(self_ty);
|
||||
items.flat_map_in_place(|item| vis.flat_map_impl_item(item));
|
||||
}
|
||||
ItemKind::Trait(box Trait { unsafety, is_auto: _, generics, bounds, items }) => {
|
||||
visit_unsafety(unsafety, vis);
|
||||
ItemKind::Trait(box Trait { safety, is_auto: _, generics, bounds, items }) => {
|
||||
visit_safety(safety, vis);
|
||||
vis.visit_generics(generics);
|
||||
visit_bounds(bounds, vis);
|
||||
items.flat_map_in_place(|item| vis.flat_map_trait_item(item));
|
||||
@@ -1254,10 +1254,10 @@ fn visit_const_item<T: MutVisitor>(
|
||||
}
|
||||
|
||||
fn noop_visit_fn_header<T: MutVisitor>(header: &mut FnHeader, vis: &mut T) {
|
||||
let FnHeader { unsafety, coroutine_kind, constness, ext: _ } = header;
|
||||
let FnHeader { safety, coroutine_kind, constness, ext: _ } = header;
|
||||
visit_constness(constness, vis);
|
||||
coroutine_kind.as_mut().map(|coroutine_kind| vis.visit_coroutine_kind(coroutine_kind));
|
||||
visit_unsafety(unsafety, vis);
|
||||
visit_safety(safety, vis);
|
||||
}
|
||||
|
||||
pub fn noop_visit_crate<T: MutVisitor>(krate: &mut Crate, vis: &mut T) {
|
||||
|
||||
@@ -881,6 +881,8 @@ pub enum NonterminalKind {
|
||||
},
|
||||
PatWithOr,
|
||||
Expr,
|
||||
/// Matches an expression using the rules from edition 2021 and earlier.
|
||||
Expr2021,
|
||||
Ty,
|
||||
Ident,
|
||||
Lifetime,
|
||||
@@ -910,6 +912,7 @@ pub fn from_symbol(
|
||||
},
|
||||
sym::pat_param => NonterminalKind::PatParam { inferred: false },
|
||||
sym::expr => NonterminalKind::Expr,
|
||||
sym::expr_2021 if edition().at_least_rust_2021() => NonterminalKind::Expr2021,
|
||||
sym::ty => NonterminalKind::Ty,
|
||||
sym::ident => NonterminalKind::Ident,
|
||||
sym::lifetime => NonterminalKind::Lifetime,
|
||||
@@ -929,6 +932,7 @@ fn symbol(self) -> Symbol {
|
||||
NonterminalKind::PatParam { inferred: false } => sym::pat_param,
|
||||
NonterminalKind::PatParam { inferred: true } | NonterminalKind::PatWithOr => sym::pat,
|
||||
NonterminalKind::Expr => sym::expr,
|
||||
NonterminalKind::Expr2021 => sym::expr_2021,
|
||||
NonterminalKind::Ty => sym::ty,
|
||||
NonterminalKind::Ident => sym::ident,
|
||||
NonterminalKind::Lifetime => sym::lifetime,
|
||||
|
||||
@@ -366,7 +366,7 @@ fn walk<'a, V: Visitor<'a>>(
|
||||
}
|
||||
ItemKind::Impl(box Impl {
|
||||
defaultness: _,
|
||||
unsafety: _,
|
||||
safety: _,
|
||||
generics,
|
||||
constness: _,
|
||||
polarity: _,
|
||||
@@ -384,7 +384,7 @@ fn walk<'a, V: Visitor<'a>>(
|
||||
try_visit!(visitor.visit_generics(generics));
|
||||
try_visit!(visitor.visit_variant_data(struct_definition));
|
||||
}
|
||||
ItemKind::Trait(box Trait { unsafety: _, is_auto: _, generics, bounds, items }) => {
|
||||
ItemKind::Trait(box Trait { safety: _, is_auto: _, generics, bounds, items }) => {
|
||||
try_visit!(visitor.visit_generics(generics));
|
||||
walk_list!(visitor, visit_param_bound, bounds, BoundKind::SuperTraits);
|
||||
walk_list!(visitor, visit_assoc_item, items, AssocCtxt::Trait);
|
||||
|
||||
@@ -188,7 +188,7 @@ fn lower_delegation_sig(
|
||||
Asyncness::No => hir::IsAsync::NotAsync,
|
||||
};
|
||||
hir::FnHeader {
|
||||
unsafety: sig.unsafety,
|
||||
safety: sig.safety,
|
||||
constness: self.tcx.constness(sig_id),
|
||||
asyncness,
|
||||
abi: sig.abi,
|
||||
@@ -341,7 +341,7 @@ fn generate_delegation_error(
|
||||
|
||||
fn generate_header_error(&self) -> hir::FnHeader {
|
||||
hir::FnHeader {
|
||||
unsafety: hir::Unsafety::Normal,
|
||||
safety: hir::Safety::Safe,
|
||||
constness: hir::Constness::NotConst,
|
||||
asyncness: hir::IsAsync::NotAsync,
|
||||
abi: abi::Abi::Rust,
|
||||
|
||||
@@ -323,7 +323,7 @@ fn lower_item_kind(
|
||||
hir::ItemKind::Union(vdata, generics)
|
||||
}
|
||||
ItemKind::Impl(box Impl {
|
||||
unsafety,
|
||||
safety,
|
||||
polarity,
|
||||
defaultness,
|
||||
constness,
|
||||
@@ -388,7 +388,7 @@ fn lower_item_kind(
|
||||
ImplPolarity::Negative(s) => ImplPolarity::Negative(self.lower_span(*s)),
|
||||
};
|
||||
hir::ItemKind::Impl(self.arena.alloc(hir::Impl {
|
||||
unsafety: self.lower_unsafety(*unsafety),
|
||||
safety: self.lower_safety(*safety),
|
||||
polarity,
|
||||
defaultness,
|
||||
defaultness_span,
|
||||
@@ -398,14 +398,14 @@ fn lower_item_kind(
|
||||
items: new_impl_items,
|
||||
}))
|
||||
}
|
||||
ItemKind::Trait(box Trait { is_auto, unsafety, generics, bounds, items }) => {
|
||||
ItemKind::Trait(box Trait { is_auto, safety, generics, bounds, items }) => {
|
||||
// FIXME(const_trait_impl, effects, fee1-dead) this should be simplified if possible
|
||||
let constness = attrs
|
||||
.unwrap_or(&[])
|
||||
.iter()
|
||||
.find(|x| x.has_name(sym::const_trait))
|
||||
.map_or(Const::No, |x| Const::Yes(x.span));
|
||||
let (generics, (unsafety, items, bounds)) = self.lower_generics(
|
||||
let (generics, (safety, items, bounds)) = self.lower_generics(
|
||||
generics,
|
||||
constness,
|
||||
id,
|
||||
@@ -418,11 +418,11 @@ fn lower_item_kind(
|
||||
let items = this.arena.alloc_from_iter(
|
||||
items.iter().map(|item| this.lower_trait_item_ref(item)),
|
||||
);
|
||||
let unsafety = this.lower_unsafety(*unsafety);
|
||||
(unsafety, items, bounds)
|
||||
let safety = this.lower_safety(*safety);
|
||||
(safety, items, bounds)
|
||||
},
|
||||
);
|
||||
hir::ItemKind::Trait(*is_auto, unsafety, generics, bounds, items)
|
||||
hir::ItemKind::Trait(*is_auto, safety, generics, bounds, items)
|
||||
}
|
||||
ItemKind::TraitAlias(generics, bounds) => {
|
||||
let (generics, bounds) = self.lower_generics(
|
||||
@@ -1360,7 +1360,7 @@ pub(super) fn lower_fn_header(&mut self, h: FnHeader) -> hir::FnHeader {
|
||||
hir::IsAsync::NotAsync
|
||||
};
|
||||
hir::FnHeader {
|
||||
unsafety: self.lower_unsafety(h.unsafety),
|
||||
safety: self.lower_safety(h.safety),
|
||||
asyncness: asyncness,
|
||||
constness: self.lower_constness(h.constness),
|
||||
abi: self.lower_extern(h.ext),
|
||||
@@ -1410,10 +1410,10 @@ pub(super) fn lower_constness(&mut self, c: Const) -> hir::Constness {
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn lower_unsafety(&mut self, u: Unsafe) -> hir::Unsafety {
|
||||
match u {
|
||||
Unsafe::Yes(_) => hir::Unsafety::Unsafe,
|
||||
Unsafe::No => hir::Unsafety::Normal,
|
||||
pub(super) fn lower_safety(&mut self, s: Safety) -> hir::Safety {
|
||||
match s {
|
||||
Safety::Unsafe(_) => hir::Safety::Unsafe,
|
||||
Safety::Default => hir::Safety::Safe,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1324,7 +1324,7 @@ fn lower_ty_direct(&mut self, t: &Ty, itctx: ImplTraitContext) -> hir::Ty<'hir>
|
||||
let generic_params = self.lower_lifetime_binder(t.id, &f.generic_params);
|
||||
hir::TyKind::BareFn(self.arena.alloc(hir::BareFnTy {
|
||||
generic_params,
|
||||
unsafety: self.lower_unsafety(f.unsafety),
|
||||
safety: self.lower_safety(f.safety),
|
||||
abi: self.lower_extern(f.ext),
|
||||
decl: self.lower_fn_decl(&f.decl, t.id, t.span, FnDeclKind::Pointer, None),
|
||||
param_names: self.lower_fn_params_to_names(&f.decl),
|
||||
|
||||
@@ -521,7 +521,7 @@ fn current_extern_span(&self) -> Span {
|
||||
fn check_foreign_fn_headerless(
|
||||
&self,
|
||||
// Deconstruct to ensure exhaustiveness
|
||||
FnHeader { unsafety, coroutine_kind, constness, ext }: FnHeader,
|
||||
FnHeader { safety, coroutine_kind, constness, ext }: FnHeader,
|
||||
) {
|
||||
let report_err = |span| {
|
||||
self.dcx().emit_err(errors::FnQualifierInExtern {
|
||||
@@ -529,9 +529,9 @@ fn check_foreign_fn_headerless(
|
||||
block: self.current_extern_span(),
|
||||
});
|
||||
};
|
||||
match unsafety {
|
||||
Unsafe::Yes(span) => report_err(span),
|
||||
Unsafe::No => (),
|
||||
match safety {
|
||||
Safety::Unsafe(span) => report_err(span),
|
||||
Safety::Default => (),
|
||||
}
|
||||
match coroutine_kind {
|
||||
Some(knd) => report_err(knd.span()),
|
||||
@@ -592,7 +592,7 @@ fn check_c_variadic_type(&self, fk: FnKind<'a>) {
|
||||
(Some(FnCtxt::Free), Some(header)) => match header.ext {
|
||||
Extern::Explicit(StrLit { symbol_unescaped: sym::C, .. }, _)
|
||||
| Extern::Implicit(_)
|
||||
if matches!(header.unsafety, Unsafe::Yes(_)) =>
|
||||
if matches!(header.safety, Safety::Unsafe(_)) =>
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -891,7 +891,7 @@ fn visit_item(&mut self, item: &'a Item) {
|
||||
|
||||
match &item.kind {
|
||||
ItemKind::Impl(box Impl {
|
||||
unsafety,
|
||||
safety,
|
||||
polarity,
|
||||
defaultness: _,
|
||||
constness,
|
||||
@@ -910,7 +910,7 @@ fn visit_item(&mut self, item: &'a Item) {
|
||||
// which isn't allowed. Not a problem for this obscure, obsolete syntax.
|
||||
this.dcx().emit_fatal(errors::ObsoleteAuto { span: item.span });
|
||||
}
|
||||
if let (&Unsafe::Yes(span), &ImplPolarity::Negative(sp)) = (unsafety, polarity)
|
||||
if let (&Safety::Unsafe(span), &ImplPolarity::Negative(sp)) = (safety, polarity)
|
||||
{
|
||||
this.dcx().emit_err(errors::UnsafeNegativeImpl {
|
||||
span: sp.to(t.path.span),
|
||||
@@ -933,7 +933,7 @@ fn visit_item(&mut self, item: &'a Item) {
|
||||
return; // Avoid visiting again.
|
||||
}
|
||||
ItemKind::Impl(box Impl {
|
||||
unsafety,
|
||||
safety,
|
||||
polarity,
|
||||
defaultness,
|
||||
constness,
|
||||
@@ -956,7 +956,7 @@ fn visit_item(&mut self, item: &'a Item) {
|
||||
&item.vis,
|
||||
errors::VisibilityNotPermittedNote::IndividualImplItems,
|
||||
);
|
||||
if let &Unsafe::Yes(span) = unsafety {
|
||||
if let &Safety::Unsafe(span) = safety {
|
||||
this.dcx().emit_err(errors::InherentImplCannotUnsafe {
|
||||
span: self_ty.span,
|
||||
annotation_span: span,
|
||||
@@ -1020,13 +1020,13 @@ fn visit_item(&mut self, item: &'a Item) {
|
||||
walk_list!(self, visit_attribute, &item.attrs);
|
||||
return; // Avoid visiting again.
|
||||
}
|
||||
ItemKind::ForeignMod(ForeignMod { abi, unsafety, .. }) => {
|
||||
ItemKind::ForeignMod(ForeignMod { abi, safety, .. }) => {
|
||||
let old_item = mem::replace(&mut self.extern_mod, Some(item));
|
||||
self.visibility_not_permitted(
|
||||
&item.vis,
|
||||
errors::VisibilityNotPermittedNote::IndividualForeignItems,
|
||||
);
|
||||
if let &Unsafe::Yes(span) = unsafety {
|
||||
if let &Safety::Unsafe(span) = safety {
|
||||
self.dcx().emit_err(errors::UnsafeItem { span, kind: "extern block" });
|
||||
}
|
||||
if abi.is_none() {
|
||||
@@ -1078,8 +1078,8 @@ fn visit_item(&mut self, item: &'a Item) {
|
||||
walk_list!(self, visit_attribute, &item.attrs);
|
||||
return; // Avoid visiting again
|
||||
}
|
||||
ItemKind::Mod(unsafety, mod_kind) => {
|
||||
if let &Unsafe::Yes(span) = unsafety {
|
||||
ItemKind::Mod(safety, mod_kind) => {
|
||||
if let &Safety::Unsafe(span) = safety {
|
||||
self.dcx().emit_err(errors::UnsafeItem { span, kind: "module" });
|
||||
}
|
||||
// Ensure that `path` attributes on modules are recorded as used (cf. issue #35584).
|
||||
|
||||
@@ -524,7 +524,10 @@ fn print_comment(&mut self, cmnt: Comment) {
|
||||
}
|
||||
}
|
||||
|
||||
fn peek_comment<'b>(&'b self) -> Option<&'b Comment> where 'a: 'b {
|
||||
fn peek_comment<'b>(&'b self) -> Option<&'b Comment>
|
||||
where
|
||||
'a: 'b,
|
||||
{
|
||||
self.comments().and_then(|c| c.peek())
|
||||
}
|
||||
|
||||
@@ -1150,7 +1153,7 @@ pub fn print_type(&mut self, ty: &ast::Ty) {
|
||||
self.pclose();
|
||||
}
|
||||
ast::TyKind::BareFn(f) => {
|
||||
self.print_ty_fn(f.ext, f.unsafety, &f.decl, None, &f.generic_params);
|
||||
self.print_ty_fn(f.ext, f.safety, &f.decl, None, &f.generic_params);
|
||||
}
|
||||
ast::TyKind::Path(None, path) => {
|
||||
self.print_path(path, false, 0);
|
||||
@@ -1908,7 +1911,7 @@ fn print_fn_ret_ty(&mut self, fn_ret_ty: &ast::FnRetTy) {
|
||||
fn print_ty_fn(
|
||||
&mut self,
|
||||
ext: ast::Extern,
|
||||
unsafety: ast::Unsafe,
|
||||
safety: ast::Safety,
|
||||
decl: &ast::FnDecl,
|
||||
name: Option<Ident>,
|
||||
generic_params: &[ast::GenericParam],
|
||||
@@ -1924,7 +1927,7 @@ fn print_ty_fn(
|
||||
},
|
||||
span: DUMMY_SP,
|
||||
};
|
||||
let header = ast::FnHeader { unsafety, ext, ..ast::FnHeader::default() };
|
||||
let header = ast::FnHeader { safety, ext, ..ast::FnHeader::default() };
|
||||
self.print_fn(decl, header, name, &generics);
|
||||
self.end();
|
||||
}
|
||||
@@ -1932,7 +1935,7 @@ fn print_ty_fn(
|
||||
fn print_fn_header_info(&mut self, header: ast::FnHeader) {
|
||||
self.print_constness(header.constness);
|
||||
header.coroutine_kind.map(|coroutine_kind| self.print_coroutine_kind(coroutine_kind));
|
||||
self.print_unsafety(header.unsafety);
|
||||
self.print_safety(header.safety);
|
||||
|
||||
match header.ext {
|
||||
ast::Extern::None => {}
|
||||
@@ -1949,10 +1952,10 @@ fn print_fn_header_info(&mut self, header: ast::FnHeader) {
|
||||
self.word("fn")
|
||||
}
|
||||
|
||||
fn print_unsafety(&mut self, s: ast::Unsafe) {
|
||||
fn print_safety(&mut self, s: ast::Safety) {
|
||||
match s {
|
||||
ast::Unsafe::No => {}
|
||||
ast::Unsafe::Yes(_) => self.word_nbsp("unsafe"),
|
||||
ast::Safety::Default => {}
|
||||
ast::Safety::Unsafe(_) => self.word_nbsp("unsafe"),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -198,10 +198,10 @@ pub(crate) fn print_item(&mut self, item: &ast::Item) {
|
||||
&item.attrs,
|
||||
);
|
||||
}
|
||||
ast::ItemKind::Mod(unsafety, mod_kind) => {
|
||||
ast::ItemKind::Mod(safety, mod_kind) => {
|
||||
self.head(Self::to_string(|s| {
|
||||
s.print_visibility(&item.vis);
|
||||
s.print_unsafety(*unsafety);
|
||||
s.print_safety(*safety);
|
||||
s.word("mod");
|
||||
}));
|
||||
self.print_ident(item.ident);
|
||||
@@ -226,7 +226,7 @@ pub(crate) fn print_item(&mut self, item: &ast::Item) {
|
||||
}
|
||||
ast::ItemKind::ForeignMod(nmod) => {
|
||||
self.head(Self::to_string(|s| {
|
||||
s.print_unsafety(nmod.unsafety);
|
||||
s.print_safety(nmod.safety);
|
||||
s.word("extern");
|
||||
}));
|
||||
if let Some(abi) = nmod.abi {
|
||||
@@ -275,7 +275,7 @@ pub(crate) fn print_item(&mut self, item: &ast::Item) {
|
||||
self.print_struct(struct_def, generics, item.ident, item.span, true);
|
||||
}
|
||||
ast::ItemKind::Impl(box ast::Impl {
|
||||
unsafety,
|
||||
safety,
|
||||
polarity,
|
||||
defaultness,
|
||||
constness,
|
||||
@@ -287,7 +287,7 @@ pub(crate) fn print_item(&mut self, item: &ast::Item) {
|
||||
self.head("");
|
||||
self.print_visibility(&item.vis);
|
||||
self.print_defaultness(*defaultness);
|
||||
self.print_unsafety(*unsafety);
|
||||
self.print_safety(*safety);
|
||||
self.word("impl");
|
||||
|
||||
if generics.params.is_empty() {
|
||||
@@ -323,7 +323,7 @@ pub(crate) fn print_item(&mut self, item: &ast::Item) {
|
||||
}
|
||||
ast::ItemKind::Trait(box ast::Trait {
|
||||
is_auto,
|
||||
unsafety,
|
||||
safety,
|
||||
generics,
|
||||
bounds,
|
||||
items,
|
||||
@@ -331,7 +331,7 @@ pub(crate) fn print_item(&mut self, item: &ast::Item) {
|
||||
}) => {
|
||||
self.head("");
|
||||
self.print_visibility(&item.vis);
|
||||
self.print_unsafety(*unsafety);
|
||||
self.print_safety(*safety);
|
||||
self.print_is_auto(*is_auto);
|
||||
self.word_nbsp("trait");
|
||||
self.print_ident(item.ident);
|
||||
|
||||
@@ -24,8 +24,8 @@
|
||||
};
|
||||
use rustc_middle::ty::print::PrintTraitRefExt as _;
|
||||
use rustc_middle::ty::{
|
||||
self, suggest_constraining_type_params, PredicateKind, ToPredicate, Ty, TyCtxt,
|
||||
TypeSuperVisitable, TypeVisitor,
|
||||
self, suggest_constraining_type_params, PredicateKind, Ty, TyCtxt, TypeSuperVisitable,
|
||||
TypeVisitor, Upcast,
|
||||
};
|
||||
use rustc_middle::util::CallKind;
|
||||
use rustc_mir_dataflow::move_paths::{InitKind, MoveOutIndex, MovePathIndex};
|
||||
@@ -1915,7 +1915,7 @@ pub(crate) fn suggest_adding_bounds_or_derive(
|
||||
self.infcx.err_ctxt().suggest_derive(
|
||||
&obligation,
|
||||
err,
|
||||
trait_ref.to_predicate(self.infcx.tcx),
|
||||
trait_ref.upcast(self.infcx.tcx),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
use rustc_infer::traits;
|
||||
use rustc_middle::bug;
|
||||
use rustc_middle::mir::{Mutability, Place, PlaceRef, ProjectionElem};
|
||||
use rustc_middle::ty::{self, InstanceDef, ToPredicate, Ty, TyCtxt};
|
||||
use rustc_middle::ty::{self, InstanceDef, Ty, TyCtxt, Upcast};
|
||||
use rustc_middle::{
|
||||
hir::place::PlaceBase,
|
||||
mir::{self, BindingForm, Local, LocalDecl, LocalInfo, LocalKind, Location},
|
||||
@@ -1255,7 +1255,7 @@ fn suggest_make_local_mut(&self, err: &mut Diag<'_>, local: Local, name: Symbol)
|
||||
self.infcx.err_ctxt().suggest_derive(
|
||||
&obligation,
|
||||
err,
|
||||
trait_ref.to_predicate(self.infcx.tcx),
|
||||
trait_ref.upcast(self.infcx.tcx),
|
||||
);
|
||||
}
|
||||
Some(errors) => {
|
||||
|
||||
@@ -1098,7 +1098,7 @@ fn suggest_deref_closure_return(&self, diag: &mut Diag<'_>) {
|
||||
liberated_sig.inputs().iter().copied(),
|
||||
peeled_ty,
|
||||
liberated_sig.c_variadic,
|
||||
hir::Unsafety::Normal,
|
||||
hir::Safety::Safe,
|
||||
rustc_target::spec::abi::Abi::Rust,
|
||||
)),
|
||||
);
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
use rustc_infer::infer::canonical::Canonical;
|
||||
use rustc_middle::bug;
|
||||
use rustc_middle::mir::ConstraintCategory;
|
||||
use rustc_middle::ty::{self, ToPredicate, Ty, TyCtxt, TypeFoldable};
|
||||
use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable, Upcast};
|
||||
use rustc_span::def_id::DefId;
|
||||
use rustc_span::Span;
|
||||
use rustc_trait_selection::traits::query::type_op::{self, TypeOpOutput};
|
||||
@@ -115,7 +115,7 @@ pub(super) fn normalize_and_prove_instantiated_predicates(
|
||||
|
||||
pub(super) fn prove_predicates(
|
||||
&mut self,
|
||||
predicates: impl IntoIterator<Item: ToPredicate<'tcx> + std::fmt::Debug>,
|
||||
predicates: impl IntoIterator<Item: Upcast<TyCtxt<'tcx>, ty::Predicate<'tcx>> + std::fmt::Debug>,
|
||||
locations: Locations,
|
||||
category: ConstraintCategory<'tcx>,
|
||||
) {
|
||||
@@ -127,12 +127,12 @@ pub(super) fn prove_predicates(
|
||||
#[instrument(skip(self), level = "debug")]
|
||||
pub(super) fn prove_predicate(
|
||||
&mut self,
|
||||
predicate: impl ToPredicate<'tcx> + std::fmt::Debug,
|
||||
predicate: impl Upcast<TyCtxt<'tcx>, ty::Predicate<'tcx>> + std::fmt::Debug,
|
||||
locations: Locations,
|
||||
category: ConstraintCategory<'tcx>,
|
||||
) {
|
||||
let param_env = self.param_env;
|
||||
let predicate = predicate.to_predicate(self.tcx());
|
||||
let predicate = predicate.upcast(self.tcx());
|
||||
let _: Result<_, ErrorGuaranteed> = self.fully_perform_op(
|
||||
locations,
|
||||
category,
|
||||
|
||||
@@ -98,7 +98,7 @@ pub(super) fn check_signature_annotation(&mut self, body: &Body<'tcx>) {
|
||||
user_provided_sig.inputs().iter().copied(),
|
||||
output_ty,
|
||||
user_provided_sig.c_variadic,
|
||||
user_provided_sig.unsafety,
|
||||
user_provided_sig.safety,
|
||||
user_provided_sig.abi,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2007,13 +2007,13 @@ fn check_rvalue(&mut self, body: &Body<'tcx>, rvalue: &Rvalue<'tcx>, location: L
|
||||
}
|
||||
}
|
||||
|
||||
CastKind::PointerCoercion(PointerCoercion::ClosureFnPointer(unsafety)) => {
|
||||
CastKind::PointerCoercion(PointerCoercion::ClosureFnPointer(safety)) => {
|
||||
let sig = match op.ty(body, tcx).kind() {
|
||||
ty::Closure(_, args) => args.as_closure().sig(),
|
||||
_ => bug!(),
|
||||
};
|
||||
let ty_fn_ptr_from =
|
||||
Ty::new_fn_ptr(tcx, tcx.signature_unclosure(sig, *unsafety));
|
||||
Ty::new_fn_ptr(tcx, tcx.signature_unclosure(sig, *safety));
|
||||
|
||||
if let Err(terr) = self.eq_types(
|
||||
*ty,
|
||||
|
||||
@@ -546,7 +546,10 @@ fn param_env(&self) -> ty::ParamEnv<'tcx> {
|
||||
self.type_checker.param_env
|
||||
}
|
||||
|
||||
fn register_predicates(&mut self, obligations: impl IntoIterator<Item: ty::ToPredicate<'tcx>>) {
|
||||
fn register_predicates(
|
||||
&mut self,
|
||||
obligations: impl IntoIterator<Item: ty::Upcast<TyCtxt<'tcx>, ty::Predicate<'tcx>>>,
|
||||
) {
|
||||
self.register_obligations(
|
||||
obligations
|
||||
.into_iter()
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
use rustc_ast::ptr::P;
|
||||
use rustc_ast::{self as ast, FnHeader, FnSig, Generics, StmtKind};
|
||||
use rustc_ast::{Fn, ItemKind, Stmt, TyKind, Unsafe};
|
||||
use rustc_ast::{Fn, ItemKind, Safety, Stmt, TyKind};
|
||||
use rustc_expand::base::{Annotatable, ExtCtxt};
|
||||
use rustc_span::symbol::{kw, sym, Ident};
|
||||
use rustc_span::Span;
|
||||
@@ -78,7 +78,7 @@ fn generate_handler(cx: &ExtCtxt<'_>, handler: Ident, span: Span, sig_span: Span
|
||||
let never = ast::FnRetTy::Ty(cx.ty(span, TyKind::Never));
|
||||
let params = thin_vec![cx.param(span, size, ty_usize.clone()), cx.param(span, align, ty_usize)];
|
||||
let decl = cx.fn_decl(params, never);
|
||||
let header = FnHeader { unsafety: Unsafe::Yes(span), ..FnHeader::default() };
|
||||
let header = FnHeader { safety: Safety::Unsafe(span), ..FnHeader::default() };
|
||||
let sig = FnSig { decl, header, span: span };
|
||||
|
||||
let body = Some(cx.block_expr(call));
|
||||
|
||||
@@ -788,7 +788,7 @@ fn create_derived_impl(
|
||||
Ident::empty(),
|
||||
attrs,
|
||||
ast::ItemKind::Impl(Box::new(ast::Impl {
|
||||
unsafety: ast::Unsafe::No,
|
||||
safety: ast::Safety::Default,
|
||||
polarity: ast::ImplPolarity::Positive,
|
||||
defaultness: ast::Defaultness::Final,
|
||||
constness: if self.is_const { ast::Const::Yes(DUMMY_SP) } else { ast::Const::No },
|
||||
|
||||
@@ -263,13 +263,13 @@ pub enum Num {
|
||||
}
|
||||
|
||||
impl Num {
|
||||
fn from_str(s: &str, arg: Option<&str>) -> Self {
|
||||
fn from_str(s: &str, arg: Option<&str>) -> Option<Self> {
|
||||
if let Some(arg) = arg {
|
||||
Num::Arg(arg.parse().unwrap_or_else(|_| panic!("invalid format arg `{arg:?}`")))
|
||||
arg.parse().ok().map(|arg| Num::Arg(arg))
|
||||
} else if s == "*" {
|
||||
Num::Next
|
||||
Some(Num::Next)
|
||||
} else {
|
||||
Num::Num(s.parse().unwrap_or_else(|_| panic!("invalid format num `{s:?}`")))
|
||||
s.parse().ok().map(|num| Num::Num(num))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -421,7 +421,10 @@ macro_rules! move_to {
|
||||
state = Prec;
|
||||
parameter = None;
|
||||
flags = "";
|
||||
width = Some(Num::from_str(at.slice_between(end).unwrap(), None));
|
||||
width = at.slice_between(end).and_then(|num| Num::from_str(num, None));
|
||||
if width.is_none() {
|
||||
return fallback();
|
||||
}
|
||||
move_to!(end);
|
||||
}
|
||||
// It's invalid, is what it is.
|
||||
@@ -452,7 +455,10 @@ macro_rules! move_to {
|
||||
'1'..='9' => {
|
||||
let end = at_next_cp_while(next, char::is_ascii_digit);
|
||||
state = Prec;
|
||||
width = Some(Num::from_str(at.slice_between(end).unwrap(), None));
|
||||
width = at.slice_between(end).and_then(|num| Num::from_str(num, None));
|
||||
if width.is_none() {
|
||||
return fallback();
|
||||
}
|
||||
move_to!(end);
|
||||
}
|
||||
_ => {
|
||||
@@ -468,7 +474,7 @@ macro_rules! move_to {
|
||||
match end.next_cp() {
|
||||
Some(('$', end2)) => {
|
||||
state = Prec;
|
||||
width = Some(Num::from_str("", Some(at.slice_between(end).unwrap())));
|
||||
width = Num::from_str("", at.slice_between(end));
|
||||
move_to!(end2);
|
||||
}
|
||||
_ => {
|
||||
@@ -500,7 +506,7 @@ macro_rules! move_to {
|
||||
match end.next_cp() {
|
||||
Some(('$', end2)) => {
|
||||
state = Length;
|
||||
precision = Some(Num::from_str("*", next.slice_between(end)));
|
||||
precision = Num::from_str("*", next.slice_between(end));
|
||||
move_to!(end2);
|
||||
}
|
||||
_ => {
|
||||
@@ -513,7 +519,7 @@ macro_rules! move_to {
|
||||
'0'..='9' => {
|
||||
let end = at_next_cp_while(next, char::is_ascii_digit);
|
||||
state = Length;
|
||||
precision = Some(Num::from_str(at.slice_between(end).unwrap(), None));
|
||||
precision = at.slice_between(end).and_then(|num| Num::from_str(num, None));
|
||||
move_to!(end);
|
||||
}
|
||||
_ => return fallback(),
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
};
|
||||
use rustc_ast::ptr::P;
|
||||
use rustc_ast::{self as ast, AttrVec, Expr, FnHeader, FnSig, Generics, Param, StmtKind};
|
||||
use rustc_ast::{Fn, ItemKind, Mutability, Stmt, Ty, TyKind, Unsafe};
|
||||
use rustc_ast::{Fn, ItemKind, Mutability, Safety, Stmt, Ty, TyKind};
|
||||
use rustc_expand::base::{Annotatable, ExtCtxt};
|
||||
use rustc_span::symbol::{kw, sym, Ident, Symbol};
|
||||
use rustc_span::Span;
|
||||
@@ -73,7 +73,7 @@ fn allocator_fn(&self, method: &AllocatorMethod) -> Stmt {
|
||||
let result = self.call_allocator(method.name, args);
|
||||
let output_ty = self.ret_ty(&method.output);
|
||||
let decl = self.cx.fn_decl(abi_args, ast::FnRetTy::Ty(output_ty));
|
||||
let header = FnHeader { unsafety: Unsafe::Yes(self.span), ..FnHeader::default() };
|
||||
let header = FnHeader { safety: Safety::Unsafe(self.span), ..FnHeader::default() };
|
||||
let sig = FnSig { decl, header, span: self.span };
|
||||
let body = Some(self.cx.block_expr(result));
|
||||
let kind = ItemKind::Fn(Box::new(Fn {
|
||||
|
||||
@@ -549,7 +549,7 @@ fn check_test_signature(
|
||||
let has_should_panic_attr = attr::contains_name(&i.attrs, sym::should_panic);
|
||||
let dcx = cx.dcx();
|
||||
|
||||
if let ast::Unsafe::Yes(span) = f.sig.header.unsafety {
|
||||
if let ast::Safety::Unsafe(span) = f.sig.header.safety {
|
||||
return Err(dcx.emit_err(errors::TestBadFn { span: i.span, cause: span, kind: "unsafe" }));
|
||||
}
|
||||
|
||||
|
||||
@@ -872,7 +872,7 @@ pub(crate) fn assert_assignable<'tcx>(
|
||||
let FnSig {
|
||||
inputs_and_output: types_from,
|
||||
c_variadic: c_variadic_from,
|
||||
unsafety: unsafety_from,
|
||||
safety: unsafety_from,
|
||||
abi: abi_from,
|
||||
} = from_sig;
|
||||
let to_sig = fx
|
||||
@@ -881,7 +881,7 @@ pub(crate) fn assert_assignable<'tcx>(
|
||||
let FnSig {
|
||||
inputs_and_output: types_to,
|
||||
c_variadic: c_variadic_to,
|
||||
unsafety: unsafety_to,
|
||||
safety: unsafety_to,
|
||||
abi: abi_to,
|
||||
} = to_sig;
|
||||
let mut types_from = types_from.iter();
|
||||
|
||||
@@ -670,11 +670,7 @@ fn bit_reverse(&mut self, width: u64, value: RValue<'gcc>) -> RValue<'gcc> {
|
||||
let step3 = self.or(left, right);
|
||||
|
||||
// Fourth step.
|
||||
if width == 8 {
|
||||
step3
|
||||
} else {
|
||||
self.gcc_bswap(step3, width)
|
||||
}
|
||||
if width == 8 { step3 } else { self.gcc_bswap(step3, width) }
|
||||
}
|
||||
128 => {
|
||||
// TODO(antoyo): find a more efficient implementation?
|
||||
@@ -1225,7 +1221,7 @@ fn get_rust_try_fn<'a, 'gcc, 'tcx>(
|
||||
iter::once(i8p),
|
||||
tcx.types.unit,
|
||||
false,
|
||||
rustc_hir::Unsafety::Unsafe,
|
||||
rustc_hir::Safety::Unsafe,
|
||||
Abi::Rust,
|
||||
)),
|
||||
);
|
||||
@@ -1236,7 +1232,7 @@ fn get_rust_try_fn<'a, 'gcc, 'tcx>(
|
||||
[i8p, i8p].iter().cloned(),
|
||||
tcx.types.unit,
|
||||
false,
|
||||
rustc_hir::Unsafety::Unsafe,
|
||||
rustc_hir::Safety::Unsafe,
|
||||
Abi::Rust,
|
||||
)),
|
||||
);
|
||||
@@ -1245,7 +1241,7 @@ fn get_rust_try_fn<'a, 'gcc, 'tcx>(
|
||||
[try_fn_ty, i8p, catch_fn_ty],
|
||||
tcx.types.i32,
|
||||
false,
|
||||
rustc_hir::Unsafety::Unsafe,
|
||||
rustc_hir::Safety::Unsafe,
|
||||
Abi::Rust,
|
||||
));
|
||||
let rust_try = gen_fn(cx, "__rust_try", rust_fn_sig, codegen);
|
||||
|
||||
@@ -990,7 +990,7 @@ fn get_rust_try_fn<'ll, 'tcx>(
|
||||
[i8p],
|
||||
tcx.types.unit,
|
||||
false,
|
||||
hir::Unsafety::Unsafe,
|
||||
hir::Safety::Unsafe,
|
||||
Abi::Rust,
|
||||
)),
|
||||
);
|
||||
@@ -1001,7 +1001,7 @@ fn get_rust_try_fn<'ll, 'tcx>(
|
||||
[i8p, i8p],
|
||||
tcx.types.unit,
|
||||
false,
|
||||
hir::Unsafety::Unsafe,
|
||||
hir::Safety::Unsafe,
|
||||
Abi::Rust,
|
||||
)),
|
||||
);
|
||||
@@ -1010,7 +1010,7 @@ fn get_rust_try_fn<'ll, 'tcx>(
|
||||
[try_fn_ty, i8p, catch_fn_ty],
|
||||
tcx.types.i32,
|
||||
false,
|
||||
hir::Unsafety::Unsafe,
|
||||
hir::Safety::Unsafe,
|
||||
Abi::Rust,
|
||||
));
|
||||
let rust_try = gen_fn(cx, "__rust_try", rust_fn_sig, codegen);
|
||||
|
||||
@@ -276,7 +276,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
|
||||
sym::target_feature => {
|
||||
if !tcx.is_closure_like(did.to_def_id())
|
||||
&& let Some(fn_sig) = fn_sig()
|
||||
&& fn_sig.skip_binder().unsafety() == hir::Unsafety::Normal
|
||||
&& fn_sig.skip_binder().safety() == hir::Safety::Safe
|
||||
{
|
||||
if tcx.sess.target.is_like_wasm || tcx.sess.opts.actually_rustdoc {
|
||||
// The `#[target_feature]` attribute is allowed on
|
||||
|
||||
@@ -365,7 +365,7 @@ fn push_debuginfo_type_name<'tcx>(
|
||||
}
|
||||
output.push_str(" (*)(");
|
||||
} else {
|
||||
output.push_str(sig.unsafety.prefix_str());
|
||||
output.push_str(sig.safety.prefix_str());
|
||||
|
||||
if sig.abi != rustc_target::spec::abi::Abi::Rust {
|
||||
output.push_str("extern \"");
|
||||
|
||||
@@ -121,7 +121,11 @@ pub fn codegen_rvalue(
|
||||
bx.write_operand_repeatedly(cg_elem, count, dest);
|
||||
}
|
||||
|
||||
mir::Rvalue::Aggregate(ref kind, ref operands) => {
|
||||
// This implementation does field projection, so never use it for `RawPtr`,
|
||||
// which will always be fine with the `codegen_rvalue_operand` path below.
|
||||
mir::Rvalue::Aggregate(ref kind, ref operands)
|
||||
if !matches!(**kind, mir::AggregateKind::RawPtr(..)) =>
|
||||
{
|
||||
let (variant_index, variant_dest, active_field_index) = match **kind {
|
||||
mir::AggregateKind::Adt(_, variant_index, _, _, active_field_index) => {
|
||||
let variant_dest = dest.project_downcast(bx, variant_index);
|
||||
|
||||
@@ -247,7 +247,10 @@ fn cast_float_to_int(
|
||||
} else {
|
||||
(in_ty, dest_ty)
|
||||
};
|
||||
assert!(matches!(self.cx().type_kind(float_ty), TypeKind::Float | TypeKind::Double));
|
||||
assert!(matches!(
|
||||
self.cx().type_kind(float_ty),
|
||||
TypeKind::Half | TypeKind::Float | TypeKind::Double | TypeKind::FP128
|
||||
));
|
||||
assert_eq!(self.cx().type_kind(int_ty), TypeKind::Integer);
|
||||
|
||||
if let Some(false) = self.cx().sess().opts.unstable_opts.saturating_float_casts {
|
||||
|
||||
@@ -81,8 +81,8 @@ fn is_promotable_const_fn(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
|
||||
if cfg!(debug_assertions) && stab.promotable {
|
||||
let sig = tcx.fn_sig(def_id);
|
||||
assert_eq!(
|
||||
sig.skip_binder().unsafety(),
|
||||
hir::Unsafety::Normal,
|
||||
sig.skip_binder().safety(),
|
||||
hir::Safety::Safe,
|
||||
"don't mark const unsafe fns as promotable",
|
||||
// https://github.com/rust-lang/rust/pull/53851#issuecomment-418760682
|
||||
);
|
||||
|
||||
@@ -112,6 +112,12 @@ fn into_diag_arg(self) -> rustc_errors::DiagArgValue {
|
||||
}
|
||||
}
|
||||
|
||||
impl<I: rustc_type_ir::Interner> IntoDiagArg for rustc_type_ir::FnSig<I> {
|
||||
fn into_diag_arg(self) -> rustc_errors::DiagArgValue {
|
||||
format!("{self:?}").into_diag_arg()
|
||||
}
|
||||
}
|
||||
|
||||
into_diag_arg_for_number!(i8, u8, i16, u16, i32, u32, i64, u64, i128, u128, isize, usize);
|
||||
|
||||
impl IntoDiagArg for bool {
|
||||
|
||||
@@ -10,6 +10,11 @@ expand_attribute_meta_item =
|
||||
expand_attribute_single_word =
|
||||
attribute must only be a single word
|
||||
|
||||
expand_attributes_on_expressions_experimental =
|
||||
attributes on expressions are experimental
|
||||
.help_outer_doc = `///` is used for outer documentation comments; for a plain comment, use `//`
|
||||
.help_inner_doc = `//!` is used for inner documentation comments; for a plain comment, use `//` by removing the `!` or inserting a space in between them: `// !`
|
||||
|
||||
expand_attributes_wrong_form =
|
||||
attribute must be of form: `attributes(foo, bar)`
|
||||
|
||||
|
||||
@@ -382,7 +382,6 @@ pub(crate) fn cfg_true(&self, attr: &Attribute) -> (bool, Option<MetaItem>) {
|
||||
}
|
||||
|
||||
/// If attributes are not allowed on expressions, emit an error for `attr`
|
||||
#[allow(rustc::untranslatable_diagnostic)] // FIXME: make this translatable
|
||||
#[instrument(level = "trace", skip(self))]
|
||||
pub(crate) fn maybe_emit_expr_attr_err(&self, attr: &Attribute) {
|
||||
if self.features.is_some_and(|features| !features.stmt_expr_attributes)
|
||||
@@ -392,11 +391,15 @@ pub(crate) fn maybe_emit_expr_attr_err(&self, attr: &Attribute) {
|
||||
&self.sess,
|
||||
sym::stmt_expr_attributes,
|
||||
attr.span,
|
||||
"attributes on expressions are experimental",
|
||||
crate::fluent_generated::expand_attributes_on_expressions_experimental,
|
||||
);
|
||||
|
||||
if attr.is_doc_comment() {
|
||||
err.help("`///` is for documentation comments. For a plain comment, use `//`.");
|
||||
err.help(if attr.style == AttrStyle::Outer {
|
||||
crate::fluent_generated::expand_help_outer_doc
|
||||
} else {
|
||||
crate::fluent_generated::expand_help_inner_doc
|
||||
});
|
||||
}
|
||||
|
||||
err.emit();
|
||||
|
||||
@@ -55,7 +55,7 @@ pub(super) fn failed_to_match_macro<'cx>(
|
||||
|
||||
let span = token.span.substitute_dummy(sp);
|
||||
|
||||
let mut err = cx.dcx().struct_span_err(span, parse_failure_msg(&token));
|
||||
let mut err = cx.dcx().struct_span_err(span, parse_failure_msg(&token, None));
|
||||
err.span_label(span, label);
|
||||
if !def_span.is_dummy() && !cx.source_map().is_imported(def_span) {
|
||||
err.span_label(cx.source_map().guess_head_span(def_span), "when calling this macro");
|
||||
@@ -200,9 +200,17 @@ fn new(cx: &'a mut ExtCtxt<'cx>, root_span: Span) -> Self {
|
||||
}
|
||||
|
||||
/// Currently used by macro_rules! compilation to extract a little information from the `Failure` case.
|
||||
pub struct FailureForwarder;
|
||||
pub struct FailureForwarder<'matcher> {
|
||||
expected_token: Option<&'matcher Token>,
|
||||
}
|
||||
|
||||
impl<'matcher> Tracker<'matcher> for FailureForwarder {
|
||||
impl<'matcher> FailureForwarder<'matcher> {
|
||||
pub fn new() -> Self {
|
||||
Self { expected_token: None }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'matcher> Tracker<'matcher> for FailureForwarder<'matcher> {
|
||||
type Failure = (Token, usize, &'static str);
|
||||
|
||||
fn build_failure(tok: Token, position: usize, msg: &'static str) -> Self::Failure {
|
||||
@@ -212,6 +220,14 @@ fn build_failure(tok: Token, position: usize, msg: &'static str) -> Self::Failur
|
||||
fn description() -> &'static str {
|
||||
"failure-forwarder"
|
||||
}
|
||||
|
||||
fn set_expected_token(&mut self, tok: &'matcher Token) {
|
||||
self.expected_token = Some(tok);
|
||||
}
|
||||
|
||||
fn get_expected_token(&self) -> Option<&'matcher Token> {
|
||||
self.expected_token
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn emit_frag_parse_err(
|
||||
@@ -320,9 +336,19 @@ pub(super) fn annotate_doc_comment(dcx: &DiagCtxt, err: &mut Diag<'_>, sm: &Sour
|
||||
|
||||
/// Generates an appropriate parsing failure message. For EOF, this is "unexpected end...". For
|
||||
/// other tokens, this is "unexpected token...".
|
||||
pub(super) fn parse_failure_msg(tok: &Token) -> Cow<'static, str> {
|
||||
match tok.kind {
|
||||
token::Eof => Cow::from("unexpected end of macro invocation"),
|
||||
_ => Cow::from(format!("no rules expected the token `{}`", pprust::token_to_string(tok))),
|
||||
pub(super) fn parse_failure_msg(tok: &Token, expected_token: Option<&Token>) -> Cow<'static, str> {
|
||||
if let Some(expected_token) = expected_token {
|
||||
Cow::from(format!(
|
||||
"expected `{}`, found `{}`",
|
||||
pprust::token_to_string(expected_token),
|
||||
pprust::token_to_string(tok),
|
||||
))
|
||||
} else {
|
||||
match tok.kind {
|
||||
token::Eof => Cow::from("unexpected end of macro invocation"),
|
||||
_ => {
|
||||
Cow::from(format!("no rules expected the token `{}`", pprust::token_to_string(tok)))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -541,6 +541,8 @@ fn parse_tt_inner<'matcher, T: Tracker<'matcher>>(
|
||||
// The separator matches the current token. Advance past it.
|
||||
mp.idx += 1;
|
||||
self.next_mps.push(mp);
|
||||
} else {
|
||||
track.set_expected_token(separator);
|
||||
}
|
||||
}
|
||||
&MatcherLoc::SequenceKleeneOpAfterSep { idx_first } => {
|
||||
@@ -632,6 +634,7 @@ pub(super) fn parse_tt<'matcher, T: Tracker<'matcher>>(
|
||||
parser.approx_token_stream_pos(),
|
||||
track,
|
||||
);
|
||||
|
||||
if let Some(res) = res {
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -167,6 +167,11 @@ fn after_arm(&mut self, _result: &NamedParseResult<Self::Failure>) {}
|
||||
fn recovery() -> Recovery {
|
||||
Recovery::Forbidden
|
||||
}
|
||||
|
||||
fn set_expected_token(&mut self, _tok: &'matcher Token) {}
|
||||
fn get_expected_token(&self) -> Option<&'matcher Token> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
/// A noop tracker that is used in the hot path of the expansion, has zero overhead thanks to
|
||||
@@ -447,16 +452,14 @@ pub fn compile_declarative_macro(
|
||||
// For this we need to reclone the macro body as the previous parser consumed it.
|
||||
let retry_parser = create_parser();
|
||||
|
||||
let parse_result = tt_parser.parse_tt(
|
||||
&mut Cow::Owned(retry_parser),
|
||||
&argument_gram,
|
||||
&mut diagnostics::FailureForwarder,
|
||||
);
|
||||
let mut track = diagnostics::FailureForwarder::new();
|
||||
let parse_result =
|
||||
tt_parser.parse_tt(&mut Cow::Owned(retry_parser), &argument_gram, &mut track);
|
||||
let Failure((token, _, msg)) = parse_result else {
|
||||
unreachable!("matcher returned something other than Failure after retry");
|
||||
};
|
||||
|
||||
let s = parse_failure_msg(&token);
|
||||
let s = parse_failure_msg(&token, track.get_expected_token());
|
||||
let sp = token.span.substitute_dummy(def.span);
|
||||
let mut err = sess.dcx().struct_span_err(sp, s);
|
||||
err.span_label(sp, msg);
|
||||
@@ -1290,7 +1293,7 @@ fn is_in_follow(tok: &mbe::TokenTree, kind: NonterminalKind) -> IsInFollow {
|
||||
// maintain
|
||||
IsInFollow::Yes
|
||||
}
|
||||
NonterminalKind::Stmt | NonterminalKind::Expr => {
|
||||
NonterminalKind::Stmt | NonterminalKind::Expr | NonterminalKind::Expr2021 => {
|
||||
const TOKENS: &[&str] = &["`=>`", "`,`", "`;`"];
|
||||
match tok {
|
||||
TokenTree::Token(token) => match token.kind {
|
||||
|
||||
@@ -16,6 +16,10 @@
|
||||
const VALID_FRAGMENT_NAMES_MSG: &str = "valid fragment specifiers are \
|
||||
`ident`, `block`, `stmt`, `expr`, `pat`, `ty`, `lifetime`, \
|
||||
`literal`, `path`, `meta`, `tt`, `item` and `vis`";
|
||||
const VALID_FRAGMENT_NAMES_MSG_2021: &str = "valid fragment specifiers are \
|
||||
`ident`, `block`, `stmt`, `expr`, `expr_2021`, `pat`, \
|
||||
`ty`, `lifetime`, `literal`, `path`, `meta`, `tt`, \
|
||||
`item` and `vis`";
|
||||
|
||||
/// Takes a `tokenstream::TokenStream` and returns a `Vec<self::TokenTree>`. Specifically, this
|
||||
/// takes a generic `TokenStream`, such as is used in the rest of the compiler, and returns a
|
||||
@@ -63,35 +67,60 @@ pub(super) fn parse(
|
||||
Some(tokenstream::TokenTree::Token(token, _)) => match token.ident() {
|
||||
Some((fragment, _)) => {
|
||||
let span = token.span.with_lo(start_sp.lo());
|
||||
|
||||
let edition = || {
|
||||
// FIXME(#85708) - once we properly decode a foreign
|
||||
// crate's `SyntaxContext::root`, then we can replace
|
||||
// this with just `span.edition()`. A
|
||||
// `SyntaxContext::root()` from the current crate will
|
||||
// have the edition of the current crate, and a
|
||||
// `SyntaxContext::root()` from a foreign crate will
|
||||
// have the edition of that crate (which we manually
|
||||
// retrieve via the `edition` parameter).
|
||||
if !span.from_expansion() {
|
||||
edition
|
||||
} else {
|
||||
span.edition()
|
||||
}
|
||||
};
|
||||
let kind =
|
||||
token::NonterminalKind::from_symbol(fragment.name, || {
|
||||
// FIXME(#85708) - once we properly decode a foreign
|
||||
// crate's `SyntaxContext::root`, then we can replace
|
||||
// this with just `span.edition()`. A
|
||||
// `SyntaxContext::root()` from the current crate will
|
||||
// have the edition of the current crate, and a
|
||||
// `SyntaxContext::root()` from a foreign crate will
|
||||
// have the edition of that crate (which we manually
|
||||
// retrieve via the `edition` parameter).
|
||||
if !span.from_expansion() {
|
||||
edition
|
||||
} else {
|
||||
span.edition()
|
||||
}
|
||||
})
|
||||
.unwrap_or_else(
|
||||
|| {
|
||||
token::NonterminalKind::from_symbol(fragment.name, edition)
|
||||
.unwrap_or_else(|| {
|
||||
let help = match fragment.name {
|
||||
sym::expr_2021 => {
|
||||
format!(
|
||||
"fragment specifier `expr_2021` \
|
||||
requires Rust 2021 or later\n\
|
||||
{VALID_FRAGMENT_NAMES_MSG}"
|
||||
)
|
||||
}
|
||||
_ if edition().at_least_rust_2021()
|
||||
&& features
|
||||
.expr_fragment_specifier_2024 =>
|
||||
{
|
||||
VALID_FRAGMENT_NAMES_MSG_2021.into()
|
||||
}
|
||||
_ => VALID_FRAGMENT_NAMES_MSG.into(),
|
||||
};
|
||||
sess.dcx().emit_err(
|
||||
errors::InvalidFragmentSpecifier {
|
||||
span,
|
||||
fragment,
|
||||
help: VALID_FRAGMENT_NAMES_MSG.into(),
|
||||
help,
|
||||
},
|
||||
);
|
||||
token::NonterminalKind::Ident
|
||||
},
|
||||
);
|
||||
});
|
||||
if kind == token::NonterminalKind::Expr2021
|
||||
&& !features.expr_fragment_specifier_2024
|
||||
{
|
||||
rustc_session::parse::feature_err(
|
||||
sess,
|
||||
sym::expr_fragment_specifier_2024,
|
||||
span,
|
||||
"fragment specifier `expr_2021` is unstable",
|
||||
)
|
||||
.emit();
|
||||
}
|
||||
result.push(TokenTree::MetaVarDecl(span, ident, Some(kind)));
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -458,6 +458,8 @@ pub fn internal(&self, feature: Symbol) -> bool {
|
||||
(unstable, exhaustive_patterns, "1.13.0", Some(51085)),
|
||||
/// Allows explicit tail calls via `become` expression.
|
||||
(incomplete, explicit_tail_calls, "1.72.0", Some(112788)),
|
||||
/// Uses 2024 rules for matching `expr` fragments in macros. Also enables `expr_2021` fragment.
|
||||
(incomplete, expr_fragment_specifier_2024, "CURRENT_RUSTC_VERSION", Some(123742)),
|
||||
/// Allows using `efiapi`, `sysv64` and `win64` as calling convention
|
||||
/// for functions with varargs.
|
||||
(unstable, extended_varargs_abi_support, "1.65.0", Some(100189)),
|
||||
|
||||
@@ -2604,7 +2604,7 @@ pub fn from_name(name: Symbol) -> Option<Self> {
|
||||
|
||||
#[derive(Debug, Clone, Copy, HashStable_Generic)]
|
||||
pub struct BareFnTy<'hir> {
|
||||
pub unsafety: Unsafety,
|
||||
pub safety: Safety,
|
||||
pub abi: Abi,
|
||||
pub generic_params: &'hir [GenericParam<'hir>],
|
||||
pub decl: &'hir FnDecl<'hir>,
|
||||
@@ -3172,9 +3172,9 @@ pub fn is_struct_or_union(&self) -> bool {
|
||||
ItemKind::Union(data, gen), (data, gen);
|
||||
|
||||
expect_trait,
|
||||
(IsAuto, Unsafety, &'hir Generics<'hir>, GenericBounds<'hir>, &'hir [TraitItemRef]),
|
||||
ItemKind::Trait(is_auto, unsafety, gen, bounds, items),
|
||||
(*is_auto, *unsafety, gen, bounds, items);
|
||||
(IsAuto, Safety, &'hir Generics<'hir>, GenericBounds<'hir>, &'hir [TraitItemRef]),
|
||||
ItemKind::Trait(is_auto, safety, gen, bounds, items),
|
||||
(*is_auto, *safety, gen, bounds, items);
|
||||
|
||||
expect_trait_alias, (&'hir Generics<'hir>, GenericBounds<'hir>),
|
||||
ItemKind::TraitAlias(gen, bounds), (gen, bounds);
|
||||
@@ -3185,25 +3185,25 @@ pub fn is_struct_or_union(&self) -> bool {
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
|
||||
#[derive(Encodable, Decodable, HashStable_Generic)]
|
||||
pub enum Unsafety {
|
||||
pub enum Safety {
|
||||
Unsafe,
|
||||
Normal,
|
||||
Safe,
|
||||
}
|
||||
|
||||
impl Unsafety {
|
||||
pub fn prefix_str(&self) -> &'static str {
|
||||
impl Safety {
|
||||
pub fn prefix_str(self) -> &'static str {
|
||||
match self {
|
||||
Self::Unsafe => "unsafe ",
|
||||
Self::Normal => "",
|
||||
Self::Safe => "",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for Unsafety {
|
||||
impl fmt::Display for Safety {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.write_str(match *self {
|
||||
Self::Unsafe => "unsafe",
|
||||
Self::Normal => "normal",
|
||||
Self::Safe => "safe",
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -3225,7 +3225,7 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
|
||||
#[derive(Copy, Clone, Debug, HashStable_Generic)]
|
||||
pub struct FnHeader {
|
||||
pub unsafety: Unsafety,
|
||||
pub safety: Safety,
|
||||
pub constness: Constness,
|
||||
pub asyncness: IsAsync,
|
||||
pub abi: Abi,
|
||||
@@ -3241,7 +3241,7 @@ pub fn is_const(&self) -> bool {
|
||||
}
|
||||
|
||||
pub fn is_unsafe(&self) -> bool {
|
||||
matches!(&self.unsafety, Unsafety::Unsafe)
|
||||
matches!(&self.safety, Safety::Unsafe)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3284,7 +3284,7 @@ pub enum ItemKind<'hir> {
|
||||
/// A union definition, e.g., `union Foo<A, B> {x: A, y: B}`.
|
||||
Union(VariantData<'hir>, &'hir Generics<'hir>),
|
||||
/// A trait definition.
|
||||
Trait(IsAuto, Unsafety, &'hir Generics<'hir>, GenericBounds<'hir>, &'hir [TraitItemRef]),
|
||||
Trait(IsAuto, Safety, &'hir Generics<'hir>, GenericBounds<'hir>, &'hir [TraitItemRef]),
|
||||
/// A trait alias.
|
||||
TraitAlias(&'hir Generics<'hir>, GenericBounds<'hir>),
|
||||
|
||||
@@ -3294,7 +3294,7 @@ pub enum ItemKind<'hir> {
|
||||
|
||||
#[derive(Debug, Clone, Copy, HashStable_Generic)]
|
||||
pub struct Impl<'hir> {
|
||||
pub unsafety: Unsafety,
|
||||
pub safety: Safety,
|
||||
pub polarity: ImplPolarity,
|
||||
pub defaultness: Defaultness,
|
||||
// We do not put a `Span` in `Defaultness` because it breaks foreign crate metadata
|
||||
|
||||
@@ -545,7 +545,7 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item<'v>) -> V::
|
||||
try_visit!(visitor.visit_enum_def(enum_definition, item.hir_id()));
|
||||
}
|
||||
ItemKind::Impl(Impl {
|
||||
unsafety: _,
|
||||
safety: _,
|
||||
defaultness: _,
|
||||
polarity: _,
|
||||
defaultness_span: _,
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
//! [`rustc_middle::ty`] form.
|
||||
|
||||
use rustc_hir::LangItem;
|
||||
use rustc_middle::ty::{self, ToPredicate, Ty, TyCtxt};
|
||||
use rustc_middle::ty::{self, Ty, TyCtxt, Upcast};
|
||||
use rustc_span::Span;
|
||||
|
||||
/// Collects together a list of type bounds. These lists of bounds occur in many places
|
||||
@@ -34,7 +34,7 @@ pub fn push_region_bound(
|
||||
span: Span,
|
||||
) {
|
||||
self.clauses
|
||||
.push((region.map_bound(|p| ty::ClauseKind::TypeOutlives(p)).to_predicate(tcx), span));
|
||||
.push((region.map_bound(|p| ty::ClauseKind::TypeOutlives(p)).upcast(tcx), span));
|
||||
}
|
||||
|
||||
pub fn push_trait_bound(
|
||||
@@ -49,7 +49,7 @@ pub fn push_trait_bound(
|
||||
.map_bound(|trait_ref| {
|
||||
ty::ClauseKind::Trait(ty::TraitPredicate { trait_ref, polarity })
|
||||
})
|
||||
.to_predicate(tcx),
|
||||
.upcast(tcx),
|
||||
span,
|
||||
);
|
||||
// FIXME(-Znext-solver): We can likely remove this hack once the new trait solver lands.
|
||||
@@ -67,7 +67,7 @@ pub fn push_projection_bound(
|
||||
span: Span,
|
||||
) {
|
||||
self.clauses.push((
|
||||
projection.map_bound(|proj| ty::ClauseKind::Projection(proj)).to_predicate(tcx),
|
||||
projection.map_bound(|proj| ty::ClauseKind::Projection(proj)).upcast(tcx),
|
||||
span,
|
||||
));
|
||||
}
|
||||
@@ -76,7 +76,7 @@ pub fn push_sized(&mut self, tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, span: Span) {
|
||||
let sized_def_id = tcx.require_lang_item(LangItem::Sized, Some(span));
|
||||
let trait_ref = ty::TraitRef::new(tcx, sized_def_id, [ty]);
|
||||
// Preferable to put this obligation first, since we report better errors for sized ambiguity.
|
||||
self.clauses.insert(0, (trait_ref.to_predicate(tcx), span));
|
||||
self.clauses.insert(0, (trait_ref.upcast(tcx), span));
|
||||
}
|
||||
|
||||
pub fn clauses(&self) -> impl Iterator<Item = (ty::Clause<'tcx>, Span)> + '_ {
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
use rustc_middle::ty::error::{ExpectedFound, TypeError};
|
||||
use rustc_middle::ty::fold::BottomUpFolder;
|
||||
use rustc_middle::ty::util::ExplicitSelf;
|
||||
use rustc_middle::ty::ToPredicate;
|
||||
use rustc_middle::ty::Upcast;
|
||||
use rustc_middle::ty::{
|
||||
self, GenericArgs, Ty, TypeFoldable, TypeFolder, TypeSuperFoldable, TypeVisitableExt,
|
||||
};
|
||||
@@ -2211,7 +2211,7 @@ fn param_env_with_gat_bounds<'tcx>(
|
||||
},
|
||||
bound_vars,
|
||||
)
|
||||
.to_predicate(tcx),
|
||||
.upcast(tcx),
|
||||
),
|
||||
};
|
||||
}
|
||||
@@ -2250,7 +2250,7 @@ fn try_report_async_mismatch<'tcx>(
|
||||
for error in errors {
|
||||
if let ObligationCauseCode::WhereClause(def_id, _) = *error.root_obligation.cause.code()
|
||||
&& def_id == async_future_def_id
|
||||
&& let Some(proj) = error.root_obligation.predicate.to_opt_poly_projection_pred()
|
||||
&& let Some(proj) = error.root_obligation.predicate.as_projection_clause()
|
||||
&& let Some(proj) = proj.no_bound_vars()
|
||||
&& infcx.can_eq(
|
||||
error.root_obligation.param_env,
|
||||
|
||||
@@ -156,7 +156,7 @@ fn main_fn_return_type_span(tcx: TyCtxt<'_>, def_id: DefId) -> Option<Span> {
|
||||
[],
|
||||
expected_return_type,
|
||||
false,
|
||||
hir::Unsafety::Normal,
|
||||
hir::Safety::Safe,
|
||||
Abi::Rust,
|
||||
));
|
||||
|
||||
@@ -252,7 +252,7 @@ fn check_start_fn_ty(tcx: TyCtxt<'_>, start_def_id: DefId) {
|
||||
[tcx.types.isize, Ty::new_imm_ptr(tcx, Ty::new_imm_ptr(tcx, tcx.types.u8))],
|
||||
tcx.types.isize,
|
||||
false,
|
||||
hir::Unsafety::Normal,
|
||||
hir::Safety::Safe,
|
||||
Abi::Rust,
|
||||
));
|
||||
|
||||
|
||||
@@ -71,13 +71,13 @@ fn equate_intrinsic_type<'tcx>(
|
||||
}
|
||||
|
||||
/// Returns the unsafety of the given intrinsic.
|
||||
pub fn intrinsic_operation_unsafety(tcx: TyCtxt<'_>, intrinsic_id: LocalDefId) -> hir::Unsafety {
|
||||
pub fn intrinsic_operation_unsafety(tcx: TyCtxt<'_>, intrinsic_id: LocalDefId) -> hir::Safety {
|
||||
let has_safe_attr = if tcx.has_attr(intrinsic_id, sym::rustc_intrinsic) {
|
||||
tcx.fn_sig(intrinsic_id).skip_binder().unsafety()
|
||||
tcx.fn_sig(intrinsic_id).skip_binder().safety()
|
||||
} else {
|
||||
match tcx.has_attr(intrinsic_id, sym::rustc_safe_intrinsic) {
|
||||
true => hir::Unsafety::Normal,
|
||||
false => hir::Unsafety::Unsafe,
|
||||
true => hir::Safety::Safe,
|
||||
false => hir::Safety::Unsafe,
|
||||
}
|
||||
};
|
||||
let is_in_list = match tcx.item_name(intrinsic_id.into()) {
|
||||
@@ -136,8 +136,8 @@ pub fn intrinsic_operation_unsafety(tcx: TyCtxt<'_>, intrinsic_id: LocalDefId) -
|
||||
| sym::fmul_algebraic
|
||||
| sym::fdiv_algebraic
|
||||
| sym::frem_algebraic
|
||||
| sym::const_eval_select => hir::Unsafety::Normal,
|
||||
_ => hir::Unsafety::Unsafe,
|
||||
| sym::const_eval_select => hir::Safety::Safe,
|
||||
_ => hir::Safety::Unsafe,
|
||||
};
|
||||
|
||||
if has_safe_attr != is_in_list {
|
||||
@@ -197,7 +197,7 @@ pub fn check_intrinsic_type(
|
||||
})
|
||||
};
|
||||
|
||||
let (n_tps, n_lts, n_cts, inputs, output, unsafety) = if name_str.starts_with("atomic_") {
|
||||
let (n_tps, n_lts, n_cts, inputs, output, safety) = if name_str.starts_with("atomic_") {
|
||||
let split: Vec<&str> = name_str.split('_').collect();
|
||||
assert!(split.len() >= 2, "Atomic intrinsic in an incorrect format");
|
||||
|
||||
@@ -219,9 +219,9 @@ pub fn check_intrinsic_type(
|
||||
return;
|
||||
}
|
||||
};
|
||||
(n_tps, 0, 0, inputs, output, hir::Unsafety::Unsafe)
|
||||
(n_tps, 0, 0, inputs, output, hir::Safety::Unsafe)
|
||||
} else {
|
||||
let unsafety = intrinsic_operation_unsafety(tcx, intrinsic_id);
|
||||
let safety = intrinsic_operation_unsafety(tcx, intrinsic_id);
|
||||
let (n_tps, n_cts, inputs, output) = match intrinsic_name {
|
||||
sym::abort => (0, 0, vec![], tcx.types.never),
|
||||
sym::unreachable => (0, 0, vec![], tcx.types.never),
|
||||
@@ -514,14 +514,14 @@ pub fn check_intrinsic_type(
|
||||
[mut_u8],
|
||||
tcx.types.unit,
|
||||
false,
|
||||
hir::Unsafety::Normal,
|
||||
hir::Safety::Safe,
|
||||
Abi::Rust,
|
||||
));
|
||||
let catch_fn_ty = ty::Binder::dummy(tcx.mk_fn_sig(
|
||||
[mut_u8, mut_u8],
|
||||
tcx.types.unit,
|
||||
false,
|
||||
hir::Unsafety::Normal,
|
||||
hir::Safety::Safe,
|
||||
Abi::Rust,
|
||||
));
|
||||
(
|
||||
@@ -656,9 +656,9 @@ pub fn check_intrinsic_type(
|
||||
return;
|
||||
}
|
||||
};
|
||||
(n_tps, 0, n_cts, inputs, output, unsafety)
|
||||
(n_tps, 0, n_cts, inputs, output, safety)
|
||||
};
|
||||
let sig = tcx.mk_fn_sig(inputs, output, false, unsafety, abi);
|
||||
let sig = tcx.mk_fn_sig(inputs, output, false, safety, abi);
|
||||
let sig = ty::Binder::bind_with_vars(sig, bound_vars);
|
||||
equate_intrinsic_type(tcx, span, intrinsic_id, n_tps, n_lts, n_cts, sig)
|
||||
}
|
||||
|
||||
@@ -456,7 +456,7 @@ fn fn_sig_suggestion<'tcx>(
|
||||
|
||||
let output = if !output.is_unit() { format!(" -> {output}") } else { String::new() };
|
||||
|
||||
let unsafety = sig.unsafety.prefix_str();
|
||||
let safety = sig.safety.prefix_str();
|
||||
let (generics, where_clauses) = bounds_from_generic_predicates(tcx, predicates);
|
||||
|
||||
// FIXME: this is not entirely correct, as the lifetimes from borrowed params will
|
||||
@@ -464,9 +464,7 @@ fn fn_sig_suggestion<'tcx>(
|
||||
// lifetimes between the `impl` and the `trait`, but this should be good enough to
|
||||
// fill in a significant portion of the missing code, and other subsequent
|
||||
// suggestions can help the user fix the code.
|
||||
format!(
|
||||
"{unsafety}{asyncness}fn {ident}{generics}({args}){output}{where_clauses} {{ todo!() }}"
|
||||
)
|
||||
format!("{safety}{asyncness}fn {ident}{generics}({args}){output}{where_clauses} {{ todo!() }}")
|
||||
}
|
||||
|
||||
/// Return placeholder code for the given associated item.
|
||||
|
||||
@@ -20,8 +20,8 @@
|
||||
use rustc_middle::ty::print::with_no_trimmed_paths;
|
||||
use rustc_middle::ty::trait_def::TraitSpecializationKind;
|
||||
use rustc_middle::ty::{
|
||||
self, AdtKind, GenericParamDefKind, ToPredicate, Ty, TyCtxt, TypeFoldable, TypeSuperVisitable,
|
||||
TypeVisitable, TypeVisitableExt, TypeVisitor,
|
||||
self, AdtKind, GenericParamDefKind, Ty, TyCtxt, TypeFoldable, TypeSuperVisitable,
|
||||
TypeVisitable, TypeVisitableExt, TypeVisitor, Upcast,
|
||||
};
|
||||
use rustc_middle::ty::{GenericArgKind, GenericArgs};
|
||||
use rustc_middle::{bug, span_bug};
|
||||
@@ -685,7 +685,7 @@ fn gather_gat_bounds<'tcx, T: TypeFoldable<TyCtxt<'tcx>>>(
|
||||
// `Self: 'me`.)
|
||||
bounds.insert(
|
||||
ty::ClauseKind::TypeOutlives(ty::OutlivesPredicate(ty_param, region_param))
|
||||
.to_predicate(tcx),
|
||||
.upcast(tcx),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -730,7 +730,7 @@ fn gather_gat_bounds<'tcx, T: TypeFoldable<TyCtxt<'tcx>>>(
|
||||
region_a_param,
|
||||
region_b_param,
|
||||
))
|
||||
.to_predicate(tcx),
|
||||
.upcast(tcx),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1350,12 +1350,12 @@ fn check_impl<'tcx>(
|
||||
// We already have a better span.
|
||||
continue;
|
||||
}
|
||||
if let Some(pred) = obligation.predicate.to_opt_poly_trait_pred()
|
||||
if let Some(pred) = obligation.predicate.as_trait_clause()
|
||||
&& pred.skip_binder().self_ty() == trait_ref.self_ty()
|
||||
{
|
||||
obligation.cause.span = hir_self_ty.span;
|
||||
}
|
||||
if let Some(pred) = obligation.predicate.to_opt_poly_projection_pred()
|
||||
if let Some(pred) = obligation.predicate.as_projection_clause()
|
||||
&& pred.skip_binder().self_ty() == trait_ref.self_ty()
|
||||
{
|
||||
obligation.cause.span = hir_self_ty.span;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
//! crate or pertains to a type defined in this crate.
|
||||
|
||||
use rustc_errors::{codes::*, struct_span_code_err};
|
||||
use rustc_hir::Unsafety;
|
||||
use rustc_hir::Safety;
|
||||
use rustc_middle::ty::print::PrintTraitRefExt as _;
|
||||
use rustc_middle::ty::{ImplPolarity::*, ImplTraitHeader, TraitDef, TyCtxt};
|
||||
use rustc_span::def_id::LocalDefId;
|
||||
@@ -18,8 +18,8 @@ pub(super) fn check_item(
|
||||
tcx.generics_of(def_id).own_params.iter().find(|p| p.pure_wrt_drop).map(|_| "may_dangle");
|
||||
let trait_ref = trait_header.trait_ref.instantiate_identity();
|
||||
|
||||
match (trait_def.unsafety, unsafe_attr, trait_header.unsafety, trait_header.polarity) {
|
||||
(Unsafety::Normal, None, Unsafety::Unsafe, Positive | Reservation) => {
|
||||
match (trait_def.safety, unsafe_attr, trait_header.safety, trait_header.polarity) {
|
||||
(Safety::Safe, None, Safety::Unsafe, Positive | Reservation) => {
|
||||
let span = tcx.def_span(def_id);
|
||||
return Err(struct_span_code_err!(
|
||||
tcx.dcx(),
|
||||
@@ -37,7 +37,7 @@ pub(super) fn check_item(
|
||||
.emit());
|
||||
}
|
||||
|
||||
(Unsafety::Unsafe, _, Unsafety::Normal, Positive | Reservation) => {
|
||||
(Safety::Unsafe, _, Safety::Safe, Positive | Reservation) => {
|
||||
let span = tcx.def_span(def_id);
|
||||
return Err(struct_span_code_err!(
|
||||
tcx.dcx(),
|
||||
@@ -61,7 +61,7 @@ pub(super) fn check_item(
|
||||
.emit());
|
||||
}
|
||||
|
||||
(Unsafety::Normal, Some(attr_name), Unsafety::Normal, Positive | Reservation) => {
|
||||
(Safety::Safe, Some(attr_name), Safety::Safe, Positive | Reservation) => {
|
||||
let span = tcx.def_span(def_id);
|
||||
return Err(struct_span_code_err!(
|
||||
tcx.dcx(),
|
||||
@@ -85,14 +85,14 @@ pub(super) fn check_item(
|
||||
.emit());
|
||||
}
|
||||
|
||||
(_, _, Unsafety::Unsafe, Negative) => {
|
||||
(_, _, Safety::Unsafe, Negative) => {
|
||||
// Reported in AST validation
|
||||
assert!(tcx.dcx().has_errors().is_some(), "unsafe negative impl");
|
||||
Ok(())
|
||||
}
|
||||
(_, _, Unsafety::Normal, Negative)
|
||||
| (Unsafety::Unsafe, _, Unsafety::Unsafe, Positive | Reservation)
|
||||
| (Unsafety::Normal, Some(_), Unsafety::Unsafe, Positive | Reservation)
|
||||
| (Unsafety::Normal, None, Unsafety::Normal, _) => Ok(()),
|
||||
(_, _, Safety::Safe, Negative)
|
||||
| (Safety::Unsafe, _, Safety::Unsafe, Positive | Reservation)
|
||||
| (Safety::Safe, Some(_), Safety::Unsafe, Positive | Reservation)
|
||||
| (Safety::Safe, None, Safety::Safe, _) => Ok(()),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
use rustc_middle::hir::nested_filter;
|
||||
use rustc_middle::query::Providers;
|
||||
use rustc_middle::ty::util::{Discr, IntTypeExt};
|
||||
use rustc_middle::ty::{self, AdtKind, Const, IsSuggestable, ToPredicate, Ty, TyCtxt};
|
||||
use rustc_middle::ty::{self, AdtKind, Const, IsSuggestable, Ty, TyCtxt, Upcast};
|
||||
use rustc_middle::{bug, span_bug};
|
||||
use rustc_span::symbol::{kw, sym, Ident, Symbol};
|
||||
use rustc_span::{Span, DUMMY_SP};
|
||||
@@ -1102,11 +1102,11 @@ fn adt_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::AdtDef<'_> {
|
||||
fn trait_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::TraitDef {
|
||||
let item = tcx.hir().expect_item(def_id);
|
||||
|
||||
let (is_auto, unsafety, items) = match item.kind {
|
||||
hir::ItemKind::Trait(is_auto, unsafety, .., items) => {
|
||||
(is_auto == hir::IsAuto::Yes, unsafety, items)
|
||||
let (is_auto, safety, items) = match item.kind {
|
||||
hir::ItemKind::Trait(is_auto, safety, .., items) => {
|
||||
(is_auto == hir::IsAuto::Yes, safety, items)
|
||||
}
|
||||
hir::ItemKind::TraitAlias(..) => (false, hir::Unsafety::Normal, &[][..]),
|
||||
hir::ItemKind::TraitAlias(..) => (false, hir::Safety::Safe, &[][..]),
|
||||
_ => span_bug!(item.span, "trait_def_of_item invoked on non-trait"),
|
||||
};
|
||||
|
||||
@@ -1247,7 +1247,7 @@ fn trait_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::TraitDef {
|
||||
|
||||
ty::TraitDef {
|
||||
def_id: def_id.to_def_id(),
|
||||
unsafety,
|
||||
safety,
|
||||
paren_sugar,
|
||||
has_auto_impl: is_auto,
|
||||
is_marker,
|
||||
@@ -1286,7 +1286,7 @@ fn fn_sig(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<ty::PolyFnSig<
|
||||
{
|
||||
icx.lowerer().lower_fn_ty(
|
||||
hir_id,
|
||||
sig.header.unsafety,
|
||||
sig.header.safety,
|
||||
sig.header.abi,
|
||||
sig.decl,
|
||||
Some(generics),
|
||||
@@ -1301,14 +1301,9 @@ fn fn_sig(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<ty::PolyFnSig<
|
||||
kind: TraitItemKind::Fn(FnSig { header, decl, span: _ }, _),
|
||||
generics,
|
||||
..
|
||||
}) => icx.lowerer().lower_fn_ty(
|
||||
hir_id,
|
||||
header.unsafety,
|
||||
header.abi,
|
||||
decl,
|
||||
Some(generics),
|
||||
None,
|
||||
),
|
||||
}) => {
|
||||
icx.lowerer().lower_fn_ty(hir_id, header.safety, header.abi, decl, Some(generics), None)
|
||||
}
|
||||
|
||||
ForeignItem(&hir::ForeignItem { kind: ForeignItemKind::Fn(fn_decl, _, _), .. }) => {
|
||||
let abi = tcx.hir().get_foreign_abi(hir_id);
|
||||
@@ -1321,8 +1316,8 @@ fn fn_sig(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<ty::PolyFnSig<
|
||||
let inputs = data.fields().iter().map(|f| tcx.type_of(f.def_id).instantiate_identity());
|
||||
// constructors for structs with `layout_scalar_valid_range` are unsafe to call
|
||||
let safety = match tcx.layout_scalar_valid_range(adt_def_id) {
|
||||
(Bound::Unbounded, Bound::Unbounded) => hir::Unsafety::Normal,
|
||||
_ => hir::Unsafety::Unsafe,
|
||||
(Bound::Unbounded, Bound::Unbounded) => hir::Safety::Safe,
|
||||
_ => hir::Safety::Unsafe,
|
||||
};
|
||||
ty::Binder::dummy(tcx.mk_fn_sig(inputs, ty, false, safety, abi::Abi::Rust))
|
||||
}
|
||||
@@ -1409,13 +1404,13 @@ fn infer_return_ty_for_fn_sig<'tcx>(
|
||||
fn_sig.inputs().iter().copied(),
|
||||
recovered_ret_ty.unwrap_or_else(|| Ty::new_error(tcx, guar)),
|
||||
fn_sig.c_variadic,
|
||||
fn_sig.unsafety,
|
||||
fn_sig.safety,
|
||||
fn_sig.abi,
|
||||
))
|
||||
}
|
||||
None => icx.lowerer().lower_fn_ty(
|
||||
hir_id,
|
||||
sig.header.unsafety,
|
||||
sig.header.safety,
|
||||
sig.header.abi,
|
||||
sig.decl,
|
||||
Some(generics),
|
||||
@@ -1574,7 +1569,7 @@ fn impl_trait_header(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<ty::ImplTrai
|
||||
};
|
||||
ty::ImplTraitHeader {
|
||||
trait_ref: ty::EarlyBinder::bind(trait_ref),
|
||||
unsafety: impl_.unsafety,
|
||||
safety: impl_.safety,
|
||||
polarity: polarity_of_impl(tcx, def_id, impl_, item.span)
|
||||
}
|
||||
})
|
||||
@@ -1665,7 +1660,7 @@ fn predicates_defined_on(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredicate
|
||||
def_id, inferred_outlives,
|
||||
);
|
||||
let inferred_outlives_iter =
|
||||
inferred_outlives.iter().map(|(clause, span)| ((*clause).to_predicate(tcx), *span));
|
||||
inferred_outlives.iter().map(|(clause, span)| ((*clause).upcast(tcx), *span));
|
||||
if result.predicates.is_empty() {
|
||||
result.predicates = tcx.arena.alloc_from_iter(inferred_outlives_iter);
|
||||
} else {
|
||||
@@ -1685,14 +1680,14 @@ fn compute_sig_of_foreign_fn_decl<'tcx>(
|
||||
decl: &'tcx hir::FnDecl<'tcx>,
|
||||
abi: abi::Abi,
|
||||
) -> ty::PolyFnSig<'tcx> {
|
||||
let unsafety = if abi == abi::Abi::RustIntrinsic {
|
||||
let safety = if abi == abi::Abi::RustIntrinsic {
|
||||
intrinsic_operation_unsafety(tcx, def_id)
|
||||
} else {
|
||||
hir::Unsafety::Unsafe
|
||||
hir::Safety::Unsafe
|
||||
};
|
||||
let hir_id = tcx.local_def_id_to_hir_id(def_id);
|
||||
let fty =
|
||||
ItemCtxt::new(tcx, def_id).lowerer().lower_fn_ty(hir_id, unsafety, abi, decl, None, None);
|
||||
ItemCtxt::new(tcx, def_id).lowerer().lower_fn_ty(hir_id, safety, abi, decl, None, None);
|
||||
|
||||
// Feature gate SIMD types in FFI, since I am not sure that the
|
||||
// ABIs are handled at all correctly. -huonw
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
use rustc_hir::def_id::{DefId, LocalDefId};
|
||||
use rustc_hir::intravisit::{self, Visitor};
|
||||
use rustc_middle::ty::{self, Ty, TyCtxt};
|
||||
use rustc_middle::ty::{GenericPredicates, ImplTraitInTraitData, ToPredicate};
|
||||
use rustc_middle::ty::{GenericPredicates, ImplTraitInTraitData, Upcast};
|
||||
use rustc_middle::{bug, span_bug};
|
||||
use rustc_span::symbol::Ident;
|
||||
use rustc_span::{Span, DUMMY_SP};
|
||||
@@ -40,11 +40,13 @@ pub(super) fn predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredic
|
||||
// `tcx.def_span(def_id);`
|
||||
let span = DUMMY_SP;
|
||||
|
||||
result.predicates =
|
||||
tcx.arena.alloc_from_iter(result.predicates.iter().copied().chain(std::iter::once((
|
||||
ty::TraitRef::identity(tcx, def_id).to_predicate(tcx),
|
||||
span,
|
||||
))));
|
||||
result.predicates = tcx.arena.alloc_from_iter(
|
||||
result
|
||||
.predicates
|
||||
.iter()
|
||||
.copied()
|
||||
.chain(std::iter::once((ty::TraitRef::identity(tcx, def_id).upcast(tcx), span))),
|
||||
);
|
||||
}
|
||||
debug!("predicates_of(def_id={:?}) = {:?}", def_id, result);
|
||||
result
|
||||
@@ -165,7 +167,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
|
||||
// (see below). Recall that a default impl is not itself an impl, but rather a
|
||||
// set of defaults that can be incorporated into another impl.
|
||||
if let Some(trait_ref) = is_default_impl_trait {
|
||||
predicates.insert((trait_ref.to_predicate(tcx), tcx.def_span(def_id)));
|
||||
predicates.insert((trait_ref.upcast(tcx), tcx.def_span(def_id)));
|
||||
}
|
||||
|
||||
// Collect the predicates that were written inline by the user on each
|
||||
@@ -196,10 +198,8 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
|
||||
.no_bound_vars()
|
||||
.expect("const parameters cannot be generic");
|
||||
let ct = icx.lowerer().lower_const_param(param.hir_id, ct_ty);
|
||||
predicates.insert((
|
||||
ty::ClauseKind::ConstArgHasType(ct, ct_ty).to_predicate(tcx),
|
||||
param.span,
|
||||
));
|
||||
predicates
|
||||
.insert((ty::ClauseKind::ConstArgHasType(ct, ct_ty).upcast(tcx), param.span));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -228,7 +228,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
|
||||
ty::ClauseKind::WellFormed(ty.into()),
|
||||
bound_vars,
|
||||
);
|
||||
predicates.insert((predicate.to_predicate(tcx), span));
|
||||
predicates.insert((predicate.upcast(tcx), span));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -257,8 +257,8 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
|
||||
)
|
||||
}
|
||||
};
|
||||
let pred = ty::ClauseKind::RegionOutlives(ty::OutlivesPredicate(r1, r2))
|
||||
.to_predicate(tcx);
|
||||
let pred =
|
||||
ty::ClauseKind::RegionOutlives(ty::OutlivesPredicate(r1, r2)).upcast(tcx);
|
||||
(pred, span)
|
||||
}))
|
||||
}
|
||||
@@ -328,12 +328,12 @@ fn compute_bidirectional_outlives_predicates<'tcx>(
|
||||
let span = tcx.def_span(param.def_id);
|
||||
predicates.push((
|
||||
ty::ClauseKind::RegionOutlives(ty::OutlivesPredicate(orig_lifetime, dup_lifetime))
|
||||
.to_predicate(tcx),
|
||||
.upcast(tcx),
|
||||
span,
|
||||
));
|
||||
predicates.push((
|
||||
ty::ClauseKind::RegionOutlives(ty::OutlivesPredicate(dup_lifetime, orig_lifetime))
|
||||
.to_predicate(tcx),
|
||||
.upcast(tcx),
|
||||
span,
|
||||
));
|
||||
}
|
||||
@@ -354,8 +354,7 @@ fn visit_anon_const(&mut self, c: &'tcx hir::AnonConst) {
|
||||
let ct = ty::Const::from_anon_const(self.tcx, c.def_id);
|
||||
if let ty::ConstKind::Unevaluated(_) = ct.kind() {
|
||||
let span = self.tcx.def_span(c.def_id);
|
||||
self.preds
|
||||
.insert((ty::ClauseKind::ConstEvaluatable(ct).to_predicate(self.tcx), span));
|
||||
self.preds.insert((ty::ClauseKind::ConstEvaluatable(ct).upcast(self.tcx), span));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -694,7 +693,7 @@ pub(super) fn type_param_predicates(
|
||||
&& param_id == item_hir_id
|
||||
{
|
||||
let identity_trait_ref = ty::TraitRef::identity(tcx, item_def_id.to_def_id());
|
||||
extend = Some((identity_trait_ref.to_predicate(tcx), item.span));
|
||||
extend = Some((identity_trait_ref.upcast(tcx), item.span));
|
||||
}
|
||||
|
||||
let icx = ItemCtxt::new(tcx, item_def_id);
|
||||
|
||||
@@ -2080,14 +2080,7 @@ fn lower_ty_common(&self, hir_ty: &hir::Ty<'tcx>, borrowed: bool, in_path: bool)
|
||||
|
||||
Ty::new_fn_ptr(
|
||||
tcx,
|
||||
self.lower_fn_ty(
|
||||
hir_ty.hir_id,
|
||||
bf.unsafety,
|
||||
bf.abi,
|
||||
bf.decl,
|
||||
None,
|
||||
Some(hir_ty),
|
||||
),
|
||||
self.lower_fn_ty(hir_ty.hir_id, bf.safety, bf.abi, bf.decl, None, Some(hir_ty)),
|
||||
)
|
||||
}
|
||||
hir::TyKind::TraitObject(bounds, lifetime, repr) => {
|
||||
@@ -2309,11 +2302,11 @@ pub fn lower_arg_ty(&self, ty: &hir::Ty<'tcx>, expected_ty: Option<Ty<'tcx>>) ->
|
||||
}
|
||||
|
||||
/// Lower a function type from the HIR to our internal notion of a function signature.
|
||||
#[instrument(level = "debug", skip(self, hir_id, unsafety, abi, decl, generics, hir_ty), ret)]
|
||||
#[instrument(level = "debug", skip(self, hir_id, safety, abi, decl, generics, hir_ty), ret)]
|
||||
pub fn lower_fn_ty(
|
||||
&self,
|
||||
hir_id: HirId,
|
||||
unsafety: hir::Unsafety,
|
||||
safety: hir::Safety,
|
||||
abi: abi::Abi,
|
||||
decl: &hir::FnDecl<'tcx>,
|
||||
generics: Option<&hir::Generics<'_>>,
|
||||
@@ -2376,7 +2369,7 @@ pub fn lower_fn_ty(
|
||||
|
||||
debug!(?output_ty);
|
||||
|
||||
let fn_ty = tcx.mk_fn_sig(input_tys, output_ty, decl.c_variadic, unsafety, abi);
|
||||
let fn_ty = tcx.mk_fn_sig(input_tys, output_ty, decl.c_variadic, safety, abi);
|
||||
let bare_fn_ty = ty::Binder::bind_with_vars(fn_ty, bound_vars);
|
||||
|
||||
if !self.allow_infer() && !(visitor.0.is_empty() && infer_replacements.is_empty()) {
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
use rustc_middle::span_bug;
|
||||
use rustc_middle::ty::fold::BottomUpFolder;
|
||||
use rustc_middle::ty::{self, ExistentialPredicateStableCmpExt as _, Ty, TyCtxt, TypeFoldable};
|
||||
use rustc_middle::ty::{DynKind, ToPredicate};
|
||||
use rustc_middle::ty::{DynKind, Upcast};
|
||||
use rustc_span::{ErrorGuaranteed, Span};
|
||||
use rustc_trait_selection::traits::error_reporting::report_object_safety_error;
|
||||
use rustc_trait_selection::traits::{self, hir_ty_lowering_object_safety_violations};
|
||||
@@ -119,7 +119,7 @@ pub(super) fn lower_trait_object_ty(
|
||||
.filter(|(trait_ref, _)| !tcx.trait_is_auto(trait_ref.def_id()));
|
||||
|
||||
for (base_trait_ref, span) in regular_traits_refs_spans {
|
||||
let base_pred: ty::Predicate<'tcx> = base_trait_ref.to_predicate(tcx);
|
||||
let base_pred: ty::Predicate<'tcx> = base_trait_ref.upcast(tcx);
|
||||
for pred in traits::elaborate(tcx, [base_pred]).filter_only_self() {
|
||||
debug!("observing object predicate `{pred:?}`");
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
use rustc_hir::def_id::LocalDefId;
|
||||
use rustc_middle::query::Providers;
|
||||
use rustc_middle::ty::GenericArgKind;
|
||||
use rustc_middle::ty::{self, CratePredicatesMap, ToPredicate, TyCtxt};
|
||||
use rustc_middle::ty::{self, CratePredicatesMap, TyCtxt, Upcast};
|
||||
use rustc_span::Span;
|
||||
|
||||
mod explicit;
|
||||
@@ -75,14 +75,14 @@ fn inferred_outlives_crate(tcx: TyCtxt<'_>, (): ()) -> CratePredicatesMap<'_> {
|
||||
match kind1.unpack() {
|
||||
GenericArgKind::Type(ty1) => Some((
|
||||
ty::ClauseKind::TypeOutlives(ty::OutlivesPredicate(ty1, *region2))
|
||||
.to_predicate(tcx),
|
||||
.upcast(tcx),
|
||||
span,
|
||||
)),
|
||||
GenericArgKind::Lifetime(region1) => Some((
|
||||
ty::ClauseKind::RegionOutlives(ty::OutlivesPredicate(
|
||||
region1, *region2,
|
||||
))
|
||||
.to_predicate(tcx),
|
||||
.upcast(tcx),
|
||||
span,
|
||||
)),
|
||||
GenericArgKind::Const(_) => {
|
||||
|
||||
@@ -287,7 +287,7 @@ fn print_type(&mut self, ty: &hir::Ty<'_>) {
|
||||
self.pclose();
|
||||
}
|
||||
hir::TyKind::BareFn(f) => {
|
||||
self.print_ty_fn(f.abi, f.unsafety, f.decl, None, f.generic_params, f.param_names);
|
||||
self.print_ty_fn(f.abi, f.safety, f.decl, None, f.generic_params, f.param_names);
|
||||
}
|
||||
hir::TyKind::OpaqueDef(..) => self.word("/*impl Trait*/"),
|
||||
hir::TyKind::Path(ref qpath) => self.print_qpath(qpath, false),
|
||||
@@ -351,7 +351,7 @@ fn print_foreign_item(&mut self, item: &hir::ForeignItem<'_>) {
|
||||
self.print_fn(
|
||||
decl,
|
||||
hir::FnHeader {
|
||||
unsafety: hir::Unsafety::Normal,
|
||||
safety: hir::Safety::Safe,
|
||||
constness: hir::Constness::NotConst,
|
||||
abi: Abi::Rust,
|
||||
asyncness: hir::IsAsync::NotAsync,
|
||||
@@ -582,7 +582,7 @@ fn print_item(&mut self, item: &hir::Item<'_>) {
|
||||
self.print_struct(struct_def, generics, item.ident.name, item.span, true);
|
||||
}
|
||||
hir::ItemKind::Impl(&hir::Impl {
|
||||
unsafety,
|
||||
safety,
|
||||
polarity,
|
||||
defaultness,
|
||||
defaultness_span: _,
|
||||
@@ -593,7 +593,7 @@ fn print_item(&mut self, item: &hir::Item<'_>) {
|
||||
}) => {
|
||||
self.head("");
|
||||
self.print_defaultness(defaultness);
|
||||
self.print_unsafety(unsafety);
|
||||
self.print_safety(safety);
|
||||
self.word_nbsp("impl");
|
||||
|
||||
if !generics.params.is_empty() {
|
||||
@@ -622,10 +622,10 @@ fn print_item(&mut self, item: &hir::Item<'_>) {
|
||||
}
|
||||
self.bclose(item.span);
|
||||
}
|
||||
hir::ItemKind::Trait(is_auto, unsafety, generics, bounds, trait_items) => {
|
||||
hir::ItemKind::Trait(is_auto, safety, generics, bounds, trait_items) => {
|
||||
self.head("");
|
||||
self.print_is_auto(is_auto);
|
||||
self.print_unsafety(unsafety);
|
||||
self.print_safety(safety);
|
||||
self.word_nbsp("trait");
|
||||
self.print_ident(item.ident);
|
||||
self.print_generic_params(generics.params);
|
||||
@@ -2234,7 +2234,7 @@ fn print_fn_output(&mut self, decl: &hir::FnDecl<'_>) {
|
||||
fn print_ty_fn(
|
||||
&mut self,
|
||||
abi: Abi,
|
||||
unsafety: hir::Unsafety,
|
||||
safety: hir::Safety,
|
||||
decl: &hir::FnDecl<'_>,
|
||||
name: Option<Symbol>,
|
||||
generic_params: &[hir::GenericParam<'_>],
|
||||
@@ -2246,7 +2246,7 @@ fn print_ty_fn(
|
||||
self.print_fn(
|
||||
decl,
|
||||
hir::FnHeader {
|
||||
unsafety,
|
||||
safety,
|
||||
abi,
|
||||
constness: hir::Constness::NotConst,
|
||||
asyncness: hir::IsAsync::NotAsync,
|
||||
@@ -2267,7 +2267,7 @@ fn print_fn_header_info(&mut self, header: hir::FnHeader) {
|
||||
hir::IsAsync::Async(_) => self.word_nbsp("async"),
|
||||
}
|
||||
|
||||
self.print_unsafety(header.unsafety);
|
||||
self.print_safety(header.safety);
|
||||
|
||||
if header.abi != Abi::Rust {
|
||||
self.word_nbsp("extern");
|
||||
@@ -2284,10 +2284,10 @@ fn print_constness(&mut self, s: hir::Constness) {
|
||||
}
|
||||
}
|
||||
|
||||
fn print_unsafety(&mut self, s: hir::Unsafety) {
|
||||
fn print_safety(&mut self, s: hir::Safety) {
|
||||
match s {
|
||||
hir::Unsafety::Normal => {}
|
||||
hir::Unsafety::Unsafe => self.word_nbsp("unsafe"),
|
||||
hir::Safety::Safe => {}
|
||||
hir::Safety::Unsafe => self.word_nbsp("unsafe"),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -201,7 +201,7 @@ fn try_overloaded_call_step(
|
||||
tupled_upvars_ty,
|
||||
),
|
||||
coroutine_closure_sig.c_variadic,
|
||||
coroutine_closure_sig.unsafety,
|
||||
coroutine_closure_sig.safety,
|
||||
coroutine_closure_sig.abi,
|
||||
);
|
||||
let adjustments = self.adjust_steps(autoderef);
|
||||
|
||||
@@ -216,7 +216,7 @@ fn check_panic_info_fn(tcx: TyCtxt<'_>, fn_id: LocalDefId, fn_sig: ty::FnSig<'_>
|
||||
ty::BoundVariableKind::Region(ty::BrAnon),
|
||||
]);
|
||||
let expected_sig = ty::Binder::bind_with_vars(
|
||||
tcx.mk_fn_sig([panic_info_ref_ty], tcx.types.never, false, fn_sig.unsafety, Abi::Rust),
|
||||
tcx.mk_fn_sig([panic_info_ref_ty], tcx.types.never, false, fn_sig.safety, Abi::Rust),
|
||||
bounds,
|
||||
);
|
||||
|
||||
@@ -239,7 +239,7 @@ fn check_lang_start_fn<'tcx>(tcx: TyCtxt<'tcx>, fn_sig: ty::FnSig<'tcx>, def_id:
|
||||
let generic_ty = Ty::new_param(tcx, fn_generic.index, fn_generic.name);
|
||||
let main_fn_ty = Ty::new_fn_ptr(
|
||||
tcx,
|
||||
Binder::dummy(tcx.mk_fn_sig([], generic_ty, false, hir::Unsafety::Normal, Abi::Rust)),
|
||||
Binder::dummy(tcx.mk_fn_sig([], generic_ty, false, hir::Safety::Safe, Abi::Rust)),
|
||||
);
|
||||
|
||||
let expected_sig = ty::Binder::dummy(tcx.mk_fn_sig(
|
||||
@@ -251,7 +251,7 @@ fn check_lang_start_fn<'tcx>(tcx: TyCtxt<'tcx>, fn_sig: ty::FnSig<'tcx>, def_id:
|
||||
],
|
||||
tcx.types.isize,
|
||||
false,
|
||||
fn_sig.unsafety,
|
||||
fn_sig.safety,
|
||||
Abi::Rust,
|
||||
));
|
||||
|
||||
|
||||
@@ -89,7 +89,7 @@ pub fn check_expr_closure(
|
||||
[Ty::new_tup(tcx, sig.inputs())],
|
||||
sig.output(),
|
||||
sig.c_variadic,
|
||||
sig.unsafety,
|
||||
sig.safety,
|
||||
sig.abi,
|
||||
)
|
||||
});
|
||||
@@ -238,7 +238,7 @@ pub fn check_expr_closure(
|
||||
],
|
||||
Ty::new_tup(tcx, &[bound_yield_ty, bound_return_ty]),
|
||||
sig.c_variadic,
|
||||
sig.unsafety,
|
||||
sig.safety,
|
||||
sig.abi,
|
||||
)
|
||||
}),
|
||||
@@ -281,7 +281,7 @@ pub fn check_expr_closure(
|
||||
liberated_sig.inputs().iter().copied(),
|
||||
coroutine_output_ty,
|
||||
liberated_sig.c_variadic,
|
||||
liberated_sig.unsafety,
|
||||
liberated_sig.safety,
|
||||
liberated_sig.abi,
|
||||
);
|
||||
|
||||
@@ -493,7 +493,7 @@ fn deduce_sig_from_projection(
|
||||
input_tys,
|
||||
ret_param_ty,
|
||||
false,
|
||||
hir::Unsafety::Normal,
|
||||
hir::Safety::Safe,
|
||||
Abi::Rust,
|
||||
));
|
||||
|
||||
@@ -605,7 +605,7 @@ fn sig_of_closure_with_expectation(
|
||||
sig.inputs().iter().cloned(),
|
||||
sig.output(),
|
||||
sig.c_variadic,
|
||||
hir::Unsafety::Normal,
|
||||
hir::Safety::Safe,
|
||||
Abi::RustCall,
|
||||
)
|
||||
});
|
||||
@@ -743,7 +743,7 @@ fn merge_supplied_sig_with_expectation(
|
||||
inputs,
|
||||
supplied_output_ty,
|
||||
expected_sigs.liberated_sig.c_variadic,
|
||||
hir::Unsafety::Normal,
|
||||
hir::Safety::Safe,
|
||||
Abi::RustCall,
|
||||
);
|
||||
|
||||
@@ -820,7 +820,7 @@ fn supplied_sig_of_closure(
|
||||
supplied_arguments,
|
||||
supplied_return,
|
||||
decl.c_variadic,
|
||||
hir::Unsafety::Normal,
|
||||
hir::Safety::Safe,
|
||||
Abi::RustCall,
|
||||
),
|
||||
bound_vars,
|
||||
@@ -984,7 +984,7 @@ fn error_sig_of_closure(
|
||||
supplied_arguments,
|
||||
err_ty,
|
||||
decl.c_variadic,
|
||||
hir::Unsafety::Normal,
|
||||
hir::Safety::Safe,
|
||||
Abi::RustCall,
|
||||
));
|
||||
|
||||
|
||||
@@ -788,8 +788,8 @@ fn coerce_from_safe_fn<F, G>(
|
||||
let outer_universe = self.infcx.universe();
|
||||
|
||||
let result = if let ty::FnPtr(fn_ty_b) = b.kind()
|
||||
&& let (hir::Unsafety::Normal, hir::Unsafety::Unsafe) =
|
||||
(fn_ty_a.unsafety(), fn_ty_b.unsafety())
|
||||
&& let (hir::Safety::Safe, hir::Safety::Unsafe) =
|
||||
(fn_ty_a.safety(), fn_ty_b.safety())
|
||||
{
|
||||
let unsafe_a = self.tcx.safe_to_unsafe_fn_ty(fn_ty_a);
|
||||
self.unify_and(unsafe_a, b, to_unsafe)
|
||||
@@ -851,7 +851,7 @@ fn coerce_from_fn_item(&self, a: Ty<'tcx>, b: Ty<'tcx>) -> CoerceResult<'tcx> {
|
||||
|
||||
// Safe `#[target_feature]` functions are not assignable to safe fn pointers (RFC 2396).
|
||||
|
||||
if b_sig.unsafety() == hir::Unsafety::Normal
|
||||
if b_sig.safety() == hir::Safety::Safe
|
||||
&& !self.tcx.codegen_fn_attrs(def_id).target_features.is_empty()
|
||||
{
|
||||
return Err(TypeError::TargetFeatureCast(def_id));
|
||||
@@ -922,14 +922,14 @@ fn coerce_closure_to_fn(
|
||||
// or
|
||||
// `unsafe fn(arg0,arg1,...) -> _`
|
||||
let closure_sig = args_a.as_closure().sig();
|
||||
let unsafety = fn_ty.unsafety();
|
||||
let safety = fn_ty.safety();
|
||||
let pointer_ty =
|
||||
Ty::new_fn_ptr(self.tcx, self.tcx.signature_unclosure(closure_sig, unsafety));
|
||||
Ty::new_fn_ptr(self.tcx, self.tcx.signature_unclosure(closure_sig, safety));
|
||||
debug!("coerce_closure_to_fn(a={:?}, b={:?}, pty={:?})", a, b, pointer_ty);
|
||||
self.unify_and(
|
||||
pointer_ty,
|
||||
b,
|
||||
simple(Adjust::Pointer(PointerCoercion::ClosureFnPointer(unsafety))),
|
||||
simple(Adjust::Pointer(PointerCoercion::ClosureFnPointer(safety))),
|
||||
)
|
||||
}
|
||||
_ => self.unify_and(a, b, identity),
|
||||
@@ -1126,27 +1126,25 @@ fn try_find_coercion_lub<E>(
|
||||
(ty::Closure(_, args), ty::FnDef(..)) => {
|
||||
let b_sig = new_ty.fn_sig(self.tcx);
|
||||
let a_sig =
|
||||
self.tcx.signature_unclosure(args.as_closure().sig(), b_sig.unsafety());
|
||||
self.tcx.signature_unclosure(args.as_closure().sig(), b_sig.safety());
|
||||
(Some(a_sig), Some(b_sig))
|
||||
}
|
||||
(ty::FnDef(..), ty::Closure(_, args)) => {
|
||||
let a_sig = prev_ty.fn_sig(self.tcx);
|
||||
let b_sig =
|
||||
self.tcx.signature_unclosure(args.as_closure().sig(), a_sig.unsafety());
|
||||
self.tcx.signature_unclosure(args.as_closure().sig(), a_sig.safety());
|
||||
(Some(a_sig), Some(b_sig))
|
||||
}
|
||||
(ty::Closure(_, args_a), ty::Closure(_, args_b)) => {
|
||||
(
|
||||
Some(self.tcx.signature_unclosure(
|
||||
args_a.as_closure().sig(),
|
||||
hir::Unsafety::Normal,
|
||||
)),
|
||||
Some(self.tcx.signature_unclosure(
|
||||
args_b.as_closure().sig(),
|
||||
hir::Unsafety::Normal,
|
||||
)),
|
||||
)
|
||||
}
|
||||
(ty::Closure(_, args_a), ty::Closure(_, args_b)) => (
|
||||
Some(
|
||||
self.tcx
|
||||
.signature_unclosure(args_a.as_closure().sig(), hir::Safety::Safe),
|
||||
),
|
||||
Some(
|
||||
self.tcx
|
||||
.signature_unclosure(args_b.as_closure().sig(), hir::Safety::Safe),
|
||||
),
|
||||
),
|
||||
_ => (None, None),
|
||||
}
|
||||
}
|
||||
@@ -1168,14 +1166,14 @@ fn try_find_coercion_lub<E>(
|
||||
let fn_ptr = Ty::new_fn_ptr(self.tcx, sig);
|
||||
let prev_adjustment = match prev_ty.kind() {
|
||||
ty::Closure(..) => {
|
||||
Adjust::Pointer(PointerCoercion::ClosureFnPointer(a_sig.unsafety()))
|
||||
Adjust::Pointer(PointerCoercion::ClosureFnPointer(a_sig.safety()))
|
||||
}
|
||||
ty::FnDef(..) => Adjust::Pointer(PointerCoercion::ReifyFnPointer),
|
||||
_ => span_bug!(cause.span, "should not try to coerce a {prev_ty} to a fn pointer"),
|
||||
};
|
||||
let next_adjustment = match new_ty.kind() {
|
||||
ty::Closure(..) => {
|
||||
Adjust::Pointer(PointerCoercion::ClosureFnPointer(b_sig.unsafety()))
|
||||
Adjust::Pointer(PointerCoercion::ClosureFnPointer(b_sig.safety()))
|
||||
}
|
||||
ty::FnDef(..) => Adjust::Pointer(PointerCoercion::ReifyFnPointer),
|
||||
_ => span_bug!(new.span, "should not try to coerce a {new_ty} to a fn pointer"),
|
||||
|
||||
@@ -558,7 +558,7 @@ fn visit_expr(&mut self, ex: &'_ hir::Expr<'_>) {
|
||||
if let Some(def_id) = typeck_results.type_dependent_def_id(ex.hir_id)
|
||||
&& let method_ty = self.root_ctxt.tcx.type_of(def_id).instantiate_identity()
|
||||
&& let sig = method_ty.fn_sig(self.root_ctxt.tcx)
|
||||
&& let hir::Unsafety::Unsafe = sig.unsafety()
|
||||
&& let hir::Safety::Unsafe = sig.safety()
|
||||
{
|
||||
let mut collector = InferVarCollector {
|
||||
value: (ex.hir_id, ex.span, UnsafeUseReason::Method),
|
||||
@@ -578,7 +578,7 @@ fn visit_expr(&mut self, ex: &'_ hir::Expr<'_>) {
|
||||
|
||||
if func_ty.is_fn()
|
||||
&& let sig = func_ty.fn_sig(self.root_ctxt.tcx)
|
||||
&& let hir::Unsafety::Unsafe = sig.unsafety()
|
||||
&& let hir::Safety::Unsafe = sig.safety()
|
||||
{
|
||||
let mut collector = InferVarCollector {
|
||||
value: (ex.hir_id, ex.span, UnsafeUseReason::Call),
|
||||
@@ -609,7 +609,7 @@ fn visit_expr(&mut self, ex: &'_ hir::Expr<'_>) {
|
||||
// `is_fn` excludes closures, but those can't be unsafe.
|
||||
if ty.is_fn()
|
||||
&& let sig = ty.fn_sig(self.root_ctxt.tcx)
|
||||
&& let hir::Unsafety::Unsafe = sig.unsafety()
|
||||
&& let hir::Safety::Unsafe = sig.safety()
|
||||
{
|
||||
let mut collector = InferVarCollector {
|
||||
value: (ex.hir_id, ex.span, UnsafeUseReason::Path),
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//! A utility module to inspect currently ambiguous obligations in the current context.
|
||||
use crate::FnCtxt;
|
||||
use rustc_infer::traits::solve::Goal;
|
||||
use rustc_infer::traits::{self, ObligationCause};
|
||||
use rustc_middle::traits::solve::Goal;
|
||||
use rustc_middle::ty::{self, Ty, TypeVisitableExt};
|
||||
use rustc_span::Span;
|
||||
use rustc_trait_selection::solve::inspect::ProofTreeInferCtxtExt;
|
||||
|
||||
@@ -28,8 +28,8 @@
|
||||
use rustc_middle::span_bug;
|
||||
use rustc_middle::ty::print::with_no_trimmed_paths;
|
||||
use rustc_middle::ty::{
|
||||
self, suggest_constraining_type_params, Article, Binder, IsSuggestable, ToPredicate, Ty,
|
||||
TypeVisitableExt,
|
||||
self, suggest_constraining_type_params, Article, Binder, IsSuggestable, Ty, TypeVisitableExt,
|
||||
Upcast,
|
||||
};
|
||||
use rustc_session::errors::ExprParenthesesNeeded;
|
||||
use rustc_span::source_map::Spanned;
|
||||
@@ -1716,7 +1716,7 @@ pub(crate) fn note_type_is_not_clone(
|
||||
}
|
||||
}
|
||||
}
|
||||
self.suggest_derive(diag, &[(trait_ref.to_predicate(self.tcx), None, None)]);
|
||||
self.suggest_derive(diag, &[(trait_ref.upcast(self.tcx), None, None)]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -145,7 +145,7 @@ fn typeck_with_fallback<'tcx>(
|
||||
|
||||
if let Some(hir::FnSig { header, decl, .. }) = node.fn_sig() {
|
||||
let fn_sig = if decl.output.get_infer_ret_ty().is_some() {
|
||||
fcx.lowerer().lower_fn_ty(id, header.unsafety, header.abi, decl, None, None)
|
||||
fcx.lowerer().lower_fn_ty(id, header.safety, header.abi, decl, None, None)
|
||||
} else {
|
||||
tcx.fn_sig(def_id).instantiate_identity()
|
||||
};
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
use rustc_middle::ty::fast_reject::{simplify_type, TreatParams};
|
||||
use rustc_middle::ty::AssocItem;
|
||||
use rustc_middle::ty::GenericParamDefKind;
|
||||
use rustc_middle::ty::ToPredicate;
|
||||
use rustc_middle::ty::Upcast;
|
||||
use rustc_middle::ty::{self, ParamEnvAnd, Ty, TyCtxt, TypeVisitableExt};
|
||||
use rustc_middle::ty::{GenericArgs, GenericArgsRef};
|
||||
use rustc_middle::{bug, span_bug};
|
||||
@@ -1496,7 +1496,7 @@ fn consider_probe(
|
||||
}
|
||||
}
|
||||
|
||||
trait_predicate = Some(ty::Binder::dummy(trait_ref).to_predicate(self.tcx));
|
||||
trait_predicate = Some(trait_ref.upcast(self.tcx));
|
||||
}
|
||||
ObjectCandidate(poly_trait_ref) | WhereClauseCandidate(poly_trait_ref) => {
|
||||
let trait_ref = self.instantiate_binder_with_fresh_vars(
|
||||
|
||||
@@ -583,7 +583,7 @@ fn check_overloaded_binop(
|
||||
if !errors.is_empty() {
|
||||
for error in errors {
|
||||
if let Some(trait_pred) =
|
||||
error.obligation.predicate.to_opt_poly_trait_pred()
|
||||
error.obligation.predicate.as_trait_clause()
|
||||
{
|
||||
let output_associated_item = match error.obligation.cause.code()
|
||||
{
|
||||
@@ -797,9 +797,9 @@ pub fn check_user_unop(
|
||||
);
|
||||
|
||||
if operand_ty.has_non_region_param() {
|
||||
let predicates = errors.iter().filter_map(|error| {
|
||||
error.obligation.predicate.to_opt_poly_trait_pred()
|
||||
});
|
||||
let predicates = errors
|
||||
.iter()
|
||||
.filter_map(|error| error.obligation.predicate.as_trait_clause());
|
||||
for pred in predicates {
|
||||
self.err_ctxt().suggest_restricting_param_bound(
|
||||
&mut err,
|
||||
|
||||
@@ -419,7 +419,7 @@ fn analyze_closure(
|
||||
[],
|
||||
tupled_upvars_ty_for_borrow,
|
||||
false,
|
||||
hir::Unsafety::Normal,
|
||||
hir::Safety::Safe,
|
||||
rustc_target::spec::abi::Abi::Rust,
|
||||
),
|
||||
self.tcx.mk_bound_variable_kinds(&[ty::BoundVariableKind::Region(
|
||||
|
||||
@@ -385,19 +385,31 @@ fn to_trace(
|
||||
a: Self,
|
||||
b: Self,
|
||||
) -> TypeTrace<'tcx> {
|
||||
use GenericArgKind::*;
|
||||
TypeTrace {
|
||||
cause: cause.clone(),
|
||||
values: match (a.unpack(), b.unpack()) {
|
||||
(Lifetime(a), Lifetime(b)) => Regions(ExpectedFound::new(a_is_expected, a, b)),
|
||||
(Type(a), Type(b)) => Terms(ExpectedFound::new(a_is_expected, a.into(), b.into())),
|
||||
(Const(a), Const(b)) => {
|
||||
(GenericArgKind::Lifetime(a), GenericArgKind::Lifetime(b)) => {
|
||||
Regions(ExpectedFound::new(a_is_expected, a, b))
|
||||
}
|
||||
(GenericArgKind::Type(a), GenericArgKind::Type(b)) => {
|
||||
Terms(ExpectedFound::new(a_is_expected, a.into(), b.into()))
|
||||
}
|
||||
(GenericArgKind::Const(a), GenericArgKind::Const(b)) => {
|
||||
Terms(ExpectedFound::new(a_is_expected, a.into(), b.into()))
|
||||
}
|
||||
|
||||
(Lifetime(_), Type(_) | Const(_))
|
||||
| (Type(_), Lifetime(_) | Const(_))
|
||||
| (Const(_), Lifetime(_) | Type(_)) => {
|
||||
(
|
||||
GenericArgKind::Lifetime(_),
|
||||
GenericArgKind::Type(_) | GenericArgKind::Const(_),
|
||||
)
|
||||
| (
|
||||
GenericArgKind::Type(_),
|
||||
GenericArgKind::Lifetime(_) | GenericArgKind::Const(_),
|
||||
)
|
||||
| (
|
||||
GenericArgKind::Const(_),
|
||||
GenericArgKind::Lifetime(_) | GenericArgKind::Type(_),
|
||||
) => {
|
||||
bug!("relating different kinds: {a:?} {b:?}")
|
||||
}
|
||||
},
|
||||
|
||||
@@ -73,7 +73,7 @@
|
||||
use rustc_middle::dep_graph::DepContext;
|
||||
use rustc_middle::ty::print::{with_forced_trimmed_paths, PrintError, PrintTraitRefExt as _};
|
||||
use rustc_middle::ty::relate::{self, RelateResult, TypeRelation};
|
||||
use rustc_middle::ty::ToPredicate;
|
||||
use rustc_middle::ty::Upcast;
|
||||
use rustc_middle::ty::{
|
||||
self, error::TypeError, IsSuggestable, List, Region, Ty, TyCtxt, TypeFoldable,
|
||||
TypeSuperVisitable, TypeVisitable, TypeVisitableExt,
|
||||
@@ -516,7 +516,7 @@ pub fn report_region_errors(
|
||||
|
||||
RegionResolutionError::CannotNormalize(clause, origin) => {
|
||||
let clause: ty::Clause<'tcx> =
|
||||
clause.map_bound(ty::ClauseKind::TypeOutlives).to_predicate(self.tcx);
|
||||
clause.map_bound(ty::ClauseKind::TypeOutlives).upcast(self.tcx);
|
||||
self.tcx
|
||||
.dcx()
|
||||
.struct_span_err(origin.span(), format!("cannot normalize `{clause}`"))
|
||||
@@ -1053,8 +1053,8 @@ fn cmp_fn_sig(
|
||||
|
||||
// unsafe extern "C" for<'a> fn(&'a T) -> &'a T
|
||||
// ^^^^^^
|
||||
values.0.push(sig1.unsafety.prefix_str(), sig1.unsafety != sig2.unsafety);
|
||||
values.1.push(sig2.unsafety.prefix_str(), sig1.unsafety != sig2.unsafety);
|
||||
values.0.push(sig1.safety.prefix_str(), sig1.safety != sig2.safety);
|
||||
values.1.push(sig2.safety.prefix_str(), sig1.safety != sig2.safety);
|
||||
|
||||
// unsafe extern "C" for<'a> fn(&'a T) -> &'a T
|
||||
// ^^^^^^^^^^
|
||||
@@ -1928,7 +1928,7 @@ enum Similar<'tcx> {
|
||||
self.tcx
|
||||
.signature_unclosure(
|
||||
args.as_closure().sig(),
|
||||
rustc_hir::Unsafety::Normal,
|
||||
rustc_hir::Safety::Safe,
|
||||
)
|
||||
.to_string(),
|
||||
),
|
||||
|
||||
@@ -168,7 +168,7 @@ fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
|
||||
let closure_sig = args.as_closure().sig();
|
||||
Ty::new_fn_ptr(
|
||||
self.tcx,
|
||||
self.tcx.signature_unclosure(closure_sig, hir::Unsafety::Normal),
|
||||
self.tcx.signature_unclosure(closure_sig, hir::Safety::Safe),
|
||||
)
|
||||
}
|
||||
_ => ty.super_fold_with(self),
|
||||
|
||||
+2
-4
@@ -409,10 +409,8 @@ fn explain_actual_impl_that_was_found(
|
||||
{
|
||||
let closure_sig = self_ty.map(|closure| {
|
||||
if let ty::Closure(_, args) = closure.kind() {
|
||||
self.tcx().signature_unclosure(
|
||||
args.as_closure().sig(),
|
||||
rustc_hir::Unsafety::Normal,
|
||||
)
|
||||
self.tcx()
|
||||
.signature_unclosure(args.as_closure().sig(), rustc_hir::Safety::Safe)
|
||||
} else {
|
||||
bug!("type is not longer closure");
|
||||
}
|
||||
|
||||
@@ -452,7 +452,7 @@ fn foo(&self, x: T) -> T { x }
|
||||
}
|
||||
(ty::FnPtr(sig), ty::FnDef(def_id, _))
|
||||
| (ty::FnDef(def_id, _), ty::FnPtr(sig)) => {
|
||||
if tcx.fn_sig(def_id).skip_binder().unsafety() < sig.unsafety() {
|
||||
if tcx.fn_sig(def_id).skip_binder().safety() < sig.safety() {
|
||||
diag.note(
|
||||
"unsafe functions cannot be coerced into safe function pointers",
|
||||
);
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
use rustc_middle::infer::unify_key::EffectVarValue;
|
||||
use rustc_middle::ty::error::{ExpectedFound, TypeError};
|
||||
use rustc_middle::ty::relate::{RelateResult, TypeRelation};
|
||||
use rustc_middle::ty::{self, InferConst, ToPredicate, Ty, TyCtxt, TypeVisitableExt};
|
||||
use rustc_middle::ty::{self, InferConst, Ty, TyCtxt, TypeVisitableExt, Upcast};
|
||||
use rustc_middle::ty::{IntType, UintType};
|
||||
use rustc_span::Span;
|
||||
|
||||
@@ -337,7 +337,10 @@ pub fn register_obligations(&mut self, obligations: PredicateObligations<'tcx>)
|
||||
self.obligations.extend(obligations);
|
||||
}
|
||||
|
||||
pub fn register_predicates(&mut self, obligations: impl IntoIterator<Item: ToPredicate<'tcx>>) {
|
||||
pub fn register_predicates(
|
||||
&mut self,
|
||||
obligations: impl IntoIterator<Item: Upcast<TyCtxt<'tcx>, ty::Predicate<'tcx>>>,
|
||||
) {
|
||||
self.obligations.extend(obligations.into_iter().map(|to_pred| {
|
||||
Obligation::new(self.infcx.tcx, self.trace.cause.clone(), self.param_env, to_pred)
|
||||
}))
|
||||
@@ -360,7 +363,10 @@ pub trait ObligationEmittingRelation<'tcx>: TypeRelation<'tcx> {
|
||||
/// Register predicates that must hold in order for this relation to hold. Uses
|
||||
/// a default obligation cause, [`ObligationEmittingRelation::register_obligations`] should
|
||||
/// be used if control over the obligation causes is required.
|
||||
fn register_predicates(&mut self, obligations: impl IntoIterator<Item: ToPredicate<'tcx>>);
|
||||
fn register_predicates(
|
||||
&mut self,
|
||||
obligations: impl IntoIterator<Item: Upcast<TyCtxt<'tcx>, ty::Predicate<'tcx>>>,
|
||||
);
|
||||
|
||||
/// Register `AliasRelate` obligation(s) that both types must be related to each other.
|
||||
fn register_type_relate_obligation(&mut self, a: Ty<'tcx>, b: Ty<'tcx>);
|
||||
|
||||
@@ -140,7 +140,10 @@ fn param_env(&self) -> ty::ParamEnv<'tcx> {
|
||||
self.fields.param_env
|
||||
}
|
||||
|
||||
fn register_predicates(&mut self, obligations: impl IntoIterator<Item: ty::ToPredicate<'tcx>>) {
|
||||
fn register_predicates(
|
||||
&mut self,
|
||||
obligations: impl IntoIterator<Item: ty::Upcast<TyCtxt<'tcx>, ty::Predicate<'tcx>>>,
|
||||
) {
|
||||
self.fields.register_predicates(obligations);
|
||||
}
|
||||
|
||||
|
||||
@@ -140,7 +140,10 @@ fn param_env(&self) -> ty::ParamEnv<'tcx> {
|
||||
self.fields.param_env
|
||||
}
|
||||
|
||||
fn register_predicates(&mut self, obligations: impl IntoIterator<Item: ty::ToPredicate<'tcx>>) {
|
||||
fn register_predicates(
|
||||
&mut self,
|
||||
obligations: impl IntoIterator<Item: ty::Upcast<TyCtxt<'tcx>, ty::Predicate<'tcx>>>,
|
||||
) {
|
||||
self.fields.register_predicates(obligations);
|
||||
}
|
||||
|
||||
|
||||
@@ -312,7 +312,10 @@ fn structurally_relate_aliases(&self) -> StructurallyRelateAliases {
|
||||
self.structurally_relate_aliases
|
||||
}
|
||||
|
||||
fn register_predicates(&mut self, obligations: impl IntoIterator<Item: ty::ToPredicate<'tcx>>) {
|
||||
fn register_predicates(
|
||||
&mut self,
|
||||
obligations: impl IntoIterator<Item: ty::Upcast<TyCtxt<'tcx>, ty::Predicate<'tcx>>>,
|
||||
) {
|
||||
self.fields.register_predicates(obligations);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
use crate::traits::Obligation;
|
||||
use rustc_hir::def_id::DefId;
|
||||
use rustc_macros::extension;
|
||||
use rustc_middle::ty::{self, ToPredicate, Ty};
|
||||
use rustc_middle::ty::{self, Ty, Upcast};
|
||||
|
||||
use super::FulfillmentError;
|
||||
use super::{ObligationCause, PredicateObligation};
|
||||
@@ -26,7 +26,7 @@ fn register_bound(
|
||||
cause,
|
||||
recursion_depth: 0,
|
||||
param_env,
|
||||
predicate: ty::Binder::dummy(trait_ref).to_predicate(infcx.tcx),
|
||||
predicate: trait_ref.upcast(infcx.tcx),
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
use rustc_middle::traits::query::NoSolution;
|
||||
use rustc_middle::traits::solve::Certainty;
|
||||
use rustc_middle::ty::error::{ExpectedFound, TypeError};
|
||||
use rustc_middle::ty::{self, Const, ToPredicate, Ty, TyCtxt};
|
||||
use rustc_middle::ty::{self, Const, Ty, TyCtxt, Upcast};
|
||||
use rustc_span::Span;
|
||||
|
||||
pub use self::ImplSource::*;
|
||||
@@ -155,7 +155,7 @@ pub fn new(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
cause: ObligationCause<'tcx>,
|
||||
param_env: ty::ParamEnv<'tcx>,
|
||||
predicate: impl ToPredicate<'tcx, O>,
|
||||
predicate: impl Upcast<TyCtxt<'tcx>, O>,
|
||||
) -> Obligation<'tcx, O> {
|
||||
Self::with_depth(tcx, cause, 0, param_env, predicate)
|
||||
}
|
||||
@@ -173,9 +173,9 @@ pub fn with_depth(
|
||||
cause: ObligationCause<'tcx>,
|
||||
recursion_depth: usize,
|
||||
param_env: ty::ParamEnv<'tcx>,
|
||||
predicate: impl ToPredicate<'tcx, O>,
|
||||
predicate: impl Upcast<TyCtxt<'tcx>, O>,
|
||||
) -> Obligation<'tcx, O> {
|
||||
let predicate = predicate.to_predicate(tcx);
|
||||
let predicate = predicate.upcast(tcx);
|
||||
Obligation { cause, param_env, recursion_depth, predicate }
|
||||
}
|
||||
|
||||
@@ -184,7 +184,7 @@ pub fn misc(
|
||||
span: Span,
|
||||
body_id: LocalDefId,
|
||||
param_env: ty::ParamEnv<'tcx>,
|
||||
trait_ref: impl ToPredicate<'tcx, O>,
|
||||
trait_ref: impl Upcast<TyCtxt<'tcx>, O>,
|
||||
) -> Obligation<'tcx, O> {
|
||||
Obligation::new(tcx, ObligationCause::misc(span, body_id), param_env, trait_ref)
|
||||
}
|
||||
@@ -192,7 +192,7 @@ pub fn misc(
|
||||
pub fn with<P>(
|
||||
&self,
|
||||
tcx: TyCtxt<'tcx>,
|
||||
value: impl ToPredicate<'tcx, P>,
|
||||
value: impl Upcast<TyCtxt<'tcx>, P>,
|
||||
) -> Obligation<'tcx, P> {
|
||||
Obligation::with_depth(tcx, self.cause.clone(), self.recursion_depth, self.param_env, value)
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
use crate::infer::outlives::components::{push_outlives_components, Component};
|
||||
use crate::traits::{self, Obligation, ObligationCauseCode, PredicateObligation};
|
||||
use rustc_data_structures::fx::FxHashSet;
|
||||
use rustc_middle::ty::{self, ToPredicate, Ty, TyCtxt};
|
||||
use rustc_middle::ty::{self, Ty, TyCtxt, Upcast};
|
||||
use rustc_span::symbol::Ident;
|
||||
use rustc_span::Span;
|
||||
|
||||
@@ -357,9 +357,7 @@ fn elaborate(&mut self, elaboratable: &O) {
|
||||
None
|
||||
}
|
||||
})
|
||||
.map(|clause| {
|
||||
elaboratable.child(bound_clause.rebind(clause).to_predicate(tcx))
|
||||
}),
|
||||
.map(|clause| elaboratable.child(bound_clause.rebind(clause).upcast(tcx))),
|
||||
);
|
||||
}
|
||||
ty::ClauseKind::RegionOutlives(..) => {
|
||||
@@ -409,14 +407,14 @@ pub fn supertraits<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
trait_ref: ty::PolyTraitRef<'tcx>,
|
||||
) -> FilterToTraits<Elaborator<'tcx, ty::Predicate<'tcx>>> {
|
||||
elaborate(tcx, [trait_ref.to_predicate(tcx)]).filter_only_self().filter_to_traits()
|
||||
elaborate(tcx, [trait_ref.upcast(tcx)]).filter_only_self().filter_to_traits()
|
||||
}
|
||||
|
||||
pub fn transitive_bounds<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
trait_refs: impl Iterator<Item = ty::PolyTraitRef<'tcx>>,
|
||||
) -> FilterToTraits<Elaborator<'tcx, ty::Predicate<'tcx>>> {
|
||||
elaborate(tcx, trait_refs.map(|trait_ref| trait_ref.to_predicate(tcx)))
|
||||
elaborate(tcx, trait_refs.map(|trait_ref| trait_ref.upcast(tcx)))
|
||||
.filter_only_self()
|
||||
.filter_to_traits()
|
||||
}
|
||||
@@ -431,7 +429,7 @@ pub fn transitive_bounds_that_define_assoc_item<'tcx>(
|
||||
trait_refs: impl Iterator<Item = ty::PolyTraitRef<'tcx>>,
|
||||
assoc_name: Ident,
|
||||
) -> FilterToTraits<Elaborator<'tcx, ty::Predicate<'tcx>>> {
|
||||
elaborate(tcx, trait_refs.map(|trait_ref| trait_ref.to_predicate(tcx)))
|
||||
elaborate(tcx, trait_refs.map(|trait_ref| trait_ref.upcast(tcx)))
|
||||
.filter_only_self_that_defines(assoc_name)
|
||||
.filter_to_traits()
|
||||
}
|
||||
@@ -457,7 +455,7 @@ impl<'tcx, I: Iterator<Item = ty::Predicate<'tcx>>> Iterator for FilterToTraits<
|
||||
|
||||
fn next(&mut self) -> Option<ty::PolyTraitRef<'tcx>> {
|
||||
while let Some(pred) = self.base_iterator.next() {
|
||||
if let Some(data) = pred.to_opt_poly_trait_pred() {
|
||||
if let Some(data) = pred.as_trait_clause() {
|
||||
return Some(data.map_bound(|t| t.trait_ref));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,8 +57,8 @@
|
||||
use rustc_middle::ty::layout::LayoutOf;
|
||||
use rustc_middle::ty::print::with_no_trimmed_paths;
|
||||
use rustc_middle::ty::GenericArgKind;
|
||||
use rustc_middle::ty::ToPredicate;
|
||||
use rustc_middle::ty::TypeVisitableExt;
|
||||
use rustc_middle::ty::Upcast;
|
||||
use rustc_middle::ty::{self, Ty, TyCtxt, VariantDef};
|
||||
use rustc_session::lint::{BuiltinLintDiag, FutureIncompatibilityReason};
|
||||
use rustc_session::{declare_lint, declare_lint_pass, impl_lint_pass};
|
||||
@@ -360,11 +360,11 @@ fn check_expr(&mut self, cx: &EarlyContext<'_>, e: &ast::Expr) {
|
||||
|
||||
fn check_item(&mut self, cx: &EarlyContext<'_>, it: &ast::Item) {
|
||||
match it.kind {
|
||||
ast::ItemKind::Trait(box ast::Trait { unsafety: ast::Unsafe::Yes(_), .. }) => {
|
||||
ast::ItemKind::Trait(box ast::Trait { safety: ast::Safety::Unsafe(_), .. }) => {
|
||||
self.report_unsafe(cx, it.span, BuiltinUnsafe::UnsafeTrait);
|
||||
}
|
||||
|
||||
ast::ItemKind::Impl(box ast::Impl { unsafety: ast::Unsafe::Yes(_), .. }) => {
|
||||
ast::ItemKind::Impl(box ast::Impl { safety: ast::Safety::Unsafe(_), .. }) => {
|
||||
self.report_unsafe(cx, it.span, BuiltinUnsafe::UnsafeImpl);
|
||||
}
|
||||
|
||||
@@ -419,7 +419,7 @@ fn check_fn(&mut self, cx: &EarlyContext<'_>, fk: FnKind<'_>, span: Span, _: ast
|
||||
if let FnKind::Fn(
|
||||
ctxt,
|
||||
_,
|
||||
ast::FnSig { header: ast::FnHeader { unsafety: ast::Unsafe::Yes(_), .. }, .. },
|
||||
ast::FnSig { header: ast::FnHeader { safety: ast::Safety::Unsafe(_), .. }, .. },
|
||||
_,
|
||||
_,
|
||||
body,
|
||||
@@ -734,7 +734,7 @@ fn type_implements_negative_copy_modulo_regions<'tcx>(
|
||||
cause: traits::ObligationCause::dummy(),
|
||||
param_env,
|
||||
recursion_depth: 0,
|
||||
predicate: ty::Binder::dummy(pred).to_predicate(tcx),
|
||||
predicate: pred.upcast(tcx),
|
||||
};
|
||||
|
||||
tcx.infer_ctxt().build().predicate_must_hold_modulo_regions(&obligation)
|
||||
|
||||
@@ -345,8 +345,8 @@ fn structurally_same_type_impl<'tcx>(
|
||||
let a_sig = tcx.instantiate_bound_regions_with_erased(a_poly_sig);
|
||||
let b_sig = tcx.instantiate_bound_regions_with_erased(b_poly_sig);
|
||||
|
||||
(a_sig.abi, a_sig.unsafety, a_sig.c_variadic)
|
||||
== (b_sig.abi, b_sig.unsafety, b_sig.c_variadic)
|
||||
(a_sig.abi, a_sig.safety, a_sig.c_variadic)
|
||||
== (b_sig.abi, b_sig.safety, b_sig.c_variadic)
|
||||
&& a_sig.inputs().iter().eq_by(b_sig.inputs().iter(), |a, b| {
|
||||
structurally_same_type_impl(seen_types, tcx, param_env, *a, *b, ckind)
|
||||
})
|
||||
|
||||
@@ -28,6 +28,7 @@ rustc_hir = { path = "../rustc_hir" }
|
||||
rustc_hir_pretty = { path = "../rustc_hir_pretty" }
|
||||
rustc_index = { path = "../rustc_index" }
|
||||
rustc_macros = { path = "../rustc_macros" }
|
||||
rustc_next_trait_solver = { path = "../rustc_next_trait_solver" }
|
||||
rustc_query_system = { path = "../rustc_query_system" }
|
||||
rustc_serialize = { path = "../rustc_serialize" }
|
||||
rustc_session = { path = "../rustc_session" }
|
||||
|
||||
@@ -61,7 +61,7 @@ macro_rules! arena_types {
|
||||
[] dtorck_constraint: rustc_middle::traits::query::DropckConstraint<'tcx>,
|
||||
[] candidate_step: rustc_middle::traits::query::CandidateStep<'tcx>,
|
||||
[] autoderef_bad_ty: rustc_middle::traits::query::MethodAutoderefBadTy<'tcx>,
|
||||
[] canonical_goal_evaluation: rustc_middle::traits::solve::inspect::GoalEvaluationStep<'tcx>,
|
||||
[] canonical_goal_evaluation: rustc_next_trait_solver::solve::inspect::GoalEvaluationStep<rustc_middle::ty::TyCtxt<'tcx>>,
|
||||
[] query_region_constraints: rustc_middle::infer::canonical::QueryRegionConstraints<'tcx>,
|
||||
[] type_op_subtype:
|
||||
rustc_middle::infer::canonical::Canonical<'tcx,
|
||||
|
||||
@@ -23,23 +23,20 @@
|
||||
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_data_structures::sync::Lock;
|
||||
use rustc_macros::{HashStable, TyDecodable, TyEncodable, TypeFoldable, TypeVisitable};
|
||||
use rustc_type_ir::Canonical as IrCanonical;
|
||||
use rustc_type_ir::CanonicalVarInfo as IrCanonicalVarInfo;
|
||||
use rustc_macros::{HashStable, TypeFoldable, TypeVisitable};
|
||||
pub use rustc_type_ir as ir;
|
||||
pub use rustc_type_ir::{CanonicalTyVarKind, CanonicalVarKind};
|
||||
use smallvec::SmallVec;
|
||||
use std::collections::hash_map::Entry;
|
||||
use std::ops::Index;
|
||||
|
||||
use crate::infer::MemberConstraint;
|
||||
use crate::mir::ConstraintCategory;
|
||||
use crate::ty::GenericArg;
|
||||
use crate::ty::{self, BoundVar, List, Region, Ty, TyCtxt, TypeFlags, TypeVisitableExt};
|
||||
|
||||
pub type Canonical<'tcx, V> = IrCanonical<TyCtxt<'tcx>, V>;
|
||||
|
||||
pub type CanonicalVarInfo<'tcx> = IrCanonicalVarInfo<TyCtxt<'tcx>>;
|
||||
use crate::ty::{self, List, Region, Ty, TyCtxt, TypeFlags, TypeVisitableExt};
|
||||
|
||||
pub type Canonical<'tcx, V> = ir::Canonical<TyCtxt<'tcx>, V>;
|
||||
pub type CanonicalVarInfo<'tcx> = ir::CanonicalVarInfo<TyCtxt<'tcx>>;
|
||||
pub type CanonicalVarValues<'tcx> = ir::CanonicalVarValues<TyCtxt<'tcx>>;
|
||||
pub type CanonicalVarInfos<'tcx> = &'tcx List<CanonicalVarInfo<'tcx>>;
|
||||
|
||||
impl<'tcx> ty::TypeFoldable<TyCtxt<'tcx>> for CanonicalVarInfos<'tcx> {
|
||||
@@ -51,74 +48,6 @@ fn try_fold_with<F: ty::FallibleTypeFolder<TyCtxt<'tcx>>>(
|
||||
}
|
||||
}
|
||||
|
||||
/// A set of values corresponding to the canonical variables from some
|
||||
/// `Canonical`. You can give these values to
|
||||
/// `canonical_value.instantiate` to instantiate them into the canonical
|
||||
/// value at the right places.
|
||||
///
|
||||
/// When you canonicalize a value `V`, you get back one of these
|
||||
/// vectors with the original values that were replaced by canonical
|
||||
/// variables. You will need to supply it later to instantiate the
|
||||
/// canonicalized query response.
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, TyDecodable, TyEncodable)]
|
||||
#[derive(HashStable, TypeFoldable, TypeVisitable)]
|
||||
pub struct CanonicalVarValues<'tcx> {
|
||||
pub var_values: ty::GenericArgsRef<'tcx>,
|
||||
}
|
||||
|
||||
impl CanonicalVarValues<'_> {
|
||||
pub fn is_identity(&self) -> bool {
|
||||
self.var_values.iter().enumerate().all(|(bv, arg)| match arg.unpack() {
|
||||
ty::GenericArgKind::Lifetime(r) => {
|
||||
matches!(*r, ty::ReBound(ty::INNERMOST, br) if br.var.as_usize() == bv)
|
||||
}
|
||||
ty::GenericArgKind::Type(ty) => {
|
||||
matches!(*ty.kind(), ty::Bound(ty::INNERMOST, bt) if bt.var.as_usize() == bv)
|
||||
}
|
||||
ty::GenericArgKind::Const(ct) => {
|
||||
matches!(ct.kind(), ty::ConstKind::Bound(ty::INNERMOST, bc) if bc.as_usize() == bv)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
pub fn is_identity_modulo_regions(&self) -> bool {
|
||||
let mut var = ty::BoundVar::ZERO;
|
||||
for arg in self.var_values {
|
||||
match arg.unpack() {
|
||||
ty::GenericArgKind::Lifetime(r) => {
|
||||
if let ty::ReBound(ty::INNERMOST, br) = *r
|
||||
&& var == br.var
|
||||
{
|
||||
var = var + 1;
|
||||
} else {
|
||||
// It's ok if this region var isn't unique
|
||||
}
|
||||
}
|
||||
ty::GenericArgKind::Type(ty) => {
|
||||
if let ty::Bound(ty::INNERMOST, bt) = *ty.kind()
|
||||
&& var == bt.var
|
||||
{
|
||||
var = var + 1;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
ty::GenericArgKind::Const(ct) => {
|
||||
if let ty::ConstKind::Bound(ty::INNERMOST, bc) = ct.kind()
|
||||
&& var == bc
|
||||
{
|
||||
var = var + 1;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
/// When we canonicalize a value to form a query, we wind up replacing
|
||||
/// various parts of it with canonical variables. This struct stores
|
||||
/// those replaced bits to remember for when we process the query
|
||||
@@ -218,78 +147,6 @@ pub fn is_proven(&self) -> bool {
|
||||
crate::infer::canonical::Certainty,
|
||||
}
|
||||
|
||||
impl<'tcx> CanonicalVarValues<'tcx> {
|
||||
// Given a list of canonical variables, construct a set of values which are
|
||||
// the identity response.
|
||||
pub fn make_identity(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
infos: CanonicalVarInfos<'tcx>,
|
||||
) -> CanonicalVarValues<'tcx> {
|
||||
CanonicalVarValues {
|
||||
var_values: tcx.mk_args_from_iter(infos.iter().enumerate().map(
|
||||
|(i, info)| -> ty::GenericArg<'tcx> {
|
||||
match info.kind {
|
||||
CanonicalVarKind::Ty(_) | CanonicalVarKind::PlaceholderTy(_) => {
|
||||
Ty::new_bound(tcx, ty::INNERMOST, ty::BoundVar::from_usize(i).into())
|
||||
.into()
|
||||
}
|
||||
CanonicalVarKind::Region(_) | CanonicalVarKind::PlaceholderRegion(_) => {
|
||||
let br = ty::BoundRegion {
|
||||
var: ty::BoundVar::from_usize(i),
|
||||
kind: ty::BrAnon,
|
||||
};
|
||||
ty::Region::new_bound(tcx, ty::INNERMOST, br).into()
|
||||
}
|
||||
CanonicalVarKind::Effect => ty::Const::new_bound(
|
||||
tcx,
|
||||
ty::INNERMOST,
|
||||
ty::BoundVar::from_usize(i),
|
||||
tcx.types.bool,
|
||||
)
|
||||
.into(),
|
||||
CanonicalVarKind::Const(_, ty)
|
||||
| CanonicalVarKind::PlaceholderConst(_, ty) => ty::Const::new_bound(
|
||||
tcx,
|
||||
ty::INNERMOST,
|
||||
ty::BoundVar::from_usize(i),
|
||||
ty,
|
||||
)
|
||||
.into(),
|
||||
}
|
||||
},
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
/// Creates dummy var values which should not be used in a
|
||||
/// canonical response.
|
||||
pub fn dummy() -> CanonicalVarValues<'tcx> {
|
||||
CanonicalVarValues { var_values: ty::List::empty() }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn len(&self) -> usize {
|
||||
self.var_values.len()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> IntoIterator for &'a CanonicalVarValues<'tcx> {
|
||||
type Item = GenericArg<'tcx>;
|
||||
type IntoIter = ::std::iter::Copied<::std::slice::Iter<'a, GenericArg<'tcx>>>;
|
||||
|
||||
fn into_iter(self) -> Self::IntoIter {
|
||||
self.var_values.iter()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> Index<BoundVar> for CanonicalVarValues<'tcx> {
|
||||
type Output = GenericArg<'tcx>;
|
||||
|
||||
fn index(&self, value: BoundVar) -> &GenericArg<'tcx> {
|
||||
&self.var_values[value.as_usize()]
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct CanonicalParamEnvCache<'tcx> {
|
||||
map: Lock<
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
mod structural_impls;
|
||||
pub mod util;
|
||||
|
||||
use crate::infer::canonical::Canonical;
|
||||
use crate::mir::ConstraintCategory;
|
||||
use crate::ty::abstract_const::NotConstEvaluatable;
|
||||
use crate::ty::GenericArgsRef;
|
||||
@@ -32,6 +31,8 @@
|
||||
use std::hash::{Hash, Hasher};
|
||||
|
||||
pub use self::select::{EvaluationCache, EvaluationResult, OverflowError, SelectionCache};
|
||||
// FIXME: Remove this import and import via `solve::`
|
||||
pub use rustc_next_trait_solver::solve::BuiltinImplSource;
|
||||
|
||||
/// Depending on the stage of compilation, we want projection to be
|
||||
/// more or less conservative.
|
||||
@@ -736,32 +737,6 @@ pub struct ImplSourceUserDefinedData<'tcx, N> {
|
||||
pub nested: Vec<N>,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq, TyEncodable, TyDecodable, HashStable, Debug)]
|
||||
pub enum BuiltinImplSource {
|
||||
/// Some builtin impl we don't need to differentiate. This should be used
|
||||
/// unless more specific information is necessary.
|
||||
Misc,
|
||||
/// A builtin impl for trait objects.
|
||||
///
|
||||
/// The vtable is formed by concatenating together the method lists of
|
||||
/// the base object trait and all supertraits, pointers to supertrait vtable will
|
||||
/// be provided when necessary; this is the start of `upcast_trait_ref`'s methods
|
||||
/// in that vtable.
|
||||
Object { vtable_base: usize },
|
||||
/// The vtable is formed by concatenating together the method lists of
|
||||
/// the base object trait and all supertraits, pointers to supertrait vtable will
|
||||
/// be provided when necessary; this is the position of `upcast_trait_ref`'s vtable
|
||||
/// within that vtable.
|
||||
TraitUpcasting { vtable_vptr_slot: Option<usize> },
|
||||
/// Unsizing a tuple like `(A, B, ..., X)` to `(A, B, ..., Y)` if `X` unsizes to `Y`.
|
||||
///
|
||||
/// This needs to be a separate variant as it is still unstable and we need to emit
|
||||
/// a feature error when using it on stable.
|
||||
TupleUnsizing,
|
||||
}
|
||||
|
||||
TrivialTypeTraversalImpls! { BuiltinImplSource }
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Hash, HashStable, PartialOrd, Ord)]
|
||||
pub enum ObjectSafetyViolation {
|
||||
/// `Self: Sized` declared on the trait.
|
||||
|
||||
@@ -12,6 +12,8 @@
|
||||
use crate::ty::{self, Ty, TyCtxt};
|
||||
use rustc_macros::{HashStable, TypeFoldable, TypeVisitable};
|
||||
use rustc_span::Span;
|
||||
// FIXME: Remove this import and import via `traits::solve`.
|
||||
pub use rustc_next_trait_solver::solve::NoSolution;
|
||||
|
||||
pub mod type_op {
|
||||
use crate::ty::fold::TypeFoldable;
|
||||
@@ -89,9 +91,6 @@ pub fn new(value: T) -> Self {
|
||||
pub type CanonicalTypeOpNormalizeGoal<'tcx, T> =
|
||||
Canonical<'tcx, ty::ParamEnvAnd<'tcx, type_op::Normalize<T>>>;
|
||||
|
||||
#[derive(Copy, Clone, Debug, Hash, HashStable, PartialEq, Eq)]
|
||||
pub struct NoSolution;
|
||||
|
||||
impl<'tcx> From<TypeError<'tcx>> for NoSolution {
|
||||
fn from(_: TypeError<'tcx>) -> NoSolution {
|
||||
NoSolution
|
||||
|
||||
@@ -1,122 +1,24 @@
|
||||
use rustc_ast_ir::try_visit;
|
||||
use rustc_data_structures::intern::Interned;
|
||||
use rustc_macros::{HashStable, TypeFoldable, TypeVisitable};
|
||||
use rustc_span::def_id::DefId;
|
||||
use rustc_next_trait_solver as ir;
|
||||
pub use rustc_next_trait_solver::solve::*;
|
||||
|
||||
use crate::infer::canonical::{CanonicalVarValues, QueryRegionConstraints};
|
||||
use crate::traits::query::NoSolution;
|
||||
use crate::traits::Canonical;
|
||||
use crate::infer::canonical::QueryRegionConstraints;
|
||||
use crate::ty::{
|
||||
self, FallibleTypeFolder, ToPredicate, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeVisitable,
|
||||
TypeVisitor,
|
||||
self, FallibleTypeFolder, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeVisitable, TypeVisitor,
|
||||
};
|
||||
|
||||
use super::BuiltinImplSource;
|
||||
|
||||
mod cache;
|
||||
pub mod inspect;
|
||||
|
||||
pub use cache::{CacheData, EvaluationCache};
|
||||
|
||||
/// A goal is a statement, i.e. `predicate`, we want to prove
|
||||
/// given some assumptions, i.e. `param_env`.
|
||||
///
|
||||
/// Most of the time the `param_env` contains the `where`-bounds of the function
|
||||
/// we're currently typechecking while the `predicate` is some trait bound.
|
||||
#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash, HashStable, TypeFoldable, TypeVisitable)]
|
||||
pub struct Goal<'tcx, P> {
|
||||
pub predicate: P,
|
||||
pub param_env: ty::ParamEnv<'tcx>,
|
||||
}
|
||||
|
||||
impl<'tcx, P> Goal<'tcx, P> {
|
||||
pub fn new(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
param_env: ty::ParamEnv<'tcx>,
|
||||
predicate: impl ToPredicate<'tcx, P>,
|
||||
) -> Goal<'tcx, P> {
|
||||
Goal { param_env, predicate: predicate.to_predicate(tcx) }
|
||||
}
|
||||
|
||||
/// Updates the goal to one with a different `predicate` but the same `param_env`.
|
||||
pub fn with<Q>(self, tcx: TyCtxt<'tcx>, predicate: impl ToPredicate<'tcx, Q>) -> Goal<'tcx, Q> {
|
||||
Goal { param_env: self.param_env, predicate: predicate.to_predicate(tcx) }
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash, HashStable, TypeFoldable, TypeVisitable)]
|
||||
pub struct Response<'tcx> {
|
||||
pub certainty: Certainty,
|
||||
pub var_values: CanonicalVarValues<'tcx>,
|
||||
/// Additional constraints returned by this query.
|
||||
pub external_constraints: ExternalConstraints<'tcx>,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash, HashStable, TypeFoldable, TypeVisitable)]
|
||||
pub enum Certainty {
|
||||
Yes,
|
||||
Maybe(MaybeCause),
|
||||
}
|
||||
|
||||
impl Certainty {
|
||||
pub const AMBIGUOUS: Certainty = Certainty::Maybe(MaybeCause::Ambiguity);
|
||||
|
||||
/// Use this function to merge the certainty of multiple nested subgoals.
|
||||
///
|
||||
/// Given an impl like `impl<T: Foo + Bar> Baz for T {}`, we have 2 nested
|
||||
/// subgoals whenever we use the impl as a candidate: `T: Foo` and `T: Bar`.
|
||||
/// If evaluating `T: Foo` results in ambiguity and `T: Bar` results in
|
||||
/// success, we merge these two responses. This results in ambiguity.
|
||||
///
|
||||
/// If we unify ambiguity with overflow, we return overflow. This doesn't matter
|
||||
/// inside of the solver as we do not distinguish ambiguity from overflow. It does
|
||||
/// however matter for diagnostics. If `T: Foo` resulted in overflow and `T: Bar`
|
||||
/// in ambiguity without changing the inference state, we still want to tell the
|
||||
/// user that `T: Baz` results in overflow.
|
||||
pub fn unify_with(self, other: Certainty) -> Certainty {
|
||||
match (self, other) {
|
||||
(Certainty::Yes, Certainty::Yes) => Certainty::Yes,
|
||||
(Certainty::Yes, Certainty::Maybe(_)) => other,
|
||||
(Certainty::Maybe(_), Certainty::Yes) => self,
|
||||
(Certainty::Maybe(a), Certainty::Maybe(b)) => Certainty::Maybe(a.unify_with(b)),
|
||||
}
|
||||
}
|
||||
|
||||
pub const fn overflow(suggest_increasing_limit: bool) -> Certainty {
|
||||
Certainty::Maybe(MaybeCause::Overflow { suggest_increasing_limit })
|
||||
}
|
||||
}
|
||||
|
||||
/// Why we failed to evaluate a goal.
|
||||
#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash, HashStable, TypeFoldable, TypeVisitable)]
|
||||
pub enum MaybeCause {
|
||||
/// We failed due to ambiguity. This ambiguity can either
|
||||
/// be a true ambiguity, i.e. there are multiple different answers,
|
||||
/// or we hit a case where we just don't bother, e.g. `?x: Trait` goals.
|
||||
Ambiguity,
|
||||
/// We gave up due to an overflow, most often by hitting the recursion limit.
|
||||
Overflow { suggest_increasing_limit: bool },
|
||||
}
|
||||
|
||||
impl MaybeCause {
|
||||
fn unify_with(self, other: MaybeCause) -> MaybeCause {
|
||||
match (self, other) {
|
||||
(MaybeCause::Ambiguity, MaybeCause::Ambiguity) => MaybeCause::Ambiguity,
|
||||
(MaybeCause::Ambiguity, MaybeCause::Overflow { .. }) => other,
|
||||
(MaybeCause::Overflow { .. }, MaybeCause::Ambiguity) => self,
|
||||
(
|
||||
MaybeCause::Overflow { suggest_increasing_limit: a },
|
||||
MaybeCause::Overflow { suggest_increasing_limit: b },
|
||||
) => MaybeCause::Overflow { suggest_increasing_limit: a || b },
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash, HashStable, TypeFoldable, TypeVisitable)]
|
||||
pub struct QueryInput<'tcx, T> {
|
||||
pub goal: Goal<'tcx, T>,
|
||||
pub predefined_opaques_in_body: PredefinedOpaques<'tcx>,
|
||||
}
|
||||
pub type Goal<'tcx, P> = ir::solve::Goal<TyCtxt<'tcx>, P>;
|
||||
pub type QueryInput<'tcx, P> = ir::solve::QueryInput<TyCtxt<'tcx>, P>;
|
||||
pub type QueryResult<'tcx> = ir::solve::QueryResult<TyCtxt<'tcx>>;
|
||||
pub type CandidateSource<'tcx> = ir::solve::CandidateSource<TyCtxt<'tcx>>;
|
||||
pub type CanonicalInput<'tcx, P = ty::Predicate<'tcx>> = ir::solve::CanonicalInput<TyCtxt<'tcx>, P>;
|
||||
pub type CanonicalResponse<'tcx> = ir::solve::CanonicalResponse<TyCtxt<'tcx>>;
|
||||
|
||||
/// Additional constraints returned on success.
|
||||
#[derive(Debug, PartialEq, Eq, Clone, Hash, HashStable, Default)]
|
||||
@@ -135,18 +37,6 @@ fn deref(&self) -> &Self::Target {
|
||||
}
|
||||
}
|
||||
|
||||
pub type CanonicalInput<'tcx, T = ty::Predicate<'tcx>> = Canonical<'tcx, QueryInput<'tcx, T>>;
|
||||
|
||||
pub type CanonicalResponse<'tcx> = Canonical<'tcx, Response<'tcx>>;
|
||||
|
||||
/// The result of evaluating a canonical query.
|
||||
///
|
||||
/// FIXME: We use a different type than the existing canonical queries. This is because
|
||||
/// we need to add a `Certainty` for `overflow` and may want to restructure this code without
|
||||
/// having to worry about changes to currently used code. Once we've made progress on this
|
||||
/// solver, merge the two responses again.
|
||||
pub type QueryResult<'tcx> = Result<CanonicalResponse<'tcx>, NoSolution>;
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Copy, Clone, Hash, HashStable)]
|
||||
pub struct ExternalConstraints<'tcx>(pub(crate) Interned<'tcx, ExternalConstraintsData<'tcx>>);
|
||||
|
||||
@@ -253,91 +143,3 @@ fn visit_with<V: TypeVisitor<TyCtxt<'tcx>>>(&self, visitor: &mut V) -> V::Result
|
||||
self.opaque_types.visit_with(visitor)
|
||||
}
|
||||
}
|
||||
|
||||
/// Why a specific goal has to be proven.
|
||||
///
|
||||
/// This is necessary as we treat nested goals different depending on
|
||||
/// their source.
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, HashStable, TypeVisitable, TypeFoldable)]
|
||||
pub enum GoalSource {
|
||||
Misc,
|
||||
/// We're proving a where-bound of an impl.
|
||||
///
|
||||
/// FIXME(-Znext-solver=coinductive): Explain how and why this
|
||||
/// changes whether cycles are coinductive.
|
||||
///
|
||||
/// This also impacts whether we erase constraints on overflow.
|
||||
/// Erasing constraints is generally very useful for perf and also
|
||||
/// results in better error messages by avoiding spurious errors.
|
||||
/// We do not erase overflow constraints in `normalizes-to` goals unless
|
||||
/// they are from an impl where-clause. This is necessary due to
|
||||
/// backwards compatability, cc trait-system-refactor-initiatitive#70.
|
||||
ImplWhereBound,
|
||||
/// Instantiating a higher-ranked goal and re-proving it.
|
||||
InstantiateHigherRanked,
|
||||
}
|
||||
|
||||
/// Possible ways the given goal can be proven.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum CandidateSource {
|
||||
/// A user written impl.
|
||||
///
|
||||
/// ## Examples
|
||||
///
|
||||
/// ```rust
|
||||
/// fn main() {
|
||||
/// let x: Vec<u32> = Vec::new();
|
||||
/// // This uses the impl from the standard library to prove `Vec<T>: Clone`.
|
||||
/// let y = x.clone();
|
||||
/// }
|
||||
/// ```
|
||||
Impl(DefId),
|
||||
/// A builtin impl generated by the compiler. When adding a new special
|
||||
/// trait, try to use actual impls whenever possible. Builtin impls should
|
||||
/// only be used in cases where the impl cannot be manually be written.
|
||||
///
|
||||
/// Notable examples are auto traits, `Sized`, and `DiscriminantKind`.
|
||||
/// For a list of all traits with builtin impls, check out the
|
||||
/// `EvalCtxt::assemble_builtin_impl_candidates` method.
|
||||
BuiltinImpl(BuiltinImplSource),
|
||||
/// An assumption from the environment.
|
||||
///
|
||||
/// More precisely we've used the `n-th` assumption in the `param_env`.
|
||||
///
|
||||
/// ## Examples
|
||||
///
|
||||
/// ```rust
|
||||
/// fn is_clone<T: Clone>(x: T) -> (T, T) {
|
||||
/// // This uses the assumption `T: Clone` from the `where`-bounds
|
||||
/// // to prove `T: Clone`.
|
||||
/// (x.clone(), x)
|
||||
/// }
|
||||
/// ```
|
||||
ParamEnv(usize),
|
||||
/// If the self type is an alias type, e.g. an opaque type or a projection,
|
||||
/// we know the bounds on that alias to hold even without knowing its concrete
|
||||
/// underlying type.
|
||||
///
|
||||
/// More precisely this candidate is using the `n-th` bound in the `item_bounds` of
|
||||
/// the self type.
|
||||
///
|
||||
/// ## Examples
|
||||
///
|
||||
/// ```rust
|
||||
/// trait Trait {
|
||||
/// type Assoc: Clone;
|
||||
/// }
|
||||
///
|
||||
/// fn foo<T: Trait>(x: <T as Trait>::Assoc) {
|
||||
/// // We prove `<T as Trait>::Assoc` by looking at the bounds on `Assoc` in
|
||||
/// // in the trait definition.
|
||||
/// let _y = x.clone();
|
||||
/// }
|
||||
/// ```
|
||||
AliasBound,
|
||||
/// A candidate that is registered only during coherence to represent some
|
||||
/// yet-unknown impl that could be produced downstream without violating orphan
|
||||
/// rules.
|
||||
// FIXME: Merge this with the forced ambiguity candidates, so those don't use `Misc`.
|
||||
CoherenceUnknowable,
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ pub struct EvaluationCache<'tcx> {
|
||||
#[derive(PartialEq, Eq)]
|
||||
pub struct CacheData<'tcx> {
|
||||
pub result: QueryResult<'tcx>,
|
||||
pub proof_tree: Option<&'tcx [inspect::GoalEvaluationStep<'tcx>]>,
|
||||
pub proof_tree: Option<&'tcx [inspect::GoalEvaluationStep<TyCtxt<'tcx>>]>,
|
||||
pub reached_depth: usize,
|
||||
pub encountered_overflow: bool,
|
||||
}
|
||||
@@ -28,7 +28,7 @@ pub fn insert(
|
||||
&self,
|
||||
tcx: TyCtxt<'tcx>,
|
||||
key: CanonicalInput<'tcx>,
|
||||
proof_tree: Option<&'tcx [inspect::GoalEvaluationStep<'tcx>]>,
|
||||
proof_tree: Option<&'tcx [inspect::GoalEvaluationStep<TyCtxt<'tcx>>]>,
|
||||
reached_depth: usize,
|
||||
encountered_overflow: bool,
|
||||
cycle_participants: FxHashSet<CanonicalInput<'tcx>>,
|
||||
@@ -105,7 +105,7 @@ struct Success<'tcx> {
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct QueryData<'tcx> {
|
||||
pub result: QueryResult<'tcx>,
|
||||
pub proof_tree: Option<&'tcx [inspect::GoalEvaluationStep<'tcx>]>,
|
||||
pub proof_tree: Option<&'tcx [inspect::GoalEvaluationStep<TyCtxt<'tcx>>]>,
|
||||
}
|
||||
|
||||
/// The cache entry for a goal `CanonicalInput`.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use rustc_data_structures::fx::FxHashSet;
|
||||
|
||||
use crate::ty::{Clause, PolyTraitRef, ToPolyTraitRef, ToPredicate, TyCtxt};
|
||||
use crate::ty::{Clause, PolyTraitRef, ToPolyTraitRef, TyCtxt, Upcast};
|
||||
|
||||
/// Given a [`PolyTraitRef`], get the [`Clause`]s implied by the trait's definition.
|
||||
///
|
||||
@@ -11,7 +11,7 @@ pub fn super_predicates_for_pretty_printing<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
trait_ref: PolyTraitRef<'tcx>,
|
||||
) -> impl Iterator<Item = Clause<'tcx>> {
|
||||
let clause = trait_ref.to_predicate(tcx);
|
||||
let clause = trait_ref.upcast(tcx);
|
||||
Elaborator { tcx, visited: FxHashSet::from_iter([clause]), stack: vec![clause] }
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ pub enum PointerCoercion {
|
||||
|
||||
/// Go from a non-capturing closure to an fn pointer or an unsafe fn pointer.
|
||||
/// It cannot convert a closure that requires unsafe.
|
||||
ClosureFnPointer(hir::Unsafety),
|
||||
ClosureFnPointer(hir::Safety),
|
||||
|
||||
/// Go from a mut raw pointer to a const raw pointer.
|
||||
MutToConstPointer,
|
||||
|
||||
@@ -89,20 +89,26 @@
|
||||
#[allow(rustc::usage_of_ty_tykind)]
|
||||
impl<'tcx> Interner for TyCtxt<'tcx> {
|
||||
type DefId = DefId;
|
||||
type DefiningOpaqueTypes = &'tcx ty::List<LocalDefId>;
|
||||
type AdtDef = ty::AdtDef<'tcx>;
|
||||
type GenericArgs = ty::GenericArgsRef<'tcx>;
|
||||
type GenericArgsSlice = &'tcx [ty::GenericArg<'tcx>];
|
||||
type GenericArg = ty::GenericArg<'tcx>;
|
||||
|
||||
type GenericArgs = ty::GenericArgsRef<'tcx>;
|
||||
type OwnItemArgs = &'tcx [ty::GenericArg<'tcx>];
|
||||
type GenericArg = ty::GenericArg<'tcx>;
|
||||
type Term = ty::Term<'tcx>;
|
||||
|
||||
type Binder<T: TypeVisitable<TyCtxt<'tcx>>> = Binder<'tcx, T>;
|
||||
type BoundVars = &'tcx List<ty::BoundVariableKind>;
|
||||
type BoundVar = ty::BoundVariableKind;
|
||||
|
||||
type CanonicalVars = CanonicalVarInfos<'tcx>;
|
||||
type PredefinedOpaques = solve::PredefinedOpaques<'tcx>;
|
||||
type DefiningOpaqueTypes = &'tcx ty::List<LocalDefId>;
|
||||
type ExternalConstraints = ExternalConstraints<'tcx>;
|
||||
type GoalEvaluationSteps = &'tcx [solve::inspect::GoalEvaluationStep<TyCtxt<'tcx>>];
|
||||
|
||||
type Ty = Ty<'tcx>;
|
||||
type Tys = &'tcx List<Ty<'tcx>>;
|
||||
type FnInputTys = &'tcx [Ty<'tcx>];
|
||||
type ParamTy = ParamTy;
|
||||
type BoundTy = ty::BoundTy;
|
||||
type PlaceholderTy = ty::PlaceholderType;
|
||||
@@ -113,21 +119,25 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
|
||||
type AllocId = crate::mir::interpret::AllocId;
|
||||
|
||||
type Pat = Pattern<'tcx>;
|
||||
type Safety = hir::Safety;
|
||||
type Abi = abi::Abi;
|
||||
|
||||
type Const = ty::Const<'tcx>;
|
||||
type AliasConst = ty::UnevaluatedConst<'tcx>;
|
||||
type PlaceholderConst = ty::PlaceholderConst;
|
||||
type ParamConst = ty::ParamConst;
|
||||
type BoundConst = ty::BoundVar;
|
||||
type ValueConst = ty::ValTree<'tcx>;
|
||||
|
||||
type ExprConst = ty::Expr<'tcx>;
|
||||
|
||||
type Region = Region<'tcx>;
|
||||
type EarlyParamRegion = ty::EarlyParamRegion;
|
||||
type LateParamRegion = ty::LateParamRegion;
|
||||
type BoundRegion = ty::BoundRegion;
|
||||
type InferRegion = ty::RegionVid;
|
||||
|
||||
type PlaceholderRegion = ty::PlaceholderRegion;
|
||||
|
||||
type ParamEnv = ty::ParamEnv<'tcx>;
|
||||
type Predicate = Predicate<'tcx>;
|
||||
type TraitPredicate = ty::TraitPredicate<'tcx>;
|
||||
type RegionOutlivesPredicate = ty::RegionOutlivesPredicate<'tcx>;
|
||||
@@ -135,10 +145,12 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
|
||||
type ProjectionPredicate = ty::ProjectionPredicate<'tcx>;
|
||||
type NormalizesTo = ty::NormalizesTo<'tcx>;
|
||||
type SubtypePredicate = ty::SubtypePredicate<'tcx>;
|
||||
|
||||
type CoercePredicate = ty::CoercePredicate<'tcx>;
|
||||
type ClosureKind = ty::ClosureKind;
|
||||
|
||||
type Clauses = ty::Clauses<'tcx>;
|
||||
|
||||
fn mk_canonical_var_infos(self, infos: &[ty::CanonicalVarInfo<Self>]) -> Self::CanonicalVars {
|
||||
self.mk_canonical_var_infos(infos)
|
||||
}
|
||||
@@ -191,7 +203,7 @@ fn trait_ref_and_own_args_for_alias(
|
||||
self,
|
||||
def_id: Self::DefId,
|
||||
args: Self::GenericArgs,
|
||||
) -> (rustc_type_ir::TraitRef<Self>, Self::GenericArgsSlice) {
|
||||
) -> (rustc_type_ir::TraitRef<Self>, Self::OwnItemArgs) {
|
||||
assert_matches!(self.def_kind(def_id), DefKind::AssocTy | DefKind::AssocConst);
|
||||
let trait_def_id = self.parent(def_id);
|
||||
assert_matches!(self.def_kind(trait_def_id), DefKind::Trait);
|
||||
@@ -223,6 +235,18 @@ fn parent(self, def_id: Self::DefId) -> Self::DefId {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> rustc_type_ir::inherent::Abi<TyCtxt<'tcx>> for abi::Abi {
|
||||
fn is_rust(self) -> bool {
|
||||
matches!(self, abi::Abi::Rust)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> rustc_type_ir::inherent::Safety<TyCtxt<'tcx>> for hir::Safety {
|
||||
fn prefix_str(self) -> &'static str {
|
||||
self.prefix_str()
|
||||
}
|
||||
}
|
||||
|
||||
type InternedSet<'tcx, T> = ShardedHashMap<InternedInSet<'tcx, T>, ()>;
|
||||
|
||||
pub struct CtxtInterners<'tcx> {
|
||||
@@ -2006,11 +2030,8 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||
/// that is, a `fn` type that is equivalent in every way for being
|
||||
/// unsafe.
|
||||
pub fn safe_to_unsafe_fn_ty(self, sig: PolyFnSig<'tcx>) -> Ty<'tcx> {
|
||||
assert_eq!(sig.unsafety(), hir::Unsafety::Normal);
|
||||
Ty::new_fn_ptr(
|
||||
self,
|
||||
sig.map_bound(|sig| ty::FnSig { unsafety: hir::Unsafety::Unsafe, ..sig }),
|
||||
)
|
||||
assert_eq!(sig.safety(), hir::Safety::Safe);
|
||||
Ty::new_fn_ptr(self, sig.map_bound(|sig| ty::FnSig { safety: hir::Safety::Unsafe, ..sig }))
|
||||
}
|
||||
|
||||
/// Given the def_id of a Trait `trait_def_id` and the name of an associated item `assoc_name`
|
||||
@@ -2067,20 +2088,16 @@ fn super_traits_of(self, trait_def_id: DefId) -> impl Iterator<Item = DefId> + '
|
||||
/// and so forth -- so e.g., if we have a sig with `Fn<(u32, i32)>` then
|
||||
/// you would get a `fn(u32, i32)`.
|
||||
/// `unsafety` determines the unsafety of the fn signature. If you pass
|
||||
/// `hir::Unsafety::Unsafe` in the previous example, then you would get
|
||||
/// `hir::Safety::Unsafe` in the previous example, then you would get
|
||||
/// an `unsafe fn (u32, i32)`.
|
||||
/// It cannot convert a closure that requires unsafe.
|
||||
pub fn signature_unclosure(
|
||||
self,
|
||||
sig: PolyFnSig<'tcx>,
|
||||
unsafety: hir::Unsafety,
|
||||
) -> PolyFnSig<'tcx> {
|
||||
pub fn signature_unclosure(self, sig: PolyFnSig<'tcx>, safety: hir::Safety) -> PolyFnSig<'tcx> {
|
||||
sig.map_bound(|s| {
|
||||
let params = match s.inputs()[0].kind() {
|
||||
ty::Tuple(params) => *params,
|
||||
_ => bug!(),
|
||||
};
|
||||
self.mk_fn_sig(params, s.output(), s.c_variadic, unsafety, abi::Abi::Rust)
|
||||
self.mk_fn_sig(params, s.output(), s.c_variadic, safety, abi::Abi::Rust)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -2347,7 +2364,7 @@ pub fn mk_fn_sig<I, T>(
|
||||
inputs: I,
|
||||
output: I::Item,
|
||||
c_variadic: bool,
|
||||
unsafety: hir::Unsafety,
|
||||
safety: hir::Safety,
|
||||
abi: abi::Abi,
|
||||
) -> T::Output
|
||||
where
|
||||
@@ -2357,7 +2374,7 @@ pub fn mk_fn_sig<I, T>(
|
||||
T::collect_and_apply(inputs.into_iter().chain(iter::once(output)), |xs| ty::FnSig {
|
||||
inputs_and_output: self.mk_type_list(xs),
|
||||
c_variadic,
|
||||
unsafety,
|
||||
safety,
|
||||
abi,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ pub enum TypeError<'tcx> {
|
||||
Mismatch,
|
||||
ConstnessMismatch(ExpectedFound<ty::BoundConstness>),
|
||||
PolarityMismatch(ExpectedFound<ty::PredicatePolarity>),
|
||||
UnsafetyMismatch(ExpectedFound<hir::Unsafety>),
|
||||
SafetyMismatch(ExpectedFound<hir::Safety>),
|
||||
AbiMismatch(ExpectedFound<abi::Abi>),
|
||||
Mutability,
|
||||
ArgumentMutability(usize),
|
||||
@@ -107,7 +107,7 @@ fn report_maybe_different(expected: &str, found: &str) -> String {
|
||||
format!("expected {} polarity, found {} polarity", values.expected, values.found)
|
||||
.into()
|
||||
}
|
||||
UnsafetyMismatch(values) => {
|
||||
SafetyMismatch(values) => {
|
||||
format!("expected {} fn, found {} fn", values.expected, values.found).into()
|
||||
}
|
||||
AbiMismatch(values) => {
|
||||
@@ -204,7 +204,7 @@ impl<'tcx> TypeError<'tcx> {
|
||||
pub fn must_include_note(self) -> bool {
|
||||
use self::TypeError::*;
|
||||
match self {
|
||||
CyclicTy(_) | CyclicConst(_) | UnsafetyMismatch(_) | ConstnessMismatch(_)
|
||||
CyclicTy(_) | CyclicConst(_) | SafetyMismatch(_) | ConstnessMismatch(_)
|
||||
| PolarityMismatch(_) | Mismatch | AbiMismatch(_) | FixedArraySize(_)
|
||||
| ArgumentSorts(..) | Sorts(_) | IntMismatch(_) | FloatMismatch(_)
|
||||
| VariadicMismatch(_) | TargetFeatureCast(_) => false,
|
||||
|
||||
@@ -281,13 +281,13 @@ pub fn types_may_unify<'tcx>(self, obligation_ty: Ty<'tcx>, impl_ty: Ty<'tcx>) -
|
||||
}
|
||||
ty::FnPtr(obl_sig) => match k {
|
||||
ty::FnPtr(impl_sig) => {
|
||||
let ty::FnSig { inputs_and_output, c_variadic, unsafety, abi } =
|
||||
let ty::FnSig { inputs_and_output, c_variadic, safety, abi } =
|
||||
obl_sig.skip_binder();
|
||||
let impl_sig = impl_sig.skip_binder();
|
||||
|
||||
abi == impl_sig.abi
|
||||
&& c_variadic == impl_sig.c_variadic
|
||||
&& unsafety == impl_sig.unsafety
|
||||
&& safety == impl_sig.safety
|
||||
&& inputs_and_output.len() == impl_sig.inputs_and_output.len()
|
||||
&& iter::zip(inputs_and_output, impl_sig.inputs_and_output)
|
||||
.all(|(obl, imp)| self.types_may_unify(obl, imp))
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
use rustc_data_structures::intern::Interned;
|
||||
use rustc_errors::{DiagArgValue, IntoDiagArg};
|
||||
use rustc_hir::def_id::DefId;
|
||||
use rustc_macros::extension;
|
||||
use rustc_macros::{
|
||||
Decodable, Encodable, HashStable, TyDecodable, TyEncodable, TypeFoldable, TypeVisitable,
|
||||
};
|
||||
@@ -25,6 +26,8 @@
|
||||
use std::ops::Deref;
|
||||
use std::ptr::NonNull;
|
||||
|
||||
pub type GenericArgKind<'tcx> = rustc_type_ir::GenericArgKind<TyCtxt<'tcx>>;
|
||||
|
||||
/// An entity in the Rust type system, which can be one of
|
||||
/// several kinds (types, lifetimes, and consts).
|
||||
/// To reduce memory usage, a `GenericArg` is an interned pointer,
|
||||
@@ -49,6 +52,14 @@ fn identity_for_item(tcx: TyCtxt<'tcx>, def_id: DefId) -> ty::GenericArgsRef<'tc
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> rustc_type_ir::inherent::IntoKind for GenericArg<'tcx> {
|
||||
type Kind = GenericArgKind<'tcx>;
|
||||
|
||||
fn kind(self) -> Self::Kind {
|
||||
self.unpack()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(parallel_compiler)]
|
||||
unsafe impl<'tcx> rustc_data_structures::sync::DynSend for GenericArg<'tcx> where
|
||||
&'tcx (Ty<'tcx>, ty::Region<'tcx>, ty::Const<'tcx>): rustc_data_structures::sync::DynSend
|
||||
@@ -79,13 +90,7 @@ fn into_diag_arg(self) -> DiagArgValue {
|
||||
const REGION_TAG: usize = 0b01;
|
||||
const CONST_TAG: usize = 0b10;
|
||||
|
||||
#[derive(Debug, TyEncodable, TyDecodable, PartialEq, Eq, HashStable)]
|
||||
pub enum GenericArgKind<'tcx> {
|
||||
Lifetime(ty::Region<'tcx>),
|
||||
Type(Ty<'tcx>),
|
||||
Const(ty::Const<'tcx>),
|
||||
}
|
||||
|
||||
#[extension(trait GenericArgPackExt<'tcx>)]
|
||||
impl<'tcx> GenericArgKind<'tcx> {
|
||||
#[inline]
|
||||
fn pack(self) -> GenericArg<'tcx> {
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
use crate::ty::util::Discr;
|
||||
pub use adt::*;
|
||||
pub use assoc::*;
|
||||
pub use generic_args::*;
|
||||
pub use generic_args::{GenericArgKind, *};
|
||||
pub use generics::*;
|
||||
pub use intrinsic::IntrinsicDef;
|
||||
use rustc_ast as ast;
|
||||
@@ -102,7 +102,7 @@
|
||||
PolyExistentialTraitRef, PolyProjectionPredicate, PolyRegionOutlivesPredicate,
|
||||
PolySubtypePredicate, PolyTraitPredicate, PolyTraitRef, PolyTypeOutlivesPredicate, Predicate,
|
||||
PredicateKind, ProjectionPredicate, RegionOutlivesPredicate, SubtypePredicate, ToPolyTraitRef,
|
||||
ToPredicate, TraitPredicate, TraitRef, TypeOutlivesPredicate,
|
||||
TraitPredicate, TraitRef, TypeOutlivesPredicate,
|
||||
};
|
||||
pub use self::region::{
|
||||
BoundRegion, BoundRegionKind, BoundRegionKind::*, EarlyParamRegion, LateParamRegion, Region,
|
||||
@@ -266,7 +266,7 @@ pub struct ImplHeader<'tcx> {
|
||||
pub struct ImplTraitHeader<'tcx> {
|
||||
pub trait_ref: ty::EarlyBinder<ty::TraitRef<'tcx>>,
|
||||
pub polarity: ImplPolarity,
|
||||
pub unsafety: hir::Unsafety,
|
||||
pub safety: hir::Safety,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Debug, TypeFoldable, TypeVisitable)]
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
use crate::ty::{
|
||||
self, Binder, DebruijnIndex, EarlyBinder, PredicatePolarity, Term, Ty, TyCtxt, TypeFlags,
|
||||
WithCachedTypeInfo,
|
||||
Upcast, UpcastFrom, WithCachedTypeInfo,
|
||||
};
|
||||
|
||||
pub type TraitRef<'tcx> = ir::TraitRef<TyCtxt<'tcx>>;
|
||||
@@ -234,10 +234,10 @@ impl<'tcx> PolyExistentialPredicate<'tcx> {
|
||||
pub fn with_self_ty(&self, tcx: TyCtxt<'tcx>, self_ty: Ty<'tcx>) -> ty::Clause<'tcx> {
|
||||
match self.skip_binder() {
|
||||
ExistentialPredicate::Trait(tr) => {
|
||||
self.rebind(tr).with_self_ty(tcx, self_ty).to_predicate(tcx)
|
||||
self.rebind(tr).with_self_ty(tcx, self_ty).upcast(tcx)
|
||||
}
|
||||
ExistentialPredicate::Projection(p) => {
|
||||
self.rebind(p.with_self_ty(tcx, self_ty)).to_predicate(tcx)
|
||||
self.rebind(p.with_self_ty(tcx, self_ty)).upcast(tcx)
|
||||
}
|
||||
ExistentialPredicate::AutoTrait(did) => {
|
||||
let generics = tcx.generics_of(did);
|
||||
@@ -249,7 +249,7 @@ pub fn with_self_ty(&self, tcx: TyCtxt<'tcx>, self_ty: Ty<'tcx>) -> ty::Clause<'
|
||||
let err_args = ty::GenericArgs::extend_with_error(tcx, did, &[self_ty.into()]);
|
||||
ty::TraitRef::new(tcx, did, err_args)
|
||||
};
|
||||
self.rebind(trait_ref).to_predicate(tcx)
|
||||
self.rebind(trait_ref).upcast(tcx)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -544,185 +544,164 @@ fn to_poly_trait_ref(&self) -> PolyTraitRef<'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
pub trait ToPredicate<'tcx, P = Predicate<'tcx>> {
|
||||
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> P;
|
||||
}
|
||||
|
||||
impl<'tcx, T> ToPredicate<'tcx, T> for T {
|
||||
fn to_predicate(self, _tcx: TyCtxt<'tcx>) -> T {
|
||||
self
|
||||
impl<'tcx> UpcastFrom<TyCtxt<'tcx>, PredicateKind<'tcx>> for Predicate<'tcx> {
|
||||
fn upcast_from(from: PredicateKind<'tcx>, tcx: TyCtxt<'tcx>) -> Self {
|
||||
ty::Binder::dummy(from).upcast(tcx)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> ToPredicate<'tcx> for PredicateKind<'tcx> {
|
||||
#[inline(always)]
|
||||
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
|
||||
ty::Binder::dummy(self).to_predicate(tcx)
|
||||
impl<'tcx> UpcastFrom<TyCtxt<'tcx>, Binder<'tcx, PredicateKind<'tcx>>> for Predicate<'tcx> {
|
||||
fn upcast_from(from: Binder<'tcx, PredicateKind<'tcx>>, tcx: TyCtxt<'tcx>) -> Self {
|
||||
tcx.mk_predicate(from)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> ToPredicate<'tcx> for Binder<'tcx, PredicateKind<'tcx>> {
|
||||
#[inline(always)]
|
||||
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
|
||||
tcx.mk_predicate(self)
|
||||
impl<'tcx> UpcastFrom<TyCtxt<'tcx>, ClauseKind<'tcx>> for Predicate<'tcx> {
|
||||
fn upcast_from(from: ClauseKind<'tcx>, tcx: TyCtxt<'tcx>) -> Self {
|
||||
tcx.mk_predicate(ty::Binder::dummy(PredicateKind::Clause(from)))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> ToPredicate<'tcx> for ClauseKind<'tcx> {
|
||||
#[inline(always)]
|
||||
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
|
||||
tcx.mk_predicate(ty::Binder::dummy(ty::PredicateKind::Clause(self)))
|
||||
impl<'tcx> UpcastFrom<TyCtxt<'tcx>, Binder<'tcx, ClauseKind<'tcx>>> for Predicate<'tcx> {
|
||||
fn upcast_from(from: Binder<'tcx, ClauseKind<'tcx>>, tcx: TyCtxt<'tcx>) -> Self {
|
||||
tcx.mk_predicate(from.map_bound(PredicateKind::Clause))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> ToPredicate<'tcx> for Binder<'tcx, ClauseKind<'tcx>> {
|
||||
#[inline(always)]
|
||||
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
|
||||
tcx.mk_predicate(self.map_bound(ty::PredicateKind::Clause))
|
||||
impl<'tcx> UpcastFrom<TyCtxt<'tcx>, Clause<'tcx>> for Predicate<'tcx> {
|
||||
fn upcast_from(from: Clause<'tcx>, _tcx: TyCtxt<'tcx>) -> Self {
|
||||
from.as_predicate()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> ToPredicate<'tcx> for Clause<'tcx> {
|
||||
#[inline(always)]
|
||||
fn to_predicate(self, _tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
|
||||
self.as_predicate()
|
||||
impl<'tcx> UpcastFrom<TyCtxt<'tcx>, ClauseKind<'tcx>> for Clause<'tcx> {
|
||||
fn upcast_from(from: ClauseKind<'tcx>, tcx: TyCtxt<'tcx>) -> Self {
|
||||
tcx.mk_predicate(Binder::dummy(PredicateKind::Clause(from))).expect_clause()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> ToPredicate<'tcx, Clause<'tcx>> for ClauseKind<'tcx> {
|
||||
#[inline(always)]
|
||||
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Clause<'tcx> {
|
||||
tcx.mk_predicate(Binder::dummy(ty::PredicateKind::Clause(self))).expect_clause()
|
||||
impl<'tcx> UpcastFrom<TyCtxt<'tcx>, Binder<'tcx, ClauseKind<'tcx>>> for Clause<'tcx> {
|
||||
fn upcast_from(from: Binder<'tcx, ClauseKind<'tcx>>, tcx: TyCtxt<'tcx>) -> Self {
|
||||
tcx.mk_predicate(from.map_bound(|clause| PredicateKind::Clause(clause))).expect_clause()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> ToPredicate<'tcx, Clause<'tcx>> for Binder<'tcx, ClauseKind<'tcx>> {
|
||||
#[inline(always)]
|
||||
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Clause<'tcx> {
|
||||
tcx.mk_predicate(self.map_bound(|clause| ty::PredicateKind::Clause(clause))).expect_clause()
|
||||
impl<'tcx> UpcastFrom<TyCtxt<'tcx>, TraitRef<'tcx>> for Predicate<'tcx> {
|
||||
fn upcast_from(from: TraitRef<'tcx>, tcx: TyCtxt<'tcx>) -> Self {
|
||||
ty::Binder::dummy(from).upcast(tcx)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> ToPredicate<'tcx> for TraitRef<'tcx> {
|
||||
#[inline(always)]
|
||||
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
|
||||
ty::Binder::dummy(self).to_predicate(tcx)
|
||||
impl<'tcx> UpcastFrom<TyCtxt<'tcx>, TraitRef<'tcx>> for TraitPredicate<'tcx> {
|
||||
fn upcast_from(from: TraitRef<'tcx>, _tcx: TyCtxt<'tcx>) -> Self {
|
||||
TraitPredicate { trait_ref: from, polarity: PredicatePolarity::Positive }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> ToPredicate<'tcx, TraitPredicate<'tcx>> for TraitRef<'tcx> {
|
||||
#[inline(always)]
|
||||
fn to_predicate(self, _tcx: TyCtxt<'tcx>) -> TraitPredicate<'tcx> {
|
||||
TraitPredicate { trait_ref: self, polarity: PredicatePolarity::Positive }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> ToPredicate<'tcx, Clause<'tcx>> for TraitRef<'tcx> {
|
||||
#[inline(always)]
|
||||
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Clause<'tcx> {
|
||||
let p: Predicate<'tcx> = self.to_predicate(tcx);
|
||||
impl<'tcx> UpcastFrom<TyCtxt<'tcx>, TraitRef<'tcx>> for Clause<'tcx> {
|
||||
fn upcast_from(from: TraitRef<'tcx>, tcx: TyCtxt<'tcx>) -> Self {
|
||||
let p: Predicate<'tcx> = from.upcast(tcx);
|
||||
p.expect_clause()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> ToPredicate<'tcx> for Binder<'tcx, TraitRef<'tcx>> {
|
||||
#[inline(always)]
|
||||
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
|
||||
let pred: PolyTraitPredicate<'tcx> = self.to_predicate(tcx);
|
||||
pred.to_predicate(tcx)
|
||||
impl<'tcx> UpcastFrom<TyCtxt<'tcx>, Binder<'tcx, TraitRef<'tcx>>> for Predicate<'tcx> {
|
||||
fn upcast_from(from: Binder<'tcx, TraitRef<'tcx>>, tcx: TyCtxt<'tcx>) -> Self {
|
||||
let pred: PolyTraitPredicate<'tcx> = from.upcast(tcx);
|
||||
pred.upcast(tcx)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> ToPredicate<'tcx, Clause<'tcx>> for Binder<'tcx, TraitRef<'tcx>> {
|
||||
#[inline(always)]
|
||||
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Clause<'tcx> {
|
||||
let pred: PolyTraitPredicate<'tcx> = self.to_predicate(tcx);
|
||||
pred.to_predicate(tcx)
|
||||
impl<'tcx> UpcastFrom<TyCtxt<'tcx>, Binder<'tcx, TraitRef<'tcx>>> for Clause<'tcx> {
|
||||
fn upcast_from(from: Binder<'tcx, TraitRef<'tcx>>, tcx: TyCtxt<'tcx>) -> Self {
|
||||
let pred: PolyTraitPredicate<'tcx> = from.upcast(tcx);
|
||||
pred.upcast(tcx)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> ToPredicate<'tcx, PolyTraitPredicate<'tcx>> for Binder<'tcx, TraitRef<'tcx>> {
|
||||
#[inline(always)]
|
||||
fn to_predicate(self, _: TyCtxt<'tcx>) -> PolyTraitPredicate<'tcx> {
|
||||
self.map_bound(|trait_ref| TraitPredicate {
|
||||
impl<'tcx> UpcastFrom<TyCtxt<'tcx>, Binder<'tcx, TraitRef<'tcx>>> for PolyTraitPredicate<'tcx> {
|
||||
fn upcast_from(from: Binder<'tcx, TraitRef<'tcx>>, _tcx: TyCtxt<'tcx>) -> Self {
|
||||
from.map_bound(|trait_ref| TraitPredicate {
|
||||
trait_ref,
|
||||
polarity: ty::PredicatePolarity::Positive,
|
||||
polarity: PredicatePolarity::Positive,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> ToPredicate<'tcx> for TraitPredicate<'tcx> {
|
||||
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
|
||||
PredicateKind::Clause(ClauseKind::Trait(self)).to_predicate(tcx)
|
||||
impl<'tcx> UpcastFrom<TyCtxt<'tcx>, TraitPredicate<'tcx>> for Predicate<'tcx> {
|
||||
fn upcast_from(from: TraitPredicate<'tcx>, tcx: TyCtxt<'tcx>) -> Self {
|
||||
PredicateKind::Clause(ClauseKind::Trait(from)).upcast(tcx)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> ToPredicate<'tcx> for PolyTraitPredicate<'tcx> {
|
||||
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
|
||||
self.map_bound(|p| PredicateKind::Clause(ClauseKind::Trait(p))).to_predicate(tcx)
|
||||
impl<'tcx> UpcastFrom<TyCtxt<'tcx>, PolyTraitPredicate<'tcx>> for Predicate<'tcx> {
|
||||
fn upcast_from(from: PolyTraitPredicate<'tcx>, tcx: TyCtxt<'tcx>) -> Self {
|
||||
from.map_bound(|p| PredicateKind::Clause(ClauseKind::Trait(p))).upcast(tcx)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> ToPredicate<'tcx, Clause<'tcx>> for TraitPredicate<'tcx> {
|
||||
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Clause<'tcx> {
|
||||
let p: Predicate<'tcx> = self.to_predicate(tcx);
|
||||
impl<'tcx> UpcastFrom<TyCtxt<'tcx>, TraitPredicate<'tcx>> for Clause<'tcx> {
|
||||
fn upcast_from(from: TraitPredicate<'tcx>, tcx: TyCtxt<'tcx>) -> Self {
|
||||
let p: Predicate<'tcx> = from.upcast(tcx);
|
||||
p.expect_clause()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> ToPredicate<'tcx, Clause<'tcx>> for PolyTraitPredicate<'tcx> {
|
||||
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Clause<'tcx> {
|
||||
let p: Predicate<'tcx> = self.to_predicate(tcx);
|
||||
impl<'tcx> UpcastFrom<TyCtxt<'tcx>, PolyTraitPredicate<'tcx>> for Clause<'tcx> {
|
||||
fn upcast_from(from: PolyTraitPredicate<'tcx>, tcx: TyCtxt<'tcx>) -> Self {
|
||||
let p: Predicate<'tcx> = from.upcast(tcx);
|
||||
p.expect_clause()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> ToPredicate<'tcx> for PolyRegionOutlivesPredicate<'tcx> {
|
||||
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
|
||||
self.map_bound(|p| PredicateKind::Clause(ClauseKind::RegionOutlives(p))).to_predicate(tcx)
|
||||
impl<'tcx> UpcastFrom<TyCtxt<'tcx>, PolyRegionOutlivesPredicate<'tcx>> for Predicate<'tcx> {
|
||||
fn upcast_from(from: PolyRegionOutlivesPredicate<'tcx>, tcx: TyCtxt<'tcx>) -> Self {
|
||||
from.map_bound(|p| PredicateKind::Clause(ClauseKind::RegionOutlives(p))).upcast(tcx)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> ToPredicate<'tcx> for OutlivesPredicate<Ty<'tcx>, ty::Region<'tcx>> {
|
||||
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
|
||||
ty::Binder::dummy(PredicateKind::Clause(ClauseKind::TypeOutlives(self))).to_predicate(tcx)
|
||||
impl<'tcx> UpcastFrom<TyCtxt<'tcx>, OutlivesPredicate<Ty<'tcx>, ty::Region<'tcx>>>
|
||||
for Predicate<'tcx>
|
||||
{
|
||||
fn upcast_from(from: OutlivesPredicate<Ty<'tcx>, ty::Region<'tcx>>, tcx: TyCtxt<'tcx>) -> Self {
|
||||
ty::Binder::dummy(PredicateKind::Clause(ClauseKind::TypeOutlives(from))).upcast(tcx)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> ToPredicate<'tcx> for ProjectionPredicate<'tcx> {
|
||||
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
|
||||
ty::Binder::dummy(PredicateKind::Clause(ClauseKind::Projection(self))).to_predicate(tcx)
|
||||
impl<'tcx> UpcastFrom<TyCtxt<'tcx>, ProjectionPredicate<'tcx>> for Predicate<'tcx> {
|
||||
fn upcast_from(from: ProjectionPredicate<'tcx>, tcx: TyCtxt<'tcx>) -> Self {
|
||||
ty::Binder::dummy(PredicateKind::Clause(ClauseKind::Projection(from))).upcast(tcx)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> ToPredicate<'tcx> for PolyProjectionPredicate<'tcx> {
|
||||
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
|
||||
self.map_bound(|p| PredicateKind::Clause(ClauseKind::Projection(p))).to_predicate(tcx)
|
||||
impl<'tcx> UpcastFrom<TyCtxt<'tcx>, PolyProjectionPredicate<'tcx>> for Predicate<'tcx> {
|
||||
fn upcast_from(from: PolyProjectionPredicate<'tcx>, tcx: TyCtxt<'tcx>) -> Self {
|
||||
from.map_bound(|p| PredicateKind::Clause(ClauseKind::Projection(p))).upcast(tcx)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> ToPredicate<'tcx, Clause<'tcx>> for ProjectionPredicate<'tcx> {
|
||||
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Clause<'tcx> {
|
||||
let p: Predicate<'tcx> = self.to_predicate(tcx);
|
||||
impl<'tcx> UpcastFrom<TyCtxt<'tcx>, ProjectionPredicate<'tcx>> for Clause<'tcx> {
|
||||
fn upcast_from(from: ProjectionPredicate<'tcx>, tcx: TyCtxt<'tcx>) -> Self {
|
||||
let p: Predicate<'tcx> = from.upcast(tcx);
|
||||
p.expect_clause()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> ToPredicate<'tcx, Clause<'tcx>> for PolyProjectionPredicate<'tcx> {
|
||||
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Clause<'tcx> {
|
||||
let p: Predicate<'tcx> = self.to_predicate(tcx);
|
||||
impl<'tcx> UpcastFrom<TyCtxt<'tcx>, PolyProjectionPredicate<'tcx>> for Clause<'tcx> {
|
||||
fn upcast_from(from: PolyProjectionPredicate<'tcx>, tcx: TyCtxt<'tcx>) -> Self {
|
||||
let p: Predicate<'tcx> = from.upcast(tcx);
|
||||
p.expect_clause()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> ToPredicate<'tcx> for NormalizesTo<'tcx> {
|
||||
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
|
||||
PredicateKind::NormalizesTo(self).to_predicate(tcx)
|
||||
impl<'tcx> UpcastFrom<TyCtxt<'tcx>, NormalizesTo<'tcx>> for Predicate<'tcx> {
|
||||
fn upcast_from(from: NormalizesTo<'tcx>, tcx: TyCtxt<'tcx>) -> Self {
|
||||
PredicateKind::NormalizesTo(from).upcast(tcx)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> Predicate<'tcx> {
|
||||
pub fn to_opt_poly_trait_pred(self) -> Option<PolyTraitPredicate<'tcx>> {
|
||||
pub fn as_trait_clause(self) -> Option<PolyTraitPredicate<'tcx>> {
|
||||
let predicate = self.kind();
|
||||
match predicate.skip_binder() {
|
||||
PredicateKind::Clause(ClauseKind::Trait(t)) => Some(predicate.rebind(t)),
|
||||
@@ -742,7 +721,7 @@ pub fn to_opt_poly_trait_pred(self) -> Option<PolyTraitPredicate<'tcx>> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn to_opt_poly_projection_pred(self) -> Option<PolyProjectionPredicate<'tcx>> {
|
||||
pub fn as_projection_clause(self) -> Option<PolyProjectionPredicate<'tcx>> {
|
||||
let predicate = self.kind();
|
||||
match predicate.skip_binder() {
|
||||
PredicateKind::Clause(ClauseKind::Projection(t)) => Some(predicate.rebind(t)),
|
||||
|
||||
@@ -3034,6 +3034,16 @@ macro_rules! define_print_and_forward_display {
|
||||
define_print! {
|
||||
(self, cx):
|
||||
|
||||
ty::FnSig<'tcx> {
|
||||
p!(write("{}", self.safety.prefix_str()));
|
||||
|
||||
if self.abi != Abi::Rust {
|
||||
p!(write("extern {} ", self.abi));
|
||||
}
|
||||
|
||||
p!("fn", pretty_fn_sig(self.inputs(), self.c_variadic, self.output()));
|
||||
}
|
||||
|
||||
ty::TraitRef<'tcx> {
|
||||
p!(write("<{} as {}>", self.self_ty(), self.print_only_trait_path()))
|
||||
}
|
||||
@@ -3169,16 +3179,6 @@ macro_rules! define_print_and_forward_display {
|
||||
p!("{{", comma_sep(self.iter()), "}}")
|
||||
}
|
||||
|
||||
ty::FnSig<'tcx> {
|
||||
p!(write("{}", self.unsafety.prefix_str()));
|
||||
|
||||
if self.abi != Abi::Rust {
|
||||
p!(write("extern {} ", self.abi));
|
||||
}
|
||||
|
||||
p!("fn", pretty_fn_sig(self.inputs(), self.c_variadic, self.output()));
|
||||
}
|
||||
|
||||
TraitRefPrintOnlyTraitPath<'tcx> {
|
||||
p!(print_def_path(self.0.def_id, self.0.args));
|
||||
}
|
||||
|
||||
@@ -396,6 +396,12 @@ pub struct BoundRegion {
|
||||
pub kind: BoundRegionKind,
|
||||
}
|
||||
|
||||
impl<'tcx> rustc_type_ir::inherent::BoundVarLike<TyCtxt<'tcx>> for BoundRegion {
|
||||
fn var(self) -> BoundVar {
|
||||
self.var
|
||||
}
|
||||
}
|
||||
|
||||
impl core::fmt::Debug for BoundRegion {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self.kind {
|
||||
|
||||
@@ -146,7 +146,7 @@ fn relate<R: TypeRelation<'tcx>>(
|
||||
if a.c_variadic != b.c_variadic {
|
||||
return Err(TypeError::VariadicMismatch(expected_found(a.c_variadic, b.c_variadic)));
|
||||
}
|
||||
let unsafety = relation.relate(a.unsafety, b.unsafety)?;
|
||||
let safety = relation.relate(a.safety, b.safety)?;
|
||||
let abi = relation.relate(a.abi, b.abi)?;
|
||||
|
||||
if a.inputs().len() != b.inputs().len() {
|
||||
@@ -181,7 +181,7 @@ fn relate<R: TypeRelation<'tcx>>(
|
||||
Ok(ty::FnSig {
|
||||
inputs_and_output: tcx.mk_type_list_from_iter(inputs_and_output)?,
|
||||
c_variadic: a.c_variadic,
|
||||
unsafety,
|
||||
safety,
|
||||
abi,
|
||||
})
|
||||
}
|
||||
@@ -197,13 +197,13 @@ fn relate<R: TypeRelation<'tcx>>(
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> Relate<'tcx> for hir::Unsafety {
|
||||
impl<'tcx> Relate<'tcx> for hir::Safety {
|
||||
fn relate<R: TypeRelation<'tcx>>(
|
||||
_relation: &mut R,
|
||||
a: hir::Unsafety,
|
||||
b: hir::Unsafety,
|
||||
) -> RelateResult<'tcx, hir::Unsafety> {
|
||||
if a != b { Err(TypeError::UnsafetyMismatch(expected_found(a, b))) } else { Ok(a) }
|
||||
a: hir::Safety,
|
||||
b: hir::Safety,
|
||||
) -> RelateResult<'tcx, hir::Safety> {
|
||||
if a != b { Err(TypeError::SafetyMismatch(expected_found(a, b))) } else { Ok(a) }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -83,49 +83,6 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> fmt::Debug for ty::FnSig<'tcx> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
WithInfcx::with_no_infcx(self).fmt(f)
|
||||
}
|
||||
}
|
||||
impl<'tcx> DebugWithInfcx<TyCtxt<'tcx>> for ty::FnSig<'tcx> {
|
||||
fn fmt<Infcx: InferCtxtLike<Interner = TyCtxt<'tcx>>>(
|
||||
this: WithInfcx<'_, Infcx, &Self>,
|
||||
f: &mut core::fmt::Formatter<'_>,
|
||||
) -> core::fmt::Result {
|
||||
let sig = this.data;
|
||||
let ty::FnSig { inputs_and_output: _, c_variadic, unsafety, abi } = sig;
|
||||
|
||||
write!(f, "{}", unsafety.prefix_str())?;
|
||||
match abi {
|
||||
rustc_target::spec::abi::Abi::Rust => (),
|
||||
abi => write!(f, "extern \"{abi:?}\" ")?,
|
||||
};
|
||||
|
||||
write!(f, "fn(")?;
|
||||
let inputs = sig.inputs();
|
||||
match inputs.len() {
|
||||
0 if *c_variadic => write!(f, "...)")?,
|
||||
0 => write!(f, ")")?,
|
||||
_ => {
|
||||
for ty in &sig.inputs()[0..(sig.inputs().len() - 1)] {
|
||||
write!(f, "{:?}, ", &this.wrap(ty))?;
|
||||
}
|
||||
write!(f, "{:?}", &this.wrap(sig.inputs().last().unwrap()))?;
|
||||
if *c_variadic {
|
||||
write!(f, "...")?;
|
||||
}
|
||||
write!(f, ")")?;
|
||||
}
|
||||
}
|
||||
|
||||
match sig.output().kind() {
|
||||
ty::Tuple(list) if list.is_empty() => Ok(()),
|
||||
_ => write!(f, " -> {:?}", &this.wrap(sig.output())),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> ty::DebugWithInfcx<TyCtxt<'tcx>> for Ty<'tcx> {
|
||||
fn fmt<Infcx: InferCtxtLike<Interner = TyCtxt<'tcx>>>(
|
||||
this: WithInfcx<'_, Infcx, &Self>,
|
||||
@@ -398,7 +355,7 @@ fn fmt<Infcx: InferCtxtLike<Interner = TyCtxt<'tcx>>>(
|
||||
// interners).
|
||||
TrivialTypeTraversalAndLiftImpls! {
|
||||
::rustc_hir::def_id::DefId,
|
||||
::rustc_hir::Unsafety,
|
||||
::rustc_hir::Safety,
|
||||
::rustc_target::spec::abi::Abi,
|
||||
crate::ty::ClosureKind,
|
||||
crate::ty::ParamConst,
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user