Skip to content

Commit 8572e48

Browse files
committed
Auto merge of #147326 - Zalathar:rollup-w696bpq, r=Zalathar
Rollup of 14 pull requests Successful merges: - #142670 (Document fully-qualified syntax in `as`' keyword doc) - #145685 (add CloneFromCell and Cell::get_cloned) - #146330 (Bump unicode_data and printables to version 17.0.0) - #146451 (Fix atan2 inaccuracy in documentation) - #146479 (add mem::conjure_zst) - #146874 (compiler: Hint at multiple crate versions if trait impl is for wrong ADT ) - #147117 (interpret `#[used]` as `#[used(compiler)]` on illumos) - #147190 (std: `sys::net` cleanups) - #147251 (Do not assert that a change in global cache only happens when concurrent) - #147280 (Return to needs-llvm-components being info-only) - #147288 (compiletest: Make `DirectiveLine` responsible for name/value splitting) - #147309 (Add documentation about unwinding to wasm targets) - #147315 (bless autodiff batching test) - #147323 (Fix top level ui tests check in tidy) r? `@ghost` `@rustbot` modify labels: rollup
2 parents a0f398e + ee8b684 commit 8572e48

File tree

54 files changed

+1585
-924
lines changed

Some content is hidden

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

54 files changed

+1585
-924
lines changed

compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,7 @@ impl<S: Stage> NoArgsAttributeParser<S> for NoMangleParser {
370370
pub(crate) struct UsedParser {
371371
first_compiler: Option<Span>,
372372
first_linker: Option<Span>,
373+
first_default: Option<Span>,
373374
}
374375

375376
// A custom `AttributeParser` is used rather than a Simple attribute parser because
@@ -382,7 +383,7 @@ impl<S: Stage> AttributeParser<S> for UsedParser {
382383
template!(Word, List: &["compiler", "linker"]),
383384
|group: &mut Self, cx, args| {
384385
let used_by = match args {
385-
ArgParser::NoArgs => UsedBy::Linker,
386+
ArgParser::NoArgs => UsedBy::Default,
386387
ArgParser::List(list) => {
387388
let Some(l) = list.single() else {
388389
cx.expected_single_argument(list.span);
@@ -423,12 +424,29 @@ impl<S: Stage> AttributeParser<S> for UsedParser {
423424
ArgParser::NameValue(_) => return,
424425
};
425426

427+
let attr_span = cx.attr_span;
428+
429+
// `#[used]` is interpreted as `#[used(linker)]` (though depending on target OS the
430+
// circumstances are more complicated). While we're checking `used_by`, also report
431+
// these cross-`UsedBy` duplicates to warn.
426432
let target = match used_by {
427433
UsedBy::Compiler => &mut group.first_compiler,
428-
UsedBy::Linker => &mut group.first_linker,
434+
UsedBy::Linker => {
435+
if let Some(prev) = group.first_default {
436+
cx.warn_unused_duplicate(prev, attr_span);
437+
return;
438+
}
439+
&mut group.first_linker
440+
}
441+
UsedBy::Default => {
442+
if let Some(prev) = group.first_linker {
443+
cx.warn_unused_duplicate(prev, attr_span);
444+
return;
445+
}
446+
&mut group.first_default
447+
}
429448
};
430449

431-
let attr_span = cx.attr_span;
432450
if let Some(prev) = *target {
433451
cx.warn_unused_duplicate(prev, attr_span);
434452
} else {
@@ -440,11 +458,13 @@ impl<S: Stage> AttributeParser<S> for UsedParser {
440458
AllowedTargets::AllowList(&[Allow(Target::Static), Warn(Target::MacroCall)]);
441459

442460
fn finalize(self, _cx: &FinalizeContext<'_, '_, S>) -> Option<AttributeKind> {
443-
// Ratcheting behaviour, if both `linker` and `compiler` are specified, use `linker`
444-
Some(match (self.first_compiler, self.first_linker) {
445-
(_, Some(span)) => AttributeKind::Used { used_by: UsedBy::Linker, span },
446-
(Some(span), _) => AttributeKind::Used { used_by: UsedBy::Compiler, span },
447-
(None, None) => return None,
461+
// If a specific form of `used` is specified, it takes precedence over generic `#[used]`.
462+
// If both `linker` and `compiler` are specified, use `linker`.
463+
Some(match (self.first_compiler, self.first_linker, self.first_default) {
464+
(_, Some(span), _) => AttributeKind::Used { used_by: UsedBy::Linker, span },
465+
(Some(span), _, _) => AttributeKind::Used { used_by: UsedBy::Compiler, span },
466+
(_, _, Some(span)) => AttributeKind::Used { used_by: UsedBy::Default, span },
467+
(None, None, None) => return None,
448468
})
449469
}
450470
}

compiler/rustc_codegen_ssa/src/codegen_attrs.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,19 @@ fn process_builtin_attrs(
263263
AttributeKind::Used { used_by, .. } => match used_by {
264264
UsedBy::Compiler => codegen_fn_attrs.flags |= CodegenFnAttrFlags::USED_COMPILER,
265265
UsedBy::Linker => codegen_fn_attrs.flags |= CodegenFnAttrFlags::USED_LINKER,
266+
UsedBy::Default => {
267+
let used_form = if tcx.sess.target.os == "illumos" {
268+
// illumos' `ld` doesn't support a section header that would represent
269+
// `#[used(linker)]`, see
270+
// https://github.com/rust-lang/rust/issues/146169. For that target,
271+
// downgrade as if `#[used(compiler)]` was requested and hope for the
272+
// best.
273+
CodegenFnAttrFlags::USED_COMPILER
274+
} else {
275+
CodegenFnAttrFlags::USED_LINKER
276+
};
277+
codegen_fn_attrs.flags |= used_form;
278+
}
266279
},
267280
AttributeKind::FfiConst(_) => {
268281
codegen_fn_attrs.flags |= CodegenFnAttrFlags::FFI_CONST

compiler/rustc_hir/src/attrs/data_structures.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,13 @@ impl Deprecation {
146146
}
147147

148148
/// There are three valid forms of the attribute:
149-
/// `#[used]`, which is semantically equivalent to `#[used(linker)]` except that the latter is currently unstable.
149+
/// `#[used]`, which is equivalent to `#[used(linker)]` on targets that support it, but `#[used(compiler)]` if not.
150150
/// `#[used(compiler)]`
151151
/// `#[used(linker)]`
152152
#[derive(Encodable, Decodable, Copy, Clone, Debug, PartialEq, Eq, Hash)]
153153
#[derive(HashStable_Generic, PrintAttribute)]
154154
pub enum UsedBy {
155+
Default,
155156
Compiler,
156157
Linker,
157158
}

compiler/rustc_middle/src/ty/context.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,9 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
207207
from_entry(entry)
208208
}
209209

210-
fn evaluation_is_concurrent(&self) -> bool {
211-
self.sess.threads() > 1
210+
fn assert_evaluation_is_concurrent(&self) {
211+
// Turns out, the assumption for this function isn't perfect.
212+
// See trait-system-refactor-initiative#234.
212213
}
213214

214215
fn expand_abstract_consts<T: TypeFoldable<TyCtxt<'tcx>>>(self, t: T) -> T {

compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs

Lines changed: 79 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,8 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
467467
span,
468468
leaf_trait_predicate,
469469
);
470-
self.note_version_mismatch(&mut err, leaf_trait_predicate);
470+
self.note_trait_version_mismatch(&mut err, leaf_trait_predicate);
471+
self.note_adt_version_mismatch(&mut err, leaf_trait_predicate);
471472
self.suggest_remove_await(&obligation, &mut err);
472473
self.suggest_derive(&obligation, &mut err, leaf_trait_predicate);
473474

@@ -2424,7 +2425,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
24242425
/// If the `Self` type of the unsatisfied trait `trait_ref` implements a trait
24252426
/// with the same path as `trait_ref`, a help message about
24262427
/// a probable version mismatch is added to `err`
2427-
fn note_version_mismatch(
2428+
fn note_trait_version_mismatch(
24282429
&self,
24292430
err: &mut Diag<'_>,
24302431
trait_pred: ty::PolyTraitPredicate<'tcx>,
@@ -2464,15 +2465,87 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
24642465
impl_spans,
24652466
format!("trait impl{} with same name found", pluralize!(trait_impls.len())),
24662467
);
2467-
let trait_crate = self.tcx.crate_name(trait_with_same_path.krate);
2468-
let crate_msg =
2469-
format!("perhaps two different versions of crate `{trait_crate}` are being used?");
2470-
err.note(crate_msg);
2468+
self.note_two_crate_versions(trait_with_same_path, err);
24712469
suggested = true;
24722470
}
24732471
suggested
24742472
}
24752473

2474+
fn note_two_crate_versions(&self, did: DefId, err: &mut Diag<'_>) {
2475+
let crate_name = self.tcx.crate_name(did.krate);
2476+
let crate_msg =
2477+
format!("perhaps two different versions of crate `{crate_name}` are being used?");
2478+
err.note(crate_msg);
2479+
}
2480+
2481+
fn note_adt_version_mismatch(
2482+
&self,
2483+
err: &mut Diag<'_>,
2484+
trait_pred: ty::PolyTraitPredicate<'tcx>,
2485+
) {
2486+
let ty::Adt(impl_self_def, _) = trait_pred.self_ty().skip_binder().peel_refs().kind()
2487+
else {
2488+
return;
2489+
};
2490+
2491+
let impl_self_did = impl_self_def.did();
2492+
2493+
// We only want to warn about different versions of a dependency.
2494+
// If no dependency is involved, bail.
2495+
if impl_self_did.krate == LOCAL_CRATE {
2496+
return;
2497+
}
2498+
2499+
let impl_self_path = self.comparable_path(impl_self_did);
2500+
let impl_self_crate_name = self.tcx.crate_name(impl_self_did.krate);
2501+
let similar_items: UnordSet<_> = self
2502+
.tcx
2503+
.visible_parent_map(())
2504+
.items()
2505+
.filter_map(|(&item, _)| {
2506+
// If we found ourselves, ignore.
2507+
if impl_self_did == item {
2508+
return None;
2509+
}
2510+
// We only want to warn about different versions of a dependency.
2511+
// Ignore items from our own crate.
2512+
if item.krate == LOCAL_CRATE {
2513+
return None;
2514+
}
2515+
// We want to warn about different versions of a dependency.
2516+
// So make sure the crate names are the same.
2517+
if impl_self_crate_name != self.tcx.crate_name(item.krate) {
2518+
return None;
2519+
}
2520+
// Filter out e.g. constructors that often have the same path
2521+
// str as the relevant ADT.
2522+
if !self.tcx.def_kind(item).is_adt() {
2523+
return None;
2524+
}
2525+
let path = self.comparable_path(item);
2526+
// We don't know if our item or the one we found is the re-exported one.
2527+
// Check both cases.
2528+
let is_similar = path.ends_with(&impl_self_path) || impl_self_path.ends_with(&path);
2529+
is_similar.then_some((item, path))
2530+
})
2531+
.collect();
2532+
2533+
let mut similar_items =
2534+
similar_items.into_items().into_sorted_stable_ord_by_key(|(_, path)| path);
2535+
similar_items.dedup();
2536+
2537+
for (similar_item, _) in similar_items {
2538+
err.span_help(self.tcx.def_span(similar_item), "item with same name found");
2539+
self.note_two_crate_versions(similar_item, err);
2540+
}
2541+
}
2542+
2543+
/// Add a `::` prefix when comparing paths so that paths with just one item
2544+
/// like "Foo" does not equal the end of "OtherFoo".
2545+
fn comparable_path(&self, did: DefId) -> String {
2546+
format!("::{}", self.tcx.def_path_str(did))
2547+
}
2548+
24762549
/// Creates a `PredicateObligation` with `new_self_ty` replacing the existing type in the
24772550
/// `trait_ref`.
24782551
///

compiler/rustc_type_ir/src/interner.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,9 @@ pub trait Interner:
183183
from_entry: impl FnOnce(&CanonicalParamEnvCacheEntry<Self>) -> R,
184184
) -> R;
185185

186-
fn evaluation_is_concurrent(&self) -> bool;
186+
/// Useful for testing. If a cache entry is replaced, this should
187+
/// (in theory) only happen when concurrent.
188+
fn assert_evaluation_is_concurrent(&self);
187189

188190
fn expand_abstract_consts<T: TypeFoldable<Self>>(self, t: T) -> T;
189191

@@ -567,7 +569,7 @@ impl<I: Interner> search_graph::Cx for I {
567569
fn with_global_cache<R>(self, f: impl FnOnce(&mut search_graph::GlobalCache<Self>) -> R) -> R {
568570
I::with_global_cache(self, f)
569571
}
570-
fn evaluation_is_concurrent(&self) -> bool {
571-
self.evaluation_is_concurrent()
572+
fn assert_evaluation_is_concurrent(&self) {
573+
self.assert_evaluation_is_concurrent()
572574
}
573575
}

compiler/rustc_type_ir/src/search_graph/global_cache.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@ impl<X: Cx> GlobalCache<X> {
5656
let with_overflow = WithOverflow { nested_goals, result };
5757
let prev = entry.with_overflow.insert(required_depth, with_overflow);
5858
if let Some(prev) = &prev {
59-
assert!(cx.evaluation_is_concurrent());
59+
cx.assert_evaluation_is_concurrent();
6060
assert_eq!(cx.get_tracked(&prev.result), evaluation_result.result);
6161
}
6262
} else {
6363
let prev = entry.success.replace(Success { required_depth, nested_goals, result });
6464
if let Some(prev) = &prev {
65-
assert!(cx.evaluation_is_concurrent());
65+
cx.assert_evaluation_is_concurrent();
6666
assert_eq!(cx.get_tracked(&prev.result), evaluation_result.result);
6767
}
6868
}

compiler/rustc_type_ir/src/search_graph/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub trait Cx: Copy {
5353

5454
fn with_global_cache<R>(self, f: impl FnOnce(&mut GlobalCache<Self>) -> R) -> R;
5555

56-
fn evaluation_is_concurrent(&self) -> bool;
56+
fn assert_evaluation_is_concurrent(&self);
5757
}
5858

5959
pub trait Delegate: Sized {

library/alloc/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@
9696
#![feature(bstr)]
9797
#![feature(bstr_internals)]
9898
#![feature(cast_maybe_uninit)]
99+
#![feature(cell_get_cloned)]
99100
#![feature(char_internals)]
100101
#![feature(char_max_len)]
101102
#![feature(clone_to_uninit)]

library/alloc/src/rc.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@
242242
#![stable(feature = "rust1", since = "1.0.0")]
243243

244244
use core::any::Any;
245-
use core::cell::Cell;
245+
use core::cell::{Cell, CloneFromCell};
246246
#[cfg(not(no_global_oom_handling))]
247247
use core::clone::CloneToUninit;
248248
use core::clone::UseCloned;
@@ -340,6 +340,10 @@ impl<T: ?Sized + Unsize<U>, U: ?Sized, A: Allocator> CoerceUnsized<Rc<U, A>> for
340340
#[unstable(feature = "dispatch_from_dyn", issue = "none")]
341341
impl<T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<Rc<U>> for Rc<T> {}
342342

343+
// SAFETY: `Rc::clone` doesn't access any `Cell`s which could contain the `Rc` being cloned.
344+
#[unstable(feature = "cell_get_cloned", issue = "145329")]
345+
unsafe impl<T: ?Sized> CloneFromCell for Rc<T> {}
346+
343347
impl<T: ?Sized> Rc<T> {
344348
#[inline]
345349
unsafe fn from_inner(ptr: NonNull<RcInner<T>>) -> Self {
@@ -3013,6 +3017,10 @@ impl<T: ?Sized + Unsize<U>, U: ?Sized, A: Allocator> CoerceUnsized<Weak<U, A>> f
30133017
#[unstable(feature = "dispatch_from_dyn", issue = "none")]
30143018
impl<T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<Weak<U>> for Weak<T> {}
30153019

3020+
// SAFETY: `Weak::clone` doesn't access any `Cell`s which could contain the `Weak` being cloned.
3021+
#[unstable(feature = "cell_get_cloned", issue = "145329")]
3022+
unsafe impl<T: ?Sized> CloneFromCell for Weak<T> {}
3023+
30163024
impl<T> Weak<T> {
30173025
/// Constructs a new `Weak<T>`, without allocating any memory.
30183026
/// Calling [`upgrade`] on the return value always gives [`None`].

0 commit comments

Comments
 (0)