diff --git a/src/librustc/traits/project.rs b/src/librustc/traits/project.rs index 787452121d375..2d63a2ce8a6df 100644 --- a/src/librustc/traits/project.rs +++ b/src/librustc/traits/project.rs @@ -38,28 +38,9 @@ use util::common::FN_OUTPUT_NAME; /// more or less conservative. #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum Reveal { - /// At type-checking time, we refuse to project any associated - /// type that is marked `default`. Non-`default` ("final") types - /// are always projected. This is necessary in general for - /// soundness of specialization. However, we *could* allow - /// projections in fully-monomorphic cases. We choose not to, - /// because we prefer for `default type` to force the type - /// definition to be treated abstractly by any consumers of the - /// impl. Concretely, that means that the following example will - /// fail to compile: - /// - /// ``` - /// trait Assoc { - /// type Output; - /// } - /// - /// impl Assoc for T { - /// default type Output = bool; - /// } - /// - /// fn main() { - /// let <() as Assoc>::Output = true; - /// } + /// At type-checking time, we avoid projecting the concrete type of + /// `impl Trait`. We do allow other monomorphic projections, such as + /// `default type` in the fully monomorphic case. UserFacing, /// At trans time, all monomorphic projections will succeed. @@ -949,15 +930,13 @@ fn assemble_candidates_from_impls<'cx, 'gcx, 'tcx>( // get a result which isn't correct for all monomorphizations. let new_candidate = if !is_default { Some(ProjectionTyCandidate::Select) - } else if obligation.param_env.reveal == Reveal::All { + } else { assert!(!poly_trait_ref.needs_infer()); if !poly_trait_ref.needs_subst() { Some(ProjectionTyCandidate::Select) } else { None } - } else { - None }; candidate_set.vec.extend(new_candidate); diff --git a/src/test/compile-fail/specialization/defaultimpl/specialization-default-projection.rs b/src/test/compile-fail/specialization/defaultimpl/specialization-default-projection.rs index ad55f44255b48..aebdc020e5164 100644 --- a/src/test/compile-fail/specialization/defaultimpl/specialization-default-projection.rs +++ b/src/test/compile-fail/specialization/defaultimpl/specialization-default-projection.rs @@ -32,10 +32,10 @@ fn generic() -> ::Assoc { } fn monomorphic() -> () { - // Even though we know that `()` is not specialized in a - // downstream crate, typeck refuses to project here. + // Since we know that `()` is not specialized in a + // downstream crate, typeck allows projection here. - generic::<()>() //~ ERROR mismatched types + generic::<()>() } fn main() { diff --git a/src/test/compile-fail/specialization/specialization-default-projection.rs b/src/test/compile-fail/specialization/specialization-default-projection.rs index 96cbd7a485251..c50b361034b90 100644 --- a/src/test/compile-fail/specialization/specialization-default-projection.rs +++ b/src/test/compile-fail/specialization/specialization-default-projection.rs @@ -32,10 +32,10 @@ fn generic() -> ::Assoc { } fn monomorphic() -> () { - // Even though we know that `()` is not specialized in a - // downstream crate, typeck refuses to project here. + // Since we know that `()` is not specialized in a + // downstream crate, typeck allows projection here. - generic::<()>() //~ ERROR mismatched types + generic::<()>() } fn main() { diff --git a/src/test/compile-fail/ufcs-partially-resolved.rs b/src/test/compile-fail/ufcs-partially-resolved.rs index f7120ddb11402..8eb0df2657644 100644 --- a/src/test/compile-fail/ufcs-partially-resolved.rs +++ b/src/test/compile-fail/ufcs-partially-resolved.rs @@ -45,7 +45,7 @@ fn main() { ::N::NN; //~ ERROR cannot find associated type `N` in `A` let _: ::Y::NN; //~ ERROR ambiguous associated type let _: ::Y::NN; //~ ERROR expected associated type, found variant `E::Y` - ::Y::NN; //~ ERROR no associated item named `NN` found for type `::Y` + ::Y::NN; //~ ERROR no associated item named `NN` found for type `u16` ::Y::NN; //~ ERROR expected associated type, found variant `E::Y` let _: ::NN; //~ ERROR cannot find associated type `NN` in `Tr::N` @@ -62,5 +62,5 @@ fn main() { let _: ::Z; //~ ERROR expected associated type, found method `Dr::Z` ::X; //~ ERROR expected method or associated constant, found associated type `Dr::X` let _: ::Z::N; //~ ERROR expected associated type, found method `Dr::Z` - ::X::N; //~ ERROR no associated item named `N` found for type `::X` + ::X::N; //~ ERROR no associated item named `N` found for type `u16` }