Skip to content

Commit 6c828e5

Browse files
committed
Auto merge of #152006 - JonathanBrouwer:rollup-TXHXPNU, r=JonathanBrouwer
Rollup of 12 pull requests Successful merges: - #149596 (resolve: Report more visibility-related early resolution ambiguities for imports) - #151695 (compiletest: Support `--extern` modifiers with `proc-macro` directive) - #151938 (Use `#![feature(adt_const_params)]` for static query flags) - #151172 (Use default field values in a few more cases) - #151825 (more float constants) - #151870 (regression test for alias-relate changes in lub) - #151872 (Add inline syntax for diagnostic messages) - #151902 (explain why we dont skip some of this work when there are field projections) - #151909 (Skip overlapping spans in argument error suggestions) - #151978 (Query cleanups) - #151979 (Fix uninitialized UEFI globals in tests) - #151992 (Port `#[rustc_hidden_type_of_opaque]` to attribute parser)
2 parents f60a0f1 + 467053f commit 6c828e5

File tree

62 files changed

+3786
-394
lines changed

Some content is hidden

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

62 files changed

+3786
-394
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4229,6 +4229,8 @@ dependencies = [
42294229
name = "rustc_macros"
42304230
version = "0.0.0"
42314231
dependencies = [
4232+
"fluent-bundle",
4233+
"fluent-syntax",
42324234
"proc-macro2",
42334235
"quote",
42344236
"syn 2.0.110",

compiler/rustc_attr_parsing/src/attributes/rustc_internal.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,14 @@ impl<S: Stage> NoArgsAttributeParser<S> for RustcHasIncoherentInherentImplsParse
307307
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcHasIncoherentInherentImpls;
308308
}
309309

310+
pub(crate) struct RustcHiddenTypeOfOpaquesParser;
311+
312+
impl<S: Stage> NoArgsAttributeParser<S> for RustcHiddenTypeOfOpaquesParser {
313+
const PATH: &[Symbol] = &[sym::rustc_hidden_type_of_opaques];
314+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
315+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
316+
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcHiddenTypeOfOpaques;
317+
}
310318
pub(crate) struct RustcNounwindParser;
311319

312320
impl<S: Stage> NoArgsAttributeParser<S> for RustcNounwindParser {

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,14 @@ use crate::attributes::rustc_dump::{
7575
RustcDumpVtable,
7676
};
7777
use crate::attributes::rustc_internal::{
78-
RustcHasIncoherentInherentImplsParser, RustcLayoutParser, RustcLayoutScalarValidRangeEndParser,
79-
RustcLayoutScalarValidRangeStartParser, RustcLegacyConstGenericsParser,
80-
RustcLintOptDenyFieldAccessParser, RustcLintOptTyParser, RustcLintQueryInstabilityParser,
81-
RustcLintUntrackedQueryInformationParser, RustcMainParser, RustcMustImplementOneOfParser,
82-
RustcNeverReturnsNullPointerParser, RustcNoImplicitAutorefsParser,
83-
RustcNonConstTraitMethodParser, RustcNounwindParser, RustcObjectLifetimeDefaultParser,
84-
RustcOffloadKernelParser, RustcScalableVectorParser, RustcSimdMonomorphizeLaneLimitParser,
78+
RustcHasIncoherentInherentImplsParser, RustcHiddenTypeOfOpaquesParser, RustcLayoutParser,
79+
RustcLayoutScalarValidRangeEndParser, RustcLayoutScalarValidRangeStartParser,
80+
RustcLegacyConstGenericsParser, RustcLintOptDenyFieldAccessParser, RustcLintOptTyParser,
81+
RustcLintQueryInstabilityParser, RustcLintUntrackedQueryInformationParser, RustcMainParser,
82+
RustcMustImplementOneOfParser, RustcNeverReturnsNullPointerParser,
83+
RustcNoImplicitAutorefsParser, RustcNonConstTraitMethodParser, RustcNounwindParser,
84+
RustcObjectLifetimeDefaultParser, RustcOffloadKernelParser, RustcScalableVectorParser,
85+
RustcSimdMonomorphizeLaneLimitParser,
8586
};
8687
use crate::attributes::semantics::MayDangleParser;
8788
use crate::attributes::stability::{
@@ -299,6 +300,7 @@ attribute_parsers!(
299300
Single<WithoutArgs<RustcDumpUserArgs>>,
300301
Single<WithoutArgs<RustcDumpVtable>>,
301302
Single<WithoutArgs<RustcHasIncoherentInherentImplsParser>>,
303+
Single<WithoutArgs<RustcHiddenTypeOfOpaquesParser>>,
302304
Single<WithoutArgs<RustcLintOptTyParser>>,
303305
Single<WithoutArgs<RustcLintQueryInstabilityParser>>,
304306
Single<WithoutArgs<RustcLintUntrackedQueryInformationParser>>,

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2309,12 +2309,12 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
23092309
tcx: TyCtxt<'hir>,
23102310
issue_span: Span,
23112311
expr_span: Span,
2312-
body_expr: Option<&'hir hir::Expr<'hir>>,
2313-
loop_bind: Option<&'hir Ident>,
2314-
loop_span: Option<Span>,
2315-
head_span: Option<Span>,
2316-
pat_span: Option<Span>,
2317-
head: Option<&'hir hir::Expr<'hir>>,
2312+
body_expr: Option<&'hir hir::Expr<'hir>> = None,
2313+
loop_bind: Option<&'hir Ident> = None,
2314+
loop_span: Option<Span> = None,
2315+
head_span: Option<Span> = None,
2316+
pat_span: Option<Span> = None,
2317+
head: Option<&'hir hir::Expr<'hir>> = None,
23182318
}
23192319
impl<'hir> Visitor<'hir> for ExprFinder<'hir> {
23202320
fn visit_expr(&mut self, ex: &'hir hir::Expr<'hir>) {
@@ -2380,17 +2380,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
23802380
hir::intravisit::walk_expr(self, ex);
23812381
}
23822382
}
2383-
let mut finder = ExprFinder {
2384-
tcx,
2385-
expr_span: span,
2386-
issue_span,
2387-
loop_bind: None,
2388-
body_expr: None,
2389-
head_span: None,
2390-
loop_span: None,
2391-
pat_span: None,
2392-
head: None,
2393-
};
2383+
let mut finder = ExprFinder { tcx, expr_span: span, issue_span, .. };
23942384
finder.visit_expr(tcx.hir_body(body_id).value);
23952385

23962386
if let Some(body_expr) = finder.body_expr
@@ -2625,13 +2615,13 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
26252615

26262616
struct ExpressionFinder<'tcx> {
26272617
capture_span: Span,
2628-
closure_change_spans: Vec<Span>,
2629-
closure_arg_span: Option<Span>,
2630-
in_closure: bool,
2631-
suggest_arg: String,
2618+
closure_change_spans: Vec<Span> = vec![],
2619+
closure_arg_span: Option<Span> = None,
2620+
in_closure: bool = false,
2621+
suggest_arg: String = String::new(),
26322622
tcx: TyCtxt<'tcx>,
2633-
closure_local_id: Option<hir::HirId>,
2634-
closure_call_changes: Vec<(Span, String)>,
2623+
closure_local_id: Option<hir::HirId> = None,
2624+
closure_call_changes: Vec<(Span, String)> = vec![],
26352625
}
26362626
impl<'hir> Visitor<'hir> for ExpressionFinder<'hir> {
26372627
fn visit_expr(&mut self, e: &'hir hir::Expr<'hir>) {
@@ -2712,16 +2702,8 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
27122702
}) = self.infcx.tcx.hir_node(self.mir_hir_id())
27132703
&& let hir::Node::Expr(expr) = self.infcx.tcx.hir_node(body_id.hir_id)
27142704
{
2715-
let mut finder = ExpressionFinder {
2716-
capture_span: *capture_kind_span,
2717-
closure_change_spans: vec![],
2718-
closure_arg_span: None,
2719-
in_closure: false,
2720-
suggest_arg: String::new(),
2721-
closure_local_id: None,
2722-
closure_call_changes: vec![],
2723-
tcx: self.infcx.tcx,
2724-
};
2705+
let mut finder =
2706+
ExpressionFinder { capture_span: *capture_kind_span, tcx: self.infcx.tcx, .. };
27252707
finder.visit_expr(expr);
27262708

27272709
if finder.closure_change_spans.is_empty() || finder.closure_call_changes.is_empty() {

compiler/rustc_borrowck/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#![allow(internal_features)]
55
#![feature(assert_matches)]
66
#![feature(box_patterns)]
7+
#![feature(default_field_values)]
78
#![feature(file_buffered)]
89
#![feature(if_let_guard)]
910
#![feature(negative_impls)]

compiler/rustc_error_messages/src/lib.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,9 @@ pub enum SubdiagMessage {
247247
/// Identifier of a Fluent message. Instances of this variant are generated by the
248248
/// `Subdiagnostic` derive.
249249
FluentIdentifier(FluentId),
250+
/// An inline Fluent message. Instances of this variant are generated by the
251+
/// `Subdiagnostic` derive.
252+
Inline(Cow<'static, str>),
250253
/// Attribute of a Fluent message. Needs to be combined with a Fluent identifier to produce an
251254
/// actual translated message. Instances of this variant are generated by the `fluent_messages`
252255
/// macro.
@@ -291,6 +294,8 @@ pub enum DiagMessage {
291294
/// <https://projectfluent.org/fluent/guide/hello.html>
292295
/// <https://projectfluent.org/fluent/guide/attributes.html>
293296
FluentIdentifier(FluentId, Option<FluentId>),
297+
/// An inline Fluent message, containing the to be translated diagnostic message.
298+
Inline(Cow<'static, str>),
294299
}
295300

296301
impl DiagMessage {
@@ -305,21 +310,22 @@ impl DiagMessage {
305310
SubdiagMessage::FluentIdentifier(id) => {
306311
return DiagMessage::FluentIdentifier(id, None);
307312
}
313+
SubdiagMessage::Inline(s) => return DiagMessage::Inline(s),
308314
SubdiagMessage::FluentAttr(attr) => attr,
309315
};
310316

311317
match self {
312-
DiagMessage::Str(s) => DiagMessage::Str(s.clone()),
313318
DiagMessage::FluentIdentifier(id, _) => {
314319
DiagMessage::FluentIdentifier(id.clone(), Some(attr))
315320
}
321+
_ => panic!("Tried to add a subdiagnostic to a message without a fluent identifier"),
316322
}
317323
}
318324

319325
pub fn as_str(&self) -> Option<&str> {
320326
match self {
321327
DiagMessage::Str(s) => Some(s),
322-
DiagMessage::FluentIdentifier(_, _) => None,
328+
DiagMessage::FluentIdentifier(_, _) | DiagMessage::Inline(_) => None,
323329
}
324330
}
325331
}
@@ -353,6 +359,7 @@ impl From<DiagMessage> for SubdiagMessage {
353359
// There isn't really a sensible behaviour for this because it loses information but
354360
// this is the most sensible of the behaviours.
355361
DiagMessage::FluentIdentifier(_, Some(attr)) => SubdiagMessage::FluentAttr(attr),
362+
DiagMessage::Inline(s) => SubdiagMessage::Inline(s),
356363
}
357364
}
358365
}

compiler/rustc_errors/src/translation.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ use std::env;
33
use std::error::Report;
44
use std::sync::Arc;
55

6+
use rustc_error_messages::langid;
67
pub use rustc_error_messages::{FluentArgs, LazyFallbackBundle};
78
use tracing::{debug, trace};
89

910
use crate::error::{TranslateError, TranslateErrorKind};
10-
use crate::{DiagArg, DiagMessage, FluentBundle, Style};
11+
use crate::fluent_bundle::FluentResource;
12+
use crate::{DiagArg, DiagMessage, FluentBundle, Style, fluent_bundle};
1113

1214
/// Convert diagnostic arguments (a rustc internal type that exists to implement
1315
/// `Encodable`/`Decodable`) into `FluentArgs` which is necessary to perform translation.
@@ -79,6 +81,28 @@ impl Translator {
7981
return Ok(Cow::Borrowed(msg));
8082
}
8183
DiagMessage::FluentIdentifier(identifier, attr) => (identifier, attr),
84+
// This translates an inline fluent diagnostic message
85+
// It does this by creating a new `FluentBundle` with only one message,
86+
// and then translating using this bundle.
87+
DiagMessage::Inline(msg) => {
88+
const GENERATED_MSG_ID: &str = "generated_msg";
89+
let resource =
90+
FluentResource::try_new(format!("{GENERATED_MSG_ID} = {msg}\n")).unwrap();
91+
let mut bundle = fluent_bundle::FluentBundle::new(vec![langid!("en-US")]);
92+
bundle.set_use_isolating(false);
93+
bundle.add_resource(resource).unwrap();
94+
let message = bundle.get_message(GENERATED_MSG_ID).unwrap();
95+
let value = message.value().unwrap();
96+
97+
let mut errs = vec![];
98+
let translated = bundle.format_pattern(value, Some(args), &mut errs).to_string();
99+
debug!(?translated, ?errs);
100+
return if errs.is_empty() {
101+
Ok(Cow::Owned(translated))
102+
} else {
103+
Err(TranslateError::fluent(&Cow::Borrowed(GENERATED_MSG_ID), args, errs))
104+
};
105+
}
82106
};
83107
let translate_with_bundle =
84108
|bundle: &'a FluentBundle| -> Result<Cow<'_, str>, TranslateError<'_>> {

compiler/rustc_hir/src/attrs/data_structures.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,6 +1057,9 @@ pub enum AttributeKind {
10571057
/// Represents `#[rustc_has_incoherent_inherent_impls]`
10581058
RustcHasIncoherentInherentImpls,
10591059

1060+
/// Represents `#[rustc_hidden_type_of_opaques]`
1061+
RustcHiddenTypeOfOpaques,
1062+
10601063
/// Represents `#[rustc_layout]`
10611064
RustcLayout(ThinVec<RustcLayoutType>),
10621065

compiler/rustc_hir/src/attrs/encode_cross_crate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ impl AttributeKind {
111111
RustcDumpVtable(..) => No,
112112
RustcDynIncompatibleTrait(..) => No,
113113
RustcHasIncoherentInherentImpls => Yes,
114+
RustcHiddenTypeOfOpaques => No,
114115
RustcLayout(..) => No,
115116
RustcLayoutScalarValidRangeEnd(..) => Yes,
116117
RustcLayoutScalarValidRangeStart(..) => Yes,

compiler/rustc_hir_analysis/src/collect/dump.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@ use rustc_middle::ty::{self, TyCtxt, TypeVisitableExt};
77
use rustc_span::sym;
88

99
pub(crate) fn opaque_hidden_types(tcx: TyCtxt<'_>) {
10-
if !tcx.has_attr(CRATE_DEF_ID, sym::rustc_hidden_type_of_opaques) {
10+
if !find_attr!(tcx.get_all_attrs(CRATE_DEF_ID), AttributeKind::RustcHiddenTypeOfOpaques) {
1111
return;
1212
}
13-
1413
for id in tcx.hir_crate_items(()).opaques() {
1514
if let hir::OpaqueTyOrigin::FnReturn { parent: fn_def_id, .. }
1615
| hir::OpaqueTyOrigin::AsyncFn { parent: fn_def_id, .. } =

0 commit comments

Comments
 (0)