Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 9 pull requests #120412

Closed
wants to merge 25 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
853504d
Remove feature not required by `Ipv6Addr::to_cononical` doctest
eopb Jan 5, 2024
f1b508c
fix: correct suggestion arg for impl trait
Young-Flash Jan 14, 2024
c0a5a85
test: add test case for impl trait arg suggestion
Young-Flash Jan 14, 2024
f9259d1
Boost intersperse(_with) performance
nyurik May 9, 2023
b8d245e
Postpone .next() call until iteration
nyurik May 9, 2023
f1dbc7b
fmt
nyurik May 9, 2023
8cbff0b
Update library/core/src/iter/adapters/intersperse.rs
nyurik Jan 26, 2024
77f31ef
use checked_add for upper bound
nyurik Jan 26, 2024
bdf7404
Update codegen test for LLVM 18
nikic Jan 26, 2024
90254cd
ScopeTree: remove destruction_scopes as unused
klensy Jan 26, 2024
304361a
Improve handling of numbers in IntoDiagnosticArg
Urgau Jan 26, 2024
93ff4a4
Fix typo
Urgau Jan 26, 2024
169c728
Remove myself from review rotation
thomcc Jan 26, 2024
a5d9def
Properly recover from trailing attr in body
estebank Nov 22, 2023
3022c76
Avoid ICE in trait without `dyn` lint
estebank Jan 23, 2024
8b3a681
minor: pick a suitable var name
Young-Flash Jan 27, 2024
4eb7ced
Rollup merge of #111379 - nyurik:intersperse-speed-up, r=cuviper
Nadrieril Jan 27, 2024
a542c31
Rollup merge of #118182 - estebank:issue-118164, r=davidtwco
Nadrieril Jan 27, 2024
dfb0be0
Rollup merge of #119641 - eopb:std-unused-ip-feature, r=ChrisDenton
Nadrieril Jan 27, 2024
5803376
Rollup merge of #119957 - Young-Flash:fix, r=fmease
Nadrieril Jan 27, 2024
60a72b6
Rollup merge of #120275 - estebank:issue-120241, r=fmease
Nadrieril Jan 27, 2024
1ef085f
Rollup merge of #120376 - nikic:update-codegen-test, r=cuviper
Nadrieril Jan 27, 2024
23fc765
Rollup merge of #120386 - klensy:destruction_scopes, r=compiler-errors
Nadrieril Jan 27, 2024
b581edf
Rollup merge of #120398 - Urgau:into_diag_arg-numbers, r=compiler-errors
Nadrieril Jan 27, 2024
cb55493
Rollup merge of #120399 - thomcc:thomcc-no-rotation, r=Nilstrieb
Nadrieril Jan 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 22 additions & 25 deletions compiler/rustc_errors/src/diagnostic_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,29 @@ macro_rules! into_diagnostic_arg_using_display {
}
}

macro_rules! into_diagnostic_arg_for_number {
($( $ty:ty ),+ $(,)?) => {
$(
impl IntoDiagnosticArg for $ty {
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
// HACK: `FluentNumber` the underline backing struct represent
// numbers using a f64 which can't represent all the i128 numbers
// So in order to be able to use fluent selectors and still
// have all the numbers representable we only convert numbers
// below a certain threshold.
if let Ok(n) = TryInto::<i128>::try_into(self) && n >= -100 && n <= 100 {
DiagnosticArgValue::Number(n)
} else {
self.to_string().into_diagnostic_arg()
}
}
}
)+
}
}

into_diagnostic_arg_using_display!(
ast::ParamKindOrd,
i8,
u8,
i16,
u16,
u32,
i64,
i128,
u128,
std::io::Error,
Box<dyn std::error::Error>,
std::num::NonZeroU32,
Expand All @@ -82,17 +95,7 @@ into_diagnostic_arg_using_display!(
ExitStatus,
);

impl IntoDiagnosticArg for i32 {
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
DiagnosticArgValue::Number(self.into())
}
}

impl IntoDiagnosticArg for u64 {
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
DiagnosticArgValue::Number(self.into())
}
}
into_diagnostic_arg_for_number!(i8, u8, i16, u16, i32, u32, i64, u64, i128, u128, isize, usize);

impl IntoDiagnosticArg for bool {
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
Expand Down Expand Up @@ -154,12 +157,6 @@ impl IntoDiagnosticArg for PathBuf {
}
}

impl IntoDiagnosticArg for usize {
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
DiagnosticArgValue::Number(self as i128)
}
}

impl IntoDiagnosticArg for PanicStrategy {
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
DiagnosticArgValue::Str(Cow::Owned(self.desc().to_string()))
Expand Down
10 changes: 4 additions & 6 deletions compiler/rustc_hir_analysis/src/astconv/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
],
Applicability::MachineApplicable,
);
} else if diag.is_error() && is_downgradable {
} else if is_downgradable {
// We'll emit the object safety error already, with a structured suggestion.
diag.downgrade_to_delayed_bug();
}
Expand All @@ -158,7 +158,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
}
if !is_object_safe {
diag.note(format!("`{trait_name}` it is not object safe, so it can't be `dyn`"));
if diag.is_error() && is_downgradable {
if is_downgradable {
// We'll emit the object safety error already, with a structured suggestion.
diag.downgrade_to_delayed_bug();
}
Expand Down Expand Up @@ -241,13 +241,11 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
} else {
let msg = "trait objects without an explicit `dyn` are deprecated";
tcx.node_span_lint(BARE_TRAIT_OBJECTS, self_ty.hir_id, self_ty.span, msg, |lint| {
if self_ty.span.can_be_used_for_suggestions()
&& !self.maybe_lint_impl_trait(self_ty, lint)
{
if self_ty.span.can_be_used_for_suggestions() {
lint.multipart_suggestion_verbose(
"use `dyn`",
sugg,
Applicability::MachineApplicable,
Applicability::MaybeIncorrect,
);
}
self.maybe_lint_blanket_trait_impl(self_ty, lint);
Expand Down
28 changes: 19 additions & 9 deletions compiler/rustc_hir_typeck/src/method/suggest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1601,23 +1601,33 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
self.ty_to_value_string(rcvr_ty.peel_refs())
};
if let SelfSource::MethodCall(_) = source {
let first_arg = if let Some(CandidateSource::Impl(impl_did)) = static_candidates.get(0)
&& let Some(assoc) = self.associated_value(*impl_did, item_name)
&& assoc.kind == ty::AssocKind::Fn
{
let first_arg = static_candidates.get(0).and_then(|candidate_source| {
let (assoc_did, self_ty) = match candidate_source {
CandidateSource::Impl(impl_did) => {
(*impl_did, self.tcx.type_of(*impl_did).instantiate_identity())
}
CandidateSource::Trait(trait_did) => (*trait_did, rcvr_ty),
};

let assoc = self.associated_value(assoc_did, item_name)?;
if assoc.kind != ty::AssocKind::Fn {
return None;
}

// for CandidateSource::Impl, `Self` will be instantiated to a concrete type
// but for CandidateSource::Trait, `Self` is still `Self`
let sig = self.tcx.fn_sig(assoc.def_id).instantiate_identity();
sig.inputs().skip_binder().get(0).and_then(|first| {
let impl_ty = self.tcx.type_of(*impl_did).instantiate_identity();
// if the type of first arg is the same as the current impl type, we should take the first arg into assoc function
if first.peel_refs() == impl_ty {
let first_ty = first.peel_refs();
if first_ty == self_ty || first_ty == self.tcx.types.self_param {
Some(first.ref_mutability().map_or("", |mutbl| mutbl.ref_prefix_str()))
} else {
None
}
})
} else {
None
};
});

let mut applicability = Applicability::MachineApplicable;
let args = if let SelfSource::MethodCall(receiver) = source
&& let Some(args) = args
Expand Down
8 changes: 0 additions & 8 deletions compiler/rustc_middle/src/middle/region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,6 @@ pub struct ScopeTree {
/// variable is declared.
var_map: FxIndexMap<hir::ItemLocalId, Scope>,

/// Maps from a `NodeId` to the associated destruction scope (if any).
destruction_scopes: FxIndexMap<hir::ItemLocalId, Scope>,

/// Identifies expressions which, if captured into a temporary, ought to
/// have a temporary whose lifetime extends to the end of the enclosing *block*,
/// and not the enclosing *statement*. Expressions that are not present in this
Expand Down Expand Up @@ -336,11 +333,6 @@ impl ScopeTree {
let prev = self.parent_map.insert(child, p);
assert!(prev.is_none());
}

// Record the destruction scopes for later so we can query them.
if let ScopeData::Destruction = child.data {
self.destruction_scopes.insert(child.item_local_id(), child);
}
}

pub fn record_var_scope(&mut self, var: hir::ItemLocalId, lifetime: Scope) {
Expand Down
19 changes: 17 additions & 2 deletions compiler/rustc_parse/src/parser/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -791,13 +791,28 @@ impl<'a> Parser<'a> {
&& let [segment] = &attr_kind.item.path.segments[..]
&& segment.ident.name == sym::cfg
&& let Some(args_span) = attr_kind.item.args.span()
&& let Ok(next_attr) = snapshot.parse_attribute(InnerAttrPolicy::Forbidden(None))
&& let next_attr = match snapshot.parse_attribute(InnerAttrPolicy::Forbidden(None))
{
Ok(next_attr) => next_attr,
Err(inner_err) => {
err.cancel();
inner_err.cancel();
return;
}
}
&& let ast::AttrKind::Normal(next_attr_kind) = next_attr.kind
&& let Some(next_attr_args_span) = next_attr_kind.item.args.span()
&& let [next_segment] = &next_attr_kind.item.path.segments[..]
&& segment.ident.name == sym::cfg
&& let Ok(next_expr) = snapshot.parse_expr()
{
let next_expr = match snapshot.parse_expr() {
Ok(next_expr) => next_expr,
Err(inner_err) => {
err.cancel();
inner_err.cancel();
return;
}
};
// We have for sure
// #[cfg(..)]
// expr
Expand Down
Loading
Loading