Skip to content

Commit

Permalink
Auto merge of rust-lang#111552 - matthiaskrgr:rollup-4nidoti, r=matth…
Browse files Browse the repository at this point in the history
…iaskrgr

Rollup of 4 pull requests

Successful merges:

 - rust-lang#111463 (Better diagnostics for `env!` where variable contains escape)
 - rust-lang#111477 (better diagnostics for `impl<..> impl Trait for Type`)
 - rust-lang#111534 (rustdoc-json: Add tests for `#![feature(inherent_associated_types)]`)
 - rust-lang#111549 ([rustdoc] Convert more GUI tests colors to their original format)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed May 14, 2023
2 parents bc88895 + d1cd127 commit 0a0e045
Show file tree
Hide file tree
Showing 15 changed files with 296 additions and 100 deletions.
12 changes: 9 additions & 3 deletions compiler/rustc_builtin_macros/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,16 @@ pub fn expand_env<'cx>(
Some(exprs) => exprs.into_iter(),
};

let Some((var, _style)) = expr_to_string(cx, exprs.next().unwrap(), "expected string literal") else {
let var_expr = exprs.next().unwrap();
let Some((var, _)) = expr_to_string(cx, var_expr.clone(), "expected string literal") else {
return DummyResult::any(sp);
};

let custom_msg = match exprs.next() {
None => None,
Some(second) => match expr_to_string(cx, second, "expected string literal") {
None => return DummyResult::any(sp),
Some((s, _style)) => Some(s),
Some((s, _)) => Some(s),
},
};

Expand All @@ -80,10 +81,15 @@ pub fn expand_env<'cx>(
cx.sess.parse_sess.env_depinfo.borrow_mut().insert((var, value));
let e = match value {
None => {
// Use the string literal in the code in the diagnostic to avoid confusing diagnostics,
// e.g. when the literal contains escape sequences.
let ast::ExprKind::Lit(ast::token::Lit { kind: ast::token::LitKind::Str, symbol: original_var, ..}) = &var_expr.kind else {
unreachable!("`expr_to_string` ensures this is a string lit")
};
cx.emit_err(errors::EnvNotDefined {
span: sp,
msg: custom_msg,
var,
var: *original_var,
help: custom_msg.is_none().then(|| help_for_missing_env_var(var.as_str())),
});
return DummyResult::any(sp);
Expand Down
5 changes: 5 additions & 0 deletions compiler/rustc_parse/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,11 @@ parse_missing_for_in_trait_impl = missing `for` in a trait impl
parse_expected_trait_in_trait_impl_found_type = expected a trait, found type
parse_extra_impl_keyword_in_trait_impl = unexpected `impl` keyword
.suggestion = remove the extra `impl`
.note = this is parsed as an `impl Trait` type, but a trait is expected at this position
parse_non_item_in_item_list = non-item in item list
.suggestion_use_const_not_let = consider using `const` instead of `let` for associated const
.label_list_start = item list starts here
Expand Down
10 changes: 10 additions & 0 deletions compiler/rustc_parse/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1519,6 +1519,16 @@ pub(crate) struct ExpectedTraitInTraitImplFoundType {
pub span: Span,
}

#[derive(Diagnostic)]
#[diag(parse_extra_impl_keyword_in_trait_impl)]
pub(crate) struct ExtraImplKeywordInTraitImpl {
#[primary_span]
#[suggestion(code = "", applicability = "maybe-incorrect")]
pub extra_impl_kw: Span,
#[note]
pub impl_trait_span: Span,
}

#[derive(Diagnostic)]
#[diag(parse_bounds_not_allowed_on_trait_aliases)]
pub(crate) struct BoundsNotAllowedOnTraitAliases {
Expand Down
22 changes: 18 additions & 4 deletions compiler/rustc_parse/src/parser/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -603,10 +603,24 @@ impl<'a> Parser<'a> {
let path = match ty_first.kind {
// This notably includes paths passed through `ty` macro fragments (#46438).
TyKind::Path(None, path) => path,
_ => {
self.sess.emit_err(errors::ExpectedTraitInTraitImplFoundType {
span: ty_first.span,
});
other => {
if let TyKind::ImplTrait(_, bounds) = other
&& let [bound] = bounds.as_slice()
{
// Suggest removing extra `impl` keyword:
// `impl<T: Default> impl Default for Wrapper<T>`
// ^^^^^
let extra_impl_kw = ty_first.span.until(bound.span());
self.sess
.emit_err(errors::ExtraImplKeywordInTraitImpl {
extra_impl_kw,
impl_trait_span: ty_first.span
});
} else {
self.sess.emit_err(errors::ExpectedTraitInTraitImplFoundType {
span: ty_first.span,
});
}
err_path(ty_first.span)
}
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.16.0
0.16.3
Loading

0 comments on commit 0a0e045

Please sign in to comment.