Skip to content

Commit a6fbd1c

Browse files
committed
Auto merge of #113968 - matthiaskrgr:rollup-7vdfcba, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - #112508 (Tweak spans for self arg, fix borrow suggestion for signature mismatch) - #113901 (Get rid of subst-relate incompleteness in new solver) - #113948 (Fix rustc-args passing issue in bootstrap) - #113950 (Remove Scope::Elision from bound-vars resolution.) - #113957 (Add regression test for issue #113941 - naive layout isn't refined) - #113959 (Migrate GUI colors test to original CSS color format) r? `@ghost` `@rustbot` modify labels: rollup
2 parents c399954 + 5215343 commit a6fbd1c

24 files changed

+217
-110
lines changed

compiler/rustc_ast/src/ast.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -2353,7 +2353,12 @@ impl Param {
23532353
/// Builds a `Param` object from `ExplicitSelf`.
23542354
pub fn from_self(attrs: AttrVec, eself: ExplicitSelf, eself_ident: Ident) -> Param {
23552355
let span = eself.span.to(eself_ident.span);
2356-
let infer_ty = P(Ty { id: DUMMY_NODE_ID, kind: TyKind::ImplicitSelf, span, tokens: None });
2356+
let infer_ty = P(Ty {
2357+
id: DUMMY_NODE_ID,
2358+
kind: TyKind::ImplicitSelf,
2359+
span: eself_ident.span,
2360+
tokens: None,
2361+
});
23572362
let (mutbl, ty) = match eself.node {
23582363
SelfKind::Explicit(ty, mutbl) => (mutbl, ty),
23592364
SelfKind::Value(mutbl) => (mutbl, infer_ty),

compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs

+21-38
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,6 @@ enum Scope<'a> {
137137
s: ScopeRef<'a>,
138138
},
139139

140-
/// A scope which either determines unspecified lifetimes or errors
141-
/// on them (e.g., due to ambiguity).
142-
Elision {
143-
s: ScopeRef<'a>,
144-
},
145-
146140
/// Use a specific lifetime (if `Some`) or leave it unset (to be
147141
/// inferred in a function body or potentially error outside one),
148142
/// for the default choice of lifetime in a trait object type.
@@ -211,7 +205,6 @@ impl<'a> fmt::Debug for TruncatedScopeDebug<'a> {
211205
Scope::Body { id, s: _ } => {
212206
f.debug_struct("Body").field("id", id).field("s", &"..").finish()
213207
}
214-
Scope::Elision { s: _ } => f.debug_struct("Elision").field("s", &"..").finish(),
215208
Scope::ObjectLifetimeDefault { lifetime, s: _ } => f
216209
.debug_struct("ObjectLifetimeDefault")
217210
.field("lifetime", lifetime)
@@ -325,9 +318,7 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
325318
break (vec![], BinderScopeType::Normal);
326319
}
327320

328-
Scope::Elision { s, .. }
329-
| Scope::ObjectLifetimeDefault { s, .. }
330-
| Scope::AnonConstBoundary { s } => {
321+
Scope::ObjectLifetimeDefault { s, .. } | Scope::AnonConstBoundary { s } => {
331322
scope = s;
332323
}
333324

@@ -526,16 +517,12 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
526517
| hir::ItemKind::Macro(..)
527518
| hir::ItemKind::Mod(..)
528519
| hir::ItemKind::ForeignMod { .. }
520+
| hir::ItemKind::Static(..)
521+
| hir::ItemKind::Const(..)
529522
| hir::ItemKind::GlobalAsm(..) => {
530523
// These sorts of items have no lifetime parameters at all.
531524
intravisit::walk_item(self, item);
532525
}
533-
hir::ItemKind::Static(..) | hir::ItemKind::Const(..) => {
534-
// No lifetime parameters, but implied 'static.
535-
self.with(Scope::Elision { s: self.scope }, |this| {
536-
intravisit::walk_item(this, item)
537-
});
538-
}
539526
hir::ItemKind::OpaqueTy(hir::OpaqueTy {
540527
origin: hir::OpaqueTyOrigin::TyAlias { .. },
541528
..
@@ -727,12 +714,7 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
727714
// Elided lifetimes are not allowed in non-return
728715
// position impl Trait
729716
let scope = Scope::TraitRefBoundary { s: self.scope };
730-
self.with(scope, |this| {
731-
let scope = Scope::Elision { s: this.scope };
732-
this.with(scope, |this| {
733-
intravisit::walk_item(this, opaque_ty);
734-
})
735-
});
717+
self.with(scope, |this| intravisit::walk_item(this, opaque_ty));
736718

737719
return;
738720
}
@@ -1293,8 +1275,7 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
12931275
scope = s;
12941276
}
12951277

1296-
Scope::Elision { s, .. }
1297-
| Scope::ObjectLifetimeDefault { s, .. }
1278+
Scope::ObjectLifetimeDefault { s, .. }
12981279
| Scope::Supertrait { s, .. }
12991280
| Scope::TraitRefBoundary { s, .. }
13001281
| Scope::AnonConstBoundary { s } => {
@@ -1357,7 +1338,6 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
13571338
Scope::Root { .. } => break,
13581339
Scope::Binder { s, .. }
13591340
| Scope::Body { s, .. }
1360-
| Scope::Elision { s, .. }
13611341
| Scope::ObjectLifetimeDefault { s, .. }
13621342
| Scope::Supertrait { s, .. }
13631343
| Scope::TraitRefBoundary { s, .. }
@@ -1409,8 +1389,7 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
14091389
scope = s;
14101390
}
14111391

1412-
Scope::Elision { s, .. }
1413-
| Scope::ObjectLifetimeDefault { s, .. }
1392+
Scope::ObjectLifetimeDefault { s, .. }
14141393
| Scope::Supertrait { s, .. }
14151394
| Scope::TraitRefBoundary { s, .. } => {
14161395
scope = s;
@@ -1483,7 +1462,6 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
14831462
Scope::Root { .. } => break,
14841463
Scope::Binder { s, .. }
14851464
| Scope::Body { s, .. }
1486-
| Scope::Elision { s, .. }
14871465
| Scope::ObjectLifetimeDefault { s, .. }
14881466
| Scope::Supertrait { s, .. }
14891467
| Scope::TraitRefBoundary { s, .. }
@@ -1564,7 +1542,6 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
15641542
Scope::Body { .. } => break true,
15651543

15661544
Scope::Binder { s, .. }
1567-
| Scope::Elision { s, .. }
15681545
| Scope::ObjectLifetimeDefault { s, .. }
15691546
| Scope::Supertrait { s, .. }
15701547
| Scope::TraitRefBoundary { s, .. }
@@ -1832,14 +1809,20 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
18321809
output: Option<&'tcx hir::Ty<'tcx>>,
18331810
in_closure: bool,
18341811
) {
1835-
self.with(Scope::Elision { s: self.scope }, |this| {
1836-
for input in inputs {
1837-
this.visit_ty(input);
1838-
}
1839-
if !in_closure && let Some(output) = output {
1840-
this.visit_ty(output);
1841-
}
1842-
});
1812+
self.with(
1813+
Scope::ObjectLifetimeDefault {
1814+
lifetime: Some(ResolvedArg::StaticLifetime),
1815+
s: self.scope,
1816+
},
1817+
|this| {
1818+
for input in inputs {
1819+
this.visit_ty(input);
1820+
}
1821+
if !in_closure && let Some(output) = output {
1822+
this.visit_ty(output);
1823+
}
1824+
},
1825+
);
18431826
if in_closure && let Some(output) = output {
18441827
self.visit_ty(output);
18451828
}
@@ -1859,7 +1842,7 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
18591842
scope = s;
18601843
}
18611844

1862-
Scope::Root { .. } | Scope::Elision { .. } => break ResolvedArg::StaticLifetime,
1845+
Scope::Root { .. } => break ResolvedArg::StaticLifetime,
18631846

18641847
Scope::Body { .. } | Scope::ObjectLifetimeDefault { lifetime: None, .. } => return,
18651848

compiler/rustc_trait_selection/messages.ftl

+10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
trait_selection_adjust_signature_borrow = consider adjusting the signature so it borrows its {$len ->
2+
[one] argument
3+
*[other] arguments
4+
}
5+
6+
trait_selection_adjust_signature_remove_borrow = consider adjusting the signature so it does not borrow its {$len ->
7+
[one] argument
8+
*[other] arguments
9+
}
10+
111
trait_selection_dump_vtable_entries = vtable entries for `{$trait_ref}`: {$entries}
212
313
trait_selection_empty_on_clause_in_rustc_on_unimplemented = empty `on`-clause in `#[rustc_on_unimplemented]`

compiler/rustc_trait_selection/src/errors.rs

+35-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
use crate::fluent_generated as fluent;
2-
use rustc_errors::{ErrorGuaranteed, Handler, IntoDiagnostic};
2+
use rustc_errors::{
3+
AddToDiagnostic, Applicability, Diagnostic, ErrorGuaranteed, Handler, IntoDiagnostic,
4+
SubdiagnosticMessage,
5+
};
36
use rustc_macros::Diagnostic;
47
use rustc_middle::ty::{self, PolyTraitRef, Ty};
58
use rustc_span::{Span, Symbol};
@@ -97,3 +100,34 @@ pub struct InherentProjectionNormalizationOverflow {
97100
pub span: Span,
98101
pub ty: String,
99102
}
103+
104+
pub enum AdjustSignatureBorrow {
105+
Borrow { to_borrow: Vec<(Span, String)> },
106+
RemoveBorrow { remove_borrow: Vec<(Span, String)> },
107+
}
108+
109+
impl AddToDiagnostic for AdjustSignatureBorrow {
110+
fn add_to_diagnostic_with<F>(self, diag: &mut Diagnostic, _: F)
111+
where
112+
F: Fn(&mut Diagnostic, SubdiagnosticMessage) -> SubdiagnosticMessage,
113+
{
114+
match self {
115+
AdjustSignatureBorrow::Borrow { to_borrow } => {
116+
diag.set_arg("len", to_borrow.len());
117+
diag.multipart_suggestion_verbose(
118+
fluent::trait_selection_adjust_signature_borrow,
119+
to_borrow,
120+
Applicability::MaybeIncorrect,
121+
);
122+
}
123+
AdjustSignatureBorrow::RemoveBorrow { remove_borrow } => {
124+
diag.set_arg("len", remove_borrow.len());
125+
diag.multipart_suggestion_verbose(
126+
fluent::trait_selection_adjust_signature_remove_borrow,
127+
remove_borrow,
128+
Applicability::MaybeIncorrect,
129+
);
130+
}
131+
}
132+
}
133+
}

compiler/rustc_trait_selection/src/solve/alias_relate.rs

+12-9
Original file line numberDiff line numberDiff line change
@@ -66,24 +66,27 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
6666
Invert::Yes,
6767
));
6868
// Relate via args
69-
let subst_relate_response = self
70-
.assemble_subst_relate_candidate(param_env, alias_lhs, alias_rhs, direction);
71-
candidates.extend(subst_relate_response);
69+
candidates.extend(
70+
self.assemble_subst_relate_candidate(
71+
param_env, alias_lhs, alias_rhs, direction,
72+
),
73+
);
7274
debug!(?candidates);
7375

7476
if let Some(merged) = self.try_merge_responses(&candidates) {
7577
Ok(merged)
7678
} else {
77-
// When relating two aliases and we have ambiguity, we prefer
78-
// relating the generic arguments of the aliases over normalizing
79-
// them. This is necessary for inference during typeck.
79+
// When relating two aliases and we have ambiguity, if both
80+
// aliases can be normalized to something, we prefer
81+
// "bidirectionally normalizing" both of them within the same
82+
// candidate.
83+
//
84+
// See <https://github.com/rust-lang/trait-system-refactor-initiative/issues/25>.
8085
//
8186
// As this is incomplete, we must not do so during coherence.
8287
match self.solver_mode() {
8388
SolverMode::Normal => {
84-
if let Ok(subst_relate_response) = subst_relate_response {
85-
Ok(subst_relate_response)
86-
} else if let Ok(bidirectional_normalizes_to_response) = self
89+
if let Ok(bidirectional_normalizes_to_response) = self
8790
.assemble_bidirectional_normalizes_to_candidate(
8891
param_env, lhs, rhs, direction,
8992
)

compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

+7-10
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use super::{
55
PredicateObligation,
66
};
77

8+
use crate::errors;
89
use crate::infer::InferCtxt;
910
use crate::traits::{NormalizeExt, ObligationCtxt};
1011

@@ -4031,6 +4032,10 @@ fn hint_missing_borrow<'tcx>(
40314032
found_node: Node<'_>,
40324033
err: &mut Diagnostic,
40334034
) {
4035+
if matches!(found_node, Node::TraitItem(..)) {
4036+
return;
4037+
}
4038+
40344039
let found_args = match found.kind() {
40354040
ty::FnPtr(f) => infcx.instantiate_binder_with_placeholders(*f).inputs().iter(),
40364041
kind => {
@@ -4102,19 +4107,11 @@ fn hint_missing_borrow<'tcx>(
41024107
}
41034108

41044109
if !to_borrow.is_empty() {
4105-
err.multipart_suggestion_verbose(
4106-
"consider borrowing the argument",
4107-
to_borrow,
4108-
Applicability::MaybeIncorrect,
4109-
);
4110+
err.subdiagnostic(errors::AdjustSignatureBorrow::Borrow { to_borrow });
41104111
}
41114112

41124113
if !remove_borrow.is_empty() {
4113-
err.multipart_suggestion_verbose(
4114-
"do not borrow the argument",
4115-
remove_borrow,
4116-
Applicability::MaybeIncorrect,
4117-
);
4114+
err.subdiagnostic(errors::AdjustSignatureBorrow::RemoveBorrow { remove_borrow });
41184115
}
41194116
}
41204117

src/bootstrap/builder.rs

+7
Original file line numberDiff line numberDiff line change
@@ -2043,6 +2043,13 @@ impl<'a> Builder<'a> {
20432043
rustflags.arg("-Zinline-mir");
20442044
}
20452045

2046+
// set rustc args passed from command line
2047+
let rustc_args =
2048+
self.config.cmd.rustc_args().iter().map(|s| s.to_string()).collect::<Vec<_>>();
2049+
if !rustc_args.is_empty() {
2050+
cargo.env("RUSTFLAGS", &rustc_args.join(" "));
2051+
}
2052+
20462053
Cargo { command: cargo, rustflags, rustdocflags, allow_features }
20472054
}
20482055

tests/rustdoc-gui/item-decl-colors.goml

+25-24
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ define-function: (
2020
block {
2121
go-to: "file://" + |DOC_PATH| + "/test_docs/struct.WithGenerics.html"
2222
show-text: true
23+
2324
set-local-storage: {"rustdoc-theme": |theme|, "rustdoc-use-system-theme": "false"}
2425
reload:
2526
assert-css: (".item-decl .code-attribute", {"color": |attr_color|}, ALL)
@@ -40,41 +41,41 @@ call-function: (
4041
"check-colors",
4142
{
4243
"theme": "ayu",
43-
"attr_color": "rgb(153, 153, 153)",
44-
"trait_color": "rgb(57, 175, 215)",
45-
"struct_color": "rgb(255, 160, 165)",
46-
"enum_color": "rgb(255, 160, 165)",
47-
"primitive_color": "rgb(255, 160, 165)",
48-
"constant_color": "rgb(57, 175, 215)",
49-
"fn_color": "rgb(253, 214, 135)",
50-
"assoc_type_color": "rgb(57, 175, 215)",
44+
"attr_color": "#999",
45+
"trait_color": "#39afd7",
46+
"struct_color": "#ffa0a5",
47+
"enum_color": "#ffa0a5",
48+
"primitive_color": "#ffa0a5",
49+
"constant_color": "#39afd7",
50+
"fn_color": "#fdd687",
51+
"assoc_type_color": "#39afd7",
5152
},
5253
)
5354
call-function: (
5455
"check-colors",
5556
{
5657
"theme": "dark",
57-
"attr_color": "rgb(153, 153, 153)",
58-
"trait_color": "rgb(183, 140, 242)",
59-
"struct_color": "rgb(45, 191, 184)",
60-
"enum_color": "rgb(45, 191, 184)",
61-
"primitive_color": "rgb(45, 191, 184)",
62-
"constant_color": "rgb(210, 153, 29)",
63-
"fn_color": "rgb(43, 171, 99)",
64-
"assoc_type_color": "rgb(210, 153, 29)",
58+
"attr_color": "#999",
59+
"trait_color": "#b78cf2",
60+
"struct_color": "#2dbfb8",
61+
"enum_color": "#2dbfb8",
62+
"primitive_color": "#2dbfb8",
63+
"constant_color": "#d2991d",
64+
"fn_color": "#2bab63",
65+
"assoc_type_color": "#d2991d",
6566
},
6667
)
6768
call-function: (
6869
"check-colors",
6970
{
7071
"theme": "light",
71-
"attr_color": "rgb(153, 153, 153)",
72-
"trait_color": "rgb(110, 79, 201)",
73-
"struct_color": "rgb(173, 55, 138)",
74-
"enum_color": "rgb(173, 55, 138)",
75-
"primitive_color": "rgb(173, 55, 138)",
76-
"constant_color": "rgb(56, 115, 173)",
77-
"fn_color": "rgb(173, 124, 55)",
78-
"assoc_type_color": "rgb(56, 115, 173)",
72+
"attr_color": "#999",
73+
"trait_color": "#6e4fc9",
74+
"struct_color": "#ad378a",
75+
"enum_color": "#ad378a",
76+
"primitive_color": "#ad378a",
77+
"constant_color": "#3873ad",
78+
"fn_color": "#ad7c37",
79+
"assoc_type_color": "#3873ad",
7980
},
8081
)

0 commit comments

Comments
 (0)