Skip to content

Commit 27f78a0

Browse files
committed
Auto merge of #147720 - matthiaskrgr:rollup-rpq38qg, r=matthiaskrgr
Rollup of 5 pull requests Successful merges: - #143191 (Stabilize `rwlock_downgrade` library feature) - #147000 (std: Add Motor OS std library port) - #147670 (some `ErrorGuaranteed` cleanups) - #147716 (Fix some comments) - #147718 (miri: use allocator_shim_contents codegen helper) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 4f08307 + 7289d92 commit 27f78a0

File tree

65 files changed

+2537
-265
lines changed

Some content is hidden

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

65 files changed

+2537
-265
lines changed

compiler/rustc_ast/src/expand/allocator.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,23 @@ pub enum AllocatorTy {
3131
Usize,
3232
}
3333

34+
/// Some allocator methods are known to the compiler: they act more like
35+
/// intrinsics/language primitives than library-defined functions.
36+
/// FIXME: ideally this would be derived from attributes like `#[rustc_allocator]`,
37+
/// so we don't have two sources of truth.
38+
#[derive(Copy, Clone, Debug)]
39+
pub enum SpecialAllocatorMethod {
40+
Alloc,
41+
AllocZeroed,
42+
Dealloc,
43+
Realloc,
44+
}
45+
3446
/// A method that will be codegened in the allocator shim.
3547
#[derive(Copy, Clone)]
3648
pub struct AllocatorMethod {
3749
pub name: Symbol,
50+
pub special: Option<SpecialAllocatorMethod>,
3851
pub inputs: &'static [AllocatorMethodInput],
3952
pub output: AllocatorTy,
4053
}
@@ -47,11 +60,13 @@ pub struct AllocatorMethodInput {
4760
pub static ALLOCATOR_METHODS: &[AllocatorMethod] = &[
4861
AllocatorMethod {
4962
name: sym::alloc,
63+
special: Some(SpecialAllocatorMethod::Alloc),
5064
inputs: &[AllocatorMethodInput { name: "layout", ty: AllocatorTy::Layout }],
5165
output: AllocatorTy::ResultPtr,
5266
},
5367
AllocatorMethod {
5468
name: sym::dealloc,
69+
special: Some(SpecialAllocatorMethod::Dealloc),
5570
inputs: &[
5671
AllocatorMethodInput { name: "ptr", ty: AllocatorTy::Ptr },
5772
AllocatorMethodInput { name: "layout", ty: AllocatorTy::Layout },
@@ -60,6 +75,7 @@ pub static ALLOCATOR_METHODS: &[AllocatorMethod] = &[
6075
},
6176
AllocatorMethod {
6277
name: sym::realloc,
78+
special: Some(SpecialAllocatorMethod::Realloc),
6379
inputs: &[
6480
AllocatorMethodInput { name: "ptr", ty: AllocatorTy::Ptr },
6581
AllocatorMethodInput { name: "layout", ty: AllocatorTy::Layout },
@@ -69,6 +85,7 @@ pub static ALLOCATOR_METHODS: &[AllocatorMethod] = &[
6985
},
7086
AllocatorMethod {
7187
name: sym::alloc_zeroed,
88+
special: Some(SpecialAllocatorMethod::AllocZeroed),
7289
inputs: &[AllocatorMethodInput { name: "layout", ty: AllocatorTy::Layout }],
7390
output: AllocatorTy::ResultPtr,
7491
},

compiler/rustc_attr_parsing/src/attributes/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ pub(crate) trait CombineAttributeParser<S: Stage>: 'static {
302302
type Item;
303303
/// A function that converts individual items (of type [`Item`](Self::Item)) into the final attribute.
304304
///
305-
/// For example, individual representations fomr `#[repr(...)]` attributes into an `AttributeKind::Repr(x)`,
305+
/// For example, individual representations from `#[repr(...)]` attributes into an `AttributeKind::Repr(x)`,
306306
/// where `x` is a vec of these individual reprs.
307307
const CONVERT: ConvertFn<Self::Item>;
308308

compiler/rustc_codegen_llvm/src/allocator.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
use libc::c_uint;
22
use rustc_ast::expand::allocator::{
3-
AllocatorMethod, AllocatorTy, NO_ALLOC_SHIM_IS_UNSTABLE, default_fn_name, global_fn_name,
3+
AllocatorMethod, AllocatorTy, NO_ALLOC_SHIM_IS_UNSTABLE, SpecialAllocatorMethod,
4+
default_fn_name, global_fn_name,
45
};
56
use rustc_codegen_ssa::traits::BaseTypeCodegenMethods as _;
67
use rustc_middle::bug;
78
use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs};
89
use rustc_middle::ty::TyCtxt;
910
use rustc_session::config::{DebugInfo, OomStrategy};
10-
use rustc_span::sym;
1111
use rustc_symbol_mangling::mangle_internal_symbol;
1212

1313
use crate::attributes::llfn_attrs_from_instance;
@@ -65,12 +65,12 @@ pub(crate) unsafe fn codegen(
6565
let from_name = mangle_internal_symbol(tcx, &global_fn_name(method.name));
6666
let to_name = mangle_internal_symbol(tcx, &default_fn_name(method.name));
6767

68-
let alloc_attr_flag = match method.name {
69-
sym::alloc => CodegenFnAttrFlags::ALLOCATOR,
70-
sym::dealloc => CodegenFnAttrFlags::DEALLOCATOR,
71-
sym::realloc => CodegenFnAttrFlags::REALLOCATOR,
72-
sym::alloc_zeroed => CodegenFnAttrFlags::ALLOCATOR_ZEROED,
73-
_ => CodegenFnAttrFlags::empty(),
68+
let alloc_attr_flag = match method.special {
69+
Some(SpecialAllocatorMethod::Alloc) => CodegenFnAttrFlags::ALLOCATOR,
70+
Some(SpecialAllocatorMethod::Dealloc) => CodegenFnAttrFlags::DEALLOCATOR,
71+
Some(SpecialAllocatorMethod::Realloc) => CodegenFnAttrFlags::REALLOCATOR,
72+
Some(SpecialAllocatorMethod::AllocZeroed) => CodegenFnAttrFlags::ALLOCATOR_ZEROED,
73+
None => CodegenFnAttrFlags::empty(),
7474
};
7575

7676
let mut attrs = CodegenFnAttrs::new();

compiler/rustc_codegen_ssa/src/base.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,7 @@ pub fn allocator_shim_contents(tcx: TyCtxt<'_>, kind: AllocatorKind) -> Vec<Allo
669669
if tcx.alloc_error_handler_kind(()).unwrap() == AllocatorKind::Default {
670670
methods.push(AllocatorMethod {
671671
name: ALLOC_ERROR_HANDLER,
672+
special: None,
672673
inputs: &[],
673674
output: AllocatorTy::Never,
674675
});

compiler/rustc_data_structures/src/graph/scc/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ enum NodeState<N, S, A: Annotation> {
289289
#[derive(Copy, Clone, Debug)]
290290
enum WalkReturn<S, A: Annotation> {
291291
/// The walk found a cycle, but the entire component is not known to have
292-
/// been fully walked yet. We only know the minimum depth of this
292+
/// been fully walked yet. We only know the minimum depth of this
293293
/// component in a minimum spanning tree of the graph. This component
294294
/// is tentatively represented by the state of the first node of this
295295
/// cycle we met, which is at `min_depth`.

compiler/rustc_hir_analysis/src/check/wfcheck.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1651,9 +1651,7 @@ fn check_method_receiver<'tcx>(
16511651

16521652
// If the receiver already has errors reported, consider it valid to avoid
16531653
// unnecessary errors (#58712).
1654-
if receiver_ty.references_error() {
1655-
return Ok(());
1656-
}
1654+
receiver_ty.error_reported()?;
16571655

16581656
let arbitrary_self_types_level = if tcx.features().arbitrary_self_types_pointers() {
16591657
Some(ArbitrarySelfTypesLevel::WithPointers)

compiler/rustc_hir_analysis/src/coherence/mod.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@ fn check_impl<'tcx>(
3939

4040
// Skip impls where one of the self type is an error type.
4141
// This occurs with e.g., resolve failures (#30589).
42-
if trait_ref.references_error() {
43-
return Ok(());
44-
}
42+
trait_ref.error_reported()?;
4543

4644
enforce_trait_manually_implementable(tcx, impl_def_id, trait_ref.def_id, trait_def)
4745
.and(enforce_empty_impls_for_marker_traits(tcx, impl_def_id, trait_ref.def_id, trait_def))
@@ -188,9 +186,9 @@ fn check_object_overlap<'tcx>(
188186
) -> Result<(), ErrorGuaranteed> {
189187
let trait_def_id = trait_ref.def_id;
190188

191-
if trait_ref.references_error() {
189+
if let Err(guar) = trait_ref.error_reported() {
192190
debug!("coherence: skipping impl {:?} with error {:?}", impl_def_id, trait_ref);
193-
return Ok(());
191+
return Err(guar);
194192
}
195193

196194
// check for overlap with the automatic `impl Trait for dyn Trait`

compiler/rustc_hir_analysis/src/impl_wf_check.rs

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -76,20 +76,10 @@ pub(crate) fn enforce_impl_lifetime_params_are_constrained(
7676
impl_def_id: LocalDefId,
7777
) -> Result<(), ErrorGuaranteed> {
7878
let impl_self_ty = tcx.type_of(impl_def_id).instantiate_identity();
79-
if impl_self_ty.references_error() {
80-
// Don't complain about unconstrained type params when self ty isn't known due to errors.
81-
// (#36836)
82-
tcx.dcx().span_delayed_bug(
83-
tcx.def_span(impl_def_id),
84-
format!(
85-
"potentially unconstrained type parameters weren't evaluated: {impl_self_ty:?}",
86-
),
87-
);
88-
// This is super fishy, but our current `rustc_hir_analysis::check_crate` pipeline depends on
89-
// `type_of` having been called much earlier, and thus this value being read from cache.
90-
// Compilation must continue in order for other important diagnostics to keep showing up.
91-
return Ok(());
92-
}
79+
80+
// Don't complain about unconstrained type params when self ty isn't known due to errors.
81+
// (#36836)
82+
impl_self_ty.error_reported()?;
9383

9484
let impl_generics = tcx.generics_of(impl_def_id);
9585
let impl_predicates = tcx.predicates_of(impl_def_id);
@@ -174,20 +164,11 @@ pub(crate) fn enforce_impl_non_lifetime_params_are_constrained(
174164
impl_def_id: LocalDefId,
175165
) -> Result<(), ErrorGuaranteed> {
176166
let impl_self_ty = tcx.type_of(impl_def_id).instantiate_identity();
177-
if impl_self_ty.references_error() {
178-
// Don't complain about unconstrained type params when self ty isn't known due to errors.
179-
// (#36836)
180-
tcx.dcx().span_delayed_bug(
181-
tcx.def_span(impl_def_id),
182-
format!(
183-
"potentially unconstrained type parameters weren't evaluated: {impl_self_ty:?}",
184-
),
185-
);
186-
// This is super fishy, but our current `rustc_hir_analysis::check_crate` pipeline depends on
187-
// `type_of` having been called much earlier, and thus this value being read from cache.
188-
// Compilation must continue in order for other important diagnostics to keep showing up.
189-
return Ok(());
190-
}
167+
168+
// Don't complain about unconstrained type params when self ty isn't known due to errors.
169+
// (#36836)
170+
impl_self_ty.error_reported()?;
171+
191172
let impl_generics = tcx.generics_of(impl_def_id);
192173
let impl_predicates = tcx.predicates_of(impl_def_id);
193174
let impl_trait_ref = tcx.impl_trait_ref(impl_def_id).map(ty::EarlyBinder::instantiate_identity);

compiler/rustc_hir_typeck/src/expr.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -685,9 +685,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
685685
});
686686
let ty =
687687
self.check_expr_with_expectation_and_needs(oprnd, hint, Needs::maybe_mut_place(mutbl));
688+
if let Err(guar) = ty.error_reported() {
689+
return Ty::new_error(self.tcx, guar);
690+
}
688691

689692
match kind {
690-
_ if ty.references_error() => Ty::new_misc_error(self.tcx),
691693
hir::BorrowKind::Raw => {
692694
self.check_named_place_expr(oprnd);
693695
Ty::new_ptr(self.tcx, ty, mutbl)

compiler/rustc_sanitizers/src/cfi/typeid/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ bitflags! {
2121
const GENERALIZE_REPR_C = 2;
2222
/// Normalizes integers for compatibility with Clang
2323
/// `-fsanitize-cfi-icall-experimental-normalize-integers` option for cross-language LLVM
24-
/// CFI and KCFI support.
24+
/// CFI and KCFI support.
2525
const NORMALIZE_INTEGERS = 4;
2626
/// Do not perform self type erasure for attaching a secondary type id to methods with their
2727
/// concrete self so they can be used as function pointers.

0 commit comments

Comments
 (0)