Skip to content

Commit 4497ac9

Browse files
committed
Auto merge of rust-lang#101221 - ehuss:update-beta-cargo, r=ehuss
[BETA] Beta 1.64 backports * Cargo: * remove missed reference to workspace inheritance in unstable.md (rust-lang/cargo#11002) * Delay formatting trimmed path until lint/error is emitted rust-lang#99893 * Use `node_type_opt` to skip over generics that were not expected rust-lang#100155 * Revert "Remove a back-compat hack on lazy TAIT rust-lang#97346" rust-lang#99860
2 parents 82bf341 + cff90fe commit 4497ac9

22 files changed

+181
-95
lines changed

compiler/rustc_errors/src/diagnostic.rs

+20
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,26 @@ pub trait IntoDiagnosticArg {
4040
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static>;
4141
}
4242

43+
pub struct DiagnosticArgFromDisplay<'a>(pub &'a dyn fmt::Display);
44+
45+
impl IntoDiagnosticArg for DiagnosticArgFromDisplay<'_> {
46+
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
47+
self.0.to_string().into_diagnostic_arg()
48+
}
49+
}
50+
51+
impl<'a> From<&'a dyn fmt::Display> for DiagnosticArgFromDisplay<'a> {
52+
fn from(t: &'a dyn fmt::Display) -> Self {
53+
DiagnosticArgFromDisplay(t)
54+
}
55+
}
56+
57+
impl<'a, T: fmt::Display> From<&'a T> for DiagnosticArgFromDisplay<'a> {
58+
fn from(t: &'a T) -> Self {
59+
DiagnosticArgFromDisplay(t)
60+
}
61+
}
62+
4363
macro_rules! into_diagnostic_arg_using_display {
4464
($( $ty:ty ),+ $(,)?) => {
4565
$(

compiler/rustc_errors/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -371,8 +371,8 @@ impl fmt::Display for ExplicitBug {
371371
impl error::Error for ExplicitBug {}
372372

373373
pub use diagnostic::{
374-
AddSubdiagnostic, DecorateLint, Diagnostic, DiagnosticArg, DiagnosticArgValue, DiagnosticId,
375-
DiagnosticStyledString, IntoDiagnosticArg, SubDiagnostic,
374+
AddSubdiagnostic, DecorateLint, Diagnostic, DiagnosticArg, DiagnosticArgFromDisplay,
375+
DiagnosticArgValue, DiagnosticId, DiagnosticStyledString, IntoDiagnosticArg, SubDiagnostic,
376376
};
377377
pub use diagnostic_builder::{DiagnosticBuilder, EmissionGuarantee, LintDiagnosticBuilder};
378378
use std::backtrace::Backtrace;

compiler/rustc_infer/src/infer/opaque_types.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -40,23 +40,25 @@ pub struct OpaqueTypeDecl<'tcx> {
4040
}
4141

4242
impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
43-
pub fn replace_opaque_types_with_inference_vars(
43+
/// This is a backwards compatibility hack to prevent breaking changes from
44+
/// lazy TAIT around RPIT handling.
45+
pub fn replace_opaque_types_with_inference_vars<T: TypeFoldable<'tcx>>(
4446
&self,
45-
ty: Ty<'tcx>,
47+
value: T,
4648
body_id: HirId,
4749
span: Span,
4850
param_env: ty::ParamEnv<'tcx>,
49-
) -> InferOk<'tcx, Ty<'tcx>> {
50-
if !ty.has_opaque_types() {
51-
return InferOk { value: ty, obligations: vec![] };
51+
) -> InferOk<'tcx, T> {
52+
if !value.has_opaque_types() {
53+
return InferOk { value, obligations: vec![] };
5254
}
5355
let mut obligations = vec![];
5456
let replace_opaque_type = |def_id: DefId| {
5557
def_id
5658
.as_local()
5759
.map_or(false, |def_id| self.opaque_type_origin(def_id, span).is_some())
5860
};
59-
let value = ty.fold_with(&mut ty::fold::BottomUpFolder {
61+
let value = value.fold_with(&mut ty::fold::BottomUpFolder {
6062
tcx: self.tcx,
6163
lt_op: |lt| lt,
6264
ct_op: |ct| ct,

compiler/rustc_privacy/src/errors.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use rustc_errors::DiagnosticArgFromDisplay;
12
use rustc_macros::{LintDiagnostic, SessionDiagnostic, SessionSubdiagnostic};
23
use rustc_span::{Span, Symbol};
34

@@ -35,7 +36,7 @@ pub struct ItemIsPrivate<'a> {
3536
#[label]
3637
pub span: Span,
3738
pub kind: &'a str,
38-
pub descr: String,
39+
pub descr: DiagnosticArgFromDisplay<'a>,
3940
}
4041

4142
#[derive(SessionDiagnostic)]
@@ -55,7 +56,7 @@ pub struct InPublicInterfaceTraits<'a> {
5556
pub span: Span,
5657
pub vis_descr: &'static str,
5758
pub kind: &'a str,
58-
pub descr: String,
59+
pub descr: DiagnosticArgFromDisplay<'a>,
5960
#[label(privacy::visibility_label)]
6061
pub vis_span: Span,
6162
}
@@ -69,7 +70,7 @@ pub struct InPublicInterface<'a> {
6970
pub span: Span,
7071
pub vis_descr: &'static str,
7172
pub kind: &'a str,
72-
pub descr: String,
73+
pub descr: DiagnosticArgFromDisplay<'a>,
7374
#[label(privacy::visibility_label)]
7475
pub vis_span: Span,
7576
}
@@ -78,7 +79,7 @@ pub struct InPublicInterface<'a> {
7879
#[lint(privacy::from_private_dep_in_public_interface)]
7980
pub struct FromPrivateDependencyInPublicInterface<'a> {
8081
pub kind: &'a str,
81-
pub descr: String,
82+
pub descr: DiagnosticArgFromDisplay<'a>,
8283
pub krate: Symbol,
8384
}
8485

@@ -87,5 +88,5 @@ pub struct FromPrivateDependencyInPublicInterface<'a> {
8788
pub struct PrivateInPublicLint<'a> {
8889
pub vis_descr: &'static str,
8990
pub kind: &'a str,
90-
pub descr: String,
91+
pub descr: DiagnosticArgFromDisplay<'a>,
9192
}

compiler/rustc_privacy/src/lib.rs

+8-11
Original file line numberDiff line numberDiff line change
@@ -1079,11 +1079,7 @@ impl<'tcx> TypePrivacyVisitor<'tcx> {
10791079
fn check_def_id(&mut self, def_id: DefId, kind: &str, descr: &dyn fmt::Display) -> bool {
10801080
let is_error = !self.item_is_accessible(def_id);
10811081
if is_error {
1082-
self.tcx.sess.emit_err(ItemIsPrivate {
1083-
span: self.span,
1084-
kind,
1085-
descr: descr.to_string(),
1086-
});
1082+
self.tcx.sess.emit_err(ItemIsPrivate { span: self.span, kind, descr: descr.into() });
10871083
}
10881084
is_error
10891085
}
@@ -1255,7 +1251,9 @@ impl<'tcx> Visitor<'tcx> for TypePrivacyVisitor<'tcx> {
12551251
};
12561252
let kind = kind.descr(def_id);
12571253
let _ = match name {
1258-
Some(name) => sess.emit_err(ItemIsPrivate { span, kind, descr: name }),
1254+
Some(name) => {
1255+
sess.emit_err(ItemIsPrivate { span, kind, descr: (&name).into() })
1256+
}
12591257
None => sess.emit_err(UnnamedItemIsPrivate { span, kind }),
12601258
};
12611259
return;
@@ -1723,7 +1721,7 @@ impl SearchInterfaceForPrivateItemsVisitor<'_> {
17231721
self.tcx.def_span(self.item_def_id.to_def_id()),
17241722
FromPrivateDependencyInPublicInterface {
17251723
kind,
1726-
descr: descr.to_string(),
1724+
descr: descr.into(),
17271725
krate: self.tcx.crate_name(def_id.krate),
17281726
},
17291727
);
@@ -1750,7 +1748,6 @@ impl SearchInterfaceForPrivateItemsVisitor<'_> {
17501748
}
17511749
};
17521750
let span = self.tcx.def_span(self.item_def_id.to_def_id());
1753-
let descr = descr.to_string();
17541751
if self.has_old_errors
17551752
|| self.in_assoc_ty
17561753
|| self.tcx.resolutions(()).has_pub_restricted
@@ -1761,15 +1758,15 @@ impl SearchInterfaceForPrivateItemsVisitor<'_> {
17611758
span,
17621759
vis_descr,
17631760
kind,
1764-
descr,
1761+
descr: descr.into(),
17651762
vis_span,
17661763
});
17671764
} else {
17681765
self.tcx.sess.emit_err(InPublicInterface {
17691766
span,
17701767
vis_descr,
17711768
kind,
1772-
descr,
1769+
descr: descr.into(),
17731770
vis_span,
17741771
});
17751772
}
@@ -1778,7 +1775,7 @@ impl SearchInterfaceForPrivateItemsVisitor<'_> {
17781775
lint::builtin::PRIVATE_IN_PUBLIC,
17791776
hir_id,
17801777
span,
1781-
PrivateInPublicLint { vis_descr, kind, descr },
1778+
PrivateInPublicLint { vis_descr, kind, descr: descr.into() },
17821779
);
17831780
}
17841781
}

compiler/rustc_trait_selection/src/traits/project.rs

+14-4
Original file line numberDiff line numberDiff line change
@@ -252,10 +252,20 @@ fn project_and_unify_type<'cx, 'tcx>(
252252
Err(InProgress) => return ProjectAndUnifyResult::Recursive,
253253
};
254254
debug!(?normalized, ?obligations, "project_and_unify_type result");
255-
match infcx
256-
.at(&obligation.cause, obligation.param_env)
257-
.eq(normalized, obligation.predicate.term)
258-
{
255+
let actual = obligation.predicate.term;
256+
// For an example where this is neccessary see src/test/ui/impl-trait/nested-return-type2.rs
257+
// This allows users to omit re-mentioning all bounds on an associated type and just use an
258+
// `impl Trait` for the assoc type to add more bounds.
259+
let InferOk { value: actual, obligations: new } =
260+
selcx.infcx().replace_opaque_types_with_inference_vars(
261+
actual,
262+
obligation.cause.body_id,
263+
obligation.cause.span,
264+
obligation.param_env,
265+
);
266+
obligations.extend(new);
267+
268+
match infcx.at(&obligation.cause, obligation.param_env).eq(normalized, actual) {
259269
Ok(InferOk { obligations: inferred_obligations, value: () }) => {
260270
obligations.extend(inferred_obligations);
261271
ProjectAndUnifyResult::Holds(obligations)

compiler/rustc_typeck/src/check/fn_ctxt/checks.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -1761,13 +1761,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
17611761
.filter_map(|seg| seg.args.as_ref())
17621762
.flat_map(|a| a.args.iter())
17631763
{
1764-
if let hir::GenericArg::Type(hir_ty) = &arg {
1765-
let ty = self.resolve_vars_if_possible(
1766-
self.typeck_results.borrow().node_type(hir_ty.hir_id),
1767-
);
1768-
if ty == predicate.self_ty() {
1769-
error.obligation.cause.span = hir_ty.span;
1770-
}
1764+
if let hir::GenericArg::Type(hir_ty) = &arg
1765+
&& let Some(ty) =
1766+
self.typeck_results.borrow().node_type_opt(hir_ty.hir_id)
1767+
&& self.resolve_vars_if_possible(ty) == predicate.self_ty()
1768+
{
1769+
error.obligation.cause.span = hir_ty.span;
1770+
break;
17711771
}
17721772
}
17731773
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
fn foo(i: impl std::fmt::Display) {}
2+
3+
fn main() {
4+
foo::<()>(());
5+
//~^ ERROR this function takes 0 generic arguments but 1 generic argument was supplied
6+
//~| ERROR `()` doesn't implement `std::fmt::Display`
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
error[E0107]: this function takes 0 generic arguments but 1 generic argument was supplied
2+
--> $DIR/issue-100154.rs:4:5
3+
|
4+
LL | foo::<()>(());
5+
| ^^^------ help: remove these generics
6+
| |
7+
| expected 0 generic arguments
8+
|
9+
note: function defined here, with 0 generic parameters
10+
--> $DIR/issue-100154.rs:1:4
11+
|
12+
LL | fn foo(i: impl std::fmt::Display) {}
13+
| ^^^
14+
= note: `impl Trait` cannot be explicitly specified as a generic argument
15+
16+
error[E0277]: `()` doesn't implement `std::fmt::Display`
17+
--> $DIR/issue-100154.rs:4:15
18+
|
19+
LL | foo::<()>(());
20+
| --------- ^^ `()` cannot be formatted with the default formatter
21+
| |
22+
| required by a bound introduced by this call
23+
|
24+
= help: the trait `std::fmt::Display` is not implemented for `()`
25+
= note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
26+
note: required by a bound in `foo`
27+
--> $DIR/issue-100154.rs:1:16
28+
|
29+
LL | fn foo(i: impl std::fmt::Display) {}
30+
| ^^^^^^^^^^^^^^^^^ required by this bound in `foo`
31+
32+
error: aborting due to 2 previous errors
33+
34+
Some errors have detailed explanations: E0107, E0277.
35+
For more information about an error, try `rustc --explain E0107`.

src/test/ui/impl-trait/issues/issue-86800.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
#![feature(type_alias_impl_trait)]
22

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

513
use std::future::Future;
614

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

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

2835
fn execute_transaction_fut<'f, F, O>(
2936
f: F,
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
1-
error: unconstrained opaque type
2-
--> $DIR/issue-86800.rs:25:34
3-
|
4-
LL | type TransactionFuture<'__, O> = impl '__ + Future<Output = TransactionResult<O>>;
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6-
|
7-
= note: `TransactionFuture` must be used in combination with a concrete type within the same module
81

9-
error: aborting due to previous error
2+
stack backtrace:
103

4+
error: internal compiler error: unexpected panic
5+
6+
7+
8+
9+
10+
11+
12+
13+
14+
query stack during panic:
15+
#0 [mir_borrowck] borrow-checking `execute_transaction_fut`
16+
#1 [type_of] computing type of `TransactionFuture::{opaque#0}`
17+
#2 [check_mod_item_types] checking item types in top-level module
18+
#3 [analysis] running analysis passes on this crate
19+
end of query stack

src/test/ui/impl-trait/nested-return-type2-tait.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#![feature(type_alias_impl_trait)]
22

3+
// check-pass
4+
35
trait Duh {}
46

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

1820
type Sendable = impl Send;
1921

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

src/test/ui/impl-trait/nested-return-type2-tait.stderr

-16
This file was deleted.

src/test/ui/impl-trait/nested-return-type2-tait2.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ type Traitable = impl Trait<Assoc = Sendable>;
2424
// var to make it uphold the `: Duh` bound on `Trait::Assoc`. The opaque
2525
// type does not implement `Duh`, even if its hidden type does. So we error out.
2626
fn foo() -> Traitable {
27-
//~^ ERROR `Sendable: Duh` is not satisfied
2827
|| 42
28+
//~^ ERROR `Sendable: Duh` is not satisfied
2929
}
3030

3131
fn main() {

src/test/ui/impl-trait/nested-return-type2-tait2.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
error[E0277]: the trait bound `Sendable: Duh` is not satisfied
2-
--> $DIR/nested-return-type2-tait2.rs:26:13
2+
--> $DIR/nested-return-type2-tait2.rs:27:5
33
|
4-
LL | fn foo() -> Traitable {
5-
| ^^^^^^^^^ the trait `Duh` is not implemented for `Sendable`
4+
LL | || 42
5+
| ^^^^^ the trait `Duh` is not implemented for `Sendable`
66
|
77
= help: the trait `Duh` is implemented for `i32`
8-
note: required because of the requirements on the impl of `Trait` for `[closure@$DIR/nested-return-type2-tait2.rs:28:5: 28:7]`
8+
note: required because of the requirements on the impl of `Trait` for `[closure@$DIR/nested-return-type2-tait2.rs:27:5: 27:7]`
99
--> $DIR/nested-return-type2-tait2.rs:14:31
1010
|
1111
LL | impl<R: Duh, F: FnMut() -> R> Trait for F {

0 commit comments

Comments
 (0)