@@ -27,6 +27,7 @@ use rustc_middle::middle::resolve_bound_vars::Set1;
27
27
use rustc_middle:: { bug, span_bug} ;
28
28
use rustc_session:: config:: { CrateType , ResolveDocLinks } ;
29
29
use rustc_session:: lint;
30
+ use rustc_session:: parse:: feature_err;
30
31
use rustc_span:: source_map:: { respan, Spanned } ;
31
32
use rustc_span:: symbol:: { kw, sym, Ident , Symbol } ;
32
33
use rustc_span:: { BytePos , Span , SyntaxContext } ;
@@ -3923,7 +3924,10 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
3923
3924
self . r . trait_map . insert ( node_id, traits) ;
3924
3925
}
3925
3926
3926
- if PrimTy :: from_name ( path[ 0 ] . ident . name ) . is_some ( ) {
3927
+ if let Some ( prim) = PrimTy :: from_name ( path[ 0 ] . ident . name ) {
3928
+ println ! ( "checking path at defer {path:?}" ) ;
3929
+ self . check_prim_gate ( prim, path_span) ;
3930
+
3927
3931
let mut std_path = Vec :: with_capacity ( 1 + path. len ( ) ) ;
3928
3932
3929
3933
std_path. push ( Segment :: from_ident ( Ident :: with_dummy_span ( sym:: std) ) ) ;
@@ -4123,6 +4127,8 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
4123
4127
&& PrimTy :: from_name ( path[ 0 ] . ident . name ) . is_some ( ) =>
4124
4128
{
4125
4129
let prim = PrimTy :: from_name ( path[ 0 ] . ident . name ) . unwrap ( ) ;
4130
+ println ! ( "checking path at module, {:?}" , path) ;
4131
+ self . check_prim_gate ( prim, path[ 0 ] . ident . span ) ;
4126
4132
PartialRes :: with_unresolved_segments ( Res :: PrimTy ( prim) , path. len ( ) - 1 )
4127
4133
}
4128
4134
PathResult :: Module ( ModuleOrUniformRoot :: Module ( module) ) => {
@@ -4659,6 +4665,29 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
4659
4665
self . r . doc_link_traits_in_scope = doc_link_traits_in_scope;
4660
4666
}
4661
4667
}
4668
+
4669
+ /// If a primitive requires a feature, emit a diagnostic if that feature is not
4670
+ /// enabled.
4671
+ ///
4672
+ /// This recreates the logic of `gate!` without a visitor's methods.
4673
+ fn check_prim_gate ( & self , prim_ty : PrimTy , span : Span ) {
4674
+ let PrimTy :: Float ( float_ty) = prim_ty else {
4675
+ return ;
4676
+ } ;
4677
+
4678
+ let tcx = self . r . tcx ( ) ;
4679
+ let ( sym, msg) = match float_ty {
4680
+ FloatTy :: F16 if !tcx. features ( ) . f16 => ( sym:: f16, "the feature `f16` is unstable" ) ,
4681
+ FloatTy :: F128 if !tcx. features ( ) . f128 => ( sym:: f128, "the feature `f128` is unstable" ) ,
4682
+ _ => return ,
4683
+ } ;
4684
+
4685
+ if span. allows_unstable ( sym) {
4686
+ return ;
4687
+ }
4688
+
4689
+ feature_err ( tcx. sess , sym, span, msg) . emit ( ) ;
4690
+ }
4662
4691
}
4663
4692
4664
4693
/// Walks the whole crate in DFS order, visiting each item, counting the declared number of
0 commit comments