Skip to content

Commit eed12bc

Browse files
committed
Auto merge of #68635 - JohnTitor:rollup-jsc34ac, r=JohnTitor
Rollup of 7 pull requests Successful merges: - #67722 (Minor: note how Any is an unsafe trait in SAFETY comments) - #68586 (Make conflicting_repr_hints a deny-by-default c-future-compat lint) - #68598 (Fix null synthetic_implementors error) - #68603 (Changelog: Demonstrate final build-override syntax) - #68609 (Set lld flavor for MSVC to link.exe) - #68611 (Correct ICE caused by macros generating invalid spans.) - #68627 (Document that write_all will not call write if given an empty buffer) Failed merges: r? @ghost
2 parents edb3684 + 50df788 commit eed12bc

File tree

14 files changed

+98
-41
lines changed

14 files changed

+98
-41
lines changed

RELEASES.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ Cargo
6262
- [Cargo.lock now uses a more git friendly format that should help to reduce
6363
merge conflicts.][cargo/7579]
6464
- [You can now override specific dependencies's build settings][cargo/7591] E.g.
65-
`[profile.dev.overrides.image] opt-level = 2` sets the `image` crate's
65+
`[profile.dev.package.image] opt-level = 2` sets the `image` crate's
6666
optimisation level to `2` for debug builds. You can also use
67-
`[profile.<profile>.build_overrides]` to override build scripts and
67+
`[profile.<profile>.build-override]` to override build scripts and
6868
their dependencies.
6969

7070
Misc

src/libcore/any.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,9 @@ impl dyn Any {
194194
#[inline]
195195
pub fn downcast_ref<T: Any>(&self) -> Option<&T> {
196196
if self.is::<T>() {
197-
// SAFETY: just checked whether we are pointing to the correct type
197+
// SAFETY: just checked whether we are pointing to the correct type, and we can rely on
198+
// that check for memory safety because we have implemented Any for all types; no other
199+
// impls can exist as they would conflict with our impl.
198200
unsafe { Some(&*(self as *const dyn Any as *const T)) }
199201
} else {
200202
None
@@ -228,7 +230,9 @@ impl dyn Any {
228230
#[inline]
229231
pub fn downcast_mut<T: Any>(&mut self) -> Option<&mut T> {
230232
if self.is::<T>() {
231-
// SAFETY: just checked whether we are pointing to the correct type
233+
// SAFETY: just checked whether we are pointing to the correct type, and we can rely on
234+
// that check for memory safety because we have implemented Any for all types; no other
235+
// impls can exist as they would conflict with our impl.
232236
unsafe { Some(&mut *(self as *mut dyn Any as *mut T)) }
233237
} else {
234238
None

src/librustc/hir/check_attr.rs

+12-9
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use rustc_hir::def_id::DefId;
1414
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
1515
use rustc_hir::DUMMY_HIR_ID;
1616
use rustc_hir::{self, HirId, Item, ItemKind, TraitItem, TraitItemKind};
17-
use rustc_session::lint::builtin::UNUSED_ATTRIBUTES;
17+
use rustc_session::lint::builtin::{CONFLICTING_REPR_HINTS, UNUSED_ATTRIBUTES};
1818
use rustc_span::symbol::sym;
1919
use rustc_span::Span;
2020
use syntax::ast::Attribute;
@@ -196,7 +196,7 @@ impl CheckAttrVisitor<'tcx> {
196196
self.tcx.codegen_fn_attrs(self.tcx.hir().local_def_id(hir_id));
197197
}
198198

199-
self.check_repr(attrs, span, target, item);
199+
self.check_repr(attrs, span, target, item, hir_id);
200200
self.check_used(attrs, target);
201201
}
202202

@@ -357,6 +357,7 @@ impl CheckAttrVisitor<'tcx> {
357357
span: &Span,
358358
target: Target,
359359
item: Option<&Item<'_>>,
360+
hir_id: HirId,
360361
) {
361362
// Extract the names of all repr hints, e.g., [foo, bar, align] for:
362363
// ```
@@ -446,13 +447,15 @@ impl CheckAttrVisitor<'tcx> {
446447
|| (is_simd && is_c)
447448
|| (int_reprs == 1 && is_c && item.map_or(false, |item| is_c_like_enum(item)))
448449
{
449-
struct_span_err!(
450-
self.tcx.sess,
451-
hint_spans.collect::<Vec<Span>>(),
452-
E0566,
453-
"conflicting representation hints",
454-
)
455-
.emit();
450+
self.tcx
451+
.struct_span_lint_hir(
452+
CONFLICTING_REPR_HINTS,
453+
hir_id,
454+
hint_spans.collect::<Vec<Span>>(),
455+
"conflicting representation hints",
456+
)
457+
.code(rustc_errors::error_code!(E0566))
458+
.emit();
456459
}
457460
}
458461

src/librustc_errors/emitter.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use crate::{
1919
pluralize, CodeSuggestion, Diagnostic, DiagnosticId, Level, SubDiagnostic, SuggestionStyle,
2020
};
2121

22+
use log::*;
2223
use rustc_data_structures::fx::FxHashMap;
2324
use rustc_data_structures::sync::Lrc;
2425
use rustc_span::hygiene::{ExpnKind, MacroKind};
@@ -2108,7 +2109,13 @@ impl<'a> Drop for WritableDst<'a> {
21082109
/// Whether the original and suggested code are visually similar enough to warrant extra wording.
21092110
pub fn is_case_difference(sm: &SourceMap, suggested: &str, sp: Span) -> bool {
21102111
// FIXME: this should probably be extended to also account for `FO0` → `FOO` and unicode.
2111-
let found = sm.span_to_snippet(sp).unwrap();
2112+
let found = match sm.span_to_snippet(sp) {
2113+
Ok(snippet) => snippet,
2114+
Err(e) => {
2115+
warn!("Invalid span {:?}. Err={:?}", sp, e);
2116+
return false;
2117+
}
2118+
};
21122119
let ascii_confusables = &['c', 'f', 'i', 'k', 'o', 's', 'u', 'v', 'w', 'x', 'y', 'z'];
21132120
// All the chars that differ in capitalization are confusable (above):
21142121
let confusable = found

src/librustc_session/lint/builtin.rs

+11
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@ declare_lint! {
1818
};
1919
}
2020

21+
declare_lint! {
22+
pub CONFLICTING_REPR_HINTS,
23+
Deny,
24+
"conflicts between `#[repr(..)]` hints that were previously accepted and used in practice",
25+
@future_incompatible = FutureIncompatibleInfo {
26+
reference: "issue #68585 <https://github.com/rust-lang/rust/issues/68585>",
27+
edition: None,
28+
};
29+
}
30+
2131
declare_lint! {
2232
pub META_VARIABLE_MISUSE,
2333
Allow,
@@ -520,6 +530,7 @@ declare_lint_pass! {
520530
MACRO_USE_EXTERN_CRATE,
521531
MACRO_EXPANDED_MACRO_EXPORTS_ACCESSED_BY_ABSOLUTE_PATHS,
522532
ILL_FORMED_ATTRIBUTE_INPUT,
533+
CONFLICTING_REPR_HINTS,
523534
META_VARIABLE_MISUSE,
524535
DEPRECATED_IN_FUTURE,
525536
AMBIGUOUS_ASSOCIATED_ITEMS,

src/librustc_target/spec/windows_msvc_base.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
use crate::spec::{LinkArgs, LinkerFlavor, TargetOptions};
1+
use crate::spec::{LinkArgs, LinkerFlavor, LldFlavor, TargetOptions};
22
use std::default::Default;
33

44
pub fn opts() -> TargetOptions {
5+
let pre_args = vec!["/NOLOGO".to_string(), "/NXCOMPAT".to_string()];
56
let mut args = LinkArgs::new();
6-
args.insert(LinkerFlavor::Msvc, vec!["/NOLOGO".to_string(), "/NXCOMPAT".to_string()]);
7+
args.insert(LinkerFlavor::Msvc, pre_args.clone());
8+
args.insert(LinkerFlavor::Lld(LldFlavor::Link), pre_args);
79

810
TargetOptions {
911
function_sections: true,
@@ -21,6 +23,7 @@ pub fn opts() -> TargetOptions {
2123
// language packs, and avoid generating Non-UTF-8 error
2224
// messages if a link error occurred.
2325
link_env: vec![("VSLANG".to_string(), "1033".to_string())],
26+
lld_flavor: LldFlavor::Link,
2427
pre_link_args: args,
2528
crt_static_allows_dylibs: true,
2629
crt_static_respected: true,

src/librustdoc/html/static/main.js

+16-14
Original file line numberDiff line numberDiff line change
@@ -1895,21 +1895,23 @@ function getSearchElement() {
18951895
var implementors = document.getElementById("implementors-list");
18961896
var synthetic_implementors = document.getElementById("synthetic-implementors-list");
18971897

1898-
// This `inlined_types` variable is used to avoid having the same implementation showing
1899-
// up twice. For example "String" in the "Sync" doc page.
1900-
//
1901-
// By the way, this is only used by and useful for traits implemented automatically (like
1902-
// "Send" and "Sync").
1903-
var inlined_types = new Set();
1904-
onEachLazy(synthetic_implementors.getElementsByClassName("impl"), function(el) {
1905-
var aliases = el.getAttribute("aliases");
1906-
if (!aliases) {
1907-
return;
1908-
}
1909-
aliases.split(",").forEach(function(alias) {
1910-
inlined_types.add(alias);
1898+
if (synthetic_implementors) {
1899+
// This `inlined_types` variable is used to avoid having the same implementation
1900+
// showing up twice. For example "String" in the "Sync" doc page.
1901+
//
1902+
// By the way, this is only used by and useful for traits implemented automatically
1903+
// (like "Send" and "Sync").
1904+
var inlined_types = new Set();
1905+
onEachLazy(synthetic_implementors.getElementsByClassName("impl"), function(el) {
1906+
var aliases = el.getAttribute("aliases");
1907+
if (!aliases) {
1908+
return;
1909+
}
1910+
aliases.split(",").forEach(function(alias) {
1911+
inlined_types.add(alias);
1912+
});
19111913
});
1912-
});
1914+
}
19131915

19141916
var libs = Object.getOwnPropertyNames(imp);
19151917
var llength = libs.length;

src/libstd/io/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1327,6 +1327,8 @@ pub trait Write {
13271327
/// not of [`ErrorKind::Interrupted`] kind generated from this method will be
13281328
/// returned.
13291329
///
1330+
/// If the buffer contains no data, this will never call [`write`].
1331+
///
13301332
/// # Errors
13311333
///
13321334
/// This function will return the first error of

src/test/ui/conflicting-repr-hints.rs

+2
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ enum B {
1111
}
1212

1313
#[repr(C, u64)] //~ ERROR conflicting representation hints
14+
//~^ WARN this was previously accepted
1415
enum C {
1516
C,
1617
}
1718

1819
#[repr(u32, u64)] //~ ERROR conflicting representation hints
20+
//~^ WARN this was previously accepted
1921
enum D {
2022
D,
2123
}

src/test/ui/conflicting-repr-hints.stderr

+16-9
Original file line numberDiff line numberDiff line change
@@ -3,45 +3,52 @@ error[E0566]: conflicting representation hints
33
|
44
LL | #[repr(C, u64)]
55
| ^ ^^^
6+
|
7+
= note: `#[deny(conflicting_repr_hints)]` on by default
8+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
9+
= note: for more information, see issue #68585 <https://github.com/rust-lang/rust/issues/68585>
610

711
error[E0566]: conflicting representation hints
8-
--> $DIR/conflicting-repr-hints.rs:18:8
12+
--> $DIR/conflicting-repr-hints.rs:19:8
913
|
1014
LL | #[repr(u32, u64)]
1115
| ^^^ ^^^
16+
|
17+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
18+
= note: for more information, see issue #68585 <https://github.com/rust-lang/rust/issues/68585>
1219

1320
error[E0587]: type has conflicting packed and align representation hints
14-
--> $DIR/conflicting-repr-hints.rs:27:1
21+
--> $DIR/conflicting-repr-hints.rs:29:1
1522
|
1623
LL | struct F(i32);
1724
| ^^^^^^^^^^^^^^
1825

1926
error[E0587]: type has conflicting packed and align representation hints
20-
--> $DIR/conflicting-repr-hints.rs:31:1
27+
--> $DIR/conflicting-repr-hints.rs:33:1
2128
|
2229
LL | struct G(i32);
2330
| ^^^^^^^^^^^^^^
2431

2532
error[E0587]: type has conflicting packed and align representation hints
26-
--> $DIR/conflicting-repr-hints.rs:35:1
33+
--> $DIR/conflicting-repr-hints.rs:37:1
2734
|
2835
LL | struct H(i32);
2936
| ^^^^^^^^^^^^^^
3037

3138
error[E0634]: type has conflicting packed representation hints
32-
--> $DIR/conflicting-repr-hints.rs:38:1
39+
--> $DIR/conflicting-repr-hints.rs:40:1
3340
|
3441
LL | struct I(i32);
3542
| ^^^^^^^^^^^^^^
3643

3744
error[E0634]: type has conflicting packed representation hints
38-
--> $DIR/conflicting-repr-hints.rs:42:1
45+
--> $DIR/conflicting-repr-hints.rs:44:1
3946
|
4047
LL | struct J(i32);
4148
| ^^^^^^^^^^^^^^
4249

4350
error[E0587]: type has conflicting packed and align representation hints
44-
--> $DIR/conflicting-repr-hints.rs:48:1
51+
--> $DIR/conflicting-repr-hints.rs:50:1
4552
|
4653
LL | / union X {
4754
LL | |
@@ -50,7 +57,7 @@ LL | | }
5057
| |_^
5158

5259
error[E0587]: type has conflicting packed and align representation hints
53-
--> $DIR/conflicting-repr-hints.rs:55:1
60+
--> $DIR/conflicting-repr-hints.rs:57:1
5461
|
5562
LL | / union Y {
5663
LL | |
@@ -59,7 +66,7 @@ LL | | }
5966
| |_^
6067

6168
error[E0587]: type has conflicting packed and align representation hints
62-
--> $DIR/conflicting-repr-hints.rs:62:1
69+
--> $DIR/conflicting-repr-hints.rs:64:1
6370
|
6471
LL | / union Z {
6572
LL | |

src/test/ui/feature-gates/feature-gate-repr-simd.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
struct Foo(u64, u64);
33

44
#[repr(C)] //~ ERROR conflicting representation hints
5+
//~^ WARN this was previously accepted
56
#[repr(simd)] //~ error: SIMD types are experimental
67
struct Bar(u64, u64);
78

src/test/ui/feature-gates/feature-gate-repr-simd.stderr

+6-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ LL | #[repr(simd)]
88
= help: add `#![feature(repr_simd)]` to the crate attributes to enable
99

1010
error[E0658]: SIMD types are experimental and possibly buggy
11-
--> $DIR/feature-gate-repr-simd.rs:5:1
11+
--> $DIR/feature-gate-repr-simd.rs:6:1
1212
|
1313
LL | #[repr(simd)]
1414
| ^^^^^^^^^^^^^
@@ -21,8 +21,13 @@ error[E0566]: conflicting representation hints
2121
|
2222
LL | #[repr(C)]
2323
| ^
24+
LL |
2425
LL | #[repr(simd)]
2526
| ^^^^
27+
|
28+
= note: `#[deny(conflicting_repr_hints)]` on by default
29+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
30+
= note: for more information, see issue #68585 <https://github.com/rust-lang/rust/issues/68585>
2631

2732
error: aborting due to 3 previous errors
2833

src/test/ui/issues/issue-47094.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
#[repr(C, u8)] //~ ERROR conflicting representation hints
2+
//~^ WARN this was previously accepted
23
enum Foo {
34
A,
45
B,
56
}
67

78
#[repr(C)] //~ ERROR conflicting representation hints
9+
//~^ WARN this was previously accepted
810
#[repr(u8)]
911
enum Bar {
1012
A,

src/test/ui/issues/issue-47094.stderr

+9-1
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,22 @@ error[E0566]: conflicting representation hints
33
|
44
LL | #[repr(C, u8)]
55
| ^ ^^
6+
|
7+
= note: `#[deny(conflicting_repr_hints)]` on by default
8+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
9+
= note: for more information, see issue #68585 <https://github.com/rust-lang/rust/issues/68585>
610

711
error[E0566]: conflicting representation hints
8-
--> $DIR/issue-47094.rs:7:8
12+
--> $DIR/issue-47094.rs:8:8
913
|
1014
LL | #[repr(C)]
1115
| ^
16+
LL |
1217
LL | #[repr(u8)]
1318
| ^^
19+
|
20+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
21+
= note: for more information, see issue #68585 <https://github.com/rust-lang/rust/issues/68585>
1422

1523
error: aborting due to 2 previous errors
1624

0 commit comments

Comments
 (0)