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

Implement Lift using interners instead of in_arena #67791

Merged
merged 4 commits into from
Jan 17, 2020
Merged
Changes from 1 commit
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
Next Next commit
Don't create strings in the fast path
Zoxc committed Jan 11, 2020

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 4b19c80819efbbf48a0efe0aba0e6e2fd3cafbc3
29 changes: 15 additions & 14 deletions src/librustc_typeck/astconv.rs
Original file line number Diff line number Diff line change
@@ -1318,10 +1318,10 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
// those that do.
self.one_bound_for_assoc_type(
|| traits::supertraits(tcx, trait_ref),
&trait_ref.print_only_trait_path().to_string(),
|| trait_ref.print_only_trait_path().to_string(),
binding.item_name,
path_span,
match binding.kind {
|| match binding.kind {
ConvertedBindingKind::Equality(ty) => Some(ty.to_string()),
_ => None,
},
@@ -1878,10 +1878,10 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
predicates.iter().filter_map(|(p, _)| p.to_opt_poly_trait_ref()),
)
},
&param_name.as_str(),
|| param_name.to_string(),
assoc_name,
span,
None,
|| None,
)
}

@@ -1890,10 +1890,10 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
fn one_bound_for_assoc_type<I>(
&self,
all_candidates: impl Fn() -> I,
ty_param_name: &str,
ty_param_name: impl Fn() -> String,
assoc_name: ast::Ident,
span: Span,
is_equality: Option<String>,
is_equality: impl Fn() -> Option<String>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Am I missing something, or are the changes in this file unrelated?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I stumbled into this since I broke Lift while working on this PR. There's more cases still where we print types without using them.

) -> Result<ty::PolyTraitRef<'tcx>, ErrorReported>
where
I: Iterator<Item = ty::PolyTraitRef<'tcx>>,
@@ -1906,7 +1906,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
None => {
self.complain_about_assoc_type_not_found(
all_candidates,
ty_param_name,
&ty_param_name(),
assoc_name,
span,
);
@@ -1919,6 +1919,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
if let Some(bound2) = matching_candidates.next() {
debug!("one_bound_for_assoc_type: bound2 = {:?}", bound2);

let is_equality = is_equality();
let bounds = iter::once(bound).chain(iter::once(bound2)).chain(matching_candidates);
let mut err = if is_equality.is_some() {
// More specific Error Index entry.
@@ -1928,7 +1929,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
E0222,
"ambiguous associated type `{}` in bounds of `{}`",
assoc_name,
ty_param_name
ty_param_name()
)
} else {
struct_span_err!(
@@ -1937,7 +1938,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
E0221,
"ambiguous associated type `{}` in bounds of `{}`",
assoc_name,
ty_param_name
ty_param_name()
)
};
err.span_label(span, format!("ambiguous associated type `{}`", assoc_name));
@@ -1975,7 +1976,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
"use fully qualified syntax to disambiguate",
format!(
"<{} as {}>::{}",
ty_param_name,
ty_param_name(),
bound.print_only_trait_path(),
assoc_name,
),
@@ -1985,7 +1986,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
} else {
err.note(&format!(
"associated type `{}` could derive from `{}`",
ty_param_name,
ty_param_name(),
bound.print_only_trait_path(),
));
}
@@ -1994,7 +1995,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
err.help(&format!(
"consider introducing a new type parameter `T` and adding `where` constraints:\
\n where\n T: {},\n{}",
ty_param_name,
ty_param_name(),
where_bounds.join(",\n"),
));
}
@@ -2108,10 +2109,10 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {

self.one_bound_for_assoc_type(
|| traits::supertraits(tcx, ty::Binder::bind(trait_ref)),
"Self",
|| "Self".to_string(),
assoc_ident,
span,
None,
|| None,
)?
}
(&ty::Param(_), Res::SelfTy(Some(param_did), None))