Skip to content

Commit

Permalink
Auto merge of rust-lang#123663 - matthiaskrgr:rollup-1qnj9j3, r=matth…
Browse files Browse the repository at this point in the history
…iaskrgr

Rollup of 9 pull requests

Successful merges:

 - rust-lang#122768 (Use the more informative generic type inference failure error on method calls on raw pointers)
 - rust-lang#123620 (sanitizers: Create the rustc_sanitizers crate)
 - rust-lang#123624 ([rustdoc] [GUI tests] Make theme switching closer to reality)
 - rust-lang#123636 (Update books)
 - rust-lang#123647 (rustdoc: slightly clean up the synthesis of blanket impls)
 - rust-lang#123648 (Avoid ICEing without the pattern_types feature gate)
 - rust-lang#123649 (KCFI: Use legal charset in shim encoding)
 - rust-lang#123652 (Fix UI tests with dist-vendored dependencies)
 - rust-lang#123655 (Remove unimplemented!() from BinOp::ty() function)

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Apr 9, 2024
2 parents bd12986 + 9ea1063 commit 86b603c
Show file tree
Hide file tree
Showing 58 changed files with 1,475 additions and 1,060 deletions.
19 changes: 16 additions & 3 deletions Cargo.lock
Expand Up @@ -3670,6 +3670,7 @@ dependencies = [
"rustc_metadata",
"rustc_middle",
"rustc_query_system",
"rustc_sanitizers",
"rustc_session",
"rustc_span",
"rustc_symbol_mangling",
Expand Down Expand Up @@ -4558,6 +4559,21 @@ dependencies = [
"tracing",
]

[[package]]
name = "rustc_sanitizers"
version = "0.0.0"
dependencies = [
"bitflags 2.5.0",
"rustc_data_structures",
"rustc_hir",
"rustc_middle",
"rustc_span",
"rustc_target",
"rustc_trait_selection",
"tracing",
"twox-hash",
]

[[package]]
name = "rustc_serialize"
version = "0.0.0"
Expand Down Expand Up @@ -4633,7 +4649,6 @@ dependencies = [
name = "rustc_symbol_mangling"
version = "0.0.0"
dependencies = [
"bitflags 2.5.0",
"punycode",
"rustc-demangle",
"rustc_data_structures",
Expand All @@ -4643,9 +4658,7 @@ dependencies = [
"rustc_session",
"rustc_span",
"rustc_target",
"rustc_trait_selection",
"tracing",
"twox-hash",
]

[[package]]
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_codegen_llvm/Cargo.toml
Expand Up @@ -28,6 +28,7 @@ rustc_macros = { path = "../rustc_macros" }
rustc_metadata = { path = "../rustc_metadata" }
rustc_middle = { path = "../rustc_middle" }
rustc_query_system = { path = "../rustc_query_system" }
rustc_sanitizers = { path = "../rustc_sanitizers" }
rustc_session = { path = "../rustc_session" }
rustc_span = { path = "../rustc_span" }
rustc_symbol_mangling = { path = "../rustc_symbol_mangling" }
Expand Down
25 changes: 11 additions & 14 deletions compiler/rustc_codegen_llvm/src/builder.rs
Expand Up @@ -20,12 +20,9 @@ use rustc_middle::ty::layout::{
FnAbiError, FnAbiOfHelpers, FnAbiRequest, LayoutError, LayoutOfHelpers, TyAndLayout,
};
use rustc_middle::ty::{self, Instance, Ty, TyCtxt};
use rustc_sanitizers::{cfi, kcfi};
use rustc_session::config::OptLevel;
use rustc_span::Span;
use rustc_symbol_mangling::typeid::{
kcfi_typeid_for_fnabi, kcfi_typeid_for_instance, typeid_for_fnabi, typeid_for_instance,
TypeIdOptions,
};
use rustc_target::abi::{self, call::FnAbi, Align, Size, WrappingRange};
use rustc_target::spec::{HasTargetSpec, SanitizerSet, Target};
use smallvec::SmallVec;
Expand Down Expand Up @@ -1632,18 +1629,18 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
return;
}

let mut options = TypeIdOptions::empty();
let mut options = cfi::TypeIdOptions::empty();
if self.tcx.sess.is_sanitizer_cfi_generalize_pointers_enabled() {
options.insert(TypeIdOptions::GENERALIZE_POINTERS);
options.insert(cfi::TypeIdOptions::GENERALIZE_POINTERS);
}
if self.tcx.sess.is_sanitizer_cfi_normalize_integers_enabled() {
options.insert(TypeIdOptions::NORMALIZE_INTEGERS);
options.insert(cfi::TypeIdOptions::NORMALIZE_INTEGERS);
}

let typeid = if let Some(instance) = instance {
typeid_for_instance(self.tcx, instance, options)
cfi::typeid_for_instance(self.tcx, instance, options)
} else {
typeid_for_fnabi(self.tcx, fn_abi, options)
cfi::typeid_for_fnabi(self.tcx, fn_abi, options)
};
let typeid_metadata = self.cx.typeid_metadata(typeid).unwrap();

Expand Down Expand Up @@ -1680,18 +1677,18 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
return None;
}

let mut options = TypeIdOptions::empty();
let mut options = kcfi::TypeIdOptions::empty();
if self.tcx.sess.is_sanitizer_cfi_generalize_pointers_enabled() {
options.insert(TypeIdOptions::GENERALIZE_POINTERS);
options.insert(kcfi::TypeIdOptions::GENERALIZE_POINTERS);
}
if self.tcx.sess.is_sanitizer_cfi_normalize_integers_enabled() {
options.insert(TypeIdOptions::NORMALIZE_INTEGERS);
options.insert(kcfi::TypeIdOptions::NORMALIZE_INTEGERS);
}

let kcfi_typeid = if let Some(instance) = instance {
kcfi_typeid_for_instance(self.tcx, instance, options)
kcfi::typeid_for_instance(self.tcx, instance, options)
} else {
kcfi_typeid_for_fnabi(self.tcx, fn_abi, options)
kcfi::typeid_for_fnabi(self.tcx, fn_abi, options)
};

Some(llvm::OperandBundleDef::new("kcfi", &[self.const_u32(kcfi_typeid)]))
Expand Down
39 changes: 19 additions & 20 deletions compiler/rustc_codegen_llvm/src/declare.rs
Expand Up @@ -22,10 +22,7 @@ use itertools::Itertools;
use rustc_codegen_ssa::traits::TypeMembershipMethods;
use rustc_data_structures::fx::FxIndexSet;
use rustc_middle::ty::{Instance, Ty};
use rustc_symbol_mangling::typeid::{
kcfi_typeid_for_fnabi, kcfi_typeid_for_instance, typeid_for_fnabi, typeid_for_instance,
TypeIdOptions,
};
use rustc_sanitizers::{cfi, kcfi};
use smallvec::SmallVec;

/// Declare a function.
Expand Down Expand Up @@ -145,47 +142,49 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
if let Some(instance) = instance {
let mut typeids = FxIndexSet::default();
for options in [
TypeIdOptions::GENERALIZE_POINTERS,
TypeIdOptions::NORMALIZE_INTEGERS,
TypeIdOptions::USE_CONCRETE_SELF,
cfi::TypeIdOptions::GENERALIZE_POINTERS,
cfi::TypeIdOptions::NORMALIZE_INTEGERS,
cfi::TypeIdOptions::USE_CONCRETE_SELF,
]
.into_iter()
.powerset()
.map(TypeIdOptions::from_iter)
.map(cfi::TypeIdOptions::from_iter)
{
let typeid = typeid_for_instance(self.tcx, instance, options);
let typeid = cfi::typeid_for_instance(self.tcx, instance, options);
if typeids.insert(typeid.clone()) {
self.add_type_metadata(llfn, typeid);
}
}
} else {
for options in
[TypeIdOptions::GENERALIZE_POINTERS, TypeIdOptions::NORMALIZE_INTEGERS]
.into_iter()
.powerset()
.map(TypeIdOptions::from_iter)
for options in [
cfi::TypeIdOptions::GENERALIZE_POINTERS,
cfi::TypeIdOptions::NORMALIZE_INTEGERS,
]
.into_iter()
.powerset()
.map(cfi::TypeIdOptions::from_iter)
{
let typeid = typeid_for_fnabi(self.tcx, fn_abi, options);
let typeid = cfi::typeid_for_fnabi(self.tcx, fn_abi, options);
self.add_type_metadata(llfn, typeid);
}
}
}

if self.tcx.sess.is_sanitizer_kcfi_enabled() {
// LLVM KCFI does not support multiple !kcfi_type attachments
let mut options = TypeIdOptions::empty();
let mut options = kcfi::TypeIdOptions::empty();
if self.tcx.sess.is_sanitizer_cfi_generalize_pointers_enabled() {
options.insert(TypeIdOptions::GENERALIZE_POINTERS);
options.insert(kcfi::TypeIdOptions::GENERALIZE_POINTERS);
}
if self.tcx.sess.is_sanitizer_cfi_normalize_integers_enabled() {
options.insert(TypeIdOptions::NORMALIZE_INTEGERS);
options.insert(kcfi::TypeIdOptions::NORMALIZE_INTEGERS);
}

if let Some(instance) = instance {
let kcfi_typeid = kcfi_typeid_for_instance(self.tcx, instance, options);
let kcfi_typeid = kcfi::typeid_for_instance(self.tcx, instance, options);
self.set_kcfi_type_metadata(llfn, kcfi_typeid);
} else {
let kcfi_typeid = kcfi_typeid_for_fnabi(self.tcx, fn_abi, options);
let kcfi_typeid = kcfi::typeid_for_fnabi(self.tcx, fn_abi, options);
self.set_kcfi_type_metadata(llfn, kcfi_typeid);
}
}
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_error_codes/src/error_codes/E0699.md
@@ -1,8 +1,10 @@
#### Note: this error code is no longer emitted by the compiler.

A method was called on a raw pointer whose inner type wasn't completely known.

Erroneous code example:

```compile_fail,edition2018,E0699
```compile_fail,edition2018
# #![deny(warnings)]
# fn main() {
let foo = &1;
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_error_codes/src/lib.rs
Expand Up @@ -441,7 +441,7 @@ E0695: 0695,
E0696: 0696,
E0697: 0697,
E0698: 0698,
E0699: 0699,
E0699: 0699, // REMOVED: merged into generic inference var error
E0700: 0700,
E0701: 0701,
E0703: 0703,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_feature/src/unstable.rs
Expand Up @@ -216,7 +216,7 @@ declare_features! (
/// Set the maximum pattern complexity allowed (not limited by default).
(internal, pattern_complexity, "1.78.0", None),
/// Allows using pattern types.
(internal, pattern_types, "CURRENT_RUSTC_VERSION", Some(54882)),
(internal, pattern_types, "CURRENT_RUSTC_VERSION", Some(123646)),
/// Allows using `#[prelude_import]` on glob `use` items.
(internal, prelude_import, "1.2.0", None),
/// Used to identify crates that contain the profiler runtime.
Expand Down
6 changes: 5 additions & 1 deletion compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs
Expand Up @@ -2249,7 +2249,11 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
Ty::new_pat(tcx, ty, pat)
}
hir::PatKind::Err(e) => Ty::new_error(tcx, e),
_ => span_bug!(pat.span, "unsupported pattern for pattern type: {pat:#?}"),
_ => Ty::new_error_with_message(
tcx,
pat.span,
format!("unsupported pattern for pattern type: {pat:#?}"),
),
};
self.record_ty(pat.hir_id, ty, pat.span);
pat_ty
Expand Down
3 changes: 0 additions & 3 deletions compiler/rustc_hir_typeck/messages.ftl
Expand Up @@ -93,9 +93,6 @@ hir_typeck_lossy_provenance_ptr2int =
.suggestion = use `.addr()` to obtain the address of a pointer
.help = if you can't comply with strict provenance and need to expose the pointer provenance you can use `.expose_provenance()` instead
hir_typeck_method_call_on_unknown_raw_pointee =
cannot call a method on a raw pointer with an unknown pointee type
hir_typeck_missing_parentheses_in_range = can't call method `{$method_name}` on type `{$ty_str}`
hir_typeck_no_associated_item = no {$item_kind} named `{$item_name}` found for {$ty_prefix} `{$ty_str}`{$trait_missing_method ->
Expand Down
7 changes: 0 additions & 7 deletions compiler/rustc_hir_typeck/src/errors.rs
Expand Up @@ -76,13 +76,6 @@ pub struct StructExprNonExhaustive {
pub what: &'static str,
}

#[derive(Diagnostic)]
#[diag(hir_typeck_method_call_on_unknown_raw_pointee, code = E0699)]
pub struct MethodCallOnUnknownRawPointee {
#[primary_span]
pub span: Span,
}

#[derive(Diagnostic)]
#[diag(hir_typeck_functional_record_update_on_non_struct, code = E0436)]
pub struct FunctionalRecordUpdateOnNonStruct {
Expand Down
43 changes: 26 additions & 17 deletions compiler/rustc_hir_typeck/src/method/probe.rs
Expand Up @@ -3,7 +3,6 @@ use super::CandidateSource;
use super::MethodError;
use super::NoMatchData;

use crate::errors::MethodCallOnUnknownRawPointee;
use crate::FnCtxt;
use rustc_data_structures::fx::FxHashSet;
use rustc_errors::Applicability;
Expand Down Expand Up @@ -430,21 +429,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
if is_suggestion.0 {
// Ambiguity was encountered during a suggestion. Just keep going.
debug!("ProbeContext: encountered ambiguity in suggestion");
} else if bad_ty.reached_raw_pointer && !self.tcx.features().arbitrary_self_types {
} else if bad_ty.reached_raw_pointer
&& !self.tcx.features().arbitrary_self_types
&& !self.tcx.sess.at_least_rust_2018()
{
// this case used to be allowed by the compiler,
// so we do a future-compat lint here for the 2015 edition
// (see https://github.com/rust-lang/rust/issues/46906)
if self.tcx.sess.at_least_rust_2018() {
self.dcx().emit_err(MethodCallOnUnknownRawPointee { span });
} else {
self.tcx.node_span_lint(
lint::builtin::TYVAR_BEHIND_RAW_POINTER,
scope_expr_id,
span,
"type annotations needed",
|_| {},
);
}
self.tcx.node_span_lint(
lint::builtin::TYVAR_BEHIND_RAW_POINTER,
scope_expr_id,
span,
"type annotations needed",
|_| {},
);
} else {
// Ended up encountering a type variable when doing autoderef,
// but it may not be a type variable after processing obligations
Expand All @@ -455,10 +453,21 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
.unwrap_or_else(|_| span_bug!(span, "instantiating {:?} failed?", ty));
let ty = self.resolve_vars_if_possible(ty.value);
let guar = match *ty.kind() {
ty::Infer(ty::TyVar(_)) => self
.err_ctxt()
.emit_inference_failure_err(self.body_id, span, ty.into(), E0282, true)
.emit(),
ty::Infer(ty::TyVar(_)) => {
let raw_ptr_call =
bad_ty.reached_raw_pointer && !self.tcx.features().arbitrary_self_types;
let mut err = self.err_ctxt().emit_inference_failure_err(
self.body_id,
span,
ty.into(),
E0282,
!raw_ptr_call,
);
if raw_ptr_call {
err.span_label(span, "cannot call a method on a raw pointer with an unknown pointee type");
}
err.emit()
}
ty::Error(guar) => guar,
_ => bug!("unexpected bad final type in method autoderef"),
};
Expand Down
15 changes: 15 additions & 0 deletions compiler/rustc_sanitizers/Cargo.toml
@@ -0,0 +1,15 @@
[package]
name = "rustc_sanitizers"
version = "0.0.0"
edition = "2021"

[dependencies]
bitflags = "2.5.0"
tracing = "0.1"
twox-hash = "1.6.3"
rustc_data_structures = { path = "../rustc_data_structures" }
rustc_hir = { path = "../rustc_hir" }
rustc_middle = { path = "../rustc_middle" }
rustc_span = { path = "../rustc_span" }
rustc_target = { path = "../rustc_target" }
rustc_trait_selection = { path = "../rustc_trait_selection" }
2 changes: 2 additions & 0 deletions compiler/rustc_sanitizers/README.md
@@ -0,0 +1,2 @@
The `rustc_sanitizers` crate contains the source code for providing support for
the [sanitizers](https://github.com/google/sanitizers) to the Rust compiler.
6 changes: 6 additions & 0 deletions compiler/rustc_sanitizers/src/cfi/mod.rs
@@ -0,0 +1,6 @@
//! LLVM Control Flow Integrity (CFI) and cross-language LLVM CFI support for the Rust compiler.
//!
//! For more information about LLVM CFI and cross-language LLVM CFI support for the Rust compiler,
//! see design document in the tracking issue #89653.
pub mod typeid;
pub use crate::cfi::typeid::{typeid_for_fnabi, typeid_for_instance, TypeIdOptions};

0 comments on commit 86b603c

Please sign in to comment.