Skip to content

Commit 7ad4e69

Browse files
committed
Auto merge of rust-lang#152517 - jhpratt:rollup-fGRcId6, r=jhpratt
Rollup of 17 pull requests Successful merges: - rust-lang#142415 (Add note when inherent impl for a alias type defined outside of the crate) - rust-lang#142680 (Fix passing/returning structs with the 64-bit SPARC ABI) - rust-lang#150768 (Don't compute FnAbi for LLVM intrinsics in backends) - rust-lang#151152 (Add FCW for derive helper attributes that will conflict with built-in attributes) - rust-lang#151814 (layout: handle rigid aliases without params) - rust-lang#151863 (Borrowck: simplify diagnostics for placeholders) - rust-lang#152159 (Add note for `?Sized` params in int-ptr casts diag) - rust-lang#152434 (Clarify names of `QueryVTable` functions for "executing" a query) - rust-lang#152478 (Remove tm_factory field from CodegenContext) - rust-lang#152498 (Partially revert "resolve: Update `NameBindingData::vis` in place") - rust-lang#152316 (fix: add continue) - rust-lang#152394 (Correctly check if a macro call is actually a macro call in rustdoc highlighter) - rust-lang#152425 (Port #![test_runner] to the attribute parser) - rust-lang#152481 (Use cg_ssa's produce_final_output_artifacts in cg_clif) - rust-lang#152485 (fix issue#152482) - rust-lang#152495 (Clean up some subdiagnostics) - rust-lang#152502 (Implement `BinaryHeap::from_raw_vec`)
2 parents 605f49b + faac3c5 commit 7ad4e69

File tree

77 files changed

+1233
-790
lines changed

Some content is hidden

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

77 files changed

+1233
-790
lines changed

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_ast_passes/src/errors.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use rustc_abi::ExternAbi;
44
use rustc_ast::ParamKindOrd;
55
use rustc_errors::codes::*;
6-
use rustc_errors::{Applicability, Diag, EmissionGuarantee, Subdiagnostic, inline_fluent};
6+
use rustc_errors::{Applicability, Diag, EmissionGuarantee, Subdiagnostic};
77
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
88
use rustc_span::{Ident, Span, Symbol};
99

@@ -927,19 +927,15 @@ pub(crate) struct FeatureOnNonNightly {
927927
pub sugg: Option<Span>,
928928
}
929929

930+
#[derive(Subdiagnostic)]
931+
#[help(
932+
"the feature `{$name}` has been stable since `{$since}` and no longer requires an attribute to enable"
933+
)]
930934
pub(crate) struct StableFeature {
931935
pub name: Symbol,
932936
pub since: Symbol,
933937
}
934938

935-
impl Subdiagnostic for StableFeature {
936-
fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
937-
diag.arg("name", self.name);
938-
diag.arg("since", self.since);
939-
diag.help(inline_fluent!("the feature `{$name}` has been stable since `{$since}` and no longer requires an attribute to enable"));
940-
}
941-
}
942-
943939
#[derive(Diagnostic)]
944940
#[diag("`{$f1}` and `{$f2}` are incompatible, using them at the same time is not allowed")]
945941
#[help("remove one of these features")]

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_attr_parsing/src/attributes/test_attrs.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,3 +228,32 @@ impl<S: Stage> NoArgsAttributeParser<S> for RustcOutlivesParser {
228228
]);
229229
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcOutlives;
230230
}
231+
232+
pub(crate) struct TestRunnerParser;
233+
234+
impl<S: Stage> SingleAttributeParser<S> for TestRunnerParser {
235+
const PATH: &[Symbol] = &[sym::test_runner];
236+
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepOutermost;
237+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
238+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
239+
const TEMPLATE: AttributeTemplate = template!(List: &["path"]);
240+
241+
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser) -> Option<AttributeKind> {
242+
let Some(list) = args.list() else {
243+
cx.expected_list(cx.attr_span, args);
244+
return None;
245+
};
246+
247+
let Some(single) = list.single() else {
248+
cx.expected_single_argument(list.span);
249+
return None;
250+
};
251+
252+
let Some(meta) = single.meta_item() else {
253+
cx.unexpected_literal(single.span());
254+
return None;
255+
};
256+
257+
Some(AttributeKind::TestRunner(meta.path().0.clone()))
258+
}
259+
}

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ attribute_parsers!(
218218
Single<SanitizeParser>,
219219
Single<ShouldPanicParser>,
220220
Single<SkipDuringMethodDispatchParser>,
221+
Single<TestRunnerParser>,
221222
Single<TransparencyParser>,
222223
Single<TypeLengthLimitParser>,
223224
Single<WindowsSubsystemParser>,

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: 44 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
///
@@ -872,6 +885,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
872885
for alias_ty in alias_tys {
873886
if alias_ty.span.desugaring_kind().is_some() {
874887
// Skip `async` desugaring `impl Future`.
888+
continue;
875889
}
876890
if let TyKind::TraitObject(_, lt) = alias_ty.kind {
877891
if lt.kind == hir::LifetimeKind::ImplicitObjectLifetimeDefault {

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_builtin_macros/src/errors.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,20 +1002,6 @@ pub(crate) struct AsmUnsupportedClobberAbi {
10021002
pub(crate) macro_name: &'static str,
10031003
}
10041004

1005-
#[derive(Diagnostic)]
1006-
#[diag("`test_runner` argument must be a path")]
1007-
pub(crate) struct TestRunnerInvalid {
1008-
#[primary_span]
1009-
pub(crate) span: Span,
1010-
}
1011-
1012-
#[derive(Diagnostic)]
1013-
#[diag("`#![test_runner(..)]` accepts exactly 1 argument")]
1014-
pub(crate) struct TestRunnerNargs {
1015-
#[primary_span]
1016-
pub(crate) span: Span,
1017-
}
1018-
10191005
#[derive(Diagnostic)]
10201006
#[diag("expected token: `,`")]
10211007
pub(crate) struct ExpectedCommaInList {

compiler/rustc_builtin_macros/src/test_harness.rs

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ use rustc_ast::entry::EntryPointType;
88
use rustc_ast::mut_visit::*;
99
use rustc_ast::visit::Visitor;
1010
use rustc_ast::{ModKind, attr};
11-
use rustc_errors::DiagCtxtHandle;
11+
use rustc_attr_parsing::AttributeParser;
1212
use rustc_expand::base::{ExtCtxt, ResolverExpand};
1313
use rustc_expand::expand::{AstFragment, ExpansionConfig};
1414
use rustc_feature::Features;
15+
use rustc_hir::attrs::AttributeKind;
1516
use rustc_session::Session;
1617
use rustc_session::lint::builtin::UNNAMEABLE_TEST_ITEMS;
1718
use rustc_span::hygiene::{AstPass, SyntaxContext, Transparency};
@@ -60,7 +61,7 @@ pub fn inject(
6061

6162
// Do this here so that the test_runner crate attribute gets marked as used
6263
// even in non-test builds
63-
let test_runner = get_test_runner(dcx, krate);
64+
let test_runner = get_test_runner(sess, features, krate);
6465

6566
if sess.is_test_crate() {
6667
let panic_strategy = match (panic_strategy, sess.opts.unstable_opts.panic_abort_tests) {
@@ -386,20 +387,16 @@ fn get_test_name(i: &ast::Item) -> Option<Symbol> {
386387
attr::first_attr_value_str_by_name(&i.attrs, sym::rustc_test_marker)
387388
}
388389

389-
fn get_test_runner(dcx: DiagCtxtHandle<'_>, krate: &ast::Crate) -> Option<ast::Path> {
390-
let test_attr = attr::find_by_name(&krate.attrs, sym::test_runner)?;
391-
let meta_list = test_attr.meta_item_list()?;
392-
let span = test_attr.span;
393-
match &*meta_list {
394-
[single] => match single.meta_item() {
395-
Some(meta_item) if meta_item.is_word() => return Some(meta_item.path.clone()),
396-
_ => {
397-
dcx.emit_err(errors::TestRunnerInvalid { span });
398-
}
399-
},
400-
_ => {
401-
dcx.emit_err(errors::TestRunnerNargs { span });
402-
}
390+
fn get_test_runner(sess: &Session, features: &Features, krate: &ast::Crate) -> Option<ast::Path> {
391+
match AttributeParser::parse_limited(
392+
sess,
393+
&krate.attrs,
394+
sym::test_runner,
395+
krate.spans.inner_span,
396+
krate.id,
397+
Some(features),
398+
) {
399+
Some(rustc_hir::Attribute::Parsed(AttributeKind::TestRunner(path))) => Some(path),
400+
_ => None,
403401
}
404-
None
405402
}

0 commit comments

Comments
 (0)