Deny bare trait objects in librustc_typeck
This commit is contained in:
parent
c946c2539e
commit
f29ac5a680
|
@ -98,7 +98,7 @@ struct ParamRange {
|
||||||
/// This type must not appear anywhere in other converted types.
|
/// This type must not appear anywhere in other converted types.
|
||||||
const TRAIT_OBJECT_DUMMY_SELF: ty::TypeVariants<'static> = ty::TyInfer(ty::FreshTy(0));
|
const TRAIT_OBJECT_DUMMY_SELF: ty::TypeVariants<'static> = ty::TyInfer(ty::FreshTy(0));
|
||||||
|
|
||||||
impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
|
impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o {
|
||||||
pub fn ast_region_to_region(&self,
|
pub fn ast_region_to_region(&self,
|
||||||
lifetime: &hir::Lifetime,
|
lifetime: &hir::Lifetime,
|
||||||
def: Option<&ty::GenericParamDef>)
|
def: Option<&ty::GenericParamDef>)
|
||||||
|
|
|
@ -604,7 +604,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
/// If there is no expected signature, then we will convert the
|
/// If there is no expected signature, then we will convert the
|
||||||
/// types that the user gave into a signature.
|
/// types that the user gave into a signature.
|
||||||
fn supplied_sig_of_closure(&self, decl: &hir::FnDecl) -> ty::PolyFnSig<'tcx> {
|
fn supplied_sig_of_closure(&self, decl: &hir::FnDecl) -> ty::PolyFnSig<'tcx> {
|
||||||
let astconv: &AstConv = self;
|
let astconv: &dyn AstConv = self;
|
||||||
|
|
||||||
// First, convert the types that the user supplied (if any).
|
// First, convert the types that the user supplied (if any).
|
||||||
let supplied_arguments = decl.inputs.iter().map(|a| astconv.ast_ty_to_ty(a));
|
let supplied_arguments = decl.inputs.iter().map(|a| astconv.ast_ty_to_ty(a));
|
||||||
|
@ -630,7 +630,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
/// so should yield an error, but returns back a signature where
|
/// so should yield an error, but returns back a signature where
|
||||||
/// all parameters are of type `TyErr`.
|
/// all parameters are of type `TyErr`.
|
||||||
fn error_sig_of_closure(&self, decl: &hir::FnDecl) -> ty::PolyFnSig<'tcx> {
|
fn error_sig_of_closure(&self, decl: &hir::FnDecl) -> ty::PolyFnSig<'tcx> {
|
||||||
let astconv: &AstConv = self;
|
let astconv: &dyn AstConv = self;
|
||||||
|
|
||||||
let supplied_arguments = decl.inputs.iter().map(|a| {
|
let supplied_arguments = decl.inputs.iter().map(|a| {
|
||||||
// Convert the types that the user supplied (if any), but ignore them.
|
// Convert the types that the user supplied (if any), but ignore them.
|
||||||
|
|
|
@ -1071,7 +1071,7 @@ impl<'gcx, 'tcx, 'exprs, E> CoerceMany<'gcx, 'tcx, 'exprs, E>
|
||||||
pub fn coerce_forced_unit<'a>(&mut self,
|
pub fn coerce_forced_unit<'a>(&mut self,
|
||||||
fcx: &FnCtxt<'a, 'gcx, 'tcx>,
|
fcx: &FnCtxt<'a, 'gcx, 'tcx>,
|
||||||
cause: &ObligationCause<'tcx>,
|
cause: &ObligationCause<'tcx>,
|
||||||
augment_error: &mut FnMut(&mut DiagnosticBuilder),
|
augment_error: &mut dyn FnMut(&mut DiagnosticBuilder),
|
||||||
label_unit_as_expected: bool)
|
label_unit_as_expected: bool)
|
||||||
{
|
{
|
||||||
self.coerce_inner(fcx,
|
self.coerce_inner(fcx,
|
||||||
|
@ -1090,7 +1090,7 @@ impl<'gcx, 'tcx, 'exprs, E> CoerceMany<'gcx, 'tcx, 'exprs, E>
|
||||||
cause: &ObligationCause<'tcx>,
|
cause: &ObligationCause<'tcx>,
|
||||||
expression: Option<&'gcx hir::Expr>,
|
expression: Option<&'gcx hir::Expr>,
|
||||||
mut expression_ty: Ty<'tcx>,
|
mut expression_ty: Ty<'tcx>,
|
||||||
augment_error: Option<&mut FnMut(&mut DiagnosticBuilder)>,
|
augment_error: Option<&mut dyn FnMut(&mut DiagnosticBuilder)>,
|
||||||
label_expression_as_expected: bool)
|
label_expression_as_expected: bool)
|
||||||
{
|
{
|
||||||
// Incorporate whatever type inference information we have
|
// Incorporate whatever type inference information we have
|
||||||
|
|
|
@ -526,7 +526,7 @@ impl<'cx, 'gcx, 'tcx> WritebackCx<'cx, 'gcx, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn resolve<T>(&self, x: &T, span: &Locatable) -> T::Lifted
|
fn resolve<T>(&self, x: &T, span: &dyn Locatable) -> T::Lifted
|
||||||
where
|
where
|
||||||
T: TypeFoldable<'tcx> + ty::Lift<'gcx>,
|
T: TypeFoldable<'tcx> + ty::Lift<'gcx>,
|
||||||
{
|
{
|
||||||
|
@ -580,14 +580,14 @@ impl Locatable for hir::HirId {
|
||||||
struct Resolver<'cx, 'gcx: 'cx + 'tcx, 'tcx: 'cx> {
|
struct Resolver<'cx, 'gcx: 'cx + 'tcx, 'tcx: 'cx> {
|
||||||
tcx: TyCtxt<'cx, 'gcx, 'tcx>,
|
tcx: TyCtxt<'cx, 'gcx, 'tcx>,
|
||||||
infcx: &'cx InferCtxt<'cx, 'gcx, 'tcx>,
|
infcx: &'cx InferCtxt<'cx, 'gcx, 'tcx>,
|
||||||
span: &'cx Locatable,
|
span: &'cx dyn Locatable,
|
||||||
body: &'gcx hir::Body,
|
body: &'gcx hir::Body,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'cx, 'gcx, 'tcx> Resolver<'cx, 'gcx, 'tcx> {
|
impl<'cx, 'gcx, 'tcx> Resolver<'cx, 'gcx, 'tcx> {
|
||||||
fn new(
|
fn new(
|
||||||
fcx: &'cx FnCtxt<'cx, 'gcx, 'tcx>,
|
fcx: &'cx FnCtxt<'cx, 'gcx, 'tcx>,
|
||||||
span: &'cx Locatable,
|
span: &'cx dyn Locatable,
|
||||||
body: &'gcx hir::Body,
|
body: &'gcx hir::Body,
|
||||||
) -> Resolver<'cx, 'gcx, 'tcx> {
|
) -> Resolver<'cx, 'gcx, 'tcx> {
|
||||||
Resolver {
|
Resolver {
|
||||||
|
|
|
@ -212,7 +212,7 @@ pub fn coerce_unsized_info<'a, 'gcx>(gcx: TyCtxt<'a, 'gcx, 'gcx>,
|
||||||
let cause = ObligationCause::misc(span, impl_node_id);
|
let cause = ObligationCause::misc(span, impl_node_id);
|
||||||
let check_mutbl = |mt_a: ty::TypeAndMut<'gcx>,
|
let check_mutbl = |mt_a: ty::TypeAndMut<'gcx>,
|
||||||
mt_b: ty::TypeAndMut<'gcx>,
|
mt_b: ty::TypeAndMut<'gcx>,
|
||||||
mk_ptr: &Fn(Ty<'gcx>) -> Ty<'gcx>| {
|
mk_ptr: &dyn Fn(Ty<'gcx>) -> Ty<'gcx>| {
|
||||||
if (mt_a.mutbl, mt_b.mutbl) == (hir::MutImmutable, hir::MutMutable) {
|
if (mt_a.mutbl, mt_b.mutbl) == (hir::MutImmutable, hir::MutMutable) {
|
||||||
infcx.report_mismatched_types(&cause,
|
infcx.report_mismatched_types(&cause,
|
||||||
mk_ptr(mt_b.ty),
|
mk_ptr(mt_b.ty),
|
||||||
|
|
|
@ -1244,7 +1244,7 @@ fn impl_polarity<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Is it marked with ?Sized
|
// Is it marked with ?Sized
|
||||||
fn is_unsized<'gcx: 'tcx, 'tcx>(astconv: &AstConv<'gcx, 'tcx>,
|
fn is_unsized<'gcx: 'tcx, 'tcx>(astconv: &dyn AstConv<'gcx, 'tcx>,
|
||||||
ast_bounds: &[hir::GenericBound],
|
ast_bounds: &[hir::GenericBound],
|
||||||
span: Span) -> bool
|
span: Span) -> bool
|
||||||
{
|
{
|
||||||
|
@ -1598,7 +1598,7 @@ pub enum SizedByDefault { Yes, No, }
|
||||||
/// Translate the AST's notion of ty param bounds (which are an enum consisting of a newtyped Ty or
|
/// Translate the AST's notion of ty param bounds (which are an enum consisting of a newtyped Ty or
|
||||||
/// a region) to ty's notion of ty param bounds, which can either be user-defined traits, or the
|
/// a region) to ty's notion of ty param bounds, which can either be user-defined traits, or the
|
||||||
/// built-in trait (formerly known as kind): Send.
|
/// built-in trait (formerly known as kind): Send.
|
||||||
pub fn compute_bounds<'gcx: 'tcx, 'tcx>(astconv: &AstConv<'gcx, 'tcx>,
|
pub fn compute_bounds<'gcx: 'tcx, 'tcx>(astconv: &dyn AstConv<'gcx, 'tcx>,
|
||||||
param_ty: Ty<'tcx>,
|
param_ty: Ty<'tcx>,
|
||||||
ast_bounds: &[hir::GenericBound],
|
ast_bounds: &[hir::GenericBound],
|
||||||
sized_by_default: SizedByDefault,
|
sized_by_default: SizedByDefault,
|
||||||
|
@ -1646,7 +1646,7 @@ pub fn compute_bounds<'gcx: 'tcx, 'tcx>(astconv: &AstConv<'gcx, 'tcx>,
|
||||||
/// because this can be anywhere from 0 predicates (`T:?Sized` adds no
|
/// because this can be anywhere from 0 predicates (`T:?Sized` adds no
|
||||||
/// predicates) to 1 (`T:Foo`) to many (`T:Bar<X=i32>` adds `T:Bar`
|
/// predicates) to 1 (`T:Foo`) to many (`T:Bar<X=i32>` adds `T:Bar`
|
||||||
/// and `<T as Bar>::X == i32`).
|
/// and `<T as Bar>::X == i32`).
|
||||||
fn predicates_from_bound<'tcx>(astconv: &AstConv<'tcx, 'tcx>,
|
fn predicates_from_bound<'tcx>(astconv: &dyn AstConv<'tcx, 'tcx>,
|
||||||
param_ty: Ty<'tcx>,
|
param_ty: Ty<'tcx>,
|
||||||
bound: &hir::GenericBound)
|
bound: &hir::GenericBound)
|
||||||
-> Vec<ty::Predicate<'tcx>>
|
-> Vec<ty::Predicate<'tcx>>
|
||||||
|
|
|
@ -2338,7 +2338,7 @@ Rust does not currently support this. A simple example that causes this error:
|
||||||
|
|
||||||
```compile_fail,E0225
|
```compile_fail,E0225
|
||||||
fn main() {
|
fn main() {
|
||||||
let _: Box<std::io::Read + std::io::Write>;
|
let _: Box<dyn std::io::Read + std::io::Write>;
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -2348,7 +2348,7 @@ auto traits. For example, the following compiles correctly:
|
||||||
|
|
||||||
```
|
```
|
||||||
fn main() {
|
fn main() {
|
||||||
let _: Box<std::io::Read + Send + Sync>;
|
let _: Box<dyn std::io::Read + Send + Sync>;
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
"##,
|
"##,
|
||||||
|
|
|
@ -70,6 +70,7 @@ This API is completely unstable and subject to change.
|
||||||
html_root_url = "https://doc.rust-lang.org/nightly/")]
|
html_root_url = "https://doc.rust-lang.org/nightly/")]
|
||||||
|
|
||||||
#![allow(non_camel_case_types)]
|
#![allow(non_camel_case_types)]
|
||||||
|
#![deny(bare_trait_objects)]
|
||||||
|
|
||||||
#![feature(box_patterns)]
|
#![feature(box_patterns)]
|
||||||
#![feature(box_syntax)]
|
#![feature(box_syntax)]
|
||||||
|
|
Loading…
Reference in New Issue