Skip to content

Commit

Permalink
Auto merge of rust-lang#117255 - TaKO8Ki:rollup-dhoz1gg, r=TaKO8Ki
Browse files Browse the repository at this point in the history
Rollup of 5 pull requests

Successful merges:

 - rust-lang#116858 (Suggest assoc fn `new` when trying to build tuple struct with private fields)
 - rust-lang#116868 (Tweak suggestion span for outer attr and point at item following invalid inner attr)
 - rust-lang#117025 (Cleanup and improve `--check-cfg` implementation)
 - rust-lang#117170 (Add support for i586-unknown-netbsd as target.)
 - rust-lang#117240 (Fix documentation typo in std::iter::Iterator::collect_into)

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Oct 27, 2023
2 parents aa91057 + 248bb0c commit b7b85ce
Show file tree
Hide file tree
Showing 36 changed files with 539 additions and 359 deletions.
398 changes: 198 additions & 200 deletions compiler/rustc_interface/src/interface.rs

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions compiler/rustc_llvm/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,14 @@ fn main() {
{
println!("cargo:rustc-link-lib=z");
} else if target.contains("netbsd") {
// On NetBSD/i386, gcc and g++ is built for i486 (to maximize backward compat)
// However, LLVM insists on using 64-bit atomics.
// This gives rise to a need to link rust itself with -latomic for these targets
if target.starts_with("i586")
|| target.starts_with("i686")
{
println!("cargo:rustc-link-lib=atomic");
}
println!("cargo:rustc-link-lib=z");
println!("cargo:rustc-link-lib=execinfo");
}
Expand Down
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
22 changes: 22 additions & 0 deletions compiler/rustc_target/src/spec/i586_unknown_netbsd.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use crate::spec::{Cc, Lld, LinkerFlavor, StackProbeType, Target, TargetOptions};

pub fn target() -> Target {
let mut base = super::netbsd_base::opts();
base.cpu = "pentium".into();
base.max_atomic_width = Some(64);
base.pre_link_args
.entry(LinkerFlavor::Gnu(Cc::Yes, Lld::No))
.or_default()
.push("-m32".into());
base.stack_probes = StackProbeType::Call;

Target {
llvm_target: "i586-unknown-netbsdelf".into(),
pointer_width: 32,
data_layout: "e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-\
f64:32:64-f80:32-n8:16:32-S128"
.into(),
arch: "x86".into(),
options: TargetOptions { mcount: "__mcount".into(), ..base },
}
}
1 change: 1 addition & 0 deletions compiler/rustc_target/src/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1426,6 +1426,7 @@ supported_targets! {
("aarch64_be-unknown-netbsd", aarch64_be_unknown_netbsd),
("armv6-unknown-netbsd-eabihf", armv6_unknown_netbsd_eabihf),
("armv7-unknown-netbsd-eabihf", armv7_unknown_netbsd_eabihf),
("i586-unknown-netbsd", i586_unknown_netbsd),
("i686-unknown-netbsd", i686_unknown_netbsd),
("powerpc-unknown-netbsd", powerpc_unknown_netbsd),
("riscv64gc-unknown-netbsd", riscv64gc_unknown_netbsd),
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
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

0 comments on commit b7b85ce

Please sign in to comment.