Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 5 pull requests #99849

Merged
merged 13 commits into from
Jul 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_expand/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ fn get_features(
.span_suggestion(
mi.span(),
"expected just one word",
format!("{}", ident.name),
ident.name,
Applicability::MaybeIncorrect,
)
.emit();
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_parse/src/parser/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1677,7 +1677,6 @@ impl<'a> Parser<'a> {
}

/// Is this a possibly malformed start of a `macro_rules! foo` item definition?

fn is_macro_rules_item(&mut self) -> IsMacroRulesItem {
if self.check_keyword(kw::MacroRules) {
let macro_rules_span = self.token.span;
Expand Down
31 changes: 14 additions & 17 deletions compiler/rustc_resolve/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2023,7 +2023,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
span: Span,
mut path: Vec<Segment>,
parent_scope: &ParentScope<'b>,
) -> Option<(Vec<Segment>, Vec<String>)> {
) -> Option<(Vec<Segment>, Option<String>)> {
debug!("make_path_suggestion: span={:?} path={:?}", span, path);

match (path.get(0), path.get(1)) {
Expand Down Expand Up @@ -2058,12 +2058,12 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
&mut self,
mut path: Vec<Segment>,
parent_scope: &ParentScope<'b>,
) -> Option<(Vec<Segment>, Vec<String>)> {
) -> Option<(Vec<Segment>, Option<String>)> {
// Replace first ident with `self` and check if that is valid.
path[0].ident.name = kw::SelfLower;
let result = self.r.maybe_resolve_path(&path, None, parent_scope);
debug!("make_missing_self_suggestion: path={:?} result={:?}", path, result);
if let PathResult::Module(..) = result { Some((path, Vec::new())) } else { None }
if let PathResult::Module(..) = result { Some((path, None)) } else { None }
}

/// Suggests a missing `crate::` if that resolves to an correct module.
Expand All @@ -2077,20 +2077,20 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
&mut self,
mut path: Vec<Segment>,
parent_scope: &ParentScope<'b>,
) -> Option<(Vec<Segment>, Vec<String>)> {
) -> Option<(Vec<Segment>, Option<String>)> {
// Replace first ident with `crate` and check if that is valid.
path[0].ident.name = kw::Crate;
let result = self.r.maybe_resolve_path(&path, None, parent_scope);
debug!("make_missing_crate_suggestion: path={:?} result={:?}", path, result);
if let PathResult::Module(..) = result {
Some((
path,
vec![
Some(
"`use` statements changed in Rust 2018; read more at \
<https://doc.rust-lang.org/edition-guide/rust-2018/module-system/path-\
clarity.html>"
.to_string(),
],
),
))
} else {
None
Expand All @@ -2108,12 +2108,12 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
&mut self,
mut path: Vec<Segment>,
parent_scope: &ParentScope<'b>,
) -> Option<(Vec<Segment>, Vec<String>)> {
) -> Option<(Vec<Segment>, Option<String>)> {
// Replace first ident with `crate` and check if that is valid.
path[0].ident.name = kw::Super;
let result = self.r.maybe_resolve_path(&path, None, parent_scope);
debug!("make_missing_super_suggestion: path={:?} result={:?}", path, result);
if let PathResult::Module(..) = result { Some((path, Vec::new())) } else { None }
if let PathResult::Module(..) = result { Some((path, None)) } else { None }
}

/// Suggests a missing external crate name if that resolves to an correct module.
Expand All @@ -2130,7 +2130,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
&mut self,
mut path: Vec<Segment>,
parent_scope: &ParentScope<'b>,
) -> Option<(Vec<Segment>, Vec<String>)> {
) -> Option<(Vec<Segment>, Option<String>)> {
if path[1].ident.span.rust_2015() {
return None;
}
Expand All @@ -2151,7 +2151,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
name, path, result
);
if let PathResult::Module(..) = result {
return Some((path, Vec::new()));
return Some((path, None));
}
}

Expand All @@ -2175,7 +2175,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
import: &'b Import<'b>,
module: ModuleOrUniformRoot<'b>,
ident: Ident,
) -> Option<(Option<Suggestion>, Vec<String>)> {
) -> Option<(Option<Suggestion>, Option<String>)> {
let ModuleOrUniformRoot::Module(mut crate_module) = module else {
return None;
};
Expand Down Expand Up @@ -2287,12 +2287,9 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
String::from("a macro with this name exists at the root of the crate"),
Applicability::MaybeIncorrect,
));
let note = vec![
"this could be because a macro annotated with `#[macro_export]` will be exported \
at the root of the crate instead of the module where it is defined"
.to_string(),
];
Some((suggestion, note))
Some((suggestion, Some("this could be because a macro annotated with `#[macro_export]` will be exported \
at the root of the crate instead of the module where it is defined"
.to_string())))
} else {
None
}
Expand Down
16 changes: 7 additions & 9 deletions compiler/rustc_resolve/src/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ impl<'a> Resolver<'a> {
struct UnresolvedImportError {
span: Span,
label: Option<String>,
note: Vec<String>,
note: Option<String>,
suggestion: Option<Suggestion>,
}

Expand Down Expand Up @@ -427,7 +427,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
let err = UnresolvedImportError {
span: import.span,
label: None,
note: Vec::new(),
note: None,
suggestion: None,
};
if path.contains("::") {
Expand Down Expand Up @@ -463,10 +463,8 @@ impl<'a, 'b> ImportResolver<'a, 'b> {

let mut diag = struct_span_err!(self.r.session, span, E0432, "{}", &msg);

if let Some((_, UnresolvedImportError { note, .. })) = errors.iter().last() {
for message in note {
diag.note(message);
}
if let Some((_, UnresolvedImportError { note: Some(note), .. })) = errors.iter().last() {
diag.note(note);
}

for (_, err) in errors.into_iter().take(MAX_LABEL_COUNT) {
Expand Down Expand Up @@ -644,7 +642,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
None => UnresolvedImportError {
span,
label: Some(label),
note: Vec::new(),
note: None,
suggestion,
},
};
Expand Down Expand Up @@ -686,7 +684,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
return Some(UnresolvedImportError {
span: import.span,
label: Some(String::from("cannot glob-import a module into itself")),
note: Vec::new(),
note: None,
suggestion: None,
});
}
Expand Down Expand Up @@ -830,7 +828,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
let (suggestion, note) =
match self.check_for_module_export_macro(import, module, ident) {
Some((suggestion, note)) => (suggestion.or(lev_suggestion), note),
_ => (lev_suggestion, Vec::new()),
_ => (lev_suggestion, None),
};

let label = match module {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ pub trait InferCtxtExt<'tcx> {
trait_pred: ty::PolyTraitPredicate<'tcx>,
) -> bool;

fn get_closure_name(&self, def_id: DefId, err: &mut Diagnostic, msg: &str) -> Option<String>;
fn get_closure_name(&self, def_id: DefId, err: &mut Diagnostic, msg: &str) -> Option<Symbol>;

fn suggest_fn_call(
&self,
Expand Down Expand Up @@ -737,13 +737,13 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
/// Given a closure's `DefId`, return the given name of the closure.
///
/// This doesn't account for reassignments, but it's only used for suggestions.
fn get_closure_name(&self, def_id: DefId, err: &mut Diagnostic, msg: &str) -> Option<String> {
let get_name = |err: &mut Diagnostic, kind: &hir::PatKind<'_>| -> Option<String> {
fn get_closure_name(&self, def_id: DefId, err: &mut Diagnostic, msg: &str) -> Option<Symbol> {
let get_name = |err: &mut Diagnostic, kind: &hir::PatKind<'_>| -> Option<Symbol> {
// Get the local name of this closure. This can be inaccurate because
// of the possibility of reassignment, but this should be good enough.
match &kind {
hir::PatKind::Binding(hir::BindingAnnotation::Unannotated, _, name, None) => {
Some(format!("{}", name))
hir::PatKind::Binding(hir::BindingAnnotation::Unannotated, _, ident, None) => {
Some(ident.name)
}
_ => {
err.note(msg);
Expand Down
6 changes: 4 additions & 2 deletions compiler/rustc_traits/src/evaluate_obligation.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use rustc_infer::infer::TyCtxtInferExt;
use rustc_infer::infer::{DefiningAnchor, TyCtxtInferExt};
use rustc_middle::ty::query::Providers;
use rustc_middle::ty::{ParamEnvAnd, TyCtxt};
use rustc_span::source_map::DUMMY_SP;
Expand All @@ -16,7 +16,9 @@ fn evaluate_obligation<'tcx>(
canonical_goal: CanonicalPredicateGoal<'tcx>,
) -> Result<EvaluationResult, OverflowError> {
debug!("evaluate_obligation(canonical_goal={:#?})", canonical_goal);
tcx.infer_ctxt().enter_with_canonical(
// HACK This bubble is required for this tests to pass:
// impl-trait/issue99642.rs
tcx.infer_ctxt().with_opaque_type_inference(DefiningAnchor::Bubble).enter_with_canonical(
DUMMY_SP,
&canonical_goal,
|ref infcx, goal, _canonical_inference_vars| {
Expand Down
15 changes: 10 additions & 5 deletions compiler/rustc_traits/src/type_op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use rustc_hir as hir;
use rustc_hir::def_id::DefId;
use rustc_infer::infer::at::ToTrace;
use rustc_infer::infer::canonical::{Canonical, QueryResponse};
use rustc_infer::infer::{InferCtxt, TyCtxtInferExt};
use rustc_infer::infer::{DefiningAnchor, InferCtxt, TyCtxtInferExt};
use rustc_infer::traits::TraitEngineExt as _;
use rustc_middle::ty::query::Providers;
use rustc_middle::ty::subst::{GenericArg, Subst, UserSelfTy, UserSubsts};
Expand Down Expand Up @@ -258,10 +258,15 @@ fn type_op_prove_predicate<'tcx>(
tcx: TyCtxt<'tcx>,
canonicalized: Canonical<'tcx, ParamEnvAnd<'tcx, ProvePredicate<'tcx>>>,
) -> Result<&'tcx Canonical<'tcx, QueryResponse<'tcx, ()>>, NoSolution> {
tcx.infer_ctxt().enter_canonical_trait_query(&canonicalized, |infcx, fulfill_cx, key| {
type_op_prove_predicate_with_cause(infcx, fulfill_cx, key, ObligationCause::dummy());
Ok(())
})
// HACK This bubble is required for this test to pass:
// impl-trait/issue-99642.rs
tcx.infer_ctxt().with_opaque_type_inference(DefiningAnchor::Bubble).enter_canonical_trait_query(
&canonicalized,
|infcx, fulfill_cx, key| {
type_op_prove_predicate_with_cause(infcx, fulfill_cx, key, ObligationCause::dummy());
Ok(())
},
)
}

/// The core of the `type_op_prove_predicate` query: for diagnostics purposes in NLL HRTB errors,
Expand Down
4 changes: 4 additions & 0 deletions library/std/src/os/fd/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use crate::os::wasi::io::OwnedFd;
use crate::sys_common::{AsInner, IntoInner};

/// Raw file descriptors.
#[cfg_attr(not(bootstrap), rustc_allowed_through_unstable_modules)]
#[stable(feature = "rust1", since = "1.0.0")]
pub type RawFd = raw::c_int;

Expand All @@ -22,6 +23,7 @@ pub type RawFd = raw::c_int;
/// This is only available on unix and WASI platforms and must be imported in
/// order to call the method. Windows platforms have a corresponding
/// `AsRawHandle` and `AsRawSocket` set of traits.
#[cfg_attr(not(bootstrap), rustc_allowed_through_unstable_modules)]
#[stable(feature = "rust1", since = "1.0.0")]
pub trait AsRawFd {
/// Extracts the raw file descriptor.
Expand Down Expand Up @@ -57,6 +59,7 @@ pub trait AsRawFd {

/// A trait to express the ability to construct an object from a raw file
/// descriptor.
#[cfg_attr(not(bootstrap), rustc_allowed_through_unstable_modules)]
#[stable(feature = "from_raw_os", since = "1.1.0")]
pub trait FromRawFd {
/// Constructs a new instance of `Self` from the given raw file
Expand Down Expand Up @@ -100,6 +103,7 @@ pub trait FromRawFd {

/// A trait to express the ability to consume an object and acquire ownership of
/// its raw file descriptor.
#[cfg_attr(not(bootstrap), rustc_allowed_through_unstable_modules)]
#[stable(feature = "into_raw_os", since = "1.4.0")]
pub trait IntoRawFd {
/// Consumes this object, returning the raw underlying file descriptor.
Expand Down
15 changes: 15 additions & 0 deletions library/std/src/os/wasi/io/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,19 @@

#![unstable(feature = "wasi_ext", issue = "71213")]

// NOTE: despite the fact that this module is unstable,
// stable Rust had the capability to access the stable
// re-exported items from os::fd::raw through this
// unstable module.
// In PR #95956 the stability checker was changed to check
// all path segments of an item rather than just the last,
// which caused the aforementioned stable usage to regress
// (see issue #99502).
// As a result, the items in os::fd::raw were given the
// rustc_allowed_through_unstable_modules attribute.
// No regression tests were added to ensure this property,
// as CI is not configured to test wasm32-wasi.
// If this module is stabilized,
// you may want to remove those attributes
// (assuming no other unstable modules need them).
pub use crate::os::fd::raw::*;
3 changes: 1 addition & 2 deletions src/librustdoc/html/static/css/settings.css
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@

.toggle {
position: relative;
display: inline-block;
width: 100%;
height: 27px;
margin-right: 20px;
display: flex;
align-items: center;
Expand All @@ -58,6 +56,7 @@
.slider {
position: relative;
width: 45px;
min-width: 45px;
display: block;
height: 28px;
margin-right: 20px;
Expand Down
9 changes: 9 additions & 0 deletions src/test/rustdoc-gui/settings.goml
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,12 @@ assert-false: "noscript section"
javascript: false
reload:
assert-css: ("noscript section", {"display": "block"})
javascript: true

// Check for the display on small screen
show-text: true
reload:
size: (300, 1000)
click: "#settings-menu"
wait-for: "#settings"
assert-css: ("#settings .slider", {"width": "45px"}, ALL)
8 changes: 8 additions & 0 deletions src/test/ui/impl-trait/issue-99642-2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// check-pass

#![feature(type_alias_impl_trait)]
type Opq = impl Sized;
fn test() -> impl Iterator<Item = Opq> {
Box::new(0..) as Box<dyn Iterator<Item = _>>
}
fn main(){}
7 changes: 7 additions & 0 deletions src/test/ui/impl-trait/issue-99642.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// check-pass

fn test() -> impl Iterator<Item = impl Sized> {
Box::new(0..) as Box<dyn Iterator<Item = _>>
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
error[E0275]: overflow evaluating the requirement `<fn() -> Foo {foo} as FnOnce<()>>::Output == fn() -> Foo {foo}`
error[E0275]: overflow evaluating the requirement `fn() -> Foo {foo}: Sized`
--> $DIR/issue-53398-cyclic-types.rs:5:13
|
LL | fn foo() -> Foo {
| ^^^
|
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`issue_53398_cyclic_types`)

error: aborting due to previous error

Expand Down