Skip to content

Commit

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

Rollup of 5 pull requests

Successful merges:

 - rust-lang#131023 (Copy correct path to clipboard for modules/keywords/primitives)
 - rust-lang#131035 (Preserve brackets around if-lets and skip while-lets)
 - rust-lang#131038 (Fix `adt_const_params` leaking `{type error}` in error msg)
 - rust-lang#131053 (Improve `--print=check-cfg` documentation)
 - rust-lang#131056 (enable compiler fingerprint logs in verbose mode)

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Sep 30, 2024
2 parents 63a0bdd + fd67755 commit fb4aebd
Show file tree
Hide file tree
Showing 75 changed files with 322 additions and 347 deletions.
17 changes: 12 additions & 5 deletions compiler/rustc_hir_analysis/src/check/wfcheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -961,13 +961,20 @@ fn check_param_wf(tcx: TyCtxt<'_>, param: &hir::GenericParam<'_>) -> Result<(),
hir_ty.span,
"using raw pointers as const generic parameters is forbidden",
),
_ => tcx.dcx().struct_span_err(
hir_ty.span,
format!("`{}` is forbidden as the type of a const generic parameter", ty),
),
_ => {
// Avoid showing "{type error}" to users. See #118179.
ty.error_reported()?;

tcx.dcx().struct_span_err(
hir_ty.span,
format!(
"`{ty}` is forbidden as the type of a const generic parameter",
),
)
}
};

diag.note("the only supported types are integers, `bool` and `char`");
diag.note("the only supported types are integers, `bool`, and `char`");

let cause = ObligationCause::misc(hir_ty.span, param.def_id);
let adt_const_params_feature_string =
Expand Down
30 changes: 28 additions & 2 deletions compiler/rustc_lint/src/if_let_rescope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,11 @@ impl IfLetRescope {
}
let tcx = cx.tcx;
let source_map = tcx.sess.source_map();
let expr_end = expr.span.shrink_to_hi();
let expr_end = match expr.kind {
hir::ExprKind::If(_cond, conseq, None) => conseq.span.shrink_to_hi(),
hir::ExprKind::If(_cond, _conseq, Some(alt)) => alt.span.shrink_to_hi(),
_ => return,
};
let mut add_bracket_to_match_head = match_head_needs_bracket(tcx, expr);
let mut significant_droppers = vec![];
let mut lifetime_ends = vec![];
Expand All @@ -145,7 +149,10 @@ impl IfLetRescope {
recovered: Recovered::No,
}) = cond.kind
{
let if_let_pat = expr.span.shrink_to_lo().between(init.span);
// Peel off round braces
let if_let_pat = source_map
.span_take_while(expr.span, |&ch| ch == '(' || ch.is_whitespace())
.between(init.span);
// The consequent fragment is always a block.
let before_conseq = conseq.span.shrink_to_lo();
let lifetime_end = source_map.end_point(conseq.span);
Expand All @@ -159,6 +166,8 @@ impl IfLetRescope {
if ty_ascription.is_some()
|| !expr.span.can_be_used_for_suggestions()
|| !pat.span.can_be_used_for_suggestions()
|| !if_let_pat.can_be_used_for_suggestions()
|| !before_conseq.can_be_used_for_suggestions()
{
// Our `match` rewrites does not support type ascription,
// so we just bail.
Expand Down Expand Up @@ -240,6 +249,23 @@ impl<'tcx> LateLintPass<'tcx> for IfLetRescope {
if let (Level::Allow, _) = cx.tcx.lint_level_at_node(IF_LET_RESCOPE, expr.hir_id) {
return;
}
if let hir::ExprKind::Loop(block, _label, hir::LoopSource::While, _span) = expr.kind
&& let Some(value) = block.expr
&& let hir::ExprKind::If(cond, _conseq, _alt) = value.kind
&& let hir::ExprKind::Let(..) = cond.kind
{
// Recall that `while let` is lowered into this:
// ```
// loop {
// if let .. { body } else { break; }
// }
// ```
// There is no observable change in drop order on the overall `if let` expression
// given that the `{ break; }` block is trivial so the edition change
// means nothing substantial to this `while` statement.
self.skip.insert(value.hir_id);
return;
}
if expr_parent_is_stmt(cx.tcx, expr.hir_id)
&& matches!(expr.kind, hir::ExprKind::If(_cond, _conseq, None))
{
Expand Down
5 changes: 5 additions & 0 deletions src/bootstrap/src/core/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2014,6 +2014,11 @@ impl<'a> Builder<'a> {
cargo.env("RUSTC_BACKTRACE_ON_ICE", "1");
}

if self.is_verbose() {
// This provides very useful logs especially when debugging build cache-related stuff.
cargo.env("CARGO_LOG", "cargo::core::compiler::fingerprint=info");
}

cargo.env("RUSTC_VERBOSE", self.verbosity.to_string());

// Downstream forks of the Rust compiler might want to use a custom libc to add support for
Expand Down
27 changes: 16 additions & 11 deletions src/doc/unstable-book/src/compiler-flags/print-check-cfg.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,28 @@ The tracking issue for this feature is: [#125704](https://github.com/rust-lang/r

------------------------

This option of the `--print` flag print the list of expected cfgs.
This option of the `--print` flag print the list of all the expected cfgs.

This is related to the `--check-cfg` flag which allows specifying arbitrary expected
This is related to the [`--check-cfg` flag][check-cfg] which allows specifying arbitrary expected
names and values.

This print option works similarly to `--print=cfg` (modulo check-cfg specifics):
- *check_cfg syntax*: *output of --print=check-cfg*
- `cfg(windows)`: `windows`
- `cfg(feature, values("foo", "bar"))`: `feature="foo"` and `feature="bar"`
- `cfg(feature, values(none(), ""))`: `feature` and `feature=""`
- `cfg(feature, values(any()))`: `feature=any()`
- `cfg(feature, values())`: `feature=`
- `cfg(any())`: `any()`
- *nothing*: `any()=any()`
This print option works similarly to `--print=cfg` (modulo check-cfg specifics).

| `--check-cfg` | `--print=check-cfg` |
|-----------------------------------|-----------------------------|
| `cfg(foo)` | `foo` |
| `cfg(foo, values("bar"))` | `foo="bar"` |
| `cfg(foo, values(none(), "bar"))` | `foo` & `foo="bar"` |
| | *check-cfg specific syntax* |
| `cfg(foo, values(any())` | `foo=any()` |
| `cfg(foo, values())` | `foo=` |
| `cfg(any())` | `any()` |
| *none* | `any()=any()` |

To be used like this:

```bash
rustc --print=check-cfg -Zunstable-options lib.rs
```

[check-cfg]: https://doc.rust-lang.org/nightly/rustc/check-cfg.html
14 changes: 9 additions & 5 deletions src/librustdoc/html/static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -1828,11 +1828,15 @@ href="https://doc.rust-lang.org/${channel}/rustdoc/read-documentation/search.htm
return;
}
but.onclick = () => {
const path = [];
onEachLazy(document.querySelectorAll(".rustdoc-breadcrumbs a"), a => {
path.push(a.textContent);
});
path.push(document.querySelector("title").textContent.split(" ")[0]);
// Most page titles are '<Item> in <path::to::module> - Rust', except
// modules (which don't have the first part) and keywords/primitives
// (which don't have a module path)
const title = document.querySelector("title").textContent.replace(" - Rust", "");
const [item, module] = title.split(" in ");
const path = [item];
if (module !== undefined) {
path.unshift(module);
}

copyContentToClipboard(path.join("::"));
copyButtonAnimation(but);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ error: `&'static mut ()` is forbidden as the type of a const generic parameter
LL | fn uwu_0<const N: &'static mut ()>() {}
| ^^^^^^^^^^^^^^^
|
= note: the only supported types are integers, `bool` and `char`
= note: the only supported types are integers, `bool`, and `char`

error: `&'static u32` is forbidden as the type of a const generic parameter
--> $DIR/suggest_feature_only_when_possible.rs:15:19
|
LL | fn owo_0<const N: &'static u32>() {}
| ^^^^^^^^^^^^
|
= note: the only supported types are integers, `bool` and `char`
= note: the only supported types are integers, `bool`, and `char`
help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types
|
LL + #![feature(adt_const_params)]
Expand All @@ -28,7 +28,7 @@ error: `Meow` is forbidden as the type of a const generic parameter
LL | fn meow_0<const N: Meow>() {}
| ^^^^
|
= note: the only supported types are integers, `bool` and `char`
= note: the only supported types are integers, `bool`, and `char`
help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types
|
LL + #![feature(adt_const_params)]
Expand All @@ -40,7 +40,7 @@ error: `&'static Meow` is forbidden as the type of a const generic parameter
LL | fn meow_1<const N: &'static Meow>() {}
| ^^^^^^^^^^^^^
|
= note: the only supported types are integers, `bool` and `char`
= note: the only supported types are integers, `bool`, and `char`
help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types
|
LL + #![feature(adt_const_params)]
Expand All @@ -56,39 +56,39 @@ error: `[Meow; 100]` is forbidden as the type of a const generic parameter
LL | fn meow_2<const N: [Meow; 100]>() {}
| ^^^^^^^^^^^
|
= note: the only supported types are integers, `bool` and `char`
= note: the only supported types are integers, `bool`, and `char`

error: `(Meow, u8)` is forbidden as the type of a const generic parameter
--> $DIR/suggest_feature_only_when_possible.rs:29:20
|
LL | fn meow_3<const N: (Meow, u8)>() {}
| ^^^^^^^^^^
|
= note: the only supported types are integers, `bool` and `char`
= note: the only supported types are integers, `bool`, and `char`

error: `(Meow, String)` is forbidden as the type of a const generic parameter
--> $DIR/suggest_feature_only_when_possible.rs:34:20
|
LL | fn meow_4<const N: (Meow, String)>() {}
| ^^^^^^^^^^^^^^
|
= note: the only supported types are integers, `bool` and `char`
= note: the only supported types are integers, `bool`, and `char`

error: `String` is forbidden as the type of a const generic parameter
--> $DIR/suggest_feature_only_when_possible.rs:38:19
|
LL | fn nya_0<const N: String>() {}
| ^^^^^^
|
= note: the only supported types are integers, `bool` and `char`
= note: the only supported types are integers, `bool`, and `char`

error: `Vec<u32>` is forbidden as the type of a const generic parameter
--> $DIR/suggest_feature_only_when_possible.rs:40:19
|
LL | fn nya_1<const N: Vec<u32>>() {}
| ^^^^^^^^
|
= note: the only supported types are integers, `bool` and `char`
= note: the only supported types are integers, `bool`, and `char`

error: aborting due to 9 previous errors

Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,25 @@ LL | struct A<const N: &u8>;
| ^ explicit lifetime name needed here

error[E0637]: `&` without an explicit lifetime name cannot be used here
--> $DIR/const-param-elided-lifetime.rs:14:15
--> $DIR/const-param-elided-lifetime.rs:13:15
|
LL | impl<const N: &u8> A<N> {
| ^ explicit lifetime name needed here

error[E0637]: `&` without an explicit lifetime name cannot be used here
--> $DIR/const-param-elided-lifetime.rs:17:21
--> $DIR/const-param-elided-lifetime.rs:15:21
|
LL | fn foo<const M: &u8>(&self) {}
| ^ explicit lifetime name needed here

error[E0637]: `&` without an explicit lifetime name cannot be used here
--> $DIR/const-param-elided-lifetime.rs:22:15
--> $DIR/const-param-elided-lifetime.rs:19:15
|
LL | impl<const N: &u8> B for A<N> {}
| ^ explicit lifetime name needed here

error[E0637]: `&` without an explicit lifetime name cannot be used here
--> $DIR/const-param-elided-lifetime.rs:26:17
--> $DIR/const-param-elided-lifetime.rs:22:17
|
LL | fn bar<const N: &u8>() {}
| ^ explicit lifetime name needed here
Expand Down
90 changes: 5 additions & 85 deletions tests/ui/const-generics/const-param-elided-lifetime.min.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,109 +5,29 @@ LL | struct A<const N: &u8>;
| ^ explicit lifetime name needed here

error[E0637]: `&` without an explicit lifetime name cannot be used here
--> $DIR/const-param-elided-lifetime.rs:14:15
--> $DIR/const-param-elided-lifetime.rs:13:15
|
LL | impl<const N: &u8> A<N> {
| ^ explicit lifetime name needed here

error[E0637]: `&` without an explicit lifetime name cannot be used here
--> $DIR/const-param-elided-lifetime.rs:17:21
--> $DIR/const-param-elided-lifetime.rs:15:21
|
LL | fn foo<const M: &u8>(&self) {}
| ^ explicit lifetime name needed here

error[E0637]: `&` without an explicit lifetime name cannot be used here
--> $DIR/const-param-elided-lifetime.rs:22:15
--> $DIR/const-param-elided-lifetime.rs:19:15
|
LL | impl<const N: &u8> B for A<N> {}
| ^ explicit lifetime name needed here

error[E0637]: `&` without an explicit lifetime name cannot be used here
--> $DIR/const-param-elided-lifetime.rs:26:17
--> $DIR/const-param-elided-lifetime.rs:22:17
|
LL | fn bar<const N: &u8>() {}
| ^ explicit lifetime name needed here

error: `&u8` is forbidden as the type of a const generic parameter
--> $DIR/const-param-elided-lifetime.rs:9:19
|
LL | struct A<const N: &u8>;
| ^^^
|
= note: the only supported types are integers, `bool` and `char`
help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types
|
LL + #![feature(adt_const_params)]
|
help: add `#![feature(unsized_const_params)]` to the crate attributes to enable references to implement the `ConstParamTy` trait
|
LL + #![feature(unsized_const_params)]
|

error: `&u8` is forbidden as the type of a const generic parameter
--> $DIR/const-param-elided-lifetime.rs:14:15
|
LL | impl<const N: &u8> A<N> {
| ^^^
|
= note: the only supported types are integers, `bool` and `char`
help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types
|
LL + #![feature(adt_const_params)]
|
help: add `#![feature(unsized_const_params)]` to the crate attributes to enable references to implement the `ConstParamTy` trait
|
LL + #![feature(unsized_const_params)]
|

error: `&u8` is forbidden as the type of a const generic parameter
--> $DIR/const-param-elided-lifetime.rs:22:15
|
LL | impl<const N: &u8> B for A<N> {}
| ^^^
|
= note: the only supported types are integers, `bool` and `char`
help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types
|
LL + #![feature(adt_const_params)]
|
help: add `#![feature(unsized_const_params)]` to the crate attributes to enable references to implement the `ConstParamTy` trait
|
LL + #![feature(unsized_const_params)]
|

error: `&u8` is forbidden as the type of a const generic parameter
--> $DIR/const-param-elided-lifetime.rs:26:17
|
LL | fn bar<const N: &u8>() {}
| ^^^
|
= note: the only supported types are integers, `bool` and `char`
help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types
|
LL + #![feature(adt_const_params)]
|
help: add `#![feature(unsized_const_params)]` to the crate attributes to enable references to implement the `ConstParamTy` trait
|
LL + #![feature(unsized_const_params)]
|

error: `&u8` is forbidden as the type of a const generic parameter
--> $DIR/const-param-elided-lifetime.rs:17:21
|
LL | fn foo<const M: &u8>(&self) {}
| ^^^
|
= note: the only supported types are integers, `bool` and `char`
help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types
|
LL + #![feature(adt_const_params)]
|
help: add `#![feature(unsized_const_params)]` to the crate attributes to enable references to implement the `ConstParamTy` trait
|
LL + #![feature(unsized_const_params)]
|

error: aborting due to 10 previous errors
error: aborting due to 5 previous errors

For more information about this error, try `rustc --explain E0637`.
Loading

0 comments on commit fb4aebd

Please sign in to comment.