Skip to content

Commit 73908eb

Browse files
committed
Auto merge of rust-lang#120412 - Nadrieril:rollup-bpgftwj, r=Nadrieril
Rollup of 9 pull requests Successful merges: - rust-lang#111379 (Boost iterator intersperse(_with) performance) - rust-lang#118182 (Properly recover from trailing attr in body) - rust-lang#119641 (Remove feature not required by `Ipv6Addr::to_cononical` doctest) - rust-lang#119957 (fix: correct suggestion arg for impl trait) - rust-lang#120275 (Avoid ICE in trait without `dyn` lint) - rust-lang#120376 (Update codegen test for LLVM 18) - rust-lang#120386 (ScopeTree: remove destruction_scopes as unused) - rust-lang#120398 (Improve handling of numbers in `IntoDiagnosticArg`) - rust-lang#120399 (Remove myself from review rotation) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 04521fd + cb55493 commit 73908eb

29 files changed

+535
-224
lines changed

compiler/rustc_errors/src/diagnostic_impls.rs

+22-25
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,29 @@ macro_rules! into_diagnostic_arg_using_display {
5858
}
5959
}
6060

61+
macro_rules! into_diagnostic_arg_for_number {
62+
($( $ty:ty ),+ $(,)?) => {
63+
$(
64+
impl IntoDiagnosticArg for $ty {
65+
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
66+
// HACK: `FluentNumber` the underline backing struct represent
67+
// numbers using a f64 which can't represent all the i128 numbers
68+
// So in order to be able to use fluent selectors and still
69+
// have all the numbers representable we only convert numbers
70+
// below a certain threshold.
71+
if let Ok(n) = TryInto::<i128>::try_into(self) && n >= -100 && n <= 100 {
72+
DiagnosticArgValue::Number(n)
73+
} else {
74+
self.to_string().into_diagnostic_arg()
75+
}
76+
}
77+
}
78+
)+
79+
}
80+
}
81+
6182
into_diagnostic_arg_using_display!(
6283
ast::ParamKindOrd,
63-
i8,
64-
u8,
65-
i16,
66-
u16,
67-
u32,
68-
i64,
69-
i128,
70-
u128,
7184
std::io::Error,
7285
Box<dyn std::error::Error>,
7386
std::num::NonZeroU32,
@@ -82,17 +95,7 @@ into_diagnostic_arg_using_display!(
8295
ExitStatus,
8396
);
8497

85-
impl IntoDiagnosticArg for i32 {
86-
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
87-
DiagnosticArgValue::Number(self.into())
88-
}
89-
}
90-
91-
impl IntoDiagnosticArg for u64 {
92-
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
93-
DiagnosticArgValue::Number(self.into())
94-
}
95-
}
98+
into_diagnostic_arg_for_number!(i8, u8, i16, u16, i32, u32, i64, u64, i128, u128, isize, usize);
9699

97100
impl IntoDiagnosticArg for bool {
98101
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
@@ -154,12 +157,6 @@ impl IntoDiagnosticArg for PathBuf {
154157
}
155158
}
156159

157-
impl IntoDiagnosticArg for usize {
158-
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
159-
DiagnosticArgValue::Number(self as i128)
160-
}
161-
}
162-
163160
impl IntoDiagnosticArg for PanicStrategy {
164161
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
165162
DiagnosticArgValue::Str(Cow::Owned(self.desc().to_string()))

compiler/rustc_hir_analysis/src/astconv/lint.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
132132
],
133133
Applicability::MachineApplicable,
134134
);
135-
} else if diag.is_error() && is_downgradable {
135+
} else if is_downgradable {
136136
// We'll emit the object safety error already, with a structured suggestion.
137137
diag.downgrade_to_delayed_bug();
138138
}
@@ -158,7 +158,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
158158
}
159159
if !is_object_safe {
160160
diag.note(format!("`{trait_name}` it is not object safe, so it can't be `dyn`"));
161-
if diag.is_error() && is_downgradable {
161+
if is_downgradable {
162162
// We'll emit the object safety error already, with a structured suggestion.
163163
diag.downgrade_to_delayed_bug();
164164
}
@@ -241,13 +241,11 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
241241
} else {
242242
let msg = "trait objects without an explicit `dyn` are deprecated";
243243
tcx.node_span_lint(BARE_TRAIT_OBJECTS, self_ty.hir_id, self_ty.span, msg, |lint| {
244-
if self_ty.span.can_be_used_for_suggestions()
245-
&& !self.maybe_lint_impl_trait(self_ty, lint)
246-
{
244+
if self_ty.span.can_be_used_for_suggestions() {
247245
lint.multipart_suggestion_verbose(
248246
"use `dyn`",
249247
sugg,
250-
Applicability::MachineApplicable,
248+
Applicability::MaybeIncorrect,
251249
);
252250
}
253251
self.maybe_lint_blanket_trait_impl(self_ty, lint);

compiler/rustc_hir_typeck/src/method/suggest.rs

+19-9
Original file line numberDiff line numberDiff line change
@@ -1601,23 +1601,33 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
16011601
self.ty_to_value_string(rcvr_ty.peel_refs())
16021602
};
16031603
if let SelfSource::MethodCall(_) = source {
1604-
let first_arg = if let Some(CandidateSource::Impl(impl_did)) = static_candidates.get(0)
1605-
&& let Some(assoc) = self.associated_value(*impl_did, item_name)
1606-
&& assoc.kind == ty::AssocKind::Fn
1607-
{
1604+
let first_arg = static_candidates.get(0).and_then(|candidate_source| {
1605+
let (assoc_did, self_ty) = match candidate_source {
1606+
CandidateSource::Impl(impl_did) => {
1607+
(*impl_did, self.tcx.type_of(*impl_did).instantiate_identity())
1608+
}
1609+
CandidateSource::Trait(trait_did) => (*trait_did, rcvr_ty),
1610+
};
1611+
1612+
let assoc = self.associated_value(assoc_did, item_name)?;
1613+
if assoc.kind != ty::AssocKind::Fn {
1614+
return None;
1615+
}
1616+
1617+
// for CandidateSource::Impl, `Self` will be instantiated to a concrete type
1618+
// but for CandidateSource::Trait, `Self` is still `Self`
16081619
let sig = self.tcx.fn_sig(assoc.def_id).instantiate_identity();
16091620
sig.inputs().skip_binder().get(0).and_then(|first| {
1610-
let impl_ty = self.tcx.type_of(*impl_did).instantiate_identity();
16111621
// if the type of first arg is the same as the current impl type, we should take the first arg into assoc function
1612-
if first.peel_refs() == impl_ty {
1622+
let first_ty = first.peel_refs();
1623+
if first_ty == self_ty || first_ty == self.tcx.types.self_param {
16131624
Some(first.ref_mutability().map_or("", |mutbl| mutbl.ref_prefix_str()))
16141625
} else {
16151626
None
16161627
}
16171628
})
1618-
} else {
1619-
None
1620-
};
1629+
});
1630+
16211631
let mut applicability = Applicability::MachineApplicable;
16221632
let args = if let SelfSource::MethodCall(receiver) = source
16231633
&& let Some(args) = args

compiler/rustc_middle/src/middle/region.rs

-8
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,6 @@ pub struct ScopeTree {
221221
/// variable is declared.
222222
var_map: FxIndexMap<hir::ItemLocalId, Scope>,
223223

224-
/// Maps from a `NodeId` to the associated destruction scope (if any).
225-
destruction_scopes: FxIndexMap<hir::ItemLocalId, Scope>,
226-
227224
/// Identifies expressions which, if captured into a temporary, ought to
228225
/// have a temporary whose lifetime extends to the end of the enclosing *block*,
229226
/// and not the enclosing *statement*. Expressions that are not present in this
@@ -336,11 +333,6 @@ impl ScopeTree {
336333
let prev = self.parent_map.insert(child, p);
337334
assert!(prev.is_none());
338335
}
339-
340-
// Record the destruction scopes for later so we can query them.
341-
if let ScopeData::Destruction = child.data {
342-
self.destruction_scopes.insert(child.item_local_id(), child);
343-
}
344336
}
345337

346338
pub fn record_var_scope(&mut self, var: hir::ItemLocalId, lifetime: Scope) {

compiler/rustc_parse/src/parser/diagnostics.rs

+17-2
Original file line numberDiff line numberDiff line change
@@ -791,13 +791,28 @@ impl<'a> Parser<'a> {
791791
&& let [segment] = &attr_kind.item.path.segments[..]
792792
&& segment.ident.name == sym::cfg
793793
&& let Some(args_span) = attr_kind.item.args.span()
794-
&& let Ok(next_attr) = snapshot.parse_attribute(InnerAttrPolicy::Forbidden(None))
794+
&& let next_attr = match snapshot.parse_attribute(InnerAttrPolicy::Forbidden(None))
795+
{
796+
Ok(next_attr) => next_attr,
797+
Err(inner_err) => {
798+
err.cancel();
799+
inner_err.cancel();
800+
return;
801+
}
802+
}
795803
&& let ast::AttrKind::Normal(next_attr_kind) = next_attr.kind
796804
&& let Some(next_attr_args_span) = next_attr_kind.item.args.span()
797805
&& let [next_segment] = &next_attr_kind.item.path.segments[..]
798806
&& segment.ident.name == sym::cfg
799-
&& let Ok(next_expr) = snapshot.parse_expr()
800807
{
808+
let next_expr = match snapshot.parse_expr() {
809+
Ok(next_expr) => next_expr,
810+
Err(inner_err) => {
811+
err.cancel();
812+
inner_err.cancel();
813+
return;
814+
}
815+
};
801816
// We have for sure
802817
// #[cfg(..)]
803818
// expr

0 commit comments

Comments
 (0)