Skip to content

Commit e2f2b54

Browse files
committed
Auto merge of #152479 - Zalathar:rollup-L2cuUCq, r=<try>
[EXPERIMENT] Rollup of 8 pull requests try-job: x86_64-msvc-1 try-job: i686-msvc-1 try-job: x86_64-mingw-1 try-job: test-various try-job: armhf-gnu try-job: aarch64-apple
2 parents d34f1f9 + 22d2b56 commit e2f2b54

35 files changed

Lines changed: 777 additions & 296 deletions

File tree

compiler/rustc_abi/src/callconv/reg.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ impl Reg {
3535

3636
reg_ctor!(f32, Float, 32);
3737
reg_ctor!(f64, Float, 64);
38+
reg_ctor!(f128, Float, 128);
3839
}
3940

4041
impl Reg {

compiler/rustc_attr_parsing/src/attributes/proc_macro_attrs.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
use rustc_hir::lints::AttributeLintKind;
2+
use rustc_session::lint::builtin::AMBIGUOUS_DERIVE_HELPERS;
3+
14
use super::prelude::*;
25

36
const PROC_MACRO_ALLOWED_TARGETS: AllowedTargets =
@@ -126,6 +129,13 @@ fn parse_derive_like<S: Stage>(
126129
cx.expected_identifier(ident.span);
127130
return None;
128131
}
132+
if rustc_feature::is_builtin_attr_name(ident.name) {
133+
cx.emit_lint(
134+
AMBIGUOUS_DERIVE_HELPERS,
135+
AttributeLintKind::AmbiguousDeriveHelpers,
136+
ident.span,
137+
);
138+
}
129139
attributes.push(ident.name);
130140
}
131141
}

compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ use rustc_traits::{type_op_ascribe_user_type_with_span, type_op_prove_predicate_
2424
use tracing::{debug, instrument};
2525

2626
use crate::MirBorrowckCtxt;
27-
use crate::region_infer::values::RegionElement;
2827
use crate::session_diagnostics::{
2928
HigherRankedErrorCause, HigherRankedLifetimeError, HigherRankedSubtypeError,
3029
};
@@ -49,11 +48,12 @@ impl<'tcx> UniverseInfo<'tcx> {
4948
UniverseInfo::RelateTys { expected, found }
5049
}
5150

51+
/// Report an error where an element erroneously made its way into `placeholder`.
5252
pub(crate) fn report_erroneous_element(
5353
&self,
5454
mbcx: &mut MirBorrowckCtxt<'_, '_, 'tcx>,
5555
placeholder: ty::PlaceholderRegion<'tcx>,
56-
error_element: RegionElement<'tcx>,
56+
error_element: Option<ty::PlaceholderRegion<'tcx>>,
5757
cause: ObligationCause<'tcx>,
5858
) {
5959
match *self {
@@ -146,14 +146,14 @@ pub(crate) trait TypeOpInfo<'tcx> {
146146
) -> Option<Diag<'infcx>>;
147147

148148
/// Constraints require that `error_element` appear in the
149-
/// values of `placeholder`, but this cannot be proven to
149+
/// values of `placeholder`, but this cannot be proven to
150150
/// hold. Report an error.
151151
#[instrument(level = "debug", skip(self, mbcx))]
152152
fn report_erroneous_element(
153153
&self,
154154
mbcx: &mut MirBorrowckCtxt<'_, '_, 'tcx>,
155155
placeholder: ty::PlaceholderRegion<'tcx>,
156-
error_element: RegionElement<'tcx>,
156+
error_element: Option<ty::PlaceholderRegion<'tcx>>,
157157
cause: ObligationCause<'tcx>,
158158
) {
159159
let tcx = mbcx.infcx.tcx;
@@ -172,19 +172,17 @@ pub(crate) trait TypeOpInfo<'tcx> {
172172
ty::PlaceholderRegion::new(adjusted_universe.into(), placeholder.bound),
173173
);
174174

175-
let error_region =
176-
if let RegionElement::PlaceholderRegion(error_placeholder) = error_element {
177-
let adjusted_universe =
178-
error_placeholder.universe.as_u32().checked_sub(base_universe.as_u32());
179-
adjusted_universe.map(|adjusted| {
180-
ty::Region::new_placeholder(
181-
tcx,
182-
ty::PlaceholderRegion::new(adjusted.into(), error_placeholder.bound),
183-
)
184-
})
185-
} else {
186-
None
187-
};
175+
// FIXME: one day this should just be error_element,
176+
// and this method shouldn't do anything.
177+
let error_region = error_element.and_then(|e| {
178+
let adjusted_universe = e.universe.as_u32().checked_sub(base_universe.as_u32());
179+
adjusted_universe.map(|adjusted| {
180+
ty::Region::new_placeholder(
181+
tcx,
182+
ty::PlaceholderRegion::new(adjusted.into(), e.bound),
183+
)
184+
})
185+
});
188186

189187
debug!(?placeholder_region);
190188

compiler/rustc_borrowck/src/diagnostics/region_errors.rs

Lines changed: 43 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ use tracing::{debug, instrument, trace};
2929

3030
use super::{LIMITATION_NOTE, OutlivesSuggestionBuilder, RegionName, RegionNameSource};
3131
use crate::nll::ConstraintDescription;
32-
use crate::region_infer::values::RegionElement;
3332
use crate::region_infer::{BlameConstraint, TypeTest};
3433
use crate::session_diagnostics::{
3534
FnMutError, FnMutReturnTypeErr, GenericDoesNotLiveLongEnough, LifetimeOutliveErr,
@@ -104,15 +103,9 @@ pub(crate) enum RegionErrorKind<'tcx> {
104103
/// A generic bound failure for a type test (`T: 'a`).
105104
TypeTestError { type_test: TypeTest<'tcx> },
106105

107-
/// Higher-ranked subtyping error.
108-
BoundUniversalRegionError {
109-
/// The placeholder free region.
110-
longer_fr: RegionVid,
111-
/// The region element that erroneously must be outlived by `longer_fr`.
112-
error_element: RegionElement<'tcx>,
113-
/// The placeholder region.
114-
placeholder: ty::PlaceholderRegion<'tcx>,
115-
},
106+
/// 'p outlives 'r, which does not hold. 'p is always a placeholder
107+
/// and 'r is some other region.
108+
PlaceholderOutlivesIllegalRegion { longer_fr: RegionVid, illegally_outlived_r: RegionVid },
116109

117110
/// Any other lifetime error.
118111
RegionError {
@@ -360,28 +353,11 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
360353
}
361354
}
362355

363-
RegionErrorKind::BoundUniversalRegionError {
356+
RegionErrorKind::PlaceholderOutlivesIllegalRegion {
364357
longer_fr,
365-
placeholder,
366-
error_element,
358+
illegally_outlived_r,
367359
} => {
368-
let error_vid = self.regioncx.region_from_element(longer_fr, &error_element);
369-
370-
// Find the code to blame for the fact that `longer_fr` outlives `error_fr`.
371-
let cause = self
372-
.regioncx
373-
.best_blame_constraint(
374-
longer_fr,
375-
NllRegionVariableOrigin::Placeholder(placeholder),
376-
error_vid,
377-
)
378-
.0
379-
.cause;
380-
381-
let universe = placeholder.universe;
382-
let universe_info = self.regioncx.universe_info(universe);
383-
384-
universe_info.report_erroneous_element(self, placeholder, error_element, cause);
360+
self.report_erroneous_rvid_reaches_placeholder(longer_fr, illegally_outlived_r)
385361
}
386362

387363
RegionErrorKind::RegionError { fr_origin, longer_fr, shorter_fr, is_reported } => {
@@ -412,6 +388,43 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
412388
outlives_suggestion.add_suggestion(self);
413389
}
414390

391+
/// Report that `longer_fr: error_vid`, which doesn't hold,
392+
/// where `longer_fr` is a placeholder.
393+
fn report_erroneous_rvid_reaches_placeholder(
394+
&mut self,
395+
longer_fr: RegionVid,
396+
error_vid: RegionVid,
397+
) {
398+
use NllRegionVariableOrigin::*;
399+
400+
let origin_longer = self.regioncx.definitions[longer_fr].origin;
401+
402+
let Placeholder(placeholder) = origin_longer else {
403+
bug!("Expected {longer_fr:?} to come from placeholder!");
404+
};
405+
406+
// FIXME: Is throwing away the existential region really the best here?
407+
let error_region = match self.regioncx.definitions[error_vid].origin {
408+
FreeRegion | Existential { .. } => None,
409+
Placeholder(other_placeholder) => Some(other_placeholder),
410+
};
411+
412+
// Find the code to blame for the fact that `longer_fr` outlives `error_fr`.
413+
let cause =
414+
self.regioncx.best_blame_constraint(longer_fr, origin_longer, error_vid).0.cause;
415+
416+
// FIXME these methods should have better names, and also probably not be this generic.
417+
// FIXME note that we *throw away* the error element here! We probably want to
418+
// thread it through the computation further down and use it, but there currently isn't
419+
// anything there to receive it.
420+
self.regioncx.universe_info(placeholder.universe).report_erroneous_element(
421+
self,
422+
placeholder,
423+
error_region,
424+
cause,
425+
);
426+
}
427+
415428
/// Report an error because the universal region `fr` was required to outlive
416429
/// `outlived_fr` but it is not known to do so. For example:
417430
///

compiler/rustc_borrowck/src/region_infer/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1379,11 +1379,11 @@ impl<'tcx> RegionInferenceContext<'tcx> {
13791379
.elements_contained_in(longer_fr_scc)
13801380
.find(|e| *e != RegionElement::PlaceholderRegion(placeholder))
13811381
{
1382+
let illegally_outlived_r = self.region_from_element(longer_fr, &error_element);
13821383
// Stop after the first error, it gets too noisy otherwise, and does not provide more information.
1383-
errors_buffer.push(RegionErrorKind::BoundUniversalRegionError {
1384+
errors_buffer.push(RegionErrorKind::PlaceholderOutlivesIllegalRegion {
13841385
longer_fr,
1385-
error_element,
1386-
placeholder,
1386+
illegally_outlived_r,
13871387
});
13881388
} else {
13891389
debug!("check_bound_universal_region: all bounds satisfied");
@@ -1572,7 +1572,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
15721572
}
15731573

15741574
/// Get the region outlived by `longer_fr` and live at `element`.
1575-
pub(crate) fn region_from_element(
1575+
fn region_from_element(
15761576
&self,
15771577
longer_fr: RegionVid,
15781578
element: &RegionElement<'tcx>,

compiler/rustc_codegen_gcc/src/intrinsic/mod.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,18 @@ use rustc_codegen_ssa::traits::{
2222
ArgAbiBuilderMethods, BaseTypeCodegenMethods, BuilderMethods, ConstCodegenMethods,
2323
IntrinsicCallBuilderMethods, LayoutTypeCodegenMethods,
2424
};
25+
use rustc_data_structures::fx::FxHashSet;
2526
use rustc_middle::bug;
26-
use rustc_middle::ty::layout::{FnAbiOf, LayoutOf};
27+
#[cfg(feature = "master")]
28+
use rustc_middle::ty::layout::FnAbiOf;
29+
use rustc_middle::ty::layout::LayoutOf;
2730
use rustc_middle::ty::{self, Instance, Ty};
2831
use rustc_span::{Span, Symbol, sym};
2932
use rustc_target::callconv::{ArgAbi, PassMode};
3033

31-
use crate::abi::{FnAbiGccExt, GccType};
34+
#[cfg(feature = "master")]
35+
use crate::abi::FnAbiGccExt;
36+
use crate::abi::GccType;
3237
use crate::builder::Builder;
3338
use crate::common::{SignType, TypeReflection};
3439
use crate::context::CodegenCx;
@@ -617,8 +622,6 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tc
617622
*func
618623
} else {
619624
self.linkage.set(FunctionType::Extern);
620-
let fn_abi = self.fn_abi_of_instance(instance, ty::List::empty());
621-
let fn_ty = fn_abi.gcc_type(self);
622625

623626
let func = match sym {
624627
"llvm.fma.f16" => {
@@ -631,13 +634,7 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tc
631634

632635
self.intrinsics.borrow_mut().insert(sym.to_string(), func);
633636

634-
self.on_stack_function_params
635-
.borrow_mut()
636-
.insert(func, fn_ty.on_stack_param_indices);
637-
#[cfg(feature = "master")]
638-
for fn_attr in fn_ty.fn_attributes {
639-
func.add_attribute(fn_attr);
640-
}
637+
self.on_stack_function_params.borrow_mut().insert(func, FxHashSet::default());
641638

642639
crate::attributes::from_fn_attrs(self, func, instance);
643640

compiler/rustc_codegen_llvm/src/intrinsic.rs

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -646,10 +646,32 @@ impl<'ll, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
646646
) -> Self::Value {
647647
let tcx = self.tcx();
648648

649-
// FIXME remove usage of fn_abi
650-
let fn_abi = self.fn_abi_of_instance(instance, ty::List::empty());
651-
assert!(!fn_abi.ret.is_indirect());
652-
let fn_ty = fn_abi.llvm_type(self);
649+
let fn_ty = instance.ty(tcx, self.typing_env());
650+
let fn_sig = match *fn_ty.kind() {
651+
ty::FnDef(def_id, args) => {
652+
tcx.instantiate_bound_regions_with_erased(tcx.fn_sig(def_id).instantiate(tcx, args))
653+
}
654+
_ => unreachable!(),
655+
};
656+
assert!(!fn_sig.c_variadic);
657+
658+
let ret_layout = self.layout_of(fn_sig.output());
659+
let llreturn_ty = if ret_layout.is_zst() {
660+
self.type_void()
661+
} else {
662+
ret_layout.immediate_llvm_type(self)
663+
};
664+
665+
let mut llargument_tys = Vec::with_capacity(fn_sig.inputs().len());
666+
for &arg in fn_sig.inputs() {
667+
let arg_layout = self.layout_of(arg);
668+
if arg_layout.is_zst() {
669+
continue;
670+
}
671+
llargument_tys.push(arg_layout.immediate_llvm_type(self));
672+
}
673+
674+
let fn_ty = self.type_func(&llargument_tys, llreturn_ty);
653675

654676
let fn_ptr = if let Some(&llfn) = self.intrinsic_instances.borrow().get(&instance) {
655677
llfn
@@ -665,12 +687,11 @@ impl<'ll, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
665687
let llfn = declare_raw_fn(
666688
self,
667689
sym,
668-
fn_abi.llvm_cconv(self),
690+
llvm::CCallConv,
669691
llvm::UnnamedAddr::Global,
670692
llvm::Visibility::Default,
671693
fn_ty,
672694
);
673-
fn_abi.apply_attrs_llfn(self, llfn, Some(instance));
674695

675696
llfn
676697
};

compiler/rustc_hir_analysis/src/coherence/inherent_impls.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,22 @@ impl<'tcx> InherentCollect<'tcx> {
110110
Ok(())
111111
} else {
112112
let impl_span = self.tcx.def_span(impl_def_id);
113-
Err(self.tcx.dcx().emit_err(errors::InherentTyOutsideNew { span: impl_span }))
113+
let mut err = errors::InherentTyOutsideNew { span: impl_span, note: None };
114+
115+
if let hir::TyKind::Path(rustc_hir::QPath::Resolved(_, path)) =
116+
self.tcx.hir_node_by_def_id(impl_def_id).expect_item().expect_impl().self_ty.kind
117+
&& let rustc_hir::def::Res::Def(DefKind::TyAlias, def_id) = path.res
118+
{
119+
let ty_name = self.tcx.def_path_str(def_id);
120+
let alias_ty_name = self.tcx.type_of(def_id).skip_binder().to_string();
121+
err.note = Some(errors::InherentTyOutsideNewAliasNote {
122+
span: self.tcx.def_span(def_id),
123+
ty_name,
124+
alias_ty_name,
125+
});
126+
}
127+
128+
Err(self.tcx.dcx().emit_err(err))
114129
}
115130
}
116131

compiler/rustc_hir_analysis/src/errors.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1223,11 +1223,27 @@ pub(crate) struct InherentTyOutsideRelevant {
12231223

12241224
#[derive(Diagnostic)]
12251225
#[diag("cannot define inherent `impl` for a type outside of the crate where the type is defined", code = E0116)]
1226-
#[note("define and implement a trait or new type instead")]
1226+
#[help(
1227+
"consider defining a trait and implementing it for the type or using a newtype wrapper like `struct MyType(ExternalType);` and implement it"
1228+
)]
1229+
#[note(
1230+
"for more details about the orphan rules, see <https://doc.rust-lang.org/reference/items/implementations.html?highlight=orphan#orphan-rules>"
1231+
)]
12271232
pub(crate) struct InherentTyOutsideNew {
12281233
#[primary_span]
12291234
#[label("impl for type defined outside of crate")]
12301235
pub span: Span,
1236+
#[subdiagnostic]
1237+
pub note: Option<InherentTyOutsideNewAliasNote>,
1238+
}
1239+
1240+
#[derive(Subdiagnostic)]
1241+
#[note("`{$ty_name}` does not define a new type, only an alias of `{$alias_ty_name}` defined here")]
1242+
pub(crate) struct InherentTyOutsideNewAliasNote {
1243+
#[primary_span]
1244+
pub span: Span,
1245+
pub ty_name: String,
1246+
pub alias_ty_name: String,
12311247
}
12321248

12331249
#[derive(Diagnostic)]

0 commit comments

Comments
 (0)