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

[BETA] Beta 1.64 backports #101221

Merged
merged 4 commits into from
Aug 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 20 additions & 0 deletions compiler/rustc_errors/src/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,26 @@ pub trait IntoDiagnosticArg {
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static>;
}

pub struct DiagnosticArgFromDisplay<'a>(pub &'a dyn fmt::Display);

impl IntoDiagnosticArg for DiagnosticArgFromDisplay<'_> {
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
self.0.to_string().into_diagnostic_arg()
}
}

impl<'a> From<&'a dyn fmt::Display> for DiagnosticArgFromDisplay<'a> {
fn from(t: &'a dyn fmt::Display) -> Self {
DiagnosticArgFromDisplay(t)
}
}

impl<'a, T: fmt::Display> From<&'a T> for DiagnosticArgFromDisplay<'a> {
fn from(t: &'a T) -> Self {
DiagnosticArgFromDisplay(t)
}
}

macro_rules! into_diagnostic_arg_using_display {
($( $ty:ty ),+ $(,)?) => {
$(
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_errors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,8 @@ impl fmt::Display for ExplicitBug {
impl error::Error for ExplicitBug {}

pub use diagnostic::{
AddSubdiagnostic, DecorateLint, Diagnostic, DiagnosticArg, DiagnosticArgValue, DiagnosticId,
DiagnosticStyledString, IntoDiagnosticArg, SubDiagnostic,
AddSubdiagnostic, DecorateLint, Diagnostic, DiagnosticArg, DiagnosticArgFromDisplay,
DiagnosticArgValue, DiagnosticId, DiagnosticStyledString, IntoDiagnosticArg, SubDiagnostic,
};
pub use diagnostic_builder::{DiagnosticBuilder, EmissionGuarantee, LintDiagnosticBuilder};
use std::backtrace::Backtrace;
Expand Down
14 changes: 8 additions & 6 deletions compiler/rustc_infer/src/infer/opaque_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,25 @@ pub struct OpaqueTypeDecl<'tcx> {
}

impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
pub fn replace_opaque_types_with_inference_vars(
/// This is a backwards compatibility hack to prevent breaking changes from
/// lazy TAIT around RPIT handling.
pub fn replace_opaque_types_with_inference_vars<T: TypeFoldable<'tcx>>(
&self,
ty: Ty<'tcx>,
value: T,
body_id: HirId,
span: Span,
param_env: ty::ParamEnv<'tcx>,
) -> InferOk<'tcx, Ty<'tcx>> {
if !ty.has_opaque_types() {
return InferOk { value: ty, obligations: vec![] };
) -> InferOk<'tcx, T> {
if !value.has_opaque_types() {
return InferOk { value, obligations: vec![] };
}
let mut obligations = vec![];
let replace_opaque_type = |def_id: DefId| {
def_id
.as_local()
.map_or(false, |def_id| self.opaque_type_origin(def_id, span).is_some())
};
let value = ty.fold_with(&mut ty::fold::BottomUpFolder {
let value = value.fold_with(&mut ty::fold::BottomUpFolder {
tcx: self.tcx,
lt_op: |lt| lt,
ct_op: |ct| ct,
Expand Down
11 changes: 6 additions & 5 deletions compiler/rustc_privacy/src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use rustc_errors::DiagnosticArgFromDisplay;
use rustc_macros::{LintDiagnostic, SessionDiagnostic, SessionSubdiagnostic};
use rustc_span::{Span, Symbol};

Expand Down Expand Up @@ -35,7 +36,7 @@ pub struct ItemIsPrivate<'a> {
#[label]
pub span: Span,
pub kind: &'a str,
pub descr: String,
pub descr: DiagnosticArgFromDisplay<'a>,
}

#[derive(SessionDiagnostic)]
Expand All @@ -55,7 +56,7 @@ pub struct InPublicInterfaceTraits<'a> {
pub span: Span,
pub vis_descr: &'static str,
pub kind: &'a str,
pub descr: String,
pub descr: DiagnosticArgFromDisplay<'a>,
#[label(privacy::visibility_label)]
pub vis_span: Span,
}
Expand All @@ -69,7 +70,7 @@ pub struct InPublicInterface<'a> {
pub span: Span,
pub vis_descr: &'static str,
pub kind: &'a str,
pub descr: String,
pub descr: DiagnosticArgFromDisplay<'a>,
#[label(privacy::visibility_label)]
pub vis_span: Span,
}
Expand All @@ -78,7 +79,7 @@ pub struct InPublicInterface<'a> {
#[lint(privacy::from_private_dep_in_public_interface)]
pub struct FromPrivateDependencyInPublicInterface<'a> {
pub kind: &'a str,
pub descr: String,
pub descr: DiagnosticArgFromDisplay<'a>,
pub krate: Symbol,
}

Expand All @@ -87,5 +88,5 @@ pub struct FromPrivateDependencyInPublicInterface<'a> {
pub struct PrivateInPublicLint<'a> {
pub vis_descr: &'static str,
pub kind: &'a str,
pub descr: String,
pub descr: DiagnosticArgFromDisplay<'a>,
}
19 changes: 8 additions & 11 deletions compiler/rustc_privacy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1079,11 +1079,7 @@ impl<'tcx> TypePrivacyVisitor<'tcx> {
fn check_def_id(&mut self, def_id: DefId, kind: &str, descr: &dyn fmt::Display) -> bool {
let is_error = !self.item_is_accessible(def_id);
if is_error {
self.tcx.sess.emit_err(ItemIsPrivate {
span: self.span,
kind,
descr: descr.to_string(),
});
self.tcx.sess.emit_err(ItemIsPrivate { span: self.span, kind, descr: descr.into() });
}
is_error
}
Expand Down Expand Up @@ -1255,7 +1251,9 @@ impl<'tcx> Visitor<'tcx> for TypePrivacyVisitor<'tcx> {
};
let kind = kind.descr(def_id);
let _ = match name {
Some(name) => sess.emit_err(ItemIsPrivate { span, kind, descr: name }),
Some(name) => {
sess.emit_err(ItemIsPrivate { span, kind, descr: (&name).into() })
}
None => sess.emit_err(UnnamedItemIsPrivate { span, kind }),
};
return;
Expand Down Expand Up @@ -1723,7 +1721,7 @@ impl SearchInterfaceForPrivateItemsVisitor<'_> {
self.tcx.def_span(self.item_def_id.to_def_id()),
FromPrivateDependencyInPublicInterface {
kind,
descr: descr.to_string(),
descr: descr.into(),
krate: self.tcx.crate_name(def_id.krate),
},
);
Expand All @@ -1750,7 +1748,6 @@ impl SearchInterfaceForPrivateItemsVisitor<'_> {
}
};
let span = self.tcx.def_span(self.item_def_id.to_def_id());
let descr = descr.to_string();
if self.has_old_errors
|| self.in_assoc_ty
|| self.tcx.resolutions(()).has_pub_restricted
Expand All @@ -1761,15 +1758,15 @@ impl SearchInterfaceForPrivateItemsVisitor<'_> {
span,
vis_descr,
kind,
descr,
descr: descr.into(),
vis_span,
});
} else {
self.tcx.sess.emit_err(InPublicInterface {
span,
vis_descr,
kind,
descr,
descr: descr.into(),
vis_span,
});
}
Expand All @@ -1778,7 +1775,7 @@ impl SearchInterfaceForPrivateItemsVisitor<'_> {
lint::builtin::PRIVATE_IN_PUBLIC,
hir_id,
span,
PrivateInPublicLint { vis_descr, kind, descr },
PrivateInPublicLint { vis_descr, kind, descr: descr.into() },
);
}
}
Expand Down
18 changes: 14 additions & 4 deletions compiler/rustc_trait_selection/src/traits/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,20 @@ fn project_and_unify_type<'cx, 'tcx>(
Err(InProgress) => return ProjectAndUnifyResult::Recursive,
};
debug!(?normalized, ?obligations, "project_and_unify_type result");
match infcx
.at(&obligation.cause, obligation.param_env)
.eq(normalized, obligation.predicate.term)
{
let actual = obligation.predicate.term;
// For an example where this is neccessary see src/test/ui/impl-trait/nested-return-type2.rs
// This allows users to omit re-mentioning all bounds on an associated type and just use an
// `impl Trait` for the assoc type to add more bounds.
let InferOk { value: actual, obligations: new } =
selcx.infcx().replace_opaque_types_with_inference_vars(
actual,
obligation.cause.body_id,
obligation.cause.span,
obligation.param_env,
);
obligations.extend(new);

match infcx.at(&obligation.cause, obligation.param_env).eq(normalized, actual) {
Ok(InferOk { obligations: inferred_obligations, value: () }) => {
obligations.extend(inferred_obligations);
ProjectAndUnifyResult::Holds(obligations)
Expand Down
14 changes: 7 additions & 7 deletions compiler/rustc_typeck/src/check/fn_ctxt/checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1761,13 +1761,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
.filter_map(|seg| seg.args.as_ref())
.flat_map(|a| a.args.iter())
{
if let hir::GenericArg::Type(hir_ty) = &arg {
let ty = self.resolve_vars_if_possible(
self.typeck_results.borrow().node_type(hir_ty.hir_id),
);
if ty == predicate.self_ty() {
error.obligation.cause.span = hir_ty.span;
}
if let hir::GenericArg::Type(hir_ty) = &arg
&& let Some(ty) =
self.typeck_results.borrow().node_type_opt(hir_ty.hir_id)
&& self.resolve_vars_if_possible(ty) == predicate.self_ty()
{
error.obligation.cause.span = hir_ty.span;
break;
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/test/ui/argument-suggestions/issue-100154.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
fn foo(i: impl std::fmt::Display) {}

fn main() {
foo::<()>(());
//~^ ERROR this function takes 0 generic arguments but 1 generic argument was supplied
//~| ERROR `()` doesn't implement `std::fmt::Display`
}
35 changes: 35 additions & 0 deletions src/test/ui/argument-suggestions/issue-100154.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
error[E0107]: this function takes 0 generic arguments but 1 generic argument was supplied
--> $DIR/issue-100154.rs:4:5
|
LL | foo::<()>(());
| ^^^------ help: remove these generics
| |
| expected 0 generic arguments
|
note: function defined here, with 0 generic parameters
--> $DIR/issue-100154.rs:1:4
|
LL | fn foo(i: impl std::fmt::Display) {}
| ^^^
= note: `impl Trait` cannot be explicitly specified as a generic argument

error[E0277]: `()` doesn't implement `std::fmt::Display`
--> $DIR/issue-100154.rs:4:15
|
LL | foo::<()>(());
| --------- ^^ `()` cannot be formatted with the default formatter
| |
| required by a bound introduced by this call
|
= help: the trait `std::fmt::Display` is not implemented for `()`
= note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
note: required by a bound in `foo`
--> $DIR/issue-100154.rs:1:16
|
LL | fn foo(i: impl std::fmt::Display) {}
| ^^^^^^^^^^^^^^^^^ required by this bound in `foo`

error: aborting due to 2 previous errors

Some errors have detailed explanations: E0107, E0277.
For more information about an error, try `rustc --explain E0107`.
9 changes: 8 additions & 1 deletion src/test/ui/impl-trait/issues/issue-86800.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
#![feature(type_alias_impl_trait)]

// edition:2021
// unset-rustc-env:RUST_BACKTRACE
// compile-flags:-Z treat-err-as-bug=1
// error-pattern:stack backtrace:
// failure-status:101
// normalize-stderr-test "note: .*" -> ""
// normalize-stderr-test "thread 'rustc' .*" -> ""
// normalize-stderr-test " +[0-9]+:.*\n" -> ""
// normalize-stderr-test " +at .*\n" -> ""

use std::future::Future;

Expand All @@ -23,7 +31,6 @@ struct Context {
type TransactionResult<O> = Result<O, ()>;

type TransactionFuture<'__, O> = impl '__ + Future<Output = TransactionResult<O>>;
//~^ ERROR unconstrained opaque type

fn execute_transaction_fut<'f, F, O>(
f: F,
Expand Down
25 changes: 17 additions & 8 deletions src/test/ui/impl-trait/issues/issue-86800.stderr
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
error: unconstrained opaque type
--> $DIR/issue-86800.rs:25:34
|
LL | type TransactionFuture<'__, O> = impl '__ + Future<Output = TransactionResult<O>>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `TransactionFuture` must be used in combination with a concrete type within the same module

error: aborting due to previous error
stack backtrace:

error: internal compiler error: unexpected panic









query stack during panic:
#0 [mir_borrowck] borrow-checking `execute_transaction_fut`
#1 [type_of] computing type of `TransactionFuture::{opaque#0}`
#2 [check_mod_item_types] checking item types in top-level module
#3 [analysis] running analysis passes on this crate
end of query stack
10 changes: 6 additions & 4 deletions src/test/ui/impl-trait/nested-return-type2-tait.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#![feature(type_alias_impl_trait)]

// check-pass

trait Duh {}

impl Duh for i32 {}
Expand All @@ -17,13 +19,13 @@ impl<R: Duh, F: FnMut() -> R> Trait for F {

type Sendable = impl Send;

// The `Sendable` here is then later compared against the inference var
// created, causing the inference var to be set to `Sendable` instead of
// The `Sendable` here is converted to an inference var and then later compared
// against the inference var created, causing the inference var to be set to
// the hidden type of `Sendable` instead of
// the hidden type. We already have obligations registered on the inference
// var to make it uphold the `: Duh` bound on `Trait::Assoc`. The opaque
// type does not implement `Duh`, even if its hidden type does. So we error out.
// type does not implement `Duh`, but if its hidden type does.
fn foo() -> impl Trait<Assoc = Sendable> {
//~^ ERROR `Sendable: Duh` is not satisfied
|| 42
}

Expand Down
16 changes: 0 additions & 16 deletions src/test/ui/impl-trait/nested-return-type2-tait.stderr

This file was deleted.

2 changes: 1 addition & 1 deletion src/test/ui/impl-trait/nested-return-type2-tait2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ type Traitable = impl Trait<Assoc = Sendable>;
// var to make it uphold the `: Duh` bound on `Trait::Assoc`. The opaque
// type does not implement `Duh`, even if its hidden type does. So we error out.
fn foo() -> Traitable {
//~^ ERROR `Sendable: Duh` is not satisfied
|| 42
//~^ ERROR `Sendable: Duh` is not satisfied
}

fn main() {
Expand Down
8 changes: 4 additions & 4 deletions src/test/ui/impl-trait/nested-return-type2-tait2.stderr
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
error[E0277]: the trait bound `Sendable: Duh` is not satisfied
--> $DIR/nested-return-type2-tait2.rs:26:13
--> $DIR/nested-return-type2-tait2.rs:27:5
|
LL | fn foo() -> Traitable {
| ^^^^^^^^^ the trait `Duh` is not implemented for `Sendable`
LL | || 42
| ^^^^^ the trait `Duh` is not implemented for `Sendable`
|
= help: the trait `Duh` is implemented for `i32`
note: required because of the requirements on the impl of `Trait` for `[closure@$DIR/nested-return-type2-tait2.rs:28:5: 28:7]`
note: required because of the requirements on the impl of `Trait` for `[closure@$DIR/nested-return-type2-tait2.rs:27:5: 27:7]`
--> $DIR/nested-return-type2-tait2.rs:14:31
|
LL | impl<R: Duh, F: FnMut() -> R> Trait for F {
Expand Down