Skip to content

Commit ad88831

Browse files
committed
Auto merge of rust-lang#93548 - matthiaskrgr:rollup-f7dkn3p, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - rust-lang#86374 (Enable combining `+crt-static` and `relocation-model=pic` on `x86_64-unknown-linux-gnu`) - rust-lang#91828 (Implement `RawWaker` and `Waker` getters for underlying pointers) - rust-lang#92021 (Eliminate duplicate codes of is_single_fp_element) - rust-lang#92584 (add rustc lint, warning when iterating over hashmaps 2) - rust-lang#93267 (implement a lint for suspicious auto trait impls) - rust-lang#93290 (remove `TyS::same_type`) - rust-lang#93436 (Update compiler_builtins to fix duplicate symbols in `armv7-linux-androideabi` rlib) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 686663a + 019c140 commit ad88831

File tree

88 files changed

+889
-241
lines changed

Some content is hidden

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

88 files changed

+889
-241
lines changed

Cargo.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -761,9 +761,9 @@ dependencies = [
761761

762762
[[package]]
763763
name = "compiler_builtins"
764-
version = "0.1.66"
764+
version = "0.1.67"
765765
source = "registry+https://github.com/rust-lang/crates.io-index"
766-
checksum = "191424db7756bbed2c4996959a0fbda94388abcf4f5a2728a8af17481ad9c4f7"
766+
checksum = "a68c69e9451f1df4b215c9588c621670c12286b53e60fb5ec4b59aaa1138d18e"
767767
dependencies = [
768768
"cc",
769769
"rustc-std-workspace-core",

compiler/rustc_ast_lowering/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#![feature(box_patterns)]
3535
#![feature(never_type)]
3636
#![recursion_limit = "256"]
37+
#![cfg_attr(not(bootstrap), allow(rustc::potential_query_instability))]
3738

3839
use rustc_ast::token::{self, Token};
3940
use rustc_ast::tokenstream::{CanSynthesizeMissingTokens, TokenStream, TokenTree};

compiler/rustc_ast_passes/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#![feature(box_patterns)]
99
#![feature(let_else)]
1010
#![recursion_limit = "256"]
11+
#![cfg_attr(not(bootstrap), allow(rustc::potential_query_instability))]
1112

1213
pub mod ast_validation;
1314
pub mod feature_gate;

compiler/rustc_borrowck/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#![feature(trusted_step)]
1010
#![feature(try_blocks)]
1111
#![recursion_limit = "256"]
12+
#![cfg_attr(not(bootstrap), allow(rustc::potential_query_instability))]
1213

1314
#[macro_use]
1415
extern crate rustc_middle;

compiler/rustc_builtin_macros/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#![feature(proc_macro_internals)]
1313
#![feature(proc_macro_quote)]
1414
#![recursion_limit = "256"]
15+
#![cfg_attr(not(bootstrap), allow(rustc::potential_query_instability))]
1516

1617
extern crate proc_macro;
1718

compiler/rustc_codegen_llvm/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#![feature(extern_types)]
1212
#![feature(nll)]
1313
#![recursion_limit = "256"]
14+
#![cfg_attr(not(bootstrap), allow(rustc::potential_query_instability))]
1415

1516
use back::write::{create_informational_target_machine, create_target_machine};
1617

compiler/rustc_codegen_ssa/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#![feature(nll)]
88
#![feature(associated_type_bounds)]
99
#![recursion_limit = "256"]
10+
#![cfg_attr(not(bootstrap), allow(rustc::potential_query_instability))]
1011

1112
//! This crate contains codegen code that is used by all codegen backends (LLVM and others).
1213
//! The backend-agnostic functions of this crate use functions defined in various traits that

compiler/rustc_const_eval/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Rust MIR: a lowered representation of Rust.
2222
#![feature(trusted_step)]
2323
#![feature(try_blocks)]
2424
#![recursion_limit = "256"]
25+
#![cfg_attr(not(bootstrap), allow(rustc::potential_query_instability))]
2526

2627
#[macro_use]
2728
extern crate tracing;

compiler/rustc_data_structures/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#![feature(vec_into_raw_parts)]
2727
#![allow(rustc::default_hash_types)]
2828
#![deny(unaligned_references)]
29+
#![cfg_attr(not(bootstrap), allow(rustc::potential_query_instability))]
2930

3031
#[macro_use]
3132
extern crate tracing;

compiler/rustc_driver/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#![feature(nll)]
99
#![feature(once_cell)]
1010
#![recursion_limit = "256"]
11+
#![cfg_attr(not(bootstrap), allow(rustc::potential_query_instability))]
1112

1213
#[macro_use]
1314
extern crate tracing;
@@ -845,7 +846,7 @@ Available lint options:
845846
let builtin = sort_lints(sess, builtin);
846847

847848
let (plugin_groups, builtin_groups): (Vec<_>, _) =
848-
lint_store.get_lint_groups().iter().cloned().partition(|&(.., p)| p);
849+
lint_store.get_lint_groups().partition(|&(.., p)| p);
849850
let plugin_groups = sort_lint_groups(plugin_groups);
850851
let builtin_groups = sort_lint_groups(builtin_groups);
851852

compiler/rustc_errors/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#![feature(if_let_guard)]
99
#![feature(let_else)]
1010
#![feature(nll)]
11+
#![cfg_attr(not(bootstrap), allow(rustc::potential_query_instability))]
1112

1213
#[macro_use]
1314
extern crate rustc_macros;

compiler/rustc_expand/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#![feature(proc_macro_span)]
1010
#![feature(try_blocks)]
1111
#![recursion_limit = "256"]
12+
#![cfg_attr(not(bootstrap), allow(rustc::potential_query_instability))]
1213

1314
#[macro_use]
1415
extern crate rustc_macros;

compiler/rustc_feature/src/builtin_attrs.rs

+3
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,9 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
581581
rustc_attr!(
582582
rustc_trivial_field_reads, Normal, template!(Word), WarnFollowing, INTERNAL_UNSTABLE
583583
),
584+
// Used by the `rustc::potential_query_instability` lint to warn methods which
585+
// might not be stable during incremental compilation.
586+
rustc_attr!(rustc_lint_query_instability, Normal, template!(Word), WarnFollowing, INTERNAL_UNSTABLE),
584587

585588
// ==========================================================================
586589
// Internal attributes, Const related:

compiler/rustc_incremental/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#![feature(let_else)]
66
#![feature(nll)]
77
#![recursion_limit = "256"]
8+
#![cfg_attr(not(bootstrap), allow(rustc::potential_query_instability))]
89

910
#[macro_use]
1011
extern crate rustc_middle;

compiler/rustc_index/src/bit_set.rs

+6
Original file line numberDiff line numberDiff line change
@@ -938,6 +938,12 @@ pub struct GrowableBitSet<T: Idx> {
938938
bit_set: BitSet<T>,
939939
}
940940

941+
impl<T: Idx> Default for GrowableBitSet<T> {
942+
fn default() -> Self {
943+
GrowableBitSet::new_empty()
944+
}
945+
}
946+
941947
impl<T: Idx> GrowableBitSet<T> {
942948
/// Ensure that the set can hold at least `min_domain_size` elements.
943949
pub fn ensure(&mut self, min_domain_size: usize) {

compiler/rustc_infer/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#![feature(min_specialization)]
2424
#![feature(label_break_value)]
2525
#![recursion_limit = "512"] // For rustdoc
26+
#![cfg_attr(not(bootstrap), allow(rustc::potential_query_instability))]
2627

2728
#[macro_use]
2829
extern crate rustc_macros;

compiler/rustc_interface/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#![feature(nll)]
77
#![feature(once_cell)]
88
#![recursion_limit = "256"]
9+
#![cfg_attr(not(bootstrap), allow(rustc::potential_query_instability))]
910

1011
mod callbacks;
1112
pub mod interface;

compiler/rustc_lint/src/builtin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2833,7 +2833,7 @@ impl ClashingExternDeclarations {
28332833
return true;
28342834
}
28352835
let tcx = cx.tcx;
2836-
if a == b || rustc_middle::ty::TyS::same_type(a, b) {
2836+
if a == b {
28372837
// All nominally-same types are structurally same, too.
28382838
true
28392839
} else {

compiler/rustc_lint/src/context.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,11 @@ impl LintStore {
143143
&self.lints
144144
}
145145

146-
pub fn get_lint_groups<'t>(&'t self) -> Vec<(&'static str, Vec<LintId>, bool)> {
146+
pub fn get_lint_groups<'t>(
147+
&'t self,
148+
) -> impl Iterator<Item = (&'static str, Vec<LintId>, bool)> + 't {
149+
// This function is not used in a way which observes the order of lints.
150+
#[cfg_attr(not(bootstrap), allow(rustc::potential_query_instability))]
147151
self.lint_groups
148152
.iter()
149153
.filter(|(_, LintGroup { depr, .. })| {
@@ -153,7 +157,6 @@ impl LintStore {
153157
.map(|(k, LintGroup { lint_ids, from_plugin, .. })| {
154158
(*k, lint_ids.clone(), *from_plugin)
155159
})
156-
.collect()
157160
}
158161

159162
pub fn register_early_pass(

compiler/rustc_lint/src/internal.rs

+59-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ use crate::{EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintContext}
55
use rustc_ast as ast;
66
use rustc_errors::Applicability;
77
use rustc_hir::def::Res;
8-
use rustc_hir::{GenericArg, HirId, Item, ItemKind, Node, Path, PathSegment, QPath, Ty, TyKind};
8+
use rustc_hir::{Expr, ExprKind, GenericArg, Path, PathSegment, QPath};
9+
use rustc_hir::{HirId, Item, ItemKind, Node, Ty, TyKind};
910
use rustc_middle::ty;
1011
use rustc_session::{declare_lint_pass, declare_tool_lint};
1112
use rustc_span::hygiene::{ExpnKind, MacroKind};
@@ -48,6 +49,63 @@ impl LateLintPass<'_> for DefaultHashTypes {
4849
}
4950
}
5051

52+
declare_tool_lint! {
53+
pub rustc::POTENTIAL_QUERY_INSTABILITY,
54+
Allow,
55+
"require explicit opt-in when using potentially unstable methods or functions",
56+
report_in_external_macro: true
57+
}
58+
59+
declare_lint_pass!(QueryStability => [POTENTIAL_QUERY_INSTABILITY]);
60+
61+
impl LateLintPass<'_> for QueryStability {
62+
fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) {
63+
// FIXME(rustdoc): This lint uses typecheck results, causing rustdoc to
64+
// error if there are resolution failures.
65+
//
66+
// As internal lints are currently always run if there are `unstable_options`,
67+
// they are added to the lint store of rustdoc. Internal lints are also
68+
// not used via the `lint_mod` query. Crate lints run outside of a query
69+
// so rustdoc currently doesn't disable them.
70+
//
71+
// Instead of relying on this, either change crate lints to a query disabled by
72+
// rustdoc, only run internal lints if the user is explicitly opting in
73+
// or figure out a different way to avoid running lints for rustdoc.
74+
if cx.tcx.sess.opts.actually_rustdoc {
75+
return;
76+
}
77+
78+
let (span, def_id, substs) = match expr.kind {
79+
ExprKind::MethodCall(segment, _, _)
80+
if let Some(def_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id) =>
81+
{
82+
(segment.ident.span, def_id, cx.typeck_results().node_substs(expr.hir_id))
83+
},
84+
_ => {
85+
let &ty::FnDef(def_id, substs) =
86+
cx.typeck_results()
87+
.node_type(expr.hir_id)
88+
.kind() else { return };
89+
(expr.span, def_id, substs)
90+
}
91+
};
92+
if let Ok(Some(instance)) = ty::Instance::resolve(cx.tcx, cx.param_env, def_id, substs) {
93+
let def_id = instance.def_id();
94+
if cx.tcx.has_attr(def_id, sym::rustc_lint_query_instability) {
95+
cx.struct_span_lint(POTENTIAL_QUERY_INSTABILITY, span, |lint| {
96+
let msg = format!(
97+
"using `{}` can result in unstable query results",
98+
cx.tcx.item_name(def_id)
99+
);
100+
lint.build(&msg)
101+
.note("if you believe this case to be fine, allow this lint and add a comment explaining your rationale")
102+
.emit();
103+
})
104+
}
105+
}
106+
}
107+
}
108+
51109
declare_tool_lint! {
52110
pub rustc::USAGE_OF_TY_TYKIND,
53111
Allow,

compiler/rustc_lint/src/lib.rs

+5
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,14 @@
3030
#![feature(bool_to_option)]
3131
#![feature(box_patterns)]
3232
#![feature(crate_visibility_modifier)]
33+
#![feature(if_let_guard)]
3334
#![feature(iter_order_by)]
3435
#![feature(let_else)]
3536
#![feature(never_type)]
3637
#![feature(nll)]
3738
#![feature(control_flow_enum)]
3839
#![recursion_limit = "256"]
40+
#![cfg_attr(not(bootstrap), allow(rustc::potential_query_instability))]
3941

4042
#[macro_use]
4143
extern crate rustc_middle;
@@ -493,6 +495,8 @@ fn register_internals(store: &mut LintStore) {
493495
store.register_early_pass(|| Box::new(LintPassImpl));
494496
store.register_lints(&DefaultHashTypes::get_lints());
495497
store.register_late_pass(|| Box::new(DefaultHashTypes));
498+
store.register_lints(&QueryStability::get_lints());
499+
store.register_late_pass(|| Box::new(QueryStability));
496500
store.register_lints(&ExistingDocKeyword::get_lints());
497501
store.register_late_pass(|| Box::new(ExistingDocKeyword));
498502
store.register_lints(&TyTyKind::get_lints());
@@ -505,6 +509,7 @@ fn register_internals(store: &mut LintStore) {
505509
None,
506510
vec![
507511
LintId::of(DEFAULT_HASH_TYPES),
512+
LintId::of(POTENTIAL_QUERY_INSTABILITY),
508513
LintId::of(USAGE_OF_TY_TYKIND),
509514
LintId::of(PASS_BY_VALUE),
510515
LintId::of(LINT_PASS_IMPL_WITHOUT_MACRO),

compiler/rustc_lint_defs/src/builtin.rs

+43
Original file line numberDiff line numberDiff line change
@@ -1793,6 +1793,10 @@ declare_lint! {
17931793
Warn,
17941794
"detects name collision with an existing but unstable method",
17951795
@future_incompatible = FutureIncompatibleInfo {
1796+
reason: FutureIncompatibilityReason::Custom(
1797+
"once this associated item is added to the standard library, \
1798+
the ambiguity may cause an error or change in behavior!"
1799+
),
17961800
reference: "issue #48919 <https://github.com/rust-lang/rust/issues/48919>",
17971801
// Note: this item represents future incompatibility of all unstable functions in the
17981802
// standard library, and thus should never be removed or changed to an error.
@@ -2335,6 +2339,10 @@ declare_lint! {
23352339
Warn,
23362340
"reservation of a two-phased borrow conflicts with other shared borrows",
23372341
@future_incompatible = FutureIncompatibleInfo {
2342+
reason: FutureIncompatibilityReason::Custom(
2343+
"this borrowing pattern was not meant to be accepted, \
2344+
and may become a hard error in the future"
2345+
),
23382346
reference: "issue #59159 <https://github.com/rust-lang/rust/issues/59159>",
23392347
};
23402348
}
@@ -3046,6 +3054,7 @@ declare_lint_pass! {
30463054
DEREF_INTO_DYN_SUPERTRAIT,
30473055
DEPRECATED_CFG_ATTR_CRATE_TYPE_NAME,
30483056
DUPLICATE_MACRO_ATTRIBUTES,
3057+
SUSPICIOUS_AUTO_TRAIT_IMPLS,
30493058
]
30503059
}
30513060

@@ -3622,3 +3631,37 @@ declare_lint! {
36223631
Warn,
36233632
"duplicated attribute"
36243633
}
3634+
3635+
declare_lint! {
3636+
/// The `suspicious_auto_trait_impls` lint checks for potentially incorrect
3637+
/// implementations of auto traits.
3638+
///
3639+
/// ### Example
3640+
///
3641+
/// ```rust
3642+
/// struct Foo<T>(T);
3643+
///
3644+
/// unsafe impl<T> Send for Foo<*const T> {}
3645+
/// ```
3646+
///
3647+
/// {{produces}}
3648+
///
3649+
/// ### Explanation
3650+
///
3651+
/// A type can implement auto traits, e.g. `Send`, `Sync` and `Unpin`,
3652+
/// in two different ways: either by writing an explicit impl or if
3653+
/// all fields of the type implement that auto trait.
3654+
///
3655+
/// The compiler disables the automatic implementation if an explicit one
3656+
/// exists for given type constructor. The exact rules governing this
3657+
/// are currently unsound and quite subtle and and will be modified in the future.
3658+
/// This change will cause the automatic implementation to be disabled in more
3659+
/// cases, potentially breaking some code.
3660+
pub SUSPICIOUS_AUTO_TRAIT_IMPLS,
3661+
Warn,
3662+
"the rules governing auto traits will change in the future",
3663+
@future_incompatible = FutureIncompatibleInfo {
3664+
reason: FutureIncompatibilityReason::FutureReleaseSemanticsChange,
3665+
reference: "issue #93367 <https://github.com/rust-lang/rust/issues/93367>",
3666+
};
3667+
}

compiler/rustc_lint_defs/src/lib.rs

+5
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,17 @@ pub enum FutureIncompatibilityReason {
163163
/// This will be an error in a future release, and
164164
/// Cargo should create a report even for dependencies
165165
FutureReleaseErrorReportNow,
166+
/// Code that changes meaning in some way in a
167+
/// future release.
168+
FutureReleaseSemanticsChange,
166169
/// Previously accepted code that will become an
167170
/// error in the provided edition
168171
EditionError(Edition),
169172
/// Code that changes meaning in some way in
170173
/// the provided edition
171174
EditionSemanticsChange(Edition),
175+
/// A custom reason.
176+
Custom(&'static str),
172177
}
173178

174179
impl FutureIncompatibilityReason {

compiler/rustc_metadata/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#![feature(try_blocks)]
1010
#![feature(never_type)]
1111
#![recursion_limit = "256"]
12+
#![cfg_attr(not(bootstrap), allow(rustc::potential_query_instability))]
1213

1314
extern crate proc_macro;
1415

compiler/rustc_middle/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
#![feature(nonzero_ops)]
5757
#![feature(unwrap_infallible)]
5858
#![recursion_limit = "512"]
59+
#![cfg_attr(not(bootstrap), allow(rustc::potential_query_instability))]
5960

6061
#[macro_use]
6162
extern crate bitflags;

0 commit comments

Comments
 (0)