Skip to content

Commit 5641481

Browse files
committed
Auto merge of rust-lang#89629 - GuillaumeGomez:rollup-s4r8me6, r=GuillaumeGomez
Rollup of 7 pull requests Successful merges: - rust-lang#89298 (Issue 89193 - Fix ICE when using `usize` and `isize` with SIMD gathers ) - rust-lang#89461 (Add `deref_into_dyn_supertrait` lint.) - rust-lang#89477 (Move items related to computing diffs to a separate file) - rust-lang#89559 (RustWrapper: adapt for LLVM API change) - rust-lang#89585 (Emit item no type error even if type inference fails) - rust-lang#89596 (Make cfg imply doc(cfg)) - rust-lang#89615 (Add InferCtxt::with_opaque_type_inference to get_body_with_borrowck_facts) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 0157cc9 + 0fbb011 commit 5641481

Some content is hidden

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

45 files changed

+730
-193
lines changed

Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -4454,6 +4454,7 @@ dependencies = [
44544454
"rustc_hir",
44554455
"rustc_index",
44564456
"rustc_infer",
4457+
"rustc_lint_defs",
44574458
"rustc_macros",
44584459
"rustc_middle",
44594460
"rustc_parse_format",

compiler/rustc_ast_passes/src/feature_gate.rs

+1
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
279279

280280
gate_doc!(
281281
cfg => doc_cfg
282+
cfg_hide => doc_cfg_hide
282283
masked => doc_masked
283284
notable_trait => doc_notable_trait
284285
keyword => doc_keyword

compiler/rustc_borrowck/src/consumers.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub fn get_body_with_borrowck_facts<'tcx>(
3131
def: ty::WithOptConstParam<LocalDefId>,
3232
) -> BodyWithBorrowckFacts<'tcx> {
3333
let (input_body, promoted) = tcx.mir_promoted(def);
34-
tcx.infer_ctxt().enter(|infcx| {
34+
tcx.infer_ctxt().with_opaque_type_inference(def.did).enter(|infcx| {
3535
let input_body: &Body<'_> = &input_body.borrow();
3636
let promoted: &IndexVec<_, _> = &promoted.borrow();
3737
*super::do_mir_borrowck(&infcx, input_body, promoted, true).1.unwrap()

compiler/rustc_codegen_llvm/src/intrinsic.rs

+25-8
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use rustc_middle::ty::{self, Ty};
2020
use rustc_middle::{bug, span_bug};
2121
use rustc_span::{sym, symbol::kw, Span, Symbol};
2222
use rustc_target::abi::{self, HasDataLayout, Primitive};
23-
use rustc_target::spec::PanicStrategy;
23+
use rustc_target::spec::{HasTargetSpec, PanicStrategy};
2424

2525
use std::cmp::Ordering;
2626
use std::iter;
@@ -1190,11 +1190,28 @@ fn generic_simd_intrinsic(
11901190
// FIXME: use:
11911191
// https://github.com/llvm-mirror/llvm/blob/master/include/llvm/IR/Function.h#L182
11921192
// https://github.com/llvm-mirror/llvm/blob/master/include/llvm/IR/Intrinsics.h#L81
1193-
fn llvm_vector_str(elem_ty: Ty<'_>, vec_len: u64, no_pointers: usize) -> String {
1193+
fn llvm_vector_str(
1194+
elem_ty: Ty<'_>,
1195+
vec_len: u64,
1196+
no_pointers: usize,
1197+
bx: &Builder<'a, 'll, 'tcx>,
1198+
) -> String {
11941199
let p0s: String = "p0".repeat(no_pointers);
11951200
match *elem_ty.kind() {
1196-
ty::Int(v) => format!("v{}{}i{}", vec_len, p0s, v.bit_width().unwrap()),
1197-
ty::Uint(v) => format!("v{}{}i{}", vec_len, p0s, v.bit_width().unwrap()),
1201+
ty::Int(v) => format!(
1202+
"v{}{}i{}",
1203+
vec_len,
1204+
p0s,
1205+
// Normalize to prevent crash if v: IntTy::Isize
1206+
v.normalize(bx.target_spec().pointer_width).bit_width().unwrap()
1207+
),
1208+
ty::Uint(v) => format!(
1209+
"v{}{}i{}",
1210+
vec_len,
1211+
p0s,
1212+
// Normalize to prevent crash if v: UIntTy::Usize
1213+
v.normalize(bx.target_spec().pointer_width).bit_width().unwrap()
1214+
),
11981215
ty::Float(v) => format!("v{}{}f{}", vec_len, p0s, v.bit_width()),
11991216
_ => unreachable!(),
12001217
}
@@ -1330,11 +1347,11 @@ fn generic_simd_intrinsic(
13301347

13311348
// Type of the vector of pointers:
13321349
let llvm_pointer_vec_ty = llvm_vector_ty(bx, underlying_ty, in_len, pointer_count);
1333-
let llvm_pointer_vec_str = llvm_vector_str(underlying_ty, in_len, pointer_count);
1350+
let llvm_pointer_vec_str = llvm_vector_str(underlying_ty, in_len, pointer_count, bx);
13341351

13351352
// Type of the vector of elements:
13361353
let llvm_elem_vec_ty = llvm_vector_ty(bx, underlying_ty, in_len, pointer_count - 1);
1337-
let llvm_elem_vec_str = llvm_vector_str(underlying_ty, in_len, pointer_count - 1);
1354+
let llvm_elem_vec_str = llvm_vector_str(underlying_ty, in_len, pointer_count - 1, bx);
13381355

13391356
let llvm_intrinsic =
13401357
format!("llvm.masked.gather.{}.{}", llvm_elem_vec_str, llvm_pointer_vec_str);
@@ -1458,11 +1475,11 @@ fn generic_simd_intrinsic(
14581475

14591476
// Type of the vector of pointers:
14601477
let llvm_pointer_vec_ty = llvm_vector_ty(bx, underlying_ty, in_len, pointer_count);
1461-
let llvm_pointer_vec_str = llvm_vector_str(underlying_ty, in_len, pointer_count);
1478+
let llvm_pointer_vec_str = llvm_vector_str(underlying_ty, in_len, pointer_count, bx);
14621479

14631480
// Type of the vector of elements:
14641481
let llvm_elem_vec_ty = llvm_vector_ty(bx, underlying_ty, in_len, pointer_count - 1);
1465-
let llvm_elem_vec_str = llvm_vector_str(underlying_ty, in_len, pointer_count - 1);
1482+
let llvm_elem_vec_str = llvm_vector_str(underlying_ty, in_len, pointer_count - 1, bx);
14661483

14671484
let llvm_intrinsic =
14681485
format!("llvm.masked.scatter.{}.{}", llvm_elem_vec_str, llvm_pointer_vec_str);

compiler/rustc_feature/src/active.rs

+3
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,9 @@ declare_features! (
675675
/// Allows `#[track_caller]` on closures and generators.
676676
(active, closure_track_caller, "1.57.0", Some(87417), None),
677677

678+
/// Allows `#[doc(cfg_hide(...))]`.
679+
(active, doc_cfg_hide, "1.57.0", Some(43781), None),
680+
678681
// -------------------------------------------------------------------------
679682
// feature-group-end: actual feature gates
680683
// -------------------------------------------------------------------------

compiler/rustc_lint_defs/src/builtin.rs

+46
Original file line numberDiff line numberDiff line change
@@ -3051,6 +3051,7 @@ declare_lint_pass! {
30513051
BREAK_WITH_LABEL_AND_LOOP,
30523052
UNUSED_ATTRIBUTES,
30533053
NON_EXHAUSTIVE_OMITTED_PATTERNS,
3054+
DEREF_INTO_DYN_SUPERTRAIT,
30543055
]
30553056
}
30563057

@@ -3512,3 +3513,48 @@ declare_lint! {
35123513
Allow,
35133514
"detect when patterns of types marked `non_exhaustive` are missed",
35143515
}
3516+
3517+
declare_lint! {
3518+
/// The `deref_into_dyn_supertrait` lint is output whenever there is a use of the
3519+
/// `Deref` implementation with a `dyn SuperTrait` type as `Output`.
3520+
///
3521+
/// These implementations will become shadowed when the `trait_upcasting` feature is stablized.
3522+
/// The `deref` functions will no longer be called implicitly, so there might be behavior change.
3523+
///
3524+
/// ### Example
3525+
///
3526+
/// ```rust,compile_fail
3527+
/// #![deny(deref_into_dyn_supertrait)]
3528+
/// #![allow(dead_code)]
3529+
///
3530+
/// use core::ops::Deref;
3531+
///
3532+
/// trait A {}
3533+
/// trait B: A {}
3534+
/// impl<'a> Deref for dyn 'a + B {
3535+
/// type Target = dyn A;
3536+
/// fn deref(&self) -> &Self::Target {
3537+
/// todo!()
3538+
/// }
3539+
/// }
3540+
///
3541+
/// fn take_a(_: &dyn A) { }
3542+
///
3543+
/// fn take_b(b: &dyn B) {
3544+
/// take_a(b);
3545+
/// }
3546+
/// ```
3547+
///
3548+
/// {{produces}}
3549+
///
3550+
/// ### Explanation
3551+
///
3552+
/// The dyn upcasting coercion feature adds new coercion rules, taking priority
3553+
/// over certain other coercion rules, which will cause some behavior change.
3554+
pub DEREF_INTO_DYN_SUPERTRAIT,
3555+
Warn,
3556+
"`Deref` implementation usage with a supertrait trait object for output might be shadowed in the future",
3557+
@future_incompatible = FutureIncompatibleInfo {
3558+
reference: "issue #89460 <https://github.com/rust-lang/rust/issues/89460>",
3559+
};
3560+
}

compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,11 @@ static LLVM_THREAD_LOCAL char *LastError;
5454
//
5555
// Notably it exits the process with code 101, unlike LLVM's default of 1.
5656
static void FatalErrorHandler(void *UserData,
57+
#if LLVM_VERSION_LT(14, 0)
5758
const std::string& Reason,
59+
#else
60+
const char* Reason,
61+
#endif
5862
bool GenCrashDiag) {
5963
// Do the same thing that the default error handler does.
6064
std::cerr << "LLVM ERROR: " << Reason << std::endl;

compiler/rustc_passes/src/check_attr.rs

+1
Original file line numberDiff line numberDiff line change
@@ -938,6 +938,7 @@ impl CheckAttrVisitor<'tcx> {
938938
// plugins: removed, but rustdoc warns about it itself
939939
sym::alias
940940
| sym::cfg
941+
| sym::cfg_hide
941942
| sym::hidden
942943
| sym::html_favicon_url
943944
| sym::html_logo_url

compiler/rustc_span/src/symbol.rs

+2
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,7 @@ symbols! {
399399
cfg_attr_multi,
400400
cfg_doctest,
401401
cfg_eval,
402+
cfg_hide,
402403
cfg_panic,
403404
cfg_sanitize,
404405
cfg_target_abi,
@@ -547,6 +548,7 @@ symbols! {
547548
doc,
548549
doc_alias,
549550
doc_cfg,
551+
doc_cfg_hide,
550552
doc_keyword,
551553
doc_masked,
552554
doc_notable_trait,

compiler/rustc_trait_selection/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ rustc_errors = { path = "../rustc_errors" }
1717
rustc_hir = { path = "../rustc_hir" }
1818
rustc_index = { path = "../rustc_index" }
1919
rustc_infer = { path = "../rustc_infer" }
20+
rustc_lint_defs = { path = "../rustc_lint_defs" }
2021
rustc_macros = { path = "../rustc_macros" }
2122
rustc_query_system = { path = "../rustc_query_system" }
2223
rustc_session = { path = "../rustc_session" }

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

+79-1
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,17 @@
66
//!
77
//! [rustc dev guide]:https://rustc-dev-guide.rust-lang.org/traits/resolution.html#candidate-assembly
88
use rustc_hir as hir;
9+
use rustc_hir::def_id::DefId;
10+
use rustc_infer::traits::TraitEngine;
911
use rustc_infer::traits::{Obligation, SelectionError, TraitObligation};
12+
use rustc_lint_defs::builtin::DEREF_INTO_DYN_SUPERTRAIT;
1013
use rustc_middle::ty::print::with_no_trimmed_paths;
11-
use rustc_middle::ty::{self, Ty, TypeFoldable};
14+
use rustc_middle::ty::{self, ToPredicate, Ty, TypeFoldable, WithConstness};
1215
use rustc_target::spec::abi::Abi;
1316

17+
use crate::traits;
1418
use crate::traits::coherence::Conflict;
19+
use crate::traits::query::evaluate_obligation::InferCtxtExt;
1520
use crate::traits::{util, SelectionResult};
1621
use crate::traits::{Overflow, Unimplemented};
1722

@@ -672,6 +677,55 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
672677
})
673678
}
674679

680+
/// Temporary migration for #89190
681+
fn need_migrate_deref_output_trait_object(
682+
&mut self,
683+
ty: Ty<'tcx>,
684+
cause: &traits::ObligationCause<'tcx>,
685+
param_env: ty::ParamEnv<'tcx>,
686+
) -> Option<(Ty<'tcx>, DefId)> {
687+
let tcx = self.tcx();
688+
if tcx.features().trait_upcasting {
689+
return None;
690+
}
691+
692+
// <ty as Deref>
693+
let trait_ref = ty::TraitRef {
694+
def_id: tcx.lang_items().deref_trait()?,
695+
substs: tcx.mk_substs_trait(ty, &[]),
696+
};
697+
698+
let obligation = traits::Obligation::new(
699+
cause.clone(),
700+
param_env,
701+
ty::Binder::dummy(trait_ref).without_const().to_predicate(tcx),
702+
);
703+
if !self.infcx.predicate_may_hold(&obligation) {
704+
return None;
705+
}
706+
707+
let mut fulfillcx = traits::FulfillmentContext::new_in_snapshot();
708+
let normalized_ty = fulfillcx.normalize_projection_type(
709+
&self.infcx,
710+
param_env,
711+
ty::ProjectionTy {
712+
item_def_id: tcx.lang_items().deref_target()?,
713+
substs: trait_ref.substs,
714+
},
715+
cause.clone(),
716+
);
717+
718+
let data = if let ty::Dynamic(ref data, ..) = normalized_ty.kind() {
719+
data
720+
} else {
721+
return None;
722+
};
723+
724+
let def_id = data.principal_def_id()?;
725+
726+
return Some((normalized_ty, def_id));
727+
}
728+
675729
/// Searches for unsizing that might apply to `obligation`.
676730
fn assemble_candidates_for_unsizing(
677731
&mut self,
@@ -732,6 +786,30 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
732786
let principal_a = data_a.principal().unwrap();
733787
let target_trait_did = principal_def_id_b.unwrap();
734788
let source_trait_ref = principal_a.with_self_ty(self.tcx(), source);
789+
if let Some((deref_output_ty, deref_output_trait_did)) = self
790+
.need_migrate_deref_output_trait_object(
791+
source,
792+
&obligation.cause,
793+
obligation.param_env,
794+
)
795+
{
796+
if deref_output_trait_did == target_trait_did {
797+
self.tcx().struct_span_lint_hir(
798+
DEREF_INTO_DYN_SUPERTRAIT,
799+
obligation.cause.body_id,
800+
obligation.cause.span,
801+
|lint| {
802+
lint.build(&format!(
803+
"`{}` implements `Deref` with supertrait `{}` as output",
804+
source,
805+
deref_output_ty
806+
)).emit();
807+
},
808+
);
809+
return;
810+
}
811+
}
812+
735813
for (idx, upcast_trait_ref) in
736814
util::supertraits(self.tcx(), source_trait_ref).enumerate()
737815
{

compiler/rustc_typeck/src/collect/type_of.rs

+23-21
Original file line numberDiff line numberDiff line change
@@ -752,29 +752,31 @@ fn infer_placeholder_type<'a>(
752752
// us to improve in typeck so we do that now.
753753
match tcx.sess.diagnostic().steal_diagnostic(span, StashKey::ItemNoType) {
754754
Some(mut err) => {
755-
// The parser provided a sub-optimal `HasPlaceholders` suggestion for the type.
756-
// We are typeck and have the real type, so remove that and suggest the actual type.
757-
err.suggestions.clear();
758-
759-
// Suggesting unnameable types won't help.
760-
let mut mk_nameable = MakeNameable::new(tcx);
761-
let ty = mk_nameable.fold_ty(ty);
762-
let sugg_ty = if mk_nameable.success { Some(ty) } else { None };
763-
if let Some(sugg_ty) = sugg_ty {
764-
err.span_suggestion(
765-
span,
766-
&format!("provide a type for the {item}", item = kind),
767-
format!("{}: {}", item_ident, sugg_ty),
768-
Applicability::MachineApplicable,
769-
);
770-
} else {
771-
err.span_note(
772-
tcx.hir().body(body_id).value.span,
773-
&format!("however, the inferred type `{}` cannot be named", ty.to_string()),
774-
);
755+
if !ty.references_error() {
756+
// The parser provided a sub-optimal `HasPlaceholders` suggestion for the type.
757+
// We are typeck and have the real type, so remove that and suggest the actual type.
758+
err.suggestions.clear();
759+
760+
// Suggesting unnameable types won't help.
761+
let mut mk_nameable = MakeNameable::new(tcx);
762+
let ty = mk_nameable.fold_ty(ty);
763+
let sugg_ty = if mk_nameable.success { Some(ty) } else { None };
764+
if let Some(sugg_ty) = sugg_ty {
765+
err.span_suggestion(
766+
span,
767+
&format!("provide a type for the {item}", item = kind),
768+
format!("{}: {}", item_ident, sugg_ty),
769+
Applicability::MachineApplicable,
770+
);
771+
} else {
772+
err.span_note(
773+
tcx.hir().body(body_id).value.span,
774+
&format!("however, the inferred type `{}` cannot be named", ty.to_string()),
775+
);
776+
}
775777
}
776778

777-
err.emit_unless(ty.references_error());
779+
err.emit();
778780
}
779781
None => {
780782
let mut diag = bad_placeholder_type(tcx, vec![span], kind);

library/alloc/src/lib.rs

+6
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@
6767
issue_tracker_base_url = "https://github.com/rust-lang/rust/issues/",
6868
test(no_crate_inject, attr(allow(unused_variables), deny(warnings)))
6969
)]
70+
#![cfg_attr(
71+
not(bootstrap),
72+
doc(cfg_hide(not(test), not(any(test, bootstrap)), target_has_atomic = "ptr"))
73+
)]
7074
#![no_std]
7175
#![needs_allocator]
7276
#![warn(deprecated_in_future)]
@@ -146,6 +150,8 @@
146150
#![feature(associated_type_bounds)]
147151
#![feature(slice_group_by)]
148152
#![feature(decl_macro)]
153+
#![feature(doc_cfg)]
154+
#![cfg_attr(not(bootstrap), feature(doc_cfg_hide))]
149155
// Allow testing this library
150156

151157
#[cfg(test)]

0 commit comments

Comments
 (0)