Skip to content

Commit f29ac5a

Browse files
committed
Deny bare trait objects in librustc_typeck
1 parent c946c25 commit f29ac5a

File tree

8 files changed

+15
-14
lines changed

8 files changed

+15
-14
lines changed

src/librustc_typeck/astconv.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ struct ParamRange {
9898
/// This type must not appear anywhere in other converted types.
9999
const TRAIT_OBJECT_DUMMY_SELF: ty::TypeVariants<'static> = ty::TyInfer(ty::FreshTy(0));
100100

101-
impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
101+
impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o {
102102
pub fn ast_region_to_region(&self,
103103
lifetime: &hir::Lifetime,
104104
def: Option<&ty::GenericParamDef>)

src/librustc_typeck/check/closure.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
604604
/// If there is no expected signature, then we will convert the
605605
/// types that the user gave into a signature.
606606
fn supplied_sig_of_closure(&self, decl: &hir::FnDecl) -> ty::PolyFnSig<'tcx> {
607-
let astconv: &AstConv = self;
607+
let astconv: &dyn AstConv = self;
608608

609609
// First, convert the types that the user supplied (if any).
610610
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> {
630630
/// so should yield an error, but returns back a signature where
631631
/// all parameters are of type `TyErr`.
632632
fn error_sig_of_closure(&self, decl: &hir::FnDecl) -> ty::PolyFnSig<'tcx> {
633-
let astconv: &AstConv = self;
633+
let astconv: &dyn AstConv = self;
634634

635635
let supplied_arguments = decl.inputs.iter().map(|a| {
636636
// Convert the types that the user supplied (if any), but ignore them.

src/librustc_typeck/check/coercion.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1071,7 +1071,7 @@ impl<'gcx, 'tcx, 'exprs, E> CoerceMany<'gcx, 'tcx, 'exprs, E>
10711071
pub fn coerce_forced_unit<'a>(&mut self,
10721072
fcx: &FnCtxt<'a, 'gcx, 'tcx>,
10731073
cause: &ObligationCause<'tcx>,
1074-
augment_error: &mut FnMut(&mut DiagnosticBuilder),
1074+
augment_error: &mut dyn FnMut(&mut DiagnosticBuilder),
10751075
label_unit_as_expected: bool)
10761076
{
10771077
self.coerce_inner(fcx,
@@ -1090,7 +1090,7 @@ impl<'gcx, 'tcx, 'exprs, E> CoerceMany<'gcx, 'tcx, 'exprs, E>
10901090
cause: &ObligationCause<'tcx>,
10911091
expression: Option<&'gcx hir::Expr>,
10921092
mut expression_ty: Ty<'tcx>,
1093-
augment_error: Option<&mut FnMut(&mut DiagnosticBuilder)>,
1093+
augment_error: Option<&mut dyn FnMut(&mut DiagnosticBuilder)>,
10941094
label_expression_as_expected: bool)
10951095
{
10961096
// Incorporate whatever type inference information we have

src/librustc_typeck/check/writeback.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ impl<'cx, 'gcx, 'tcx> WritebackCx<'cx, 'gcx, 'tcx> {
526526
}
527527
}
528528

529-
fn resolve<T>(&self, x: &T, span: &Locatable) -> T::Lifted
529+
fn resolve<T>(&self, x: &T, span: &dyn Locatable) -> T::Lifted
530530
where
531531
T: TypeFoldable<'tcx> + ty::Lift<'gcx>,
532532
{
@@ -580,14 +580,14 @@ impl Locatable for hir::HirId {
580580
struct Resolver<'cx, 'gcx: 'cx + 'tcx, 'tcx: 'cx> {
581581
tcx: TyCtxt<'cx, 'gcx, 'tcx>,
582582
infcx: &'cx InferCtxt<'cx, 'gcx, 'tcx>,
583-
span: &'cx Locatable,
583+
span: &'cx dyn Locatable,
584584
body: &'gcx hir::Body,
585585
}
586586

587587
impl<'cx, 'gcx, 'tcx> Resolver<'cx, 'gcx, 'tcx> {
588588
fn new(
589589
fcx: &'cx FnCtxt<'cx, 'gcx, 'tcx>,
590-
span: &'cx Locatable,
590+
span: &'cx dyn Locatable,
591591
body: &'gcx hir::Body,
592592
) -> Resolver<'cx, 'gcx, 'tcx> {
593593
Resolver {

src/librustc_typeck/coherence/builtin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ pub fn coerce_unsized_info<'a, 'gcx>(gcx: TyCtxt<'a, 'gcx, 'gcx>,
212212
let cause = ObligationCause::misc(span, impl_node_id);
213213
let check_mutbl = |mt_a: ty::TypeAndMut<'gcx>,
214214
mt_b: ty::TypeAndMut<'gcx>,
215-
mk_ptr: &Fn(Ty<'gcx>) -> Ty<'gcx>| {
215+
mk_ptr: &dyn Fn(Ty<'gcx>) -> Ty<'gcx>| {
216216
if (mt_a.mutbl, mt_b.mutbl) == (hir::MutImmutable, hir::MutMutable) {
217217
infcx.report_mismatched_types(&cause,
218218
mk_ptr(mt_b.ty),

src/librustc_typeck/collect.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1244,7 +1244,7 @@ fn impl_polarity<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
12441244
}
12451245

12461246
// Is it marked with ?Sized
1247-
fn is_unsized<'gcx: 'tcx, 'tcx>(astconv: &AstConv<'gcx, 'tcx>,
1247+
fn is_unsized<'gcx: 'tcx, 'tcx>(astconv: &dyn AstConv<'gcx, 'tcx>,
12481248
ast_bounds: &[hir::GenericBound],
12491249
span: Span) -> bool
12501250
{
@@ -1598,7 +1598,7 @@ pub enum SizedByDefault { Yes, No, }
15981598
/// Translate the AST's notion of ty param bounds (which are an enum consisting of a newtyped Ty or
15991599
/// a region) to ty's notion of ty param bounds, which can either be user-defined traits, or the
16001600
/// built-in trait (formerly known as kind): Send.
1601-
pub fn compute_bounds<'gcx: 'tcx, 'tcx>(astconv: &AstConv<'gcx, 'tcx>,
1601+
pub fn compute_bounds<'gcx: 'tcx, 'tcx>(astconv: &dyn AstConv<'gcx, 'tcx>,
16021602
param_ty: Ty<'tcx>,
16031603
ast_bounds: &[hir::GenericBound],
16041604
sized_by_default: SizedByDefault,
@@ -1646,7 +1646,7 @@ pub fn compute_bounds<'gcx: 'tcx, 'tcx>(astconv: &AstConv<'gcx, 'tcx>,
16461646
/// because this can be anywhere from 0 predicates (`T:?Sized` adds no
16471647
/// predicates) to 1 (`T:Foo`) to many (`T:Bar<X=i32>` adds `T:Bar`
16481648
/// and `<T as Bar>::X == i32`).
1649-
fn predicates_from_bound<'tcx>(astconv: &AstConv<'tcx, 'tcx>,
1649+
fn predicates_from_bound<'tcx>(astconv: &dyn AstConv<'tcx, 'tcx>,
16501650
param_ty: Ty<'tcx>,
16511651
bound: &hir::GenericBound)
16521652
-> Vec<ty::Predicate<'tcx>>

src/librustc_typeck/diagnostics.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2338,7 +2338,7 @@ Rust does not currently support this. A simple example that causes this error:
23382338
23392339
```compile_fail,E0225
23402340
fn main() {
2341-
let _: Box<std::io::Read + std::io::Write>;
2341+
let _: Box<dyn std::io::Read + std::io::Write>;
23422342
}
23432343
```
23442344
@@ -2348,7 +2348,7 @@ auto traits. For example, the following compiles correctly:
23482348
23492349
```
23502350
fn main() {
2351-
let _: Box<std::io::Read + Send + Sync>;
2351+
let _: Box<dyn std::io::Read + Send + Sync>;
23522352
}
23532353
```
23542354
"##,

src/librustc_typeck/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ This API is completely unstable and subject to change.
7070
html_root_url = "https://doc.rust-lang.org/nightly/")]
7171

7272
#![allow(non_camel_case_types)]
73+
#![deny(bare_trait_objects)]
7374

7475
#![feature(box_patterns)]
7576
#![feature(box_syntax)]

0 commit comments

Comments
 (0)