@@ -15,7 +15,7 @@ use crate::collect::HirPlaceholderCollector;
15
15
use crate :: errors:: AmbiguousLifetimeBound ;
16
16
use crate :: middle:: resolve_bound_vars as rbv;
17
17
use crate :: require_c_abi_if_c_variadic;
18
- use rustc_ast:: TraitObjectSyntax ;
18
+ use rustc_ast:: { FloatTy , TraitObjectSyntax } ;
19
19
use rustc_data_structures:: fx:: { FxHashSet , FxIndexMap } ;
20
20
use rustc_errors:: {
21
21
codes:: * , struct_span_code_err, Applicability , Diag , ErrorGuaranteed , FatalError , MultiSpan ,
@@ -33,6 +33,7 @@ use rustc_middle::ty::{
33
33
TypeVisitableExt ,
34
34
} ;
35
35
use rustc_session:: lint:: builtin:: AMBIGUOUS_ASSOCIATED_ITEMS ;
36
+ use rustc_session:: parse:: feature_err;
36
37
use rustc_span:: edit_distance:: find_best_match_for_name;
37
38
use rustc_span:: symbol:: { kw, Ident , Symbol } ;
38
39
use rustc_span:: { sym, BytePos , Span , DUMMY_SP } ;
@@ -2174,6 +2175,29 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
2174
2175
}
2175
2176
}
2176
2177
} ) ;
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
+
2177
2201
match prim_ty {
2178
2202
hir:: PrimTy :: Bool => tcx. types . bool ,
2179
2203
hir:: PrimTy :: Char => tcx. types . char ,
@@ -2803,6 +2827,31 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
2803
2827
}
2804
2828
Some ( r)
2805
2829
}
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
+ }
2806
2855
}
2807
2856
2808
2857
fn assoc_kind_str ( kind : ty:: AssocKind ) -> & ' static str {
0 commit comments