Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 91385d5

Browse files
committedNov 9, 2022
Auto merge of rust-lang#104179 - Manishearth:rollup-yvsx5hh, r=Manishearth
Rollup of 7 pull requests Successful merges: - rust-lang#100508 (avoid making substs of type aliases late bound when used as fn args) - rust-lang#101381 (Test that target feature mix up with homogeneous floats is sound) - rust-lang#103353 (Fix Access Violation when using lld & ThinLTO on windows-msvc) - rust-lang#103521 (Avoid possible infinite loop when next_point reaching the end of file) - rust-lang#103559 (first move on a nested span_label) - rust-lang#103778 (Update several crates for improved support of the new targets) - rust-lang#103827 (Properly remap and check for substs compatibility in `confirm_impl_trait_in_trait_candidate`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents bc2504a + 6c021cf commit 91385d5

File tree

32 files changed

+759
-84
lines changed

32 files changed

+759
-84
lines changed
 

‎Cargo.lock

Lines changed: 39 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2496,7 +2496,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
24962496
checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f"
24972497
dependencies = [
24982498
"lock_api",
2499-
"parking_lot_core 0.9.3",
2499+
"parking_lot_core 0.9.4",
25002500
]
25012501

25022502
[[package]]
@@ -2515,15 +2515,15 @@ dependencies = [
25152515

25162516
[[package]]
25172517
name = "parking_lot_core"
2518-
version = "0.9.3"
2518+
version = "0.9.4"
25192519
source = "registry+https://github.com/rust-lang/crates.io-index"
2520-
checksum = "09a279cbf25cb0757810394fbc1e359949b59e348145c643a939a525692e6929"
2520+
checksum = "4dc9e0dc2adc1c69d09143aff38d3d30c5c3f0df0dad82e6d25547af174ebec0"
25212521
dependencies = [
25222522
"cfg-if 1.0.0",
25232523
"libc",
25242524
"redox_syscall",
25252525
"smallvec",
2526-
"windows-sys 0.36.1",
2526+
"windows-sys 0.42.0",
25272527
]
25282528

25292529
[[package]]
@@ -2748,9 +2748,9 @@ dependencies = [
27482748

27492749
[[package]]
27502750
name = "psm"
2751-
version = "0.1.16"
2751+
version = "0.1.21"
27522752
source = "registry+https://github.com/rust-lang/crates.io-index"
2753-
checksum = "cd136ff4382c4753fc061cb9e4712ab2af263376b95bbd5bd8cd50c020b78e69"
2753+
checksum = "5787f7cda34e3033a72192c018bc5883100330f362ef279a8cbccfce8bb4e874"
27542754
dependencies = [
27552755
"cc",
27562756
]
@@ -4651,9 +4651,9 @@ checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3"
46514651

46524652
[[package]]
46534653
name = "stacker"
4654-
version = "0.1.14"
4654+
version = "0.1.15"
46554655
source = "registry+https://github.com/rust-lang/crates.io-index"
4656-
checksum = "90939d5171a4420b3ff5fbc8954d641e7377335454c259dcb80786f3f21dc9b4"
4656+
checksum = "c886bd4480155fd3ef527d45e9ac8dd7118a898a46530b7b94c3e21866259fce"
46574657
dependencies = [
46584658
"cc",
46594659
"cfg-if 1.0.0",
@@ -5473,17 +5473,25 @@ dependencies = [
54735473

54745474
[[package]]
54755475
name = "windows-sys"
5476-
version = "0.36.1"
5476+
version = "0.42.0"
54775477
source = "registry+https://github.com/rust-lang/crates.io-index"
5478-
checksum = "ea04155a16a59f9eab786fe12a4a450e75cdb175f9e0d80da1e17db09f55b8d2"
5478+
checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7"
54795479
dependencies = [
5480-
"windows_aarch64_msvc 0.36.1",
5481-
"windows_i686_gnu 0.36.1",
5482-
"windows_i686_msvc 0.36.1",
5483-
"windows_x86_64_gnu 0.36.1",
5484-
"windows_x86_64_msvc 0.36.1",
5480+
"windows_aarch64_gnullvm",
5481+
"windows_aarch64_msvc 0.42.0",
5482+
"windows_i686_gnu 0.42.0",
5483+
"windows_i686_msvc 0.42.0",
5484+
"windows_x86_64_gnu 0.42.0",
5485+
"windows_x86_64_gnullvm",
5486+
"windows_x86_64_msvc 0.42.0",
54855487
]
54865488

5489+
[[package]]
5490+
name = "windows_aarch64_gnullvm"
5491+
version = "0.42.0"
5492+
source = "registry+https://github.com/rust-lang/crates.io-index"
5493+
checksum = "41d2aa71f6f0cbe00ae5167d90ef3cfe66527d6f613ca78ac8024c3ccab9a19e"
5494+
54875495
[[package]]
54885496
name = "windows_aarch64_msvc"
54895497
version = "0.28.0"
@@ -5492,9 +5500,9 @@ checksum = "52695a41e536859d5308cc613b4a022261a274390b25bd29dfff4bf08505f3c2"
54925500

54935501
[[package]]
54945502
name = "windows_aarch64_msvc"
5495-
version = "0.36.1"
5503+
version = "0.42.0"
54965504
source = "registry+https://github.com/rust-lang/crates.io-index"
5497-
checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47"
5505+
checksum = "dd0f252f5a35cac83d6311b2e795981f5ee6e67eb1f9a7f64eb4500fbc4dcdb4"
54985506

54995507
[[package]]
55005508
name = "windows_i686_gnu"
@@ -5504,9 +5512,9 @@ checksum = "f54725ac23affef038fecb177de6c9bf065787c2f432f79e3c373da92f3e1d8a"
55045512

55055513
[[package]]
55065514
name = "windows_i686_gnu"
5507-
version = "0.36.1"
5515+
version = "0.42.0"
55085516
source = "registry+https://github.com/rust-lang/crates.io-index"
5509-
checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6"
5517+
checksum = "fbeae19f6716841636c28d695375df17562ca208b2b7d0dc47635a50ae6c5de7"
55105518

55115519
[[package]]
55125520
name = "windows_i686_msvc"
@@ -5516,9 +5524,9 @@ checksum = "51d5158a43cc43623c0729d1ad6647e62fa384a3d135fd15108d37c683461f64"
55165524

55175525
[[package]]
55185526
name = "windows_i686_msvc"
5519-
version = "0.36.1"
5527+
version = "0.42.0"
55205528
source = "registry+https://github.com/rust-lang/crates.io-index"
5521-
checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024"
5529+
checksum = "84c12f65daa39dd2babe6e442988fc329d6243fdce47d7d2d155b8d874862246"
55225530

55235531
[[package]]
55245532
name = "windows_x86_64_gnu"
@@ -5528,9 +5536,15 @@ checksum = "bc31f409f565611535130cfe7ee8e6655d3fa99c1c61013981e491921b5ce954"
55285536

55295537
[[package]]
55305538
name = "windows_x86_64_gnu"
5531-
version = "0.36.1"
5539+
version = "0.42.0"
5540+
source = "registry+https://github.com/rust-lang/crates.io-index"
5541+
checksum = "bf7b1b21b5362cbc318f686150e5bcea75ecedc74dd157d874d754a2ca44b0ed"
5542+
5543+
[[package]]
5544+
name = "windows_x86_64_gnullvm"
5545+
version = "0.42.0"
55325546
source = "registry+https://github.com/rust-lang/crates.io-index"
5533-
checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1"
5547+
checksum = "09d525d2ba30eeb3297665bd434a54297e4170c7f1a44cad4ef58095b4cd2028"
55345548

55355549
[[package]]
55365550
name = "windows_x86_64_msvc"
@@ -5540,9 +5554,9 @@ checksum = "3f2b8c7cbd3bfdddd9ab98769f9746a7fad1bca236554cd032b78d768bc0e89f"
55405554

55415555
[[package]]
55425556
name = "windows_x86_64_msvc"
5543-
version = "0.36.1"
5557+
version = "0.42.0"
55445558
source = "registry+https://github.com/rust-lang/crates.io-index"
5545-
checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680"
5559+
checksum = "f40009d85759725a34da6d89a94e63d7bdc50a862acf0dbc7c8e488f1edcb6f5"
55465560

55475561
[[package]]
55485562
name = "xattr"

‎compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -724,13 +724,19 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
724724
borrow_span,
725725
&self.describe_any_place(borrow.borrowed_place.as_ref()),
726726
);
727-
728-
borrow_spans.var_span_label(
727+
borrow_spans.var_subdiag(
729728
&mut err,
730-
{
729+
|var_span| {
730+
use crate::session_diagnostics::CaptureVarCause::*;
731731
let place = &borrow.borrowed_place;
732732
let desc_place = self.describe_any_place(place.as_ref());
733-
format!("borrow occurs due to use of {}{}", desc_place, borrow_spans.describe())
733+
match borrow_spans {
734+
UseSpans::ClosureUse { generator_kind, .. } => match generator_kind {
735+
Some(_) => BorrowUsePlaceGenerator { place: desc_place, var_span },
736+
None => BorrowUsePlaceClosure { place: desc_place, var_span },
737+
},
738+
_ => BorrowUsePlace { place: desc_place, var_span },
739+
}
734740
},
735741
"mutable",
736742
);

‎compiler/rustc_borrowck/src/diagnostics/mod.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,26 @@ impl UseSpans<'_> {
623623
}
624624
}
625625

626+
/// Add a subdiagnostic to the use of the captured variable, if it exists.
627+
pub(super) fn var_subdiag(
628+
self,
629+
err: &mut Diagnostic,
630+
f: impl Fn(Span) -> crate::session_diagnostics::CaptureVarCause,
631+
kind_desc: impl Into<String>,
632+
) {
633+
if let UseSpans::ClosureUse { capture_kind_span, path_span, .. } = self {
634+
if capture_kind_span == path_span {
635+
err.subdiagnostic(f(capture_kind_span));
636+
} else {
637+
err.subdiagnostic(crate::session_diagnostics::CaptureVarKind {
638+
kind_desc: kind_desc.into(),
639+
kind_span: capture_kind_span,
640+
});
641+
err.subdiagnostic(f(path_span));
642+
}
643+
}
644+
}
645+
626646
/// Returns `false` if this place is not used in a closure.
627647
pub(super) fn for_closure(&self) -> bool {
628648
match *self {

‎compiler/rustc_borrowck/src/session_diagnostics.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,3 +148,33 @@ pub(crate) enum RequireStaticErr {
148148
multi_span: MultiSpan,
149149
},
150150
}
151+
152+
#[derive(Subdiagnostic)]
153+
#[label(borrowck_capture_kind_label)]
154+
pub(crate) struct CaptureVarKind {
155+
pub kind_desc: String,
156+
#[primary_span]
157+
pub kind_span: Span,
158+
}
159+
160+
#[derive(Subdiagnostic)]
161+
pub(crate) enum CaptureVarCause {
162+
#[label(borrowck_var_borrow_by_use_place)]
163+
BorrowUsePlace {
164+
place: String,
165+
#[primary_span]
166+
var_span: Span,
167+
},
168+
#[label(borrowck_var_borrow_by_use_place_in_generator)]
169+
BorrowUsePlaceGenerator {
170+
place: String,
171+
#[primary_span]
172+
var_span: Span,
173+
},
174+
#[label(borrowck_var_borrow_by_use_place_in_closure)]
175+
BorrowUsePlaceClosure {
176+
place: String,
177+
#[primary_span]
178+
var_span: Span,
179+
},
180+
}

‎compiler/rustc_codegen_llvm/src/consts.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use rustc_middle::mir::mono::MonoItem;
1919
use rustc_middle::ty::layout::LayoutOf;
2020
use rustc_middle::ty::{self, Instance, Ty};
2121
use rustc_middle::{bug, span_bug};
22+
use rustc_session::config::Lto;
2223
use rustc_target::abi::{
2324
AddressSpace, Align, HasDataLayout, Primitive, Scalar, Size, WrappingRange,
2425
};
@@ -303,7 +304,8 @@ impl<'ll> CodegenCx<'ll, '_> {
303304
// ThinLTO can't handle this workaround in all cases, so we don't
304305
// emit the attrs. Instead we make them unnecessary by disallowing
305306
// dynamic linking when linker plugin based LTO is enabled.
306-
!self.tcx.sess.opts.cg.linker_plugin_lto.enabled();
307+
!self.tcx.sess.opts.cg.linker_plugin_lto.enabled() &&
308+
self.tcx.sess.lto() != Lto::Thin;
307309

308310
// If this assertion triggers, there's something wrong with commandline
309311
// argument validation.

‎compiler/rustc_data_structures/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ rustc_macros = { path = "../rustc_macros" }
2323
rustc_serialize = { path = "../rustc_serialize" }
2424
smallvec = { version = "1.8.1", features = ["const_generics", "union", "may_dangle"] }
2525
stable_deref_trait = "1.0.0"
26-
stacker = "0.1.14"
26+
stacker = "0.1.15"
2727
tempfile = "3.2"
2828
thin-vec = "0.2.9"
2929
tracing = "0.1"

‎compiler/rustc_error_messages/locales/en-US/borrowck.ftl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,15 @@ borrowck_returned_lifetime_short =
5858
5959
borrowck_used_impl_require_static =
6060
the used `impl` has a `'static` requirement
61+
62+
borrowck_capture_kind_label =
63+
capture is {$kind_desc} because of use here
64+
65+
borrowck_var_borrow_by_use_place_in_generator =
66+
borrow occurs due to use of {$place} in closure in generator
67+
68+
borrowck_var_borrow_by_use_place_in_closure =
69+
borrow occurs due to use of {$place} in closure
70+
71+
borrowck_var_borrow_by_use_place =
72+
borrow occurs due to use of {$place}

‎compiler/rustc_hir_analysis/src/collect/lifetimes.rs

Lines changed: 99 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use rustc_middle::bug;
1818
use rustc_middle::hir::map::Map;
1919
use rustc_middle::hir::nested_filter;
2020
use rustc_middle::middle::resolve_lifetime::*;
21-
use rustc_middle::ty::{self, DefIdTree, TyCtxt};
21+
use rustc_middle::ty::{self, DefIdTree, TyCtxt, TypeSuperVisitable, TypeVisitor};
2222
use rustc_span::def_id::DefId;
2323
use rustc_span::symbol::{sym, Ident};
2424
use rustc_span::Span;
@@ -1781,7 +1781,7 @@ fn is_late_bound_map(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<&FxIndexSet<
17811781

17821782
let mut late_bound = FxIndexSet::default();
17831783

1784-
let mut constrained_by_input = ConstrainedCollector::default();
1784+
let mut constrained_by_input = ConstrainedCollector { regions: Default::default(), tcx };
17851785
for arg_ty in decl.inputs {
17861786
constrained_by_input.visit_ty(arg_ty);
17871787
}
@@ -1834,12 +1834,65 @@ fn is_late_bound_map(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<&FxIndexSet<
18341834
debug!(?late_bound);
18351835
return Some(tcx.arena.alloc(late_bound));
18361836

1837-
#[derive(Default)]
1838-
struct ConstrainedCollector {
1837+
/// Visits a `ty::Ty` collecting information about what generic parameters are constrained.
1838+
///
1839+
/// The visitor does not operate on `hir::Ty` so that it can be called on the rhs of a `type Alias<...> = ...;`
1840+
/// which may live in a separate crate so there would not be any hir available. Instead we use the `type_of`
1841+
/// query to obtain a `ty::Ty` which will be present even in cross crate scenarios. It also naturally
1842+
/// handles cycle detection as we go through the query system.
1843+
///
1844+
/// This is necessary in the first place for the following case:
1845+
/// ```
1846+
/// type Alias<'a, T> = <T as Trait<'a>>::Assoc;
1847+
/// fn foo<'a>(_: Alias<'a, ()>) -> Alias<'a, ()> { ... }
1848+
/// ```
1849+
///
1850+
/// If we conservatively considered `'a` unconstrained then we could break users who had written code before
1851+
/// we started correctly handling aliases. If we considered `'a` constrained then it would become late bound
1852+
/// causing an error during astconv as the `'a` is not constrained by the input type `<() as Trait<'a>>::Assoc`
1853+
/// but appears in the output type `<() as Trait<'a>>::Assoc`.
1854+
///
1855+
/// We must therefore "look into" the `Alias` to see whether we should consider `'a` constrained or not.
1856+
///
1857+
/// See #100508 #85533 #47511 for additional context
1858+
struct ConstrainedCollectorPostAstConv {
1859+
arg_is_constrained: Box<[bool]>,
1860+
}
1861+
1862+
use std::ops::ControlFlow;
1863+
use ty::Ty;
1864+
impl<'tcx> TypeVisitor<'tcx> for ConstrainedCollectorPostAstConv {
1865+
fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow<!> {
1866+
match t.kind() {
1867+
ty::Param(param_ty) => {
1868+
self.arg_is_constrained[param_ty.index as usize] = true;
1869+
}
1870+
ty::Projection(_) => return ControlFlow::Continue(()),
1871+
_ => (),
1872+
}
1873+
t.super_visit_with(self)
1874+
}
1875+
1876+
fn visit_const(&mut self, _: ty::Const<'tcx>) -> ControlFlow<!> {
1877+
ControlFlow::Continue(())
1878+
}
1879+
1880+
fn visit_region(&mut self, r: ty::Region<'tcx>) -> ControlFlow<!> {
1881+
debug!("r={:?}", r.kind());
1882+
if let ty::RegionKind::ReEarlyBound(region) = r.kind() {
1883+
self.arg_is_constrained[region.index as usize] = true;
1884+
}
1885+
1886+
ControlFlow::Continue(())
1887+
}
1888+
}
1889+
1890+
struct ConstrainedCollector<'tcx> {
1891+
tcx: TyCtxt<'tcx>,
18391892
regions: FxHashSet<LocalDefId>,
18401893
}
18411894

1842-
impl<'v> Visitor<'v> for ConstrainedCollector {
1895+
impl<'v> Visitor<'v> for ConstrainedCollector<'_> {
18431896
fn visit_ty(&mut self, ty: &'v hir::Ty<'v>) {
18441897
match ty.kind {
18451898
hir::TyKind::Path(
@@ -1850,6 +1903,47 @@ fn is_late_bound_map(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<&FxIndexSet<
18501903
// (defined above)
18511904
}
18521905

1906+
hir::TyKind::Path(hir::QPath::Resolved(
1907+
None,
1908+
hir::Path { res: Res::Def(DefKind::TyAlias, alias_def), segments, span },
1909+
)) => {
1910+
// See comments on `ConstrainedCollectorPostAstConv` for why this arm does not just consider
1911+
// substs to be unconstrained.
1912+
let generics = self.tcx.generics_of(alias_def);
1913+
let mut walker = ConstrainedCollectorPostAstConv {
1914+
arg_is_constrained: vec![false; generics.params.len()].into_boxed_slice(),
1915+
};
1916+
walker.visit_ty(self.tcx.type_of(alias_def));
1917+
1918+
match segments.last() {
1919+
Some(hir::PathSegment { args: Some(args), .. }) => {
1920+
let tcx = self.tcx;
1921+
for constrained_arg in
1922+
args.args.iter().enumerate().flat_map(|(n, arg)| {
1923+
match walker.arg_is_constrained.get(n) {
1924+
Some(true) => Some(arg),
1925+
Some(false) => None,
1926+
None => {
1927+
tcx.sess.delay_span_bug(
1928+
*span,
1929+
format!(
1930+
"Incorrect generic arg count for alias {:?}",
1931+
alias_def
1932+
),
1933+
);
1934+
None
1935+
}
1936+
}
1937+
})
1938+
{
1939+
self.visit_generic_arg(constrained_arg);
1940+
}
1941+
}
1942+
Some(_) => (),
1943+
None => bug!("Path with no segments or self type"),
1944+
}
1945+
}
1946+
18531947
hir::TyKind::Path(hir::QPath::Resolved(None, ref path)) => {
18541948
// consider only the lifetimes on the final
18551949
// segment; I am not sure it's even currently

‎compiler/rustc_middle/src/ty/error.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,9 @@ impl<'tcx> TyCtxt<'tcx> {
430430
(ty::Projection(_), ty::Projection(_)) => {
431431
diag.note("an associated type was expected, but a different one was found");
432432
}
433-
(ty::Param(p), ty::Projection(proj)) | (ty::Projection(proj), ty::Param(p)) => {
433+
(ty::Param(p), ty::Projection(proj)) | (ty::Projection(proj), ty::Param(p))
434+
if self.def_kind(proj.item_def_id) != DefKind::ImplTraitPlaceholder =>
435+
{
434436
let generics = self.generics_of(body_owner_def_id);
435437
let p_span = self.def_span(generics.type_param(p, self).def_id);
436438
if !sp.contains(p_span) {

‎compiler/rustc_span/src/source_map.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -855,7 +855,8 @@ impl SourceMap {
855855
/// Returns a new span representing the next character after the end-point of this span.
856856
/// Special cases:
857857
/// - if span is a dummy one, returns the same span
858-
/// - if next_point reached the end of source, return span with lo = hi
858+
/// - if next_point reached the end of source, return a span exceeding the end of source,
859+
/// which means sm.span_to_snippet(next_point) will get `Err`
859860
/// - respect multi-byte characters
860861
pub fn next_point(&self, sp: Span) -> Span {
861862
if sp.is_dummy() {
@@ -864,9 +865,6 @@ impl SourceMap {
864865
let start_of_next_point = sp.hi().0;
865866

866867
let width = self.find_width_of_character_at_span(sp, true);
867-
if width == 0 {
868-
return Span::new(sp.hi(), sp.hi(), sp.ctxt(), None);
869-
}
870868
// If the width is 1, then the next span should only contain the next char besides current ending.
871869
// However, in the case of a multibyte character, where the width != 1, the next span should
872870
// span multiple bytes to include the whole character.
@@ -938,7 +936,7 @@ impl SourceMap {
938936
// Ensure indexes are also not malformed.
939937
if start_index > end_index || end_index > source_len - 1 {
940938
debug!("find_width_of_character_at_span: source indexes are malformed");
941-
return 0;
939+
return 1;
942940
}
943941

944942
let src = local_begin.sf.external_src.borrow();

‎compiler/rustc_span/src/source_map/tests.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -511,16 +511,17 @@ fn test_next_point() {
511511
assert_eq!(span.lo().0, 4);
512512
assert_eq!(span.hi().0, 5);
513513

514-
// A non-empty span at the last byte should advance to create an empty
515-
// span pointing at the end of the file.
514+
// Reaching to the end of file, return a span that will get error with `span_to_snippet`
516515
let span = Span::with_root_ctxt(BytePos(4), BytePos(5));
517516
let span = sm.next_point(span);
518517
assert_eq!(span.lo().0, 5);
519-
assert_eq!(span.hi().0, 5);
518+
assert_eq!(span.hi().0, 6);
519+
assert!(sm.span_to_snippet(span).is_err());
520520

521-
// Empty span pointing just past the last byte.
521+
// Reaching to the end of file, return a span that will get error with `span_to_snippet`
522522
let span = Span::with_root_ctxt(BytePos(5), BytePos(5));
523523
let span = sm.next_point(span);
524524
assert_eq!(span.lo().0, 5);
525-
assert_eq!(span.hi().0, 5);
525+
assert_eq!(span.hi().0, 6);
526+
assert!(sm.span_to_snippet(span).is_err());
526527
}

‎compiler/rustc_trait_selection/src/traits/project.rs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2187,7 +2187,7 @@ fn confirm_impl_candidate<'cx, 'tcx>(
21872187
// Verify that the trait item and its implementation have compatible substs lists
21882188
fn check_substs_compatible<'tcx>(
21892189
tcx: TyCtxt<'tcx>,
2190-
assoc_ty: &ty::AssocItem,
2190+
assoc_item: &ty::AssocItem,
21912191
substs: ty::SubstsRef<'tcx>,
21922192
) -> bool {
21932193
fn check_substs_compatible_inner<'tcx>(
@@ -2219,7 +2219,10 @@ fn check_substs_compatible<'tcx>(
22192219
true
22202220
}
22212221

2222-
check_substs_compatible_inner(tcx, tcx.generics_of(assoc_ty.def_id), substs.as_slice())
2222+
let generics = tcx.generics_of(assoc_item.def_id);
2223+
// Chop off any additional substs (RPITIT) substs
2224+
let substs = &substs[0..generics.count().min(substs.len())];
2225+
check_substs_compatible_inner(tcx, generics, substs)
22232226
}
22242227

22252228
fn confirm_impl_trait_in_trait_candidate<'tcx>(
@@ -2248,11 +2251,27 @@ fn confirm_impl_trait_in_trait_candidate<'tcx>(
22482251
};
22492252
}
22502253

2251-
let impl_fn_def_id = leaf_def.item.def_id;
22522254
// Rebase from {trait}::{fn}::{opaque} to {impl}::{fn}::{opaque},
22532255
// since `data.substs` are the impl substs.
22542256
let impl_fn_substs =
22552257
obligation.predicate.substs.rebase_onto(tcx, tcx.parent(trait_fn_def_id), data.substs);
2258+
let impl_fn_substs = translate_substs(
2259+
selcx.infcx(),
2260+
obligation.param_env,
2261+
data.impl_def_id,
2262+
impl_fn_substs,
2263+
leaf_def.defining_node,
2264+
);
2265+
2266+
if !check_substs_compatible(tcx, &leaf_def.item, impl_fn_substs) {
2267+
let err = tcx.ty_error_with_message(
2268+
obligation.cause.span,
2269+
"impl method and trait method have different parameters",
2270+
);
2271+
return Progress { term: err.into(), obligations };
2272+
}
2273+
2274+
let impl_fn_def_id = leaf_def.item.def_id;
22562275

22572276
let cause = ObligationCause::new(
22582277
obligation.cause.span,

‎src/bootstrap/Cargo.lock

Lines changed: 66 additions & 9 deletions
Original file line numberDiff line numberDiff line change

‎src/bootstrap/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ test = false
3636

3737
[dependencies]
3838
cmake = "0.1.38"
39-
fd-lock = "3.0.6"
39+
fd-lock = "3.0.7"
4040
filetime = "0.2"
4141
getopts = "0.2.19"
4242
cc = "1.0.69"
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
use std::sync::atomic::{AtomicPtr, Ordering};
2+
3+
#[inline(always)]
4+
pub fn memrchr() {
5+
fn detect() {}
6+
7+
static CROSS_CRATE_STATIC_ITEM: AtomicPtr<()> = AtomicPtr::new(detect as *mut ());
8+
9+
unsafe {
10+
let fun = CROSS_CRATE_STATIC_ITEM.load(Ordering::SeqCst);
11+
std::mem::transmute::<*mut (), fn()>(fun)()
12+
}
13+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// compile-flags: -O -C lto=thin -C prefer-dynamic=no
2+
// only-windows
3+
// aux-build:static_dllimport_aux.rs
4+
5+
// Test that on Windows, when performing ThinLTO, we do not mark cross-crate static items with
6+
// dllimport because lld does not fix the symbol names for us.
7+
8+
extern crate static_dllimport_aux;
9+
10+
// CHECK-LABEL: @{{.+}}CROSS_CRATE_STATIC_ITEM{{.+}} =
11+
// CHECK-SAME: external local_unnamed_addr global %"{{.+}}AtomicPtr
12+
13+
pub fn main() {
14+
static_dllimport_aux::memrchr();
15+
}
Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
// This test check that even if we mixup target feature of function with homogenous floats,
2+
// the abi is sound and still produce the right answer.
3+
//
4+
// This is basically the same test as src/test/ui/simd/target-feature-mixup.rs but for floats and
5+
// without #[repr(simd)]
6+
7+
// run-pass
8+
// ignore-emscripten
9+
// ignore-sgx no processes
10+
11+
#![feature(avx512_target_feature)]
12+
13+
#![allow(overflowing_literals)]
14+
#![allow(unused_variables)]
15+
16+
use std::process::{Command, ExitStatus};
17+
use std::env;
18+
19+
fn main() {
20+
if let Some(level) = env::args().nth(1) {
21+
return test::main(&level)
22+
}
23+
24+
match std::env::var("TARGET") {
25+
Ok(s) => {
26+
// Skip this tests on i586-unknown-linux-gnu where sse2 is disabled
27+
if s.contains("i586") {
28+
return
29+
}
30+
}
31+
Err(_) => return,
32+
}
33+
34+
let me = env::current_exe().unwrap();
35+
for level in ["sse", "avx", "avx512"].iter() {
36+
let status = Command::new(&me).arg(level).status().unwrap();
37+
if status.success() {
38+
println!("success with {}", level);
39+
continue
40+
}
41+
42+
// We don't actually know if our computer has the requisite target features
43+
// for the test below. Testing for that will get added to libstd later so
44+
// for now just assume sigill means this is a machine that can't run this test.
45+
if is_sigill(status) {
46+
println!("sigill with {}, assuming spurious", level);
47+
continue
48+
}
49+
panic!("invalid status at {}: {}", level, status);
50+
}
51+
}
52+
53+
#[cfg(unix)]
54+
fn is_sigill(status: ExitStatus) -> bool {
55+
use std::os::unix::prelude::*;
56+
status.signal() == Some(4)
57+
}
58+
59+
#[cfg(windows)]
60+
fn is_sigill(status: ExitStatus) -> bool {
61+
status.code() == Some(0xc000001d)
62+
}
63+
64+
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
65+
#[allow(nonstandard_style)]
66+
mod test {
67+
#[derive(PartialEq, Debug, Clone, Copy)]
68+
struct f32x2(f32, f32);
69+
70+
#[derive(PartialEq, Debug, Clone, Copy)]
71+
struct f32x4(f32, f32, f32, f32);
72+
73+
#[derive(PartialEq, Debug, Clone, Copy)]
74+
struct f32x8(f32, f32, f32, f32, f32, f32, f32, f32);
75+
76+
pub fn main(level: &str) {
77+
unsafe {
78+
main_normal(level);
79+
main_sse(level);
80+
if level == "sse" {
81+
return
82+
}
83+
main_avx(level);
84+
if level == "avx" {
85+
return
86+
}
87+
main_avx512(level);
88+
}
89+
}
90+
91+
macro_rules! mains {
92+
($(
93+
$(#[$attr:meta])*
94+
unsafe fn $main:ident(level: &str) {
95+
...
96+
}
97+
)*) => ($(
98+
$(#[$attr])*
99+
unsafe fn $main(level: &str) {
100+
let m128 = f32x2(1., 2.);
101+
let m256 = f32x4(3., 4., 5., 6.);
102+
let m512 = f32x8(7., 8., 9., 10., 11., 12., 13., 14.);
103+
assert_eq!(id_sse_128(m128), m128);
104+
assert_eq!(id_sse_256(m256), m256);
105+
assert_eq!(id_sse_512(m512), m512);
106+
107+
if level == "sse" {
108+
return
109+
}
110+
assert_eq!(id_avx_128(m128), m128);
111+
assert_eq!(id_avx_256(m256), m256);
112+
assert_eq!(id_avx_512(m512), m512);
113+
114+
if level == "avx" {
115+
return
116+
}
117+
assert_eq!(id_avx512_128(m128), m128);
118+
assert_eq!(id_avx512_256(m256), m256);
119+
assert_eq!(id_avx512_512(m512), m512);
120+
}
121+
)*)
122+
}
123+
124+
mains! {
125+
unsafe fn main_normal(level: &str) { ... }
126+
#[target_feature(enable = "sse2")]
127+
unsafe fn main_sse(level: &str) { ... }
128+
#[target_feature(enable = "avx")]
129+
unsafe fn main_avx(level: &str) { ... }
130+
#[target_feature(enable = "avx512bw")]
131+
unsafe fn main_avx512(level: &str) { ... }
132+
}
133+
134+
#[target_feature(enable = "sse2")]
135+
unsafe fn id_sse_128(a: f32x2) -> f32x2 {
136+
assert_eq!(a, f32x2(1., 2.));
137+
a.clone()
138+
}
139+
140+
#[target_feature(enable = "sse2")]
141+
unsafe fn id_sse_256(a: f32x4) -> f32x4 {
142+
assert_eq!(a, f32x4(3., 4., 5., 6.));
143+
a.clone()
144+
}
145+
146+
#[target_feature(enable = "sse2")]
147+
unsafe fn id_sse_512(a: f32x8) -> f32x8 {
148+
assert_eq!(a, f32x8(7., 8., 9., 10., 11., 12., 13., 14.));
149+
a.clone()
150+
}
151+
152+
#[target_feature(enable = "avx")]
153+
unsafe fn id_avx_128(a: f32x2) -> f32x2 {
154+
assert_eq!(a, f32x2(1., 2.));
155+
a.clone()
156+
}
157+
158+
#[target_feature(enable = "avx")]
159+
unsafe fn id_avx_256(a: f32x4) -> f32x4 {
160+
assert_eq!(a, f32x4(3., 4., 5., 6.));
161+
a.clone()
162+
}
163+
164+
#[target_feature(enable = "avx")]
165+
unsafe fn id_avx_512(a: f32x8) -> f32x8 {
166+
assert_eq!(a, f32x8(7., 8., 9., 10., 11., 12., 13., 14.));
167+
a.clone()
168+
}
169+
170+
#[target_feature(enable = "avx512bw")]
171+
unsafe fn id_avx512_128(a: f32x2) -> f32x2 {
172+
assert_eq!(a, f32x2(1., 2.));
173+
a.clone()
174+
}
175+
176+
#[target_feature(enable = "avx512bw")]
177+
unsafe fn id_avx512_256(a: f32x4) -> f32x4 {
178+
assert_eq!(a, f32x4(3., 4., 5., 6.));
179+
a.clone()
180+
}
181+
182+
#[target_feature(enable = "avx512bw")]
183+
unsafe fn id_avx512_512(a: f32x8) -> f32x8 {
184+
assert_eq!(a, f32x8(7., 8., 9., 10., 11., 12., 13., 14.));
185+
a.clone()
186+
}
187+
}
188+
189+
#[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))]
190+
mod test {
191+
pub fn main(level: &str) {}
192+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#![feature(return_position_impl_trait_in_trait)]
2+
#![allow(incomplete_features)]
3+
4+
struct U;
5+
6+
trait Foo {
7+
fn bar(&self) -> impl Sized;
8+
}
9+
10+
impl Foo for U {
11+
fn bar<T>(&self) {}
12+
//~^ ERROR method `bar` has 1 type parameter but its trait declaration has 0 type parameters
13+
}
14+
15+
fn main() {
16+
U.bar();
17+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0049]: method `bar` has 1 type parameter but its trait declaration has 0 type parameters
2+
--> $DIR/generics-mismatch.rs:11:12
3+
|
4+
LL | fn bar(&self) -> impl Sized;
5+
| - expected 0 type parameters
6+
...
7+
LL | fn bar<T>(&self) {}
8+
| ^ found 1 type parameter
9+
10+
error: aborting due to previous error
11+
12+
For more information about this error, try `rustc --explain E0049`.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// FIXME(compiler-errors): I'm not exactly sure if this is expected to pass or not.
2+
// But we fixed an ICE anyways.
3+
4+
#![feature(specialization)]
5+
#![feature(return_position_impl_trait_in_trait)]
6+
#![allow(incomplete_features)]
7+
8+
trait Foo {
9+
fn bar(&self) -> impl Sized;
10+
}
11+
12+
default impl<U> Foo for U
13+
where
14+
U: Copy,
15+
{
16+
fn bar(&self) -> U {
17+
//~^ ERROR method `bar` has an incompatible type for trait
18+
*self
19+
}
20+
}
21+
22+
impl Foo for i32 {}
23+
24+
fn main() {
25+
1i32.bar();
26+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
error[E0053]: method `bar` has an incompatible type for trait
2+
--> $DIR/specialization-broken.rs:16:22
3+
|
4+
LL | default impl<U> Foo for U
5+
| - this type parameter
6+
...
7+
LL | fn bar(&self) -> U {
8+
| ^
9+
| |
10+
| expected associated type, found type parameter `U`
11+
| help: change the output type to match the trait: `impl Sized`
12+
|
13+
note: type in trait
14+
--> $DIR/specialization-broken.rs:9:22
15+
|
16+
LL | fn bar(&self) -> impl Sized;
17+
| ^^^^^^^^^^
18+
= note: expected fn pointer `fn(&U) -> impl Sized`
19+
found fn pointer `fn(&U) -> U`
20+
21+
error: aborting due to previous error
22+
23+
For more information about this error, try `rustc --explain E0053`.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// check-pass
2+
3+
#![feature(specialization)]
4+
#![feature(return_position_impl_trait_in_trait)]
5+
#![allow(incomplete_features)]
6+
7+
trait Foo {
8+
fn bar(&self) -> impl Sized;
9+
}
10+
11+
impl<U> Foo for U
12+
where
13+
U: Copy,
14+
{
15+
fn bar(&self) -> U {
16+
*self
17+
}
18+
}
19+
20+
impl Foo for i32 {}
21+
22+
fn main() {
23+
let _: i32 = 1i32.bar();
24+
}

‎src/test/ui/issues/issue-47511.stderr

Lines changed: 0 additions & 18 deletions
This file was deleted.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pub trait Trait<'a> {
2+
type Assoc;
3+
}
4+
5+
pub type Alias<'a, T> = <T as Trait<'a>>::Assoc;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// aux-build:upstream_alias.rs
2+
// check-pass
3+
4+
extern crate upstream_alias;
5+
6+
fn foo<'a, T: for<'b> upstream_alias::Trait<'b>>(_: upstream_alias::Alias<'a, T>) -> &'a () {
7+
todo!()
8+
}
9+
10+
fn main() {}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// check-pass
2+
3+
trait Gats<'a> {
4+
type Assoc;
5+
type Assoc2;
6+
}
7+
8+
trait Trait: for<'a> Gats<'a> {
9+
fn foo<'a>(_: &mut <Self as Gats<'a>>::Assoc) -> <Self as Gats<'a>>::Assoc2;
10+
}
11+
12+
impl<'a> Gats<'a> for () {
13+
type Assoc = &'a u32;
14+
type Assoc2 = ();
15+
}
16+
17+
type GatsAssoc<'a, T> = <T as Gats<'a>>::Assoc;
18+
type GatsAssoc2<'a, T> = <T as Gats<'a>>::Assoc2;
19+
20+
impl Trait for () {
21+
fn foo<'a>(_: &mut GatsAssoc<'a, Self>) -> GatsAssoc2<'a, Self> {}
22+
}
23+
24+
fn main() {}

‎src/test/ui/issues/issue-47511.rs renamed to ‎src/test/ui/late-bound-lifetimes/issue-47511.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
// check-fail
2-
// known-bug: #47511
3-
4-
// Regression test for #47511: anonymous lifetimes can appear
5-
// unconstrained in a return type, but only if they appear just once
6-
// in the input, as the input to a projection.
1+
// check-pass
72

83
fn f(_: X) -> X {
94
unimplemented!()
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// check-pass
2+
3+
fn f(_: X) -> X {
4+
unimplemented!()
5+
}
6+
7+
fn g<'a>(_: X<'a>) -> X<'a> {
8+
unimplemented!()
9+
}
10+
11+
type X<'a> = &'a ();
12+
13+
fn main() {
14+
let _: for<'a> fn(X<'a>) -> X<'a> = g;
15+
let _: for<'a> fn(X<'a>) -> X<'a> = f;
16+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// ensures that we don't ICE when there are too many args supplied to the alias.
2+
3+
trait Trait<'a> {
4+
type Assoc;
5+
}
6+
7+
type Alias<'a, T> = <T as Trait<'a>>::Assoc;
8+
9+
fn bar<'a, T: Trait<'a>>(_: Alias<'a, 'a, T>) {}
10+
//~^ error: this type alias takes 1 lifetime argument but 2 lifetime arguments were supplied
11+
12+
fn main() {}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error[E0107]: this type alias takes 1 lifetime argument but 2 lifetime arguments were supplied
2+
--> $DIR/mismatched_arg_count.rs:9:29
3+
|
4+
LL | fn bar<'a, T: Trait<'a>>(_: Alias<'a, 'a, T>) {}
5+
| ^^^^^ -- help: remove this lifetime argument
6+
| |
7+
| expected 1 lifetime argument
8+
|
9+
note: type alias defined here, with 1 lifetime parameter: `'a`
10+
--> $DIR/mismatched_arg_count.rs:7:6
11+
|
12+
LL | type Alias<'a, T> = <T as Trait<'a>>::Assoc;
13+
| ^^^^^ --
14+
15+
error: aborting due to previous error
16+
17+
For more information about this error, try `rustc --explain E0107`.

‎src/test/ui/parser/issue-103451.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// error-pattern: this file contains an unclosed delimiter
2+
// error-pattern: expected value, found struct `R`
3+
struct R { }
4+
struct S {
5+
x: [u8; R
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
error: this file contains an unclosed delimiter
2+
--> $DIR/issue-103451.rs:5:15
3+
|
4+
LL | struct S {
5+
| - unclosed delimiter
6+
LL | x: [u8; R
7+
| - ^
8+
| |
9+
| unclosed delimiter
10+
11+
error: this file contains an unclosed delimiter
12+
--> $DIR/issue-103451.rs:5:15
13+
|
14+
LL | struct S {
15+
| - unclosed delimiter
16+
LL | x: [u8; R
17+
| - ^
18+
| |
19+
| unclosed delimiter
20+
21+
error[E0423]: expected value, found struct `R`
22+
--> $DIR/issue-103451.rs:5:13
23+
|
24+
LL | struct R { }
25+
| ------------ `R` defined here
26+
LL | struct S {
27+
LL | x: [u8; R
28+
| ^ help: use struct literal syntax instead: `R {}`
29+
30+
error: aborting due to 3 previous errors
31+
32+
For more information about this error, try `rustc --explain E0423`.

0 commit comments

Comments
 (0)
This repository has been archived.