Skip to content

Commit 93f7a9a

Browse files
committed
Auto merge of rust-lang#129933 - matthiaskrgr:rollup-ws3flpn, r=matthiaskrgr
Rollup of 9 pull requests Successful merges: - rust-lang#127692 (Suggest `impl Trait` for References to Bare Trait in Function Header) - rust-lang#128701 (Don't Suggest Labeling `const` and `unsafe` Blocks ) - rust-lang#128934 (Non-exhaustive structs may be empty) - rust-lang#129630 (Document the broken C ABI of `wasm32-unknown-unknown`) - rust-lang#129706 (Rename dump of coroutine by-move-body to be more consistent, fix ICE in dump_mir) - rust-lang#129896 (do not attempt to prove unknowable goals) - rust-lang#129926 (Move `SanityCheck` and `MirPass`) - rust-lang#129928 (rustc_driver_impl: remove some old dead logic) - rust-lang#129930 (include 1.80.1 release notes on master) r? `@ghost` `@rustbot` modify labels: rollup
2 parents d6c8169 + 67c3113 commit 93f7a9a

File tree

103 files changed

+1652
-606
lines changed

Some content is hidden

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

103 files changed

+1652
-606
lines changed

RELEASES.md

+8
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,14 @@ tools.
112112

113113
- [Add a Rust-for Linux `auto` CI job to check kernel builds.](https://github.com/rust-lang/rust/pull/125209/)
114114

115+
Version 1.80.1 (2024-08-08)
116+
===========================
117+
118+
<a id="1.80.1"></a>
119+
120+
- [Fix miscompilation in the jump threading MIR optimization when comparing floats](https://github.com/rust-lang/rust/pull/128271)
121+
- [Revert changes to the `dead_code` lint from 1.80.0](https://github.com/rust-lang/rust/pull/128618)
122+
115123
Version 1.80.0 (2024-07-25)
116124
==========================
117125

compiler/rustc_driver_impl/src/lib.rs

+2-11
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ use rustc_session::lint::{Lint, LintId};
6161
use rustc_session::output::collect_crate_types;
6262
use rustc_session::{config, filesearch, EarlyDiagCtxt, Session};
6363
use rustc_span::source_map::FileLoader;
64-
use rustc_span::symbol::sym;
6564
use rustc_span::FileName;
6665
use rustc_target::json::ToJson;
6766
use rustc_target::spec::{Target, TargetTriple};
@@ -777,16 +776,8 @@ fn print_crate_info(
777776
.config
778777
.iter()
779778
.filter_map(|&(name, value)| {
780-
// Note that crt-static is a specially recognized cfg
781-
// directive that's printed out here as part of
782-
// rust-lang/rust#37406, but in general the
783-
// `target_feature` cfg is gated under
784-
// rust-lang/rust#29717. For now this is just
785-
// specifically allowing the crt-static cfg and that's
786-
// it, this is intended to get into Cargo and then go
787-
// through to build scripts.
788-
if (name != sym::target_feature || value != Some(sym::crt_dash_static))
789-
&& !sess.is_nightly_build()
779+
// On stable, exclude unstable flags.
780+
if !sess.is_nightly_build()
790781
&& find_gated_cfg(|cfg_sym| cfg_sym == name).is_some()
791782
{
792783
return None;

compiler/rustc_hir_analysis/src/hir_ty_lowering/lint.rs

+55-23
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,6 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
133133
return;
134134
};
135135
let sugg = self.add_generic_param_suggestion(generics, self_ty.span, &impl_trait_name);
136-
if sugg.is_empty() {
137-
return;
138-
};
139136
diag.multipart_suggestion(
140137
format!(
141138
"alternatively use a blanket implementation to implement `{of_trait_name}` for \
@@ -170,6 +167,10 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
170167
let parent_id = tcx.hir().get_parent_item(self_ty.hir_id).def_id;
171168
// FIXME: If `type_alias_impl_trait` is enabled, also look for `Trait0<Ty = Trait1>`
172169
// and suggest `Trait0<Ty = impl Trait1>`.
170+
// Functions are found in three different contexts.
171+
// 1. Independent functions
172+
// 2. Functions inside trait blocks
173+
// 3. Functions inside impl blocks
173174
let (sig, generics, owner) = match tcx.hir_node_by_def_id(parent_id) {
174175
hir::Node::Item(hir::Item { kind: hir::ItemKind::Fn(sig, generics, _), .. }) => {
175176
(sig, generics, None)
@@ -180,13 +181,21 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
180181
owner_id,
181182
..
182183
}) => (sig, generics, Some(tcx.parent(owner_id.to_def_id()))),
184+
hir::Node::ImplItem(hir::ImplItem {
185+
kind: hir::ImplItemKind::Fn(sig, _),
186+
generics,
187+
owner_id,
188+
..
189+
}) => (sig, generics, Some(tcx.parent(owner_id.to_def_id()))),
183190
_ => return false,
184191
};
185192
let Ok(trait_name) = tcx.sess.source_map().span_to_snippet(self_ty.span) else {
186193
return false;
187194
};
188195
let impl_sugg = vec![(self_ty.span.shrink_to_lo(), "impl ".to_string())];
189196
let mut is_downgradable = true;
197+
198+
// Check if trait object is safe for suggesting dynamic dispatch.
190199
let is_object_safe = match self_ty.kind {
191200
hir::TyKind::TraitObject(objects, ..) => {
192201
objects.iter().all(|(o, _)| match o.trait_ref.path.res {
@@ -202,8 +211,15 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
202211
}
203212
_ => false,
204213
};
214+
215+
let borrowed = matches!(
216+
tcx.parent_hir_node(self_ty.hir_id),
217+
hir::Node::Ty(hir::Ty { kind: hir::TyKind::Ref(..), .. })
218+
);
219+
220+
// Suggestions for function return type.
205221
if let hir::FnRetTy::Return(ty) = sig.decl.output
206-
&& ty.hir_id == self_ty.hir_id
222+
&& ty.peel_refs().hir_id == self_ty.hir_id
207223
{
208224
let pre = if !is_object_safe {
209225
format!("`{trait_name}` is not object safe, ")
@@ -214,14 +230,26 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
214230
"{pre}use `impl {trait_name}` to return an opaque type, as long as you return a \
215231
single underlying type",
216232
);
233+
217234
diag.multipart_suggestion_verbose(msg, impl_sugg, Applicability::MachineApplicable);
235+
236+
// Suggest `Box<dyn Trait>` for return type
218237
if is_object_safe {
219-
diag.multipart_suggestion_verbose(
220-
"alternatively, you can return an owned trait object",
238+
// If the return type is `&Trait`, we don't want
239+
// the ampersand to be displayed in the `Box<dyn Trait>`
240+
// suggestion.
241+
let suggestion = if borrowed {
242+
vec![(ty.span, format!("Box<dyn {trait_name}>"))]
243+
} else {
221244
vec![
222245
(ty.span.shrink_to_lo(), "Box<dyn ".to_string()),
223246
(ty.span.shrink_to_hi(), ">".to_string()),
224-
],
247+
]
248+
};
249+
250+
diag.multipart_suggestion_verbose(
251+
"alternatively, you can return an owned trait object",
252+
suggestion,
225253
Applicability::MachineApplicable,
226254
);
227255
} else if is_downgradable {
@@ -230,39 +258,43 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
230258
}
231259
return true;
232260
}
261+
262+
// Suggestions for function parameters.
233263
for ty in sig.decl.inputs {
234-
if ty.hir_id != self_ty.hir_id {
264+
if ty.peel_refs().hir_id != self_ty.hir_id {
235265
continue;
236266
}
237267
let sugg = self.add_generic_param_suggestion(generics, self_ty.span, &trait_name);
238-
if !sugg.is_empty() {
239-
diag.multipart_suggestion_verbose(
240-
format!("use a new generic type parameter, constrained by `{trait_name}`"),
241-
sugg,
242-
Applicability::MachineApplicable,
243-
);
244-
diag.multipart_suggestion_verbose(
245-
"you can also use an opaque type, but users won't be able to specify the type \
246-
parameter when calling the `fn`, having to rely exclusively on type inference",
247-
impl_sugg,
248-
Applicability::MachineApplicable,
249-
);
250-
}
268+
diag.multipart_suggestion_verbose(
269+
format!("use a new generic type parameter, constrained by `{trait_name}`"),
270+
sugg,
271+
Applicability::MachineApplicable,
272+
);
273+
diag.multipart_suggestion_verbose(
274+
"you can also use an opaque type, but users won't be able to specify the type \
275+
parameter when calling the `fn`, having to rely exclusively on type inference",
276+
impl_sugg,
277+
Applicability::MachineApplicable,
278+
);
251279
if !is_object_safe {
252280
diag.note(format!("`{trait_name}` it is not object safe, so it can't be `dyn`"));
253281
if is_downgradable {
254282
// We'll emit the object safety error already, with a structured suggestion.
255283
diag.downgrade_to_delayed_bug();
256284
}
257285
} else {
286+
// No ampersand in suggestion if it's borrowed already
287+
let (dyn_str, paren_dyn_str) =
288+
if borrowed { ("dyn ", "(dyn ") } else { ("&dyn ", "&(dyn ") };
289+
258290
let sugg = if let hir::TyKind::TraitObject([_, _, ..], _, _) = self_ty.kind {
259291
// There are more than one trait bound, we need surrounding parentheses.
260292
vec![
261-
(self_ty.span.shrink_to_lo(), "&(dyn ".to_string()),
293+
(self_ty.span.shrink_to_lo(), paren_dyn_str.to_string()),
262294
(self_ty.span.shrink_to_hi(), ")".to_string()),
263295
]
264296
} else {
265-
vec![(self_ty.span.shrink_to_lo(), "&dyn ".to_string())]
297+
vec![(self_ty.span.shrink_to_lo(), dyn_str.to_string())]
266298
};
267299
diag.multipart_suggestion_verbose(
268300
format!(

compiler/rustc_middle/src/mir/mod.rs

-62
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
//! [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/mir/index.html
44
55
use std::borrow::Cow;
6-
use std::cell::RefCell;
7-
use std::collections::hash_map::Entry;
86
use std::fmt::{self, Debug, Formatter};
97
use std::ops::{Index, IndexMut};
108
use std::{iter, mem};
@@ -26,7 +24,6 @@ use rustc_index::bit_set::BitSet;
2624
use rustc_index::{Idx, IndexSlice, IndexVec};
2725
use rustc_macros::{HashStable, TyDecodable, TyEncodable, TypeFoldable, TypeVisitable};
2826
use rustc_serialize::{Decodable, Encodable};
29-
use rustc_session::Session;
3027
use rustc_span::source_map::Spanned;
3128
use rustc_span::symbol::Symbol;
3229
use rustc_span::{Span, DUMMY_SP};
@@ -106,65 +103,6 @@ impl<'tcx> HasLocalDecls<'tcx> for Body<'tcx> {
106103
}
107104
}
108105

109-
thread_local! {
110-
static PASS_NAMES: RefCell<FxHashMap<&'static str, &'static str>> = {
111-
RefCell::new(FxHashMap::default())
112-
};
113-
}
114-
115-
/// Converts a MIR pass name into a snake case form to match the profiling naming style.
116-
fn to_profiler_name(type_name: &'static str) -> &'static str {
117-
PASS_NAMES.with(|names| match names.borrow_mut().entry(type_name) {
118-
Entry::Occupied(e) => *e.get(),
119-
Entry::Vacant(e) => {
120-
let snake_case: String = type_name
121-
.chars()
122-
.flat_map(|c| {
123-
if c.is_ascii_uppercase() {
124-
vec!['_', c.to_ascii_lowercase()]
125-
} else if c == '-' {
126-
vec!['_']
127-
} else {
128-
vec![c]
129-
}
130-
})
131-
.collect();
132-
let result = &*String::leak(format!("mir_pass{}", snake_case));
133-
e.insert(result);
134-
result
135-
}
136-
})
137-
}
138-
139-
/// A streamlined trait that you can implement to create a pass; the
140-
/// pass will be named after the type, and it will consist of a main
141-
/// loop that goes over each available MIR and applies `run_pass`.
142-
pub trait MirPass<'tcx> {
143-
fn name(&self) -> &'static str {
144-
// FIXME Simplify the implementation once more `str` methods get const-stable.
145-
// See copypaste in `MirLint`
146-
const {
147-
let name = std::any::type_name::<Self>();
148-
crate::util::common::c_name(name)
149-
}
150-
}
151-
152-
fn profiler_name(&self) -> &'static str {
153-
to_profiler_name(self.name())
154-
}
155-
156-
/// Returns `true` if this pass is enabled with the current combination of compiler flags.
157-
fn is_enabled(&self, _sess: &Session) -> bool {
158-
true
159-
}
160-
161-
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>);
162-
163-
fn is_mir_dump_enabled(&self) -> bool {
164-
true
165-
}
166-
}
167-
168106
impl MirPhase {
169107
/// Gets the index of the current MirPhase within the set of all `MirPhase`s.
170108
///

compiler/rustc_middle/src/mir/pretty.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,9 @@ fn write_mir_sig(tcx: TyCtxt<'_>, body: &Body<'_>, w: &mut dyn io::Write) -> io:
612612
let def_id = body.source.def_id();
613613
let kind = tcx.def_kind(def_id);
614614
let is_function = match kind {
615-
DefKind::Fn | DefKind::AssocFn | DefKind::Ctor(..) => true,
615+
DefKind::Fn | DefKind::AssocFn | DefKind::Ctor(..) | DefKind::SyntheticCoroutineBody => {
616+
true
617+
}
616618
_ => tcx.is_closure_like(def_id),
617619
};
618620
match (kind, body.source.promoted) {

compiler/rustc_middle/src/ty/inhabitedness/mod.rs

-4
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,6 @@ impl<'tcx> VariantDef {
8181
adt: ty::AdtDef<'_>,
8282
) -> InhabitedPredicate<'tcx> {
8383
debug_assert!(!adt.is_union());
84-
if self.is_field_list_non_exhaustive() && !self.def_id.is_local() {
85-
// Non-exhaustive variants from other crates are always considered inhabited.
86-
return InhabitedPredicate::True;
87-
}
8884
InhabitedPredicate::all(
8985
tcx,
9086
self.fields.iter().map(|field| {

compiler/rustc_middle/src/util/common.rs

-16
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,3 @@ pub fn to_readable_str(mut val: usize) -> String {
2020

2121
groups.join("_")
2222
}
23-
24-
// const wrapper for `if let Some((_, tail)) = name.rsplit_once(':') { tail } else { name }`
25-
pub const fn c_name(name: &'static str) -> &'static str {
26-
// FIXME Simplify the implementation once more `str` methods get const-stable.
27-
// and inline into call site
28-
let bytes = name.as_bytes();
29-
let mut i = bytes.len();
30-
while i > 0 && bytes[i - 1] != b':' {
31-
i = i - 1;
32-
}
33-
let (_, bytes) = bytes.split_at(i);
34-
match std::str::from_utf8(bytes) {
35-
Ok(name) => name,
36-
Err(_) => name,
37-
}
38-
}

0 commit comments

Comments
 (0)