Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5affbb1

Browse files
committed
Auto merge of #127924 - matthiaskrgr:rollup-1gn6afv, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - #124881 (Use ThreadId instead of TLS-address in `ReentrantLock`) - #127656 (make pub_use_of_private_extern_crate show up in cargo's future breakage reports) - #127748 (Use Option's discriminant as its size hint) - #127854 (Add internal lint for detecting non-glob imports of `rustc_type_ir::inherent`) - #127908 (Update extern linking documentation) - #127919 (Allow a git command for getting the current branch in bootstrap to fail) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 5753b30 + 6c10822 commit 5affbb1

File tree

17 files changed

+393
-47
lines changed

17 files changed

+393
-47
lines changed

‎compiler/rustc_lint/messages.ftl‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,9 @@ lint_non_fmt_panic_unused =
556556
}
557557
.add_fmt_suggestion = or add a "{"{"}{"}"}" format string to use the message literally
558558
559+
lint_non_glob_import_type_ir_inherent = non-glob import of `rustc_type_ir::inherent`
560+
.suggestion = try using a glob import instead
561+
559562
lint_non_local_definitions_cargo_update = the {$macro_kind} `{$macro_name}` may come from an old version of the `{$crate_name}` crate, try updating your dependency with `cargo update -p {$crate_name}`
560563
561564
lint_non_local_definitions_deprecation = this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue <https://github.com/rust-lang/rust/issues/120363>

‎compiler/rustc_lint/src/internal.rs‎

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
44
use crate::lints::{
55
BadOptAccessDiag, DefaultHashTypesDiag, DiagOutOfImpl, LintPassByHand, NonExistentDocKeyword,
6-
QueryInstability, SpanUseEqCtxtDiag, TyQualified, TykindDiag, TykindKind, UntranslatableDiag,
6+
NonGlobImportTypeIrInherent, QueryInstability, SpanUseEqCtxtDiag, TyQualified, TykindDiag,
7+
TykindKind, UntranslatableDiag,
78
};
89
use crate::{EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintContext};
910
use rustc_ast as ast;
@@ -263,6 +264,49 @@ fn gen_args(segment: &PathSegment<'_>) -> String {
263264
String::new()
264265
}
265266

267+
declare_tool_lint! {
268+
/// The `non_glob_import_of_type_ir_inherent_item` lint detects
269+
/// non-glob imports of module `rustc_type_ir::inherent`.
270+
pub rustc::NON_GLOB_IMPORT_OF_TYPE_IR_INHERENT,
271+
Allow,
272+
"non-glob import of `rustc_type_ir::inherent`",
273+
report_in_external_macro: true
274+
}
275+
276+
declare_lint_pass!(TypeIr => [NON_GLOB_IMPORT_OF_TYPE_IR_INHERENT]);
277+
278+
impl<'tcx> LateLintPass<'tcx> for TypeIr {
279+
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'tcx>) {
280+
let rustc_hir::ItemKind::Use(path, kind) = item.kind else { return };
281+
282+
let is_mod_inherent = |def_id| cx.tcx.is_diagnostic_item(sym::type_ir_inherent, def_id);
283+
let (lo, hi, snippet) = match path.segments {
284+
[.., penultimate, segment]
285+
if penultimate.res.opt_def_id().is_some_and(is_mod_inherent) =>
286+
{
287+
(segment.ident.span, item.ident.span, "*")
288+
}
289+
[.., segment]
290+
if path.res.iter().flat_map(Res::opt_def_id).any(is_mod_inherent)
291+
&& let rustc_hir::UseKind::Single = kind =>
292+
{
293+
let (lo, snippet) =
294+
match cx.tcx.sess.source_map().span_to_snippet(path.span).as_deref() {
295+
Ok("self") => (path.span, "*"),
296+
_ => (segment.ident.span.shrink_to_hi(), "::*"),
297+
};
298+
(lo, if segment.ident == item.ident { lo } else { item.ident.span }, snippet)
299+
}
300+
_ => return,
301+
};
302+
cx.emit_span_lint(
303+
NON_GLOB_IMPORT_OF_TYPE_IR_INHERENT,
304+
path.span,
305+
NonGlobImportTypeIrInherent { suggestion: lo.eq_ctxt(hi).then(|| lo.to(hi)), snippet },
306+
);
307+
}
308+
}
309+
266310
declare_tool_lint! {
267311
/// The `lint_pass_impl_without_macro` detects manual implementations of a lint
268312
/// pass, without using [`declare_lint_pass`] or [`impl_lint_pass`].

‎compiler/rustc_lint/src/lib.rs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,8 @@ fn register_internals(store: &mut LintStore) {
572572
store.register_late_mod_pass(|_| Box::new(ExistingDocKeyword));
573573
store.register_lints(&TyTyKind::get_lints());
574574
store.register_late_mod_pass(|_| Box::new(TyTyKind));
575+
store.register_lints(&TypeIr::get_lints());
576+
store.register_late_mod_pass(|_| Box::new(TypeIr));
575577
store.register_lints(&Diagnostics::get_lints());
576578
store.register_late_mod_pass(|_| Box::new(Diagnostics));
577579
store.register_lints(&BadOptAccess::get_lints());
@@ -595,6 +597,7 @@ fn register_internals(store: &mut LintStore) {
595597
LintId::of(PASS_BY_VALUE),
596598
LintId::of(LINT_PASS_IMPL_WITHOUT_MACRO),
597599
LintId::of(USAGE_OF_QUALIFIED_TY),
600+
LintId::of(NON_GLOB_IMPORT_OF_TYPE_IR_INHERENT),
598601
LintId::of(EXISTING_DOC_KEYWORD),
599602
LintId::of(BAD_OPT_ACCESS),
600603
LintId::of(SPAN_USE_EQ_CTXT),

‎compiler/rustc_lint/src/lints.rs‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -926,6 +926,14 @@ pub struct TyQualified {
926926
pub suggestion: Span,
927927
}
928928

929+
#[derive(LintDiagnostic)]
930+
#[diag(lint_non_glob_import_type_ir_inherent)]
931+
pub struct NonGlobImportTypeIrInherent {
932+
#[suggestion(code = "{snippet}", applicability = "maybe-incorrect")]
933+
pub suggestion: Option<Span>,
934+
pub snippet: &'static str,
935+
}
936+
929937
#[derive(LintDiagnostic)]
930938
#[diag(lint_lintpass_by_hand)]
931939
#[help]

‎compiler/rustc_lint_defs/src/builtin.rs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,16 +1203,16 @@ declare_lint! {
12031203
/// This was historically allowed, but is not the intended behavior
12041204
/// according to the visibility rules. This is a [future-incompatible]
12051205
/// lint to transition this to a hard error in the future. See [issue
1206-
/// #34537] for more details.
1206+
/// #127909] for more details.
12071207
///
1208-
/// [issue #34537]: https://github.com/rust-lang/rust/issues/34537
1208+
/// [issue #127909]: https://github.com/rust-lang/rust/issues/127909
12091209
/// [future-incompatible]: ../index.md#future-incompatible-lints
12101210
pub PUB_USE_OF_PRIVATE_EXTERN_CRATE,
12111211
Deny,
12121212
"detect public re-exports of private extern crates",
12131213
@future_incompatible = FutureIncompatibleInfo {
1214-
reason: FutureIncompatibilityReason::FutureReleaseErrorDontReportInDeps,
1215-
reference: "issue #34537 <https://github.com/rust-lang/rust/issues/34537>",
1214+
reason: FutureIncompatibilityReason::FutureReleaseErrorReportInDeps,
1215+
reference: "issue #127909 <https://github.com/rust-lang/rust/issues/127909>",
12161216
};
12171217
}
12181218

‎compiler/rustc_span/src/symbol.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1926,6 +1926,7 @@ symbols! {
19261926
type_ascription,
19271927
type_changing_struct_update,
19281928
type_id,
1929+
type_ir_inherent,
19291930
type_length_limit,
19301931
type_macros,
19311932
type_name,

‎compiler/rustc_type_ir/src/effects.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::inherent::{AdtDef,IntoKind,Ty};
1+
use crate::inherent::*;
22
use crate::lang_items::TraitSolverLangItem::{EffectsMaybe, EffectsNoRuntime, EffectsRuntime};
33
use crate::Interner;
44

‎compiler/rustc_type_ir/src/lib.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ pub mod elaborate;
2424
pub mod error;
2525
pub mod fast_reject;
2626
pub mod fold;
27+
#[cfg_attr(feature = "nightly", rustc_diagnostic_item = "type_ir_inherent")]
2728
pub mod inherent;
2829
pub mod ir_print;
2930
pub mod lang_items;

‎library/core/src/option.rs‎

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,13 @@ impl<T> Option<T> {
770770
}
771771
}
772772

773+
#[inline]
774+
const fn len(&self) -> usize {
775+
// Using the intrinsic avoids emitting a branch to get the 0 or 1.
776+
let discriminant: isize = crate::intrinsics::discriminant_value(self);
777+
discriminant as usize
778+
}
779+
773780
/// Returns a slice of the contained value, if any. If this is `None`, an
774781
/// empty slice is returned. This can be useful to have a single type of
775782
/// iterator over an `Option` or slice.
@@ -812,7 +819,7 @@ impl<T> Option<T> {
812819
unsafe {
813820
slice::from_raw_parts(
814821
(self as *const Self).byte_add(core::mem::offset_of!(Self, Some.0)).cast(),
815-
self.is_some()asusize,
822+
self.len(),
816823
)
817824
}
818825
}
@@ -869,7 +876,7 @@ impl<T> Option<T> {
869876
unsafe {
870877
slice::from_raw_parts_mut(
871878
(self as *mut Self).byte_add(core::mem::offset_of!(Self, Some.0)).cast(),
872-
self.is_some()asusize,
879+
self.len(),
873880
)
874881
}
875882
}
@@ -2242,10 +2249,8 @@ impl<A> Iterator for Item<A> {
22422249

22432250
#[inline]
22442251
fn size_hint(&self) -> (usize, Option<usize>) {
2245-
match self.opt {
2246-
Some(_) => (1, Some(1)),
2247-
None => (0, Some(0)),
2248-
}
2252+
let len = self.len();
2253+
(len, Some(len))
22492254
}
22502255
}
22512256

@@ -2256,7 +2261,12 @@ impl<A> DoubleEndedIterator for Item<A> {
22562261
}
22572262
}
22582263

2259-
impl<A> ExactSizeIterator for Item<A> {}
2264+
impl<A> ExactSizeIterator for Item<A> {
2265+
#[inline]
2266+
fn len(&self) -> usize {
2267+
self.opt.len()
2268+
}
2269+
}
22602270
impl<A> FusedIterator for Item<A> {}
22612271
unsafe impl<A> TrustedLen for Item<A> {}
22622272

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /