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 6 pull requests #113968

Merged
merged 15 commits into from
Jul 22, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion compiler/rustc_ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2353,7 +2353,12 @@ impl Param {
/// Builds a `Param` object from `ExplicitSelf`.
pub fn from_self(attrs: AttrVec, eself: ExplicitSelf, eself_ident: Ident) -> Param {
let span = eself.span.to(eself_ident.span);
let infer_ty = P(Ty { id: DUMMY_NODE_ID, kind: TyKind::ImplicitSelf, span, tokens: None });
let infer_ty = P(Ty {
id: DUMMY_NODE_ID,
kind: TyKind::ImplicitSelf,
span: eself_ident.span,
tokens: None,
});
let (mutbl, ty) = match eself.node {
SelfKind::Explicit(ty, mutbl) => (mutbl, ty),
SelfKind::Value(mutbl) => (mutbl, infer_ty),
Expand Down
59 changes: 21 additions & 38 deletions compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,6 @@ enum Scope<'a> {
s: ScopeRef<'a>,
},

/// A scope which either determines unspecified lifetimes or errors
/// on them (e.g., due to ambiguity).
Elision {
s: ScopeRef<'a>,
},

/// Use a specific lifetime (if `Some`) or leave it unset (to be
/// inferred in a function body or potentially error outside one),
/// for the default choice of lifetime in a trait object type.
Expand Down Expand Up @@ -211,7 +205,6 @@ impl<'a> fmt::Debug for TruncatedScopeDebug<'a> {
Scope::Body { id, s: _ } => {
f.debug_struct("Body").field("id", id).field("s", &"..").finish()
}
Scope::Elision { s: _ } => f.debug_struct("Elision").field("s", &"..").finish(),
Scope::ObjectLifetimeDefault { lifetime, s: _ } => f
.debug_struct("ObjectLifetimeDefault")
.field("lifetime", lifetime)
Expand Down Expand Up @@ -325,9 +318,7 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
break (vec![], BinderScopeType::Normal);
}

Scope::Elision { s, .. }
| Scope::ObjectLifetimeDefault { s, .. }
| Scope::AnonConstBoundary { s } => {
Scope::ObjectLifetimeDefault { s, .. } | Scope::AnonConstBoundary { s } => {
scope = s;
}

Expand Down Expand Up @@ -526,16 +517,12 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
| hir::ItemKind::Macro(..)
| hir::ItemKind::Mod(..)
| hir::ItemKind::ForeignMod { .. }
| hir::ItemKind::Static(..)
| hir::ItemKind::Const(..)
| hir::ItemKind::GlobalAsm(..) => {
// These sorts of items have no lifetime parameters at all.
intravisit::walk_item(self, item);
}
hir::ItemKind::Static(..) | hir::ItemKind::Const(..) => {
// No lifetime parameters, but implied 'static.
self.with(Scope::Elision { s: self.scope }, |this| {
intravisit::walk_item(this, item)
});
}
hir::ItemKind::OpaqueTy(hir::OpaqueTy {
origin: hir::OpaqueTyOrigin::TyAlias { .. },
..
Expand Down Expand Up @@ -727,12 +714,7 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
// Elided lifetimes are not allowed in non-return
// position impl Trait
let scope = Scope::TraitRefBoundary { s: self.scope };
self.with(scope, |this| {
let scope = Scope::Elision { s: this.scope };
this.with(scope, |this| {
intravisit::walk_item(this, opaque_ty);
})
});
self.with(scope, |this| intravisit::walk_item(this, opaque_ty));

return;
}
Expand Down Expand Up @@ -1293,8 +1275,7 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
scope = s;
}

Scope::Elision { s, .. }
| Scope::ObjectLifetimeDefault { s, .. }
Scope::ObjectLifetimeDefault { s, .. }
| Scope::Supertrait { s, .. }
| Scope::TraitRefBoundary { s, .. }
| Scope::AnonConstBoundary { s } => {
Expand Down Expand Up @@ -1357,7 +1338,6 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
Scope::Root { .. } => break,
Scope::Binder { s, .. }
| Scope::Body { s, .. }
| Scope::Elision { s, .. }
| Scope::ObjectLifetimeDefault { s, .. }
| Scope::Supertrait { s, .. }
| Scope::TraitRefBoundary { s, .. }
Expand Down Expand Up @@ -1409,8 +1389,7 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
scope = s;
}

Scope::Elision { s, .. }
| Scope::ObjectLifetimeDefault { s, .. }
Scope::ObjectLifetimeDefault { s, .. }
| Scope::Supertrait { s, .. }
| Scope::TraitRefBoundary { s, .. } => {
scope = s;
Expand Down Expand Up @@ -1483,7 +1462,6 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
Scope::Root { .. } => break,
Scope::Binder { s, .. }
| Scope::Body { s, .. }
| Scope::Elision { s, .. }
| Scope::ObjectLifetimeDefault { s, .. }
| Scope::Supertrait { s, .. }
| Scope::TraitRefBoundary { s, .. }
Expand Down Expand Up @@ -1564,7 +1542,6 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
Scope::Body { .. } => break true,

Scope::Binder { s, .. }
| Scope::Elision { s, .. }
| Scope::ObjectLifetimeDefault { s, .. }
| Scope::Supertrait { s, .. }
| Scope::TraitRefBoundary { s, .. }
Expand Down Expand Up @@ -1832,14 +1809,20 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
output: Option<&'tcx hir::Ty<'tcx>>,
in_closure: bool,
) {
self.with(Scope::Elision { s: self.scope }, |this| {
for input in inputs {
this.visit_ty(input);
}
if !in_closure && let Some(output) = output {
this.visit_ty(output);
}
});
self.with(
Scope::ObjectLifetimeDefault {
lifetime: Some(ResolvedArg::StaticLifetime),
s: self.scope,
},
|this| {
for input in inputs {
this.visit_ty(input);
}
if !in_closure && let Some(output) = output {
this.visit_ty(output);
}
},
);
if in_closure && let Some(output) = output {
self.visit_ty(output);
}
Expand All @@ -1859,7 +1842,7 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
scope = s;
}

Scope::Root { .. } | Scope::Elision { .. } => break ResolvedArg::StaticLifetime,
Scope::Root { .. } => break ResolvedArg::StaticLifetime,

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

Expand Down
10 changes: 10 additions & 0 deletions compiler/rustc_trait_selection/messages.ftl
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
trait_selection_adjust_signature_borrow = consider adjusting the signature so it borrows its {$len ->
[one] argument
*[other] arguments
}

trait_selection_adjust_signature_remove_borrow = consider adjusting the signature so it does not borrow its {$len ->
[one] argument
*[other] arguments
}

trait_selection_dump_vtable_entries = vtable entries for `{$trait_ref}`: {$entries}

trait_selection_empty_on_clause_in_rustc_on_unimplemented = empty `on`-clause in `#[rustc_on_unimplemented]`
Expand Down
36 changes: 35 additions & 1 deletion compiler/rustc_trait_selection/src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use crate::fluent_generated as fluent;
use rustc_errors::{ErrorGuaranteed, Handler, IntoDiagnostic};
use rustc_errors::{
AddToDiagnostic, Applicability, Diagnostic, ErrorGuaranteed, Handler, IntoDiagnostic,
SubdiagnosticMessage,
};
use rustc_macros::Diagnostic;
use rustc_middle::ty::{self, PolyTraitRef, Ty};
use rustc_span::{Span, Symbol};
Expand Down Expand Up @@ -97,3 +100,34 @@ pub struct InherentProjectionNormalizationOverflow {
pub span: Span,
pub ty: String,
}

pub enum AdjustSignatureBorrow {
Borrow { to_borrow: Vec<(Span, String)> },
RemoveBorrow { remove_borrow: Vec<(Span, String)> },
}

impl AddToDiagnostic for AdjustSignatureBorrow {
fn add_to_diagnostic_with<F>(self, diag: &mut Diagnostic, _: F)
where
F: Fn(&mut Diagnostic, SubdiagnosticMessage) -> SubdiagnosticMessage,
{
match self {
AdjustSignatureBorrow::Borrow { to_borrow } => {
diag.set_arg("len", to_borrow.len());
diag.multipart_suggestion_verbose(
fluent::trait_selection_adjust_signature_borrow,
to_borrow,
Applicability::MaybeIncorrect,
);
}
AdjustSignatureBorrow::RemoveBorrow { remove_borrow } => {
diag.set_arg("len", remove_borrow.len());
diag.multipart_suggestion_verbose(
fluent::trait_selection_adjust_signature_remove_borrow,
remove_borrow,
Applicability::MaybeIncorrect,
);
}
}
}
}
21 changes: 12 additions & 9 deletions compiler/rustc_trait_selection/src/solve/alias_relate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,24 +66,27 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
Invert::Yes,
));
// Relate via args
let subst_relate_response = self
.assemble_subst_relate_candidate(param_env, alias_lhs, alias_rhs, direction);
candidates.extend(subst_relate_response);
candidates.extend(
self.assemble_subst_relate_candidate(
param_env, alias_lhs, alias_rhs, direction,
),
);
debug!(?candidates);

if let Some(merged) = self.try_merge_responses(&candidates) {
Ok(merged)
} else {
// When relating two aliases and we have ambiguity, we prefer
// relating the generic arguments of the aliases over normalizing
// them. This is necessary for inference during typeck.
// When relating two aliases and we have ambiguity, if both
// aliases can be normalized to something, we prefer
// "bidirectionally normalizing" both of them within the same
// candidate.
//
// See <https://github.com/rust-lang/trait-system-refactor-initiative/issues/25>.
//
// As this is incomplete, we must not do so during coherence.
match self.solver_mode() {
SolverMode::Normal => {
if let Ok(subst_relate_response) = subst_relate_response {
Ok(subst_relate_response)
} else if let Ok(bidirectional_normalizes_to_response) = self
if let Ok(bidirectional_normalizes_to_response) = self
.assemble_bidirectional_normalizes_to_candidate(
param_env, lhs, rhs, direction,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use super::{
PredicateObligation,
};

use crate::errors;
use crate::infer::InferCtxt;
use crate::traits::{NormalizeExt, ObligationCtxt};

Expand Down Expand Up @@ -4031,6 +4032,10 @@ fn hint_missing_borrow<'tcx>(
found_node: Node<'_>,
err: &mut Diagnostic,
) {
if matches!(found_node, Node::TraitItem(..)) {
return;
}

let found_args = match found.kind() {
ty::FnPtr(f) => infcx.instantiate_binder_with_placeholders(*f).inputs().iter(),
kind => {
Expand Down Expand Up @@ -4102,19 +4107,11 @@ fn hint_missing_borrow<'tcx>(
}

if !to_borrow.is_empty() {
err.multipart_suggestion_verbose(
"consider borrowing the argument",
to_borrow,
Applicability::MaybeIncorrect,
);
err.subdiagnostic(errors::AdjustSignatureBorrow::Borrow { to_borrow });
}

if !remove_borrow.is_empty() {
err.multipart_suggestion_verbose(
"do not borrow the argument",
remove_borrow,
Applicability::MaybeIncorrect,
);
err.subdiagnostic(errors::AdjustSignatureBorrow::RemoveBorrow { remove_borrow });
}
}

Expand Down
7 changes: 7 additions & 0 deletions src/bootstrap/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2043,6 +2043,13 @@ impl<'a> Builder<'a> {
rustflags.arg("-Zinline-mir");
}

// set rustc args passed from command line
let rustc_args =
self.config.cmd.rustc_args().iter().map(|s| s.to_string()).collect::<Vec<_>>();
if !rustc_args.is_empty() {
cargo.env("RUSTFLAGS", &rustc_args.join(" "));
}

Cargo { command: cargo, rustflags, rustdocflags, allow_features }
}

Expand Down
49 changes: 25 additions & 24 deletions tests/rustdoc-gui/item-decl-colors.goml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ define-function: (
block {
go-to: "file://" + |DOC_PATH| + "/test_docs/struct.WithGenerics.html"
show-text: true

set-local-storage: {"rustdoc-theme": |theme|, "rustdoc-use-system-theme": "false"}
reload:
assert-css: (".item-decl .code-attribute", {"color": |attr_color|}, ALL)
Expand All @@ -40,41 +41,41 @@ call-function: (
"check-colors",
{
"theme": "ayu",
"attr_color": "rgb(153, 153, 153)",
"trait_color": "rgb(57, 175, 215)",
"struct_color": "rgb(255, 160, 165)",
"enum_color": "rgb(255, 160, 165)",
"primitive_color": "rgb(255, 160, 165)",
"constant_color": "rgb(57, 175, 215)",
"fn_color": "rgb(253, 214, 135)",
"assoc_type_color": "rgb(57, 175, 215)",
"attr_color": "#999",
"trait_color": "#39afd7",
"struct_color": "#ffa0a5",
"enum_color": "#ffa0a5",
"primitive_color": "#ffa0a5",
"constant_color": "#39afd7",
"fn_color": "#fdd687",
"assoc_type_color": "#39afd7",
},
)
call-function: (
"check-colors",
{
"theme": "dark",
"attr_color": "rgb(153, 153, 153)",
"trait_color": "rgb(183, 140, 242)",
"struct_color": "rgb(45, 191, 184)",
"enum_color": "rgb(45, 191, 184)",
"primitive_color": "rgb(45, 191, 184)",
"constant_color": "rgb(210, 153, 29)",
"fn_color": "rgb(43, 171, 99)",
"assoc_type_color": "rgb(210, 153, 29)",
"attr_color": "#999",
"trait_color": "#b78cf2",
"struct_color": "#2dbfb8",
"enum_color": "#2dbfb8",
"primitive_color": "#2dbfb8",
"constant_color": "#d2991d",
"fn_color": "#2bab63",
"assoc_type_color": "#d2991d",
},
)
call-function: (
"check-colors",
{
"theme": "light",
"attr_color": "rgb(153, 153, 153)",
"trait_color": "rgb(110, 79, 201)",
"struct_color": "rgb(173, 55, 138)",
"enum_color": "rgb(173, 55, 138)",
"primitive_color": "rgb(173, 55, 138)",
"constant_color": "rgb(56, 115, 173)",
"fn_color": "rgb(173, 124, 55)",
"assoc_type_color": "rgb(56, 115, 173)",
"attr_color": "#999",
"trait_color": "#6e4fc9",
"struct_color": "#ad378a",
"enum_color": "#ad378a",
"primitive_color": "#ad378a",
"constant_color": "#3873ad",
"fn_color": "#ad7c37",
"assoc_type_color": "#3873ad",
},
)
Loading