@@ -15,7 +15,7 @@ use crate::collect::HirPlaceholderCollector;
1515use crate :: errors:: AmbiguousLifetimeBound ;
1616use crate :: middle:: resolve_bound_vars as rbv;
1717use crate :: require_c_abi_if_c_variadic;
18- use rustc_ast:: TraitObjectSyntax ;
18+ use rustc_ast:: { FloatTy , TraitObjectSyntax } ;
1919use rustc_data_structures:: fx:: { FxHashSet , FxIndexMap } ;
2020use rustc_errors:: {
2121 codes:: * , struct_span_code_err, Applicability , Diag , ErrorGuaranteed , FatalError , MultiSpan ,
@@ -33,6 +33,7 @@ use rustc_middle::ty::{
3333 TypeVisitableExt ,
3434} ;
3535use rustc_session:: lint:: builtin:: AMBIGUOUS_ASSOCIATED_ITEMS ;
36+ use rustc_session:: parse:: feature_err;
3637use rustc_span:: edit_distance:: find_best_match_for_name;
3738use rustc_span:: symbol:: { kw, Ident , Symbol } ;
3839use rustc_span:: { sym, BytePos , Span , DUMMY_SP } ;
@@ -2174,6 +2175,29 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
21742175 }
21752176 }
21762177 } ) ;
2178+
2179+ if let Some ( e) = self . check_float_gate (
2180+ prim_ty,
2181+ FloatTy :: F16 ,
2182+ self . tcx ( ) . features ( ) . f16 ,
2183+ sym:: f16,
2184+ path. span ,
2185+ "the feature `f16` is unstable" ,
2186+ ) {
2187+ return e;
2188+ }
2189+
2190+ if let Some ( e) = self . check_float_gate (
2191+ prim_ty,
2192+ FloatTy :: F128 ,
2193+ self . tcx ( ) . features ( ) . f128 ,
2194+ sym:: f128,
2195+ path. span ,
2196+ "the feature `f128` is unstable" ,
2197+ ) {
2198+ return e;
2199+ }
2200+
21772201 match prim_ty {
21782202 hir:: PrimTy :: Bool => tcx. types . bool ,
21792203 hir:: PrimTy :: Char => tcx. types . char ,
@@ -2803,6 +2827,31 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
28032827 }
28042828 Some ( r)
28052829 }
2830+
2831+ /// If the float type is not enabled by the feature, return `Some(error)`. `None` if there are
2832+ /// no problems.
2833+ fn check_float_gate (
2834+ & self ,
2835+ prim_ty : hir:: PrimTy ,
2836+ gated_ty : FloatTy ,
2837+ feat_enabled : bool ,
2838+ feat_sym : Symbol ,
2839+ span : Span ,
2840+ msg : & ' static str ,
2841+ ) -> Option < Ty < ' tcx > > {
2842+ let hir:: PrimTy :: Float ( float_ty) = prim_ty else {
2843+ return None ;
2844+ } ;
2845+
2846+ if float_ty == gated_ty && !feat_enabled && !span. allows_unstable ( feat_sym) {
2847+ let sess = self . tcx ( ) . sess ;
2848+ let guar = feature_err ( sess, sym:: f16, span, msg) . emit ( ) ;
2849+ self . set_tainted_by_errors ( guar) ;
2850+ Some ( Ty :: new_error ( self . tcx ( ) , guar) )
2851+ } else {
2852+ None
2853+ }
2854+ }
28062855}
28072856
28082857fn assoc_kind_str ( kind : ty:: AssocKind ) -> & ' static str {
0 commit comments