Skip to content

Commit b020ec7

Browse files
committed
Merge branch 'master' into error_ast_low_type_contraint_parentheses
2 parents dae3e5a + 9598b4b commit b020ec7

File tree

127 files changed

+1998
-458
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

127 files changed

+1998
-458
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5509,6 +5509,8 @@ dependencies = [
55095509
"pretty_assertions 1.2.1",
55105510
"regex",
55115511
"rustc_version",
5512+
"serde",
5513+
"serde_json",
55125514
]
55135515

55145516
[[package]]

compiler/rustc/Windows Manifest.xml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2+
<!--
3+
This is a Windows application manifest file.
4+
See: https://docs.microsoft.com/en-us/windows/win32/sbscs/application-manifests
5+
-->
6+
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
7+
<!-- Versions rustc supports as compiler hosts -->
8+
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
9+
<application>
10+
<!-- Windows 7 --><supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
11+
<!-- Windows 8 --><supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>
12+
<!-- Windows 8.1 --><supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
13+
<!-- Windows 10 and 11 --><supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
14+
</application>
15+
</compatibility>
16+
<!-- Use UTF-8 code page -->
17+
<asmv3:application>
18+
<asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2019/WindowsSettings">
19+
<activeCodePage>UTF-8</activeCodePage>
20+
</asmv3:windowsSettings>
21+
</asmv3:application>
22+
<!-- Remove (most) legacy path limits -->
23+
<asmv3:application>
24+
<asmv3:windowsSettings xmlns:ws2="http://schemas.microsoft.com/SMI/2016/WindowsSettings">
25+
<ws2:longPathAware>true</ws2:longPathAware>
26+
</asmv3:windowsSettings>
27+
</asmv3:application>
28+
</assembly>

compiler/rustc/build.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
use std::env;
2+
3+
fn main() {
4+
let target_os = env::var("CARGO_CFG_TARGET_OS");
5+
let target_env = env::var("CARGO_CFG_TARGET_ENV");
6+
if Ok("windows") == target_os.as_deref() && Ok("msvc") == target_env.as_deref() {
7+
set_windows_exe_options();
8+
}
9+
}
10+
11+
// Add a manifest file to rustc.exe.
12+
fn set_windows_exe_options() {
13+
static WINDOWS_MANIFEST_FILE: &str = "Windows Manifest.xml";
14+
15+
let mut manifest = env::current_dir().unwrap();
16+
manifest.push(WINDOWS_MANIFEST_FILE);
17+
18+
println!("cargo:rerun-if-changed={}", WINDOWS_MANIFEST_FILE);
19+
// Embed the Windows application manifest file.
20+
println!("cargo:rustc-link-arg-bin=rustc-main=/MANIFEST:EMBED");
21+
println!("cargo:rustc-link-arg-bin=rustc-main=/MANIFESTINPUT:{}", manifest.to_str().unwrap());
22+
// Turn linker warnings into errors.
23+
println!("cargo:rustc-link-arg-bin=rustc-main=/WX");
24+
}

compiler/rustc_borrowck/src/diagnostics/region_name.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -567,15 +567,17 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
567567
let lifetime =
568568
self.try_match_adt_and_generic_args(substs, needle_fr, args, search_stack)?;
569569
match lifetime.name {
570-
hir::LifetimeName::Param(_)
570+
hir::LifetimeName::Param(hir::ParamName::Plain(_) | hir::ParamName::Error)
571571
| hir::LifetimeName::Error
572-
| hir::LifetimeName::Static
573-
| hir::LifetimeName::Underscore => {
572+
| hir::LifetimeName::Static => {
574573
let lifetime_span = lifetime.span;
575574
Some(RegionNameHighlight::MatchedAdtAndSegment(lifetime_span))
576575
}
577576

578-
hir::LifetimeName::ImplicitObjectLifetimeDefault | hir::LifetimeName::Implicit => {
577+
hir::LifetimeName::Param(hir::ParamName::Fresh(_))
578+
| hir::LifetimeName::ImplicitObjectLifetimeDefault
579+
| hir::LifetimeName::Implicit
580+
| hir::LifetimeName::Underscore => {
579581
// In this case, the user left off the lifetime; so
580582
// they wrote something like:
581583
//

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2147,7 +2147,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
21472147
}
21482148
}
21492149

2150-
CastKind::PointerAddress => {
2150+
CastKind::PointerExposeAddress => {
21512151
let ty_from = op.ty(body, tcx);
21522152
let cast_ty_from = CastTy::from_ty(ty_from);
21532153
let cast_ty_to = CastTy::from_ty(*ty);

compiler/rustc_codegen_cranelift/src/base.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,11 @@ fn codegen_stmt<'tcx>(
607607
let operand = codegen_operand(fx, operand);
608608
lval.write_cvalue(fx, operand.cast_pointer_to(to_layout));
609609
}
610-
Rvalue::Cast(CastKind::Misc | CastKind::PointerAddress, ref operand, to_ty) => {
610+
Rvalue::Cast(
611+
CastKind::Misc | CastKind::PointerExposeAddress,
612+
ref operand,
613+
to_ty,
614+
) => {
611615
let operand = codegen_operand(fx, operand);
612616
let from_ty = operand.layout().ty;
613617
let to_ty = fx.monomorphize(to_ty);

compiler/rustc_codegen_ssa/src/mir/rvalue.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
181181
let cast = bx.cx().layout_of(self.monomorphize(mir_cast_ty));
182182

183183
let val = match *kind {
184-
mir::CastKind::PointerAddress => {
184+
mir::CastKind::PointerExposeAddress => {
185185
assert!(bx.cx().is_backend_immediate(cast));
186186
let llptr = operand.immediate();
187187
let llcast_ty = bx.cx().immediate_backend_type(cast);

compiler/rustc_const_eval/src/interpret/cast.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
3131
self.unsize_into(src, cast_ty, dest)?;
3232
}
3333

34-
PointerAddress => {
34+
PointerExposeAddress => {
3535
let src = self.read_immediate(src)?;
36-
let res = self.pointer_address_cast(&src, cast_ty)?;
36+
let res = self.pointer_expose_address_cast(&src, cast_ty)?;
3737
self.write_immediate(res, dest)?;
3838
}
3939

@@ -184,7 +184,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
184184
Ok(self.cast_from_int_like(scalar, src.layout, cast_ty)?.into())
185185
}
186186

187-
pub fn pointer_address_cast(
187+
pub fn pointer_expose_address_cast(
188188
&mut self,
189189
src: &ImmTy<'tcx, M::PointerTag>,
190190
cast_ty: Ty<'tcx>,

compiler/rustc_const_eval/src/interpret/memory.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,10 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
441441
msg,
442442
})
443443
}
444+
// Ensure we never consider the null pointer dereferencable.
445+
if M::PointerTag::OFFSET_IS_ADDR {
446+
assert_ne!(ptr.addr(), Size::ZERO);
447+
}
444448
// Test align. Check this last; if both bounds and alignment are violated
445449
// we want the error to be about the bounds.
446450
if let Some(align) = align {

compiler/rustc_const_eval/src/transform/check_consts/check.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
542542
// in the type of any local, which also excludes casts).
543543
}
544544

545-
Rvalue::Cast(CastKind::PointerAddress, _, _) => {
545+
Rvalue::Cast(CastKind::PointerExposeAddress, _, _) => {
546546
self.check_op(ops::RawPtrToIntCast);
547547
}
548548

compiler/rustc_const_eval/src/transform/promote_consts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ impl<'tcx> Validator<'_, 'tcx> {
502502
Rvalue::ThreadLocalRef(_) => return Err(Unpromotable),
503503

504504
// ptr-to-int casts are not possible in consts and thus not promotable
505-
Rvalue::Cast(CastKind::PointerAddress, _, _) => return Err(Unpromotable),
505+
Rvalue::Cast(CastKind::PointerExposeAddress, _, _) => return Err(Unpromotable),
506506

507507
// int-to-ptr casts are fine, they just use the integer value at pointer type.
508508
Rvalue::Cast(_, operand, _) => {

compiler/rustc_data_structures/src/sso/set.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,10 @@ impl<T: Eq + Hash> SsoHashSet<T> {
126126

127127
/// Adds a value to the set.
128128
///
129-
/// If the set did not have this value present, `true` is returned.
129+
/// Returns whether the value was newly inserted. That is:
130130
///
131-
/// If the set did have this value present, `false` is returned.
131+
/// - If the set did not previously contain this value, `true` is returned.
132+
/// - If the set already contained this value, `false` is returned.
132133
#[inline]
133134
pub fn insert(&mut self, elem: T) -> bool {
134135
self.map.insert(elem, ()).is_none()

compiler/rustc_error_messages/locales/en-US/parser.ftl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,21 @@ parser-add-paren = try adding parentheses
1414
parser-forgot-paren = perhaps you forgot parentheses?
1515
1616
parser-expect-path = expected a path
17+
18+
parser-maybe-recover-from-bad-qpath-stage-2 =
19+
missing angle brackets in associated item path
20+
.suggestion = try: `{$ty}`
21+
22+
parser-incorrect-semicolon =
23+
expected item, found `;`
24+
.suggestion = remove this semicolon
25+
.help = {$name} declarations are not followed by a semicolon
26+
27+
parser-incorrect-use-of-await =
28+
incorrect use of `await`
29+
.parentheses-suggestion = `await` is not a method call, remove the parentheses
30+
.postfix-suggestion = `await` is a postfix operation
31+
32+
parser-in-in-typo =
33+
expected iterable, found keyword `in`
34+
.suggestion = remove the duplicated `in`

compiler/rustc_errors/src/emitter.rs

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1715,6 +1715,7 @@ impl EmitterWriter {
17151715

17161716
fn emit_suggestion_default(
17171717
&mut self,
1718+
span: &MultiSpan,
17181719
suggestion: &CodeSuggestion,
17191720
args: &FluentArgs<'_>,
17201721
level: &Level,
@@ -1766,6 +1767,30 @@ impl EmitterWriter {
17661767
None,
17671768
}
17681769

1770+
if let Some(span) = span.primary_span() {
1771+
// Compare the primary span of the diagnostic with the span of the suggestion
1772+
// being emitted. If they belong to the same file, we don't *need* to show the
1773+
// file name, saving in verbosity, but if it *isn't* we do need it, otherwise we're
1774+
// telling users to make a change but not clarifying *where*.
1775+
let loc = sm.lookup_char_pos(parts[0].span.lo());
1776+
if loc.file.name != sm.span_to_filename(span) && loc.file.name.is_real() {
1777+
buffer.puts(row_num - 1, 0, "--> ", Style::LineNumber);
1778+
buffer.append(
1779+
row_num - 1,
1780+
&format!(
1781+
"{}:{}:{}",
1782+
sm.filename_for_diagnostics(&loc.file.name),
1783+
sm.doctest_offset_line(&loc.file.name, loc.line),
1784+
loc.col.0 + 1,
1785+
),
1786+
Style::LineAndColumn,
1787+
);
1788+
for _ in 0..max_line_num_len {
1789+
buffer.prepend(row_num - 1, " ", Style::NoStyle);
1790+
}
1791+
row_num += 1;
1792+
}
1793+
}
17691794
let show_code_change = if has_deletion && !is_multiline {
17701795
DisplaySuggestion::Diff
17711796
} else if (parts.len() != 1 || parts[0].snippet.trim() != complete.trim())
@@ -1787,7 +1812,7 @@ impl EmitterWriter {
17871812
assert!(!file_lines.lines.is_empty() || parts[0].span.is_dummy());
17881813

17891814
let line_start = sm.lookup_char_pos(parts[0].span.lo()).line;
1790-
draw_col_separator_no_space(&mut buffer, 1, max_line_num_len + 1);
1815+
draw_col_separator_no_space(&mut buffer, row_num - 1, max_line_num_len + 1);
17911816
let mut lines = complete.lines();
17921817
if lines.clone().next().is_none() {
17931818
// Account for a suggestion to completely remove a line(s) with whitespace (#94192).
@@ -2046,9 +2071,13 @@ impl EmitterWriter {
20462071
) {
20472072
panic!("failed to emit error: {}", e);
20482073
}
2049-
} else if let Err(e) =
2050-
self.emit_suggestion_default(sugg, args, &Level::Help, max_line_num_len)
2051-
{
2074+
} else if let Err(e) = self.emit_suggestion_default(
2075+
span,
2076+
sugg,
2077+
args,
2078+
&Level::Help,
2079+
max_line_num_len,
2080+
) {
20522081
panic!("failed to emit error: {}", e);
20532082
};
20542083
}

compiler/rustc_hir/src/def.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,10 @@ impl<Id> Res<Id> {
671671

672672
#[track_caller]
673673
pub fn expect_non_local<OtherId>(self) -> Res<OtherId> {
674-
self.map_id(|_| panic!("unexpected `Res::Local`"))
674+
self.map_id(
675+
#[track_caller]
676+
|_| panic!("unexpected `Res::Local`"),
677+
)
675678
}
676679

677680
pub fn macro_kind(self) -> Option<MacroKind> {

compiler/rustc_hir/src/hir.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,17 @@ impl LifetimeName {
131131
}
132132
}
133133

134+
pub fn is_anonymous(&self) -> bool {
135+
match *self {
136+
LifetimeName::ImplicitObjectLifetimeDefault
137+
| LifetimeName::Implicit
138+
| LifetimeName::Underscore
139+
| LifetimeName::Param(ParamName::Fresh(_))
140+
| LifetimeName::Error => true,
141+
LifetimeName::Static | LifetimeName::Param(_) => false,
142+
}
143+
}
144+
134145
pub fn is_elided(&self) -> bool {
135146
match self {
136147
LifetimeName::ImplicitObjectLifetimeDefault

compiler/rustc_hir/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
//! [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/hir.html
44
55
#![feature(associated_type_defaults)]
6+
#![feature(closure_track_caller)]
67
#![feature(const_btree_new)]
78
#![feature(let_else)]
89
#![feature(once_cell)]

compiler/rustc_infer/src/infer/error_reporting/mod.rs

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ use rustc_middle::ty::{
7272
subst::{GenericArgKind, Subst, SubstsRef},
7373
Binder, EarlyBinder, List, Region, Ty, TyCtxt, TypeFoldable,
7474
};
75-
use rustc_span::{sym, BytePos, DesugaringKind, Pos, Span};
75+
use rustc_span::{sym, symbol::kw, BytePos, DesugaringKind, Pos, Span};
7676
use rustc_target::spec::abi;
7777
use std::ops::ControlFlow;
7878
use std::{cmp, fmt, iter};
@@ -161,35 +161,45 @@ fn msg_span_from_early_bound_and_free_regions<'tcx>(
161161
{
162162
sp = param.span;
163163
}
164-
(format!("the lifetime `{}` as defined here", br.name), sp)
164+
let text = if br.has_name() {
165+
format!("the lifetime `{}` as defined here", br.name)
166+
} else {
167+
format!("the anonymous lifetime as defined here")
168+
};
169+
(text, sp)
165170
}
166-
ty::ReFree(ty::FreeRegion {
167-
bound_region: ty::BoundRegionKind::BrNamed(_, name), ..
168-
}) => {
169-
let mut sp = sm.guess_head_span(tcx.def_span(scope));
170-
if let Some(param) =
171-
tcx.hir().get_generics(scope).and_then(|generics| generics.get_named(name))
171+
ty::ReFree(ref fr) => {
172+
if !fr.bound_region.is_named()
173+
&& let Some((ty, _)) = find_anon_type(tcx, region, &fr.bound_region)
172174
{
173-
sp = param.span;
174-
}
175-
(format!("the lifetime `{}` as defined here", name), sp)
176-
}
177-
ty::ReFree(ref fr) => match fr.bound_region {
178-
ty::BrAnon(idx) => {
179-
if let Some((ty, _)) = find_anon_type(tcx, region, &fr.bound_region) {
180-
("the anonymous lifetime defined here".to_string(), ty.span)
181-
} else {
182-
(
175+
("the anonymous lifetime defined here".to_string(), ty.span)
176+
} else {
177+
match fr.bound_region {
178+
ty::BoundRegionKind::BrNamed(_, name) => {
179+
let mut sp = sm.guess_head_span(tcx.def_span(scope));
180+
if let Some(param) =
181+
tcx.hir().get_generics(scope).and_then(|generics| generics.get_named(name))
182+
{
183+
sp = param.span;
184+
}
185+
let text = if name == kw::UnderscoreLifetime {
186+
format!("the anonymous lifetime as defined here")
187+
} else {
188+
format!("the lifetime `{}` as defined here", name)
189+
};
190+
(text, sp)
191+
}
192+
ty::BrAnon(idx) => (
183193
format!("the anonymous lifetime #{} defined here", idx + 1),
184-
tcx.def_span(scope),
185-
)
194+
tcx.def_span(scope)
195+
),
196+
_ => (
197+
format!("the lifetime `{}` as defined here", region),
198+
sm.guess_head_span(tcx.def_span(scope)),
199+
),
186200
}
187201
}
188-
_ => (
189-
format!("the lifetime `{}` as defined here", region),
190-
sm.guess_head_span(tcx.def_span(scope)),
191-
),
192-
},
202+
}
193203
_ => bug!(),
194204
}
195205
}
@@ -2552,7 +2562,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
25522562
ty::ReEarlyBound(ty::EarlyBoundRegion { name, .. })
25532563
| ty::ReFree(ty::FreeRegion { bound_region: ty::BrNamed(_, name), .. }),
25542564
_,
2555-
) => {
2565+
) if name != kw::UnderscoreLifetime => {
25562566
// Does the required lifetime have a nice name we can print?
25572567
let mut err = struct_span_err!(
25582568
self.tcx.sess,

0 commit comments

Comments
 (0)