@@ -27,6 +27,7 @@ use rustc_middle::middle::resolve_bound_vars::Set1;
2727use rustc_middle:: { bug, span_bug} ;
2828use rustc_session:: config:: { CrateType , ResolveDocLinks } ;
2929use rustc_session:: lint;
30+ use rustc_session:: parse:: feature_err;
3031use rustc_span:: source_map:: { respan, Spanned } ;
3132use rustc_span:: symbol:: { kw, sym, Ident , Symbol } ;
3233use rustc_span:: { BytePos , Span , SyntaxContext } ;
@@ -3923,7 +3924,10 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
39233924 self . r . trait_map . insert ( node_id, traits) ;
39243925 }
39253926
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+
39273931 let mut std_path = Vec :: with_capacity ( 1 + path. len ( ) ) ;
39283932
39293933 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> {
41234127 && PrimTy :: from_name ( path[ 0 ] . ident . name ) . is_some ( ) =>
41244128 {
41254129 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 ) ;
41264132 PartialRes :: with_unresolved_segments ( Res :: PrimTy ( prim) , path. len ( ) - 1 )
41274133 }
41284134 PathResult :: Module ( ModuleOrUniformRoot :: Module ( module) ) => {
@@ -4659,6 +4665,29 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
46594665 self . r . doc_link_traits_in_scope = doc_link_traits_in_scope;
46604666 }
46614667 }
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+ }
46624691}
46634692
46644693/// Walks the whole crate in DFS order, visiting each item, counting the declared number of
0 commit comments