Skip to content

Commit b833ad5

Browse files
committedNov 18, 2022
Auto merge of #104573 - matthiaskrgr:rollup-k36ybtp, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - #101162 (Migrate rustc_resolve to use SessionDiagnostic, part # 1) - #103386 (Don't allow `CoerceUnsized` into `dyn*` (except for trait upcasting)) - #103405 (Detect incorrect chaining of if and if let conditions and recover) - #103594 (Fix non-associativity of `Instant` math on `aarch64-apple-darwin` targets) - #104006 (Add variant_name function to `LangItem`) - #104494 (Migrate GUI test to use functions) - #104516 (rustdoc: clean up sidebar width CSS) - #104550 (fix a typo) Failed merges: - #104554 (Use `ErrorGuaranteed::unchecked_claim_error_was_emitted` less) r? `@ghost` `@rustbot` modify labels: rollup
·
1.88.01.67.0
2 parents 70fe5f0 + 7e5e520 commit b833ad5

File tree

31 files changed

+1281
-587
lines changed

31 files changed

+1281
-587
lines changed
 

‎Cargo.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4047,6 +4047,7 @@ dependencies = [
40474047
"rustc_feature",
40484048
"rustc_hir",
40494049
"rustc_index",
4050+
"rustc_macros",
40504051
"rustc_metadata",
40514052
"rustc_middle",
40524053
"rustc_query_system",

‎compiler/rustc_error_messages/locales/en-US/parser.ftl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ parser_invalid_logical_operator = `{$incorrect}` is not a logical operator
5454
parser_tilde_is_not_unary_operator = `~` cannot be used as a unary operator
5555
.suggestion = use `!` to perform bitwise not
5656
57+
parser_unexpected_if_with_if = unexpected `if` in the condition expression
58+
.suggestion = remove the `if`
59+
5760
parser_unexpected_token_after_not = unexpected {$negated_desc} after identifier
5861
parser_unexpected_token_after_not_bitwise = use `!` to perform bitwise not
5962
parser_unexpected_token_after_not_logical = use `!` to perform logical negation
Lines changed: 211 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,211 @@
1+
resolve_parent_module_reset_for_binding =
2+
parent module is reset for binding
3+
4+
resolve_ampersand_used_without_explicit_lifetime_name =
5+
`&` without an explicit lifetime name cannot be used here
6+
.note = explicit lifetime name needed here
7+
8+
resolve_underscore_lifetime_name_cannot_be_used_here =
9+
`'_` cannot be used here
10+
.note = `'_` is a reserved lifetime name
11+
12+
resolve_crate_may_not_be_imported =
13+
`$crate` may not be imported
14+
15+
resolve_crate_root_imports_must_be_named_explicitly =
16+
crate root imports need to be explicitly named: `use crate as name;`
17+
18+
resolve_generic_params_from_outer_function =
19+
can't use generic parameters from outer function
20+
.label = use of generic parameter from outer function
21+
.suggestion = try using a local generic parameter instead
22+
23+
resolve_self_type_implicitly_declared_by_impl =
24+
`Self` type implicitly declared here, by this `impl`
25+
26+
resolve_cannot_use_self_type_here =
27+
can't use `Self` here
28+
29+
resolve_use_a_type_here_instead =
30+
use a type here instead
31+
32+
resolve_type_param_from_outer_fn =
33+
type parameter from outer function
34+
35+
resolve_const_param_from_outer_fn =
36+
const parameter from outer function
37+
38+
resolve_try_using_local_generic_parameter =
39+
try using a local generic parameter instead
40+
41+
resolve_try_adding_local_generic_param_on_method =
42+
try adding a local generic parameter in this method instead
43+
44+
resolve_help_try_using_local_generic_param =
45+
try using a local generic paramter instead
46+
47+
resolve_name_is_already_used_as_generic_parameter =
48+
the name `{$name}` is already used for a generic parameter in this item's generic parameters
49+
.label = already used
50+
.first_use_of_name = first use of `{$name}`
51+
52+
resolve_method_not_member_of_trait =
53+
method `{$method}` is not a member of trait `{$trait_}`
54+
.label = not a member of trait `{$trait_}`
55+
56+
resolve_associated_fn_with_similar_name_exists =
57+
there is an associated function with a similar name
58+
59+
resolve_type_not_member_of_trait =
60+
type `{$type_}` is not a member of trait `{$trait_}`
61+
.label = not a member of trait `{$trait_}`
62+
63+
resolve_associated_type_with_similar_name_exists =
64+
there is an associated type with a similar name
65+
66+
resolve_const_not_member_of_trait =
67+
const `{$const_}` is not a member of trait `{$trait_}`
68+
.label = not a member of trait `{$trait_}`
69+
70+
resolve_associated_const_with_similar_name_exists =
71+
there is an associated constant with a similar name
72+
73+
resolve_variable_bound_with_different_mode =
74+
variable `{$variable_name}` is bound inconsistently across alternatives separated by `|`
75+
.label = bound in different ways
76+
.first_binding_span = first binding
77+
78+
resolve_ident_bound_more_than_once_in_parameter_list =
79+
identifier `{$identifier}` is bound more than once in this parameter list
80+
.label = used as parameter more than once
81+
82+
resolve_ident_bound_more_than_once_in_same_pattern =
83+
identifier `{$identifier}` is bound more than once in the same pattern
84+
.label = used in a pattern more than once
85+
86+
resolve_undeclared_label =
87+
use of undeclared label `{$name}`
88+
.label = undeclared label `{$name}`
89+
90+
resolve_label_with_similar_name_reachable =
91+
a label with a similar name is reachable
92+
93+
resolve_try_using_similarly_named_label =
94+
try using similarly named label
95+
96+
resolve_unreachable_label_with_similar_name_exists =
97+
a label with a similar name exists but is unreachable
98+
99+
resolve_self_import_can_only_appear_once_in_the_list =
100+
`self` import can only appear once in an import list
101+
.label = can only appear once in an import list
102+
103+
resolve_self_import_only_in_import_list_with_non_empty_prefix =
104+
`self` import can only appear in an import list with a non-empty prefix
105+
.label = can only appear in an import list with a non-empty prefix
106+
107+
resolve_cannot_capture_dynamic_environment_in_fn_item =
108+
can't capture dynamic environment in a fn item
109+
.help = use the `|| {"{"} ... {"}"}` closure form instead
110+
111+
resolve_attempt_to_use_non_constant_value_in_constant =
112+
attempt to use a non-constant value in a constant
113+
114+
resolve_attempt_to_use_non_constant_value_in_constant_with_suggestion =
115+
consider using `{$suggestion}` instead of `{$current}`
116+
117+
resolve_attempt_to_use_non_constant_value_in_constant_label_with_suggestion =
118+
non-constant value
119+
120+
resolve_attempt_to_use_non_constant_value_in_constant_without_suggestion =
121+
this would need to be a `{$suggestion}`
122+
123+
resolve_self_imports_only_allowed_within =
124+
`self` imports are only allowed within a {"{"} {"}"} list
125+
126+
resolve_self_imports_only_allowed_within_suggestion =
127+
consider importing the module directly
128+
129+
resolve_self_imports_only_allowed_within_multipart_suggestion =
130+
alternatively, use the multi-path `use` syntax to import `self`
131+
132+
resolve_binding_shadows_something_unacceptable =
133+
{$shadowing_binding}s cannot shadow {$shadowed_binding}s
134+
.label = cannot be named the same as {$article} {$shadowed_binding}
135+
.label_shadowed_binding = the {$shadowed_binding} `{$name}` is {$participle} here
136+
137+
resolve_binding_shadows_something_unacceptable_suggestion =
138+
try specify the pattern arguments
139+
140+
resolve_forward_declared_generic_param =
141+
generic parameters with a default cannot use forward declared identifiers
142+
.label = defaulted generic parameters cannot be forward declared
143+
144+
resolve_param_in_ty_of_const_param =
145+
the type of const parameters must not depend on other generic parameters
146+
.label = the type must not depend on the parameter `{$name}`
147+
148+
resolve_self_in_generic_param_default =
149+
generic parameters cannot use `Self` in their defaults
150+
.label = `Self` in generic parameter default
151+
152+
resolve_param_in_non_trivial_anon_const =
153+
generic parameters may not be used in const operations
154+
.label = cannot perform const operation using `{$name}`
155+
156+
resolve_param_in_non_trivial_anon_const_help =
157+
use `#![feature(generic_const_exprs)]` to allow generic const expressions
158+
159+
resolve_param_in_non_trivial_anon_const_sub_type =
160+
type parameters may not be used in const expressions
161+
162+
resolve_param_in_non_trivial_anon_const_sub_non_type =
163+
const parameters may only be used as standalone arguments, i.e. `{$name}`
164+
165+
resolve_unreachable_label =
166+
use of unreachable label `{$name}`
167+
.label = unreachable label `{$name}`
168+
.label_definition_span = unreachable label defined here
169+
.note = labels are unreachable through functions, closures, async blocks and modules
170+
171+
resolve_unreachable_label_suggestion_use_similarly_named =
172+
try using similarly named label
173+
174+
resolve_unreachable_label_similar_name_reachable =
175+
a label with a similar name is reachable
176+
177+
resolve_unreachable_label_similar_name_unreachable =
178+
a label with a similar name exists but is also unreachable
179+
180+
resolve_trait_impl_mismatch =
181+
item `{$name}` is an associated {$kind}, which doesn't match its trait `{$trait_path}`
182+
.label = does not match trait
183+
.label_trait_item = item in trait
184+
185+
resolve_invalid_asm_sym =
186+
invalid `sym` operand
187+
.label = is a local variable
188+
.help = `sym` operands must refer to either a function or a static
189+
190+
resolve_trait_impl_duplicate =
191+
duplicate definitions with name `{$name}`:
192+
.label = duplicate definition
193+
.old_span_label = previous definition here
194+
.trait_item_span = item in trait
195+
196+
resolve_relative_2018 =
197+
relative paths are not supported in visibilities in 2018 edition or later
198+
.suggestion = try
199+
200+
resolve_ancestor_only =
201+
visibilities can only be restricted to ancestor modules
202+
203+
resolve_expected_found =
204+
expected module, found {$res} `{$path_str}`
205+
.label = not a module
206+
207+
resolve_indeterminate =
208+
cannot determine resolution for the visibility
209+
210+
resolve_module_only =
211+
visibility must resolve to a module

‎compiler/rustc_error_messages/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ fluent_messages! {
6363
plugin_impl => "../locales/en-US/plugin_impl.ftl",
6464
privacy => "../locales/en-US/privacy.ftl",
6565
query_system => "../locales/en-US/query_system.ftl",
66+
resolve => "../locales/en-US/resolve.ftl",
6667
save_analysis => "../locales/en-US/save_analysis.ftl",
6768
session => "../locales/en-US/session.ftl",
6869
symbol_mangling => "../locales/en-US/symbol_mangling.ftl",

‎compiler/rustc_errors/src/diagnostic_impls.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,12 @@ impl IntoDiagnosticArg for DiagnosticSymbolList {
211211
}
212212
}
213213

214+
impl<Id> IntoDiagnosticArg for hir::def::Res<Id> {
215+
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
216+
DiagnosticArgValue::Str(Cow::Borrowed(self.descr()))
217+
}
218+
}
219+
214220
impl IntoDiagnostic<'_, !> for TargetDataLayoutErrors<'_> {
215221
fn into_diagnostic(self, handler: &Handler) -> DiagnosticBuilder<'_, !> {
216222
let mut diag;

‎compiler/rustc_hir/src/lang_items.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,14 @@ macro_rules! language_item_table {
9595
}
9696
}
9797

98+
/// Returns the name of the `LangItem` enum variant.
99+
// This method is used by Clippy for internal lints.
100+
pub fn variant_name(self) -> &'static str {
101+
match self {
102+
$( LangItem::$variant => stringify!($variant), )*
103+
}
104+
}
105+
98106
pub fn target(self) -> Target {
99107
match self {
100108
$( LangItem::$variant => $target, )*

‎compiler/rustc_middle/src/mir/interpret/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ impl fmt::Display for InvalidProgramInfo<'_> {
144144
AlreadyReported(ErrorGuaranteed { .. }) => {
145145
write!(
146146
f,
147-
"an error has already been reported elsewhere (this sould not usually be printed)"
147+
"an error has already been reported elsewhere (this should not usually be printed)"
148148
)
149149
}
150150
Layout(ref err) => write!(f, "{err}"),

‎compiler/rustc_parse/src/errors.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1219,3 +1219,11 @@ pub(crate) struct FnPtrWithGenericsSugg {
12191219
pub arity: usize,
12201220
pub for_param_list_exists: bool,
12211221
}
1222+
1223+
#[derive(Diagnostic)]
1224+
#[diag(parser_unexpected_if_with_if)]
1225+
pub(crate) struct UnexpectedIfWithIf(
1226+
#[primary_span]
1227+
#[suggestion(applicability = "machine-applicable", code = " ", style = "verbose")]
1228+
pub Span,
1229+
);

‎compiler/rustc_parse/src/parser/expr.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ use crate::errors::{
2121
NoFieldsForFnCall, NotAsNegationOperator, NotAsNegationOperatorSub,
2222
OuterAttributeNotAllowedOnIfElse, ParenthesesWithStructFields,
2323
RequireColonAfterLabeledExpression, ShiftInterpretedAsGeneric, StructLiteralNotAllowedHere,
24-
StructLiteralNotAllowedHereSugg, TildeAsUnaryOperator, UnexpectedTokenAfterLabel,
25-
UnexpectedTokenAfterLabelSugg, WrapExpressionInParentheses,
24+
StructLiteralNotAllowedHereSugg, TildeAsUnaryOperator, UnexpectedIfWithIf,
25+
UnexpectedTokenAfterLabel, UnexpectedTokenAfterLabelSugg, WrapExpressionInParentheses,
2626
};
2727
use crate::maybe_recover_from_interpolated_ty_qpath;
2828
use core::mem;
@@ -2239,6 +2239,7 @@ impl<'a> Parser<'a> {
22392239
if let Some(block) = recover_block_from_condition(self) {
22402240
block
22412241
} else {
2242+
self.error_on_extra_if(&cond)?;
22422243
// Parse block, which will always fail, but we can add a nice note to the error
22432244
self.parse_block().map_err(|mut err| {
22442245
err.span_note(
@@ -2375,6 +2376,16 @@ impl<'a> Parser<'a> {
23752376
});
23762377
}
23772378

2379+
fn error_on_extra_if(&mut self, cond: &P<Expr>) -> PResult<'a, ()> {
2380+
if let ExprKind::Binary(Spanned { span: binop_span, node: binop}, _, right) = &cond.kind &&
2381+
let BinOpKind::And = binop &&
2382+
let ExprKind::If(cond, ..) = &right.kind {
2383+
Err(self.sess.create_err(UnexpectedIfWithIf(binop_span.shrink_to_hi().to(cond.span.shrink_to_lo()))))
2384+
} else {
2385+
Ok(())
2386+
}
2387+
}
2388+
23782389
/// Parses `for <src_pat> in <src_expr> <src_loop_block>` (`for` token already eaten).
23792390
fn parse_for_expr(&mut self, opt_label: Option<Label>, lo: Span) -> PResult<'a, P<Expr>> {
23802391
// Record whether we are about to parse `for (`.

‎compiler/rustc_resolve/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ rustc_expand = { path = "../rustc_expand" }
1717
rustc_feature = { path = "../rustc_feature" }
1818
rustc_hir = { path = "../rustc_hir" }
1919
rustc_index = { path = "../rustc_index" }
20+
rustc_macros = { path = "../rustc_macros" }
2021
rustc_metadata = { path = "../rustc_metadata" }
2122
rustc_middle = { path = "../rustc_middle" }
2223
rustc_query_system = { path = "../rustc_query_system" }

‎compiler/rustc_resolve/src/diagnostics.rs

Lines changed: 182 additions & 362 deletions
Large diffs are not rendered by default.

‎compiler/rustc_resolve/src/errors.rs

Lines changed: 474 additions & 0 deletions
Large diffs are not rendered by default.

‎compiler/rustc_resolve/src/late.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use rustc_ast::ptr::P;
1616
use rustc_ast::visit::{self, AssocCtxt, BoundKind, FnCtxt, FnKind, Visitor};
1717
use rustc_ast::*;
1818
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap};
19-
use rustc_errors::DiagnosticId;
19+
use rustc_errors::{DiagnosticArgValue, DiagnosticId, IntoDiagnosticArg};
2020
use rustc_hir::def::Namespace::{self, *};
2121
use rustc_hir::def::{self, CtorKind, DefKind, LifetimeRes, PartialRes, PerNS};
2222
use rustc_hir::def_id::{DefId, LocalDefId, CRATE_DEF_ID, LOCAL_CRATE};
@@ -31,6 +31,7 @@ use smallvec::{smallvec, SmallVec};
3131

3232
use rustc_span::source_map::{respan, Spanned};
3333
use std::assert_matches::debug_assert_matches;
34+
use std::borrow::Cow;
3435
use std::collections::{hash_map::Entry, BTreeSet};
3536
use std::mem::{replace, swap, take};
3637

@@ -78,6 +79,12 @@ impl PatternSource {
7879
}
7980
}
8081

82+
impl IntoDiagnosticArg for PatternSource {
83+
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
84+
DiagnosticArgValue::Str(Cow::Borrowed(self.descr()))
85+
}
86+
}
87+
8188
/// Denotes whether the context for the set of already bound bindings is a `Product`
8289
/// or `Or` context. This is used in e.g., `fresh_binding` and `resolve_pattern_inner`.
8390
/// See those functions for more information.

‎compiler/rustc_resolve/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ mod check_unused;
7373
mod def_collector;
7474
mod diagnostics;
7575
mod effective_visibilities;
76+
mod errors;
7677
mod ident;
7778
mod imports;
7879
mod late;

‎compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
780780

781781
match (source.kind(), target.kind()) {
782782
// Trait+Kx+'a -> Trait+Ky+'b (upcasts).
783-
(&ty::Dynamic(ref data_a, ..), &ty::Dynamic(ref data_b, ..)) => {
783+
(&ty::Dynamic(ref data_a, _, dyn_a), &ty::Dynamic(ref data_b, _, dyn_b))
784+
if dyn_a == dyn_b =>
785+
{
784786
// Upcast coercions permit several things:
785787
//
786788
// 1. Dropping auto traits, e.g., `Foo + Send` to `Foo`
@@ -841,7 +843,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
841843
}
842844

843845
// `T` -> `Trait`
844-
(_, &ty::Dynamic(..)) => {
846+
(_, &ty::Dynamic(_, _, ty::Dyn)) => {
845847
candidates.vec.push(BuiltinUnsizeCandidate);
846848
}
847849

‎compiler/rustc_trait_selection/src/traits/select/confirmation.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -912,7 +912,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
912912
let mut nested = vec![];
913913
match (source.kind(), target.kind()) {
914914
// Trait+Kx+'a -> Trait+Ky+'b (auto traits and lifetime subtyping).
915-
(&ty::Dynamic(ref data_a, r_a, ty::Dyn), &ty::Dynamic(ref data_b, r_b, ty::Dyn)) => {
915+
(&ty::Dynamic(ref data_a, r_a, dyn_a), &ty::Dynamic(ref data_b, r_b, dyn_b))
916+
if dyn_a == dyn_b =>
917+
{
916918
// See `assemble_candidates_for_unsizing` for more info.
917919
// We already checked the compatibility of auto traits within `assemble_candidates_for_unsizing`.
918920
let iter = data_a
@@ -931,7 +933,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
931933
.map(ty::Binder::dummy),
932934
);
933935
let existential_predicates = tcx.mk_poly_existential_predicates(iter);
934-
let source_trait = tcx.mk_dynamic(existential_predicates, r_b, ty::Dyn);
936+
let source_trait = tcx.mk_dynamic(existential_predicates, r_b, dyn_a);
935937

936938
// Require that the traits involved in this upcast are **equal**;
937939
// only the **lifetime bound** is changed.
@@ -1140,7 +1142,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
11401142
}));
11411143
}
11421144

1143-
_ => bug!(),
1145+
_ => bug!("source: {source}, target: {target}"),
11441146
};
11451147

11461148
Ok(ImplSourceBuiltinData { nested })

‎library/std/src/sys/unix/time.rs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,11 @@ impl From<libc::timespec> for Timespec {
149149
}
150150
}
151151

152-
#[cfg(any(target_os = "macos", target_os = "ios", target_os = "watchos"))]
152+
#[cfg(any(
153+
all(target_os = "macos", any(not(target_arch = "aarch64"), miri)),
154+
target_os = "ios",
155+
target_os = "watchos"
156+
))]
153157
mod inner {
154158
use crate::sync::atomic::{AtomicU64, Ordering};
155159
use crate::sys::cvt;
@@ -265,7 +269,11 @@ mod inner {
265269
}
266270
}
267271

268-
#[cfg(not(any(target_os = "macos", target_os = "ios", target_os = "watchos")))]
272+
#[cfg(not(any(
273+
all(target_os = "macos", any(not(target_arch = "aarch64"), miri)),
274+
target_os = "ios",
275+
target_os = "watchos"
276+
)))]
269277
mod inner {
270278
use crate::fmt;
271279
use crate::mem::MaybeUninit;
@@ -281,7 +289,11 @@ mod inner {
281289

282290
impl Instant {
283291
pub fn now() -> Instant {
284-
Instant { t: Timespec::now(libc::CLOCK_MONOTONIC) }
292+
#[cfg(target_os = "macos")]
293+
const clock_id: libc::clockid_t = libc::CLOCK_UPTIME_RAW;
294+
#[cfg(not(target_os = "macos"))]
295+
const clock_id: libc::clockid_t = libc::CLOCK_MONOTONIC;
296+
Instant { t: Timespec::now(clock_id) }
285297
}
286298

287299
pub fn checked_sub_instant(&self, other: &Instant) -> Option<Duration> {
@@ -312,13 +324,8 @@ mod inner {
312324
}
313325
}
314326

315-
#[cfg(not(any(target_os = "dragonfly", target_os = "espidf", target_os = "horizon")))]
316-
pub type clock_t = libc::c_int;
317-
#[cfg(any(target_os = "dragonfly", target_os = "espidf", target_os = "horizon"))]
318-
pub type clock_t = libc::c_ulong;
319-
320327
impl Timespec {
321-
pub fn now(clock: clock_t) -> Timespec {
328+
pub fn now(clock: libc::clockid_t) -> Timespec {
322329
// Try to use 64-bit time in preparation for Y2038.
323330
#[cfg(all(target_os = "linux", target_env = "gnu", target_pointer_width = "32"))]
324331
{

‎library/std/src/time/tests.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,14 @@ fn instant_math_is_associative() {
8888
// Changing the order of instant math shouldn't change the results,
8989
// especially when the expression reduces to X + identity.
9090
assert_eq!((now + offset) - now, (now - now) + offset);
91+
92+
// On any platform, `Instant` should have the same resolution as `Duration` (e.g. 1 nanosecond)
93+
// or better. Otherwise, math will be non-associative (see #91417).
94+
let now = Instant::now();
95+
let provided_offset = Duration::from_nanos(1);
96+
let later = now + provided_offset;
97+
let measured_offset = later - now;
98+
assert_eq!(measured_offset, provided_offset);
9199
}
92100

93101
#[test]

‎src/librustdoc/html/static/css/rustdoc.css

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -384,8 +384,7 @@ img {
384384

385385
.sidebar {
386386
font-size: 0.875rem;
387-
width: 200px;
388-
min-width: 200px;
387+
flex: 0 0 200px;
389388
overflow-y: scroll;
390389
position: sticky;
391390
height: 100vh;
@@ -394,12 +393,7 @@ img {
394393
}
395394

396395
.rustdoc.source .sidebar {
397-
width: 50px;
398-
min-width: 0px;
399-
max-width: 300px;
400-
flex-grow: 0;
401-
flex-shrink: 0;
402-
flex-basis: auto;
396+
flex-basis: 50px;
403397
border-right: 1px solid;
404398
overflow-x: hidden;
405399
/* The sidebar is by default hidden */
@@ -420,7 +414,7 @@ img {
420414

421415
.source-sidebar-expanded .source .sidebar {
422416
overflow-y: auto;
423-
width: 300px;
417+
flex-basis: 300px;
424418
}
425419

426420
.source-sidebar-expanded .source .sidebar > *:not(#sidebar-toggle) {
@@ -1701,6 +1695,7 @@ in storage.js
17011695
z-index: 11;
17021696
/* Reduce height slightly to account for mobile topbar. */
17031697
height: calc(100vh - 45px);
1698+
width: 200px;
17041699
}
17051700

17061701
/* The source view uses a different design for the sidebar toggle, and doesn't have a topbar,

‎src/test/rustdoc-gui/sidebar-source-code-display.goml

Lines changed: 87 additions & 162 deletions
Original file line numberDiff line numberDiff line change
@@ -29,170 +29,95 @@ assert-local-storage: {"rustdoc-source-sidebar-show": "true"}
2929
// Now we check the display of the sidebar items.
3030
show-text: true
3131

32-
// First we start with the light theme.
33-
local-storage: {"rustdoc-theme": "light", "rustdoc-use-system-theme": "false"}
34-
reload:
35-
// Waiting for the sidebar to be displayed...
36-
wait-for-css: ("#sidebar-toggle", {"visibility": "visible"})
37-
assert-css: (
38-
"#source-sidebar details[open] > .files a.selected",
39-
{"color": "rgb(0, 0, 0)", "background-color": "rgb(255, 255, 255)"},
40-
)
41-
// Without hover or focus.
42-
assert-css: ("#sidebar-toggle > button", {"background-color": "rgba(0, 0, 0, 0)"})
43-
// With focus.
44-
focus: "#sidebar-toggle > button"
45-
assert-css: ("#sidebar-toggle > button", {"background-color": "rgb(224, 224, 224)"})
46-
focus: ".search-input"
47-
// With hover.
48-
move-cursor-to: "#sidebar-toggle > button"
49-
assert-css: ("#sidebar-toggle > button", {"background-color": "rgb(224, 224, 224)"})
50-
// Without hover.
51-
assert-css: (
52-
"#source-sidebar details[open] > .files a:not(.selected)",
53-
{"color": "rgb(0, 0, 0)", "background-color": "rgba(0, 0, 0, 0)"},
54-
)
55-
// With focus.
56-
focus: "#source-sidebar details[open] > .files a:not(.selected)"
57-
wait-for-css: (
58-
"#source-sidebar details[open] > .files a:not(.selected)",
59-
{"color": "rgb(0, 0, 0)", "background-color": "rgb(224, 224, 224)"},
60-
)
61-
focus: ".search-input"
62-
// With hover.
63-
move-cursor-to: "#source-sidebar details[open] > .files a:not(.selected)"
64-
assert-css: (
65-
"#source-sidebar details[open] > .files a:not(.selected)",
66-
{"color": "rgb(0, 0, 0)", "background-color": "rgb(224, 224, 224)"},
67-
)
68-
// Without hover.
69-
assert-css: (
70-
"#source-sidebar details[open] > .folders > details > summary",
71-
{"color": "rgb(0, 0, 0)", "background-color": "rgba(0, 0, 0, 0)"},
72-
)
73-
// With focus.
74-
focus: "#source-sidebar details[open] > .folders > details > summary"
75-
wait-for-css: (
76-
"#source-sidebar details[open] > .folders > details > summary",
77-
{"color": "rgb(0, 0, 0)", "background-color": "rgb(224, 224, 224)"},
78-
)
79-
focus: ".search-input"
80-
// With hover.
81-
move-cursor-to: "#source-sidebar details[open] > .folders > details > summary"
82-
assert-css: (
83-
"#source-sidebar details[open] > .folders > details > summary",
84-
{"color": "rgb(0, 0, 0)", "background-color": "rgb(224, 224, 224)"},
32+
define-function: (
33+
"check-colors",
34+
(
35+
theme, color, color_hover, background, background_hover, background_toggle,
36+
background_toggle_hover,
37+
),
38+
[
39+
("local-storage", {"rustdoc-theme": |theme|, "rustdoc-use-system-theme": "false"}),
40+
("reload"),
41+
("wait-for-css", ("#sidebar-toggle", {"visibility": "visible"})),
42+
("assert-css", (
43+
"#source-sidebar details[open] > .files a.selected",
44+
{"color": |color_hover|, "background-color": |background|},
45+
)),
46+
// Without hover or focus.
47+
("assert-css", ("#sidebar-toggle > button", {"background-color": |background_toggle|})),
48+
// With focus.
49+
("focus", "#sidebar-toggle > button"),
50+
("assert-css", ("#sidebar-toggle > button", {"background-color": |background_toggle_hover|})),
51+
("focus", ".search-input"),
52+
// With hover.
53+
("move-cursor-to", "#sidebar-toggle > button"),
54+
("assert-css", ("#sidebar-toggle > button", {"background-color": |background_toggle_hover|})),
55+
// Without hover.
56+
("assert-css", (
57+
"#source-sidebar details[open] > .files a:not(.selected)",
58+
{"color": |color|, "background-color": |background_toggle|},
59+
)),
60+
// With focus.
61+
("focus", "#source-sidebar details[open] > .files a:not(.selected)"),
62+
("wait-for-css", (
63+
"#source-sidebar details[open] > .files a:not(.selected)",
64+
{"color": |color_hover|, "background-color": |background_hover|},
65+
)),
66+
("focus", ".search-input"),
67+
// With hover.
68+
("move-cursor-to", "#source-sidebar details[open] > .files a:not(.selected)"),
69+
("assert-css", (
70+
"#source-sidebar details[open] > .files a:not(.selected)",
71+
{"color": |color_hover|, "background-color": |background_hover|},
72+
)),
73+
// Without hover.
74+
("assert-css", (
75+
"#source-sidebar details[open] > .folders > details > summary",
76+
{"color": |color|, "background-color": |background_toggle|},
77+
)),
78+
// With focus.
79+
("focus", "#source-sidebar details[open] > .folders > details > summary"),
80+
("wait-for-css", (
81+
"#source-sidebar details[open] > .folders > details > summary",
82+
{"color": |color_hover|, "background-color": |background_hover|},
83+
)),
84+
("focus", ".search-input"),
85+
// With hover.
86+
("move-cursor-to", "#source-sidebar details[open] > .folders > details > summary"),
87+
("assert-css", (
88+
"#source-sidebar details[open] > .folders > details > summary",
89+
{"color": |color_hover|, "background-color": |background_hover|},
90+
)),
91+
],
8592
)
8693

87-
// Now with the dark theme.
88-
local-storage: {"rustdoc-theme": "dark", "rustdoc-use-system-theme": "false"}
89-
reload:
90-
// Waiting for the sidebar to be displayed...
91-
wait-for-css: ("#sidebar-toggle", {"visibility": "visible"})
92-
assert-css: (
93-
"#source-sidebar details[open] > .files > a.selected",
94-
{"color": "rgb(221, 221, 221)", "background-color": "rgb(51, 51, 51)"},
95-
)
96-
// Without hover or focus.
97-
assert-css: ("#sidebar-toggle > button", {"background-color": "rgba(0, 0, 0, 0)"})
98-
// With focus.
99-
focus: "#sidebar-toggle > button"
100-
assert-css: ("#sidebar-toggle > button", {"background-color": "rgb(103, 103, 103)"})
101-
focus: ".search-input"
102-
// With hover.
103-
move-cursor-to: "#sidebar-toggle > button"
104-
assert-css: ("#sidebar-toggle > button", {"background-color": "rgb(103, 103, 103)"})
105-
// Without hover.
106-
assert-css: (
107-
"#source-sidebar details[open] > .files > a:not(.selected)",
108-
{"color": "rgb(221, 221, 221)", "background-color": "rgba(0, 0, 0, 0)"},
109-
)
110-
// With focus.
111-
focus: "#source-sidebar details[open] > .files a:not(.selected)"
112-
wait-for-css: (
113-
"#source-sidebar details[open] > .files a:not(.selected)",
114-
{"color": "rgb(221, 221, 221)", "background-color": "rgb(68, 68, 68)"},
115-
)
116-
focus: ".search-input"
117-
// With hover.
118-
move-cursor-to: "#source-sidebar details[open] > .files a:not(.selected)"
119-
assert-css: (
120-
"#source-sidebar details[open] > .files a:not(.selected)",
121-
{"color": "rgb(221, 221, 221)", "background-color": "rgb(68, 68, 68)"},
122-
)
123-
// Without hover.
124-
assert-css: (
125-
"#source-sidebar details[open] > .folders > details > summary",
126-
{"color": "rgb(221, 221, 221)", "background-color": "rgba(0, 0, 0, 0)"},
127-
)
128-
// With focus.
129-
focus: "#source-sidebar details[open] > .folders > details > summary"
130-
wait-for-css: (
131-
"#source-sidebar details[open] > .folders > details > summary",
132-
{"color": "rgb(221, 221, 221)", "background-color": "rgb(68, 68, 68)"},
133-
)
134-
focus: ".search-input"
135-
// With hover.
136-
move-cursor-to: "#source-sidebar details[open] > .folders > details > summary"
137-
assert-css: (
138-
"#source-sidebar details[open] > .folders > details > summary",
139-
{"color": "rgb(221, 221, 221)", "background-color": "rgb(68, 68, 68)"},
140-
)
141-
142-
// And finally with the ayu theme.
143-
local-storage: {"rustdoc-theme": "ayu", "rustdoc-use-system-theme": "false"}
144-
reload:
145-
// Waiting for the sidebar to be displayed...
146-
wait-for-css: ("#sidebar-toggle", {"visibility": "visible"})
147-
assert-css: (
148-
"#source-sidebar details[open] > .files a.selected",
149-
{"color": "rgb(255, 180, 76)", "background-color": "rgb(20, 25, 31)"},
150-
)
151-
// Without hover or focus.
152-
assert-css: ("#sidebar-toggle > button", {"background-color": "rgba(0, 0, 0, 0)"})
153-
// With focus.
154-
focus: "#sidebar-toggle > button"
155-
assert-css: ("#sidebar-toggle > button", {"background-color": "rgba(70, 70, 70, 0.33)"})
156-
focus: ".search-input"
157-
// With hover.
158-
move-cursor-to: "#sidebar-toggle > button"
159-
assert-css: ("#sidebar-toggle > button", {"background-color": "rgba(70, 70, 70, 0.33)"})
160-
// Without hover.
161-
assert-css: (
162-
"#source-sidebar details[open] > .files a:not(.selected)",
163-
{"color": "rgb(197, 197, 197)", "background-color": "rgba(0, 0, 0, 0)"},
164-
)
165-
// With focus.
166-
focus: "#source-sidebar details[open] > .files a:not(.selected)"
167-
wait-for-css: (
168-
"#source-sidebar details[open] > .files a:not(.selected)",
169-
{"color": "rgb(255, 180, 76)", "background-color": "rgb(20, 25, 31)"},
170-
)
171-
focus: ".search-input"
172-
// With hover.
173-
move-cursor-to: "#source-sidebar details[open] > .files a:not(.selected)"
174-
assert-css: (
175-
"#source-sidebar details[open] > .files a:not(.selected)",
176-
{"color": "rgb(255, 180, 76)", "background-color": "rgb(20, 25, 31)"},
177-
)
178-
// Without hover.
179-
assert-css: (
180-
"#source-sidebar details[open] > .folders > details > summary",
181-
{"color": "rgb(197, 197, 197)", "background-color": "rgba(0, 0, 0, 0)"},
182-
)
183-
// With focus.
184-
focus: "#source-sidebar details[open] > .folders > details > summary"
185-
wait-for-css: (
186-
"#source-sidebar details[open] > .folders > details > summary",
187-
{"color": "rgb(255, 180, 76)", "background-color": "rgb(20, 25, 31)"},
188-
)
189-
focus: ".search-input"
190-
// With hover.
191-
move-cursor-to: "#source-sidebar details[open] > .folders > details > summary"
192-
assert-css: (
193-
"#source-sidebar details[open] > .folders > details > summary",
194-
{"color": "rgb(255, 180, 76)", "background-color": "rgb(20, 25, 31)"},
195-
)
94+
call-function: ("check-colors", {
95+
"theme": "light",
96+
"color": "rgb(0, 0, 0)",
97+
"color_hover": "rgb(0, 0, 0)",
98+
"background": "rgb(255, 255, 255)",
99+
"background_hover": "rgb(224, 224, 224)",
100+
"background_toggle": "rgba(0, 0, 0, 0)",
101+
"background_toggle_hover": "rgb(224, 224, 224)",
102+
})
103+
call-function: ("check-colors", {
104+
"theme": "dark",
105+
"color": "rgb(221, 221, 221)",
106+
"color_hover": "rgb(221, 221, 221)",
107+
"background": "rgb(51, 51, 51)",
108+
"background_hover": "rgb(68, 68, 68)",
109+
"background_toggle": "rgba(0, 0, 0, 0)",
110+
"background_toggle_hover": "rgb(103, 103, 103)",
111+
})
112+
call-function: ("check-colors", {
113+
"theme": "ayu",
114+
"color": "rgb(197, 197, 197)",
115+
"color_hover": "rgb(255, 180, 76)",
116+
"background": "rgb(20, 25, 31)",
117+
"background_hover": "rgb(20, 25, 31)",
118+
"background_toggle": "rgba(0, 0, 0, 0)",
119+
"background_toggle_hover": "rgba(70, 70, 70, 0.33)",
120+
})
196121

197122
// Now checking on mobile devices.
198123
size: (500, 700)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// check-pass
2+
3+
#![feature(dyn_star)]
4+
#![allow(incomplete_features)]
5+
6+
trait AddOne {
7+
fn add1(&mut self) -> usize;
8+
}
9+
10+
impl AddOne for usize {
11+
fn add1(&mut self) -> usize {
12+
*self += 1;
13+
*self
14+
}
15+
}
16+
17+
fn add_one(i: &mut (dyn* AddOne + '_)) -> usize {
18+
i.add1()
19+
}
20+
21+
fn main() {
22+
let mut x = 42usize as dyn* AddOne;
23+
24+
println!("{}", add_one(&mut x));
25+
println!("{}", add_one(&mut x));
26+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#![feature(dyn_star)]
2+
#![allow(incomplete_features)]
3+
4+
use std::fmt::Debug;
5+
6+
fn main() {
7+
let i = 42 as &dyn* Debug;
8+
//~^ ERROR non-primitive cast: `i32` as `&dyn* Debug`
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0605]: non-primitive cast: `i32` as `&dyn* Debug`
2+
--> $DIR/unsize-into-ref-dyn-star.rs:7:13
3+
|
4+
LL | let i = 42 as &dyn* Debug;
5+
| ^^^^^^^^^^^^^^^^^ an `as` expression can only be used to convert between primitive types or to coerce to a specific trait object
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0605`.

‎src/test/ui/parser/issue-103381.fixed

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// run-rustfix
2+
3+
#![feature(let_chains)]
4+
#![allow(unused_variables)]
5+
#![allow(dead_code)]
6+
#![allow(irrefutable_let_patterns)]
7+
8+
fn err_some(b: bool, x: Option<u32>) {
9+
if b && let Some(x) = x {}
10+
//~^ ERROR unexpected `if` in the condition expression
11+
}
12+
13+
fn err_none(b: bool, x: Option<u32>) {
14+
if b && let None = x {}
15+
//~^ ERROR unexpected `if` in the condition expression
16+
}
17+
18+
fn err_bool_1() {
19+
if true && true { true } else { false };
20+
//~^ ERROR unexpected `if` in the condition expression
21+
}
22+
23+
fn err_bool_2() {
24+
if true && false { true } else { false };
25+
//~^ ERROR unexpected `if` in the condition expression
26+
}
27+
28+
fn should_ok_1() {
29+
if true && if let x = 1 { true } else { true } {}
30+
}
31+
32+
fn should_ok_2() {
33+
if true && if let 1 = 1 { true } else { true } {}
34+
}
35+
36+
fn should_ok_3() {
37+
if true && if true { true } else { false } {}
38+
}
39+
40+
fn shoule_match_ok() {
41+
#[cfg(feature = "full")]
42+
{
43+
let a = 1;
44+
let b = 2;
45+
if match a {
46+
1 if b == 1 => true,
47+
_ => false,
48+
} && if a > 1 { true } else { false }
49+
{
50+
true
51+
}
52+
}
53+
}
54+
55+
fn should_ok_in_nested() {
56+
if true && if true { true } else { false } { true } else { false };
57+
}
58+
59+
fn main() {}

‎src/test/ui/parser/issue-103381.rs

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// run-rustfix
2+
3+
#![feature(let_chains)]
4+
#![allow(unused_variables)]
5+
#![allow(dead_code)]
6+
#![allow(irrefutable_let_patterns)]
7+
8+
fn err_some(b: bool, x: Option<u32>) {
9+
if b && if let Some(x) = x {}
10+
//~^ ERROR unexpected `if` in the condition expression
11+
}
12+
13+
fn err_none(b: bool, x: Option<u32>) {
14+
if b && if let None = x {}
15+
//~^ ERROR unexpected `if` in the condition expression
16+
}
17+
18+
fn err_bool_1() {
19+
if true && if true { true } else { false };
20+
//~^ ERROR unexpected `if` in the condition expression
21+
}
22+
23+
fn err_bool_2() {
24+
if true && if false { true } else { false };
25+
//~^ ERROR unexpected `if` in the condition expression
26+
}
27+
28+
fn should_ok_1() {
29+
if true && if let x = 1 { true } else { true } {}
30+
}
31+
32+
fn should_ok_2() {
33+
if true && if let 1 = 1 { true } else { true } {}
34+
}
35+
36+
fn should_ok_3() {
37+
if true && if true { true } else { false } {}
38+
}
39+
40+
fn shoule_match_ok() {
41+
#[cfg(feature = "full")]
42+
{
43+
let a = 1;
44+
let b = 2;
45+
if match a {
46+
1 if b == 1 => true,
47+
_ => false,
48+
} && if a > 1 { true } else { false }
49+
{
50+
true
51+
}
52+
}
53+
}
54+
55+
fn should_ok_in_nested() {
56+
if true && if true { true } else { false } { true } else { false };
57+
}
58+
59+
fn main() {}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
error: unexpected `if` in the condition expression
2+
--> $DIR/issue-103381.rs:9:12
3+
|
4+
LL | if b && if let Some(x) = x {}
5+
| ^^^^
6+
|
7+
help: remove the `if`
8+
|
9+
LL - if b && if let Some(x) = x {}
10+
LL + if b && let Some(x) = x {}
11+
|
12+
13+
error: unexpected `if` in the condition expression
14+
--> $DIR/issue-103381.rs:14:12
15+
|
16+
LL | if b && if let None = x {}
17+
| ^^^^
18+
|
19+
help: remove the `if`
20+
|
21+
LL - if b && if let None = x {}
22+
LL + if b && let None = x {}
23+
|
24+
25+
error: unexpected `if` in the condition expression
26+
--> $DIR/issue-103381.rs:19:15
27+
|
28+
LL | if true && if true { true } else { false };
29+
| ^^^^
30+
|
31+
help: remove the `if`
32+
|
33+
LL - if true && if true { true } else { false };
34+
LL + if true && true { true } else { false };
35+
|
36+
37+
error: unexpected `if` in the condition expression
38+
--> $DIR/issue-103381.rs:24:15
39+
|
40+
LL | if true && if false { true } else { false };
41+
| ^^^^
42+
|
43+
help: remove the `if`
44+
|
45+
LL - if true && if false { true } else { false };
46+
LL + if true && false { true } else { false };
47+
|
48+
49+
error: aborting due to 4 previous errors
50+

‎src/tools/clippy/clippy_lints/src/utils/internal_lints/invalid_paths.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,22 +79,22 @@ pub fn check_path(cx: &LateContext<'_>, path: &[&str]) -> bool {
7979
SimplifiedTypeGen::StrSimplifiedType,
8080
]
8181
.iter()
82-
.flat_map(|&ty| cx.tcx.incoherent_impls(ty));
83-
for item_def_id in lang_items.items().iter().flatten().chain(incoherent_impls) {
84-
let lang_item_path = cx.get_def_path(*item_def_id);
82+
.flat_map(|&ty| cx.tcx.incoherent_impls(ty).iter().copied());
83+
for item_def_id in lang_items.iter().map(|(_, def_id)| def_id).chain(incoherent_impls) {
84+
let lang_item_path = cx.get_def_path(item_def_id);
8585
if path_syms.starts_with(&lang_item_path) {
8686
if let [item] = &path_syms[lang_item_path.len()..] {
8787
if matches!(
88-
cx.tcx.def_kind(*item_def_id),
88+
cx.tcx.def_kind(item_def_id),
8989
DefKind::Mod | DefKind::Enum | DefKind::Trait
9090
) {
91-
for child in cx.tcx.module_children(*item_def_id) {
91+
for child in cx.tcx.module_children(item_def_id) {
9292
if child.ident.name == *item {
9393
return true;
9494
}
9595
}
9696
} else {
97-
for child in cx.tcx.associated_item_def_ids(*item_def_id) {
97+
for child in cx.tcx.associated_item_def_ids(item_def_id) {
9898
if cx.tcx.item_name(*child) == *item {
9999
return true;
100100
}

‎src/tools/clippy/clippy_lints/src/utils/internal_lints/unnecessary_def_path.rs

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_ast::ast::LitKind;
66
use rustc_data_structures::fx::FxHashSet;
77
use rustc_errors::Applicability;
88
use rustc_hir as hir;
9-
use rustc_hir::def::{DefKind, Namespace, Res};
9+
use rustc_hir::def::{DefKind, Res};
1010
use rustc_hir::def_id::DefId;
1111
use rustc_hir::{Expr, ExprKind, Local, Mutability, Node};
1212
use rustc_lint::{LateContext, LateLintPass};
@@ -91,7 +91,7 @@ impl UnnecessaryDefPath {
9191
#[allow(clippy::too_many_lines)]
9292
fn check_call(&mut self, cx: &LateContext<'_>, func: &Expr<'_>, args: &[Expr<'_>], span: Span) {
9393
enum Item {
94-
LangItem(Symbol),
94+
LangItem(&'static str),
9595
DiagnosticItem(Symbol),
9696
}
9797
static PATHS: &[&[&str]] = &[
@@ -325,18 +325,9 @@ fn inherent_def_path_res(cx: &LateContext<'_>, segments: &[&str]) -> Option<DefI
325325
})
326326
}
327327

328-
fn get_lang_item_name(cx: &LateContext<'_>, def_id: DefId) -> Option<Symbol> {
329-
if let Some(lang_item) = cx.tcx.lang_items().items().iter().position(|id| *id == Some(def_id)) {
330-
let lang_items = def_path_res(cx, &["rustc_hir", "lang_items", "LangItem"], Some(Namespace::TypeNS)).def_id();
331-
let item_name = cx
332-
.tcx
333-
.adt_def(lang_items)
334-
.variants()
335-
.iter()
336-
.nth(lang_item)
337-
.unwrap()
338-
.name;
339-
Some(item_name)
328+
fn get_lang_item_name(cx: &LateContext<'_>, def_id: DefId) -> Option<&'static str> {
329+
if let Some((lang_item, _)) = cx.tcx.lang_items().iter().find(|(_, id)| *id == def_id) {
330+
Some(lang_item.variant_name())
340331
} else {
341332
None
342333
}

‎src/tools/clippy/tests/ui-internal/unnecessary_def_path.fixed

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,14 @@ fn _f<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>, did: DefId, expr: &Expr<'_>) {
4848
let _ = is_type_lang_item(cx, ty, LangItem::OwnedBox);
4949
let _ = is_type_diagnostic_item(cx, ty, sym::maybe_uninit_uninit);
5050

51-
let _ = cx.tcx.lang_items().require(LangItem::OwnedBox).ok() == Some(did);
51+
let _ = cx.tcx.lang_items().get(LangItem::OwnedBox) == Some(did);
5252
let _ = cx.tcx.is_diagnostic_item(sym::Option, did);
53-
let _ = cx.tcx.lang_items().require(LangItem::OptionSome).ok() == Some(did);
53+
let _ = cx.tcx.lang_items().get(LangItem::OptionSome) == Some(did);
5454

5555
let _ = is_trait_method(cx, expr, sym::AsRef);
5656

5757
let _ = is_path_diagnostic_item(cx, expr, sym::Option);
58-
let _ = path_res(cx, expr).opt_def_id().map_or(false, |id| cx.tcx.lang_items().require(LangItem::IteratorNext).ok() == Some(id));
58+
let _ = path_res(cx, expr).opt_def_id().map_or(false, |id| cx.tcx.lang_items().get(LangItem::IteratorNext) == Some(id));
5959
let _ = is_res_lang_ctor(cx, path_res(cx, expr), LangItem::OptionSome);
6060
}
6161

‎src/tools/clippy/tests/ui-internal/unnecessary_def_path.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ error: use of a def path to a `LangItem`
5757
--> $DIR/unnecessary_def_path.rs:51:13
5858
|
5959
LL | let _ = match_def_path(cx, did, &["alloc", "boxed", "Box"]);
60-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `cx.tcx.lang_items().require(LangItem::OwnedBox).ok() == Some(did)`
60+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `cx.tcx.lang_items().get(LangItem::OwnedBox) == Some(did)`
6161

6262
error: use of a def path to a diagnostic item
6363
--> $DIR/unnecessary_def_path.rs:52:13
@@ -69,7 +69,7 @@ error: use of a def path to a `LangItem`
6969
--> $DIR/unnecessary_def_path.rs:53:13
7070
|
7171
LL | let _ = match_def_path(cx, did, &["core", "option", "Option", "Some"]);
72-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `cx.tcx.lang_items().require(LangItem::OptionSome).ok() == Some(did)`
72+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `cx.tcx.lang_items().get(LangItem::OptionSome) == Some(did)`
7373
|
7474
= help: if this `DefId` came from a constructor expression or pattern then the parent `DefId` should be used instead
7575

@@ -89,7 +89,7 @@ error: use of a def path to a `LangItem`
8989
--> $DIR/unnecessary_def_path.rs:58:13
9090
|
9191
LL | let _ = is_expr_path_def_path(cx, expr, &["core", "iter", "traits", "Iterator", "next"]);
92-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `path_res(cx, expr).opt_def_id().map_or(false, |id| cx.tcx.lang_items().require(LangItem::IteratorNext).ok() == Some(id))`
92+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `path_res(cx, expr).opt_def_id().map_or(false, |id| cx.tcx.lang_items().get(LangItem::IteratorNext) == Some(id))`
9393

9494
error: use of a def path to a `LangItem`
9595
--> $DIR/unnecessary_def_path.rs:59:13
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
error: hardcoded path to a language item
2-
--> $DIR/unnecessary_def_path_hardcoded_path.rs:11:40
1+
error: hardcoded path to a diagnostic item
2+
--> $DIR/unnecessary_def_path_hardcoded_path.rs:10:36
33
|
4-
LL | const DEREF_MUT_TRAIT: [&str; 4] = ["core", "ops", "deref", "DerefMut"];
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4+
LL | const DEREF_TRAIT: [&str; 4] = ["core", "ops", "deref", "Deref"];
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
7-
= help: convert all references to use `LangItem::DerefMut`
7+
= help: convert all references to use `sym::Deref`
88
= note: `-D clippy::unnecessary-def-path` implied by `-D warnings`
99

1010
error: hardcoded path to a diagnostic item
@@ -15,13 +15,13 @@ LL | const DEREF_TRAIT_METHOD: [&str; 5] = ["core", "ops", "deref", "Deref",
1515
|
1616
= help: convert all references to use `sym::deref_method`
1717

18-
error: hardcoded path to a diagnostic item
19-
--> $DIR/unnecessary_def_path_hardcoded_path.rs:10:36
18+
error: hardcoded path to a language item
19+
--> $DIR/unnecessary_def_path_hardcoded_path.rs:11:40
2020
|
21-
LL | const DEREF_TRAIT: [&str; 4] = ["core", "ops", "deref", "Deref"];
22-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21+
LL | const DEREF_MUT_TRAIT: [&str; 4] = ["core", "ops", "deref", "DerefMut"];
22+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2323
|
24-
= help: convert all references to use `sym::Deref`
24+
= help: convert all references to use `LangItem::DerefMut`
2525

2626
error: aborting due to 3 previous errors
2727

0 commit comments

Comments
 (0)
Please sign in to comment.