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 5 pull requests #117264

Closed
wants to merge 16 commits into from
Closed
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
398 changes: 198 additions & 200 deletions compiler/rustc_interface/src/interface.rs

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions compiler/rustc_passes/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,9 @@ passes_invalid_attr_at_crate_level =
`{$name}` attribute cannot be used at crate level
.suggestion = perhaps you meant to use an outer attribute

passes_invalid_attr_at_crate_level_item =
the inner attribute doesn't annotate this {$kind}

passes_invalid_deprecation_version =
invalid deprecation version found
.label = invalid deprecation version
Expand Down
22 changes: 21 additions & 1 deletion compiler/rustc_passes/src/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2534,10 +2534,30 @@ fn check_invalid_crate_level_attr(tcx: TyCtxt<'_>, attrs: &[Attribute]) {
if attr.style == AttrStyle::Inner {
for attr_to_check in ATTRS_TO_CHECK {
if attr.has_name(*attr_to_check) {
let item = tcx
.hir()
.items()
.map(|id| tcx.hir().item(id))
.find(|item| !item.span.is_dummy()) // Skip prelude `use`s
.map(|item| errors::ItemFollowingInnerAttr {
span: item.ident.span,
kind: item.kind.descr(),
});
tcx.sess.emit_err(errors::InvalidAttrAtCrateLevel {
span: attr.span,
snippet: tcx.sess.source_map().span_to_snippet(attr.span).ok(),
sugg_span: tcx
.sess
.source_map()
.span_to_snippet(attr.span)
.ok()
.filter(|src| src.starts_with("#!["))
.map(|_| {
attr.span
.with_lo(attr.span.lo() + BytePos(1))
.with_hi(attr.span.lo() + BytePos(2))
}),
name: *attr_to_check,
item,
});
}
}
Expand Down
20 changes: 15 additions & 5 deletions compiler/rustc_passes/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -856,8 +856,15 @@ pub struct UnknownLangItem {

pub struct InvalidAttrAtCrateLevel {
pub span: Span,
pub snippet: Option<String>,
pub sugg_span: Option<Span>,
pub name: Symbol,
pub item: Option<ItemFollowingInnerAttr>,
}

#[derive(Clone, Copy)]
pub struct ItemFollowingInnerAttr {
pub span: Span,
pub kind: &'static str,
}

impl IntoDiagnostic<'_> for InvalidAttrAtCrateLevel {
Expand All @@ -871,15 +878,18 @@ impl IntoDiagnostic<'_> for InvalidAttrAtCrateLevel {
diag.set_arg("name", self.name);
// Only emit an error with a suggestion if we can create a string out
// of the attribute span
if let Some(src) = self.snippet {
let replacement = src.replace("#!", "#");
if let Some(span) = self.sugg_span {
diag.span_suggestion_verbose(
self.span,
span,
fluent::passes_suggestion,
replacement,
String::new(),
rustc_errors::Applicability::MachineApplicable,
);
}
if let Some(item) = self.item {
diag.set_arg("kind", item.kind);
diag.span_label(item.span, fluent::passes_invalid_attr_at_crate_level_item);
}
diag
}
}
Expand Down
21 changes: 20 additions & 1 deletion compiler/rustc_resolve/src/late/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1570,7 +1570,26 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
err.set_primary_message(
"cannot initialize a tuple struct which contains private fields",
);

if !def_id.is_local()
&& self
.r
.tcx
.inherent_impls(def_id)
.iter()
.flat_map(|impl_def_id| {
self.r.tcx.provided_trait_methods(*impl_def_id)
})
.any(|assoc| !assoc.fn_has_self_parameter && assoc.name == sym::new)
{
// FIXME: look for associated functions with Self return type,
// instead of relying only on the name and lack of self receiver.
err.span_suggestion_verbose(
span.shrink_to_hi(),
"you might have meant to use the `new` associated function",
"::new".to_string(),
Applicability::MaybeIncorrect,
);
}
// Use spans of the tuple struct definition.
self.r.field_def_ids(def_id).map(|field_ids| {
field_ids
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/iter/traits/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2142,7 +2142,7 @@ pub trait Iterator {
/// passed collection. The collection is then returned, so the call chain
/// can be continued.
///
/// This is useful when you already have a collection and wants to add
/// This is useful when you already have a collection and want to add
/// the iterator items to it.
///
/// This method is a convenience method to call [Extend::extend](trait.Extend.html),
Expand Down
23 changes: 23 additions & 0 deletions src/doc/rustc/src/profile-guided-optimization.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,26 @@ in Clang's documentation is therefore an interesting read for anyone who wants
to use PGO with Rust.

[clang-pgo]: https://clang.llvm.org/docs/UsersManual.html#profile-guided-optimization

## Community Maintained Tools

As an alternative to directly using the compiler for Profile-Guided Optimization,
you may choose to go with `cargo-pgo`, which has an intuitive command-line API
and saves you the trouble of doing all the manual work. You can read more about
it in their repository accessible from this link: https:/Kobzol/cargo-pgo

For the sake of completeness, here are the corresponding steps using `cargo-pgo`:

```bash
# Install if you haven't already
cargo install cargo-pgo

cargo pgo build
cargo pgo optimize
```

These steps will do the following just as before:

1. Build an instrumented binary from the source code.
2. Run the instrumented binary to gather PGO profiles.
3. Use the gathered PGO profiles from the last step to build an optimized binary.
2 changes: 1 addition & 1 deletion src/doc/unstable-book/src/compiler-flags/check-cfg.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ fn do_mumble_frotz() {}

```bash
# This turns on checking for feature values, but not for condition names.
rustc --check-cfg 'configure(feature, values("zapping", "lasers"))' \
rustc --check-cfg 'cfg(feature, values("zapping", "lasers"))' \
--check-cfg 'cfg(any())' \
--cfg 'feature="zapping"' -Z unstable-options
```
Expand Down
8 changes: 6 additions & 2 deletions tests/ui/attributes/unix_sigpipe/unix_sigpipe-crate.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@ error: `unix_sigpipe` attribute cannot be used at crate level
|
LL | #![unix_sigpipe = "inherit"]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL |
LL | fn main() {}
| ---- the inner attribute doesn't annotate this function
|
help: perhaps you meant to use an outer attribute
|
LL | #[unix_sigpipe = "inherit"]
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~
LL - #![unix_sigpipe = "inherit"]
LL + #[unix_sigpipe = "inherit"]
|

error: aborting due to previous error

2 changes: 2 additions & 0 deletions tests/ui/check-cfg/invalid-arguments.any_values.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
error: invalid `--check-cfg` argument: `cfg(any(),values())` (`values()` cannot be specified before the names)

4 changes: 3 additions & 1 deletion tests/ui/check-cfg/invalid-arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// revisions: multiple_values_any not_empty_any not_empty_values_any
// revisions: values_any_missing_values values_any_before_ident ident_in_values_1
// revisions: ident_in_values_2 unknown_meta_item_1 unknown_meta_item_2 unknown_meta_item_3
// revisions: mixed_values_any mixed_any giberich
// revisions: mixed_values_any mixed_any any_values giberich unterminated
//
// compile-flags: -Z unstable-options
// [anything_else]compile-flags: --check-cfg=anything_else(...)
Expand All @@ -29,6 +29,8 @@
// [unknown_meta_item_3]compile-flags: --check-cfg=cfg(foo,values(test()))
// [mixed_values_any]compile-flags: --check-cfg=cfg(foo,values("bar",any()))
// [mixed_any]compile-flags: --check-cfg=cfg(any(),values(any()))
// [any_values]compile-flags: --check-cfg=cfg(any(),values())
// [giberich]compile-flags: --check-cfg=cfg(...)
// [unterminated]compile-flags: --check-cfg=cfg(

fn main() {}
2 changes: 2 additions & 0 deletions tests/ui/check-cfg/invalid-arguments.unterminated.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
error: invalid `--check-cfg` argument: `cfg(` (expected `cfg(name, values("value1", "value2", ... "valueN"))`)

Loading
Loading