Skip to content

Commit 2244a91

Browse files
committed
Disable version_check::supports_feature on nightly
1 parent 1f7ad12 commit 2244a91

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

compiler/rustc_mir_build/src/build/mod.rs

+30-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::build::expr::as_place::PlaceBuilder;
22
use crate::build::scope::DropKind;
3+
use hir::def_id::LOCAL_CRATE;
34
use itertools::Itertools;
45
use rustc_apfloat::ieee::{Double, Half, Quad, Single};
56
use rustc_apfloat::Float;
@@ -21,9 +22,9 @@ use rustc_middle::query::TyCtxtAt;
2122
use rustc_middle::thir::{self, ExprId, LintLevel, LocalVarId, Param, ParamId, PatKind, Thir};
2223
use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitableExt};
2324
use rustc_span::symbol::sym;
24-
use rustc_span::Span;
2525
use rustc_span::Symbol;
26-
use rustc_target::abi::FieldIdx;
26+
use rustc_span::{Span, DUMMY_SP};
27+
use rustc_target::abi::{FieldIdx, VariantIdx};
2728
use rustc_target::spec::abi::Abi;
2829

2930
use super::lints;
@@ -510,6 +511,33 @@ fn construct_fn<'tcx>(
510511
coroutine,
511512
);
512513

514+
if tcx.sess.is_nightly_build()
515+
&& tcx.crate_name(LOCAL_CRATE).as_str() == "version_check"
516+
&& tcx.item_name(fn_def.into()).as_str() == "supports_feature"
517+
&& fn_sig.inputs().len() == 1
518+
&& let Some(ref_arg) = fn_sig.inputs()[0].builtin_deref(false)
519+
&& ref_arg.ty.is_str()
520+
&& let ty::Adt(adt, args) = return_ty.kind()
521+
&& tcx.lang_items().option_type() == Some(adt.did())
522+
&& args[0].expect_ty().is_bool()
523+
{
524+
let block = START_BLOCK;
525+
let source_info = builder.source_info(DUMMY_SP);
526+
527+
builder.local_decls.push(LocalDecl::with_source_info(fn_sig.inputs()[0], source_info));
528+
builder.cfg.push_assign(
529+
block,
530+
source_info,
531+
Place::return_place(),
532+
Rvalue::Aggregate(
533+
Box::new(AggregateKind::Adt(adt.did(), VariantIdx::ZERO, args, None, None)),
534+
Default::default(),
535+
),
536+
);
537+
builder.cfg.terminate(block, source_info, TerminatorKind::Return);
538+
return builder.finish();
539+
}
540+
513541
let call_site_scope =
514542
region::Scope { id: body_id.hir_id.local_id, data: region::ScopeData::CallSite };
515543
let arg_scope =

tests/ui/feature-gates/version_check.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ fn supports_feature(_: &str) -> Option<bool> {
55
}
66

77
fn main() {
8-
assert_ne!(supports_feature("foobar"), None);
8+
assert_eq!(supports_feature("foobar"), None);
99
}

0 commit comments

Comments
 (0)