Skip to content

Commit 86b603c

Browse files
committed
Auto merge of #123663 - matthiaskrgr:rollup-1qnj9j3, r=matthiaskrgr
Rollup of 9 pull requests Successful merges: - #122768 (Use the more informative generic type inference failure error on method calls on raw pointers) - #123620 (sanitizers: Create the rustc_sanitizers crate) - #123624 ([rustdoc] [GUI tests] Make theme switching closer to reality) - #123636 (Update books) - #123647 (rustdoc: slightly clean up the synthesis of blanket impls) - #123648 (Avoid ICEing without the pattern_types feature gate) - #123649 (KCFI: Use legal charset in shim encoding) - #123652 (Fix UI tests with dist-vendored dependencies) - #123655 (Remove unimplemented!() from BinOp::ty() function) r? `@ghost` `@rustbot` modify labels: rollup
2 parents bd12986 + 9ea1063 commit 86b603c

File tree

58 files changed

+1475
-1060
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+1475
-1060
lines changed

Cargo.lock

+16-3
Original file line numberDiff line numberDiff line change
@@ -3670,6 +3670,7 @@ dependencies = [
36703670
"rustc_metadata",
36713671
"rustc_middle",
36723672
"rustc_query_system",
3673+
"rustc_sanitizers",
36733674
"rustc_session",
36743675
"rustc_span",
36753676
"rustc_symbol_mangling",
@@ -4558,6 +4559,21 @@ dependencies = [
45584559
"tracing",
45594560
]
45604561

4562+
[[package]]
4563+
name = "rustc_sanitizers"
4564+
version = "0.0.0"
4565+
dependencies = [
4566+
"bitflags 2.5.0",
4567+
"rustc_data_structures",
4568+
"rustc_hir",
4569+
"rustc_middle",
4570+
"rustc_span",
4571+
"rustc_target",
4572+
"rustc_trait_selection",
4573+
"tracing",
4574+
"twox-hash",
4575+
]
4576+
45614577
[[package]]
45624578
name = "rustc_serialize"
45634579
version = "0.0.0"
@@ -4633,7 +4649,6 @@ dependencies = [
46334649
name = "rustc_symbol_mangling"
46344650
version = "0.0.0"
46354651
dependencies = [
4636-
"bitflags 2.5.0",
46374652
"punycode",
46384653
"rustc-demangle",
46394654
"rustc_data_structures",
@@ -4643,9 +4658,7 @@ dependencies = [
46434658
"rustc_session",
46444659
"rustc_span",
46454660
"rustc_target",
4646-
"rustc_trait_selection",
46474661
"tracing",
4648-
"twox-hash",
46494662
]
46504663

46514664
[[package]]

compiler/rustc_codegen_llvm/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ rustc_macros = { path = "../rustc_macros" }
2828
rustc_metadata = { path = "../rustc_metadata" }
2929
rustc_middle = { path = "../rustc_middle" }
3030
rustc_query_system = { path = "../rustc_query_system" }
31+
rustc_sanitizers = { path = "../rustc_sanitizers" }
3132
rustc_session = { path = "../rustc_session" }
3233
rustc_span = { path = "../rustc_span" }
3334
rustc_symbol_mangling = { path = "../rustc_symbol_mangling" }

compiler/rustc_codegen_llvm/src/builder.rs

+11-14
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,9 @@ use rustc_middle::ty::layout::{
2020
FnAbiError, FnAbiOfHelpers, FnAbiRequest, LayoutError, LayoutOfHelpers, TyAndLayout,
2121
};
2222
use rustc_middle::ty::{self, Instance, Ty, TyCtxt};
23+
use rustc_sanitizers::{cfi, kcfi};
2324
use rustc_session::config::OptLevel;
2425
use rustc_span::Span;
25-
use rustc_symbol_mangling::typeid::{
26-
kcfi_typeid_for_fnabi, kcfi_typeid_for_instance, typeid_for_fnabi, typeid_for_instance,
27-
TypeIdOptions,
28-
};
2926
use rustc_target::abi::{self, call::FnAbi, Align, Size, WrappingRange};
3027
use rustc_target::spec::{HasTargetSpec, SanitizerSet, Target};
3128
use smallvec::SmallVec;
@@ -1632,18 +1629,18 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
16321629
return;
16331630
}
16341631

1635-
let mut options = TypeIdOptions::empty();
1632+
let mut options = cfi::TypeIdOptions::empty();
16361633
if self.tcx.sess.is_sanitizer_cfi_generalize_pointers_enabled() {
1637-
options.insert(TypeIdOptions::GENERALIZE_POINTERS);
1634+
options.insert(cfi::TypeIdOptions::GENERALIZE_POINTERS);
16381635
}
16391636
if self.tcx.sess.is_sanitizer_cfi_normalize_integers_enabled() {
1640-
options.insert(TypeIdOptions::NORMALIZE_INTEGERS);
1637+
options.insert(cfi::TypeIdOptions::NORMALIZE_INTEGERS);
16411638
}
16421639

16431640
let typeid = if let Some(instance) = instance {
1644-
typeid_for_instance(self.tcx, instance, options)
1641+
cfi::typeid_for_instance(self.tcx, instance, options)
16451642
} else {
1646-
typeid_for_fnabi(self.tcx, fn_abi, options)
1643+
cfi::typeid_for_fnabi(self.tcx, fn_abi, options)
16471644
};
16481645
let typeid_metadata = self.cx.typeid_metadata(typeid).unwrap();
16491646

@@ -1680,18 +1677,18 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
16801677
return None;
16811678
}
16821679

1683-
let mut options = TypeIdOptions::empty();
1680+
let mut options = kcfi::TypeIdOptions::empty();
16841681
if self.tcx.sess.is_sanitizer_cfi_generalize_pointers_enabled() {
1685-
options.insert(TypeIdOptions::GENERALIZE_POINTERS);
1682+
options.insert(kcfi::TypeIdOptions::GENERALIZE_POINTERS);
16861683
}
16871684
if self.tcx.sess.is_sanitizer_cfi_normalize_integers_enabled() {
1688-
options.insert(TypeIdOptions::NORMALIZE_INTEGERS);
1685+
options.insert(kcfi::TypeIdOptions::NORMALIZE_INTEGERS);
16891686
}
16901687

16911688
let kcfi_typeid = if let Some(instance) = instance {
1692-
kcfi_typeid_for_instance(self.tcx, instance, options)
1689+
kcfi::typeid_for_instance(self.tcx, instance, options)
16931690
} else {
1694-
kcfi_typeid_for_fnabi(self.tcx, fn_abi, options)
1691+
kcfi::typeid_for_fnabi(self.tcx, fn_abi, options)
16951692
};
16961693

16971694
Some(llvm::OperandBundleDef::new("kcfi", &[self.const_u32(kcfi_typeid)]))

compiler/rustc_codegen_llvm/src/declare.rs

+19-20
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,7 @@ use itertools::Itertools;
2222
use rustc_codegen_ssa::traits::TypeMembershipMethods;
2323
use rustc_data_structures::fx::FxIndexSet;
2424
use rustc_middle::ty::{Instance, Ty};
25-
use rustc_symbol_mangling::typeid::{
26-
kcfi_typeid_for_fnabi, kcfi_typeid_for_instance, typeid_for_fnabi, typeid_for_instance,
27-
TypeIdOptions,
28-
};
25+
use rustc_sanitizers::{cfi, kcfi};
2926
use smallvec::SmallVec;
3027

3128
/// Declare a function.
@@ -145,47 +142,49 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
145142
if let Some(instance) = instance {
146143
let mut typeids = FxIndexSet::default();
147144
for options in [
148-
TypeIdOptions::GENERALIZE_POINTERS,
149-
TypeIdOptions::NORMALIZE_INTEGERS,
150-
TypeIdOptions::USE_CONCRETE_SELF,
145+
cfi::TypeIdOptions::GENERALIZE_POINTERS,
146+
cfi::TypeIdOptions::NORMALIZE_INTEGERS,
147+
cfi::TypeIdOptions::USE_CONCRETE_SELF,
151148
]
152149
.into_iter()
153150
.powerset()
154-
.map(TypeIdOptions::from_iter)
151+
.map(cfi::TypeIdOptions::from_iter)
155152
{
156-
let typeid = typeid_for_instance(self.tcx, instance, options);
153+
let typeid = cfi::typeid_for_instance(self.tcx, instance, options);
157154
if typeids.insert(typeid.clone()) {
158155
self.add_type_metadata(llfn, typeid);
159156
}
160157
}
161158
} else {
162-
for options in
163-
[TypeIdOptions::GENERALIZE_POINTERS, TypeIdOptions::NORMALIZE_INTEGERS]
164-
.into_iter()
165-
.powerset()
166-
.map(TypeIdOptions::from_iter)
159+
for options in [
160+
cfi::TypeIdOptions::GENERALIZE_POINTERS,
161+
cfi::TypeIdOptions::NORMALIZE_INTEGERS,
162+
]
163+
.into_iter()
164+
.powerset()
165+
.map(cfi::TypeIdOptions::from_iter)
167166
{
168-
let typeid = typeid_for_fnabi(self.tcx, fn_abi, options);
167+
let typeid = cfi::typeid_for_fnabi(self.tcx, fn_abi, options);
169168
self.add_type_metadata(llfn, typeid);
170169
}
171170
}
172171
}
173172

174173
if self.tcx.sess.is_sanitizer_kcfi_enabled() {
175174
// LLVM KCFI does not support multiple !kcfi_type attachments
176-
let mut options = TypeIdOptions::empty();
175+
let mut options = kcfi::TypeIdOptions::empty();
177176
if self.tcx.sess.is_sanitizer_cfi_generalize_pointers_enabled() {
178-
options.insert(TypeIdOptions::GENERALIZE_POINTERS);
177+
options.insert(kcfi::TypeIdOptions::GENERALIZE_POINTERS);
179178
}
180179
if self.tcx.sess.is_sanitizer_cfi_normalize_integers_enabled() {
181-
options.insert(TypeIdOptions::NORMALIZE_INTEGERS);
180+
options.insert(kcfi::TypeIdOptions::NORMALIZE_INTEGERS);
182181
}
183182

184183
if let Some(instance) = instance {
185-
let kcfi_typeid = kcfi_typeid_for_instance(self.tcx, instance, options);
184+
let kcfi_typeid = kcfi::typeid_for_instance(self.tcx, instance, options);
186185
self.set_kcfi_type_metadata(llfn, kcfi_typeid);
187186
} else {
188-
let kcfi_typeid = kcfi_typeid_for_fnabi(self.tcx, fn_abi, options);
187+
let kcfi_typeid = kcfi::typeid_for_fnabi(self.tcx, fn_abi, options);
189188
self.set_kcfi_type_metadata(llfn, kcfi_typeid);
190189
}
191190
}

compiler/rustc_error_codes/src/error_codes/E0699.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
#### Note: this error code is no longer emitted by the compiler.
2+
13
A method was called on a raw pointer whose inner type wasn't completely known.
24

35
Erroneous code example:
46

5-
```compile_fail,edition2018,E0699
7+
```compile_fail,edition2018
68
# #![deny(warnings)]
79
# fn main() {
810
let foo = &1;

compiler/rustc_error_codes/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ E0695: 0695,
441441
E0696: 0696,
442442
E0697: 0697,
443443
E0698: 0698,
444-
E0699: 0699,
444+
E0699: 0699, // REMOVED: merged into generic inference var error
445445
E0700: 0700,
446446
E0701: 0701,
447447
E0703: 0703,

compiler/rustc_feature/src/unstable.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ declare_features! (
216216
/// Set the maximum pattern complexity allowed (not limited by default).
217217
(internal, pattern_complexity, "1.78.0", None),
218218
/// Allows using pattern types.
219-
(internal, pattern_types, "CURRENT_RUSTC_VERSION", Some(54882)),
219+
(internal, pattern_types, "CURRENT_RUSTC_VERSION", Some(123646)),
220220
/// Allows using `#[prelude_import]` on glob `use` items.
221221
(internal, prelude_import, "1.2.0", None),
222222
/// Used to identify crates that contain the profiler runtime.

compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -2249,7 +2249,11 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
22492249
Ty::new_pat(tcx, ty, pat)
22502250
}
22512251
hir::PatKind::Err(e) => Ty::new_error(tcx, e),
2252-
_ => span_bug!(pat.span, "unsupported pattern for pattern type: {pat:#?}"),
2252+
_ => Ty::new_error_with_message(
2253+
tcx,
2254+
pat.span,
2255+
format!("unsupported pattern for pattern type: {pat:#?}"),
2256+
),
22532257
};
22542258
self.record_ty(pat.hir_id, ty, pat.span);
22552259
pat_ty

compiler/rustc_hir_typeck/messages.ftl

-3
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,6 @@ hir_typeck_lossy_provenance_ptr2int =
9393
.suggestion = use `.addr()` to obtain the address of a pointer
9494
.help = if you can't comply with strict provenance and need to expose the pointer provenance you can use `.expose_provenance()` instead
9595
96-
hir_typeck_method_call_on_unknown_raw_pointee =
97-
cannot call a method on a raw pointer with an unknown pointee type
98-
9996
hir_typeck_missing_parentheses_in_range = can't call method `{$method_name}` on type `{$ty_str}`
10097
10198
hir_typeck_no_associated_item = no {$item_kind} named `{$item_name}` found for {$ty_prefix} `{$ty_str}`{$trait_missing_method ->

compiler/rustc_hir_typeck/src/errors.rs

-7
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,6 @@ pub struct StructExprNonExhaustive {
7676
pub what: &'static str,
7777
}
7878

79-
#[derive(Diagnostic)]
80-
#[diag(hir_typeck_method_call_on_unknown_raw_pointee, code = E0699)]
81-
pub struct MethodCallOnUnknownRawPointee {
82-
#[primary_span]
83-
pub span: Span,
84-
}
85-
8679
#[derive(Diagnostic)]
8780
#[diag(hir_typeck_functional_record_update_on_non_struct, code = E0436)]
8881
pub struct FunctionalRecordUpdateOnNonStruct {

compiler/rustc_hir_typeck/src/method/probe.rs

+26-17
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use super::CandidateSource;
33
use super::MethodError;
44
use super::NoMatchData;
55

6-
use crate::errors::MethodCallOnUnknownRawPointee;
76
use crate::FnCtxt;
87
use rustc_data_structures::fx::FxHashSet;
98
use rustc_errors::Applicability;
@@ -430,21 +429,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
430429
if is_suggestion.0 {
431430
// Ambiguity was encountered during a suggestion. Just keep going.
432431
debug!("ProbeContext: encountered ambiguity in suggestion");
433-
} else if bad_ty.reached_raw_pointer && !self.tcx.features().arbitrary_self_types {
432+
} else if bad_ty.reached_raw_pointer
433+
&& !self.tcx.features().arbitrary_self_types
434+
&& !self.tcx.sess.at_least_rust_2018()
435+
{
434436
// this case used to be allowed by the compiler,
435437
// so we do a future-compat lint here for the 2015 edition
436438
// (see https://github.com/rust-lang/rust/issues/46906)
437-
if self.tcx.sess.at_least_rust_2018() {
438-
self.dcx().emit_err(MethodCallOnUnknownRawPointee { span });
439-
} else {
440-
self.tcx.node_span_lint(
441-
lint::builtin::TYVAR_BEHIND_RAW_POINTER,
442-
scope_expr_id,
443-
span,
444-
"type annotations needed",
445-
|_| {},
446-
);
447-
}
439+
self.tcx.node_span_lint(
440+
lint::builtin::TYVAR_BEHIND_RAW_POINTER,
441+
scope_expr_id,
442+
span,
443+
"type annotations needed",
444+
|_| {},
445+
);
448446
} else {
449447
// Ended up encountering a type variable when doing autoderef,
450448
// but it may not be a type variable after processing obligations
@@ -455,10 +453,21 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
455453
.unwrap_or_else(|_| span_bug!(span, "instantiating {:?} failed?", ty));
456454
let ty = self.resolve_vars_if_possible(ty.value);
457455
let guar = match *ty.kind() {
458-
ty::Infer(ty::TyVar(_)) => self
459-
.err_ctxt()
460-
.emit_inference_failure_err(self.body_id, span, ty.into(), E0282, true)
461-
.emit(),
456+
ty::Infer(ty::TyVar(_)) => {
457+
let raw_ptr_call =
458+
bad_ty.reached_raw_pointer && !self.tcx.features().arbitrary_self_types;
459+
let mut err = self.err_ctxt().emit_inference_failure_err(
460+
self.body_id,
461+
span,
462+
ty.into(),
463+
E0282,
464+
!raw_ptr_call,
465+
);
466+
if raw_ptr_call {
467+
err.span_label(span, "cannot call a method on a raw pointer with an unknown pointee type");
468+
}
469+
err.emit()
470+
}
462471
ty::Error(guar) => guar,
463472
_ => bug!("unexpected bad final type in method autoderef"),
464473
};

compiler/rustc_sanitizers/Cargo.toml

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[package]
2+
name = "rustc_sanitizers"
3+
version = "0.0.0"
4+
edition = "2021"
5+
6+
[dependencies]
7+
bitflags = "2.5.0"
8+
tracing = "0.1"
9+
twox-hash = "1.6.3"
10+
rustc_data_structures = { path = "../rustc_data_structures" }
11+
rustc_hir = { path = "../rustc_hir" }
12+
rustc_middle = { path = "../rustc_middle" }
13+
rustc_span = { path = "../rustc_span" }
14+
rustc_target = { path = "../rustc_target" }
15+
rustc_trait_selection = { path = "../rustc_trait_selection" }

compiler/rustc_sanitizers/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
The `rustc_sanitizers` crate contains the source code for providing support for
2+
the [sanitizers](https://github.com/google/sanitizers) to the Rust compiler.
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//! LLVM Control Flow Integrity (CFI) and cross-language LLVM CFI support for the Rust compiler.
2+
//!
3+
//! For more information about LLVM CFI and cross-language LLVM CFI support for the Rust compiler,
4+
//! see design document in the tracking issue #89653.
5+
pub mod typeid;
6+
pub use crate::cfi::typeid::{typeid_for_fnabi, typeid_for_instance, TypeIdOptions};

0 commit comments

Comments
 (0)