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 11 pull requests #105746

Merged
merged 23 commits into from
Dec 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
687b4d9
Add regression test for #104678
JohnTitor Dec 14, 2022
5f5ae17
Consider discriminant fields that are ordered before variant fields
compiler-errors Dec 12, 2022
bdc3c4b
Make print_type_sizes test not use feature(start)
compiler-errors Dec 12, 2022
9e3d847
rustdoc: remove unnecessary CSS `kbd { cursor: default }`
notriddle Dec 14, 2022
7bf36de
Make report_projection_error more term agnostic
compiler-errors Dec 12, 2022
cfa6a93
Auto traits in dyn are suggestable
compiler-errors Dec 12, 2022
2a0d712
Do not mention long types in E0599 label
estebank Dec 14, 2022
de59844
more clippy::complexity fixes
matthiaskrgr Dec 14, 2022
afcc354
rustdoc: remove no-op CSS `.scrape-example .src-line-numbers { margin…
notriddle Dec 14, 2022
da98ef9
Ensure async trait impls are async (or otherwise return an opaque type)
ComputerDruid Nov 3, 2022
6ac0b94
rustdoc: remove no-op CSS `.item-info:before { color }`
notriddle Dec 15, 2022
a5beb7a
Various cleanups to dest prop
JakobDegen Dec 14, 2022
c00eac3
Rollup merge of #104592 - ComputerDruid:async_check, r=compiler-errors
matthiaskrgr Dec 15, 2022
5d24760
Rollup merge of #105623 - compiler-errors:generator-type-size-fix, r=…
matthiaskrgr Dec 15, 2022
a2c9f2a
Rollup merge of #105627 - compiler-errors:dyn-auto-suggestable, r=dav…
matthiaskrgr Dec 15, 2022
78cf8cc
Rollup merge of #105633 - compiler-errors:term-agnostic, r=oli-obk
matthiaskrgr Dec 15, 2022
6cdc83b
Rollup merge of #105683 - JakobDegen:dest-prop-storage, r=tmiasko
matthiaskrgr Dec 15, 2022
8111cc4
Rollup merge of #105692 - JohnTitor:issue-104678, r=compiler-errors
matthiaskrgr Dec 15, 2022
a6337d3
Rollup merge of #105707 - notriddle:notriddle/kbd-cursor, r=jhpratt,G…
matthiaskrgr Dec 15, 2022
cb9bcaf
Rollup merge of #105715 - estebank:unsatisfied-bounds-label, r=compil…
matthiaskrgr Dec 15, 2022
c0862f3
Rollup merge of #105722 - matthiaskrgr:compl2, r=compiler-errors
matthiaskrgr Dec 15, 2022
99a1bfc
Rollup merge of #105724 - notriddle:notriddle/scrape-example-src-line…
matthiaskrgr Dec 15, 2022
2650b7b
Rollup merge of #105730 - notriddle:notriddle/item-info-before, r=Gui…
matthiaskrgr Dec 15, 2022
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
8 changes: 1 addition & 7 deletions compiler/rustc_ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2466,20 +2466,14 @@ pub enum ModKind {
Unloaded,
}

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

impl Default for ModSpans {
fn default() -> ModSpans {
ModSpans { inner_span: Default::default(), inject_use_span: Default::default() }
}
}

/// Foreign module declaration.
///
/// E.g., `extern { .. }` or `extern "C" { .. }`.
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_data_structures/src/sorted_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,13 @@ impl<K: Ord, V> SortedMap<K, V> {
/// Iterate over the keys, sorted
#[inline]
pub fn keys(&self) -> impl Iterator<Item = &K> + ExactSizeIterator + DoubleEndedIterator {
self.data.iter().map(|&(ref k, _)| k)
self.data.iter().map(|(k, _)| k)
}

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

#[inline]
Expand Down Expand Up @@ -222,7 +222,7 @@ impl<K: Ord, V> SortedMap<K, V> {
K: Borrow<Q>,
Q: Ord + ?Sized,
{
self.data.binary_search_by(|&(ref x, _)| x.borrow().cmp(key))
self.data.binary_search_by(|(x, _)| x.borrow().cmp(key))
}

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

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

SortedMap { data }
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_error_messages/locales/en-US/hir_analysis.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ hir_analysis_lifetimes_or_bounds_mismatch_on_trait =
.where_label = this `where` clause might not match the one in the trait
.bounds_label = this bound might be missing in the impl

hir_analysis_async_trait_impl_should_be_async =
method `{$method_name}` should be async because the method from the trait is async
.trait_item_label = required because the trait method is async

hir_analysis_drop_impl_on_wrong_item =
the `Drop` trait may only be implemented for local structs, enums, and unions
.label = must be a struct, enum, or union in the current crate
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_errors/src/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2313,7 +2313,7 @@ impl FileWithAnnotatedLines {
}

// Find overlapping multiline annotations, put them at different depths
multiline_annotations.sort_by_key(|&(_, ref ml)| (ml.line_start, usize::MAX - ml.line_end));
multiline_annotations.sort_by_key(|(_, ml)| (ml.line_start, usize::MAX - ml.line_end));
for (_, ann) in multiline_annotations.clone() {
for (_, a) in multiline_annotations.iter_mut() {
// Move all other multiline annotations overlapping with this one
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_errors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ impl CodeSuggestion {
// Account for the difference between the width of the current code and the
// snippet being suggested, so that the *later* suggestions are correctly
// aligned on the screen.
acc += len as isize - (cur_hi.col.0 - cur_lo.col.0) as isize;
acc += len - (cur_hi.col.0 - cur_lo.col.0) as isize;
}
prev_hi = cur_hi;
prev_line = sf.get_line(prev_hi.line - 1);
Expand Down
32 changes: 32 additions & 0 deletions compiler/rustc_hir_analysis/src/check/compare_method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ pub(crate) fn compare_impl_method<'tcx>(
return;
}

if let Err(_) = compare_asyncness(tcx, impl_m, impl_m_span, trait_m, trait_item_span) {
return;
}

if let Err(_) = compare_predicate_entailment(tcx, impl_m, impl_m_span, trait_m, impl_trait_ref)
{
return;
Expand Down Expand Up @@ -323,6 +327,34 @@ fn compare_predicate_entailment<'tcx>(
Ok(())
}

fn compare_asyncness<'tcx>(
tcx: TyCtxt<'tcx>,
impl_m: &ty::AssocItem,
impl_m_span: Span,
trait_m: &ty::AssocItem,
trait_item_span: Option<Span>,
) -> Result<(), ErrorGuaranteed> {
if tcx.asyncness(trait_m.def_id) == hir::IsAsync::Async {
match tcx.fn_sig(impl_m.def_id).skip_binder().output().kind() {
ty::Alias(ty::Opaque, ..) => {
// allow both `async fn foo()` and `fn foo() -> impl Future`
}
ty::Error(rustc_errors::ErrorGuaranteed { .. }) => {
// We don't know if it's ok, but at least it's already an error.
}
_ => {
return Err(tcx.sess.emit_err(crate::errors::AsyncTraitImplShouldBeAsync {
span: impl_m_span,
method_name: trait_m.name,
trait_item_span,
}));
}
};
}

Ok(())
}

#[instrument(skip(tcx), level = "debug", ret)]
pub fn collect_trait_impl_trait_tys<'tcx>(
tcx: TyCtxt<'tcx>,
Expand Down
11 changes: 11 additions & 0 deletions compiler/rustc_hir_analysis/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,17 @@ pub struct LifetimesOrBoundsMismatchOnTrait {
pub ident: Ident,
}

#[derive(Diagnostic)]
#[diag(hir_analysis_async_trait_impl_should_be_async)]
pub struct AsyncTraitImplShouldBeAsync {
#[primary_span]
// #[label]
pub span: Span,
#[label(trait_item_label)]
pub trait_item_span: Option<Span>,
pub method_name: Symbol,
}

#[derive(Diagnostic)]
#[diag(hir_analysis_drop_impl_on_wrong_item, code = "E0120")]
pub struct DropImplOnWrongItem {
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_hir_pretty/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1757,7 +1757,6 @@ impl<'a> State<'a> {
self.print_qpath(qpath, true);
self.popen();
if let Some(ddpos) = ddpos.as_opt_usize() {
let ddpos = ddpos as usize;
self.commasep(Inconsistent, &elts[..ddpos], |s, p| s.print_pat(p));
if ddpos != 0 {
self.word_space(",");
Expand Down
9 changes: 8 additions & 1 deletion compiler/rustc_hir_typeck/src/method/suggest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -893,7 +893,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
}
} else {
err.span_label(span, format!("{item_kind} cannot be called on `{ty_str}` due to unsatisfied trait bounds"));
let ty_str = if ty_str.len() > 50 {
String::new()
} else {
format!("on `{ty_str}` ")
};
err.span_label(span, format!(
"{item_kind} cannot be called {ty_str}due to unsatisfied trait bounds"
));
}
};

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_macros/src/diagnostics/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ impl Mismatch {
let crate_name = std::env::var("CARGO_CRATE_NAME").ok()?;

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

let slug_name = slug.segments.first()?.ident.to_string();
if !slug_name.starts_with(slug_prefix) {
Expand Down
15 changes: 2 additions & 13 deletions compiler/rustc_middle/src/ty/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
use std::ops::ControlFlow;

use crate::ty::{
visit::TypeVisitable, AliasTy, Const, ConstKind, DefIdTree, ExistentialPredicate, InferConst,
InferTy, Opaque, PolyTraitPredicate, Ty, TyCtxt, TypeSuperVisitable, TypeVisitor,
visit::TypeVisitable, AliasTy, Const, ConstKind, DefIdTree, InferConst, InferTy, Opaque,
PolyTraitPredicate, Ty, TyCtxt, TypeSuperVisitable, TypeVisitor,
};

use rustc_data_structures::fx::FxHashMap;
Expand Down Expand Up @@ -469,17 +469,6 @@ impl<'tcx> TypeVisitor<'tcx> for IsSuggestableVisitor<'tcx> {
}
}

Dynamic(dty, _, _) => {
for pred in *dty {
match pred.skip_binder() {
ExistentialPredicate::Trait(_) | ExistentialPredicate::Projection(_) => {
// Okay
}
_ => return ControlFlow::Break(()),
}
}
}

Param(param) => {
// FIXME: It would be nice to make this not use string manipulation,
// but it's pretty hard to do this, since `ty::ParamTy` is missing
Expand Down
Loading