Skip to content

Commit 777bb86

Browse files
committed
Auto merge of rust-lang#93119 - matthiaskrgr:rollup-ku3cn5j, r=matthiaskrgr
Rollup of 13 pull requests Successful merges: - rust-lang#89747 (Add MaybeUninit::(slice_)as_bytes(_mut)) - rust-lang#89764 (Fix variant index / discriminant confusion in uninhabited enum branching) - rust-lang#91606 (Stabilize `-Z print-link-args` as `--print link-args`) - rust-lang#91694 (rustdoc: decouple stability and const-stability) - rust-lang#92183 (Point at correct argument when async fn output type lifetime disagrees with signature) - rust-lang#92582 (improve `_` constants in item signature handling) - rust-lang#92680 (intra-doc: Use the impl's assoc item where possible) - rust-lang#92704 (Change lint message to be stronger for &T -> &mut T transmute) - rust-lang#92861 (Rustdoc mobile: put out-of-band info on its own line) - rust-lang#92992 (Help optimize out backtraces when disabled) - rust-lang#93038 (Fix star handling in block doc comments) - rust-lang#93108 (:arrow_up: rust-analyzer) - rust-lang#93112 (Fix CVE-2022-21658) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 74fbbef + dbc9749 commit 777bb86

File tree

99 files changed

+1914
-803
lines changed

Some content is hidden

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

99 files changed

+1914
-803
lines changed

compiler/rustc_ast/src/attr/mod.rs

+11
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,17 @@ impl Attribute {
242242
}
243243
}
244244

245+
pub fn doc_str_and_comment_kind(&self) -> Option<(Symbol, CommentKind)> {
246+
match self.kind {
247+
AttrKind::DocComment(kind, data) => Some((data, kind)),
248+
AttrKind::Normal(ref item, _) if item.path == sym::doc => item
249+
.meta_kind()
250+
.and_then(|kind| kind.value_str())
251+
.map(|data| (data, CommentKind::Line)),
252+
_ => None,
253+
}
254+
}
255+
245256
pub fn doc_str(&self) -> Option<Symbol> {
246257
match self.kind {
247258
AttrKind::DocComment(.., data) => Some(data),

compiler/rustc_ast/src/util/comments.rs

+25-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::token::CommentKind;
12
use rustc_span::source_map::SourceMap;
23
use rustc_span::{BytePos, CharPos, FileName, Pos, Symbol};
34

@@ -25,7 +26,7 @@ pub struct Comment {
2526

2627
/// Makes a doc string more presentable to users.
2728
/// Used by rustdoc and perhaps other tools, but not by rustc.
28-
pub fn beautify_doc_string(data: Symbol) -> Symbol {
29+
pub fn beautify_doc_string(data: Symbol, kind: CommentKind) -> Symbol {
2930
fn get_vertical_trim(lines: &[&str]) -> Option<(usize, usize)> {
3031
let mut i = 0;
3132
let mut j = lines.len();
@@ -42,10 +43,28 @@ pub fn beautify_doc_string(data: Symbol) -> Symbol {
4243
if i != 0 || j != lines.len() { Some((i, j)) } else { None }
4344
}
4445

45-
fn get_horizontal_trim(lines: &[&str]) -> Option<usize> {
46+
fn get_horizontal_trim(lines: &[&str], kind: CommentKind) -> Option<usize> {
4647
let mut i = usize::MAX;
4748
let mut first = true;
4849

50+
// In case we have doc comments like `/**` or `/*!`, we want to remove stars if they are
51+
// present. However, we first need to strip the empty lines so they don't get in the middle
52+
// when we try to compute the "horizontal trim".
53+
let lines = if kind == CommentKind::Block {
54+
let mut i = 0;
55+
let mut j = lines.len();
56+
57+
while i < j && lines[i].trim().is_empty() {
58+
i += 1;
59+
}
60+
while j > i && lines[j - 1].trim().is_empty() {
61+
j -= 1;
62+
}
63+
&lines[i..j]
64+
} else {
65+
lines
66+
};
67+
4968
for line in lines {
5069
for (j, c) in line.chars().enumerate() {
5170
if j > i || !"* \t".contains(c) {
@@ -79,11 +98,13 @@ pub fn beautify_doc_string(data: Symbol) -> Symbol {
7998
} else {
8099
&mut lines
81100
};
82-
if let Some(horizontal) = get_horizontal_trim(&lines) {
101+
if let Some(horizontal) = get_horizontal_trim(&lines, kind) {
83102
changes = true;
84103
// remove a "[ \t]*\*" block from each line, if possible
85104
for line in lines.iter_mut() {
86-
*line = &line[horizontal + 1..];
105+
if horizontal + 1 < line.len() {
106+
*line = &line[horizontal + 1..];
107+
}
87108
}
88109
}
89110
if changes {

compiler/rustc_ast/src/util/comments/tests.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustc_span::create_default_session_globals_then;
55
fn test_block_doc_comment_1() {
66
create_default_session_globals_then(|| {
77
let comment = "\n * Test \n ** Test\n * Test\n";
8-
let stripped = beautify_doc_string(Symbol::intern(comment));
8+
let stripped = beautify_doc_string(Symbol::intern(comment), CommentKind::Block);
99
assert_eq!(stripped.as_str(), " Test \n* Test\n Test");
1010
})
1111
}
@@ -14,7 +14,7 @@ fn test_block_doc_comment_1() {
1414
fn test_block_doc_comment_2() {
1515
create_default_session_globals_then(|| {
1616
let comment = "\n * Test\n * Test\n";
17-
let stripped = beautify_doc_string(Symbol::intern(comment));
17+
let stripped = beautify_doc_string(Symbol::intern(comment), CommentKind::Block);
1818
assert_eq!(stripped.as_str(), " Test\n Test");
1919
})
2020
}
@@ -23,21 +23,21 @@ fn test_block_doc_comment_2() {
2323
fn test_block_doc_comment_3() {
2424
create_default_session_globals_then(|| {
2525
let comment = "\n let a: *i32;\n *a = 5;\n";
26-
let stripped = beautify_doc_string(Symbol::intern(comment));
26+
let stripped = beautify_doc_string(Symbol::intern(comment), CommentKind::Block);
2727
assert_eq!(stripped.as_str(), " let a: *i32;\n *a = 5;");
2828
})
2929
}
3030

3131
#[test]
3232
fn test_line_doc_comment() {
3333
create_default_session_globals_then(|| {
34-
let stripped = beautify_doc_string(Symbol::intern(" test"));
34+
let stripped = beautify_doc_string(Symbol::intern(" test"), CommentKind::Line);
3535
assert_eq!(stripped.as_str(), " test");
36-
let stripped = beautify_doc_string(Symbol::intern("! test"));
36+
let stripped = beautify_doc_string(Symbol::intern("! test"), CommentKind::Line);
3737
assert_eq!(stripped.as_str(), "! test");
38-
let stripped = beautify_doc_string(Symbol::intern("test"));
38+
let stripped = beautify_doc_string(Symbol::intern("test"), CommentKind::Line);
3939
assert_eq!(stripped.as_str(), "test");
40-
let stripped = beautify_doc_string(Symbol::intern("!test"));
40+
let stripped = beautify_doc_string(Symbol::intern("!test"), CommentKind::Line);
4141
assert_eq!(stripped.as_str(), "!test");
4242
})
4343
}

compiler/rustc_codegen_ssa/src/back/link.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ fn link_natively<'a, B: ArchiveBuilder<'a>>(
667667
cmd.env_remove(k);
668668
}
669669

670-
if sess.opts.debugging_opts.print_link_args {
670+
if sess.opts.prints.contains(&PrintRequest::LinkArgs) {
671671
println!("{:?}", &cmd);
672672
}
673673

compiler/rustc_driver/src/lib.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -645,9 +645,9 @@ impl RustcDefaultCalls {
645645
temps_dir: &Option<PathBuf>,
646646
) -> Compilation {
647647
use rustc_session::config::PrintRequest::*;
648-
// PrintRequest::NativeStaticLibs is special - printed during linking
648+
// NativeStaticLibs and LinkArgs are special - printed during linking
649649
// (empty iterator returns true)
650-
if sess.opts.prints.iter().all(|&p| p == PrintRequest::NativeStaticLibs) {
650+
if sess.opts.prints.iter().all(|&p| p == NativeStaticLibs || p == LinkArgs) {
651651
return Compilation::Continue;
652652
}
653653

@@ -738,7 +738,8 @@ impl RustcDefaultCalls {
738738
codegen_backend.print(*req, sess);
739739
}
740740
// Any output here interferes with Cargo's parsing of other printed output
741-
PrintRequest::NativeStaticLibs => {}
741+
NativeStaticLibs => {}
742+
LinkArgs => {}
742743
}
743744
}
744745
Compilation::Stop

compiler/rustc_hir/src/hir.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -2726,6 +2726,10 @@ pub struct FnHeader {
27262726
}
27272727

27282728
impl FnHeader {
2729+
pub fn is_async(&self) -> bool {
2730+
matches!(&self.asyncness, IsAsync::Async)
2731+
}
2732+
27292733
pub fn is_const(&self) -> bool {
27302734
matches!(&self.constness, Constness::Const)
27312735
}
@@ -3169,7 +3173,7 @@ impl<'hir> Node<'hir> {
31693173
}
31703174
}
31713175

3172-
pub fn fn_decl(&self) -> Option<&FnDecl<'hir>> {
3176+
pub fn fn_decl(&self) -> Option<&'hir FnDecl<'hir>> {
31733177
match self {
31743178
Node::TraitItem(TraitItem { kind: TraitItemKind::Fn(fn_sig, _), .. })
31753179
| Node::ImplItem(ImplItem { kind: ImplItemKind::Fn(fn_sig, _), .. })
@@ -3181,6 +3185,15 @@ impl<'hir> Node<'hir> {
31813185
}
31823186
}
31833187

3188+
pub fn fn_sig(&self) -> Option<&'hir FnSig<'hir>> {
3189+
match self {
3190+
Node::TraitItem(TraitItem { kind: TraitItemKind::Fn(fn_sig, _), .. })
3191+
| Node::ImplItem(ImplItem { kind: ImplItemKind::Fn(fn_sig, _), .. })
3192+
| Node::Item(Item { kind: ItemKind::Fn(fn_sig, _, _), .. }) => Some(fn_sig),
3193+
_ => None,
3194+
}
3195+
}
3196+
31843197
pub fn body_id(&self) -> Option<BodyId> {
31853198
match self {
31863199
Node::TraitItem(TraitItem {

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

+19-12
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@ use rustc_hir::def_id::DefId;
6565
use rustc_hir::lang_items::LangItem;
6666
use rustc_hir::{Item, ItemKind, Node};
6767
use rustc_middle::dep_graph::DepContext;
68-
use rustc_middle::ty::error::TypeError;
6968
use rustc_middle::ty::{
7069
self,
70+
error::TypeError,
7171
subst::{GenericArgKind, Subst, SubstsRef},
72-
Region, Ty, TyCtxt, TypeFoldable,
72+
Binder, Region, Ty, TyCtxt, TypeFoldable,
7373
};
7474
use rustc_span::{sym, BytePos, DesugaringKind, MultiSpan, Pos, Span};
7575
use rustc_target::spec::abi;
@@ -1765,7 +1765,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
17651765
self.note_error_origin(diag, cause, exp_found, terr);
17661766
}
17671767

1768-
pub fn get_impl_future_output_ty(&self, ty: Ty<'tcx>) -> Option<Ty<'tcx>> {
1768+
pub fn get_impl_future_output_ty(&self, ty: Ty<'tcx>) -> Option<Binder<'tcx, Ty<'tcx>>> {
17691769
if let ty::Opaque(def_id, substs) = ty.kind() {
17701770
let future_trait = self.tcx.require_lang_item(LangItem::Future, None);
17711771
// Future::Output
@@ -1775,13 +1775,20 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
17751775

17761776
for (predicate, _) in bounds {
17771777
let predicate = predicate.subst(self.tcx, substs);
1778-
if let ty::PredicateKind::Projection(projection_predicate) =
1779-
predicate.kind().skip_binder()
1780-
{
1781-
if projection_predicate.projection_ty.item_def_id == item_def_id {
1782-
// We don't account for multiple `Future::Output = Ty` contraints.
1783-
return projection_predicate.term.ty();
1784-
}
1778+
let output = predicate
1779+
.kind()
1780+
.map_bound(|kind| match kind {
1781+
ty::PredicateKind::Projection(projection_predicate)
1782+
if projection_predicate.projection_ty.item_def_id == item_def_id =>
1783+
{
1784+
projection_predicate.term.ty()
1785+
}
1786+
_ => None,
1787+
})
1788+
.transpose();
1789+
if output.is_some() {
1790+
// We don't account for multiple `Future::Output = Ty` contraints.
1791+
return output;
17851792
}
17861793
}
17871794
}
@@ -1823,8 +1830,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
18231830
}
18241831

18251832
match (
1826-
self.get_impl_future_output_ty(exp_found.expected),
1827-
self.get_impl_future_output_ty(exp_found.found),
1833+
self.get_impl_future_output_ty(exp_found.expected).map(Binder::skip_binder),
1834+
self.get_impl_future_output_ty(exp_found.found).map(Binder::skip_binder),
18281835
) {
18291836
(Some(exp), Some(found)) if same_type_modulo_infer(exp, found) => match cause.code() {
18301837
ObligationCauseCode::IfExpression(box IfExpressionCause { then, .. }) => {

compiler/rustc_infer/src/infer/error_reporting/nice_region_error/different_lifetimes.rs

+33-76
Original file line numberDiff line numberDiff line change
@@ -106,90 +106,47 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
106106
None => String::new(),
107107
};
108108

109-
let (span_1, span_2, main_label, span_label, future_return_type) =
110-
match (sup_is_ret_type, sub_is_ret_type) {
111-
(None, None) => {
112-
let (main_label_1, span_label_1) = if ty_sup.hir_id == ty_sub.hir_id {
113-
(
114-
"this type is declared with multiple lifetimes...".to_owned(),
115-
"...but data with one lifetime flows into the other here".to_owned(),
116-
)
117-
} else {
118-
(
119-
"these two types are declared with different lifetimes...".to_owned(),
120-
format!("...but data{} flows{} here", span_label_var1, span_label_var2),
121-
)
122-
};
123-
(ty_sup.span, ty_sub.span, main_label_1, span_label_1, None)
124-
}
109+
debug!(
110+
"try_report_anon_anon_conflict: sub_is_ret_type={:?} sup_is_ret_type={:?}",
111+
sub_is_ret_type, sup_is_ret_type
112+
);
125113

126-
(Some(ret_span), _) => {
127-
let sup_future = self.future_return_type(scope_def_id_sup);
128-
let (return_type, action) = if sup_future.is_some() {
129-
("returned future", "held across an await point")
130-
} else {
131-
("return type", "returned")
132-
};
114+
let mut err = struct_span_err!(self.tcx().sess, span, E0623, "lifetime mismatch");
133115

134-
(
135-
ty_sub.span,
136-
ret_span,
137-
format!(
138-
"this parameter and the {} are declared with different lifetimes...",
139-
return_type
140-
),
141-
format!("...but data{} is {} here", span_label_var1, action),
142-
sup_future,
143-
)
144-
}
145-
(_, Some(ret_span)) => {
146-
let sub_future = self.future_return_type(scope_def_id_sub);
147-
let (return_type, action) = if sub_future.is_some() {
148-
("returned future", "held across an await point")
149-
} else {
150-
("return type", "returned")
151-
};
116+
match (sup_is_ret_type, sub_is_ret_type) {
117+
(ret_capture @ Some(ret_span), _) | (_, ret_capture @ Some(ret_span)) => {
118+
let param_span =
119+
if sup_is_ret_type == ret_capture { ty_sub.span } else { ty_sup.span };
120+
121+
err.span_label(
122+
param_span,
123+
"this parameter and the return type are declared with different lifetimes...",
124+
);
125+
err.span_label(ret_span, "");
126+
err.span_label(span, format!("...but data{} is returned here", span_label_var1));
127+
}
152128

153-
(
129+
(None, None) => {
130+
if ty_sup.hir_id == ty_sub.hir_id {
131+
err.span_label(ty_sup.span, "this type is declared with multiple lifetimes...");
132+
err.span_label(ty_sub.span, "");
133+
err.span_label(span, "...but data with one lifetime flows into the other here");
134+
} else {
135+
err.span_label(
154136
ty_sup.span,
155-
ret_span,
156-
format!(
157-
"this parameter and the {} are declared with different lifetimes...",
158-
return_type
159-
),
160-
format!("...but data{} is {} here", span_label_var1, action),
161-
sub_future,
162-
)
137+
"these two types are declared with different lifetimes...",
138+
);
139+
err.span_label(ty_sub.span, "");
140+
err.span_label(
141+
span,
142+
format!("...but data{} flows{} here", span_label_var1, span_label_var2),
143+
);
163144
}
164-
};
165-
166-
let mut err = struct_span_err!(self.tcx().sess, span, E0623, "lifetime mismatch");
167-
168-
err.span_label(span_1, main_label);
169-
err.span_label(span_2, String::new());
170-
err.span_label(span, span_label);
145+
}
146+
}
171147

172148
self.suggest_adding_lifetime_params(sub, ty_sup, ty_sub, &mut err);
173149

174-
if let Some(t) = future_return_type {
175-
let snip = self
176-
.tcx()
177-
.sess
178-
.source_map()
179-
.span_to_snippet(t.span)
180-
.ok()
181-
.and_then(|s| match (&t.kind, s.as_str()) {
182-
(rustc_hir::TyKind::Tup(&[]), "") => Some("()".to_string()),
183-
(_, "") => None,
184-
_ => Some(s),
185-
})
186-
.unwrap_or_else(|| "{unnamed_type}".to_string());
187-
188-
err.span_label(
189-
t.span,
190-
&format!("this `async fn` implicitly returns an `impl Future<Output = {}>`", snip),
191-
);
192-
}
193150
err.emit();
194151
Some(ErrorReported)
195152
}

0 commit comments

Comments
 (0)