Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 8 pull requests #136673

Closed
wants to merge 48 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
8b14227
add MSVC tuple providers
Walnut356 Jan 10, 2025
71b6d49
add MSVC slice providers
Walnut356 Jan 10, 2025
c425660
add msvc enum providers
Walnut356 Jan 11, 2025
009994a
organize lldb_commands
Walnut356 Jan 11, 2025
2b8ff75
add MSVC str providers
Walnut356 Jan 11, 2025
4f59533
add alternate inner type lookup for vec/string for missing template args
Walnut356 Jan 11, 2025
f725ad7
more robust tuple summary
Walnut356 Jan 11, 2025
0bf0817
More robust sequence formatter
Walnut356 Jan 11, 2025
a3adcd2
add alternate inner type lookup for hashmap/set when template args mi…
Walnut356 Jan 11, 2025
2be8812
tidy
Walnut356 Jan 11, 2025
e8c5e09
doc comment for get_template_args
Walnut356 Jan 12, 2025
0f12b8c
slots fix
Walnut356 Jan 19, 2025
77d36c7
Remove rustc-dev-guide
ehuss Jan 23, 2025
af8c33d
Update toolstate maintainers
ehuss Jan 23, 2025
724b885
pattern migration: move labels out of the suggestion struct
dianne Feb 3, 2025
bdc6c4d
reword pattern migration diagnostic to make sense in all editions
dianne Feb 3, 2025
bbe40ac
use more specific wording for subpatterns from macro expansions
dianne Feb 4, 2025
9202001
add tests for label formatting
dianne Feb 4, 2025
4331f55
highlight the whole problem subpattern when pointing out the default …
dianne Feb 4, 2025
203d310
experimentally label the spans for default binding modes
dianne Feb 4, 2025
a064e78
don't include trailing open parens in labels for reference patterns
dianne Feb 4, 2025
767f820
separate labels for default binding mode spans into their own notes
dianne Feb 5, 2025
a5cc4cb
reword default binding mode notes
dianne Feb 5, 2025
060cc37
peace of mind: remove a call to `Option::expect`
dianne Feb 5, 2025
b32a533
try to suggest eliding redundant binding modifiers
dianne Feb 5, 2025
8dcdb3e
peace of mind: be absolutely sure we don't try to emit a 0-part sugge…
dianne Feb 5, 2025
cac63ff
Only suggest unit for unit fallback when spans dont come from macro e…
compiler-errors Feb 5, 2025
eb9bba8
Walk into nested bodies when suggesting unit for unit fallback
compiler-errors Feb 5, 2025
f1e4d94
add more pattern migration tests
dianne Jan 31, 2025
d4914a7
replace one `.map_or(true, ...)` with `.is_none_or(...)`
WaffleLapkin Feb 6, 2025
3815ed6
Remove some unnecessary parens in `assert!` conditions
estebank Jan 23, 2025
da9a85a
stabilize `feature(trait_upcasting)`
WaffleLapkin Dec 16, 2024
a970a0d
change `deref_into_dyn_supertrait` lint wording
WaffleLapkin Dec 16, 2024
e9d5d11
remove `feature(trait_upcasting)` from tests and bless them
WaffleLapkin Dec 16, 2024
9e6d0b3
remove unstable book entry for `feature(trait_upcasting)`
WaffleLapkin Dec 16, 2024
3c94d3e
remove use of `feature(trait_upcasting)` from core tests
WaffleLapkin Dec 16, 2024
fd94542
remove use of `feature(trait_upcasting)` from miri
WaffleLapkin Dec 16, 2024
bc1d68e
adjust a comment
WaffleLapkin Jan 16, 2025
4915995
allow+update `deref_into_dyn_supertrait`
WaffleLapkin Feb 6, 2025
2a6b274
Remove dead code from rustc_codegen_llvm and the LLVM wrapper
dpaoliello Feb 6, 2025
fcd67f1
Rollup merge of #134367 - WaffleLapkin:trait_upcasting_as_a_treat, r=…
matthiaskrgr Feb 7, 2025
c77fdef
Rollup merge of #135354 - Walnut356:msvc_lldb, r=wesleywiser
matthiaskrgr Feb 7, 2025
5c7c10d
Rollup merge of #135940 - ehuss:toolstate-update, r=Mark-Simulacrum
matthiaskrgr Feb 7, 2025
f7e791a
Rollup merge of #135945 - estebank:useless-parens, r=compiler-errors
matthiaskrgr Feb 7, 2025
492711e
Rollup merge of #136577 - dianne:simple-pat-migration-simplification,…
matthiaskrgr Feb 7, 2025
303bc62
Rollup merge of #136598 - compiler-errors:unit-fallback, r=WaffleLapkin
matthiaskrgr Feb 7, 2025
85aec92
Rollup merge of #136653 - dpaoliello:cleanllvm1, r=Zalathar
matthiaskrgr Feb 7, 2025
9541ce1
Rollup merge of #136664 - WaffleLapkin:un-map_or-true, r=compiler-errors
matthiaskrgr Feb 7, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 0 additions & 29 deletions compiler/rustc_codegen_llvm/src/llvm/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,6 @@ pub enum LLVMRustResult {
Failure,
}

/// Translation of LLVM's MachineTypes enum, defined in llvm\include\llvm\BinaryFormat\COFF.h.
///
/// We include only architectures supported on Windows.
#[derive(Copy, Clone, PartialEq)]
#[repr(C)]
pub enum LLVMMachineType {
AMD64 = 0x8664,
I386 = 0x14c,
ARM64 = 0xaa64,
ARM64EC = 0xa641,
ARM = 0x01c0,
}

/// Must match the layout of `LLVMRustModuleFlagMergeBehavior`.
///
/// When merging modules (e.g. during LTO), their metadata flags are combined. Conflicts are
Expand Down Expand Up @@ -645,16 +632,6 @@ pub enum ThreadLocalMode {
LocalExec,
}

/// LLVMRustTailCallKind
#[derive(Copy, Clone)]
#[repr(C)]
pub enum TailCallKind {
None,
Tail,
MustTail,
NoTail,
}

/// LLVMRustChecksumKind
#[derive(Copy, Clone)]
#[repr(C)]
Expand Down Expand Up @@ -773,7 +750,6 @@ pub struct Builder<'a>(InvariantOpaque<'a>);
#[repr(C)]
pub struct PassManager<'a>(InvariantOpaque<'a>);
unsafe extern "C" {
pub type Pass;
pub type TargetMachine;
pub type Archive;
}
Expand All @@ -799,7 +775,6 @@ unsafe extern "C" {
}

pub type DiagnosticHandlerTy = unsafe extern "C" fn(&DiagnosticInfo, *mut c_void);
pub type InlineAsmDiagHandlerTy = unsafe extern "C" fn(&SMDiagnostic, *const c_void, c_uint);

pub mod debuginfo {
use std::ptr;
Expand Down Expand Up @@ -853,7 +828,6 @@ pub mod debuginfo {
pub type DIFile = DIScope;
pub type DILexicalBlock = DIScope;
pub type DISubprogram = DIScope;
pub type DINameSpace = DIScope;
pub type DIType = DIDescriptor;
pub type DIBasicType = DIType;
pub type DIDerivedType = DIType;
Expand Down Expand Up @@ -1809,7 +1783,6 @@ unsafe extern "C" {
Name: *const c_char,
NameLen: size_t,
) -> Option<&Value>;
pub fn LLVMRustSetTailCallKind(CallInst: &Value, TKC: TailCallKind);

// Operations on attributes
pub fn LLVMRustCreateAttrNoValue(C: &Context, attr: AttributeKind) -> &Attribute;
Expand Down Expand Up @@ -2586,8 +2559,6 @@ unsafe extern "C" {

pub fn LLVMRustGetElementTypeArgIndex(CallSite: &Value) -> i32;

pub fn LLVMRustIsBitcode(ptr: *const u8, len: usize) -> bool;

pub fn LLVMRustLLVMHasZlibCompressionForDebugSymbols() -> bool;

pub fn LLVMRustLLVMHasZstdCompressionForDebugSymbols() -> bool;
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_feature/src/accepted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,9 @@ declare_features! (
/// Allows `#[track_caller]` to be used which provides
/// accurate caller location reporting during panic (RFC 2091).
(accepted, track_caller, "1.46.0", Some(47809)),
/// Allows dyn upcasting trait objects via supertraits.
/// Dyn upcasting is casting, e.g., `dyn Foo -> dyn Bar` where `Foo: Bar`.
(accepted, trait_upcasting, "CURRENT_RUSTC_VERSION", Some(65991)),
/// Allows #[repr(transparent)] on univariant enums (RFC 2645).
(accepted, transparent_enums, "1.42.0", Some(60405)),
/// Allows indexing tuples.
Expand Down
3 changes: 0 additions & 3 deletions compiler/rustc_feature/src/unstable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -634,9 +634,6 @@ declare_features! (
(unstable, thread_local, "1.0.0", Some(29594)),
/// Allows defining `trait X = A + B;` alias items.
(unstable, trait_alias, "1.24.0", Some(41517)),
/// Allows dyn upcasting trait objects via supertraits.
/// Dyn upcasting is casting, e.g., `dyn Foo -> dyn Bar` where `Foo: Bar`.
(unstable, trait_upcasting, "1.56.0", Some(65991)),
/// Allows for transmuting between arrays with sizes that contain generic consts.
(unstable, transmute_generic_consts, "1.70.0", Some(109929)),
/// Allows #[repr(transparent)] on unions (RFC 2645).
Expand Down
23 changes: 0 additions & 23 deletions compiler/rustc_hir_typeck/src/coercion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,6 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
)];

let mut has_unsized_tuple_coercion = false;
let mut has_trait_upcasting_coercion = None;

// Keep resolving `CoerceUnsized` and `Unsize` predicates to avoid
// emitting a coercion in cases like `Foo<$1>` -> `Foo<$2>`, where
Expand Down Expand Up @@ -690,13 +689,6 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
// these here and emit a feature error if coercion doesn't fail
// due to another reason.
match impl_source {
traits::ImplSource::Builtin(
BuiltinImplSource::TraitUpcasting { .. },
_,
) => {
has_trait_upcasting_coercion =
Some((trait_pred.self_ty(), trait_pred.trait_ref.args.type_at(1)));
}
traits::ImplSource::Builtin(BuiltinImplSource::TupleUnsizing, _) => {
has_unsized_tuple_coercion = true;
}
Expand All @@ -707,21 +699,6 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
}
}

if let Some((sub, sup)) = has_trait_upcasting_coercion
&& !self.tcx().features().trait_upcasting()
{
// Renders better when we erase regions, since they're not really the point here.
let (sub, sup) = self.tcx.erase_regions((sub, sup));
let mut err = feature_err(
&self.tcx.sess,
sym::trait_upcasting,
self.cause.span,
format!("cannot cast `{sub}` to `{sup}`, trait upcasting coercion is experimental"),
);
err.note(format!("required when coercing `{source}` into `{target}`"));
err.emit();
}

if has_unsized_tuple_coercion && !self.tcx.features().unsized_tuple_coercion() {
feature_err(
&self.tcx.sess,
Expand Down
18 changes: 16 additions & 2 deletions compiler/rustc_hir_typeck/src/fallback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,7 @@ impl<'tcx> Visitor<'tcx> for AnnotateUnitFallbackVisitor<'_, 'tcx> {
if let Some(ty) = self.fcx.typeck_results.borrow().node_type_opt(inf_id)
&& let Some(vid) = self.fcx.root_vid(ty)
&& self.reachable_vids.contains(&vid)
&& inf_span.can_be_used_for_suggestions()
{
return ControlFlow::Break(errors::SuggestAnnotation::Unit(inf_span));
}
Expand All @@ -662,7 +663,7 @@ impl<'tcx> Visitor<'tcx> for AnnotateUnitFallbackVisitor<'_, 'tcx> {
&mut self,
qpath: &'tcx rustc_hir::QPath<'tcx>,
id: HirId,
_span: Span,
span: Span,
) -> Self::Result {
let arg_segment = match qpath {
hir::QPath::Resolved(_, path) => {
Expand All @@ -674,13 +675,21 @@ impl<'tcx> Visitor<'tcx> for AnnotateUnitFallbackVisitor<'_, 'tcx> {
}
};
// Alternatively, try to turbofish `::<_, (), _>`.
if let Some(def_id) = self.fcx.typeck_results.borrow().qpath_res(qpath, id).opt_def_id() {
if let Some(def_id) = self.fcx.typeck_results.borrow().qpath_res(qpath, id).opt_def_id()
&& span.can_be_used_for_suggestions()
{
self.suggest_for_segment(arg_segment, def_id, id)?;
}
hir::intravisit::walk_qpath(self, qpath, id)
}

fn visit_expr(&mut self, expr: &'tcx hir::Expr<'tcx>) -> Self::Result {
if let hir::ExprKind::Closure(&hir::Closure { body, .. })
| hir::ExprKind::ConstBlock(hir::ConstBlock { body, .. }) = expr.kind
{
self.visit_body(self.fcx.tcx.hir().body(body))?;
}

// Try to suggest adding an explicit qself `()` to a trait method path.
// i.e. changing `Default::default()` to `<() as Default>::default()`.
if let hir::ExprKind::Path(hir::QPath::Resolved(None, path)) = expr.kind
Expand All @@ -691,17 +700,21 @@ impl<'tcx> Visitor<'tcx> for AnnotateUnitFallbackVisitor<'_, 'tcx> {
&& let Some(vid) = self.fcx.root_vid(self_ty)
&& self.reachable_vids.contains(&vid)
&& let [.., trait_segment, _method_segment] = path.segments
&& expr.span.can_be_used_for_suggestions()
{
let span = path.span.shrink_to_lo().to(trait_segment.ident.span);
return ControlFlow::Break(errors::SuggestAnnotation::Path(span));
}

// Or else, try suggesting turbofishing the method args.
if let hir::ExprKind::MethodCall(segment, ..) = expr.kind
&& let Some(def_id) =
self.fcx.typeck_results.borrow().type_dependent_def_id(expr.hir_id)
&& expr.span.can_be_used_for_suggestions()
{
self.suggest_for_segment(segment, def_id, expr.hir_id)?;
}

hir::intravisit::walk_expr(self, expr)
}

Expand All @@ -712,6 +725,7 @@ impl<'tcx> Visitor<'tcx> for AnnotateUnitFallbackVisitor<'_, 'tcx> {
&& let Some(ty) = self.fcx.typeck_results.borrow().node_type_opt(local.hir_id)
&& let Some(vid) = self.fcx.root_vid(ty)
&& self.reachable_vids.contains(&vid)
&& local.span.can_be_used_for_suggestions()
{
return ControlFlow::Break(errors::SuggestAnnotation::Local(
local.pat.span.shrink_to_hi(),
Expand Down
78 changes: 55 additions & 23 deletions compiler/rustc_hir_typeck/src/pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

// Determine the binding mode...
let bm = match user_bind_annot {
BindingMode(ByRef::No, Mutability::Mut) if matches!(def_br, ByRef::Yes(_)) => {
BindingMode(ByRef::No, Mutability::Mut) if let ByRef::Yes(def_br_mutbl) = def_br => {
// Only mention the experimental `mut_ref` feature if if we're in edition 2024 and
// using other experimental matching features compatible with it.
if pat.span.at_least_rust_2024()
Expand All @@ -834,22 +834,22 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// `mut` resets the binding mode on edition <= 2021
self.add_rust_2024_migration_desugared_pat(
pat_info.top_info.hir_id,
pat.span,
pat,
ident.span,
"requires binding by-value, but the implicit default is by-reference",
def_br_mutbl,
);
BindingMode(ByRef::No, Mutability::Mut)
}
}
BindingMode(ByRef::No, mutbl) => BindingMode(def_br, mutbl),
BindingMode(ByRef::Yes(_), _) => {
if matches!(def_br, ByRef::Yes(_)) {
if let ByRef::Yes(def_br_mutbl) = def_br {
// `ref`/`ref mut` overrides the binding mode on edition <= 2021
self.add_rust_2024_migration_desugared_pat(
pat_info.top_info.hir_id,
pat.span,
pat,
ident.span,
"cannot override to bind by-reference when that is the implicit default",
def_br_mutbl,
);
}
user_bind_annot
Expand Down Expand Up @@ -2386,9 +2386,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
pat_info.binding_mode = ByRef::No;
self.add_rust_2024_migration_desugared_pat(
pat_info.top_info.hir_id,
pat.span,
pat,
inner.span,
"cannot implicitly match against multiple layers of reference",
inh_mut,
)
}
}
Expand Down Expand Up @@ -2778,33 +2778,65 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
fn add_rust_2024_migration_desugared_pat(
&self,
pat_id: HirId,
subpat_span: Span,
subpat: &'tcx Pat<'tcx>,
cutoff_span: Span,
detailed_label: &str,
def_br_mutbl: Mutability,
) {
// Try to trim the span we're labeling to just the `&` or binding mode that's an issue.
// If the subpattern's span is is from an expansion, the emitted label will not be trimmed.
let source_map = self.tcx.sess.source_map();
let cutoff_span = source_map
.span_extend_prev_while(cutoff_span, char::is_whitespace)
.span_extend_prev_while(cutoff_span, |c| c.is_whitespace() || c == '(')
.unwrap_or(cutoff_span);
// Ensure we use the syntax context and thus edition of `subpat_span`; this will be a hard
// Ensure we use the syntax context and thus edition of `subpat.span`; this will be a hard
// error if the subpattern is of edition >= 2024.
let trimmed_span = subpat_span.until(cutoff_span).with_ctxt(subpat_span.ctxt());
let trimmed_span = subpat.span.until(cutoff_span).with_ctxt(subpat.span.ctxt());

let mut typeck_results = self.typeck_results.borrow_mut();
let mut table = typeck_results.rust_2024_migration_desugared_pats_mut();
// FIXME(ref_pat_eat_one_layer_2024): The migration diagnostic doesn't know how to track the
// default binding mode in the presence of Rule 3 or Rule 5. As a consequence, the labels it
// gives for default binding modes are wrong, as well as suggestions based on the default
// binding mode. This keeps it from making those suggestions, as doing so could panic.
let info = table.entry(pat_id).or_insert_with(|| ty::Rust2024IncompatiblePatInfo {
primary_labels: Vec::new(),
bad_modifiers: false,
bad_ref_pats: false,
suggest_eliding_modes: !self.tcx.features().ref_pat_eat_one_layer_2024()
&& !self.tcx.features().ref_pat_eat_one_layer_2024_structural(),
});

// Only provide a detailed label if the problematic subpattern isn't from an expansion.
// In the case that it's from a macro, we'll add a more detailed note in the emitter.
let desc = if subpat_span.from_expansion() {
"default binding mode is reset within expansion"
let from_expansion = subpat.span.from_expansion();
let primary_label = if from_expansion {
// NB: This wording assumes the only expansions that can produce problematic reference
// patterns and bindings are macros. If a desugaring or AST pass is added that can do
// so, we may want to inspect the span's source callee or macro backtrace.
"occurs within macro expansion".to_owned()
} else {
detailed_label
let pat_kind = if let PatKind::Binding(user_bind_annot, _, _, _) = subpat.kind {
info.bad_modifiers |= true;
// If the user-provided binding modifier doesn't match the default binding mode, we'll
// need to suggest reference patterns, which can affect other bindings.
// For simplicity, we opt to suggest making the pattern fully explicit.
info.suggest_eliding_modes &=
user_bind_annot == BindingMode(ByRef::Yes(def_br_mutbl), Mutability::Not);
"binding modifier"
} else {
info.bad_ref_pats |= true;
// For simplicity, we don't try to suggest eliding reference patterns. Thus, we'll
// suggest adding them instead, which can affect the types assigned to bindings.
// As such, we opt to suggest making the pattern fully explicit.
info.suggest_eliding_modes = false;
"reference pattern"
};
let dbm_str = match def_br_mutbl {
Mutability::Not => "ref",
Mutability::Mut => "ref mut",
};
format!("{pat_kind} not allowed under `{dbm_str}` default binding mode")
};

self.typeck_results
.borrow_mut()
.rust_2024_migration_desugared_pats_mut()
.entry(pat_id)
.or_default()
.push((trimmed_span, desc.to_owned()));
info.primary_labels.push((trimmed_span, primary_label));
}
}
25 changes: 12 additions & 13 deletions compiler/rustc_lint/src/deref_into_dyn_supertrait.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use rustc_hir::{self as hir, LangItem};
use rustc_middle::ty;
use rustc_session::lint::FutureIncompatibilityReason;
use rustc_session::{declare_lint, declare_lint_pass};
use rustc_span::sym;
use rustc_trait_selection::traits::supertraits;
Expand All @@ -9,11 +8,12 @@ use crate::lints::{SupertraitAsDerefTarget, SupertraitAsDerefTargetLabel};
use crate::{LateContext, LateLintPass, LintContext};

declare_lint! {
/// The `deref_into_dyn_supertrait` lint is output whenever there is a use of the
/// `Deref` implementation with a `dyn SuperTrait` type as `Output`.
/// The `deref_into_dyn_supertrait` lint is emitted whenever there is a `Deref` implementation
/// for `dyn SubTrait` with a `dyn SuperTrait` type as the `Output` type.
///
/// These implementations will become shadowed when the `trait_upcasting` feature is stabilized.
/// The `deref` functions will no longer be called implicitly, so there might be behavior change.
/// These implementations are "shadowed" by trait upcasting (stabilized since
/// CURRENT_RUSTC_VERSION). The `deref` functions is no longer called implicitly, which might
/// change behavior compared to previous rustc versions.
///
/// ### Example
///
Expand Down Expand Up @@ -43,15 +43,14 @@ declare_lint! {
///
/// ### Explanation
///
/// The dyn upcasting coercion feature adds new coercion rules, taking priority
/// over certain other coercion rules, which will cause some behavior change.
/// The trait upcasting coercion added a new coercion rule, taking priority over certain other
/// coercion rules, which causes some behavior change compared to older `rustc` versions.
///
/// `deref` can be still called explicitly, it just isn't called as part of a deref coercion
/// (since trait upcasting coercion takes priority).
pub DEREF_INTO_DYN_SUPERTRAIT,
Warn,
"`Deref` implementation usage with a supertrait trait object for output might be shadowed in the future",
@future_incompatible = FutureIncompatibleInfo {
reason: FutureIncompatibilityReason::FutureReleaseSemanticsChange,
reference: "issue #89460 <https://github.com/rust-lang/rust/issues/89460>",
};
Allow,
"`Deref` implementation with a supertrait trait object for output is shadowed by trait upcasting",
}

declare_lint_pass!(DerefIntoDynSupertrait => [DEREF_INTO_DYN_SUPERTRAIT]);
Expand Down
Loading
Loading