Skip to content

Commit 984eab5

Browse files
committed
Auto merge of #105746 - matthiaskrgr:rollup-sz3grbv, r=matthiaskrgr
Rollup of 11 pull requests Successful merges: - #104592 (Ensure async trait impls are async (or otherwise return an opaque type)) - #105623 (Fix `-Z print-type-sizes` for generators with discriminant field ordered first) - #105627 (Auto traits in `dyn Trait + Auto` are suggestable) - #105633 (Make `report_projection_error` more `Term` agnostic) - #105683 (Various cleanups to dest prop) - #105692 (Add regression test for #104678) - #105707 (rustdoc: remove unnecessary CSS `kbd { cursor: default }`) - #105715 (Do not mention long types in E0599 label) - #105722 (more clippy::complexity fixes) - #105724 (rustdoc: remove no-op CSS `.scrape-example .src-line-numbers { margin: 0 }`) - #105730 (rustdoc: remove no-op CSS `.item-info:before { color }`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 397b66e + 2650b7b commit 984eab5

File tree

61 files changed

+509
-325
lines changed

Some content is hidden

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

61 files changed

+509
-325
lines changed

compiler/rustc_ast/src/ast.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -2466,20 +2466,14 @@ pub enum ModKind {
24662466
Unloaded,
24672467
}
24682468

2469-
#[derive(Copy, Clone, Encodable, Decodable, Debug)]
2469+
#[derive(Copy, Clone, Encodable, Decodable, Debug, Default)]
24702470
pub struct ModSpans {
24712471
/// `inner_span` covers the body of the module; for a file module, its the whole file.
24722472
/// For an inline module, its the span inside the `{ ... }`, not including the curly braces.
24732473
pub inner_span: Span,
24742474
pub inject_use_span: Span,
24752475
}
24762476

2477-
impl Default for ModSpans {
2478-
fn default() -> ModSpans {
2479-
ModSpans { inner_span: Default::default(), inject_use_span: Default::default() }
2480-
}
2481-
}
2482-
24832477
/// Foreign module declaration.
24842478
///
24852479
/// E.g., `extern { .. }` or `extern "C" { .. }`.

compiler/rustc_data_structures/src/sorted_map.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,13 @@ impl<K: Ord, V> SortedMap<K, V> {
126126
/// Iterate over the keys, sorted
127127
#[inline]
128128
pub fn keys(&self) -> impl Iterator<Item = &K> + ExactSizeIterator + DoubleEndedIterator {
129-
self.data.iter().map(|&(ref k, _)| k)
129+
self.data.iter().map(|(k, _)| k)
130130
}
131131

132132
/// Iterate over values, sorted by key
133133
#[inline]
134134
pub fn values(&self) -> impl Iterator<Item = &V> + ExactSizeIterator + DoubleEndedIterator {
135-
self.data.iter().map(|&(_, ref v)| v)
135+
self.data.iter().map(|(_, v)| v)
136136
}
137137

138138
#[inline]
@@ -222,7 +222,7 @@ impl<K: Ord, V> SortedMap<K, V> {
222222
K: Borrow<Q>,
223223
Q: Ord + ?Sized,
224224
{
225-
self.data.binary_search_by(|&(ref x, _)| x.borrow().cmp(key))
225+
self.data.binary_search_by(|(x, _)| x.borrow().cmp(key))
226226
}
227227

228228
#[inline]
@@ -300,7 +300,7 @@ impl<K: Ord, V> FromIterator<(K, V)> for SortedMap<K, V> {
300300
fn from_iter<T: IntoIterator<Item = (K, V)>>(iter: T) -> Self {
301301
let mut data: Vec<(K, V)> = iter.into_iter().collect();
302302

303-
data.sort_unstable_by(|&(ref k1, _), &(ref k2, _)| k1.cmp(k2));
303+
data.sort_unstable_by(|(k1, _), (k2, _)| k1.cmp(k2));
304304
data.dedup_by(|&mut (ref k1, _), &mut (ref k2, _)| k1.cmp(k2) == Ordering::Equal);
305305

306306
SortedMap { data }

compiler/rustc_error_messages/locales/en-US/hir_analysis.ftl

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ hir_analysis_lifetimes_or_bounds_mismatch_on_trait =
2020
.where_label = this `where` clause might not match the one in the trait
2121
.bounds_label = this bound might be missing in the impl
2222
23+
hir_analysis_async_trait_impl_should_be_async =
24+
method `{$method_name}` should be async because the method from the trait is async
25+
.trait_item_label = required because the trait method is async
26+
2327
hir_analysis_drop_impl_on_wrong_item =
2428
the `Drop` trait may only be implemented for local structs, enums, and unions
2529
.label = must be a struct, enum, or union in the current crate

compiler/rustc_errors/src/emitter.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2313,7 +2313,7 @@ impl FileWithAnnotatedLines {
23132313
}
23142314

23152315
// Find overlapping multiline annotations, put them at different depths
2316-
multiline_annotations.sort_by_key(|&(_, ref ml)| (ml.line_start, usize::MAX - ml.line_end));
2316+
multiline_annotations.sort_by_key(|(_, ml)| (ml.line_start, usize::MAX - ml.line_end));
23172317
for (_, ann) in multiline_annotations.clone() {
23182318
for (_, a) in multiline_annotations.iter_mut() {
23192319
// Move all other multiline annotations overlapping with this one

compiler/rustc_errors/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ impl CodeSuggestion {
324324
// Account for the difference between the width of the current code and the
325325
// snippet being suggested, so that the *later* suggestions are correctly
326326
// aligned on the screen.
327-
acc += len as isize - (cur_hi.col.0 - cur_lo.col.0) as isize;
327+
acc += len - (cur_hi.col.0 - cur_lo.col.0) as isize;
328328
}
329329
prev_hi = cur_hi;
330330
prev_line = sf.get_line(prev_hi.line - 1);

compiler/rustc_hir_analysis/src/check/compare_method.rs

+32
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ pub(crate) fn compare_impl_method<'tcx>(
6767
return;
6868
}
6969

70+
if let Err(_) = compare_asyncness(tcx, impl_m, impl_m_span, trait_m, trait_item_span) {
71+
return;
72+
}
73+
7074
if let Err(_) = compare_predicate_entailment(tcx, impl_m, impl_m_span, trait_m, impl_trait_ref)
7175
{
7276
return;
@@ -323,6 +327,34 @@ fn compare_predicate_entailment<'tcx>(
323327
Ok(())
324328
}
325329

330+
fn compare_asyncness<'tcx>(
331+
tcx: TyCtxt<'tcx>,
332+
impl_m: &ty::AssocItem,
333+
impl_m_span: Span,
334+
trait_m: &ty::AssocItem,
335+
trait_item_span: Option<Span>,
336+
) -> Result<(), ErrorGuaranteed> {
337+
if tcx.asyncness(trait_m.def_id) == hir::IsAsync::Async {
338+
match tcx.fn_sig(impl_m.def_id).skip_binder().output().kind() {
339+
ty::Alias(ty::Opaque, ..) => {
340+
// allow both `async fn foo()` and `fn foo() -> impl Future`
341+
}
342+
ty::Error(rustc_errors::ErrorGuaranteed { .. }) => {
343+
// We don't know if it's ok, but at least it's already an error.
344+
}
345+
_ => {
346+
return Err(tcx.sess.emit_err(crate::errors::AsyncTraitImplShouldBeAsync {
347+
span: impl_m_span,
348+
method_name: trait_m.name,
349+
trait_item_span,
350+
}));
351+
}
352+
};
353+
}
354+
355+
Ok(())
356+
}
357+
326358
#[instrument(skip(tcx), level = "debug", ret)]
327359
pub fn collect_trait_impl_trait_tys<'tcx>(
328360
tcx: TyCtxt<'tcx>,

compiler/rustc_hir_analysis/src/errors.rs

+11
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,17 @@ pub struct LifetimesOrBoundsMismatchOnTrait {
5151
pub ident: Ident,
5252
}
5353

54+
#[derive(Diagnostic)]
55+
#[diag(hir_analysis_async_trait_impl_should_be_async)]
56+
pub struct AsyncTraitImplShouldBeAsync {
57+
#[primary_span]
58+
// #[label]
59+
pub span: Span,
60+
#[label(trait_item_label)]
61+
pub trait_item_span: Option<Span>,
62+
pub method_name: Symbol,
63+
}
64+
5465
#[derive(Diagnostic)]
5566
#[diag(hir_analysis_drop_impl_on_wrong_item, code = "E0120")]
5667
pub struct DropImplOnWrongItem {

compiler/rustc_hir_pretty/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1757,7 +1757,6 @@ impl<'a> State<'a> {
17571757
self.print_qpath(qpath, true);
17581758
self.popen();
17591759
if let Some(ddpos) = ddpos.as_opt_usize() {
1760-
let ddpos = ddpos as usize;
17611760
self.commasep(Inconsistent, &elts[..ddpos], |s, p| s.print_pat(p));
17621761
if ddpos != 0 {
17631762
self.word_space(",");

compiler/rustc_hir_typeck/src/method/suggest.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -893,7 +893,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
893893
}
894894
}
895895
} else {
896-
err.span_label(span, format!("{item_kind} cannot be called on `{ty_str}` due to unsatisfied trait bounds"));
896+
let ty_str = if ty_str.len() > 50 {
897+
String::new()
898+
} else {
899+
format!("on `{ty_str}` ")
900+
};
901+
err.span_label(span, format!(
902+
"{item_kind} cannot be called {ty_str}due to unsatisfied trait bounds"
903+
));
897904
}
898905
};
899906

compiler/rustc_macros/src/diagnostics/diagnostic.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ impl Mismatch {
192192
let crate_name = std::env::var("CARGO_CRATE_NAME").ok()?;
193193

194194
// If we're not in a "rustc_" crate, bail.
195-
let Some(("rustc", slug_prefix)) = crate_name.split_once("_") else { return None };
195+
let Some(("rustc", slug_prefix)) = crate_name.split_once('_') else { return None };
196196

197197
let slug_name = slug.segments.first()?.ident.to_string();
198198
if !slug_name.starts_with(slug_prefix) {

compiler/rustc_middle/src/ty/diagnostics.rs

+2-13
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
use std::ops::ControlFlow;
44

55
use crate::ty::{
6-
visit::TypeVisitable, AliasTy, Const, ConstKind, DefIdTree, ExistentialPredicate, InferConst,
7-
InferTy, Opaque, PolyTraitPredicate, Ty, TyCtxt, TypeSuperVisitable, TypeVisitor,
6+
visit::TypeVisitable, AliasTy, Const, ConstKind, DefIdTree, InferConst, InferTy, Opaque,
7+
PolyTraitPredicate, Ty, TyCtxt, TypeSuperVisitable, TypeVisitor,
88
};
99

1010
use rustc_data_structures::fx::FxHashMap;
@@ -469,17 +469,6 @@ impl<'tcx> TypeVisitor<'tcx> for IsSuggestableVisitor<'tcx> {
469469
}
470470
}
471471

472-
Dynamic(dty, _, _) => {
473-
for pred in *dty {
474-
match pred.skip_binder() {
475-
ExistentialPredicate::Trait(_) | ExistentialPredicate::Projection(_) => {
476-
// Okay
477-
}
478-
_ => return ControlFlow::Break(()),
479-
}
480-
}
481-
}
482-
483472
Param(param) => {
484473
// FIXME: It would be nice to make this not use string manipulation,
485474
// but it's pretty hard to do this, since `ty::ParamTy` is missing

0 commit comments

Comments
 (0)