Skip to content

Commit

Permalink
Remove a useless feature gateing
Browse files Browse the repository at this point in the history
With the planned lazy TAIT system, this will not really make sense anymore anyway.
  • Loading branch information
oli-obk committed Aug 6, 2021
1 parent a30b548 commit c091b5c
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 100 deletions.
65 changes: 2 additions & 63 deletions compiler/rustc_typeck/src/check/check.rs
Expand Up @@ -94,69 +94,8 @@ pub(super) fn check_fn<'a, 'tcx>(

let declared_ret_ty = fn_sig.output();

let feature = match tcx.hir().get(fn_id) {
// TAIT usage in function return position.
// Example:
//
// ```rust
// type Foo = impl Debug;
// fn bar() -> Foo { 42 }
// ```
Node::Item(hir::Item { kind: ItemKind::Fn(..), .. }) |
// TAIT usage in associated function return position.
//
// Example with a free type alias:
//
// ```rust
// type Foo = impl Debug;
// impl SomeTrait for SomeType {
// fn bar() -> Foo { 42 }
// }
// ```
//
// Example with an associated TAIT:
//
// ```rust
// impl SomeTrait for SomeType {
// type Foo = impl Debug;
// fn bar() -> Self::Foo { 42 }
// }
// ```
Node::ImplItem(hir::ImplItem {
kind: hir::ImplItemKind::Fn(..), ..
}) => None,
// Forbid TAIT in trait declarations for now.
// Examples:
//
// ```rust
// type Foo = impl Debug;
// trait Bar {
// fn bar() -> Foo;
// }
// trait Bop {
// type Bop: PartialEq<Foo>;
// }
// ```
Node::TraitItem(hir::TraitItem {
kind: hir::TraitItemKind::Fn(..),
..
}) |
// Forbid TAIT in closure return position for now.
// Example:
//
// ```rust
// type Foo = impl Debug;
// let x = |y| -> Foo { 42 + y };
// ```
Node::Expr(hir::Expr { kind: hir::ExprKind::Closure(..), .. }) => Some(sym::type_alias_impl_trait),
node => bug!("Item being checked wasn't a function/closure: {:?}", node),
};
let revealed_ret_ty = fcx.instantiate_opaque_types_from_value(
fn_id,
declared_ret_ty,
decl.output.span(),
feature,
);
let revealed_ret_ty =
fcx.instantiate_opaque_types_from_value(fn_id, declared_ret_ty, decl.output.span());
debug!("check_fn: declared_ret_ty: {}, revealed_ret_ty: {}", declared_ret_ty, revealed_ret_ty);
fcx.ret_coercion = Some(RefCell::new(CoerceMany::new(revealed_ret_ty)));
fcx.ret_type_span = Some(decl.output.span());
Expand Down
17 changes: 1 addition & 16 deletions compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs
Expand Up @@ -29,12 +29,11 @@ use rustc_middle::ty::{
};
use rustc_session::lint;
use rustc_session::lint::builtin::BARE_TRAIT_OBJECTS;
use rustc_session::parse::feature_err;
use rustc_span::edition::Edition;
use rustc_span::hygiene::DesugaringKind;
use rustc_span::source_map::{original_sp, DUMMY_SP};
use rustc_span::symbol::{kw, sym, Ident};
use rustc_span::{self, BytePos, MultiSpan, Span};
use rustc_span::{hygiene::DesugaringKind, Symbol};
use rustc_trait_selection::infer::InferCtxtExt as _;
use rustc_trait_selection::opaque_types::InferCtxtExt as _;
use rustc_trait_selection::traits::error_reporting::InferCtxtExt as _;
Expand Down Expand Up @@ -368,7 +367,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
parent_id: hir::HirId,
value: T,
value_span: Span,
feature: Option<Symbol>,
) -> T {
let parent_def_id = self.tcx.hir().local_def_id(parent_id);
debug!(
Expand All @@ -388,19 +386,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let mut infcx = self.infcx.inner.borrow_mut();

for (ty, decl) in opaque_type_map {
if let Some(feature) = feature {
if let hir::OpaqueTyOrigin::TyAlias = decl.origin {
if !self.tcx.features().enabled(feature) {
feature_err(
&self.tcx.sess.parse_sess,
feature,
value_span,
"type alias impl trait is not permitted here",
)
.emit();
}
}
}
let _ = infcx.opaque_types.insert(ty, decl);
let _ = infcx.opaque_types_vars.insert(decl.concrete_ty, decl.opaque_type);
}
Expand Down
1 change: 0 additions & 1 deletion src/test/ui/type-alias-impl-trait/issue-60371.rs
Expand Up @@ -11,7 +11,6 @@ impl Bug for &() {
//~^ ERROR the trait bound `(): Bug` is not satisfied

const FUN: fn() -> Self::Item = || ();
//~^ ERROR type alias impl trait is not permitted here
}

fn main() {}
11 changes: 1 addition & 10 deletions src/test/ui/type-alias-impl-trait/issue-60371.stderr
Expand Up @@ -7,15 +7,6 @@ LL | type Item = impl Bug;
= note: see issue #63063 <https://github.com/rust-lang/rust/issues/63063> for more information
= help: add `#![feature(type_alias_impl_trait)]` to the crate attributes to enable

error[E0658]: type alias impl trait is not permitted here
--> $DIR/issue-60371.rs:13:40
|
LL | const FUN: fn() -> Self::Item = || ();
| ^
|
= note: see issue #63063 <https://github.com/rust-lang/rust/issues/63063> for more information
= help: add `#![feature(type_alias_impl_trait)]` to the crate attributes to enable

error[E0277]: the trait bound `(): Bug` is not satisfied
--> $DIR/issue-60371.rs:10:17
|
Expand All @@ -25,7 +16,7 @@ LL | type Item = impl Bug;
= help: the following implementations were found:
<&() as Bug>

error: aborting due to 3 previous errors
error: aborting due to 2 previous errors

Some errors have detailed explanations: E0277, E0658.
For more information about an error, try `rustc --explain E0277`.
@@ -1,4 +1,5 @@
// compile-flags: -Zsave-analysis
// check-pass

#![feature(type_alias_impl_trait, rustc_attrs)]

Expand All @@ -11,9 +12,7 @@ type T = impl Sized;

fn take(_: fn() -> T) {}

#[rustc_error]
fn main() {
//~^ ERROR fatal error triggered by #[rustc_error]
take(|| {});
take(|| {});
}

This file was deleted.

0 comments on commit c091b5c

Please sign in to comment.