Skip to content

Commit 1a7b16b

Browse files
authored
Unrolled build for rust-lang#123603
Rollup merge of rust-lang#123603 - compiler-errors:no-intrinsic, r=estebank Don't even parse an intrinsic unless the feature gate is enabled Don't return true in `tcx.is_intrinsic` if the function is defined locally and `#![feature(intrinsics)]` is not enabled. This is a slightly more general fix than rust-lang#123526, since rust-lang#123587 shows that we have simplifying assumptions about intrinsics elsewhere in the compiler. This will make the code ICE again if the user **enables** `#[feature(intrinsics)]`, but I kind of feel like if we want to fix that, we should make the `INTERNAL_FEATURES` lint `Deny` again. Perhaps we could do that on non-nightly compilers. Or we should just stop compilation altogether if they have `#![feature]` enabled on a non-nightly compiler. As for the UX of *real* cases of hitting these ICEs, I believe pretty strongly that if a compiler/stdlib dev is modifying internal intrinsics (intentionally, like when making a change to rustc) we have no guarantee to make the ICE better looking for them. Honestly, *not* spitting out a stack trace is probably a disservice to the people who hit those ICEs in that case. r? `@Nilstrieb` `@estebank`
2 parents ccfcd95 + 651d02a commit 1a7b16b

10 files changed

+67
-78
lines changed

compiler/rustc_hir_typeck/src/expr.rs

+3-8
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ use rustc_span::source_map::Spanned;
5454
use rustc_span::symbol::{kw, sym, Ident, Symbol};
5555
use rustc_span::Span;
5656
use rustc_target::abi::{FieldIdx, FIRST_VARIANT};
57-
use rustc_target::spec::abi::Abi::RustIntrinsic;
5857
use rustc_trait_selection::infer::InferCtxtExt;
5958
use rustc_trait_selection::traits::error_reporting::suggestions::TypeErrCtxtExt as _;
6059
use rustc_trait_selection::traits::error_reporting::TypeErrCtxtExt;
@@ -541,16 +540,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
541540
if let ty::FnDef(did, _) = *ty.kind() {
542541
let fn_sig = ty.fn_sig(tcx);
543542

544-
if tcx.fn_sig(did).skip_binder().abi() == RustIntrinsic
545-
&& tcx.item_name(did) == sym::transmute
546-
{
543+
if tcx.is_intrinsic(did, sym::transmute) {
547544
let Some(from) = fn_sig.inputs().skip_binder().get(0) else {
548-
let e = self.dcx().span_delayed_bug(
545+
span_bug!(
549546
tcx.def_span(did),
550-
"intrinsic fn `transmute` defined with no parameters",
547+
"intrinsic fn `transmute` defined with no parameters"
551548
);
552-
self.set_tainted_by_errors(e);
553-
return Ty::new_error(tcx, e);
554549
};
555550
let to = fn_sig.output().skip_binder();
556551
// We defer the transmute to the end of typeck, once all inference vars have

compiler/rustc_middle/src/ty/util.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -1684,10 +1684,15 @@ pub fn is_doc_notable_trait(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
16841684
.any(|items| items.iter().any(|item| item.has_name(sym::notable_trait)))
16851685
}
16861686

1687-
/// Determines whether an item is an intrinsic (which may be via Abi or via the `rustc_intrinsic` attribute)
1687+
/// Determines whether an item is an intrinsic (which may be via Abi or via the `rustc_intrinsic` attribute).
1688+
///
1689+
/// We double check the feature gate here because whether a function may be defined as an intrinsic causes
1690+
/// the compiler to make some assumptions about its shape; if the user doesn't use a feature gate, they may
1691+
/// cause an ICE that we otherwise may want to prevent.
16881692
pub fn intrinsic_raw(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<ty::IntrinsicDef> {
1689-
if matches!(tcx.fn_sig(def_id).skip_binder().abi(), Abi::RustIntrinsic)
1690-
|| tcx.has_attr(def_id, sym::rustc_intrinsic)
1693+
if (matches!(tcx.fn_sig(def_id).skip_binder().abi(), Abi::RustIntrinsic)
1694+
&& tcx.features().intrinsics)
1695+
|| (tcx.has_attr(def_id, sym::rustc_intrinsic) && tcx.features().rustc_attrs)
16911696
{
16921697
Some(ty::IntrinsicDef {
16931698
name: tcx.item_name(def_id.into()),

tests/ui/feature-gates/feature-gate-abi.rs

-2
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,8 @@ trait Tuple { }
1313
// Functions
1414
extern "rust-intrinsic" fn f1() {} //~ ERROR intrinsics are subject to change
1515
//~^ ERROR intrinsic must be in
16-
//~| ERROR unrecognized intrinsic function: `f1`
1716
extern "rust-intrinsic" fn f2() {} //~ ERROR intrinsics are subject to change
1817
//~^ ERROR intrinsic must be in
19-
//~| ERROR unrecognized intrinsic function: `f2`
2018
extern "rust-call" fn f4(_: ()) {} //~ ERROR rust-call ABI is subject to change
2119

2220
// Methods in trait definition

tests/ui/feature-gates/feature-gate-abi.stderr

+27-44
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ LL | extern "rust-intrinsic" fn f1() {}
88
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
99

1010
error[E0658]: intrinsics are subject to change
11-
--> $DIR/feature-gate-abi.rs:17:8
11+
--> $DIR/feature-gate-abi.rs:16:8
1212
|
1313
LL | extern "rust-intrinsic" fn f2() {}
1414
| ^^^^^^^^^^^^^^^^
@@ -17,7 +17,7 @@ LL | extern "rust-intrinsic" fn f2() {}
1717
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
1818

1919
error[E0658]: rust-call ABI is subject to change
20-
--> $DIR/feature-gate-abi.rs:20:8
20+
--> $DIR/feature-gate-abi.rs:18:8
2121
|
2222
LL | extern "rust-call" fn f4(_: ()) {}
2323
| ^^^^^^^^^^^
@@ -27,7 +27,7 @@ LL | extern "rust-call" fn f4(_: ()) {}
2727
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
2828

2929
error[E0658]: intrinsics are subject to change
30-
--> $DIR/feature-gate-abi.rs:24:12
30+
--> $DIR/feature-gate-abi.rs:22:12
3131
|
3232
LL | extern "rust-intrinsic" fn m1();
3333
| ^^^^^^^^^^^^^^^^
@@ -36,7 +36,7 @@ LL | extern "rust-intrinsic" fn m1();
3636
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
3737

3838
error[E0658]: intrinsics are subject to change
39-
--> $DIR/feature-gate-abi.rs:26:12
39+
--> $DIR/feature-gate-abi.rs:24:12
4040
|
4141
LL | extern "rust-intrinsic" fn m2();
4242
| ^^^^^^^^^^^^^^^^
@@ -45,7 +45,7 @@ LL | extern "rust-intrinsic" fn m2();
4545
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
4646

4747
error[E0658]: rust-call ABI is subject to change
48-
--> $DIR/feature-gate-abi.rs:28:12
48+
--> $DIR/feature-gate-abi.rs:26:12
4949
|
5050
LL | extern "rust-call" fn m4(_: ());
5151
| ^^^^^^^^^^^
@@ -55,7 +55,7 @@ LL | extern "rust-call" fn m4(_: ());
5555
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
5656

5757
error[E0658]: rust-call ABI is subject to change
58-
--> $DIR/feature-gate-abi.rs:30:12
58+
--> $DIR/feature-gate-abi.rs:28:12
5959
|
6060
LL | extern "rust-call" fn dm4(_: ()) {}
6161
| ^^^^^^^^^^^
@@ -65,7 +65,7 @@ LL | extern "rust-call" fn dm4(_: ()) {}
6565
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
6666

6767
error[E0658]: intrinsics are subject to change
68-
--> $DIR/feature-gate-abi.rs:37:12
68+
--> $DIR/feature-gate-abi.rs:35:12
6969
|
7070
LL | extern "rust-intrinsic" fn m1() {}
7171
| ^^^^^^^^^^^^^^^^
@@ -74,7 +74,7 @@ LL | extern "rust-intrinsic" fn m1() {}
7474
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
7575

7676
error[E0658]: intrinsics are subject to change
77-
--> $DIR/feature-gate-abi.rs:39:12
77+
--> $DIR/feature-gate-abi.rs:37:12
7878
|
7979
LL | extern "rust-intrinsic" fn m2() {}
8080
| ^^^^^^^^^^^^^^^^
@@ -83,7 +83,7 @@ LL | extern "rust-intrinsic" fn m2() {}
8383
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
8484

8585
error[E0658]: rust-call ABI is subject to change
86-
--> $DIR/feature-gate-abi.rs:41:12
86+
--> $DIR/feature-gate-abi.rs:39:12
8787
|
8888
LL | extern "rust-call" fn m4(_: ()) {}
8989
| ^^^^^^^^^^^
@@ -93,7 +93,7 @@ LL | extern "rust-call" fn m4(_: ()) {}
9393
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
9494

9595
error[E0658]: intrinsics are subject to change
96-
--> $DIR/feature-gate-abi.rs:46:12
96+
--> $DIR/feature-gate-abi.rs:44:12
9797
|
9898
LL | extern "rust-intrinsic" fn im1() {}
9999
| ^^^^^^^^^^^^^^^^
@@ -102,7 +102,7 @@ LL | extern "rust-intrinsic" fn im1() {}
102102
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
103103

104104
error[E0658]: intrinsics are subject to change
105-
--> $DIR/feature-gate-abi.rs:48:12
105+
--> $DIR/feature-gate-abi.rs:46:12
106106
|
107107
LL | extern "rust-intrinsic" fn im2() {}
108108
| ^^^^^^^^^^^^^^^^
@@ -111,7 +111,7 @@ LL | extern "rust-intrinsic" fn im2() {}
111111
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
112112

113113
error[E0658]: rust-call ABI is subject to change
114-
--> $DIR/feature-gate-abi.rs:50:12
114+
--> $DIR/feature-gate-abi.rs:48:12
115115
|
116116
LL | extern "rust-call" fn im4(_: ()) {}
117117
| ^^^^^^^^^^^
@@ -121,7 +121,7 @@ LL | extern "rust-call" fn im4(_: ()) {}
121121
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
122122

123123
error[E0658]: intrinsics are subject to change
124-
--> $DIR/feature-gate-abi.rs:54:18
124+
--> $DIR/feature-gate-abi.rs:52:18
125125
|
126126
LL | type A1 = extern "rust-intrinsic" fn();
127127
| ^^^^^^^^^^^^^^^^
@@ -130,7 +130,7 @@ LL | type A1 = extern "rust-intrinsic" fn();
130130
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
131131

132132
error[E0658]: intrinsics are subject to change
133-
--> $DIR/feature-gate-abi.rs:55:18
133+
--> $DIR/feature-gate-abi.rs:53:18
134134
|
135135
LL | type A2 = extern "rust-intrinsic" fn();
136136
| ^^^^^^^^^^^^^^^^
@@ -139,7 +139,7 @@ LL | type A2 = extern "rust-intrinsic" fn();
139139
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
140140

141141
error[E0658]: rust-call ABI is subject to change
142-
--> $DIR/feature-gate-abi.rs:56:18
142+
--> $DIR/feature-gate-abi.rs:54:18
143143
|
144144
LL | type A4 = extern "rust-call" fn(_: ());
145145
| ^^^^^^^^^^^
@@ -149,7 +149,7 @@ LL | type A4 = extern "rust-call" fn(_: ());
149149
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
150150

151151
error[E0658]: intrinsics are subject to change
152-
--> $DIR/feature-gate-abi.rs:59:8
152+
--> $DIR/feature-gate-abi.rs:57:8
153153
|
154154
LL | extern "rust-intrinsic" {}
155155
| ^^^^^^^^^^^^^^^^
@@ -158,7 +158,7 @@ LL | extern "rust-intrinsic" {}
158158
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
159159

160160
error[E0658]: intrinsics are subject to change
161-
--> $DIR/feature-gate-abi.rs:60:8
161+
--> $DIR/feature-gate-abi.rs:58:8
162162
|
163163
LL | extern "rust-intrinsic" {}
164164
| ^^^^^^^^^^^^^^^^
@@ -167,7 +167,7 @@ LL | extern "rust-intrinsic" {}
167167
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
168168

169169
error[E0658]: rust-call ABI is subject to change
170-
--> $DIR/feature-gate-abi.rs:61:8
170+
--> $DIR/feature-gate-abi.rs:59:8
171171
|
172172
LL | extern "rust-call" {}
173173
| ^^^^^^^^^^^
@@ -176,30 +176,14 @@ LL | extern "rust-call" {}
176176
= help: add `#![feature(unboxed_closures)]` to the crate attributes to enable
177177
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
178178

179-
error[E0093]: unrecognized intrinsic function: `f1`
180-
--> $DIR/feature-gate-abi.rs:14:28
181-
|
182-
LL | extern "rust-intrinsic" fn f1() {}
183-
| ^^ unrecognized intrinsic
184-
|
185-
= help: if you're adding an intrinsic, be sure to update `check_intrinsic_type`
186-
187-
error[E0093]: unrecognized intrinsic function: `f2`
188-
--> $DIR/feature-gate-abi.rs:17:28
189-
|
190-
LL | extern "rust-intrinsic" fn f2() {}
191-
| ^^ unrecognized intrinsic
192-
|
193-
= help: if you're adding an intrinsic, be sure to update `check_intrinsic_type`
194-
195179
error: intrinsic must be in `extern "rust-intrinsic" { ... }` block
196-
--> $DIR/feature-gate-abi.rs:24:32
180+
--> $DIR/feature-gate-abi.rs:22:32
197181
|
198182
LL | extern "rust-intrinsic" fn m1();
199183
| ^^
200184

201185
error: intrinsic must be in `extern "rust-intrinsic" { ... }` block
202-
--> $DIR/feature-gate-abi.rs:26:32
186+
--> $DIR/feature-gate-abi.rs:24:32
203187
|
204188
LL | extern "rust-intrinsic" fn m2();
205189
| ^^
@@ -211,36 +195,35 @@ LL | extern "rust-intrinsic" fn f1() {}
211195
| ^^
212196

213197
error: intrinsic must be in `extern "rust-intrinsic" { ... }` block
214-
--> $DIR/feature-gate-abi.rs:17:33
198+
--> $DIR/feature-gate-abi.rs:16:33
215199
|
216200
LL | extern "rust-intrinsic" fn f2() {}
217201
| ^^
218202

219203
error: intrinsic must be in `extern "rust-intrinsic" { ... }` block
220-
--> $DIR/feature-gate-abi.rs:37:37
204+
--> $DIR/feature-gate-abi.rs:35:37
221205
|
222206
LL | extern "rust-intrinsic" fn m1() {}
223207
| ^^
224208

225209
error: intrinsic must be in `extern "rust-intrinsic" { ... }` block
226-
--> $DIR/feature-gate-abi.rs:39:37
210+
--> $DIR/feature-gate-abi.rs:37:37
227211
|
228212
LL | extern "rust-intrinsic" fn m2() {}
229213
| ^^
230214

231215
error: intrinsic must be in `extern "rust-intrinsic" { ... }` block
232-
--> $DIR/feature-gate-abi.rs:46:38
216+
--> $DIR/feature-gate-abi.rs:44:38
233217
|
234218
LL | extern "rust-intrinsic" fn im1() {}
235219
| ^^
236220

237221
error: intrinsic must be in `extern "rust-intrinsic" { ... }` block
238-
--> $DIR/feature-gate-abi.rs:48:38
222+
--> $DIR/feature-gate-abi.rs:46:38
239223
|
240224
LL | extern "rust-intrinsic" fn im2() {}
241225
| ^^
242226

243-
error: aborting due to 29 previous errors
227+
error: aborting due to 27 previous errors
244228

245-
Some errors have detailed explanations: E0093, E0658.
246-
For more information about an error, try `rustc --explain E0093`.
229+
For more information about this error, try `rustc --explain E0658`.

tests/ui/feature-gates/feature-gate-intrinsics.rs

-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,5 @@ extern "rust-intrinsic" { //~ ERROR intrinsics are subject to change
44

55
extern "rust-intrinsic" fn baz() {} //~ ERROR intrinsics are subject to change
66
//~^ ERROR intrinsic must be in
7-
//~| ERROR unrecognized intrinsic function: `baz`
87

98
fn main() {}

tests/ui/feature-gates/feature-gate-intrinsics.stderr

+1-9
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,13 @@ LL | fn bar();
2424
|
2525
= help: if you're adding an intrinsic, be sure to update `check_intrinsic_type`
2626

27-
error[E0093]: unrecognized intrinsic function: `baz`
28-
--> $DIR/feature-gate-intrinsics.rs:5:28
29-
|
30-
LL | extern "rust-intrinsic" fn baz() {}
31-
| ^^^ unrecognized intrinsic
32-
|
33-
= help: if you're adding an intrinsic, be sure to update `check_intrinsic_type`
34-
3527
error: intrinsic must be in `extern "rust-intrinsic" { ... }` block
3628
--> $DIR/feature-gate-intrinsics.rs:5:34
3729
|
3830
LL | extern "rust-intrinsic" fn baz() {}
3931
| ^^
4032

41-
error: aborting due to 5 previous errors
33+
error: aborting due to 4 previous errors
4234

4335
Some errors have detailed explanations: E0093, E0658.
4436
For more information about an error, try `rustc --explain E0093`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
fn main() {
2+
read_via_copy();
3+
}
4+
5+
extern "rust-intrinsic" fn read_via_copy() {}
6+
//~^ ERROR intrinsics are subject to change
7+
//~| ERROR intrinsic must be in `extern "rust-intrinsic" { ... }` block
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
error[E0658]: intrinsics are subject to change
2+
--> $DIR/incorrect-read_via_copy-defn.rs:5:8
3+
|
4+
LL | extern "rust-intrinsic" fn read_via_copy() {}
5+
| ^^^^^^^^^^^^^^^^
6+
|
7+
= help: add `#![feature(intrinsics)]` to the crate attributes to enable
8+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
9+
10+
error: intrinsic must be in `extern "rust-intrinsic" { ... }` block
11+
--> $DIR/incorrect-read_via_copy-defn.rs:5:44
12+
|
13+
LL | extern "rust-intrinsic" fn read_via_copy() {}
14+
| ^^
15+
16+
error: aborting due to 2 previous errors
17+
18+
For more information about this error, try `rustc --explain E0658`.

tests/ui/intrinsics/incorrect-transmute.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,5 @@ fn main() {
33
}
44

55
extern "rust-intrinsic" fn transmute() {}
6-
//~^ ERROR intrinsic has wrong number of type parameters: found 0, expected 2
7-
//~| ERROR intrinsics are subject to change
6+
//~^ ERROR intrinsics are subject to change
87
//~| ERROR intrinsic must be in `extern "rust-intrinsic" { ... }` block

tests/ui/intrinsics/incorrect-transmute.stderr

+2-9
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,12 @@ LL | extern "rust-intrinsic" fn transmute() {}
77
= help: add `#![feature(intrinsics)]` to the crate attributes to enable
88
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
99

10-
error[E0094]: intrinsic has wrong number of type parameters: found 0, expected 2
11-
--> $DIR/incorrect-transmute.rs:5:37
12-
|
13-
LL | extern "rust-intrinsic" fn transmute() {}
14-
| ^ expected 2 type parameters
15-
1610
error: intrinsic must be in `extern "rust-intrinsic" { ... }` block
1711
--> $DIR/incorrect-transmute.rs:5:40
1812
|
1913
LL | extern "rust-intrinsic" fn transmute() {}
2014
| ^^
2115

22-
error: aborting due to 3 previous errors
16+
error: aborting due to 2 previous errors
2317

24-
Some errors have detailed explanations: E0094, E0658.
25-
For more information about an error, try `rustc --explain E0094`.
18+
For more information about this error, try `rustc --explain E0658`.

0 commit comments

Comments
 (0)